From f09dd7e7a54764e1c1258c011b4fa8b99c3f552d Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 2 May 2014 18:30:05 -0300 Subject: [PATCH] dashdemux: handle error messages from the sources Set up a message handling function to be able to catch errors from the source element and signal the cond to allow the download loop to retry the download. --- ext/dash/gstdashdemux.c | 49 +++++++++++++++++++++++++++++++++++++++++ ext/dash/gstdashdemux.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/ext/dash/gstdashdemux.c b/ext/dash/gstdashdemux.c index 63508a1364..ac07b23370 100644 --- a/ext/dash/gstdashdemux.c +++ b/ext/dash/gstdashdemux.c @@ -195,6 +195,9 @@ static void gst_dash_demux_dispose (GObject * obj); static GstStateChangeReturn gst_dash_demux_change_state (GstElement * element, GstStateChange transition); +/* GstBin */ +static void gst_dash_demux_handle_message (GstBin * bin, GstMessage * msg); + /* GstDashDemux */ static GstFlowReturn gst_dash_demux_pad (GstPad * pad, GstObject * parent, GstBuffer * buf); @@ -258,9 +261,11 @@ gst_dash_demux_class_init (GstDashDemuxClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; + GstBinClass *gstbin_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; + gstbin_class = (GstBinClass *) klass; gobject_class->set_property = gst_dash_demux_set_property; gobject_class->get_property = gst_dash_demux_get_property; @@ -301,6 +306,8 @@ gst_dash_demux_class_init (GstDashDemuxClass * klass) "David Corvoysier \n\ Hamid Zakari \n\ Gianluca Gennari "); + + gstbin_class->handle_message = gst_dash_demux_handle_message; } static void @@ -399,6 +406,48 @@ gst_dash_demux_change_state (GstElement * element, GstStateChange transition) return ret; } +static void +gst_dash_demux_handle_message (GstBin * bin, GstMessage * msg) +{ + GstDashDemux *demux = GST_DASH_DEMUX_CAST (bin); + + switch (GST_MESSAGE_TYPE (msg)) { + case GST_MESSAGE_ERROR:{ + GSList *iter; + GstDashDemuxStream *stream; + GError *err = NULL; + gchar *debug = NULL; + + for (iter = demux->streams; iter; iter = g_slist_next (iter)) { + stream = iter->data; + if (GST_OBJECT_CAST (stream->src) == GST_MESSAGE_SRC (msg)) { + gst_message_parse_error (msg, &err, &debug); + + GST_WARNING_OBJECT (stream->pad, "Source posted error: %d:%d %s (%s)", + err->domain, err->code, err->message, debug); + + /* error, but ask to retry */ + stream->last_ret = GST_FLOW_CUSTOM_ERROR; + g_cond_signal (&stream->fragment_download_cond); + + g_error_free (err); + g_free (debug); + break; + } + } + + gst_message_unref (msg); + msg = NULL; + } + break; + default: + break; + } + + if (msg) + GST_BIN_CLASS (parent_class)->handle_message (bin, msg); +} + static gboolean gst_dash_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event) { diff --git a/ext/dash/gstdashdemux.h b/ext/dash/gstdashdemux.h index feb017200b..ac7f721bc9 100644 --- a/ext/dash/gstdashdemux.h +++ b/ext/dash/gstdashdemux.h @@ -47,6 +47,8 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DASH_DEMUX)) #define GST_IS_DASH_DEMUX_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DASH_DEMUX)) +#define GST_DASH_DEMUX_CAST(obj) \ + ((GstDashDemux *)obj) typedef struct _GstDashDemuxStream GstDashDemuxStream; typedef struct _GstDashDemux GstDashDemux;