From c8c34e8dffd26003ee50facdaffc57ab94f1fb9e Mon Sep 17 00:00:00 2001 From: joel larsson Date: Fri, 20 Jun 2008 10:02:14 +0000 Subject: [PATCH] Add timeout property like udpsrc. Fixes #538628. Original commit message from CVS: Patch by: joel larsson * docs/plugins/gstreamer-plugins.args: * plugins/elements/gstfdsrc.c: (gst_fd_src_class_init), (gst_fd_src_init), (gst_fd_src_update_fd), (gst_fd_src_set_property), (gst_fd_src_get_property), (gst_fd_src_create): * plugins/elements/gstfdsrc.h: Add timeout property like udpsrc. Fixes #538628. Add some more docs and example pipelines. --- ChangeLog | 13 ++++ docs/plugins/gstreamer-plugins.args | 12 +++- plugins/elements/gstfdsrc.c | 114 ++++++++++++++++++++++++++++++------ plugins/elements/gstfdsrc.h | 3 + 4 files changed, 122 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 487d72f..d392346 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2008-06-20 Wim Taymans + Patch by: joel larsson + + * docs/plugins/gstreamer-plugins.args: + * plugins/elements/gstfdsrc.c: (gst_fd_src_class_init), + (gst_fd_src_init), (gst_fd_src_update_fd), + (gst_fd_src_set_property), (gst_fd_src_get_property), + (gst_fd_src_create): + * plugins/elements/gstfdsrc.h: + Add timeout property like udpsrc. Fixes #538628. + Add some more docs and example pipelines. + +2008-06-20 Wim Taymans + * docs/libs/gstreamer-libs-sections.txt: * libs/gst/base/gstbasesink.c: (gst_base_sink_init), (gst_base_sink_query_latency), (gst_base_sink_set_render_delay), diff --git a/docs/plugins/gstreamer-plugins.args b/docs/plugins/gstreamer-plugins.args index 937d7ad..afc461d 100644 --- a/docs/plugins/gstreamer-plugins.args +++ b/docs/plugins/gstreamer-plugins.args @@ -271,7 +271,7 @@ GstFakeSink::num-buffers gint ->= -1 +>= G_MAXULONG rw num-buffers Number of buffers to accept going EOS. @@ -289,6 +289,16 @@ +GstFdSrc::timeout +guint64 + +rw +Timeout +Post a message after timeout microseconds (0 = disabled). +0 + + + GstFileSrc::fd gint >= 0 diff --git a/plugins/elements/gstfdsrc.c b/plugins/elements/gstfdsrc.c index 83f9476..5e2c0f5 100644 --- a/plugins/elements/gstfdsrc.c +++ b/plugins/elements/gstfdsrc.c @@ -25,10 +25,42 @@ * @short_description: read from a unix file descriptor * @see_also: #GstFdSink * + * + * * Read data from a unix file descriptor. + * + * Examples + * + * Here is a simple pipeline to read from the standard input and dump the data + * with a fakesink. + * + * gst-launch -v fdsrc ! fakesink dump=1 + * + * To generate data, enter some data on the console folowed by enter. + * The above mentioned pipeline should dump data packets to the console. + * + * + * If the timeout property is set to a + * value bigger than 0, fdsrc will generate an element message named + * "GstFdSrcTimeout" + * if no data was recieved in the given timeout. + * The message's structure contains one field: + * + * + * + * #guint64 + * "timeout": the timeout in microseconds that + * expired when waiting for data. + * + * + * + * + * + * Last reviewed on 2008-06-20 (0.10.21) + * + * */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -50,8 +82,6 @@ #include "gstfdsrc.h" -#define DEFAULT_BLOCKSIZE 4096 - static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -60,10 +90,17 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", GST_DEBUG_CATEGORY_STATIC (gst_fd_src_debug); #define GST_CAT_DEFAULT gst_fd_src_debug +#define DEFAULT_FD 0 +#define DEFAULT_TIMEOUT 0 + enum { PROP_0, + PROP_FD, + PROP_TIMEOUT, + + PROP_LAST }; static void gst_fd_src_uri_handler_init (gpointer g_iface, gpointer iface_data); @@ -136,7 +173,12 @@ gst_fd_src_class_init (GstFdSrcClass * klass) g_object_class_install_property (gobject_class, PROP_FD, g_param_spec_int ("fd", "fd", "An open file descriptor to read from", - 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + 0, G_MAXINT, DEFAULT_FD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMEOUT, + g_param_spec_uint64 ("timeout", "Timeout", + "Post a message after timeout microseconds (0 = disabled)", 0, + G_MAXUINT64, DEFAULT_TIMEOUT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_fd_src_start); gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_fd_src_stop); @@ -152,9 +194,10 @@ gst_fd_src_class_init (GstFdSrcClass * klass) static void gst_fd_src_init (GstFdSrc * fdsrc, GstFdSrcClass * klass) { - fdsrc->fd = -1; fdsrc->new_fd = 0; fdsrc->seekable_fd = FALSE; + fdsrc->fd = DEFAULT_FD; + fdsrc->timeout = DEFAULT_TIMEOUT; fdsrc->uri = g_strdup_printf ("fd://0"); fdsrc->curoffset = 0; } @@ -176,7 +219,7 @@ gst_fd_src_update_fd (GstFdSrc * src) struct stat stat_results; /* we need to always update the fdset since it may not have existed when - * gst_fd_src_update_fd() was called earlier */ + * gst_fd_src_update_fd () was called earlier */ if (src->fdset != NULL) { GstPollFD fd = GST_POLL_FD_INIT; @@ -303,6 +346,11 @@ gst_fd_src_set_property (GObject * object, guint prop_id, const GValue * value, } GST_OBJECT_UNLOCK (object); break; + case PROP_TIMEOUT: + src->timeout = g_value_get_uint64 (value); + GST_DEBUG_OBJECT (src, "poll timeout set to %" GST_TIME_FORMAT, + GST_TIME_ARGS (src->timeout)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -319,6 +367,9 @@ gst_fd_src_get_property (GObject * object, guint prop_id, GValue * value, case PROP_FD: g_value_set_int (value, src->fd); break; + case PROP_TIMEOUT: + g_value_set_uint64 (value, src->timeout); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -332,24 +383,49 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) GstBuffer *buf; gssize readbytes; guint blocksize; + GstClockTime timeout; #ifndef HAVE_WIN32 + gboolean try_again; gint retval; #endif src = GST_FD_SRC (psrc); + if (src->timeout > 0) { + timeout = src->timeout * GST_USECOND; + } else { + timeout = GST_CLOCK_TIME_NONE; + } + #ifndef HAVE_WIN32 do { - retval = gst_poll_wait (src->fdset, GST_CLOCK_TIME_NONE); - } while (retval == -1 && (errno == EINTR || errno == EAGAIN)); /* retry if interrupted */ - - if (retval == -1) { - if (errno == EBUSY) - goto stopped; - else - goto select_error; - } + try_again = FALSE; + + GST_LOG_OBJECT (src, "doing poll, timeout %" GST_TIME_FORMAT, + GST_TIME_ARGS (src->timeout)); + + retval = gst_poll_wait (src->fdset, timeout); + GST_LOG_OBJECT (src, "poll returned %d", retval); + + if (G_UNLIKELY (retval == -1)) { + if (errno == EINTR || errno == EAGAIN) { + /* retry if interrupted */ + try_again = TRUE; + } else if (errno == EBUSY) { + goto stopped; + } else { + goto poll_error; + } + } else if (G_UNLIKELY (retval == 0)) { + try_again = TRUE; + /* timeout, post element message */ + gst_element_post_message (GST_ELEMENT_CAST (src), + gst_message_new_element (GST_OBJECT_CAST (src), + gst_structure_new ("GstFdSrcTimeout", + "timeout", G_TYPE_UINT64, src->timeout, NULL))); + } + } while (G_UNLIKELY (try_again)); /* retry if interrupted or timeout */ #endif blocksize = GST_BASE_SRC (src)->blocksize; @@ -382,16 +458,16 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) /* ERRORS */ #ifndef HAVE_WIN32 -select_error: +poll_error: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), - ("select on file descriptor: %s.", g_strerror (errno))); - GST_DEBUG_OBJECT (psrc, "Error during select"); + ("poll on file descriptor: %s.", g_strerror (errno))); + GST_DEBUG_OBJECT (psrc, "Error during poll"); return GST_FLOW_ERROR; } stopped: { - GST_DEBUG_OBJECT (psrc, "Select stopped"); + GST_DEBUG_OBJECT (psrc, "Poll stopped"); return GST_FLOW_WRONG_STATE; } #endif diff --git a/plugins/elements/gstfdsrc.h b/plugins/elements/gstfdsrc.h index 2f8b419..4085810 100644 --- a/plugins/elements/gstfdsrc.h +++ b/plugins/elements/gstfdsrc.h @@ -62,6 +62,9 @@ struct _GstFdSrc { gint fd; gboolean seekable_fd; + /* poll timeout */ + guint64 timeout; + gchar *uri; GstPoll *fdset; -- 2.7.4