diff options
Diffstat (limited to 'ext/mpeg2enc/gstmpeg2enc.cc')
-rw-r--r-- | ext/mpeg2enc/gstmpeg2enc.cc | 140 |
1 files changed, 61 insertions, 79 deletions
diff --git a/ext/mpeg2enc/gstmpeg2enc.cc b/ext/mpeg2enc/gstmpeg2enc.cc index 7ee28bd9..1f6e582a 100644 --- a/ext/mpeg2enc/gstmpeg2enc.cc +++ b/ext/mpeg2enc/gstmpeg2enc.cc @@ -30,13 +30,15 @@ * we do something manual... */ static void -add_fps (GstCaps *caps) +add_fps (GstCaps * caps) { GstStructure *structure = gst_caps_get_structure (caps, 0); - GValue list = { 0 }, fps = { 0 }; - gdouble fpss[] = { 24.0/1.001, 24.0, 25.0, - 30.0/1.001, 30.0, 50.0, - 60.0/1.001, 60.0, 0 }; + GValue list = { 0 }, fps = { + 0}; + gdouble fpss[] = { 24.0 / 1.001, 24.0, 25.0, + 30.0 / 1.001, 30.0, 50.0, + 60.0 / 1.001, 60.0, 0 + }; guint n; g_value_init (&list, GST_TYPE_LIST); @@ -59,15 +61,13 @@ sink_templ (void) GstCaps *caps; caps = gst_caps_new_simple ("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, - GST_MAKE_FOURCC ('I','4','2','0'), - "width", GST_TYPE_INT_RANGE, 16, 4096, - "height", GST_TYPE_INT_RANGE, 16, 4096, - NULL); + "format", GST_TYPE_FOURCC, + GST_MAKE_FOURCC ('I', '4', '2', '0'), + "width", GST_TYPE_INT_RANGE, 16, 4096, + "height", GST_TYPE_INT_RANGE, 16, 4096, NULL); add_fps (caps); - templ = gst_pad_template_new ("sink", GST_PAD_SINK, - GST_PAD_ALWAYS, caps); + templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps); } return templ; @@ -82,42 +82,34 @@ src_templ (void) GstCaps *caps; caps = gst_caps_new_simple ("video/mpeg", - "systemstream", G_TYPE_BOOLEAN, FALSE, - "mpegversion", GST_TYPE_INT_RANGE, 1, 2, - "width", GST_TYPE_INT_RANGE, 16, 4096, - "height", GST_TYPE_INT_RANGE, 16, 4096, - NULL); + "systemstream", G_TYPE_BOOLEAN, FALSE, + "mpegversion", GST_TYPE_INT_RANGE, 1, 2, + "width", GST_TYPE_INT_RANGE, 16, 4096, + "height", GST_TYPE_INT_RANGE, 16, 4096, NULL); add_fps (caps); - templ = gst_pad_template_new ("src", GST_PAD_SRC, - GST_PAD_ALWAYS, caps); + templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps); } return templ; } -static void gst_mpeg2enc_base_init (GstMpeg2encClass *klass); -static void gst_mpeg2enc_class_init (GstMpeg2encClass *klass); -static void gst_mpeg2enc_init (GstMpeg2enc *enc); -static void gst_mpeg2enc_dispose (GObject *object); +static void gst_mpeg2enc_base_init (GstMpeg2encClass * klass); +static void gst_mpeg2enc_class_init (GstMpeg2encClass * klass); +static void gst_mpeg2enc_init (GstMpeg2enc * enc); +static void gst_mpeg2enc_dispose (GObject * object); -static void gst_mpeg2enc_loop (GstElement *element); +static void gst_mpeg2enc_loop (GstElement * element); static GstPadLinkReturn - gst_mpeg2enc_sink_link (GstPad *pad, - const GstCaps *caps); +gst_mpeg2enc_sink_link (GstPad * pad, const GstCaps * caps); -static GstElementStateReturn - gst_mpeg2enc_change_state (GstElement *element); +static GstElementStateReturn gst_mpeg2enc_change_state (GstElement * element); -static void gst_mpeg2enc_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void gst_mpeg2enc_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); +static void gst_mpeg2enc_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_mpeg2enc_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); static GstElementClass *parent_class = NULL; @@ -128,7 +120,7 @@ gst_mpeg2enc_get_type (void) if (!gst_mpeg2enc_type) { static const GTypeInfo gst_mpeg2enc_info = { - sizeof (GstMpeg2encClass), + sizeof (GstMpeg2encClass), (GBaseInitFunc) gst_mpeg2enc_base_init, NULL, (GClassInitFunc) gst_mpeg2enc_class_init, @@ -141,34 +133,31 @@ gst_mpeg2enc_get_type (void) gst_mpeg2enc_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstMpeg2enc", - &gst_mpeg2enc_info, - (GTypeFlags) 0); + "GstMpeg2enc", &gst_mpeg2enc_info, (GTypeFlags) 0); } return gst_mpeg2enc_type; } static void -gst_mpeg2enc_base_init (GstMpeg2encClass *klass) +gst_mpeg2enc_base_init (GstMpeg2encClass * klass) { static GstElementDetails gst_mpeg2enc_details = { "mpeg2enc video encoder", "Codec/Video/Encoder", "High-quality MPEG-1/2 video encoder", "Andrew Stevens <andrew.stevens@nexgo.de>\n" - "Ronald Bultje <rbultje@ronald.bitfreak.net>" + "Ronald Bultje <rbultje@ronald.bitfreak.net>" }; GstElementClass *element_class = GST_ELEMENT_CLASS (klass); gst_element_class_add_pad_template (element_class, src_templ ()); gst_element_class_add_pad_template (element_class, sink_templ ()); - gst_element_class_set_details (element_class, - &gst_mpeg2enc_details); + gst_element_class_set_details (element_class, &gst_mpeg2enc_details); } static void -gst_mpeg2enc_class_init (GstMpeg2encClass *klass) +gst_mpeg2enc_class_init (GstMpeg2encClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass); @@ -188,32 +177,35 @@ gst_mpeg2enc_class_init (GstMpeg2encClass *klass) } static void -gst_mpeg2enc_dispose (GObject *object) +gst_mpeg2enc_dispose (GObject * object) { GstMpeg2enc *enc = GST_MPEG2ENC (object); if (enc->encoder) { delete enc->encoder; + enc->encoder = NULL; } delete enc->options; } static void -gst_mpeg2enc_init (GstMpeg2enc *enc) +gst_mpeg2enc_init (GstMpeg2enc * enc) { GstElement *element = GST_ELEMENT (enc); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); GST_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE); - enc->sinkpad = gst_pad_new_from_template ( - gst_element_class_get_pad_template (klass, "sink"), "sink"); + enc->sinkpad = + gst_pad_new_from_template (gst_element_class_get_pad_template (klass, + "sink"), "sink"); gst_pad_set_link_function (enc->sinkpad, gst_mpeg2enc_sink_link); gst_element_add_pad (element, enc->sinkpad); - enc->srcpad = gst_pad_new_from_template ( - gst_element_class_get_pad_template (klass, "src"), "src"); + enc->srcpad = + gst_pad_new_from_template (gst_element_class_get_pad_template (klass, + "src"), "src"); gst_pad_use_explicit_caps (enc->srcpad); gst_element_add_pad (element, enc->srcpad); @@ -225,7 +217,7 @@ gst_mpeg2enc_init (GstMpeg2enc *enc) } static void -gst_mpeg2enc_loop (GstElement *element) +gst_mpeg2enc_loop (GstElement * element) { GstMpeg2enc *enc = GST_MPEG2ENC (element); @@ -240,19 +232,20 @@ gst_mpeg2enc_loop (GstElement *element) if (!(caps = GST_PAD_CAPS (enc->sinkpad))) { GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), - ("format wasn't negotiated before loop function")); + ("format wasn't negotiated before loop function")); return; } /* create new encoder with these settings */ enc->encoder = new GstMpeg2Encoder (enc->options, enc->sinkpad, - caps, enc->srcpad); + caps, enc->srcpad); /* and set caps on other side */ othercaps = enc->encoder->getFormat (); if (gst_pad_set_explicit_caps (enc->srcpad, othercaps) <= 0) { GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), (NULL)); delete enc->encoder; + enc->encoder = NULL; return; } @@ -263,8 +256,7 @@ gst_mpeg2enc_loop (GstElement *element) } static GstPadLinkReturn -gst_mpeg2enc_sink_link (GstPad *pad, - const GstCaps *caps) +gst_mpeg2enc_sink_link (GstPad * pad, const GstCaps * caps) { GstMpeg2enc *enc = GST_MPEG2ENC (gst_pad_get_parent (pad)); @@ -273,6 +265,7 @@ gst_mpeg2enc_sink_link (GstPad *pad, if (enc->encoder) { delete enc->encoder; + enc->encoder = NULL; } @@ -280,25 +273,21 @@ gst_mpeg2enc_sink_link (GstPad *pad, } static void -gst_mpeg2enc_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +gst_mpeg2enc_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec) { GST_MPEG2ENC (object)->options->getProperty (prop_id, value); } static void -gst_mpeg2enc_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +gst_mpeg2enc_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec) { GST_MPEG2ENC (object)->options->setProperty (prop_id, value); } static GstElementStateReturn -gst_mpeg2enc_change_state (GstElement *element) +gst_mpeg2enc_change_state (GstElement * element) { GstMpeg2enc *enc = GST_MPEG2ENC (element); @@ -318,21 +307,14 @@ gst_mpeg2enc_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "mpeg2enc", - GST_RANK_NONE, - GST_TYPE_MPEG2ENC); + GST_RANK_NONE, GST_TYPE_MPEG2ENC); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mpeg2enc", - "High-quality MPEG-1/2 video encoder", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mpeg2enc", + "High-quality MPEG-1/2 video encoder", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) |