# HG changeset patch # User renatofilho # Date 1181841668 -3600 # Node ID 3cf3c6019e3b49f41424cbfaa1bd1272c58deae5 # Parent 312d6bc514f3260bb7832b8874217d36a4856831 [svn r757] fixed indent using GNU Style diff -r 312d6bc514f3 -r 3cf3c6019e3b gst-gmyth/concatmux/gstconcatmux.c --- a/gst-gmyth/concatmux/gstconcatmux.c Thu Jun 14 18:19:52 2007 +0100 +++ b/gst-gmyth/concatmux/gstconcatmux.c Thu Jun 14 18:21:08 2007 +0100 @@ -42,7 +42,7 @@ #include -GST_DEBUG_CATEGORY_STATIC (gst_concat_mux_debug); +GST_DEBUG_CATEGORY_STATIC(gst_concat_mux_debug); #define GST_CAT_DEFAULT gst_concat_mux_debug #define GST_TYPE_CONCAT_MUX (gst_concat_mux_get_type()) @@ -63,18 +63,18 @@ { GstElement element; - /* Caps */ + /* Caps */ GstCaps *sink_caps; - /* pad */ + /* pad */ GstPad *srcpad; GstPad *sinkpad; - /* sinkpads */ + /* sinkpads */ GSList *sinks; gint numpads; - /* offset in stream */ + /* offset in stream */ guint64 offset; guint64 timeoffset; guint64 start_time; @@ -91,85 +91,88 @@ /* elementfactory information */ static const GstElementDetails gst_concat_mux_details = -GST_ELEMENT_DETAILS ("Concat muxer", - "Codec/Muxer", - "mux concat streams", - "Renato Filho "); +GST_ELEMENT_DETAILS("Concat muxer", + "Codec/Muxer", + "mux concat streams", + "Renato Filho "); -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY - ); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d", - GST_PAD_SINK, - GST_PAD_REQUEST, - GST_STATIC_CAPS_ANY - ); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE("sink_%d", + GST_PAD_SINK, + GST_PAD_REQUEST, + GST_STATIC_CAPS_ANY); -static void gst_concat_mux_base_init (gpointer g_class); -static void gst_concat_mux_class_init (GstConcatMuxClass * klass); -static void gst_concat_mux_init (GstConcatMux * concat_mux); +static void gst_concat_mux_base_init(gpointer g_class); +static void gst_concat_mux_class_init(GstConcatMuxClass * klass); +static void gst_concat_mux_init(GstConcatMux * concat_mux); -static void gst_concat_mux_finalize (GObject * object); +static void gst_concat_mux_finalize(GObject * object); -static gboolean gst_concat_mux_handle_src_event (GstPad * pad, - GstEvent * event); -static gboolean gst_concat_mux_handle_sink_event (GstPad * pad, - GstEvent * event); +static gboolean gst_concat_mux_handle_src_event(GstPad * pad, + GstEvent * event); +static gboolean gst_concat_mux_handle_sink_event(GstPad * pad, + GstEvent * event); -static GstPad *gst_concat_mux_request_new_pad (GstElement * element, - GstPadTemplate * templ, const gchar * name); -static GstStateChangeReturn gst_concat_mux_change_state (GstElement * - element, GstStateChange transition); +static GstPad *gst_concat_mux_request_new_pad(GstElement * element, + GstPadTemplate * templ, + const gchar * name); +static GstStateChangeReturn gst_concat_mux_change_state(GstElement * element, + GstStateChange + transition); -static GstFlowReturn gst_concat_mux_chain (GstPad * pad, GstBuffer * buf); -static void gst_concat_mux_clear (GstConcatMux *mux); +static GstFlowReturn gst_concat_mux_chain(GstPad * pad, GstBuffer * buf); +static void gst_concat_mux_clear(GstConcatMux * mux); static GstElementClass *parent_class = NULL; GType -gst_concat_mux_get_type (void) +gst_concat_mux_get_type(void) { static GType concat_mux_type = 0; - if (!concat_mux_type) { - static const GTypeInfo concat_mux_info = { - sizeof (GstConcatMuxClass), - gst_concat_mux_base_init, - NULL, - (GClassInitFunc) gst_concat_mux_class_init, - NULL, - NULL, - sizeof (GstConcatMux), - 0, - (GInstanceInitFunc) gst_concat_mux_init, - }; + if (!concat_mux_type) + { + static const GTypeInfo concat_mux_info = { + sizeof(GstConcatMuxClass), + gst_concat_mux_base_init, + NULL, + (GClassInitFunc) gst_concat_mux_class_init, + NULL, + NULL, + sizeof(GstConcatMux), + 0, + (GInstanceInitFunc) gst_concat_mux_init, + }; - concat_mux_type = - g_type_register_static (GST_TYPE_ELEMENT, "GstConcatMux", - &concat_mux_info, 0); - } + concat_mux_type = + g_type_register_static(GST_TYPE_ELEMENT, "GstConcatMux", + &concat_mux_info, 0); + } return concat_mux_type; } static void -gst_concat_mux_base_init (gpointer g_class) +gst_concat_mux_base_init(gpointer g_class) { - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GstElementClass *element_class = GST_ELEMENT_CLASS(g_class); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_factory)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_factory)); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&src_factory)); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&sink_factory)); - gst_element_class_set_details (element_class, &gst_concat_mux_details); + gst_element_class_set_details(element_class, &gst_concat_mux_details); } static void -gst_concat_mux_class_init (GstConcatMuxClass * klass) +gst_concat_mux_class_init(GstConcatMuxClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; @@ -177,7 +180,7 @@ gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_peek_parent (klass); + parent_class = g_type_class_peek_parent(klass); gobject_class->finalize = gst_concat_mux_finalize; @@ -186,285 +189,304 @@ } static void -gst_concat_mux_init (GstConcatMux * concat_mux) +gst_concat_mux_init(GstConcatMux * concat_mux) { - GstElementClass *klass = GST_ELEMENT_GET_CLASS (concat_mux); + GstElementClass *klass = GST_ELEMENT_GET_CLASS(concat_mux); concat_mux->srcpad = - gst_pad_new_from_template (gst_element_class_get_pad_template (klass, - "src"), "src"); - gst_pad_set_event_function (concat_mux->srcpad, - gst_concat_mux_handle_src_event); - gst_element_add_pad (GST_ELEMENT (concat_mux), concat_mux->srcpad); + gst_pad_new_from_template(gst_element_class_get_pad_template(klass, + "src"), + "src"); + gst_pad_set_event_function(concat_mux->srcpad, + gst_concat_mux_handle_src_event); + gst_element_add_pad(GST_ELEMENT(concat_mux), concat_mux->srcpad); } static void -gst_concat_mux_finalize (GObject * object) +gst_concat_mux_finalize(GObject * object) { GstConcatMux *concat_mux; - concat_mux = GST_CONCAT_MUX (object); - gst_concat_mux_clear (GST_CONCAT_MUX (object)); + concat_mux = GST_CONCAT_MUX(object); + gst_concat_mux_clear(GST_CONCAT_MUX(object)); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS(parent_class)->finalize(object); } static void -gst_concat_mux_free_pad (gpointer data, - gpointer user_data) +gst_concat_mux_free_pad(gpointer data, gpointer user_data) { - GMutex *mux; + GMutex *mux; - mux = gst_pad_get_element_private (GST_PAD (data)); - g_mutex_unlock (mux); - g_mutex_free (mux); - gst_object_unref (GST_OBJECT (data)); + mux = gst_pad_get_element_private(GST_PAD(data)); + g_mutex_unlock(mux); + g_mutex_free(mux); + gst_object_unref(GST_OBJECT(data)); } static void -gst_concat_mux_clear (GstConcatMux *mux) +gst_concat_mux_clear(GstConcatMux * mux) { mux->resync = TRUE; mux->timeoffset = 0; mux->offset = 0; mux->negotiated = FALSE; mux->done = TRUE; - if (mux->sinks != NULL) { - g_slist_foreach (mux->sinks, gst_concat_mux_free_pad, mux); - g_slist_free (mux->sinks); - mux->sinks = NULL; - } + if (mux->sinks != NULL) + { + g_slist_foreach(mux->sinks, gst_concat_mux_free_pad, mux); + g_slist_free(mux->sinks); + mux->sinks = NULL; + } } static GstPadLinkReturn -gst_concat_mux_sinkconnect (GstPad * pad, GstPad * peer) +gst_concat_mux_sinkconnect(GstPad * pad, GstPad * peer) { gchar *pad_name = NULL; GstConcatMux *concat_mux; - concat_mux = GST_CONCAT_MUX (gst_pad_get_parent (pad)); + concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad)); - if (concat_mux->sink_caps != NULL) { - GstCaps *peer_caps = gst_pad_get_caps (peer); - GstCaps *intersect; + if (concat_mux->sink_caps != NULL) + { + GstCaps *peer_caps = gst_pad_get_caps(peer); + GstCaps *intersect; - intersect = gst_caps_intersect (concat_mux->sink_caps, peer_caps); - if (intersect == NULL) { - gst_caps_unref (peer_caps); - return GST_PAD_LINK_NOFORMAT; - } - gst_caps_unref (peer_caps); - gst_caps_unref (intersect); - } else { - concat_mux->sink_caps = gst_pad_get_caps (pad); - } + intersect = gst_caps_intersect(concat_mux->sink_caps, peer_caps); + if (intersect == NULL) + { + gst_caps_unref(peer_caps); + return GST_PAD_LINK_NOFORMAT; + } + gst_caps_unref(peer_caps); + gst_caps_unref(intersect); + } + else + { + concat_mux->sink_caps = gst_pad_get_caps(pad); + } - pad_name = gst_pad_get_name (pad); + pad_name = gst_pad_get_name(pad); - GST_DEBUG_OBJECT (concat_mux, "sinkconnect triggered on %s", pad_name); + GST_DEBUG_OBJECT(concat_mux, "sinkconnect triggered on %s", pad_name); - g_free (pad_name); + g_free(pad_name); - gst_object_unref (concat_mux); + gst_object_unref(concat_mux); return GST_PAD_LINK_OK; } static GstPad * -gst_concat_mux_request_new_pad (GstElement * element, - GstPadTemplate * templ, const gchar * req_name) +gst_concat_mux_request_new_pad(GstElement * element, + GstPadTemplate * templ, const gchar * req_name) { GstConcatMux *concat_mux; GstPad *newpad; - GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); + GstElementClass *klass = GST_ELEMENT_GET_CLASS(element); GMutex *mutex; - g_return_val_if_fail (templ != NULL, NULL); + g_return_val_if_fail(templ != NULL, NULL); - if (templ->direction != GST_PAD_SINK) { - g_warning ("concat_mux: request pad that is not a SINK pad\n"); - return NULL; - } + if (templ->direction != GST_PAD_SINK) + { + g_warning("concat_mux: request pad that is not a SINK pad\n"); + return NULL; + } - g_return_val_if_fail (GST_IS_CONCAT_MUX (element), NULL); + g_return_val_if_fail(GST_IS_CONCAT_MUX(element), NULL); - concat_mux = GST_CONCAT_MUX (element); + concat_mux = GST_CONCAT_MUX(element); - if (templ == gst_element_class_get_pad_template (klass, "sink_%d")) { - gchar *name; + if (templ == gst_element_class_get_pad_template(klass, "sink_%d")) + { + gchar *name; - /* create new pad with the name */ - name = g_strdup_printf ("sink_%02d", concat_mux->numpads); - g_debug ("NEw pad %s", name); - newpad = gst_pad_new_from_template (templ, name); - g_free (name); - concat_mux->sinks = g_slist_append (concat_mux->sinks, newpad); - g_debug ("New sink %p / %d", newpad, g_slist_length (concat_mux->sinks)); - concat_mux->numpads++; - } else { - g_warning ("concat_mux: this is not our template!\n"); - return NULL; - } + /* create new pad with the name */ + name = g_strdup_printf("sink_%02d", concat_mux->numpads); + g_debug("NEw pad %s", name); + newpad = gst_pad_new_from_template(templ, name); + g_free(name); + concat_mux->sinks = g_slist_append(concat_mux->sinks, newpad); + g_debug("New sink %p / %d", newpad, g_slist_length(concat_mux->sinks)); + concat_mux->numpads++; + } + else + { + g_warning("concat_mux: this is not our template!\n"); + return NULL; + } - mutex = g_mutex_new (); + mutex = g_mutex_new(); - if (concat_mux->sinkpad == NULL) { - concat_mux->sinkpad = newpad; - } - else { - g_mutex_lock (mutex); - } + if (concat_mux->sinkpad == NULL) + { + concat_mux->sinkpad = newpad; + } + else + { + g_mutex_lock(mutex); + } - gst_pad_set_element_private (newpad, mutex); - /* setup some pad functions */ - gst_pad_set_link_function (newpad, gst_concat_mux_sinkconnect); - gst_pad_set_event_function (newpad, gst_concat_mux_handle_sink_event); - gst_pad_set_chain_function (newpad, gst_concat_mux_chain); + gst_pad_set_element_private(newpad, mutex); + /* setup some pad functions */ + gst_pad_set_link_function(newpad, gst_concat_mux_sinkconnect); + gst_pad_set_event_function(newpad, gst_concat_mux_handle_sink_event); + gst_pad_set_chain_function(newpad, gst_concat_mux_chain); - /* add the pad to the element */ - gst_element_add_pad (element, newpad); + /* add the pad to the element */ + gst_element_add_pad(element, newpad); return newpad; } /* handle events */ static gboolean -gst_concat_mux_handle_src_event (GstPad * pad, GstEvent * event) +gst_concat_mux_handle_src_event(GstPad * pad, GstEvent * event) { GstConcatMux *concat_mux; GstEventType type; - concat_mux = GST_CONCAT_MUX (gst_pad_get_parent (pad)); + concat_mux = GST_CONCAT_MUX(gst_pad_get_parent(pad)); - type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; + type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN; - switch (type) { - case GST_EVENT_SEEK: - /* disable seeking for now */ - return FALSE; - default: - break; - } + switch (type) + { + case GST_EVENT_SEEK: + /* disable seeking for now */ + return FALSE; + default: + break; + } - gst_object_unref (concat_mux); + gst_object_unref(concat_mux); - return gst_pad_event_default (pad, event); + return gst_pad_event_default(pad, event); } /* handle events */ static gboolean -gst_concat_mux_handle_sink_event (GstPad * pad, GstEvent * event) +gst_concat_mux_handle_sink_event(GstPad * pad, GstEvent * event) { GstConcatMux *mux; GstEventType type; - mux = GST_CONCAT_MUX (gst_pad_get_parent (pad)); + mux = GST_CONCAT_MUX(gst_pad_get_parent(pad)); - type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN; + type = event ? GST_EVENT_TYPE(event) : GST_EVENT_UNKNOWN; - switch (type) { - case GST_EVENT_EOS: - { - mux->resync = TRUE; - g_debug ("sink EOS %p / %d", pad, g_slist_length (mux->sinks)); - /* mark pad eos */ - mux->sinks = g_slist_remove (mux->sinks, pad); - g_debug ("sink len %d", g_slist_length (mux->sinks)); - if (g_slist_length (mux->sinks) != 0) { - GMutex *mutex; - mux->sinkpad = mux->sinks->data; - mutex = (GMutex *) gst_pad_get_element_private (mux->sinkpad); - g_mutex_unlock (mutex); - g_debug ("sink pad %p", mux->sinkpad); - return TRUE; - } + switch (type) + { + case GST_EVENT_EOS: + { + mux->resync = TRUE; + g_debug("sink EOS %p / %d", pad, g_slist_length(mux->sinks)); + /* mark pad eos */ + mux->sinks = g_slist_remove(mux->sinks, pad); + g_debug("sink len %d", g_slist_length(mux->sinks)); + if (g_slist_length(mux->sinks) != 0) + { + GMutex *mutex; + mux->sinkpad = mux->sinks->data; + mutex = (GMutex *) gst_pad_get_element_private(mux->sinkpad); + g_mutex_unlock(mutex); + g_debug("sink pad %p", mux->sinkpad); + return TRUE; + } - g_debug ("sink list is empty"); - } - default: - break; - } + g_debug("sink list is empty"); + } + default: + break; + } - gst_object_unref (mux); + gst_object_unref(mux); - return gst_pad_event_default (pad, event); + return gst_pad_event_default(pad, event); } static GstFlowReturn -gst_concat_mux_chain (GstPad * pad, GstBuffer * buf) +gst_concat_mux_chain(GstPad * pad, GstBuffer * buf) { - GstConcatMux *mux = (GstConcatMux *) GST_PAD_PARENT (pad); + GstConcatMux *mux = (GstConcatMux *) GST_PAD_PARENT(pad); GstBuffer *databuf = NULL; GstFlowReturn ret = GST_FLOW_OK; GMutex *mutex; - mutex = (GMutex*) gst_pad_get_element_private (pad); + mutex = (GMutex *) gst_pad_get_element_private(pad); - g_mutex_lock (mutex); - if (mux->done) { - g_debug ("DONE pad %p", pad); - g_mutex_unlock (mutex); - return GST_FLOW_OK; - } + g_mutex_lock(mutex); + if (mux->done) + { + g_debug("DONE pad %p", pad); + g_mutex_unlock(mutex); + return GST_FLOW_OK; + } - databuf = gst_buffer_make_metadata_writable (buf); + databuf = gst_buffer_make_metadata_writable(buf); - if (!mux->negotiated) { - /* - GstCaps *newcaps; - newcaps = gst_pad_get_caps (mux->sinkpad); + if (!mux->negotiated) + { + /* + GstCaps *newcaps; + newcaps = gst_pad_get_caps (mux->sinkpad); - g_debug ("CAPS: %s",gst_caps_to_string (newcaps)); + g_debug ("CAPS: %s",gst_caps_to_string (newcaps)); - if (!gst_pad_set_caps (mux->srcpad, newcaps)) - goto nego_error; - */ - mux->negotiated = TRUE; - } + if (!gst_pad_set_caps (mux->srcpad, newcaps)) + goto nego_error; + */ + mux->negotiated = TRUE; + } - /* - g_debug ("Running [%s]\n" - "\tTOFFSET [%"G_GUINT64_FORMAT"]\n" - "\tB_TSTAMP [%"G_GUINT64_FORMAT"]\n" - "\tB_DURATION [%"G_GUINT64_FORMAT"]\n" - "\tOFFSET [%"G_GUINT64_FORMAT"]\n" - "\tB_OFFSET [%"G_GUINT64_FORMAT"]", - gst_element_get_name (mux), - mux->timeoffset, - GST_BUFFER_TIMESTAMP (databuf), - GST_BUFFER_DURATION (databuf), - mux->offset, - GST_BUFFER_OFFSET (databuf)); - */ + /* + g_debug ("Running [%s]\n" + "\tTOFFSET [%"G_GUINT64_FORMAT"]\n" + "\tB_TSTAMP [%"G_GUINT64_FORMAT"]\n" + "\tB_DURATION [%"G_GUINT64_FORMAT"]\n" + "\tOFFSET [%"G_GUINT64_FORMAT"]\n" + "\tB_OFFSET [%"G_GUINT64_FORMAT"]", + gst_element_get_name (mux), + mux->timeoffset, + GST_BUFFER_TIMESTAMP (databuf), + GST_BUFFER_DURATION (databuf), + mux->offset, + GST_BUFFER_OFFSET (databuf)); + */ - if (mux->resync) { - g_debug ("RESYNC [%s]", gst_element_get_name (mux)); - mux->timeoffset += GST_BUFFER_TIMESTAMP (databuf); - GST_BUFFER_TIMESTAMP (databuf) = mux->timeoffset; - mux->timeoffset += GST_BUFFER_DURATION (databuf); + if (mux->resync) + { + g_debug("RESYNC [%s]", gst_element_get_name(mux)); + mux->timeoffset += GST_BUFFER_TIMESTAMP(databuf); + GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset; + mux->timeoffset += GST_BUFFER_DURATION(databuf); - mux->offset += GST_BUFFER_OFFSET (databuf); - GST_BUFFER_OFFSET (databuf) = mux->offset; - mux->offset += GST_BUFFER_SIZE (databuf); - mux->resync = FALSE; - } else { + mux->offset += GST_BUFFER_OFFSET(databuf); + GST_BUFFER_OFFSET(databuf) = mux->offset; + mux->offset += GST_BUFFER_SIZE(databuf); + mux->resync = FALSE; + } + else + { - GST_BUFFER_TIMESTAMP (databuf) = mux->timeoffset; - mux->timeoffset += GST_BUFFER_DURATION (databuf); + GST_BUFFER_TIMESTAMP(databuf) = mux->timeoffset; + mux->timeoffset += GST_BUFFER_DURATION(databuf); - GST_BUFFER_OFFSET (databuf) = mux->offset; - mux->offset += GST_BUFFER_SIZE (databuf); - } + GST_BUFFER_OFFSET(databuf) = mux->offset; + mux->offset += GST_BUFFER_SIZE(databuf); + } - gst_buffer_set_caps (databuf, GST_PAD_CAPS (pad)); - ret = gst_pad_push (mux->srcpad, databuf); + gst_buffer_set_caps(databuf, GST_PAD_CAPS(pad)); + ret = gst_pad_push(mux->srcpad, databuf); - //gst_buffer_unref (buf); + //gst_buffer_unref (buf); - g_mutex_unlock (mutex); + g_mutex_unlock(mutex); return ret; /* nego_error: @@ -474,69 +496,71 @@ return GST_FLOW_NOT_NEGOTIATED; } */ - /* -no_caps: - { + /* + no_caps: + { GST_WARNING_OBJECT (mux, "no caps on the incoming buffer %p", best->buffer); GST_ELEMENT_ERROR (mux, CORE, NEGOTIATION, (NULL), (NULL)); ret = GST_FLOW_NOT_NEGOTIATED; goto beach; - } + } */ } static GstStateChangeReturn -gst_concat_mux_change_state (GstElement * element, GstStateChange transition) +gst_concat_mux_change_state(GstElement * element, GstStateChange transition) { GstConcatMux *concat_mux; GstStateChangeReturn ret; - concat_mux = GST_CONCAT_MUX (element); + concat_mux = GST_CONCAT_MUX(element); - switch (transition) { - case GST_STATE_CHANGE_READY_TO_PAUSED: - concat_mux->done = FALSE; - concat_mux->resync = TRUE; - GST_DEBUG_OBJECT (concat_mux, "starting collect pads"); - break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - GST_DEBUG_OBJECT (concat_mux, "stopping collect pads"); - gst_concat_mux_clear (concat_mux); - break; - default: - break; - } + switch (transition) + { + case GST_STATE_CHANGE_READY_TO_PAUSED: + concat_mux->done = FALSE; + concat_mux->resync = TRUE; + GST_DEBUG_OBJECT(concat_mux, "starting collect pads"); + break; + case GST_STATE_CHANGE_PAUSED_TO_READY: + GST_DEBUG_OBJECT(concat_mux, "stopping collect pads"); + gst_concat_mux_clear(concat_mux); + break; + default: + break; + } - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition); if (ret == GST_STATE_CHANGE_FAILURE) - return ret; + return ret; - switch (transition) { - default: - break; - } + switch (transition) + { + default: + break; + } return ret; } gboolean -gst_concat_mux_plugin_init (GstPlugin * plugin) +gst_concat_mux_plugin_init(GstPlugin * plugin) { #ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); #endif /* ENABLE_NLS */ - GST_DEBUG_CATEGORY_INIT (gst_concat_mux_debug, "concatmux", 0, - "concat muxer"); - - return gst_element_register (plugin, "concatmux", GST_RANK_NONE, - GST_TYPE_CONCAT_MUX); + GST_DEBUG_CATEGORY_INIT(gst_concat_mux_debug, "concatmux", 0, + "concat muxer"); + + return gst_element_register(plugin, "concatmux", GST_RANK_NONE, + GST_TYPE_CONCAT_MUX); } -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "concatmux", - "Concat streamers", - gst_concat_mux_plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) - +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "concatmux", + "Concat streamers", + gst_concat_mux_plugin_init, VERSION, GST_LICENSE, + GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff -r 312d6bc514f3 -r 3cf3c6019e3b gst-gmyth/mythsrc/gstmythtvsrc.c --- a/gst-gmyth/mythsrc/gstmythtvsrc.c Thu Jun 14 18:19:52 2007 +0100 +++ b/gst-gmyth/mythsrc/gstmythtvsrc.c Thu Jun 14 18:21:08 2007 +0100 @@ -84,7 +84,7 @@ #include #include -GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug); +GST_DEBUG_CATEGORY_STATIC(mythtvsrc_debug); #define GST_CAT_DEFAULT mythtvsrc_debug #define GST_GMYTHTV_ID_NUM 1 @@ -108,17 +108,17 @@ #define INTERNAL_BUFFER_SIZE (90*1024) static const GstElementDetails gst_mythtv_src_details = -GST_ELEMENT_DETAILS ("MythTV client source", - "Source/Network", - "Control and receive data as a client over the network " - "via raw socket connections using the MythTV protocol", - "Rosfran Borges "); +GST_ELEMENT_DETAILS("MythTV client source", + "Source/Network", + "Control and receive data as a client over the network " + "via raw socket connections using the MythTV protocol", + "Rosfran Borges "); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY ); - /* GST_STATIC_CAPS ("video/x-nuv")); */ +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + /* GST_STATIC_CAPS ("video/x-nuv")); */ enum { @@ -136,71 +136,73 @@ PROP_GMYTHTV_MAX_TRY }; -static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src); +static void gst_mythtv_src_clear(GstMythtvSrc * mythtv_src); -static void gst_mythtv_src_finalize (GObject * gobject); +static void gst_mythtv_src_finalize(GObject * gobject); -static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc, - GstBuffer ** outbuf); +static GstFlowReturn gst_mythtv_src_create(GstPushSrc * psrc, + GstBuffer ** outbuf); -static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc); -static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc); -static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size); -static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src); +static gboolean gst_mythtv_src_start(GstBaseSrc * bsrc); +static gboolean gst_mythtv_src_stop(GstBaseSrc * bsrc); +static gboolean gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size); +static gboolean gst_mythtv_src_is_seekable(GstBaseSrc * push_src); -static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base, - GstSegment * segment); +static gboolean gst_mythtv_src_do_seek(GstBaseSrc * base, + GstSegment * segment); static GstStateChangeReturn -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition); +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition); -static void gst_mythtv_src_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_mythtv_src_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static void gst_mythtv_src_set_property(GObject * object, guint prop_id, + const GValue * value, + GParamSpec * pspec); +static void gst_mythtv_src_get_property(GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_mythtv_src_uri_handler_init (gpointer g_iface, - gpointer iface_data); +static void gst_mythtv_src_uri_handler_init(gpointer g_iface, + gpointer iface_data); -static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query); +static gboolean gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query); -static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); +static gboolean gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event); -static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size, - GByteArray * data_ptr); +static GMythFileReadResult do_read_request_response(GstMythtvSrc * src, + guint size, + GByteArray * data_ptr); static void -_urihandler_init (GType type) +_urihandler_init(GType type) { static const GInterfaceInfo urihandler_info = { - gst_mythtv_src_uri_handler_init, - NULL, - NULL + gst_mythtv_src_uri_handler_init, + NULL, + NULL }; - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); + g_type_add_interface_static(type, GST_TYPE_URI_HANDLER, &urihandler_info); - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src"); + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, "MythTV src"); } -GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc, - GST_TYPE_PUSH_SRC, _urihandler_init) +GST_BOILERPLATE_FULL(GstMythtvSrc, gst_mythtv_src, GstPushSrc, + GST_TYPE_PUSH_SRC, _urihandler_init) + static void gst_mythtv_src_base_init(gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS(g_class); - static void gst_mythtv_src_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 + (&srctemplate)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&srctemplate)); - - gst_element_class_set_details (element_class, &gst_mythtv_src_details); + gst_element_class_set_details(element_class, &gst_mythtv_src_details); element_class->change_state = gst_mythtv_src_change_state; } static void -gst_mythtv_src_class_init (GstMythtvSrcClass * klass) +gst_mythtv_src_class_init(GstMythtvSrcClass * klass) { GObjectClass *gobject_class; GstPushSrcClass *gstpushsrc_class; @@ -215,60 +217,64 @@ gobject_class->finalize = gst_mythtv_src_finalize; g_object_class_install_property - (gobject_class, PROP_LOCATION, - g_param_spec_string ("location", "Location", - "The location. In the form:" - "\n\t\t\tmyth://a.com/file.nuv" - "\n\t\t\tmyth://a.com:23223/file.nuv " - "\n\t\t\ta.com/file.nuv - default scheme 'myth'", - "", G_PARAM_READWRITE)); + (gobject_class, PROP_LOCATION, + g_param_spec_string("location", "Location", + "The location. In the form:" + "\n\t\t\tmyth://a.com/file.nuv" + "\n\t\t\tmyth://a.com:23223/file.nuv " + "\n\t\t\ta.com/file.nuv - default scheme 'myth'", + "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_VERSION, - g_param_spec_int ("mythtv-version", "mythtv-version", - "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_VERSION, + g_param_spec_int("mythtv-version", "mythtv-version", + "Change MythTV version", 26, 30, 26, + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVEID, - g_param_spec_int ("mythtv-live-id", "mythtv-live-id", - "Change MythTV version", - 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVEID, + g_param_spec_int("mythtv-live-id", "mythtv-live-id", + "Change MythTV version", + 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, - g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid", - "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, + g_param_spec_string("mythtv-live-chainid", "mythtv-live-chainid", + "Sets the MythTV chain ID (from TV Chain)", "", + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_LIVE, - g_param_spec_boolean ("mythtv-live", "mythtv-live", - "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_LIVE, + g_param_spec_boolean("mythtv-live", "mythtv-live", + "Enable MythTV Live TV content streaming", FALSE, + G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION, - g_param_spec_boolean ("mythtv-enable-timing-position", - "mythtv-enable-timing-position", - "Enable MythTV Live TV content size continuous updating", FALSE, - G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION, + g_param_spec_boolean("mythtv-enable-timing-position", + "mythtv-enable-timing-position", + "Enable MythTV Live TV content size continuous updating", + FALSE, G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, - g_param_spec_string ("mythtv-channel", "mythtv-channel", - "Change MythTV channel number", - "", G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, + g_param_spec_string("mythtv-channel", "mythtv-channel", + "Change MythTV channel number", + "", G_PARAM_READWRITE)); g_object_class_install_property - (gobject_class, PROP_GMYTHTV_MAX_TRY, - g_param_spec_int ("max-try", "max-try", - "Set the max try for get MythTV free recorder", - 0, G_MAXINT, 10, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_MAX_TRY, + g_param_spec_int("max-try", "max-try", + "Set the max try for get MythTV free recorder", + 0, G_MAXINT, 10, G_PARAM_READWRITE)); #ifndef GST_DISABLE_GST_DEBUG g_object_class_install_property - (gobject_class, PROP_GMYTHTV_DBG, - g_param_spec_boolean ("mythtv-debug", "mythtv-debug", - "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE)); + (gobject_class, PROP_GMYTHTV_DBG, + g_param_spec_boolean("mythtv-debug", "mythtv-debug", + "Enable MythTV debug messages", FALSE, + G_PARAM_READWRITE)); #endif gstbasesrc_class->start = gst_mythtv_src_start; @@ -279,12 +285,12 @@ gstbasesrc_class->do_seek = gst_mythtv_src_do_seek; gstpushsrc_class->create = gst_mythtv_src_create; - GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, - "MythTV Client Source"); + GST_DEBUG_CATEGORY_INIT(mythtvsrc_debug, "mythtvsrc", 0, + "MythTV Client Source"); } static void -gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class) +gst_mythtv_src_init(GstMythtvSrc * this, GstMythtvSrcClass * g_class) { this->file = NULL; @@ -308,7 +314,7 @@ this->enable_timing_position = FALSE; this->update_prog_chain = FALSE; - this->user_agent = g_strdup ("mythtvsrc"); + this->user_agent = g_strdup("mythtvsrc"); this->update_prog_chain = FALSE; this->channel_name = NULL; @@ -319,114 +325,132 @@ this->wait_to_transfer = 0; - gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES); + gst_base_src_set_format(GST_BASE_SRC(this), GST_FORMAT_BYTES); - gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)), - gst_mythtv_src_handle_event); - gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)), - gst_mythtv_src_handle_query); + gst_pad_set_event_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)), + gst_mythtv_src_handle_event); + gst_pad_set_query_function(GST_BASE_SRC_PAD(GST_BASE_SRC(this)), + gst_mythtv_src_handle_query); } static void -gst_mythtv_src_clear (GstMythtvSrc *mythtv_src) +gst_mythtv_src_clear(GstMythtvSrc * mythtv_src) { mythtv_src->unique_setup = FALSE; - if (mythtv_src->spawn_livetv) { - g_object_unref (mythtv_src->spawn_livetv); - mythtv_src->spawn_livetv = NULL; - } + if (mythtv_src->spawn_livetv) + { + g_object_unref(mythtv_src->spawn_livetv); + mythtv_src->spawn_livetv = NULL; + } - if (mythtv_src->file) { - g_object_unref (mythtv_src->file); - mythtv_src->file = NULL; - } + if (mythtv_src->file) + { + g_object_unref(mythtv_src->file); + mythtv_src->file = NULL; + } - if (mythtv_src->backend_info) { - g_object_unref (mythtv_src->backend_info); - mythtv_src->backend_info = NULL; - } + if (mythtv_src->backend_info) + { + g_object_unref(mythtv_src->backend_info); + mythtv_src->backend_info = NULL; + } - if (mythtv_src->bytes_queue) { - g_byte_array_free (mythtv_src->bytes_queue, TRUE); - mythtv_src->bytes_queue = NULL; - } + if (mythtv_src->bytes_queue) + { + g_byte_array_free(mythtv_src->bytes_queue, TRUE); + mythtv_src->bytes_queue = NULL; + } } static void -gst_mythtv_src_finalize (GObject * gobject) +gst_mythtv_src_finalize(GObject * gobject) { - GstMythtvSrc *this = GST_MYTHTV_SRC (gobject); + GstMythtvSrc *this = GST_MYTHTV_SRC(gobject); - gst_mythtv_src_clear (this); + gst_mythtv_src_clear(this); - if (this->uri_name) { - g_free (this->uri_name); - this->uri_name = NULL; - } + if (this->uri_name) + { + g_free(this->uri_name); + this->uri_name = NULL; + } - if (this->user_agent) { - g_free (this->user_agent); - this->user_agent = NULL; - } + if (this->user_agent) + { + g_free(this->user_agent); + this->user_agent = NULL; + } - G_OBJECT_CLASS (parent_class)->finalize (gobject); + G_OBJECT_CLASS(parent_class)->finalize(gobject); } static GMythFileReadResult -do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr) +do_read_request_response(GstMythtvSrc * src, guint size, + GByteArray * data_ptr) { gint read = 0; guint sizetoread = size; gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS; GMythFileReadResult result; - GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread); + GST_LOG_OBJECT(src, "Starting: Reading %d bytes...", sizetoread); - /* Loop sending the Myth File Transfer request: - * Retry whilst authentication fails and we supply it. */ + /* Loop sending the Myth File Transfer request: + * Retry whilst authentication fails and we supply it. */ - while (sizetoread == size && --max_iters > 0) { - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ - if ( IS_GMYTH_FILE_LOCAL(src->file) ) - result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file), - data_ptr, sizetoread, src->live_tv); - else if ( IS_GMYTH_FILE_TRANSFER(src->file) ) - result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file), - data_ptr, sizetoread, src->live_tv ); + while (sizetoread == size && --max_iters > 0) + { + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ + if (IS_GMYTH_FILE_LOCAL(src->file)) + result = gmyth_file_local_read(GMYTH_FILE_LOCAL(src->file), + data_ptr, sizetoread, src->live_tv); + else if (IS_GMYTH_FILE_TRANSFER(src->file)) + result = gmyth_file_transfer_read(GMYTH_FILE_TRANSFER(src->file), + data_ptr, sizetoread, src->live_tv); - if (data_ptr->len > 0) { - read += data_ptr->len; - sizetoread -= data_ptr->len; - } else if (data_ptr->len <= 0) { - if (src->live_tv == FALSE) { - result = GMYTH_FILE_READ_EOF; - goto eos; - } else { - if (result == GMYTH_FILE_READ_ERROR) { /* -314 */ - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!"); - goto done; - } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */ - GST_INFO_OBJECT (src, - "[LiveTV] FileTransfer - Go to athe next program chain!"); - src->update_prog_chain = TRUE; - continue; - } - goto done; - } + if (data_ptr->len > 0) + { + read += data_ptr->len; + sizetoread -= data_ptr->len; + } + else if (data_ptr->len <= 0) + { + if (src->live_tv == FALSE) + { + result = GMYTH_FILE_READ_EOF; + goto eos; + } + else + { + if (result == GMYTH_FILE_READ_ERROR) + { /* -314 */ + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer READ_ERROR!"); + goto done; + } + else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) + { /* -315 */ + GST_INFO_OBJECT(src, + "[LiveTV] FileTransfer - Go to athe next program chain!"); + src->update_prog_chain = TRUE; + continue; + } + goto done; + } - } /* else if (data_ptr->len == 0) - goto done;*/ + } /* else if (data_ptr->len == 0) + goto done; */ - if (read == sizetoread) - goto done; - } + if (read == sizetoread) + goto done; + } - if ((read < 0 && !src->live_tv) || max_iters == 0) { - result = GMYTH_FILE_READ_EOF; - goto eos; - } + if ((read < 0 && !src->live_tv) || max_iters == 0) + { + result = GMYTH_FILE_READ_EOF; + goto eos; + } goto done; @@ -438,471 +462,532 @@ } static GstFlowReturn -gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) +gst_mythtv_src_create(GstPushSrc * psrc, GstBuffer ** outbuf) { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; guint buffer_size_inter = 0; - src = GST_MYTHTV_SRC (psrc); + src = GST_MYTHTV_SRC(psrc); - /* The caller should know the number of bytes and not read beyond EOS. */ - if (G_UNLIKELY (src->eos)) - goto eos; - GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...", - src->read_offset, MAX_READ_SIZE); + /* The caller should know the number of bytes and not read beyond EOS. */ + if (G_UNLIKELY(src->eos)) + goto eos; + GST_DEBUG_OBJECT(src, "offset = %" G_GUINT64_FORMAT ", size = %d...", + src->read_offset, MAX_READ_SIZE); - GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.", - (gint) src->buffer_remain, src->bytes_queue->len); + GST_DEBUG_OBJECT(src, "Create: buffer_remain: %d, buffer_size = %d.", + (gint) src->buffer_remain, src->bytes_queue->len); program_chain_changed: - /* just get from the byte array, no network effort... */ - if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) { - GByteArray *buffer; - GMythFileReadResult result = GMYTH_FILE_READ_OK; - - buffer = NULL; - buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain); + /* just get from the byte array, no network effort... */ + if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) + { + GByteArray *buffer; + GMythFileReadResult result = GMYTH_FILE_READ_OK; - if (buffer_size_inter > REQUEST_MAX_SIZE) - buffer_size_inter = REQUEST_MAX_SIZE; + buffer = NULL; + buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain); - buffer = g_byte_array_new (); + if (buffer_size_inter > REQUEST_MAX_SIZE) + buffer_size_inter = REQUEST_MAX_SIZE; - result = do_read_request_response (src, buffer_size_inter, buffer); + buffer = g_byte_array_new(); - /* got the next program info? */ - if (G_UNLIKELY (src->update_prog_chain) || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) { - GST_DEBUG_OBJECT (src, "Update PROGRAM CHAIN!!! buffer_size = %d.", - src->bytes_queue->len); - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, NULL)); + result = do_read_request_response(src, buffer_size_inter, buffer); + + /* got the next program info? */ + if (G_UNLIKELY(src->update_prog_chain) + || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) + { + GST_DEBUG_OBJECT(src, "Update PROGRAM CHAIN!!! buffer_size = %d.", + src->bytes_queue->len); + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)), + gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM, + NULL)); /* gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); */ - src->update_prog_chain = FALSE; - src->eos = FALSE; + src->update_prog_chain = FALSE; + src->eos = FALSE; - if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { - /* - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - goto program_chain_changed; */ - } else if (result == GMYTH_FILE_READ_OK) { - /* remove wasteful, NUV file header data */ - /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */ - /* TODO: need to send a new segment event to NUVDemux? */ - //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); + if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) + { + /* + if (buffer != NULL) { + g_byte_array_free (buffer, TRUE); + buffer = NULL; + } + goto program_chain_changed; */ + } + else if (result == GMYTH_FILE_READ_OK) + { + /* remove wasteful, NUV file header data */ + /* buffer = g_byte_array_remove_range( buffer, 0, 512 ); */ + /* TODO: need to send a new segment event to NUVDemux? */ + //gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), + // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0)); - /* goto change_progchain; */ - } + /* goto change_progchain; */ + } - } /* */ + } /* */ - if (G_UNLIKELY (buffer->len < 0)) { - - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - - if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN )) - goto change_progchain; - else - goto read_error; - } else if (G_UNLIKELY (buffer->len == 0)) { - - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } - - if (!src->live_tv) - goto done; - else - goto program_chain_changed; - } + if (G_UNLIKELY(buffer->len < 0)) + { - src->bytes_queue = - g_byte_array_append (src->bytes_queue, buffer->data, buffer->len); - if (buffer->len > buffer_size_inter) - GST_WARNING_OBJECT (src, - "INCREASED buffer size! Backend sent more than we ask him... (%d)", - abs (buffer->len - buffer_size_inter)); + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } - src->buffer_remain += buffer->len; + if (src->live_tv || (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN)) + goto change_progchain; + else + goto read_error; + } + else if (G_UNLIKELY(buffer->len == 0)) + { - if (buffer != NULL) { - g_byte_array_free (buffer, TRUE); - buffer = NULL; - } + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } - /* - GST_DEBUG_OBJECT (src, - "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, " - "OFFSET = %llu, CONTENT SIZE = %llu.", read, - src->bytes_read, src->read_offset, src->content_size); - */ - } + if (!src->live_tv) + goto done; + else + goto program_chain_changed; + } + + src->bytes_queue = + g_byte_array_append(src->bytes_queue, buffer->data, buffer->len); + if (buffer->len > buffer_size_inter) + GST_WARNING_OBJECT(src, + "INCREASED buffer size! Backend sent more than we ask him... (%d)", + abs(buffer->len - buffer_size_inter)); + + src->buffer_remain += buffer->len; + + if (buffer != NULL) + { + g_byte_array_free(buffer, TRUE); + buffer = NULL; + } + + /* + GST_DEBUG_OBJECT (src, + "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, " + "OFFSET = %llu, CONTENT SIZE = %llu.", read, + src->bytes_read, src->read_offset, src->content_size); + */ + } guint buffer_size = - (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; + (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; - *outbuf = gst_buffer_new (); + *outbuf = gst_buffer_new(); - /* - GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d", - (buffer_size_inter == - 0) ? "NO, got from buffer" : "YES, go see the backend's log file", - src->buffer_remain); - */ + /* + GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d", + (buffer_size_inter == + 0) ? "NO, got from buffer" : "YES, go see the backend's log file", + src->buffer_remain); + */ - GST_BUFFER_SIZE (*outbuf) = buffer_size; - GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf)); - GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf); - g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data, - GST_BUFFER_SIZE (*outbuf)); - GST_BUFFER_OFFSET (*outbuf) = src->read_offset; - GST_BUFFER_OFFSET_END (*outbuf) = - src->read_offset + GST_BUFFER_SIZE (*outbuf); + GST_BUFFER_SIZE(*outbuf) = buffer_size; + GST_BUFFER_MALLOCDATA(*outbuf) = g_malloc0(GST_BUFFER_SIZE(*outbuf)); + GST_BUFFER_DATA(*outbuf) = GST_BUFFER_MALLOCDATA(*outbuf); + g_memmove(GST_BUFFER_DATA((*outbuf)), src->bytes_queue->data, + GST_BUFFER_SIZE(*outbuf)); + GST_BUFFER_OFFSET(*outbuf) = src->read_offset; + GST_BUFFER_OFFSET_END(*outbuf) = + src->read_offset + GST_BUFFER_SIZE(*outbuf); - src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); + src->buffer_remain -= GST_BUFFER_SIZE(*outbuf); - src->read_offset += GST_BUFFER_SIZE (*outbuf); - src->bytes_read += GST_BUFFER_SIZE (*outbuf); - //GST_DEBUG_OBJECT (src, "Buffer output with size: %d", - // GST_BUFFER_SIZE (*outbuf)); + src->read_offset += GST_BUFFER_SIZE(*outbuf); + src->bytes_read += GST_BUFFER_SIZE(*outbuf); + //GST_DEBUG_OBJECT (src, "Buffer output with size: %d", + // GST_BUFFER_SIZE (*outbuf)); - /* flushs the newly buffer got from byte array */ + /* flushs the newly buffer got from byte array */ src->bytes_queue = - g_byte_array_remove_range (src->bytes_queue, 0, buffer_size); + g_byte_array_remove_range(src->bytes_queue, 0, buffer_size); - if ( G_UNLIKELY (src->eos) || ( !src->live_tv - && ( src->bytes_read >= src->content_size ) ) ) - goto eos; + if (G_UNLIKELY(src->eos) || (!src->live_tv + && (src->bytes_read >= src->content_size))) + goto eos; done: { - const gchar *reason = gst_flow_get_name (ret); - return ret; + const gchar *reason = gst_flow_get_name(ret); + return ret; } eos: { - const gchar *reason = gst_flow_get_name (ret); + const gchar *reason = gst_flow_get_name(ret); - GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason); - return GST_FLOW_UNEXPECTED; + GST_DEBUG_OBJECT(src, "pausing task, reason %s", reason); + return GST_FLOW_UNEXPECTED; } - /* ERRORS */ + /* ERRORS */ read_error: { - GST_ELEMENT_ERROR (src, RESOURCE, READ, - (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name)); - return GST_FLOW_ERROR; + GST_ELEMENT_ERROR(src, RESOURCE, READ, + (NULL), ("Could not read any bytes (%i, %s)", read, + src->uri_name)); + return GST_FLOW_ERROR; } change_progchain: { - GST_ELEMENT_ERROR (src, RESOURCE, READ, - (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, - src->uri_name)); + GST_ELEMENT_ERROR(src, RESOURCE, READ, + (NULL), + ("Seek failed, go to the next program info... (%i, %s)", + read, src->uri_name)); /* TODO: need to send a new segment event to NUVDemux? */ - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0)); + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(psrc)), + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME, + 0, -1, 0)); - goto program_chain_changed; + goto program_chain_changed; } } gint64 -gst_mythtv_src_get_position (GstMythtvSrc * src) +gst_mythtv_src_get_position(GstMythtvSrc * src) { gint64 size_tmp = 0; guint max_tries = 2; - if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) < - GMYTHTV_TRANSFER_MAX_BUFFER)) { + if (src->live_tv == TRUE && (abs(src->content_size - src->bytes_read) < + GMYTHTV_TRANSFER_MAX_BUFFER)) + { - get_file_pos: - g_usleep (10); - size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder); - if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER)) - src->content_size = size_tmp; - else if (size_tmp > 0 && --max_tries > 0) - goto get_file_pos; - GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp); - /* sets the last content size amount before it can be updated */ - src->prev_content_size = src->content_size; - } + get_file_pos: + g_usleep(10); + size_tmp = + gmyth_recorder_get_file_position(src->spawn_livetv->recorder); + if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER)) + src->content_size = size_tmp; + else if (size_tmp > 0 && --max_tries > 0) + goto get_file_pos; + GST_LOG_OBJECT(src, "GET_POSITION: file_position = %lld", size_tmp); + /* sets the last content size amount before it can be updated */ + src->prev_content_size = src->content_size; + } return src->content_size; } static gboolean -gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment) +gst_mythtv_src_do_seek(GstBaseSrc * base, GstSegment * segment) { - GstMythtvSrc *src = GST_MYTHTV_SRC (base); + GstMythtvSrc *src = GST_MYTHTV_SRC(base); gint64 new_offset = -1; gint64 actual_seek = segment->start; gboolean ret = TRUE; - GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment); + GST_LOG_OBJECT(src, "seek, segment: %" GST_SEGMENT_FORMAT, segment); - if (segment->format == GST_FORMAT_TIME) { - goto done; - } - GST_LOG_OBJECT (src, - "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)", - actual_seek, src->read_offset); - /* verify if it needs to seek */ - if (src->read_offset != actual_seek) { - - /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ - if ( IS_GMYTH_FILE_LOCAL(src->file) ) - new_offset = - gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET); - else if ( IS_GMYTH_FILE_TRANSFER(src->file) ) - new_offset = - gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET); + if (segment->format == GST_FORMAT_TIME) + { + goto done; + } + GST_LOG_OBJECT(src, + "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)", + actual_seek, src->read_offset); + /* verify if it needs to seek */ + if (src->read_offset != actual_seek) + { - GST_LOG_OBJECT (src, - "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.", - segment->start, src->read_offset, new_offset); - if (G_UNLIKELY (new_offset < 0)) { - ret = FALSE; - if (!src->live_tv) - goto eos; - } + /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */ + if (IS_GMYTH_FILE_LOCAL(src->file)) + new_offset = + gmyth_file_local_seek(GMYTH_FILE_LOCAL(src->file), segment->start, + G_SEEK_SET); + else if (IS_GMYTH_FILE_TRANSFER(src->file)) + new_offset = + gmyth_file_transfer_seek(GMYTH_FILE_TRANSFER(src->file), + segment->start, SEEK_SET); - src->read_offset = new_offset; + GST_LOG_OBJECT(src, + "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.", + segment->start, src->read_offset, new_offset); + if (G_UNLIKELY(new_offset < 0)) + { + ret = FALSE; + if (!src->live_tv) + goto eos; + } - if (ret == FALSE) { - GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!"); - } + src->read_offset = new_offset; - } + if (ret == FALSE) + { + GST_INFO_OBJECT(src, "Failed to set the SEEK on segment!"); + } + + } done: return ret; eos: { - GST_DEBUG_OBJECT (src, "EOS found on seeking!!!"); - return FALSE; + GST_DEBUG_OBJECT(src, "EOS found on seeking!!!"); + return FALSE; } } /* create a socket for connecting to remote server */ static gboolean -gst_mythtv_src_start (GstBaseSrc * bsrc) +gst_mythtv_src_start(GstBaseSrc * bsrc) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); - GString *chain_id_local = NULL; + GString *chain_id_local = NULL; GMythURI *gmyth_uri = NULL; gboolean ret = TRUE; GstMessage *msg; - if (src->unique_setup == FALSE) { - src->unique_setup = TRUE; - } else { - goto done; - } - - gmyth_uri = gmyth_uri_new_with_value (src->uri_name); - src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name); - src->live_tv = gmyth_uri_is_livetv( gmyth_uri ); - /* testing UPnP... */ - /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */ - if ( src->live_tv ) { - src->spawn_livetv = gmyth_livetv_new (src->backend_info); - - gchar* ch = gmyth_uri_get_channel_name( gmyth_uri ); - if ( ch != NULL ) - src->channel_name = ch; - - if (src->channel_name != NULL) { - gboolean result; - result = gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name); - if (result == FALSE) { - GST_INFO_OBJECT (src, "LiveTV setup felt down on error"); - ret = FALSE; - goto init_failed; - } + if (src->unique_setup == FALSE) + { + src->unique_setup = TRUE; + } + else + { + goto done; + } - } else { - if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) { - GST_INFO_OBJECT (src, "LiveTV setup felt down on error"); - ret = FALSE; - goto init_failed; - } - } + gmyth_uri = gmyth_uri_new_with_value(src->uri_name); + src->backend_info = gmyth_backend_info_new_with_uri(src->uri_name); + src->live_tv = gmyth_uri_is_livetv(gmyth_uri); + /* testing UPnP... */ + /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */ + if (src->live_tv) + { + src->spawn_livetv = gmyth_livetv_new(src->backend_info); - /* testing change channel... */ - /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */ + gchar *ch = gmyth_uri_get_channel_name(gmyth_uri); + if (ch != NULL) + src->channel_name = ch; - src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) ); + if (src->channel_name != NULL) + { + gboolean result; + result = + gmyth_livetv_channel_name_setup(src->spawn_livetv, + src->channel_name); + if (result == FALSE) + { + GST_INFO_OBJECT(src, "LiveTV setup felt down on error"); + ret = FALSE; + goto init_failed; + } - if (NULL == src->file) { - GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL"); - ret = FALSE; - goto init_failed; - } - - /* Check if the file is local to this specific client renderer */ - if ( gmyth_uri_is_local_file(gmyth_uri) ) - ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) ); - else - ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ? - gmyth_uri_get_path(src->spawn_livetv->uri) : - src->spawn_livetv->proginfo->pathname->str ); - - /* sets the mythtvsrc "location" property */ - g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL); + } + else + { + if (gmyth_livetv_setup(src->spawn_livetv) == FALSE) + { + GST_INFO_OBJECT(src, "LiveTV setup felt down on error"); + ret = FALSE; + goto init_failed; + } + } - if ( !ret ) + /* testing change channel... */ + /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */ + + src->file = + GMYTH_FILE(gmyth_livetv_create_file_transfer(src->spawn_livetv)); + + if (NULL == src->file) { - GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" ); - g_object_unref( src->file ); - src->file = NULL; - goto init_failed; + GST_INFO_OBJECT(src, "[LiveTV] FileTransfer equals to NULL"); + ret = FALSE; + goto init_failed; } - } else { - - /* Check if the file is local to this specific client renderer, and tries to open - * a local connection - */ - if ( gmyth_uri_is_local_file(gmyth_uri) ) - { - src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info)); - ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) ); - } else { - src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info)); - ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name ); - } - } /* if (else) - recorded FileTransfer */ + /* Check if the file is local to this specific client renderer */ + if (gmyth_uri_is_local_file(gmyth_uri)) + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file)); + else + ret = + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file), + src->spawn_livetv->uri != + NULL ? gmyth_uri_get_path(src-> + spawn_livetv-> + uri) : src-> + spawn_livetv->proginfo->pathname->str); - if (NULL == src->file) { - GST_INFO_OBJECT (src, "FileTransfer is NULL"); - goto init_failed; - } - /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */ + /* sets the mythtvsrc "location" property */ + g_object_set(src, "location", gmyth_file_get_uri(src->file), NULL); - if (ret == FALSE) { + if (!ret) + { + GST_INFO_OBJECT(src, + "Error: couldn't open the FileTransfer from LiveTV source!"); + g_object_unref(src->file); + src->file = NULL; + goto init_failed; + } + } + else + { + + /* Check if the file is local to this specific client renderer, and tries to open + * a local connection + */ + if (gmyth_uri_is_local_file(gmyth_uri)) + { + src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info)); + ret = gmyth_file_local_open(GMYTH_FILE_LOCAL(src->file)); + } + else + { + src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info)); + ret = + gmyth_file_transfer_open(GMYTH_FILE_TRANSFER(src->file), + src->uri_name); + } + + } /* if (else) - recorded FileTransfer */ + + if (NULL == src->file) + { + GST_INFO_OBJECT(src, "FileTransfer is NULL"); + goto init_failed; + } + /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */ + + if (ret == FALSE) + { #ifndef GST_DISABLE_GST_DEBUG - if (src->mythtv_msgs_dbg) - GST_INFO_OBJECT (src, - "MythTV FileTransfer request failed when setting up socket connection!"); + if (src->mythtv_msgs_dbg) + GST_INFO_OBJECT(src, + "MythTV FileTransfer request failed when setting up socket connection!"); #endif - goto begin_req_failed; - } + goto begin_req_failed; + } - GST_INFO_OBJECT (src, - "MythTV FileTransfer filesize = %lld, content_size = %lld!", - gmyth_file_get_filesize( src->file ), src->content_size); + GST_INFO_OBJECT(src, + "MythTV FileTransfer filesize = %lld, content_size = %lld!", + gmyth_file_get_filesize(src->file), src->content_size); - src->content_size = gmyth_file_get_filesize (src->file); + src->content_size = gmyth_file_get_filesize(src->file); - msg = gst_message_new_duration (GST_OBJECT (src), GST_FORMAT_BYTES, src->content_size); - gst_element_post_message (GST_ELEMENT (src), msg); + msg = + gst_message_new_duration(GST_OBJECT(src), GST_FORMAT_BYTES, + src->content_size); + gst_element_post_message(GST_ELEMENT(src), msg); src->do_start = FALSE; - /* this is used for the buffer cache */ - src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE); + /* this is used for the buffer cache */ + src->bytes_queue = g_byte_array_sized_new(INTERNAL_BUFFER_SIZE); src->buffer_remain = 0; - - gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)), - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, - src->content_size, 0)); + + gst_pad_push_event(GST_BASE_SRC_PAD(GST_BASE_SRC(src)), + gst_event_new_new_segment(TRUE, 1.0, GST_FORMAT_TIME, 0, + src->content_size, 0)); done: - if (gmyth_uri != NULL) + if (gmyth_uri != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_object_unref(gmyth_uri); + gmyth_uri = NULL; } - if (chain_id_local != NULL) { - g_string_free (chain_id_local, TRUE); - chain_id_local = NULL; - } - - return TRUE; - - /* ERRORS */ -init_failed: - if (gmyth_uri != NULL) + if (chain_id_local != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_string_free(chain_id_local, TRUE); + chain_id_local = NULL; } - if (src->spawn_livetv != NULL) { - g_object_unref (src->spawn_livetv); - src->spawn_livetv = NULL; - } - - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - (NULL), ("Could not initialize MythTV library (%i, %s)", ret, - src->uri_name)); + return TRUE; - - gst_mythtv_src_clear (src); - - return FALSE; -begin_req_failed: - if (gmyth_uri != NULL) + /* ERRORS */ +init_failed: + if (gmyth_uri != NULL) { - g_object_unref (gmyth_uri); - gmyth_uri = NULL; + g_object_unref(gmyth_uri); + gmyth_uri = NULL; } - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, - src->uri_name)); - return FALSE; + if (src->spawn_livetv != NULL) + { + g_object_unref(src->spawn_livetv); + src->spawn_livetv = NULL; + } + + GST_ELEMENT_ERROR(src, LIBRARY, INIT, + (NULL), ("Could not initialize MythTV library (%i, %s)", + ret, src->uri_name)); + + + gst_mythtv_src_clear(src); + + return FALSE; +begin_req_failed: + if (gmyth_uri != NULL) + { + g_object_unref(gmyth_uri); + gmyth_uri = NULL; + } + + GST_ELEMENT_ERROR(src, LIBRARY, INIT, + (NULL), + ("Could not begin request sent to MythTV server (%i, %s)", + ret, src->uri_name)); + return FALSE; } static gboolean -gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size) +gst_mythtv_src_get_size(GstBaseSrc * bsrc, guint64 * size) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); gboolean ret = TRUE; - GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)", - abs (src->content_size - src->prev_content_size), - GMYTHTV_TRANSFER_MAX_BUFFER); + GST_LOG_OBJECT(src, "Differs from previous content size: %d (max.: %d)", + abs(src->content_size - src->prev_content_size), + GMYTHTV_TRANSFER_MAX_BUFFER); - if (src->live_tv) { - ret = FALSE; - } else if (src->live_tv && src->enable_timing_position - && (abs (src->content_size - src->bytes_read) < - GMYTHTV_TRANSFER_MAX_BUFFER)) { + if (src->live_tv) + { + ret = FALSE; + } + else if (src->live_tv && src->enable_timing_position + && (abs(src->content_size - src->bytes_read) < + GMYTHTV_TRANSFER_MAX_BUFFER)) + { - gint64 new_offset = - gmyth_recorder_get_file_position (src->spawn_livetv->recorder); - if (new_offset > 0 && new_offset > src->content_size) { - src->content_size = new_offset; - } else if (new_offset < src->content_size) { - src->update_prog_chain = TRUE; - } + gint64 new_offset = + gmyth_recorder_get_file_position(src->spawn_livetv->recorder); + if (new_offset > 0 && new_offset > src->content_size) + { + src->content_size = new_offset; + } + else if (new_offset < src->content_size) + { + src->update_prog_chain = TRUE; + } - } + } *size = src->content_size; - GST_LOG_OBJECT (src, "Content size = %lld", src->content_size); + GST_LOG_OBJECT(src, "Content size = %lld", src->content_size); return ret; @@ -911,312 +996,328 @@ /* close the socket and associated resources * used both to recover from errors and go to NULL state */ static gboolean -gst_mythtv_src_stop (GstBaseSrc * bsrc) +gst_mythtv_src_stop(GstBaseSrc * bsrc) { - GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); - - gst_mythtv_src_clear (src); + GstMythtvSrc *src = GST_MYTHTV_SRC(bsrc); - /* src->eos = FALSE; */ + gst_mythtv_src_clear(src); + + /* src->eos = FALSE; */ return TRUE; } static gboolean -gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event) +gst_mythtv_src_handle_event(GstPad * pad, GstEvent * event) { - GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad)); + GstMythtvSrc *src = GST_MYTHTV_SRC(GST_PAD_PARENT(pad)); gint64 cont_size = 0; gboolean ret = FALSE; - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_EOS: - GST_WARNING_OBJECT (src, "Got EOS event"); + switch (GST_EVENT_TYPE(event)) + { + case GST_EVENT_EOS: + GST_WARNING_OBJECT(src, "Got EOS event"); - if (src->live_tv) { - cont_size = gst_mythtv_src_get_position (src); - if (cont_size > src->content_size) { - src->content_size = cont_size; - src->eos = FALSE; - } else { - src->eos = TRUE; - gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL); - gst_element_set_locked_state (GST_ELEMENT (src), FALSE); - } - } - break; - default: - ret = gst_pad_event_default (pad, event); - } + if (src->live_tv) + { + cont_size = gst_mythtv_src_get_position(src); + if (cont_size > src->content_size) + { + src->content_size = cont_size; + src->eos = FALSE; + } + else + { + src->eos = TRUE; + gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL); + gst_element_set_locked_state(GST_ELEMENT(src), FALSE); + } + } + break; + default: + ret = gst_pad_event_default(pad, event); + } return ret; } static gboolean -gst_mythtv_src_is_seekable (GstBaseSrc * push_src) +gst_mythtv_src_is_seekable(GstBaseSrc * push_src) { return TRUE; } static gboolean -gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query) +gst_mythtv_src_handle_query(GstPad * pad, GstQuery * query) { gboolean res = FALSE; - GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad)); + GstMythtvSrc *myth = GST_MYTHTV_SRC(gst_pad_get_parent(pad)); GstFormat formt; - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_POSITION: - { - gst_query_parse_position (query, &formt, NULL); - if (formt == GST_FORMAT_BYTES) { - gst_query_set_position (query, formt, myth->read_offset); - GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset); - res = TRUE; - } else if (formt == GST_FORMAT_TIME) { - res = gst_pad_query_default (pad, query); - } - break; - } - case GST_QUERY_DURATION: - { - gst_query_parse_duration (query, &formt, NULL); - if (formt == GST_FORMAT_BYTES) { - gint64 size = myth->content_size; - gst_query_set_duration (query, GST_FORMAT_BYTES, 10); - GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, size); - res = TRUE; - } else if (formt == GST_FORMAT_TIME) { - res = gst_pad_query_default (pad, query); - } - break; - } - default: - { - res = gst_pad_query_default (pad, query); - break; - } - } + switch (GST_QUERY_TYPE(query)) + { + case GST_QUERY_POSITION: + { + gst_query_parse_position(query, &formt, NULL); + if (formt == GST_FORMAT_BYTES) + { + gst_query_set_position(query, formt, myth->read_offset); + GST_DEBUG_OBJECT(myth, "POS %" G_GINT64_FORMAT, + myth->read_offset); + res = TRUE; + } + else if (formt == GST_FORMAT_TIME) + { + res = gst_pad_query_default(pad, query); + } + break; + } + case GST_QUERY_DURATION: + { + gst_query_parse_duration(query, &formt, NULL); + if (formt == GST_FORMAT_BYTES) + { + gint64 size = myth->content_size; + gst_query_set_duration(query, GST_FORMAT_BYTES, 10); + GST_DEBUG_OBJECT(myth, "SIZE %" G_GINT64_FORMAT, size); + res = TRUE; + } + else if (formt == GST_FORMAT_TIME) + { + res = gst_pad_query_default(pad, query); + } + break; + } + default: + { + res = gst_pad_query_default(pad, query); + break; + } + } - gst_object_unref (myth); + gst_object_unref(myth); return res; } static GstStateChangeReturn -gst_mythtv_src_change_state (GstElement * element, GstStateChange transition) +gst_mythtv_src_change_state(GstElement * element, GstStateChange transition) { GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE; - GstMythtvSrc *src = GST_MYTHTV_SRC (element); + GstMythtvSrc *src = GST_MYTHTV_SRC(element); - g_debug ("MYTHSRC: state_changed"); + switch (transition) + { + case GST_STATE_CHANGE_NULL_TO_READY: + break; + case GST_STATE_CHANGE_READY_TO_PAUSED: + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + if (src->live_tv) + { + if (!gmyth_recorder_send_frontend_ready_command(src->spawn_livetv-> + recorder)) + GST_WARNING_OBJECT(src, + "Couldn't send the FRONTEND_READY message to the backend!"); + else + GST_DEBUG_OBJECT(src, "FRONTEND_READY was sent to the backend"); + } + break; + default: + break; + } - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - if (src->live_tv) { - if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv-> - recorder)) - GST_WARNING_OBJECT (src, - "Couldn't send the FRONTEND_READY message to the backend!"); - else - GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend"); - } - break; - default: - break; - } + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + return ret; - g_debug ("MYTHSRC: state_changed 1"); - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - if (ret == GST_STATE_CHANGE_FAILURE) - return ret; + switch (transition) + { + case GST_STATE_CHANGE_READY_TO_NULL: + gst_mythtv_src_clear(src); + break; + case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + case GST_STATE_CHANGE_PAUSED_TO_READY: + break; + default: + break; + } - - g_debug ("MYTHSRC: state_changed2"); - - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - gst_mythtv_src_clear (src); - break; - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - case GST_STATE_CHANGE_PAUSED_TO_READY: - break; - default: - break; - } - - g_debug ("MYTHSRC: state_changed: DONE"); return ret; } static void -gst_mythtv_src_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) +gst_mythtv_src_set_property(GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object); - GST_OBJECT_LOCK (mythtvsrc); - switch (prop_id) { - case PROP_LOCATION: - { - if (!g_value_get_string (value)) { - GST_WARNING ("location property cannot be NULL"); - break; - } + GST_OBJECT_LOCK(mythtvsrc); + switch (prop_id) + { + case PROP_LOCATION: + { + if (!g_value_get_string(value)) + { + GST_WARNING("location property cannot be NULL"); + break; + } - if (mythtvsrc->uri_name != NULL) { - g_free (mythtvsrc->uri_name); - mythtvsrc->uri_name = NULL; - } - mythtvsrc->uri_name = g_value_dup_string (value); + if (mythtvsrc->uri_name != NULL) + { + g_free(mythtvsrc->uri_name); + mythtvsrc->uri_name = NULL; + } + mythtvsrc->uri_name = g_value_dup_string(value); - break; - } + break; + } #ifndef GST_DISABLE_GST_DEBUG - case PROP_GMYTHTV_DBG: - { - mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value); - break; - } + case PROP_GMYTHTV_DBG: + { + mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean(value); + break; + } #endif - case PROP_GMYTHTV_VERSION: - { - mythtvsrc->mythtv_version = g_value_get_int (value); - break; - } - case PROP_GMYTHTV_LIVEID: - { - mythtvsrc->live_tv_id = g_value_get_int (value); - break; - } - case PROP_GMYTHTV_LIVE: - { - mythtvsrc->live_tv = g_value_get_boolean (value); - break; - } - case PROP_GMYTHTV_ENABLE_TIMING_POSITION: - { - mythtvsrc->enable_timing_position = g_value_get_boolean (value); - break; - } - case PROP_GMYTHTV_LIVE_CHAINID: - { - if (!g_value_get_string (value)) { - GST_WARNING ("MythTV Live chainid property cannot be NULL"); - break; - } + case PROP_GMYTHTV_VERSION: + { + mythtvsrc->mythtv_version = g_value_get_int(value); + break; + } + case PROP_GMYTHTV_LIVEID: + { + mythtvsrc->live_tv_id = g_value_get_int(value); + break; + } + case PROP_GMYTHTV_LIVE: + { + mythtvsrc->live_tv = g_value_get_boolean(value); + break; + } + case PROP_GMYTHTV_ENABLE_TIMING_POSITION: + { + mythtvsrc->enable_timing_position = g_value_get_boolean(value); + break; + } + case PROP_GMYTHTV_LIVE_CHAINID: + { + if (!g_value_get_string(value)) + { + GST_WARNING("MythTV Live chainid property cannot be NULL"); + break; + } - if (mythtvsrc->live_chain_id != NULL) { - g_free (mythtvsrc->live_chain_id); - mythtvsrc->live_chain_id = NULL; - } - mythtvsrc->live_chain_id = g_value_dup_string (value); - break; - } - case PROP_GMYTHTV_CHANNEL_NUM: - { - mythtvsrc->channel_name = g_value_dup_string (value); - break; - } - case PROP_GMYTHTV_MAX_TRY: - { - mythtvsrc->max_try = g_value_get_int (value); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + if (mythtvsrc->live_chain_id != NULL) + { + g_free(mythtvsrc->live_chain_id); + mythtvsrc->live_chain_id = NULL; + } + mythtvsrc->live_chain_id = g_value_dup_string(value); + break; + } + case PROP_GMYTHTV_CHANNEL_NUM: + { + mythtvsrc->channel_name = g_value_dup_string(value); + break; + } + case PROP_GMYTHTV_MAX_TRY: + { + mythtvsrc->max_try = g_value_get_int(value); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } - GST_OBJECT_UNLOCK (mythtvsrc); + GST_OBJECT_UNLOCK(mythtvsrc); } static void -gst_mythtv_src_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec) +gst_mythtv_src_get_property(GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { - GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); + GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC(object); - GST_OBJECT_LOCK (mythtvsrc); - switch (prop_id) { - case PROP_LOCATION: - { - g_value_set_string (value, mythtvsrc->uri_name); - break; - } + GST_OBJECT_LOCK(mythtvsrc); + switch (prop_id) + { + case PROP_LOCATION: + { + g_value_set_string(value, mythtvsrc->uri_name); + break; + } #ifndef GST_DISABLE_GST_DEBUG - case PROP_GMYTHTV_DBG: - g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg); - break; + case PROP_GMYTHTV_DBG: + g_value_set_boolean(value, mythtvsrc->mythtv_msgs_dbg); + break; #endif - case PROP_GMYTHTV_VERSION: - { - g_value_set_int (value, mythtvsrc->mythtv_version); - break; - } - case PROP_GMYTHTV_LIVEID: - { - g_value_set_int (value, mythtvsrc->live_tv_id); - break; - } - case PROP_GMYTHTV_LIVE: - g_value_set_boolean (value, mythtvsrc->live_tv); - break; - case PROP_GMYTHTV_ENABLE_TIMING_POSITION: - g_value_set_boolean (value, mythtvsrc->enable_timing_position); - break; - case PROP_GMYTHTV_LIVE_CHAINID: - { - g_value_set_string (value, mythtvsrc->live_chain_id); - break; - } - case PROP_GMYTHTV_CHANNEL_NUM: - { - g_value_set_string (value, mythtvsrc->channel_name); - break; - } - case PROP_GMYTHTV_MAX_TRY: - { - g_value_set_int (value, mythtvsrc->max_try); - break; - } + case PROP_GMYTHTV_VERSION: + { + g_value_set_int(value, mythtvsrc->mythtv_version); + break; + } + case PROP_GMYTHTV_LIVEID: + { + g_value_set_int(value, mythtvsrc->live_tv_id); + break; + } + case PROP_GMYTHTV_LIVE: + g_value_set_boolean(value, mythtvsrc->live_tv); + break; + case PROP_GMYTHTV_ENABLE_TIMING_POSITION: + g_value_set_boolean(value, mythtvsrc->enable_timing_position); + break; + case PROP_GMYTHTV_LIVE_CHAINID: + { + g_value_set_string(value, mythtvsrc->live_chain_id); + break; + } + case PROP_GMYTHTV_CHANNEL_NUM: + { + g_value_set_string(value, mythtvsrc->channel_name); + break; + } + case PROP_GMYTHTV_MAX_TRY: + { + g_value_set_int(value, mythtvsrc->max_try); + break; + } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } - GST_OBJECT_UNLOCK (mythtvsrc); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } + GST_OBJECT_UNLOCK(mythtvsrc); } static gboolean -plugin_init (GstPlugin * plugin) +plugin_init(GstPlugin * plugin) { - return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE, - GST_TYPE_MYTHTV_SRC); + return gst_element_register(plugin, "mythtvsrc", GST_RANK_NONE, + GST_TYPE_MYTHTV_SRC); } -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mythtv", - "lib MythTV src", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mythtv", + "lib MythTV src", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, + GST_PACKAGE_ORIGIN); /*** GSTURIHANDLER INTERFACE *************************************************/ static guint -gst_mythtv_src_uri_get_type (void) +gst_mythtv_src_uri_get_type(void) { return GST_URI_SRC; } static gchar ** -gst_mythtv_src_uri_get_protocols (void) +gst_mythtv_src_uri_get_protocols(void) { static gchar *protocols[] = { "myth", "myths", NULL }; @@ -1224,33 +1325,34 @@ } static const gchar * -gst_mythtv_src_uri_get_uri (GstURIHandler * handler) +gst_mythtv_src_uri_get_uri(GstURIHandler * handler) { - GstMythtvSrc *src = GST_MYTHTV_SRC (handler); + GstMythtvSrc *src = GST_MYTHTV_SRC(handler); return src->uri_name; } static gboolean -gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) +gst_mythtv_src_uri_set_uri(GstURIHandler * handler, const gchar * uri) { - GstMythtvSrc *src = GST_MYTHTV_SRC (handler); + GstMythtvSrc *src = GST_MYTHTV_SRC(handler); gchar *protocol; - protocol = gst_uri_get_protocol (uri); - if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) { - g_free (protocol); - return FALSE; - } - g_free (protocol); - g_object_set (src, "location", uri, NULL); + protocol = gst_uri_get_protocol(uri); + if ((strcmp(protocol, "myth") != 0) && (strcmp(protocol, "myths") != 0)) + { + g_free(protocol); + return FALSE; + } + g_free(protocol); + g_object_set(src, "location", uri, NULL); return TRUE; } static void -gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data) +gst_mythtv_src_uri_handler_init(gpointer g_iface, gpointer iface_data) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; @@ -1261,9 +1363,9 @@ } void -size_header_handler (void *userdata, const char *value) +size_header_handler(void *userdata, const char *value) { - GstMythtvSrc *src = GST_MYTHTV_SRC (userdata); + GstMythtvSrc *src = GST_MYTHTV_SRC(userdata); - GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size); + GST_DEBUG_OBJECT(src, "content size = %lld bytes", src->content_size); } diff -r 312d6bc514f3 -r 3cf3c6019e3b gst-gmyth/mythsrc/gstmythtvsrc.h --- a/gst-gmyth/mythsrc/gstmythtvsrc.h Thu Jun 14 18:19:52 2007 +0100 +++ b/gst-gmyth/mythsrc/gstmythtvsrc.h Thu Jun 14 18:21:08 2007 +0100 @@ -33,7 +33,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_MYTHTV_SRC \ (gst_mythtv_src_get_type()) #define GST_MYTHTV_SRC(obj) \ @@ -44,24 +43,25 @@ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MYTHTV_SRC)) #define GST_IS_MYTHTV_SRC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MYTHTV_SRC)) - typedef struct _GstMythtvSrc GstMythtvSrc; typedef struct _GstMythtvSrcClass GstMythtvSrcClass; -typedef enum { +typedef enum +{ GST_MYTHTV_SRC_FILE_TRANSFER, GST_MYTHTV_SRC_NEXT_PROGRAM_CHAIN, GST_MYTHTV_SRC_INVALID_DATA } GstMythtvState; -struct _GstMythtvSrc { +struct _GstMythtvSrc +{ GstPushSrc element; - /* MythFileTransfer */ + /* MythFileTransfer */ GMythFile *file; GMythLiveTV *spawn_livetv; - + GMythBackendInfo *backend_info; GstMythtvState state; @@ -97,37 +97,37 @@ gint live_tv_id; - gchar* channel_name; + gchar *channel_name; guint mode; - /* MythTV capabilities */ + /* MythTV capabilities */ GstCaps *mythtv_caps; GByteArray *bytes_queue; #ifndef GST_DISABLE_GST_DEBUG - /* enable Myth TV debug messages */ + /* enable Myth TV debug messages */ gboolean mythtv_msgs_dbg; #endif gboolean update_prog_chain; - /* stablish a maximum iteration value to the IS_RECORDING message */ + /* stablish a maximum iteration value to the IS_RECORDING message */ guint wait_to_transfer; - /* max try number to get freerecorder */ + /* max try number to get freerecorder */ gint max_try; gint try_number; }; -struct _GstMythtvSrcClass { +struct _GstMythtvSrcClass +{ GstPushSrcClass parent_class; }; -GType gst_mythtv_src_get_type (void); +GType gst_mythtv_src_get_type(void); G_END_DECLS - #endif /* __GST_MYTHTV_SRC_H__ */ diff -r 312d6bc514f3 -r 3cf3c6019e3b gst-gmyth/nuvdemux/gstnuvdemux.c --- a/gst-gmyth/nuvdemux/gstnuvdemux.c Thu Jun 14 18:19:52 2007 +0100 +++ b/gst-gmyth/nuvdemux/gstnuvdemux.c Thu Jun 14 18:21:08 2007 +0100 @@ -58,112 +58,112 @@ #define GST_NUV_DEMUX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_NUV_DEMUX, GstNuvDemuxPrivate)) -GST_DEBUG_CATEGORY_STATIC (nuvdemux_debug); +GST_DEBUG_CATEGORY_STATIC(nuvdemux_debug); #define GST_CAT_DEFAULT nuvdemux_debug #define GST_FLOW_ERROR_NO_DATA -101 #define GST_FLOW_ERROR_EOS -102 enum { - NUV_PUSH_MODE = 0, - NUV_PULL_MODE + NUV_PUSH_MODE = 0, + NUV_PULL_MODE }; -GST_DEBUG_CATEGORY_EXTERN (GST_CAT_EVENT); +GST_DEBUG_CATEGORY_EXTERN(GST_CAT_EVENT); static const GstElementDetails gst_nuv_demux_details = -GST_ELEMENT_DETAILS ("Nuv demuxer", - "Codec/Demuxer", - "Demultiplex a .nuv file into audio and video", - "Renato Araujo Oliveira Filho ," - "Rosfran Borges "); +GST_ELEMENT_DETAILS("Nuv demuxer", + "Codec/Demuxer", + "Demultiplex a .nuv file into audio and video", + "Renato Araujo Oliveira Filho ," + "Rosfran Borges "); /* file header */ typedef struct { - gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */ - gchar version[5]; /* "x.xx\0" */ + gchar id[12]; /* "NuppelVideo\0" or "MythTVVideo\0" */ + gchar version[5]; /* "x.xx\0" */ - gint i_width; - gint i_height; - gint i_width_desired; - gint i_height_desired; + gint i_width; + gint i_height; + gint i_width_desired; + gint i_height_desired; - gchar i_mode; /* P progressive, I interlaced */ + gchar i_mode; /* P progressive, I interlaced */ - gdouble d_aspect; /* 1.0 squared pixel */ - gdouble d_fps; - //fps num/denom - gint i_fpsn; - gint i_fpsd; + gdouble d_aspect; /* 1.0 squared pixel */ + gdouble d_fps; + //fps num/denom + gint i_fpsn; + gint i_fpsd; - gint i_video_blocks; /* 0 no video, -1 unknown */ - gint i_audio_blocks; - gint i_text_blocks; + gint i_video_blocks; /* 0 no video, -1 unknown */ + gint i_audio_blocks; + gint i_text_blocks; - gint i_keyframe_distance; + gint i_keyframe_distance; } nuv_header; /* frame header */ typedef struct { - gchar i_type; /* A: audio, V: video, S: sync; T: test - R: Seekpoint (string:RTjjjjjjjj) - D: Extra data for codec */ - gchar i_compression; /* V: 0 uncompressed - 1 RTJpeg - 2 RTJpeg+lzo - N black frame - L copy last - A: 0 uncompressed (44100 1-bits, 2ch) - 1 lzo - 2 layer 2 - 3 layer 3 - F flac - S shorten - N null frame loudless - L copy last - S: B audio and vdeo sync point - A audio sync info (timecode == effective - dsp frequency*100) - V next video sync (timecode == next video - frame num) - S audio,video,text correlation */ - gchar i_keyframe; /* 0 keyframe, else no no key frame */ - guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16 - 0x02: gauss 5 pixel (8,1,1,1,1)/12 - 0x04: cartoon filter */ + gchar i_type; /* A: audio, V: video, S: sync; T: test + R: Seekpoint (string:RTjjjjjjjj) + D: Extra data for codec */ + gchar i_compression; /* V: 0 uncompressed + 1 RTJpeg + 2 RTJpeg+lzo + N black frame + L copy last + A: 0 uncompressed (44100 1-bits, 2ch) + 1 lzo + 2 layer 2 + 3 layer 3 + F flac + S shorten + N null frame loudless + L copy last + S: B audio and vdeo sync point + A audio sync info (timecode == effective + dsp frequency*100) + V next video sync (timecode == next video + frame num) + S audio,video,text correlation */ + gchar i_keyframe; /* 0 keyframe, else no no key frame */ + guint8 i_filters; /* 0x01: gauss 5 pixel (8,2,2,2,2)/16 + 0x02: gauss 5 pixel (8,1,1,1,1)/12 + 0x04: cartoon filter */ - gint32 i_timecode; /* ms */ + gint32 i_timecode; /* ms */ - gint i_length; /* V,A,T: length of following data - S: length of packet correl */ + gint i_length; /* V,A,T: length of following data + S: length of packet correl */ } nuv_frame_header; /* FIXME Not sure of this one */ typedef struct { - gint i_version; - guint32 i_video_fcc; + gint i_version; + guint32 i_video_fcc; - guint32 i_audio_fcc; - gint i_audio_sample_rate; - gint i_audio_bits_per_sample; - gint i_audio_channels; - gint i_audio_compression_ratio; - gint i_audio_quality; - gint i_rtjpeg_quality; - gint i_rtjpeg_luma_filter; - gint i_rtjpeg_chroma_filter; - gint i_lavc_bitrate; - gint i_lavc_qmin; - gint i_lavc_qmax; - gint i_lavc_maxqdiff; - gint64 i_seekable_offset; - gint64 i_keyframe_adjust_offset; + guint32 i_audio_fcc; + gint i_audio_sample_rate; + gint i_audio_bits_per_sample; + gint i_audio_channels; + gint i_audio_compression_ratio; + gint i_audio_quality; + gint i_rtjpeg_quality; + gint i_rtjpeg_luma_filter; + gint i_rtjpeg_chroma_filter; + gint i_lavc_bitrate; + gint i_lavc_qmin; + gint i_lavc_qmax; + gint i_lavc_maxqdiff; + gint64 i_seekable_offset; + gint64 i_keyframe_adjust_offset; } nuv_extended_header; @@ -174,7 +174,8 @@ } frame_index_data; -typedef enum { +typedef enum +{ GST_NUV_DEMUX_START, GST_NUV_DEMUX_HEADER_DATA, GST_NUV_DEMUX_EXTRA_DATA, @@ -187,125 +188,132 @@ GST_NUV_DEMUX_INVALID_DATA } GstNuvDemuxState; -struct _GstNuvDemuxPrivate { - /* used for indicate the mode */ - guint mode; +struct _GstNuvDemuxPrivate +{ + /* used for indicate the mode */ + guint mode; - /* used on push mode */ - GstAdapter *adapter; + /* used on push mode */ + GstAdapter *adapter; - /* pads */ - GstPad *sinkpad; - GstPad *src_video_pad; - GstPad *src_audio_pad; + /* pads */ + GstPad *sinkpad; + GstPad *src_video_pad; + GstPad *src_audio_pad; - /* Flow control */ - GstFlowReturn last_video_return; - GstFlowReturn last_audio_return; - gboolean more_data; - gboolean eos; - gboolean new_file; - guint segment; + /* Flow control */ + GstFlowReturn last_video_return; + GstFlowReturn last_audio_return; + gboolean more_data; + gboolean eos; + gboolean new_file; + guint segment; - /* NUV decoding state */ - GstNuvDemuxState state; - guint64 offset; + /* NUV decoding state */ + GstNuvDemuxState state; + guint64 offset; - /* duration information */ - guint64 duration_bytes; - guint64 duration_time; - guint64 segment_stop; - guint64 segment_start; + /* duration information */ + guint64 duration_bytes; + guint64 duration_time; + guint64 segment_stop; + guint64 segment_start; - /* segment control info */ - gboolean new_audio_segment; - gboolean new_video_segment; + /* segment control info */ + gboolean new_audio_segment; + gboolean new_video_segment; - /* Mpeg ExtraData */ - guint64 mpeg_data_size; - GstBuffer *mpeg_buffer; + /* Mpeg ExtraData */ + guint64 mpeg_data_size; + GstBuffer *mpeg_buffer; - /* Headers */ + /* Headers */ nuv_header h; nuv_extended_header eh; nuv_frame_header fh; - /* anothers info */ - guint64 header_lengh; - gint64 time_start; - gint64 time_diff; - gint64 time_qos; - guint64 last_frame_time; - GSList *index; + /* anothers info */ + guint64 header_lengh; + gint64 time_start; + gint64 time_diff; + gint64 time_qos; + guint64 last_frame_time; + GSList *index; }; -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-nuv")); +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS + ("video/x-nuv")); static GstStaticPadTemplate audio_src_template = -GST_STATIC_PAD_TEMPLATE ("audio_src", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY); +GST_STATIC_PAD_TEMPLATE("audio_src", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); static GstStaticPadTemplate video_src_template = -GST_STATIC_PAD_TEMPLATE ("video_src", - GST_PAD_SRC, - GST_PAD_SOMETIMES, - GST_STATIC_CAPS_ANY); +GST_STATIC_PAD_TEMPLATE("video_src", + GST_PAD_SRC, + GST_PAD_SOMETIMES, + GST_STATIC_CAPS_ANY); -static void gst_nuv_demux_dispose (GObject * object); -static void gst_nuv_demux_finalize (GObject * object); -static GstStateChangeReturn gst_nuv_demux_change_state (GstElement * element, - GstStateChange transition); -static void gst_nuv_demux_loop (GstPad * pad); -static GstFlowReturn gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf); -static GstFlowReturn gst_nuv_demux_play (GstPad * pad); -static gboolean gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, - gboolean active); -static gboolean gst_nuv_demux_sink_activate_push (GstPad * pad, - gboolean active); -static gboolean gst_nuv_demux_sink_activate (GstPad * sinkpad); -static gboolean gst_nuv_demux_sink_event (GstPad *pad, GstEvent *event); -static gboolean gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event); -static frame_index_data * gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos, - gint64 segment_stop, GstFormat format); +static void gst_nuv_demux_dispose(GObject * object); +static void gst_nuv_demux_finalize(GObject * object); +static GstStateChangeReturn gst_nuv_demux_change_state(GstElement * element, + GstStateChange + transition); +static void gst_nuv_demux_loop(GstPad * pad); +static GstFlowReturn gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf); +static GstFlowReturn gst_nuv_demux_play(GstPad * pad); +static gboolean gst_nuv_demux_sink_activate_pull(GstPad * sinkpad, + gboolean active); +static gboolean gst_nuv_demux_sink_activate_push(GstPad * pad, + gboolean active); +static gboolean gst_nuv_demux_sink_activate(GstPad * sinkpad); +static gboolean gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event); +static gboolean gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event); +static frame_index_data *gst_nuv_demux_do_seek_index(GstNuvDemux * nuv, + gint64 seek_pos, + gint64 segment_stop, + GstFormat format); -static GstFlowReturn gst_nuv_demux_move_bytes (GstNuvDemux * nuv, guint64 size); -static GstFlowReturn gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, - gboolean move, GstBuffer ** buffer); -static void gst_nuv_demux_reset (GstNuvDemux * nuv); -static void gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv); -static void gst_nuv_demux_send_eos (GstNuvDemux * nuv); -static void gst_nuv_demux_create_seek_index (GstNuvDemux * nuv); +static GstFlowReturn gst_nuv_demux_move_bytes(GstNuvDemux * nuv, + guint64 size); +static GstFlowReturn gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size, + gboolean move, + GstBuffer ** buffer); +static void gst_nuv_demux_reset(GstNuvDemux * nuv); +static void gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv); +static void gst_nuv_demux_send_eos(GstNuvDemux * nuv); +static void gst_nuv_demux_create_seek_index(GstNuvDemux * nuv); -#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6) -GstBuffer * gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes); +#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6) +GstBuffer *gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes); #endif -GST_BOILERPLATE (GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT); +GST_BOILERPLATE(GstNuvDemux, gst_nuv_demux, GstElement, GST_TYPE_ELEMENT); /****************************************************************************** * Utils function ******************************************************************************/ #if G_BYTE_ORDER == G_BIG_ENDIAN static inline gdouble -_gdouble_swap_le_be (gdouble * d) +_gdouble_swap_le_be(gdouble * d) { union { - guint64 i; - gdouble d; + guint64 i; + gdouble d; } u; u.d = *d; - u.i = GUINT64_SWAP_LE_BE (u.i); + u.i = GUINT64_SWAP_LE_BE(u.i); return u.d; } @@ -315,169 +323,186 @@ #endif /* G_BYTE_ORDER != G_BIG_ENDIAN */ static void -double2fraction (double in, int *num, int *denom) +double2fraction(double in, int *num, int *denom) { - if (in == 29.97) { - *num = 30000; - *denom = 1001; - } else if (in == 23.976) { - *num = 24000; - *denom = 1001; - } else { - *denom = 1; - while (in - floor(in) >= 0.1) { - *denom *= 10; - in *= 10.0; - } - *num = (int)floor(in); - } + if (in == 29.97) + { + *num = 30000; + *denom = 1001; + } + else if (in == 23.976) + { + *num = 24000; + *denom = 1001; + } + else + { + *denom = 1; + while (in - floor(in) >= 0.1) + { + *denom *= 10; + in *= 10.0; + } + *num = (int) floor(in); + } } /* GObject Functions */ static void -gst_nuv_demux_base_init (gpointer klass) +gst_nuv_demux_base_init(gpointer klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstElementClass *element_class = GST_ELEMENT_CLASS(klass); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&audio_src_template)); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&audio_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&video_src_template)); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&video_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); - gst_element_class_set_details (element_class, &gst_nuv_demux_details); + gst_element_class_add_pad_template(element_class, + gst_static_pad_template_get + (&sink_template)); + gst_element_class_set_details(element_class, &gst_nuv_demux_details); } static void -gst_nuv_demux_class_init (GstNuvDemuxClass * klass) +gst_nuv_demux_class_init(GstNuvDemuxClass * klass) { - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + GstElementClass *gstelement_class = GST_ELEMENT_CLASS(klass); GObjectClass *gobject_class = (GObjectClass *) klass; - GST_DEBUG_CATEGORY_INIT (nuvdemux_debug, "nuvdemux", - 0, "Demuxer for NUV streams"); + GST_DEBUG_CATEGORY_INIT(nuvdemux_debug, "nuvdemux", + 0, "Demuxer for NUV streams"); - parent_class = g_type_class_peek_parent (klass); + parent_class = g_type_class_peek_parent(klass); gobject_class->dispose = gst_nuv_demux_dispose; gobject_class->finalize = gst_nuv_demux_finalize; gstelement_class->change_state = gst_nuv_demux_change_state; - g_type_class_add_private (gobject_class, sizeof (GstNuvDemuxPrivate)); + g_type_class_add_private(gobject_class, sizeof(GstNuvDemuxPrivate)); } static void -gst_nuv_demux_init (GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class) +gst_nuv_demux_init(GstNuvDemux * nuv, GstNuvDemuxClass * nuv_class) { - nuv->priv = GST_NUV_DEMUX_GET_PRIVATE (nuv); - nuv->priv->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); + nuv->priv = GST_NUV_DEMUX_GET_PRIVATE(nuv); + nuv->priv->sinkpad = + gst_pad_new_from_static_template(&sink_template, "sink"); - /* creating adapter */ + /* creating adapter */ nuv->priv->mode = NUV_PUSH_MODE; - nuv->priv->adapter = gst_adapter_new (); + nuv->priv->adapter = gst_adapter_new(); nuv->priv->new_audio_segment = TRUE; nuv->priv->new_video_segment = TRUE; - gst_pad_set_activate_function (nuv->priv->sinkpad, gst_nuv_demux_sink_activate); - gst_pad_set_activatepull_function (nuv->priv->sinkpad, - gst_nuv_demux_sink_activate_pull); - gst_pad_set_activatepush_function (nuv->priv->sinkpad, - gst_nuv_demux_sink_activate_push); - gst_pad_set_chain_function (nuv->priv->sinkpad, - GST_DEBUG_FUNCPTR (gst_nuv_demux_chain)); - gst_pad_set_event_function (nuv->priv->sinkpad, - GST_DEBUG_FUNCPTR (gst_nuv_demux_sink_event)); + gst_pad_set_activate_function(nuv->priv->sinkpad, + gst_nuv_demux_sink_activate); + gst_pad_set_activatepull_function(nuv->priv->sinkpad, + gst_nuv_demux_sink_activate_pull); + gst_pad_set_activatepush_function(nuv->priv->sinkpad, + gst_nuv_demux_sink_activate_push); + gst_pad_set_chain_function(nuv->priv->sinkpad, + GST_DEBUG_FUNCPTR(gst_nuv_demux_chain)); + gst_pad_set_event_function(nuv->priv->sinkpad, + GST_DEBUG_FUNCPTR(gst_nuv_demux_sink_event)); - gst_element_add_pad (GST_ELEMENT (nuv), nuv->priv->sinkpad); + gst_element_add_pad(GST_ELEMENT(nuv), nuv->priv->sinkpad); } static void -gst_nuv_demux_dispose (GObject * object) +gst_nuv_demux_dispose(GObject * object) { - GstNuvDemux *nuv = GST_NUV_DEMUX (object); + GstNuvDemux *nuv = GST_NUV_DEMUX(object); - if (nuv->priv->mpeg_buffer != NULL) { - gst_buffer_unref (nuv->priv->mpeg_buffer); - } + if (nuv->priv->mpeg_buffer != NULL) + { + gst_buffer_unref(nuv->priv->mpeg_buffer); + } - gst_nuv_demux_reset (GST_NUV_DEMUX (object)); - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (object)); + gst_nuv_demux_reset(GST_NUV_DEMUX(object)); + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(object)); - if (nuv->priv->adapter != NULL) { - gst_object_unref (nuv->priv->adapter); - } + if (nuv->priv->adapter != NULL) + { + gst_object_unref(nuv->priv->adapter); + } } static void -gst_nuv_demux_finalize (GObject * object) +gst_nuv_demux_finalize(GObject * object) { - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS(parent_class)->finalize(object); } /* HeaderLoad: */ static GstFlowReturn -gst_nuv_demux_header_load (GstNuvDemux * nuv, nuv_header *h) +gst_nuv_demux_header_load(GstNuvDemux * nuv, nuv_header * h) { GstBuffer *buffer = NULL; - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 72, TRUE, &buffer); + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 72, TRUE, &buffer); - if ((res != GST_FLOW_OK) || (buffer == NULL)) { - goto done; - } + if ((res != GST_FLOW_OK) || (buffer == NULL)) + { + goto done; + } - if (h != NULL) { - memcpy (h->id, buffer->data, 12); - memcpy (h->version, buffer->data + 12, 5); - h->i_width = GST_READ_UINT32_LE (&buffer->data[20]); - h->i_height = GST_READ_UINT32_LE (&buffer->data[24]); - h->i_width_desired = GST_READ_UINT32_LE (&buffer->data[28]); - h->i_height_desired = GST_READ_UINT32_LE (&buffer->data[32]); - h->i_mode = GPOINTER_TO_INT (buffer->data[36]); - h->d_aspect = READ_DOUBLE_FROM_LE (&buffer->data[40]); - h->d_fps = READ_DOUBLE_FROM_LE (&buffer->data[48]); - /* get the num and denom values from fps */ - double2fraction (h->d_fps, &h->i_fpsn, &h->i_fpsd); - h->i_video_blocks = GST_READ_UINT32_LE (&buffer->data[56]); - h->i_audio_blocks = GST_READ_UINT32_LE (&buffer->data[60]); - h->i_text_blocks = GST_READ_UINT32_LE (&buffer->data[64]); - h->i_keyframe_distance = GST_READ_UINT32_LE (&buffer->data[68]); + if (h != NULL) + { + memcpy(h->id, buffer->data, 12); + memcpy(h->version, buffer->data + 12, 5); + h->i_width = GST_READ_UINT32_LE(&buffer->data[20]); + h->i_height = GST_READ_UINT32_LE(&buffer->data[24]); + h->i_width_desired = GST_READ_UINT32_LE(&buffer->data[28]); + h->i_height_desired = GST_READ_UINT32_LE(&buffer->data[32]); + h->i_mode = GPOINTER_TO_INT(buffer->data[36]); + h->d_aspect = READ_DOUBLE_FROM_LE(&buffer->data[40]); + h->d_fps = READ_DOUBLE_FROM_LE(&buffer->data[48]); + /* get the num and denom values from fps */ + double2fraction(h->d_fps, &h->i_fpsn, &h->i_fpsd); + h->i_video_blocks = GST_READ_UINT32_LE(&buffer->data[56]); + h->i_audio_blocks = GST_READ_UINT32_LE(&buffer->data[60]); + h->i_text_blocks = GST_READ_UINT32_LE(&buffer->data[64]); + h->i_keyframe_distance = GST_READ_UINT32_LE(&buffer->data[68]); - GST_DEBUG_OBJECT (nuv, - "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", h->id, - h->version, h->i_width, h->i_height, h->d_aspect, h->d_fps, - h->i_video_blocks, h->i_audio_blocks, h->i_text_blocks, - h->i_keyframe_distance); - } + GST_DEBUG_OBJECT(nuv, + "nuv: h=%s v=%s %dx%d a=%f fps=%f v=%d a=%d t=%d kfd=%d", + h->id, h->version, h->i_width, h->i_height, + h->d_aspect, h->d_fps, h->i_video_blocks, + h->i_audio_blocks, h->i_text_blocks, + h->i_keyframe_distance); + } done: - if (buffer != NULL) { - gst_buffer_unref (buffer); - buffer = NULL; - } + if (buffer != NULL) + { + gst_buffer_unref(buffer); + buffer = NULL; + } return res; } static GstFlowReturn -gst_nuv_demux_stream_header_data (GstNuvDemux * nuv) +gst_nuv_demux_stream_header_data(GstNuvDemux * nuv) { GstFlowReturn res; - if (nuv->priv->new_file) - res = gst_nuv_demux_header_load (nuv, NULL); + if (nuv->priv->new_file) + res = gst_nuv_demux_header_load(nuv, NULL); else - res = gst_nuv_demux_header_load (nuv, &nuv->priv->h); + res = gst_nuv_demux_header_load(nuv, &nuv->priv->h); if (res == GST_FLOW_OK) - nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA; + nuv->priv->state = GST_NUV_DEMUX_EXTRA_DATA; return res; } @@ -485,258 +510,286 @@ * Read NUV file tag */ static GstFlowReturn -gst_nuv_demux_stream_file_header (GstNuvDemux * nuv) +gst_nuv_demux_stream_file_header(GstNuvDemux * nuv) { GstFlowReturn res = GST_FLOW_OK; GstBuffer *file_header = NULL; - res = gst_nuv_demux_read_bytes (nuv, 12, FALSE, &file_header); - if (res == GST_FLOW_OK) { - if (strncmp ((gchar *) file_header->data, "MythTVVideo", 11) || - strncmp ((gchar *) file_header->data, "NuppelVideo", 11)) { - nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA; - } else { - GST_DEBUG_OBJECT (nuv, "error parsing file header"); - nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA; - res = GST_FLOW_ERROR; - } - } + res = gst_nuv_demux_read_bytes(nuv, 12, FALSE, &file_header); + if (res == GST_FLOW_OK) + { + if (strncmp((gchar *) file_header->data, "MythTVVideo", 11) || + strncmp((gchar *) file_header->data, "NuppelVideo", 11)) + { + nuv->priv->state = GST_NUV_DEMUX_HEADER_DATA; + } + else + { + GST_DEBUG_OBJECT(nuv, "error parsing file header"); + nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA; + res = GST_FLOW_ERROR; + } + } - if (file_header != NULL) { - gst_buffer_unref (file_header); - file_header = NULL; - } + if (file_header != NULL) + { + gst_buffer_unref(file_header); + file_header = NULL; + } return res; } /* FrameHeaderLoad: */ static GstFlowReturn -gst_nuv_demux_frame_header_load (GstNuvDemux * nuv, nuv_frame_header *h) +gst_nuv_demux_frame_header_load(GstNuvDemux * nuv, nuv_frame_header * h) { unsigned char *data; GstBuffer *buf = NULL; - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 12, TRUE, &buf); + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 12, TRUE, &buf); - if ((res != GST_FLOW_OK) || (buf == NULL)) { - goto done; - } + if ((res != GST_FLOW_OK) || (buf == NULL)) + { + goto done; + } if (h == NULL) goto done; - + data = buf->data; - h->i_type = GPOINTER_TO_INT (data[0]); - h->i_compression = GPOINTER_TO_INT (data[1]); - h->i_keyframe = GPOINTER_TO_INT (data[2]); - h->i_filters = GPOINTER_TO_INT (data[3]); - h->i_timecode = GST_READ_UINT32_LE (&data[4]); - h->i_length = GST_READ_UINT32_LE (&data[8]); + h->i_type = GPOINTER_TO_INT(data[0]); + h->i_compression = GPOINTER_TO_INT(data[1]); + h->i_keyframe = GPOINTER_TO_INT(data[2]); + h->i_filters = GPOINTER_TO_INT(data[3]); + h->i_timecode = GST_READ_UINT32_LE(&data[4]); + h->i_length = GST_READ_UINT32_LE(&data[8]); - GST_DEBUG_OBJECT (nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d", - h->i_type, - h->i_compression ? h->i_compression : ' ', - h->i_keyframe ? h->i_keyframe : ' ', - h->i_filters, h->i_timecode, h->i_length); + GST_DEBUG_OBJECT(nuv, "frame hdr: t=%c c=%c k=%d f=0x%x timecode=%d l=%d", + h->i_type, + h->i_compression ? h->i_compression : ' ', + h->i_keyframe ? h->i_keyframe : ' ', + h->i_filters, h->i_timecode, h->i_length); -done: - if (buf != NULL) { - gst_buffer_unref (buf); - buf = NULL; - } +done: + if (buf != NULL) + { + gst_buffer_unref(buf); + buf = NULL; + } return res; } static GstFlowReturn -gst_nuv_demux_extended_header_load (GstNuvDemux * nuv, - nuv_extended_header * h) +gst_nuv_demux_extended_header_load(GstNuvDemux * nuv, nuv_extended_header * h) { unsigned char *data; GstBuffer *buff = NULL; - GstFlowReturn res = gst_nuv_demux_read_bytes (nuv, 512, TRUE, &buff); + GstFlowReturn res = gst_nuv_demux_read_bytes(nuv, 512, TRUE, &buff); - if ((res != GST_FLOW_OK) || (buff == NULL)) { - goto done; - } + if ((res != GST_FLOW_OK) || (buff == NULL)) + { + goto done; + } if (h == NULL) - goto done; + goto done; data = buff->data; - h->i_version = GST_READ_UINT32_LE (&data[0]); - h->i_video_fcc = GST_MAKE_FOURCC (data[4], data[5], data[6], data[7]); - h->i_audio_fcc = GST_MAKE_FOURCC (data[8], data[9], data[10], data[11]); - h->i_audio_sample_rate = GST_READ_UINT32_LE (&data[12]); - h->i_audio_bits_per_sample = GST_READ_UINT32_LE (&data[16]); - h->i_audio_channels = GST_READ_UINT32_LE (&data[20]); - h->i_audio_compression_ratio = GST_READ_UINT32_LE (&data[24]); - h->i_audio_quality = GST_READ_UINT32_LE (&data[28]); - h->i_rtjpeg_quality = GST_READ_UINT32_LE (&data[32]); - h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE (&data[36]); - h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE (&data[40]); - h->i_lavc_bitrate = GST_READ_UINT32_LE (&data[44]); - h->i_lavc_qmin = GST_READ_UINT32_LE (&data[48]); - h->i_lavc_qmin = GST_READ_UINT32_LE (&data[52]); - h->i_lavc_maxqdiff = GST_READ_UINT32_LE (&data[56]); - h->i_seekable_offset = GST_READ_UINT64_LE (&data[60]); - h->i_keyframe_adjust_offset = GST_READ_UINT64_LE (&data[68]); + h->i_version = GST_READ_UINT32_LE(&data[0]); + h->i_video_fcc = GST_MAKE_FOURCC(data[4], data[5], data[6], data[7]); + h->i_audio_fcc = GST_MAKE_FOURCC(data[8], data[9], data[10], data[11]); + h->i_audio_sample_rate = GST_READ_UINT32_LE(&data[12]); + h->i_audio_bits_per_sample = GST_READ_UINT32_LE(&data[16]); + h->i_audio_channels = GST_READ_UINT32_LE(&data[20]); + h->i_audio_compression_ratio = GST_READ_UINT32_LE(&data[24]); + h->i_audio_quality = GST_READ_UINT32_LE(&data[28]); + h->i_rtjpeg_quality = GST_READ_UINT32_LE(&data[32]); + h->i_rtjpeg_luma_filter = GST_READ_UINT32_LE(&data[36]); + h->i_rtjpeg_chroma_filter = GST_READ_UINT32_LE(&data[40]); + h->i_lavc_bitrate = GST_READ_UINT32_LE(&data[44]); + h->i_lavc_qmin = GST_READ_UINT32_LE(&data[48]); + h->i_lavc_qmin = GST_READ_UINT32_LE(&data[52]); + h->i_lavc_maxqdiff = GST_READ_UINT32_LE(&data[56]); + h->i_seekable_offset = GST_READ_UINT64_LE(&data[60]); + h->i_keyframe_adjust_offset = GST_READ_UINT64_LE(&data[68]); - GST_DEBUG_OBJECT (nuv, - "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d" - "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld", - h->i_version, (gchar *) & h->i_video_fcc, (gchar *) & h->i_audio_fcc, - h->i_audio_sample_rate, h->i_audio_bits_per_sample, h->i_audio_channels, - h->i_audio_compression_ratio, h->i_audio_quality, h->i_rtjpeg_quality, - h->i_rtjpeg_luma_filter, h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate, - h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, h->i_seekable_offset, - h->i_keyframe_adjust_offset); + GST_DEBUG_OBJECT(nuv, + "ex hdr: v=%d vffc=%4.4s afcc=%4.4s %dHz %dbits ach=%d acr=%d aq=%d" + "rtjpeg q=%d lf=%d lc=%d lavc br=%d qmin=%d qmax=%d maxqdiff=%d seekableoff=%lld keyfao=%lld", + h->i_version, (gchar *) & h->i_video_fcc, + (gchar *) & h->i_audio_fcc, h->i_audio_sample_rate, + h->i_audio_bits_per_sample, h->i_audio_channels, + h->i_audio_compression_ratio, h->i_audio_quality, + h->i_rtjpeg_quality, h->i_rtjpeg_luma_filter, + h->i_rtjpeg_chroma_filter, h->i_lavc_bitrate, + h->i_lavc_qmin, h->i_lavc_qmax, h->i_lavc_maxqdiff, + h->i_seekable_offset, h->i_keyframe_adjust_offset); done: - if (buff != NULL) { - gst_buffer_unref (buff); - buff = NULL; - } + if (buff != NULL) + { + gst_buffer_unref(buff); + buff = NULL; + } return res; } /* Query Functions */ static const GstQueryType * -gst_nuv_demux_get_src_query_types (GstPad * pad) +gst_nuv_demux_get_src_query_types(GstPad * pad) { static const GstQueryType src_types[] = { - GST_QUERY_POSITION, - GST_QUERY_DURATION, - 0 + GST_QUERY_POSITION, + GST_QUERY_DURATION, + 0 }; return src_types; } static gboolean -gst_nuv_demux_handle_src_query (GstPad * pad, GstQuery * query) +gst_nuv_demux_handle_src_query(GstPad * pad, GstQuery * query) { gboolean res = FALSE; - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad)); - switch (GST_QUERY_TYPE (query)) - { - case GST_QUERY_POSITION: + switch (GST_QUERY_TYPE(query)) { + case GST_QUERY_POSITION: + { GstFormat format; - gst_query_parse_position (query, &format, NULL); - switch (format) - { - case GST_FORMAT_TIME: - if (GST_CLOCK_TIME_IS_VALID (nuv->priv->last_frame_time)) { - gst_query_set_position (query, GST_FORMAT_TIME, nuv->priv->last_frame_time); - res = TRUE; - } - break; - default: - break; - } + gst_query_parse_position(query, &format, NULL); + switch (format) + { + case GST_FORMAT_TIME: + if (GST_CLOCK_TIME_IS_VALID(nuv->priv->last_frame_time)) + { + gst_query_set_position(query, GST_FORMAT_TIME, + nuv->priv->last_frame_time); + res = TRUE; + } + break; + default: + break; + } break; - } - case GST_QUERY_DURATION: - { - GstFormat format; - gst_query_parse_duration (query, &format, NULL); - switch (format) + } + case GST_QUERY_DURATION: { - case GST_FORMAT_TIME: - if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) { - gst_query_set_duration (query, GST_FORMAT_TIME, nuv->priv->duration_time); - res = TRUE; - } - break; - default: - break; + GstFormat format; + gst_query_parse_duration(query, &format, NULL); + switch (format) + { + case GST_FORMAT_TIME: + if (nuv->priv->duration_time != GST_CLOCK_TIME_NONE) + { + gst_query_set_duration(query, GST_FORMAT_TIME, + nuv->priv->duration_time); + res = TRUE; + } + break; + default: + break; + } + break; } - break; - } default: break; - } + } - if (res==FALSE) { - res = gst_pad_query_default (pad, query); - } + if (res == FALSE) + { + res = gst_pad_query_default(pad, query); + } - gst_object_unref (nuv); + gst_object_unref(nuv); return res; } -static GstPad* -gst_nuv_demux_create_pad (GstNuvDemux *nuv, GstCaps *caps, GstStaticPadTemplate *template, const gchar* name) +static GstPad * +gst_nuv_demux_create_pad(GstNuvDemux * nuv, GstCaps * caps, + GstStaticPadTemplate * template, const gchar * name) { - GstPad *pad = NULL; - pad = gst_pad_new_from_static_template (template, name); - gst_pad_set_caps (pad, caps); - gst_pad_set_active (pad, TRUE); - gst_pad_use_fixed_caps (pad); - gst_element_add_pad (GST_ELEMENT (nuv), pad); + GstPad *pad = NULL; + pad = gst_pad_new_from_static_template(template, name); + gst_pad_set_caps(pad, caps); + gst_pad_set_active(pad, TRUE); + gst_pad_use_fixed_caps(pad); + gst_element_add_pad(GST_ELEMENT(nuv), pad); - gst_pad_set_event_function (pad, - GST_DEBUG_FUNCPTR (gst_nuv_demux_srcpad_event)); + gst_pad_set_event_function(pad, + GST_DEBUG_FUNCPTR(gst_nuv_demux_srcpad_event)); - gst_pad_set_query_type_function (pad, - GST_DEBUG_FUNCPTR (gst_nuv_demux_get_src_query_types)); + gst_pad_set_query_type_function(pad, + GST_DEBUG_FUNCPTR + (gst_nuv_demux_get_src_query_types)); - gst_pad_set_query_function (pad, - GST_DEBUG_FUNCPTR (gst_nuv_demux_handle_src_query)); - + gst_pad_set_query_function(pad, + GST_DEBUG_FUNCPTR + (gst_nuv_demux_handle_src_query)); - return pad; + + return pad; } static void -gst_nuv_demux_create_pads (GstNuvDemux * nuv) +gst_nuv_demux_create_pads(GstNuvDemux * nuv) { - if (nuv->priv->h.i_video_blocks != 0) { - GstCaps *video_caps = NULL; + if (nuv->priv->h.i_video_blocks != 0) + { + GstCaps *video_caps = NULL; - video_caps = gst_caps_new_simple ("video/x-divx", - "divxversion", G_TYPE_INT, 4, - "width", G_TYPE_INT, nuv->priv->h.i_width, - "height", G_TYPE_INT, nuv->priv->h.i_height, - "framerate", GST_TYPE_FRACTION, nuv->priv->h.i_fpsn, nuv->priv->h.i_fpsd, - "format", GST_TYPE_FOURCC, nuv->priv->eh.i_video_fcc, - "pixel-aspect-ratio", GST_TYPE_FRACTION, - (gint) (nuv->priv->h.d_aspect * 1000.0f), 1000, NULL); + video_caps = gst_caps_new_simple("video/x-divx", + "divxversion", G_TYPE_INT, 4, + "width", G_TYPE_INT, + nuv->priv->h.i_width, "height", + G_TYPE_INT, nuv->priv->h.i_height, + "framerate", GST_TYPE_FRACTION, + nuv->priv->h.i_fpsn, + nuv->priv->h.i_fpsd, "format", + GST_TYPE_FOURCC, + nuv->priv->eh.i_video_fcc, + "pixel-aspect-ratio", + GST_TYPE_FRACTION, + (gint) (nuv->priv->h.d_aspect * + 1000.0f), 1000, NULL); - nuv->priv->src_video_pad = gst_nuv_demux_create_pad (nuv, video_caps, &video_src_template, "video_src"); - gst_caps_unref (video_caps); - } + nuv->priv->src_video_pad = + gst_nuv_demux_create_pad(nuv, video_caps, &video_src_template, + "video_src"); + gst_caps_unref(video_caps); + } - if (nuv->priv->h.i_audio_blocks != 0) { - GstCaps *audio_caps = NULL; + if (nuv->priv->h.i_audio_blocks != 0) + { + GstCaps *audio_caps = NULL; - audio_caps = gst_caps_new_simple ("audio/mpeg", - "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate, - "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc, - "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels, - "layer", G_TYPE_INT, 3, // fixme: magic number - "mpegversion", G_TYPE_INT, nuv->priv->eh.i_version, NULL); - - nuv->priv->src_audio_pad = gst_nuv_demux_create_pad (nuv, audio_caps, &audio_src_template, "audio_src"); - gst_caps_unref (audio_caps); - } + audio_caps = gst_caps_new_simple("audio/mpeg", "rate", G_TYPE_INT, nuv->priv->eh.i_audio_sample_rate, "format", GST_TYPE_FOURCC, nuv->priv->eh.i_audio_fcc, "channels", G_TYPE_INT, nuv->priv->eh.i_audio_channels, "layer", G_TYPE_INT, 3, // fixme: magic number + "mpegversion", G_TYPE_INT, + nuv->priv->eh.i_version, NULL); - gst_element_no_more_pads (GST_ELEMENT (nuv)); + nuv->priv->src_audio_pad = + gst_nuv_demux_create_pad(nuv, audio_caps, &audio_src_template, + "audio_src"); + gst_caps_unref(audio_caps); + } + + gst_element_no_more_pads(GST_ELEMENT(nuv)); } static gboolean -gst_nuv_demux_validate_header (nuv_frame_header *h) +gst_nuv_demux_validate_header(nuv_frame_header * h) { gboolean valid = FALSE; - //g_usleep (1 * G_USEC_PER_SEC ); - switch (h->i_type) { + //g_usleep (1 * G_USEC_PER_SEC ); + switch (h->i_type) + { /* case 'V': if (h->i_compression == 0 || @@ -768,63 +821,65 @@ } break; */ - case 'A': - case 'V': - case 'S': - case 'R': - case 'D': - case 'Q': - valid = TRUE; - break; - default: - valid = FALSE; - } + case 'A': + case 'V': + case 'S': + case 'R': + case 'D': + case 'Q': + valid = TRUE; + break; + default: + valid = FALSE; + } return valid; } static GstFlowReturn -gst_nuv_demux_read_head_frame (GstNuvDemux * nuv) +gst_nuv_demux_read_head_frame(GstNuvDemux * nuv) { GstFlowReturn ret = GST_FLOW_OK; gboolean valid = FALSE; - do { - ret = gst_nuv_demux_frame_header_load (nuv, &nuv->priv->fh); - if (ret != GST_FLOW_OK) { - return ret; - } + do + { + ret = gst_nuv_demux_frame_header_load(nuv, &nuv->priv->fh); + if (ret != GST_FLOW_OK) + { + return ret; + } - if (gst_nuv_demux_validate_header (&nuv->priv->fh) == TRUE) - valid = TRUE; + if (gst_nuv_demux_validate_header(&nuv->priv->fh) == TRUE) + valid = TRUE; - } while (valid == FALSE); + } + while (valid == FALSE); nuv->priv->state = GST_NUV_DEMUX_MOVI; return ret; } static gboolean -gst_nuv_combine_flow (GstNuvDemux *nuv) +gst_nuv_combine_flow(GstNuvDemux * nuv) { - GstFlowReturn ret_video = nuv->priv->last_video_return; - GstFlowReturn ret_audio = nuv->priv->last_audio_return; + GstFlowReturn ret_video = nuv->priv->last_video_return; + GstFlowReturn ret_audio = nuv->priv->last_audio_return; - if ((ret_video != GST_FLOW_OK) && - (ret_audio != GST_FLOW_OK)) - return FALSE; + if ((ret_video != GST_FLOW_OK) && (ret_audio != GST_FLOW_OK)) + return FALSE; - if (GST_FLOW_IS_FATAL (ret_video)) - return FALSE; + if (GST_FLOW_IS_FATAL(ret_video)) + return FALSE; - if (GST_FLOW_IS_FATAL (ret_audio)) - return FALSE; + if (GST_FLOW_IS_FATAL(ret_audio)) + return FALSE; - return TRUE; + return TRUE; } static GstFlowReturn -gst_nuv_demux_stream_data (GstNuvDemux * nuv) +gst_nuv_demux_stream_data(GstNuvDemux * nuv) { GstFlowReturn ret = GST_FLOW_OK; GstPad *pad = NULL; @@ -834,539 +889,653 @@ h = nuv->priv->fh; - if (h.i_type == 'R') { - goto done; - } - - if (h.i_length > 0) { - ret = gst_nuv_demux_read_bytes (nuv, h.i_length, TRUE, &buf); - if ((ret != GST_FLOW_OK) || (buf == NULL)) { - goto done; - } - - if ((h.i_timecode < 0)) { - h.i_timecode = 0; - //goto done; - } - - timestamp = h.i_timecode * GST_MSECOND; - GST_BUFFER_TIMESTAMP (buf) = timestamp; - } - else { - goto done; - } - - - switch (h.i_type) { - case 'V': - { - pad = nuv->priv->src_video_pad; - - if (nuv->priv->new_video_segment) { - - /* send new segment event*/ - gst_pad_push_event (nuv->priv->src_video_pad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, - GST_CLOCK_TIME_NONE, 0)); - - if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) { - nuv->priv->time_start = timestamp; - } - nuv->priv->new_video_segment = FALSE; - } - - break; - } - case 'A': - { - pad = nuv->priv->src_audio_pad; - - if (nuv->priv->new_audio_segment) { - /* send new segment event*/ - gst_pad_push_event (nuv->priv->src_audio_pad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, - GST_CLOCK_TIME_NONE, 0)); - - if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) { - nuv->priv->time_start = timestamp; - } - nuv->priv->new_audio_segment = FALSE; - } - - break; - } - case 'S': - { - switch (h.i_compression) { - case 'V': - GST_DEBUG_OBJECT (nuv, "sending new video segment: %d", h.i_timecode); - gst_pad_push_event (nuv->priv->src_video_pad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, h.i_timecode * GST_MSECOND, - GST_CLOCK_TIME_NONE, 0)); - break; - case 'A': - GST_DEBUG_OBJECT (nuv, "sending new audio segment: %d", h.i_timecode); - gst_pad_push_event (nuv->priv->src_audio_pad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, - GST_CLOCK_TIME_NONE, 0)); - break; - default: - break; - } - goto done; - } - default: - break; - } - - if ((buf != NULL) && (pad != NULL)) { - /* pushing the buffer */ - gst_buffer_set_caps (buf, GST_PAD_CAPS (pad)); - ret = gst_pad_push (pad, buf); - buf = NULL; - - if (ret != GST_FLOW_OK) { - GST_WARNING_OBJECT (nuv, "error: %d pushing on srcpad %s", ret, gst_pad_get_name (pad)); - - if (pad == nuv->priv->src_video_pad) { - nuv->priv->last_video_return = ret; - } - else if (pad == nuv->priv->src_audio_pad) { - nuv->priv->last_audio_return = ret; - } - - /* verify anothers flow if is necessary stop task */ - if (gst_nuv_combine_flow (nuv) != FALSE) { - ret = GST_FLOW_OK; - } else { - GST_WARNING_OBJECT (nuv, "error: on push"); + if (h.i_type == 'R') + { + goto done; } - } - } + if (h.i_length > 0) + { + ret = gst_nuv_demux_read_bytes(nuv, h.i_length, TRUE, &buf); + if ((ret != GST_FLOW_OK) || (buf == NULL)) + { + goto done; + } + + if ((h.i_timecode < 0)) + { + h.i_timecode = 0; + //goto done; + } + + timestamp = h.i_timecode * GST_MSECOND; + GST_BUFFER_TIMESTAMP(buf) = timestamp; + } + else + { + goto done; + } + + + switch (h.i_type) + { + case 'V': + { + pad = nuv->priv->src_video_pad; + + if (nuv->priv->new_video_segment) + { + + /* send new segment event */ + gst_pad_push_event(nuv->priv->src_video_pad, + gst_event_new_new_segment(TRUE, 1.0, + GST_FORMAT_TIME, 0, + GST_CLOCK_TIME_NONE, + 0)); + + if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) + { + nuv->priv->time_start = timestamp; + } + nuv->priv->new_video_segment = FALSE; + } + + break; + } + case 'A': + { + pad = nuv->priv->src_audio_pad; + + if (nuv->priv->new_audio_segment) + { + /* send new segment event */ + gst_pad_push_event(nuv->priv->src_audio_pad, + gst_event_new_new_segment(TRUE, 1.0, + GST_FORMAT_TIME, 0, + GST_CLOCK_TIME_NONE, + 0)); + + if (nuv->priv->time_start == GST_CLOCK_TIME_NONE) + { + nuv->priv->time_start = timestamp; + } + nuv->priv->new_audio_segment = FALSE; + } + + break; + } + case 'S': + { + switch (h.i_compression) + { + case 'V': + GST_DEBUG_OBJECT(nuv, "sending new video segment: %d", + h.i_timecode); + gst_pad_push_event(nuv->priv->src_video_pad, + gst_event_new_new_segment(TRUE, 1.0, + GST_FORMAT_TIME, + h.i_timecode * + GST_MSECOND, + GST_CLOCK_TIME_NONE, + 0)); + break; + case 'A': + GST_DEBUG_OBJECT(nuv, "sending new audio segment: %d", + h.i_timecode); + gst_pad_push_event(nuv->priv->src_audio_pad, + gst_event_new_new_segment(TRUE, 1.0, + GST_FORMAT_TIME, 0, + GST_CLOCK_TIME_NONE, + 0)); + break; + default: + break; + } + goto done; + } + default: + break; + } + + if ((buf != NULL) && (pad != NULL)) + { + /* pushing the buffer */ + gst_buffer_set_caps(buf, GST_PAD_CAPS(pad)); + ret = gst_pad_push(pad, buf); + buf = NULL; + + if (ret != GST_FLOW_OK) + { + GST_WARNING_OBJECT(nuv, "error: %d pushing on srcpad %s", ret, + gst_pad_get_name(pad)); + + if (pad == nuv->priv->src_video_pad) + { + nuv->priv->last_video_return = ret; + } + else if (pad == nuv->priv->src_audio_pad) + { + nuv->priv->last_audio_return = ret; + } + + /* verify anothers flow if is necessary stop task */ + if (gst_nuv_combine_flow(nuv) != FALSE) + { + ret = GST_FLOW_OK; + } + else + { + GST_WARNING_OBJECT(nuv, "error: on push"); + } + + } + } done: - if (buf != NULL) { - gst_buffer_unref (buf); - buf = NULL; - } - if (ret == GST_FLOW_OK) { - nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER; - memset (&nuv->priv->fh, 0, sizeof (nuv->priv->fh)); - } + if (buf != NULL) + { + gst_buffer_unref(buf); + buf = NULL; + } + if (ret == GST_FLOW_OK) + { + nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER; + memset(&nuv->priv->fh, 0, sizeof(nuv->priv->fh)); + } return ret; } static GstFlowReturn -gst_nuv_demux_stream_mpeg_data (GstNuvDemux * nuv) +gst_nuv_demux_stream_mpeg_data(GstNuvDemux * nuv) { GstFlowReturn ret = GST_FLOW_OK; - /* ffmpeg extra data */ - if (nuv->priv->new_file) { - GstBuffer *buf; - ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, &buf); - gst_buffer_unref (buf); - } else { - ret = gst_nuv_demux_read_bytes (nuv, nuv->priv->mpeg_data_size, TRUE, - &nuv->priv->mpeg_buffer); - } + /* ffmpeg extra data */ + if (nuv->priv->new_file) + { + GstBuffer *buf; + ret = + gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE, &buf); + gst_buffer_unref(buf); + } + else + { + ret = gst_nuv_demux_read_bytes(nuv, nuv->priv->mpeg_data_size, TRUE, + &nuv->priv->mpeg_buffer); + } - if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) { - return ret; - } + if ((ret != GST_FLOW_OK) || (nuv->priv->mpeg_buffer == NULL)) + { + return ret; + } - GST_BUFFER_SIZE (nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size; + GST_BUFFER_SIZE(nuv->priv->mpeg_buffer) = nuv->priv->mpeg_data_size; nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER; return ret; } static GstFlowReturn -gst_nuv_demux_stream_extra_data (GstNuvDemux * nuv) +gst_nuv_demux_stream_extra_data(GstNuvDemux * nuv) { GstFlowReturn ret = GST_FLOW_OK; - /* Load 'D' */ + /* Load 'D' */ nuv_frame_header h; - if (nuv->priv->new_file) - ret = gst_nuv_demux_frame_header_load (nuv, NULL); - else - ret = gst_nuv_demux_frame_header_load (nuv, &h); + if (nuv->priv->new_file) + ret = gst_nuv_demux_frame_header_load(nuv, NULL); + else + ret = gst_nuv_demux_frame_header_load(nuv, &h); if (ret != GST_FLOW_OK) - return ret; + return ret; - if (h.i_type != 'D') { - GST_WARNING_OBJECT (nuv, "Unsuported rtjpeg"); - return GST_FLOW_NOT_SUPPORTED; - } + if (h.i_type != 'D') + { + GST_WARNING_OBJECT(nuv, "Unsuported rtjpeg"); + return GST_FLOW_NOT_SUPPORTED; + } - if (h.i_length > 0) { - if (h.i_compression == 'F') { - nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA; - } else { - GST_WARNING_OBJECT (nuv, "only file with extended chunk are supported"); - return GST_FLOW_NOT_SUPPORTED; - } - } else { - nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER; - } + if (h.i_length > 0) + { + if (h.i_compression == 'F') + { + nuv->priv->state = GST_NUV_DEMUX_MPEG_DATA; + } + else + { + GST_WARNING_OBJECT(nuv, + "only file with extended chunk are supported"); + return GST_FLOW_NOT_SUPPORTED; + } + } + else + { + nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER; + } return ret; } static GstFlowReturn -gst_nuv_demux_stream_extend_header_data (GstNuvDemux * nuv) +gst_nuv_demux_stream_extend_header_data(GstNuvDemux * nuv) { GstFlowReturn ret = GST_FLOW_OK; if (nuv->priv->new_file) - ret = gst_nuv_demux_extended_header_load (nuv, NULL); - else { - ret = gst_nuv_demux_extended_header_load (nuv, &nuv->priv->eh); + ret = gst_nuv_demux_extended_header_load(nuv, NULL); + else + { + ret = gst_nuv_demux_extended_header_load(nuv, &nuv->priv->eh); if (ret != GST_FLOW_OK) - return ret; - gst_nuv_demux_create_pads (nuv); - } + return ret; + gst_nuv_demux_create_pads(nuv); + } nuv->priv->state = GST_NUV_DEMUX_INDEX_CREATE; return ret; } static GstFlowReturn -gst_nuv_demux_stream_extend_header (GstNuvDemux * nuv) +gst_nuv_demux_stream_extend_header(GstNuvDemux * nuv) { GstBuffer *buf = NULL; GstFlowReturn res = GST_FLOW_OK; - res = gst_nuv_demux_read_bytes (nuv, 1, FALSE, &buf); - if ((res != GST_FLOW_OK) || (buf == NULL)) { - if (buf != NULL) { - gst_buffer_unref (buf); - } - return res; - } + res = gst_nuv_demux_read_bytes(nuv, 1, FALSE, &buf); + if ((res != GST_FLOW_OK) || (buf == NULL)) + { + if (buf != NULL) + { + gst_buffer_unref(buf); + } + return res; + } - if (buf->data[0] == 'X') { - gst_buffer_unref (buf); - buf = NULL; - nuv_frame_header h; + if (buf->data[0] == 'X') + { + gst_buffer_unref(buf); + buf = NULL; + nuv_frame_header h; - res = gst_nuv_demux_frame_header_load (nuv, &h); - if (res != GST_FLOW_OK) - return res; + res = gst_nuv_demux_frame_header_load(nuv, &h); + if (res != GST_FLOW_OK) + return res; - if (h.i_length != 512) { - return GST_FLOW_ERROR; - } - nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA; - } else { - nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA; - g_object_unref (buf); - GST_ELEMENT_WARNING (nuv, STREAM, FAILED, - (_("incomplete NUV support")), ("incomplete NUV support")); - return GST_FLOW_ERROR; - } + if (h.i_length != 512) + { + return GST_FLOW_ERROR; + } + nuv->priv->state = GST_NUV_DEMUX_EXTEND_HEADER_DATA; + } + else + { + nuv->priv->state = GST_NUV_DEMUX_INVALID_DATA; + g_object_unref(buf); + GST_ELEMENT_WARNING(nuv, STREAM, FAILED, + (_("incomplete NUV support")), + ("incomplete NUV support")); + return GST_FLOW_ERROR; + } return res; } static void -gst_nuv_demux_create_seek_index (GstNuvDemux * nuv) +gst_nuv_demux_create_seek_index(GstNuvDemux * nuv) { GstMessage *msg; nuv_frame_header h; - while (gst_nuv_demux_frame_header_load (nuv, &h) == GST_FLOW_OK) { - if ((h.i_type == 'V') && (h.i_keyframe == 0)) { - frame_index_data *f = g_new0 (frame_index_data, 1); + while (gst_nuv_demux_frame_header_load(nuv, &h) == GST_FLOW_OK) + { + if ((h.i_type == 'V') && (h.i_keyframe == 0)) + { + frame_index_data *f = g_new0(frame_index_data, 1); - f->offset = nuv->priv->offset - 12; - f->timecode = h.i_timecode * GST_MSECOND; + f->offset = nuv->priv->offset - 12; + f->timecode = h.i_timecode * GST_MSECOND; - nuv->priv->index = g_slist_append (nuv->priv->index, f); - } - if (h.i_type != 'R') { - nuv->priv->offset += h.i_length; + nuv->priv->index = g_slist_append(nuv->priv->index, f); + } + if (h.i_type != 'R') + { + nuv->priv->offset += h.i_length; if (h.i_type == 'A' || h.i_type == 'V') - nuv->priv->duration_time = h.i_timecode * GST_MSECOND; - } - } - GST_DEBUG_OBJECT (nuv, "CREATING INDEX: DONE : DURATION Bytes/Sec: %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, - nuv->priv->offset, nuv->priv->duration_time); - + nuv->priv->duration_time = h.i_timecode * GST_MSECOND; + } + } + GST_DEBUG_OBJECT(nuv, + "CREATING INDEX: DONE : DURATION Bytes/Sec: %" + G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, nuv->priv->offset, + nuv->priv->duration_time); + nuv->priv->duration_bytes = nuv->priv->offset; nuv->priv->offset = nuv->priv->header_lengh; - msg = gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, nuv->priv->duration_time); - gst_element_post_message (GST_ELEMENT (nuv), msg); + msg = + gst_message_new_duration(GST_OBJECT(nuv), GST_FORMAT_TIME, + nuv->priv->duration_time); + gst_element_post_message(GST_ELEMENT(nuv), msg); } static GstFlowReturn -gst_nuv_demux_play (GstPad * pad) +gst_nuv_demux_play(GstPad * pad) { GstFlowReturn res = GST_FLOW_OK; - GstNuvDemux *nuv = GST_NUV_DEMUX (GST_PAD_PARENT (pad)); + GstNuvDemux *nuv = GST_NUV_DEMUX(GST_PAD_PARENT(pad)); - switch (nuv->priv->state) { - case GST_NUV_DEMUX_START: - res = gst_nuv_demux_stream_file_header (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + switch (nuv->priv->state) + { + case GST_NUV_DEMUX_START: + res = gst_nuv_demux_stream_file_header(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_HEADER_DATA: - res = gst_nuv_demux_stream_header_data (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_HEADER_DATA: + res = gst_nuv_demux_stream_header_data(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_EXTRA_DATA: - res = gst_nuv_demux_stream_extra_data (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_EXTRA_DATA: + res = gst_nuv_demux_stream_extra_data(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_MPEG_DATA: - res = gst_nuv_demux_stream_mpeg_data (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_MPEG_DATA: + res = gst_nuv_demux_stream_mpeg_data(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_EXTEND_HEADER: - res = gst_nuv_demux_stream_extend_header (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_EXTEND_HEADER: + res = gst_nuv_demux_stream_extend_header(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_EXTEND_HEADER_DATA: - res = gst_nuv_demux_stream_extend_header_data (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - //store file header size - nuv->priv->header_lengh = nuv->priv->offset; - break; + case GST_NUV_DEMUX_EXTEND_HEADER_DATA: + res = gst_nuv_demux_stream_extend_header_data(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + //store file header size + nuv->priv->header_lengh = nuv->priv->offset; + break; - case GST_NUV_DEMUX_INDEX_CREATE: - if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) { - gst_nuv_demux_create_seek_index (nuv); - } + case GST_NUV_DEMUX_INDEX_CREATE: + if ((nuv->priv->mode == NUV_PULL_MODE) && (!nuv->priv->new_file)) + { + gst_nuv_demux_create_seek_index(nuv); + } - case GST_NUV_DEMUX_FRAME_HEADER: - res = gst_nuv_demux_read_head_frame (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_FRAME_HEADER: + res = gst_nuv_demux_read_head_frame(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_MOVI: - res = gst_nuv_demux_stream_data (nuv); - if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) { - goto pause; - } - break; + case GST_NUV_DEMUX_MOVI: + res = gst_nuv_demux_stream_data(nuv); + if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) + { + goto pause; + } + break; - case GST_NUV_DEMUX_INVALID_DATA: - goto pause; - break; - default: - g_assert_not_reached (); - } + case GST_NUV_DEMUX_INVALID_DATA: + goto pause; + break; + default: + g_assert_not_reached(); + } return GST_FLOW_OK; pause: - GST_LOG_OBJECT (nuv, "pausing task, reason %s", gst_flow_get_name (res)); - gst_pad_pause_task (nuv->priv->sinkpad); + GST_LOG_OBJECT(nuv, "pausing task, reason %s", gst_flow_get_name(res)); + gst_pad_pause_task(nuv->priv->sinkpad); - if (res == GST_FLOW_ERROR_EOS) { - gst_nuv_demux_send_eos (nuv); - nuv->priv->eos = TRUE; - res = GST_FLOW_OK; - } + if (res == GST_FLOW_ERROR_EOS) + { + gst_nuv_demux_send_eos(nuv); + nuv->priv->eos = TRUE; + res = GST_FLOW_OK; + } - if (GST_FLOW_IS_FATAL (res)) { - GST_ELEMENT_ERROR (nuv, STREAM, FAILED, - (_("Internal data stream error.")), - ("streaming stopped, reason %s", gst_flow_get_name (res))); + if (GST_FLOW_IS_FATAL(res)) + { + GST_ELEMENT_ERROR(nuv, STREAM, FAILED, + (_("Internal data stream error.")), + ("streaming stopped, reason %s", + gst_flow_get_name(res))); - gst_nuv_demux_send_eos (nuv); - } + gst_nuv_demux_send_eos(nuv); + } return res; } static void -gst_nuv_demux_send_eos (GstNuvDemux * nuv) +gst_nuv_demux_send_eos(GstNuvDemux * nuv) { - gst_element_post_message (GST_ELEMENT (nuv), - gst_message_new_segment_done (GST_OBJECT (nuv), GST_FORMAT_TIME, -1)); + gst_element_post_message(GST_ELEMENT(nuv), + gst_message_new_segment_done(GST_OBJECT(nuv), + GST_FORMAT_TIME, -1)); if (nuv->priv->src_video_pad) - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_eos ()); + gst_pad_push_event(nuv->priv->src_video_pad, gst_event_new_eos()); if (nuv->priv->src_audio_pad) - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_eos ()); + gst_pad_push_event(nuv->priv->src_audio_pad, gst_event_new_eos()); } static GstFlowReturn -gst_nuv_demux_read_bytes (GstNuvDemux * nuv, guint64 size, gboolean move, - GstBuffer ** buffer) +gst_nuv_demux_read_bytes(GstNuvDemux * nuv, guint64 size, gboolean move, + GstBuffer ** buffer) { GstFlowReturn ret = GST_FLOW_OK; - if (size == 0) { - return ret; - } + if (size == 0) + { + return ret; + } - if (nuv->priv->mode == NUV_PULL_MODE) { - ret = gst_pad_pull_range (nuv->priv->sinkpad, nuv->priv->offset, size, buffer); - if (ret == GST_FLOW_OK) { - if (move) { - nuv->priv->offset += size; - } - /* got eos */ - } else if (ret == GST_FLOW_UNEXPECTED) { - return GST_FLOW_ERROR_EOS; - } - } else { - if (gst_adapter_available (nuv->priv->adapter) < size) { - nuv->priv->more_data = TRUE; - return GST_FLOW_ERROR_NO_DATA; - } - if (move) { - *buffer = gst_adapter_take_buffer (nuv->priv->adapter, size); - } else { - guint8 *data = NULL; - data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size); - *buffer = gst_buffer_new (); - gst_buffer_set_data (*buffer, data, size); - } - } + if (nuv->priv->mode == NUV_PULL_MODE) + { + ret = + gst_pad_pull_range(nuv->priv->sinkpad, nuv->priv->offset, size, + buffer); + if (ret == GST_FLOW_OK) + { + if (move) + { + nuv->priv->offset += size; + } + /* got eos */ + } + else if (ret == GST_FLOW_UNEXPECTED) + { + return GST_FLOW_ERROR_EOS; + } + } + else + { + if (gst_adapter_available(nuv->priv->adapter) < size) + { + nuv->priv->more_data = TRUE; + return GST_FLOW_ERROR_NO_DATA; + } + if (move) + { + *buffer = gst_adapter_take_buffer(nuv->priv->adapter, size); + } + else + { + guint8 *data = NULL; + data = (guint8 *) gst_adapter_peek(nuv->priv->adapter, size); + *buffer = gst_buffer_new(); + gst_buffer_set_data(*buffer, data, size); + } + } return ret; } static GstFlowReturn -gst_nuv_demux_move_bytes (GstNuvDemux * nuv, guint64 size) +gst_nuv_demux_move_bytes(GstNuvDemux * nuv, guint64 size) { GstFlowReturn ret = GST_FLOW_OK; - if (size == 0) { - return ret; - } + if (size == 0) + { + return ret; + } - if (nuv->priv->mode == NUV_PULL_MODE) { - nuv->priv->offset += size; - } else { - if (gst_adapter_available (nuv->priv->adapter) < size) { - nuv->priv->more_data = TRUE; - return GST_FLOW_ERROR_NO_DATA; - } - gst_adapter_flush (nuv->priv->adapter, size); - } + if (nuv->priv->mode == NUV_PULL_MODE) + { + nuv->priv->offset += size; + } + else + { + if (gst_adapter_available(nuv->priv->adapter) < size) + { + nuv->priv->more_data = TRUE; + return GST_FLOW_ERROR_NO_DATA; + } + gst_adapter_flush(nuv->priv->adapter, size); + } return ret; } static gboolean -gst_nuv_demux_sink_activate (GstPad * sinkpad) +gst_nuv_demux_sink_activate(GstPad * sinkpad) { gboolean res = TRUE; - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad)); - - if (gst_pad_check_pull_range (sinkpad)) { - gst_adapter_clear (nuv->priv->adapter); - res = gst_pad_activate_pull (sinkpad, TRUE); - } else { - gst_adapter_clear (nuv->priv->adapter); - res = gst_pad_activate_push (sinkpad, TRUE); - } - - g_object_unref (nuv); + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad)); + + if (gst_pad_check_pull_range(sinkpad)) + { + gst_adapter_clear(nuv->priv->adapter); + res = gst_pad_activate_pull(sinkpad, TRUE); + } + else + { + gst_adapter_clear(nuv->priv->adapter); + res = gst_pad_activate_push(sinkpad, TRUE); + } + + g_object_unref(nuv); return res; } static gboolean -gst_nuv_demux_sink_activate_pull (GstPad * sinkpad, gboolean active) +gst_nuv_demux_sink_activate_pull(GstPad * sinkpad, gboolean active) { - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (sinkpad)); + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(sinkpad)); - if (active) { - GST_DEBUG_OBJECT (nuv, "activating pull function"); - nuv->priv->mode = NUV_PULL_MODE; - gst_adapter_clear (nuv->priv->adapter); + if (active) + { + GST_DEBUG_OBJECT(nuv, "activating pull function"); + nuv->priv->mode = NUV_PULL_MODE; + gst_adapter_clear(nuv->priv->adapter); - gst_pad_start_task (sinkpad, (GstTaskFunction) gst_nuv_demux_loop, sinkpad); - } else { - GST_DEBUG_OBJECT (nuv, "deactivating pull function"); - gst_pad_stop_task (sinkpad); - } - gst_object_unref (nuv); + gst_pad_start_task(sinkpad, (GstTaskFunction) gst_nuv_demux_loop, + sinkpad); + } + else + { + GST_DEBUG_OBJECT(nuv, "deactivating pull function"); + gst_pad_stop_task(sinkpad); + } + gst_object_unref(nuv); return TRUE; } static gboolean -gst_nuv_demux_sink_activate_push (GstPad * pad, gboolean active) +gst_nuv_demux_sink_activate_push(GstPad * pad, gboolean active) { - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad)); - if (active) { - nuv->priv->mode = NUV_PUSH_MODE; - gst_adapter_clear (nuv->priv->adapter); + if (active) + { + nuv->priv->mode = NUV_PUSH_MODE; + gst_adapter_clear(nuv->priv->adapter); - GST_DEBUG_OBJECT (nuv, "activating push/chain function"); - } else { - GST_DEBUG_OBJECT (nuv, "deactivating push/chain function"); - } + GST_DEBUG_OBJECT(nuv, "activating push/chain function"); + } + else + { + GST_DEBUG_OBJECT(nuv, "deactivating push/chain function"); + } - gst_object_unref (nuv); + gst_object_unref(nuv); return TRUE; } static frame_index_data * -gst_nuv_demux_do_seek_index (GstNuvDemux *nuv, gint64 seek_pos, - gint64 segment_stop, GstFormat format) +gst_nuv_demux_do_seek_index(GstNuvDemux * nuv, gint64 seek_pos, + gint64 segment_stop, GstFormat format) { GSList *l; frame_index_data *ret = NULL; - if (nuv->priv->index == NULL) { - return NULL; - } + if (nuv->priv->index == NULL) + { + return NULL; + } - /* find keyframe closest to the requested position */ - for (l = nuv->priv->index; l != NULL; l = l->next) { - frame_index_data *f = (frame_index_data *) l->data; - gint64 pos = 0; - - if (format == GST_FORMAT_BYTES) { - pos = f->offset; - } else if (format == GST_FORMAT_TIME) { - pos = f->timecode; - } else { - return NULL; - } + /* find keyframe closest to the requested position */ + for (l = nuv->priv->index; l != NULL; l = l->next) + { + frame_index_data *f = (frame_index_data *) l->data; + gint64 pos = 0; - if (pos >= seek_pos) { - ret = f; - break; - } + if (format == GST_FORMAT_BYTES) + { + pos = f->offset; + } + else if (format == GST_FORMAT_TIME) + { + pos = f->timecode; + } + else + { + return NULL; + } - if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE) && (pos > segment_stop)) { - break; - } - } + if (pos >= seek_pos) + { + ret = f; + break; + } + + if ((segment_stop != -1) && (segment_stop != GST_CLOCK_TIME_NONE) + && (pos > segment_stop)) + { + break; + } + } return ret; } static gboolean -gst_nuv_demux_do_seek (GstNuvDemux *nuv, GstEvent * event) +gst_nuv_demux_do_seek(GstNuvDemux * nuv, GstEvent * event) { gdouble rate; GstFormat format; @@ -1381,17 +1550,19 @@ gint64 segment_stop; GstEvent *newsegment_event; - if (nuv->priv->eos) { - return FALSE; - } + if (nuv->priv->eos) + { + return FALSE; + } - if (nuv->priv->mode == NUV_PUSH_MODE) { - return FALSE; - } + if (nuv->priv->mode == NUV_PUSH_MODE) + { + return FALSE; + } - gst_event_parse_seek (event, &rate, &format, &flags, - &cur_type, &cur, &stop_type, &stop); + gst_event_parse_seek(event, &rate, &format, &flags, + &cur_type, &cur, &stop_type, &stop); @@ -1402,249 +1573,277 @@ } */ - if (rate <= 0.0) { - GST_DEBUG_OBJECT (nuv, "Can only seek with positive rate"); - return FALSE; - } - - if (cur_type == GST_SEEK_TYPE_SET) { - GST_OBJECT_LOCK (nuv); - if (gst_nuv_demux_do_seek_index (nuv, cur, -1, format) == NULL) { - GST_DEBUG_OBJECT (nuv, "No matching seek entry in index"); - GST_OBJECT_UNLOCK (nuv); - return FALSE; - } - GST_OBJECT_UNLOCK (nuv); - } + if (rate <= 0.0) + { + GST_DEBUG_OBJECT(nuv, "Can only seek with positive rate"); + return FALSE; + } + + if (cur_type == GST_SEEK_TYPE_SET) + { + GST_OBJECT_LOCK(nuv); + if (gst_nuv_demux_do_seek_index(nuv, cur, -1, format) == NULL) + { + GST_DEBUG_OBJECT(nuv, "No matching seek entry in index"); + GST_OBJECT_UNLOCK(nuv); + return FALSE; + } + GST_OBJECT_UNLOCK(nuv); + } flush = !!(flags & GST_SEEK_FLAG_FLUSH); - - if (flush) { - gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_start ()); - if (nuv->priv->src_video_pad != NULL) { - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_start ()); - } - if (nuv->priv->src_audio_pad != NULL) { - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_start ()); - } - } - else { - gst_pad_pause_task (nuv->priv->sinkpad); - } + if (flush) + { + gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_start()); + if (nuv->priv->src_video_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_video_pad, + gst_event_new_flush_start()); + } - GST_PAD_STREAM_LOCK (nuv->priv->sinkpad); - GST_OBJECT_LOCK (nuv); + if (nuv->priv->src_audio_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_audio_pad, + gst_event_new_flush_start()); + } + } + else + { + gst_pad_pause_task(nuv->priv->sinkpad); + } + + GST_PAD_STREAM_LOCK(nuv->priv->sinkpad); + GST_OBJECT_LOCK(nuv); if (cur == GST_CLOCK_TIME_NONE) - cur = 0; + cur = 0; if (stop == GST_CLOCK_TIME_NONE) - stop = nuv->priv->duration_time; + stop = nuv->priv->duration_time; if (cur_type == GST_SEEK_TYPE_SET) - segment_start = cur; + segment_start = cur; else if (cur_type == GST_SEEK_TYPE_CUR) - segment_start = nuv->priv->segment_start + cur; + segment_start = nuv->priv->segment_start + cur; else - segment_start = nuv->priv->segment_start; + segment_start = nuv->priv->segment_start; if (stop_type == GST_SEEK_TYPE_SET) - segment_stop = stop; + segment_stop = stop; else if (stop_type == GST_SEEK_TYPE_CUR) - segment_stop = nuv->priv->segment_stop + stop; + segment_stop = nuv->priv->segment_stop + stop; else - segment_stop = nuv->priv->segment_stop; + segment_stop = nuv->priv->segment_stop; - segment_start = CLAMP (segment_start, 0, nuv->priv->duration_time); - segment_stop = CLAMP (segment_stop, 0, nuv->priv->duration_time); + segment_start = CLAMP(segment_start, 0, nuv->priv->duration_time); + segment_stop = CLAMP(segment_stop, 0, nuv->priv->duration_time); - entry = gst_nuv_demux_do_seek_index (nuv, segment_start, - segment_stop, format); + entry = gst_nuv_demux_do_seek_index(nuv, segment_start, + segment_stop, format); - if (entry == NULL) { - GST_DEBUG_OBJECT (nuv, "No matching seek entry in index"); - goto seek_error; - } + if (entry == NULL) + { + GST_DEBUG_OBJECT(nuv, "No matching seek entry in index"); + goto seek_error; + } segment_start = entry->timecode; nuv->priv->segment_start = segment_start; nuv->priv->segment_stop = segment_stop; - GST_OBJECT_UNLOCK (nuv); + GST_OBJECT_UNLOCK(nuv); - if (!nuv->priv->eos) { - GstMessage *msg; - msg = gst_message_new_segment_start (GST_OBJECT (nuv), GST_FORMAT_TIME, - nuv->priv->segment_start); - - gst_element_post_message (GST_ELEMENT (nuv), msg); - } + if (!nuv->priv->eos) + { + GstMessage *msg; + msg = gst_message_new_segment_start(GST_OBJECT(nuv), GST_FORMAT_TIME, + nuv->priv->segment_start); - GST_DEBUG_OBJECT (nuv, "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" G_GUINT64_FORMAT, - segment_start, segment_stop); - newsegment_event = gst_event_new_new_segment (FALSE, rate, - GST_FORMAT_TIME, segment_start, segment_stop, segment_start); + gst_element_post_message(GST_ELEMENT(nuv), msg); + } + GST_DEBUG_OBJECT(nuv, + "NEW SEGMENT START %" G_GUINT64_FORMAT ", STOP %" + G_GUINT64_FORMAT, segment_start, segment_stop); + newsegment_event = + gst_event_new_new_segment(FALSE, rate, GST_FORMAT_TIME, segment_start, + segment_stop, segment_start); - if (flush) { - if (nuv->priv->src_video_pad != NULL) { - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_new_flush_stop ()); - } - if (nuv->priv->src_audio_pad != NULL) { - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_new_flush_stop ()); - } + if (flush) + { + if (nuv->priv->src_video_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_video_pad, + gst_event_new_flush_stop()); + } - gst_pad_push_event (nuv->priv->sinkpad, gst_event_new_flush_stop ()); - } + if (nuv->priv->src_audio_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_audio_pad, + gst_event_new_flush_stop()); + } - - if (nuv->priv->src_video_pad != NULL) { - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event)); - } - if (nuv->priv->src_audio_pad != NULL) { - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event)); - } + gst_pad_push_event(nuv->priv->sinkpad, gst_event_new_flush_stop()); + } - gst_event_unref (newsegment_event); + + if (nuv->priv->src_video_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_video_pad, + gst_event_ref(newsegment_event)); + } + if (nuv->priv->src_audio_pad != NULL) + { + gst_pad_push_event(nuv->priv->src_audio_pad, + gst_event_ref(newsegment_event)); + } + + gst_event_unref(newsegment_event); nuv->priv->state = GST_NUV_DEMUX_FRAME_HEADER; nuv->priv->offset = entry->offset; - gst_pad_start_task (nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop, - nuv->priv->sinkpad); + gst_pad_start_task(nuv->priv->sinkpad, (GstTaskFunction) gst_nuv_demux_loop, + nuv->priv->sinkpad); - GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad); + GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad); return TRUE; seek_error: - GST_DEBUG_OBJECT (nuv, "Got a seek error"); - GST_OBJECT_UNLOCK (nuv); - GST_PAD_STREAM_UNLOCK (nuv->priv->sinkpad); + GST_DEBUG_OBJECT(nuv, "Got a seek error"); + GST_OBJECT_UNLOCK(nuv); + GST_PAD_STREAM_UNLOCK(nuv->priv->sinkpad); return FALSE; } static gboolean -gst_nuv_demux_srcpad_event (GstPad * pad, GstEvent * event) +gst_nuv_demux_srcpad_event(GstPad * pad, GstEvent * event) { gboolean res = FALSE; GstNuvDemux *nuv; - nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_SEEK: - res = gst_nuv_demux_do_seek (nuv, event); - break; - default: - res = FALSE; - break; - } - - gst_object_unref (nuv); + nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad)); + + switch (GST_EVENT_TYPE(event)) + { + case GST_EVENT_SEEK: + res = gst_nuv_demux_do_seek(nuv, event); + break; + default: + res = FALSE; + break; + } + + gst_object_unref(nuv); return res; } static gboolean -gst_nuv_demux_sink_event (GstPad * pad, GstEvent * event) +gst_nuv_demux_sink_event(GstPad * pad, GstEvent * event) { - gboolean res = FALSE; - GstNuvDemux *nuv; + gboolean res = FALSE; + GstNuvDemux *nuv; - nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); - - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_NEWSEGMENT: - { - gboolean update; - gdouble rate; - GstFormat format; - gint64 start; - gint64 stop; - gint64 position; + nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad)); - gst_event_parse_new_segment (event, &update, &rate, &format, &start, &stop, &position); - if ((format == GST_FORMAT_BYTES) && (start == 0)) { - g_debug ("NEW SEGMENT 0"); - if (nuv->priv->segment > 0) { - nuv->priv->new_file = TRUE; - nuv->priv->state = GST_NUV_DEMUX_START; - nuv->priv->offset = 0; - } - nuv->priv->segment++; + switch (GST_EVENT_TYPE(event)) + { + case GST_EVENT_NEWSEGMENT: + { + gboolean update; + gdouble rate; + GstFormat format; + gint64 start; + gint64 stop; + gint64 position; - /* - newsegment_event = gst_event_new_new_segment (FALSE, rate, - GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE); + gst_event_parse_new_segment(event, &update, &rate, &format, &start, + &stop, &position); + if ((format == GST_FORMAT_BYTES) && (start == 0)) + { + g_debug("NEW SEGMENT 0"); + if (nuv->priv->segment > 0) + { + nuv->priv->new_file = TRUE; + nuv->priv->state = GST_NUV_DEMUX_START; + nuv->priv->offset = 0; + } + nuv->priv->segment++; - gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event)); - gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event)); - gst_event_unref (newsegment_event); - */ - res = gst_pad_event_default(pad, event); - } - break; - } - case GST_EVENT_CUSTOM_DOWNSTREAM: - { - /* - nuv->priv->new_file = TRUE; - nuv->priv->state = GST_NUV_DEMUX_START; - nuv->priv->offset = 0; - */ - GST_PAD_STREAM_LOCK (pad); - gst_nuv_demux_reset( nuv ); - GST_PAD_STREAM_UNLOCK (pad); + /* + newsegment_event = gst_event_new_new_segment (FALSE, rate, + GST_FORMAT_TIME, 0, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE); - res = gst_pad_event_default (pad, event); - break; - } - default: - res = gst_pad_event_default (pad, event); - break; - } + gst_pad_push_event (nuv->priv->src_audio_pad, gst_event_ref (newsegment_event)); + gst_pad_push_event (nuv->priv->src_video_pad, gst_event_ref (newsegment_event)); + gst_event_unref (newsegment_event); + */ + res = gst_pad_event_default(pad, event); + } + break; + } + case GST_EVENT_CUSTOM_DOWNSTREAM: + { + /* + nuv->priv->new_file = TRUE; + nuv->priv->state = GST_NUV_DEMUX_START; + nuv->priv->offset = 0; + */ + GST_PAD_STREAM_LOCK(pad); + gst_nuv_demux_reset(nuv); + GST_PAD_STREAM_UNLOCK(pad); - return res; + res = gst_pad_event_default(pad, event); + break; + } + default: + res = gst_pad_event_default(pad, event); + break; + } + + return res; } static GstFlowReturn -gst_nuv_demux_chain (GstPad * pad, GstBuffer * buf) +gst_nuv_demux_chain(GstPad * pad, GstBuffer * buf) { GstFlowReturn ret = GST_FLOW_OK; - GstNuvDemux *nuv = GST_NUV_DEMUX (gst_pad_get_parent (pad)); - + GstNuvDemux *nuv = GST_NUV_DEMUX(gst_pad_get_parent(pad)); + if (nuv->priv->mode != NUV_PUSH_MODE) - return ret; + return ret; - gst_adapter_push (nuv->priv->adapter, buf); - - while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) { - ret = gst_nuv_demux_play (pad); - } + gst_adapter_push(nuv->priv->adapter, buf); + + while ((ret == GST_FLOW_OK) && (nuv->priv->more_data == FALSE)) + { + ret = gst_nuv_demux_play(pad); + } nuv->priv->more_data = FALSE; - gst_object_unref (nuv); + gst_object_unref(nuv); return ret; } static void -gst_nuv_demux_loop (GstPad * pad) +gst_nuv_demux_loop(GstPad * pad) { - gst_nuv_demux_play (pad); + gst_nuv_demux_play(pad); } static void -gst_nuv_demux_index_free (gpointer data, gpointer user_data) +gst_nuv_demux_index_free(gpointer data, gpointer user_data) { - g_free (data); + g_free(data); } static void -gst_nuv_demux_reset (GstNuvDemux * nuv) +gst_nuv_demux_reset(GstNuvDemux * nuv) { nuv->priv->eos = FALSE; nuv->priv->more_data = FALSE; @@ -1662,160 +1861,172 @@ nuv->priv->segment_start = GST_CLOCK_TIME_NONE; nuv->priv->new_file = FALSE; - //clear index list - g_slist_foreach (nuv->priv->index, gst_nuv_demux_index_free, NULL); - g_slist_free (nuv->priv->index); + //clear index list + g_slist_foreach(nuv->priv->index, gst_nuv_demux_index_free, NULL); + g_slist_free(nuv->priv->index); nuv->priv->index = NULL; - gst_adapter_clear (nuv->priv->adapter); + gst_adapter_clear(nuv->priv->adapter); - if (nuv->priv->mpeg_buffer != NULL) { - gst_buffer_unref (nuv->priv->mpeg_buffer); - nuv->priv->mpeg_buffer = NULL; - } + if (nuv->priv->mpeg_buffer != NULL) + { + gst_buffer_unref(nuv->priv->mpeg_buffer); + nuv->priv->mpeg_buffer = NULL; + } } static void -gst_nuv_demux_destoy_src_pad (GstNuvDemux * nuv) +gst_nuv_demux_destoy_src_pad(GstNuvDemux * nuv) { - if (nuv->priv->src_video_pad) { - gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_video_pad); - nuv->priv->src_video_pad = NULL; - } + if (nuv->priv->src_video_pad) + { + gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_video_pad); + nuv->priv->src_video_pad = NULL; + } - if (nuv->priv->src_audio_pad) { - gst_element_remove_pad (GST_ELEMENT (nuv), nuv->priv->src_audio_pad); - nuv->priv->src_audio_pad = NULL; - } + if (nuv->priv->src_audio_pad) + { + gst_element_remove_pad(GST_ELEMENT(nuv), nuv->priv->src_audio_pad); + nuv->priv->src_audio_pad = NULL; + } } static GstStateChangeReturn -gst_nuv_demux_change_state (GstElement * element, GstStateChange transition) +gst_nuv_demux_change_state(GstElement * element, GstStateChange transition) { GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; - g_debug ("Nuvdemux state_change"); - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - gst_nuv_demux_reset (GST_NUV_DEMUX (element)); - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element)); - break; - default: - break; - } + g_debug("Nuvdemux state_change"); + switch (transition) + { + case GST_STATE_CHANGE_NULL_TO_READY: + gst_nuv_demux_reset(GST_NUV_DEMUX(element)); + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element)); + break; + default: + break; + } - g_debug ("Nuvdemux state_change: 1"); + g_debug("Nuvdemux state_change: 1"); - ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - if (ret == GST_STATE_CHANGE_FAILURE) { - goto done; - } + ret = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + { + goto done; + } - g_debug ("Nuvdemux state_change: 2"); + g_debug("Nuvdemux state_change: 2"); - switch (transition) { - case GST_STATE_CHANGE_READY_TO_NULL: - gst_nuv_demux_reset (GST_NUV_DEMUX (element)); - gst_nuv_demux_destoy_src_pad (GST_NUV_DEMUX (element)); - break; - default: - break; - } + switch (transition) + { + case GST_STATE_CHANGE_READY_TO_NULL: + gst_nuv_demux_reset(GST_NUV_DEMUX(element)); + gst_nuv_demux_destoy_src_pad(GST_NUV_DEMUX(element)); + break; + default: + break; + } - g_debug ("Nuvdemux state_change: DONE"); + g_debug("Nuvdemux state_change: DONE"); done: return ret; } -#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6) +#if (GST_VERSION_MINOR == 10) && (GST_VERSION_MICRO < 6) GstBuffer * -gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) +gst_adapter_take_buffer(GstAdapter * adapter, guint nbytes) { GstBuffer *buffer; GstBuffer *cur; guint8 *data; - g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); - g_return_val_if_fail (nbytes > 0, NULL); + g_return_val_if_fail(GST_IS_ADAPTER(adapter), NULL); + g_return_val_if_fail(nbytes > 0, NULL); - GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes); + GST_LOG_OBJECT(adapter, "taking buffer of %u bytes", nbytes); - /* we don't have enough data, return NULL. This is unlikely - * as one usually does an _available() first instead of peeking a - * random size. */ - if (G_UNLIKELY (nbytes > adapter->size)) - return NULL; + /* we don't have enough data, return NULL. This is unlikely + * as one usually does an _available() first instead of peeking a + * random size. */ + if (G_UNLIKELY(nbytes > adapter->size)) + return NULL; - /* our head buffer has enough data left, return it */ + /* our head buffer has enough data left, return it */ cur = adapter->buflist->data; - if (GST_BUFFER_SIZE (cur) >= nbytes + adapter->skip) { - GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", - nbytes); - buffer = gst_buffer_create_sub (cur, adapter->skip, nbytes); + if (GST_BUFFER_SIZE(cur) >= nbytes + adapter->skip) + { + GST_LOG_OBJECT(adapter, "providing buffer of %d bytes via sub-buffer", + nbytes); + buffer = gst_buffer_create_sub(cur, adapter->skip, nbytes); - gst_adapter_flush (adapter, nbytes); + gst_adapter_flush(adapter, nbytes); - return buffer; - } + return buffer; + } - data = gst_adapter_take (adapter, nbytes); + data = gst_adapter_take(adapter, nbytes); if (data == NULL) - return NULL; + return NULL; - buffer = gst_buffer_new (); - GST_BUFFER_DATA (buffer) = data; - GST_BUFFER_MALLOCDATA (buffer) = data; - GST_BUFFER_SIZE (buffer) = nbytes; + buffer = gst_buffer_new(); + GST_BUFFER_DATA(buffer) = data; + GST_BUFFER_MALLOCDATA(buffer) = data; + GST_BUFFER_SIZE(buffer) = nbytes; return buffer; } #endif static void -gst_nuv_typefind (GstTypeFind * tf, gpointer unused) +gst_nuv_typefind(GstTypeFind * tf, gpointer unused) { - guint8 *data = gst_type_find_peek (tf, 0, 11); + guint8 *data = gst_type_find_peek(tf, 0, 11); - if (data) { - if (memcmp (data, "MythTVVideo", 11) == 0 - || memcmp (data, "NuppelVideo", 11) == 0) { - gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, - gst_caps_new_simple ("video/x-nuv", NULL)); - } - } + if (data) + { + if (memcmp(data, "MythTVVideo", 11) == 0 + || memcmp(data, "NuppelVideo", 11) == 0) + { + gst_type_find_suggest(tf, GST_TYPE_FIND_MAXIMUM, + gst_caps_new_simple("video/x-nuv", NULL)); + } + } } static gboolean -plugin_init (GstPlugin * plugin) +plugin_init(GstPlugin * plugin) { - static gchar *exts[] = { "nuv", NULL }; + static gchar *exts[] = { "nuv", NULL }; #ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + setlocale(LC_ALL, ""); + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); #endif /* ENABLE_NLS */ - if (!gst_element_register (plugin, "nuvdemux", GST_RANK_SECONDARY, - GST_TYPE_NUV_DEMUX)) { - return FALSE; - } + if (!gst_element_register(plugin, "nuvdemux", GST_RANK_SECONDARY, + GST_TYPE_NUV_DEMUX)) + { + return FALSE; + } - if (!gst_type_find_register (plugin, "video/x-nuv", GST_RANK_SECONDARY, - gst_nuv_typefind, - exts, - gst_caps_new_simple ("video/x-nuv", NULL), NULL, NULL)) { - GST_WARNING ("can't register typefind"); - return FALSE; - } + if (!gst_type_find_register(plugin, "video/x-nuv", GST_RANK_SECONDARY, + gst_nuv_typefind, + exts, + gst_caps_new_simple("video/x-nuv", NULL), NULL, + NULL)) + { + GST_WARNING("can't register typefind"); + return FALSE; + } return TRUE; } -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "nuvdemux", - "Demuxes and muxes audio and video", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) - +GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "nuvdemux", + "Demuxes and muxes audio and video", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, + GST_PACKAGE_ORIGIN) diff -r 312d6bc514f3 -r 3cf3c6019e3b gst-gmyth/nuvdemux/gstnuvdemux.h --- a/gst-gmyth/nuvdemux/gstnuvdemux.h Thu Jun 14 18:19:52 2007 +0100 +++ b/gst-gmyth/nuvdemux/gstnuvdemux.h Thu Jun 14 18:21:08 2007 +0100 @@ -26,7 +26,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_NUV_DEMUX \ (gst_nuv_demux_get_type ()) #define GST_NUV_DEMUX(obj) \ @@ -37,19 +36,19 @@ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_NUV_DEMUX)) #define GST_IS_NUV_DEMUX_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_NUV_DEMUX)) - typedef struct _GstNuvDemuxPrivate GstNuvDemuxPrivate; -typedef struct _GstNuvDemux { - GstElement parent; +typedef struct _GstNuvDemux +{ + GstElement parent; GstNuvDemuxPrivate *priv; } GstNuvDemux; -typedef struct _GstNuvDemuxClass { +typedef struct _GstNuvDemuxClass +{ GstElementClass parent_class; } GstNuvDemuxClass; -GType gst_nuv_demux_get_type (void); +GType gst_nuv_demux_get_type(void); G_END_DECLS - #endif /* __GST_NUV_DEMUX_H__ */