From 3d53a08118394491c92ca6462ca702407a1e2a67 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 12 Aug 2004 09:12:13 +0000 Subject: [PATCH] gst/elements/gstfilesrc.c: work with non-regular files that can be mmapped (like /dev/zero) Original commit message from CVS: * gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap): work with non-regular files that can be mmapped (like /dev/zero) * gst/elements/gsttypefindelement.c: (gst_type_find_element_chain): get rid of typefinds that require a seek when we can't seek instead of trying them over and over again * tools/gst-launch.c: (idle_func), (error_cb), (main): return non-zero failure value when the pipeline was interrupted or an error occurred --- ChangeLog | 11 +++++++++++ gst/elements/gstfilesrc.c | 10 ++++++---- gst/elements/gsttypefindelement.c | 17 +++++++++++++++-- plugins/elements/gstfilesrc.c | 10 ++++++---- plugins/elements/gsttypefindelement.c | 17 +++++++++++++++-- tools/gst-launch.c | 24 ++++++++++++++++++------ 6 files changed, 71 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index a32dd4850e..6dfa45a2b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-08-12 Benjamin Otte + + * gst/elements/gstfilesrc.c: (gst_filesrc_get_mmap): + work with non-regular files that can be mmapped (like /dev/zero) + * gst/elements/gsttypefindelement.c: (gst_type_find_element_chain): + get rid of typefinds that require a seek when we can't seek instead + of trying them over and over again + * tools/gst-launch.c: (idle_func), (error_cb), (main): + return non-zero failure value when the pipeline was interrupted or + an error occurred + 2004-08-11 Steve Lhomme * win32/config.h: diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c index b03ecf5a62..ba18487c3d 100644 --- a/gst/elements/gstfilesrc.c +++ b/gst/elements/gstfilesrc.c @@ -508,10 +508,12 @@ gst_filesrc_get_mmap (GstFileSrc * src) mapend = mapstart + mapsize; /* note this is the byte *after* the map */ /* check to see if we're going to overflow the end of the file */ - if (readend > src->filelen) { - if (!gst_filesrc_check_filesize (src) || readend > src->filelen) { - readsize = src->filelen - src->curoffset; - readend = src->curoffset + readsize; + if (src->is_regular) { + if (readend > src->filelen) { + if (!gst_filesrc_check_filesize (src) || readend > src->filelen) { + readsize = src->filelen - src->curoffset; + readend = src->curoffset + readsize; + } } } diff --git a/gst/elements/gsttypefindelement.c b/gst/elements/gsttypefindelement.c index faea68b0fd..676744619a 100644 --- a/gst/elements/gsttypefindelement.c +++ b/gst/elements/gsttypefindelement.c @@ -617,6 +617,7 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) if (typefind->caps) { stop_typefinding (typefind); } else if (typefind->possibilities == NULL) { + error: GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); stop_typefinding (typefind); } else { @@ -633,6 +634,7 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) } if (!walk) { /* find out if we should seek */ + restart: for (walk = typefind->possibilities; walk; walk = g_list_next (walk)) { entry = (TypeFindEntry *) walk->data; if (entry->requested_size > 0) { @@ -661,8 +663,19 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) GST_DEBUG_OBJECT (typefind, "'%s' was reset - couldn't seek to %" G_GINT64_FORMAT, GST_PLUGIN_FEATURE_NAME (entry->factory), seek_offset); - entry->requested_size = 0; - entry->requested_offset = 0; + if (entry->probability == 0) { + free_entry (entry); + typefind->possibilities = + g_list_delete_link (typefind->possibilities, walk); + /* FIXME: too many gotos */ + if (!typefind->possibilities) + goto error; + /* we modified the list, let's restart */ + goto restart; + } else { + entry->requested_size = 0; + entry->requested_offset = 0; + } } } } diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index b03ecf5a62..ba18487c3d 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -508,10 +508,12 @@ gst_filesrc_get_mmap (GstFileSrc * src) mapend = mapstart + mapsize; /* note this is the byte *after* the map */ /* check to see if we're going to overflow the end of the file */ - if (readend > src->filelen) { - if (!gst_filesrc_check_filesize (src) || readend > src->filelen) { - readsize = src->filelen - src->curoffset; - readend = src->curoffset + readsize; + if (src->is_regular) { + if (readend > src->filelen) { + if (!gst_filesrc_check_filesize (src) || readend > src->filelen) { + readsize = src->filelen - src->curoffset; + readend = src->curoffset + readsize; + } } } diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index faea68b0fd..676744619a 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -617,6 +617,7 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) if (typefind->caps) { stop_typefinding (typefind); } else if (typefind->possibilities == NULL) { + error: GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL)); stop_typefinding (typefind); } else { @@ -633,6 +634,7 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) } if (!walk) { /* find out if we should seek */ + restart: for (walk = typefind->possibilities; walk; walk = g_list_next (walk)) { entry = (TypeFindEntry *) walk->data; if (entry->requested_size > 0) { @@ -661,8 +663,19 @@ gst_type_find_element_chain (GstPad * pad, GstData * data) GST_DEBUG_OBJECT (typefind, "'%s' was reset - couldn't seek to %" G_GINT64_FORMAT, GST_PLUGIN_FEATURE_NAME (entry->factory), seek_offset); - entry->requested_size = 0; - entry->requested_offset = 0; + if (entry->probability == 0) { + free_entry (entry); + typefind->possibilities = + g_list_delete_link (typefind->possibilities, walk); + /* FIXME: too many gotos */ + if (!typefind->possibilities) + goto error; + /* we modified the list, let's restart */ + goto restart; + } else { + entry->requested_size = 0; + entry->requested_offset = 0; + } } } } diff --git a/tools/gst-launch.c b/tools/gst-launch.c index 256618efc4..dea2b871fd 100644 --- a/tools/gst-launch.c +++ b/tools/gst-launch.c @@ -66,6 +66,7 @@ static guint64 max = 0; static GstClock *s_clock; static GstElement *pipeline; gboolean caught_intr = FALSE; +gboolean caught_error = FALSE; gboolean idle_func (gpointer data) @@ -85,8 +86,8 @@ idle_func (gpointer data) min = MIN (min, diff); max = MAX (max, diff); - if (!busy || caught_intr || (max_iterations > 0 - && iterations >= max_iterations)) { + if (!busy || caught_intr || caught_error || + (max_iterations > 0 && iterations >= max_iterations)) { char *s_iterations; char *s_sum; char *s_ave; @@ -308,6 +309,7 @@ print_tag (const GstTagList * list, const gchar * tag, gpointer unused) g_free (str); } } + static void found_tag (GObject * pipeline, GstElement * source, GstTagList * tags) { @@ -316,6 +318,13 @@ found_tag (GObject * pipeline, GstElement * source, GstTagList * tags) gst_tag_list_foreach (tags, print_tag, NULL); } +static void +error_cb (GObject * object, GstObject * source, GError * error, gchar * debug) +{ + gst_element_default_error (object, source, error, debug); + caught_error = TRUE; +} + #ifndef DISABLE_FAULT_HANDLER /* we only use sighandler here because the registers are not important */ static void @@ -481,7 +490,7 @@ main (int argc, char *argv[]) } else { fprintf (stderr, _("ERROR: pipeline could not be constructed.\n")); } - exit (1); + return 1; } else if (error) { fprintf (stderr, _("WARNING: erroneous pipeline: %s\n"), error->message); fprintf (stderr, _(" Trying to run anyway.\n")); @@ -497,8 +506,7 @@ main (int argc, char *argv[]) if (tags) { g_signal_connect (pipeline, "found-tag", G_CALLBACK (found_tag), NULL); } - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), - NULL); + g_signal_connect (pipeline, "error", G_CALLBACK (error_cb), NULL); #ifndef GST_DISABLE_LOADSAVE if (savefile) { @@ -513,7 +521,7 @@ main (int argc, char *argv[]) if (real_pipeline == NULL) { fprintf (stderr, _("ERROR: the 'pipeline' element wasn't found.\n")); - exit (1); + return 1; } gst_bin_add (GST_BIN (real_pipeline), pipeline); pipeline = real_pipeline; @@ -537,6 +545,10 @@ main (int argc, char *argv[]) gst_element_wait_state_change (pipeline); g_print ("got the state change.\n"); } + if (caught_intr) + res = 2; + if (caught_error) + res = 3; gst_element_set_state (pipeline, GST_STATE_NULL); }