diff options
author | Alessandro Decina <alessandro.decina@collabora.co.uk> | 2011-10-21 10:36:52 +0200 |
---|---|---|
committer | Alessandro Decina <alessandro.decina@collabora.co.uk> | 2011-10-21 10:39:29 +0200 |
commit | 9297fbe3244c223de77261d1895b48ea98106519 (patch) | |
tree | 26fecdfbd4c156014d9dc357486b4e9760739310 | |
parent | 05e439256130a78384add9c60304f721d120d00c (diff) |
ducatimpeg4enc: add mpeg4 encoder
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gstducati.c | 4 | ||||
-rw-r--r-- | src/gstducatimpeg4enc.c | 284 | ||||
-rw-r--r-- | src/gstducatimpeg4enc.h | 56 |
4 files changed, 345 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index bccf8e1..2e70207 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,7 @@ noinst_HEADERS = \ gstducatih264dec.h \ gstducatividdec.h \ gstducatih264enc.h \ + gstducatimpeg4enc.h \ gstducatividenc.h \ gstducatibufferpool.h \ gstducati.h @@ -27,6 +28,7 @@ libgstducati_la_SOURCES = \ gstducatividdec.c \ gstducatibufferpool.c \ gstducatih264enc.c \ + gstducatimpeg4enc.c \ gstducatividenc.c \ gstducati.c \ $(noinst_HEADERS) diff --git a/src/gstducati.c b/src/gstducati.c index b6e19fb..ae3e800 100644 --- a/src/gstducati.c +++ b/src/gstducati.c @@ -30,6 +30,7 @@ #include "gstducativp7dec.h" #include "gstducatirvdec.h" #include "gstducatih264enc.h" +#include "gstducatimpeg4enc.h" GST_DEBUG_CATEGORY (gst_ducati_debug); @@ -48,7 +49,8 @@ plugin_init (GstPlugin * plugin) gst_element_register (plugin, "ducativp6dec", GST_RANK_PRIMARY, GST_TYPE_DUCATIVP6DEC) && gst_element_register (plugin, "ducativp7dec", GST_RANK_PRIMARY, GST_TYPE_DUCATIVP7DEC) && gst_element_register (plugin, "ducatirvdec", GST_RANK_PRIMARY, GST_TYPE_DUCATIRVDEC) && - gst_element_register (plugin, "ducatih264enc", GST_RANK_PRIMARY, GST_TYPE_DUCATIH264ENC); + gst_element_register (plugin, "ducatih264enc", GST_RANK_PRIMARY, GST_TYPE_DUCATIH264ENC) && + gst_element_register (plugin, "ducatimpeg4enc", GST_RANK_PRIMARY, GST_TYPE_DUCATIMPEG4ENC); } void * diff --git a/src/gstducatimpeg4enc.c b/src/gstducatimpeg4enc.c new file mode 100644 index 0000000..50f0001 --- /dev/null +++ b/src/gstducatimpeg4enc.c @@ -0,0 +1,284 @@ +/* GStreamer + * Copyright (c) 2011, Texas Instruments Incorporated + * Copyright (c) 2011, Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Alessandro Decina <alessandro.decina@collabora.com> + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstducati.h" +#include "gstducatimpeg4enc.h" + +#include <string.h> + +#include <math.h> + +#define GST_CAT_DEFAULT gst_ducati_debug + +#define DEFAULT_PROFILE GST_DUCATI_MPEG4ENC_PROFILE_SIMPLE +#define DEFAULT_LEVEL GST_DUCATI_MPEG4ENC_LEVEL_5 + +#define GST_TYPE_DUCATI_MPEG4ENC_PROFILE (gst_ducati_mpeg4enc_profile_get_type ()) +#define GST_TYPE_DUCATI_MPEG4ENC_LEVEL (gst_ducati_mpeg4enc_level_get_type ()) + + +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_PROFILE, + PROP_LEVEL, +}; + +static void gst_ducati_mpeg4enc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_ducati_mpeg4enc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_ducati_mpeg4enc_allocate_params (GstDucatiVidEnc * + self, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz, + gint outargs_sz); +static gboolean gst_ducati_mpeg4enc_configure (GstDucatiVidEnc * self); + + +static GstStaticPadTemplate gst_ducati_mpeg4enc_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("NV12")) + ); + +static GstStaticPadTemplate gst_ducati_mpeg4enc_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/mpeg, mpegversion=4, systemstream=false") + ); + +GST_BOILERPLATE (GstDucatiMPEG4Enc, gst_ducati_mpeg4enc, GstDucatiVidEnc, + GST_TYPE_DUCATIVIDENC); + + +/* the values for the following enums are taken from the codec */ + +enum +{ + GST_DUCATI_MPEG4ENC_PROFILE_SIMPLE = 3, /**< BaseLine Profile */ +}; + +enum +{ + GST_DUCATI_MPEG4ENC_LEVEL_0 = 0, /**< MPEG4 Simple Profile Level 0 */ + GST_DUCATI_MPEG4ENC_LEVEL_0B = 9, /**< MPEG4 Simple Profile Level 0b*/ + GST_DUCATI_MPEG4ENC_LEVEL_1 = 1, /**< MPEG4 Simple Profile Level 1 */ + GST_DUCATI_MPEG4ENC_LEVEL_2 = 2, /**< MPEG4 Simple Profile Level 2 */ + GST_DUCATI_MPEG4ENC_LEVEL_3 = 3, /**< MPEG4 Simple Profile Level 3 */ + GST_DUCATI_MPEG4ENC_LEVEL_4A = 4, /**< MPEG4 Simple Profile Level 4a*/ + GST_DUCATI_MPEG4ENC_LEVEL_5 = 5, /**< MPEG4 Simple Profile Level 5 */ + GST_DUCATI_MPEG4ENC_LEVEL_6 = 6 /**< MPEG4 Simple Profile Level 6 */ +}; + +static GType +gst_ducati_mpeg4enc_profile_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GEnumValue vals[] = { + {GST_DUCATI_MPEG4ENC_PROFILE_SIMPLE, "Simple", "simple"}, + {0, NULL, NULL}, + }; + + type = g_enum_register_static ("GstDucatiMPEG4EncProfile", vals); + } + + return type; +} + +static GType +gst_ducati_mpeg4enc_level_get_type (void) +{ + static GType type = 0; + + if (!type) { + static const GEnumValue vals[] = { + {GST_DUCATI_MPEG4ENC_LEVEL_0, "Level 0", "level-0"}, + {GST_DUCATI_MPEG4ENC_LEVEL_0B, "Level 0B", "level-0b"}, + {GST_DUCATI_MPEG4ENC_LEVEL_1, "Level 1", "level-1"}, + {GST_DUCATI_MPEG4ENC_LEVEL_2, "Level 2", "level-2"}, + {GST_DUCATI_MPEG4ENC_LEVEL_3, "Level 3", "level-3"}, + {GST_DUCATI_MPEG4ENC_LEVEL_4A, "Level 4", "level-4"}, + {GST_DUCATI_MPEG4ENC_LEVEL_5, "Level 5", "level-5"}, + {GST_DUCATI_MPEG4ENC_LEVEL_6, "Level 6", "level-6"}, + {0, NULL, NULL}, + }; + + type = g_enum_register_static ("GstDucatiMPEG4EncLevel", vals); + } + + return type; +} + +static void +gst_ducati_mpeg4enc_base_init (gpointer g_class) +{ + + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_ducati_mpeg4enc_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_ducati_mpeg4enc_sink_template)); + + gst_element_class_set_details_simple (element_class, "MPEG4 Encoder", + "Codec/Encoder/Video", + "Encode raw video into MPEG4 stream", + "Alessandro Decina <alessandro.decina@collabora.com>"); + + GST_DUCATIVIDENC_CLASS (element_class)->codec_name = "ivahd_mpeg4enc"; +} + +static void +gst_ducati_mpeg4enc_class_init (GstDucatiMPEG4EncClass * klass) +{ + GObjectClass *gobject_class; + GstDucatiVidEncClass *videnc_class; + + gobject_class = G_OBJECT_CLASS (klass); + videnc_class = GST_DUCATIVIDENC_CLASS (klass); + + gobject_class->set_property = gst_ducati_mpeg4enc_set_property; + gobject_class->get_property = gst_ducati_mpeg4enc_get_property; + + videnc_class->allocate_params = gst_ducati_mpeg4enc_allocate_params; + videnc_class->configure = gst_ducati_mpeg4enc_configure; + + g_object_class_install_property (gobject_class, PROP_PROFILE, + g_param_spec_enum ("profile", "MPEG4 Profile", "MPEG4 Profile", + GST_TYPE_DUCATI_MPEG4ENC_PROFILE, DEFAULT_PROFILE, + G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, PROP_LEVEL, + g_param_spec_enum ("level", "MPEG4 Level", "MPEG4 Level", + GST_TYPE_DUCATI_MPEG4ENC_LEVEL, DEFAULT_LEVEL, G_PARAM_READWRITE)); +} + +static void +gst_ducati_mpeg4enc_init (GstDucatiMPEG4Enc * self, + GstDucatiMPEG4EncClass * klass) +{ + GST_DEBUG ("gst_ducati_mpeg4enc_init"); + + self->profile = DEFAULT_PROFILE; + self->level = DEFAULT_LEVEL; +} + +static void +gst_ducati_mpeg4enc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstDucatiMPEG4Enc *self = GST_DUCATIMPEG4ENC (object); + + g_return_if_fail (GST_IS_DUCATIMPEG4ENC (object)); + self = GST_DUCATIMPEG4ENC (object); + + switch (prop_id) { + case PROP_PROFILE: + self->profile = g_value_get_enum (value); + break; + case PROP_LEVEL: + self->level = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +gst_ducati_mpeg4enc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstDucatiMPEG4Enc *self = GST_DUCATIMPEG4ENC (object); + + g_return_if_fail (GST_IS_DUCATIMPEG4ENC (object)); + self = GST_DUCATIMPEG4ENC (object); + + switch (prop_id) { + case PROP_PROFILE: + g_value_set_enum (value, self->profile); + break; + case PROP_LEVEL: + g_value_set_enum (value, self->level); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static gboolean +gst_ducati_mpeg4enc_configure (GstDucatiVidEnc * videnc) +{ + GstDucatiMPEG4Enc *self = GST_DUCATIMPEG4ENC (videnc); + IMPEG4ENC_Params *params; + IMPEG4ENC_DynamicParams *dynParams; + + if (!GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc)) + return FALSE; + + params = (IMPEG4ENC_Params *) videnc->params; + dynParams = (IMPEG4ENC_DynamicParams *) videnc->dynParams; + + videnc->params->profile = self->profile; + videnc->params->level = self->level; + videnc->params->maxInterFrameInterval = 0; + + params->useDataPartitioning = 0; + params->useRvlc = 0; + params->useShortVideoHeader = 0; + params->vopTimeIncrementResolution = 60; + params->nonMultiple16RefPadMethod = 1; + params->pixelRange = 1; + params->enableSceneChangeAlgo = 1; + params->useVOS = 0; + params->enableMONA = 0; + + videnc->dynParams->mvAccuracy = IVIDENC2_MOTIONVECTOR_HALFPEL; + videnc->dynParams->interFrameInterval = 0; + + dynParams->aspectRatioIdc = IMPEG4ENC_ASPECTRATIO_SQUARE; + + return TRUE; +} + +static gboolean +gst_ducati_mpeg4enc_allocate_params (GstDucatiVidEnc * + videnc, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz, + gint outargs_sz) +{ + return GST_DUCATIVIDENC_CLASS (parent_class)->allocate_params (videnc, + sizeof (IMPEG4ENC_Params), sizeof (IMPEG4ENC_DynamicParams), + sizeof (IMPEG4ENC_Status), sizeof (IVIDENC2_InArgs), + sizeof (IVIDENC2_OutArgs)); +} diff --git a/src/gstducatimpeg4enc.h b/src/gstducatimpeg4enc.h new file mode 100644 index 0000000..e991a51 --- /dev/null +++ b/src/gstducatimpeg4enc.h @@ -0,0 +1,56 @@ +/* + * GStreamer + * Copyright (c) 2010, Texas Instruments Incorporated + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __GST_DUCATIMPEG4ENC_H__ +#define __GST_DUCATIMPEG4ENC_H__ + +#include <ti/sdo/codecs/mpeg4enc/impeg4enc.h> +#include "gstducatividenc.h" + +#define GST_TYPE_DUCATIMPEG4ENC \ + (gst_ducati_mpeg4enc_get_type()) +#define GST_DUCATIMPEG4ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DUCATIMPEG4ENC,GstDucatiMPEG4Enc)) +#define GST_DUCATIMPEG4ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DUCATIMPEG4ENC,GstDucatiMPEG4EncClass)) +#define GST_IS_DUCATIMPEG4ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DUCATIMPEG4ENC)) +#define GST_IS_DUCATIMPEG4ENC_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DUCATIMPEG4ENC)) +#define GST_DUCATIMPEG4ENC_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DUCATIMPEG4ENC, GstDucatiMPEG4EncClass)) + +typedef struct _GstDucatiMPEG4Enc GstDucatiMPEG4Enc; +typedef struct _GstDucatiMPEG4EncClass GstDucatiMPEG4EncClass; + +struct _GstDucatiMPEG4Enc +{ + GstDucatiVidEnc parent; + guint profile; + guint level; +}; + +struct _GstDucatiMPEG4EncClass +{ + GstDucatiVidEncClass parent_class; +}; + +GType gst_ducati_mpeg4enc_get_type (void); + +#endif |