baseparse: only post 'no valid frames' error if buffers were received
authorThiago Santos <thiagoss@osg.samsung.com>
Wed, 25 Mar 2015 13:49:08 +0000 (10:49 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Thu, 26 Mar 2015 15:25:57 +0000 (12:25 -0300)
Otherwise baseparse will consider empty streams to be an error while
an empty stream is a valid scenario. With this patch, errors would
only be emitted if the parser received data but wasn't able to
produce any output from it.

This change is only for push-mode operation as in pull mode an
empty file can be considered an error for the one driving the
pipeline

Includes a unit test for it

https://bugzilla.gnome.org/show_bug.cgi?id=733171

libs/gst/base/gstbaseparse.c
tests/check/libs/baseparse.c

index 013e682..5580b14 100644 (file)
@@ -1165,7 +1165,8 @@ gst_base_parse_sink_event_default (GstBaseParse * parse, GstEvent * event)
         gst_base_parse_finish_fragment (parse, TRUE);
 
       /* If we STILL have zero frames processed, fire an error */
-      if (parse->priv->framecount == 0 && !parse->priv->saw_gaps) {
+      if (parse->priv->framecount == 0 && !parse->priv->saw_gaps &&
+          !parse->priv->first_buffer) {
         GST_ELEMENT_ERROR (parse, STREAM, WRONG_TYPE,
             ("No valid frames found before end of stream"), (NULL));
       }
index 4491c41..b9a8da0 100644 (file)
@@ -28,6 +28,7 @@
 
 static GstPad *mysrcpad, *mysinkpad;
 static GstElement *parsetest;
+static GstBus *bus;
 
 #define TEST_VIDEO_WIDTH 640
 #define TEST_VIDEO_HEIGHT 480
@@ -134,11 +135,17 @@ setup_parsertester (void)
   parsetest = g_object_new (GST_PARSER_TESTER_TYPE, NULL);
   mysrcpad = gst_check_setup_src_pad (parsetest, &srctemplate);
   mysinkpad = gst_check_setup_sink_pad (parsetest, &sinktemplate);
+  bus = gst_bus_new ();
+  gst_element_set_bus (parsetest, bus);
 }
 
 static void
 cleanup_parsertest (void)
 {
+  /* release the bus first to get rid of all refcounts */
+  gst_element_set_bus (parsetest, NULL);
+  gst_object_unref (bus);
+
   gst_pad_set_active (mysrcpad, FALSE);
   gst_pad_set_active (mysinkpad, FALSE);
   gst_check_teardown_src_pad (parsetest);
@@ -184,6 +191,17 @@ send_startup_events (void)
 }
 
 static void
+check_no_error_received (void)
+{
+  GstMessage *msg;
+
+  msg = gst_bus_pop_filtered (bus, GST_MESSAGE_ERROR);
+  fail_unless (msg == NULL);
+  if (msg)
+    gst_message_unref (msg);
+}
+
+static void
 run_parser_playback_test (GList * input, gint expected_output, gdouble rate)
 {
   GstBuffer *buffer;
@@ -238,6 +256,8 @@ run_parser_playback_test (GList * input, gint expected_output, gdouble rate)
   g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
   buffers = NULL;
 
+  check_no_error_received ();
+
   cleanup_parsertest ();
 }
 
@@ -287,6 +307,15 @@ GST_START_TEST (parser_reverse_playback_on_passthrough)
 
 GST_END_TEST;
 
+GST_START_TEST (parser_empty_stream)
+{
+  setup_parsertester ();
+
+  run_parser_playback_test (NULL, 0, 1.0);
+}
+
+GST_END_TEST;
+
 
 static Suite *
 gst_baseparse_suite (void)
@@ -296,6 +325,7 @@ gst_baseparse_suite (void)
 
   suite_add_tcase (s, tc);
   tcase_add_test (tc, parser_playback);
+  tcase_add_test (tc, parser_empty_stream);
   tcase_add_test (tc, parser_reverse_playback_on_passthrough);
 
   return s;