mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-05 09:00:54 +00:00
gst/elements/gstfdsrc.*: Fix hang on state-change with blocking input (#149791).
Original commit message from CVS: * gst/elements/gstfdsrc.c: (gst_fdsrc_class_init), (gst_fdsrc_change_state), (gst_fdsrc_release_locks), (gst_fdsrc_get): * gst/elements/gstfdsrc.h: Fix hang on state-change with blocking input (#149791).
This commit is contained in:
parent
c1ce267dd1
commit
2a7b791b32
5 changed files with 74 additions and 30 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2005-03-26 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
|
||||||
|
|
||||||
|
* gst/elements/gstfdsrc.c: (gst_fdsrc_class_init),
|
||||||
|
(gst_fdsrc_change_state), (gst_fdsrc_release_locks),
|
||||||
|
(gst_fdsrc_get):
|
||||||
|
* gst/elements/gstfdsrc.h:
|
||||||
|
Fix hang on state-change with blocking input (#149791).
|
||||||
|
|
||||||
2005-03-25 David Schleef <ds@schleef.org>
|
2005-03-25 David Schleef <ds@schleef.org>
|
||||||
|
|
||||||
* gst/gstcpu.c: (illegal_instruction_handler),
|
* gst/gstcpu.c: (illegal_instruction_handler),
|
||||||
|
|
|
@ -101,6 +101,7 @@ static void gst_fdsrc_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
static GstElementStateReturn gst_fdsrc_change_state (GstElement * element);
|
static GstElementStateReturn gst_fdsrc_change_state (GstElement * element);
|
||||||
|
static gboolean gst_fdsrc_release_locks (GstElement * element);
|
||||||
static GstData *gst_fdsrc_get (GstPad * pad);
|
static GstData *gst_fdsrc_get (GstPad * pad);
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ gst_fdsrc_class_init (GstFdSrcClass * klass)
|
||||||
gobject_class->dispose = gst_fdsrc_dispose;
|
gobject_class->dispose = gst_fdsrc_dispose;
|
||||||
|
|
||||||
gstelement_class->change_state = gst_fdsrc_change_state;
|
gstelement_class->change_state = gst_fdsrc_change_state;
|
||||||
|
gstelement_class->release_locks = gst_fdsrc_release_locks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -179,19 +181,16 @@ gst_fdsrc_change_state (GstElement * element)
|
||||||
GstFdSrc *src = GST_FDSRC (element);
|
GstFdSrc *src = GST_FDSRC (element);
|
||||||
|
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
switch (GST_STATE_TRANSITION (element)) {
|
||||||
case GST_STATE_NULL_TO_READY:
|
|
||||||
break;
|
|
||||||
case GST_STATE_READY_TO_NULL:
|
|
||||||
break;
|
|
||||||
case GST_STATE_READY_TO_PAUSED:
|
case GST_STATE_READY_TO_PAUSED:
|
||||||
src->curoffset = 0;
|
src->curoffset = 0;
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* in any case, an interrupt succeeds if we get here */
|
||||||
|
src->interrupted = FALSE;
|
||||||
|
|
||||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||||
|
|
||||||
|
@ -255,6 +254,16 @@ gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_fdsrc_release_locks (GstElement * element)
|
||||||
|
{
|
||||||
|
GstFdSrc *src = GST_FDSRC (element);
|
||||||
|
|
||||||
|
src->interrupted = TRUE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static GstData *
|
static GstData *
|
||||||
gst_fdsrc_get (GstPad * pad)
|
gst_fdsrc_get (GstPad * pad)
|
||||||
{
|
{
|
||||||
|
@ -264,7 +273,7 @@ gst_fdsrc_get (GstPad * pad)
|
||||||
|
|
||||||
#ifndef HAVE_WIN32
|
#ifndef HAVE_WIN32
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
struct timeval t, *tp = &t;
|
struct timeval t;
|
||||||
gint retval;
|
gint retval;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -277,16 +286,24 @@ gst_fdsrc_get (GstPad * pad)
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&readfds);
|
||||||
FD_SET (src->fd, &readfds);
|
FD_SET (src->fd, &readfds);
|
||||||
|
|
||||||
if (src->timeout != 0) {
|
/* loop until data is available, or a timeout is set. Re-enter
|
||||||
GST_TIME_TO_TIMEVAL (src->timeout, t);
|
* loop if we got a timeout without a timeout set, or if we
|
||||||
} else
|
* received an interrupt event. */
|
||||||
tp = NULL;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
retval = select (src->fd + 1, &readfds, NULL, NULL, tp);
|
if (src->timeout != 0) {
|
||||||
} while (retval == -1 && errno == EINTR); /* retry if interrupted */
|
GST_TIME_TO_TIMEVAL (src->timeout, t);
|
||||||
|
} else {
|
||||||
|
GST_TIME_TO_TIMEVAL (1000000000, t);
|
||||||
|
}
|
||||||
|
|
||||||
if (retval == -1) {
|
retval = select (src->fd + 1, &readfds, NULL, NULL, &t);
|
||||||
|
} while (!src->interrupted &&
|
||||||
|
((retval == -1 && errno == EINTR) || (retval == 0 && src->timeout == 0)));
|
||||||
|
|
||||||
|
if (src->interrupted) {
|
||||||
|
GST_DEBUG_OBJECT (src, "received interrupt");
|
||||||
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
||||||
|
} else if (retval == -1) {
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
||||||
("select on file descriptor: %s.", g_strerror (errno)));
|
("select on file descriptor: %s.", g_strerror (errno)));
|
||||||
gst_element_set_eos (GST_ELEMENT (src));
|
gst_element_set_eos (GST_ELEMENT (src));
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct _GstFdSrc {
|
||||||
|
|
||||||
/* fd */
|
/* fd */
|
||||||
gint fd;
|
gint fd;
|
||||||
|
gboolean interrupted;
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
|
|
||||||
gulong curoffset; /* current offset in file */
|
gulong curoffset; /* current offset in file */
|
||||||
|
|
|
@ -101,6 +101,7 @@ static void gst_fdsrc_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
static GstElementStateReturn gst_fdsrc_change_state (GstElement * element);
|
static GstElementStateReturn gst_fdsrc_change_state (GstElement * element);
|
||||||
|
static gboolean gst_fdsrc_release_locks (GstElement * element);
|
||||||
static GstData *gst_fdsrc_get (GstPad * pad);
|
static GstData *gst_fdsrc_get (GstPad * pad);
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ gst_fdsrc_class_init (GstFdSrcClass * klass)
|
||||||
gobject_class->dispose = gst_fdsrc_dispose;
|
gobject_class->dispose = gst_fdsrc_dispose;
|
||||||
|
|
||||||
gstelement_class->change_state = gst_fdsrc_change_state;
|
gstelement_class->change_state = gst_fdsrc_change_state;
|
||||||
|
gstelement_class->release_locks = gst_fdsrc_release_locks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -179,19 +181,16 @@ gst_fdsrc_change_state (GstElement * element)
|
||||||
GstFdSrc *src = GST_FDSRC (element);
|
GstFdSrc *src = GST_FDSRC (element);
|
||||||
|
|
||||||
switch (GST_STATE_TRANSITION (element)) {
|
switch (GST_STATE_TRANSITION (element)) {
|
||||||
case GST_STATE_NULL_TO_READY:
|
|
||||||
break;
|
|
||||||
case GST_STATE_READY_TO_NULL:
|
|
||||||
break;
|
|
||||||
case GST_STATE_READY_TO_PAUSED:
|
case GST_STATE_READY_TO_PAUSED:
|
||||||
src->curoffset = 0;
|
src->curoffset = 0;
|
||||||
break;
|
break;
|
||||||
case GST_STATE_PAUSED_TO_READY:
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* in any case, an interrupt succeeds if we get here */
|
||||||
|
src->interrupted = FALSE;
|
||||||
|
|
||||||
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
||||||
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
||||||
|
|
||||||
|
@ -255,6 +254,16 @@ gst_fdsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_fdsrc_release_locks (GstElement * element)
|
||||||
|
{
|
||||||
|
GstFdSrc *src = GST_FDSRC (element);
|
||||||
|
|
||||||
|
src->interrupted = TRUE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static GstData *
|
static GstData *
|
||||||
gst_fdsrc_get (GstPad * pad)
|
gst_fdsrc_get (GstPad * pad)
|
||||||
{
|
{
|
||||||
|
@ -264,7 +273,7 @@ gst_fdsrc_get (GstPad * pad)
|
||||||
|
|
||||||
#ifndef HAVE_WIN32
|
#ifndef HAVE_WIN32
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
struct timeval t, *tp = &t;
|
struct timeval t;
|
||||||
gint retval;
|
gint retval;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -277,16 +286,24 @@ gst_fdsrc_get (GstPad * pad)
|
||||||
FD_ZERO (&readfds);
|
FD_ZERO (&readfds);
|
||||||
FD_SET (src->fd, &readfds);
|
FD_SET (src->fd, &readfds);
|
||||||
|
|
||||||
if (src->timeout != 0) {
|
/* loop until data is available, or a timeout is set. Re-enter
|
||||||
GST_TIME_TO_TIMEVAL (src->timeout, t);
|
* loop if we got a timeout without a timeout set, or if we
|
||||||
} else
|
* received an interrupt event. */
|
||||||
tp = NULL;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
retval = select (src->fd + 1, &readfds, NULL, NULL, tp);
|
if (src->timeout != 0) {
|
||||||
} while (retval == -1 && errno == EINTR); /* retry if interrupted */
|
GST_TIME_TO_TIMEVAL (src->timeout, t);
|
||||||
|
} else {
|
||||||
|
GST_TIME_TO_TIMEVAL (1000000000, t);
|
||||||
|
}
|
||||||
|
|
||||||
if (retval == -1) {
|
retval = select (src->fd + 1, &readfds, NULL, NULL, &t);
|
||||||
|
} while (!src->interrupted &&
|
||||||
|
((retval == -1 && errno == EINTR) || (retval == 0 && src->timeout == 0)));
|
||||||
|
|
||||||
|
if (src->interrupted) {
|
||||||
|
GST_DEBUG_OBJECT (src, "received interrupt");
|
||||||
|
return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
|
||||||
|
} else if (retval == -1) {
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
||||||
("select on file descriptor: %s.", g_strerror (errno)));
|
("select on file descriptor: %s.", g_strerror (errno)));
|
||||||
gst_element_set_eos (GST_ELEMENT (src));
|
gst_element_set_eos (GST_ELEMENT (src));
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct _GstFdSrc {
|
||||||
|
|
||||||
/* fd */
|
/* fd */
|
||||||
gint fd;
|
gint fd;
|
||||||
|
gboolean interrupted;
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
|
|
||||||
gulong curoffset; /* current offset in file */
|
gulong curoffset; /* current offset in file */
|
||||||
|
|
Loading…
Reference in a new issue