/* 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 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "gstducati.h" #include "gstducatimpeg4enc.h" #include #include #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 "); 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; 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; 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); if (!GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc)) return FALSE; videnc->params->profile = self->profile; videnc->params->level = self->level; videnc->params->maxInterFrameInterval = 0; videnc->dynParams->mvAccuracy = IVIDENC2_MOTIONVECTOR_HALFPEL; videnc->dynParams->interFrameInterval = 0; 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 (IVIDENC2_Params), sizeof (IVIDENC2_DynamicParams), sizeof (IVIDENC2_Status), sizeof (IVIDENC2_InArgs), sizeof (IVIDENC2_OutArgs)); }