playbin3: Reconfigure on streams-selected message.
authorJan Schmidt <jan@centricular.com>
Mon, 17 Jan 2022 15:52:47 +0000 (02:52 +1100)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 11 Mar 2022 14:02:01 +0000 (15:02 +0100)
Don't reconfigure outputs when the select-streams
event is sent from the app, as the selection may
not take effect for some time. Instead, wait
for the pipeline to confirm the new set of
selected streams when it sends the message.

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

subprojects/gst-plugins-base/gst/playback/gstplaybin3.c

index a732160..1192101 100644 (file)
@@ -2300,15 +2300,8 @@ gst_play_bin3_send_event (GstElement * element, GstEvent * event)
      * the selection with that combiner */
     event = update_select_streams_event (playbin, event, group);
 
-    if (group->collection) {
-      group->selected_stream_types =
-          get_stream_type_for_event (group->collection, event);
-      playbin->selected_stream_types =
-          playbin->groups[0].selected_stream_types | playbin->groups[1].
-          selected_stream_types;
-      if (playbin->active_stream_types != playbin->selected_stream_types)
-        reconfigure_output (playbin);
-    }
+    /* Don't reconfigure playsink just yet, until the streams-selected
+     * message(s) tell us as streams become active / available */
 
     /* Send this event directly to uridecodebin, so it works even
      * if uridecodebin didn't add any pads yet */
@@ -2585,6 +2578,32 @@ gst_play_bin3_handle_message (GstBin * bin, GstMessage * msg)
     if (playbin->is_live && GST_STATE_TARGET (playbin) == GST_STATE_PLAYING) {
       do_reset_time = TRUE;
     }
+  } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED) {
+    GstSourceGroup *target_group;
+
+    GST_PLAY_BIN3_LOCK (playbin);
+
+    target_group = find_source_group_owner (playbin, msg->src);
+    if (target_group) {
+      GstStreamType selected_types = 0;
+      guint i, nb;
+      nb = gst_message_streams_selected_get_size (msg);
+      for (i = 0; i < nb; i++) {
+        GstStream *stream = gst_message_streams_selected_get_stream (msg, i);
+        selected_types |= gst_stream_get_stream_type (stream);
+        gst_object_unref (stream);
+      }
+      target_group->selected_stream_types = selected_types;
+      playbin->selected_stream_types =
+          playbin->groups[0].selected_stream_types | playbin->groups[1].
+          selected_stream_types;
+      if (playbin->active_stream_types != playbin->selected_stream_types) {
+        GST_DEBUG_OBJECT (playbin,
+            "selected stream types changed, reconfiguring output");
+        reconfigure_output (playbin);
+      }
+    }
+    GST_PLAY_BIN3_UNLOCK (playbin);
   }
 
 beach: