examples: win32-videooverlay-playbin: Add a repeat option
authorSeungha Yang <seungha@centricular.com>
Fri, 29 Oct 2021 16:55:38 +0000 (01:55 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 2 Nov 2021 16:55:50 +0000 (16:55 +0000)
... in order to test pipeline/element reuse cases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1275>

subprojects/gst-plugins-base/tests/examples/overlay/win32-videooverlay-playbin.c

index 15e3b9d..a34ffdd 100644 (file)
@@ -30,6 +30,7 @@ static GMainLoop *loop = NULL;
 static gboolean visible = FALSE;
 static HWND hwnd = NULL;
 static gboolean set_handle_on_request = FALSE;
+static gboolean test_reuse = FALSE;
 
 static LRESULT CALLBACK
 window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
@@ -115,6 +116,8 @@ bus_sync_handler (GstBus * bus, GstMessage * msg, gpointer user_data)
       g_clear_error (&err);
       g_free (dbg);
 
+      test_reuse = FALSE;
+
       g_main_loop_quit (loop);
       break;
     }
@@ -145,6 +148,9 @@ main (gint argc, gchar ** argv)
     {"set-handle-on-request", 0, 0, G_OPTION_ARG_NONE, &set_handle_on_request,
         "Set window handle on \"prepare-window-handle\" message", NULL}
     ,
+    {"repeat", 0, 0, G_OPTION_ARG_NONE, &test_reuse,
+        "Repeat and reuse pipeline per EOS", NULL}
+    ,
     {NULL}
   };
 
@@ -218,22 +224,25 @@ main (gint argc, gchar ** argv)
     gst_println ("Will set window handle on \"prepare-window-handle\" message");
   }
 
-  g_object_set (playbin, "uri", uri, NULL);
+  gst_bus_add_watch (GST_ELEMENT_BUS (playbin), bus_msg, playbin);
   gst_bus_set_sync_handler (GST_ELEMENT_BUS (playbin),
       bus_sync_handler, NULL, NULL);
-  gst_bus_add_watch (GST_ELEMENT_BUS (playbin), bus_msg, playbin);
+  g_object_set (playbin, "uri", uri, NULL);
 
-  if (gst_element_set_state (playbin,
-          GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) {
-    gst_printerrln ("Pipeline doesn't want to pause");
-    gst_bus_remove_watch (GST_ELEMENT_BUS (playbin));
+  do {
+    if (gst_element_set_state (playbin,
+            GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) {
+      gst_printerrln ("Pipeline doesn't want to pause");
+      gst_bus_remove_watch (GST_ELEMENT_BUS (playbin));
 
-    exitcode = 1;
-    goto terminate;
-  }
+      exitcode = 1;
+      goto terminate;
+    }
+
+    g_main_loop_run (loop);
+    gst_element_set_state (playbin, GST_STATE_NULL);
+  } while (test_reuse);
 
-  g_main_loop_run (loop);
-  gst_element_set_state (playbin, GST_STATE_NULL);
   gst_bus_remove_watch (GST_ELEMENT_BUS (playbin));
 
 terminate: