pipeline: Be smarter about how we match encoding profiles and tracks
authorThibault Saunier <tsaunier@igalia.com>
Thu, 17 Oct 2019 14:19:11 +0000 (16:19 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Mon, 21 Oct 2019 10:25:25 +0000 (10:25 +0000)
ges/ges-pipeline.c

index 6dd5316..a30b12b 100644 (file)
@@ -1041,6 +1041,7 @@ ges_pipeline_set_render_settings (GESPipeline * pipeline,
 {
   GError *err = NULL;
   GstEncodingProfile *set_profile;
+  guint n_videotracks = 0, n_audiotracks = 0;
 
   g_return_val_if_fail (GES_IS_PIPELINE (pipeline), FALSE);
   CHECK_THREAD (pipeline);
@@ -1056,21 +1057,27 @@ ges_pipeline_set_render_settings (GESPipeline * pipeline,
     GList *tmptrack, *tracks =
         ges_timeline_get_tracks (pipeline->priv->timeline);
 
-    for (; tmpprofiles; tmpprofiles = tmpprofiles->next) {
-      for (tmptrack = tracks; tmptrack; tmptrack = tmptrack->next) {
-        if ((GST_IS_ENCODING_AUDIO_PROFILE (tmpprofiles->data) &&
-                GES_IS_AUDIO_TRACK (tmptrack->data)) ||
-            (GST_IS_ENCODING_VIDEO_PROFILE (tmpprofiles->data) &&
-                GES_IS_VIDEO_TRACK (tmptrack->data))) {
-          GST_DEBUG_OBJECT (pipeline, "Setting presence to 1!");
-          gst_encoding_profile_set_presence (tmpprofiles->data, 1);
-          gst_encoding_profile_set_allow_dynamic_output (tmpprofiles->data,
-              FALSE);
-        }
-      }
+    for (tmptrack = tracks; tmptrack; tmptrack = tmptrack->next) {
+      if (GES_IS_AUDIO_TRACK (tmptrack->data))
+        n_audiotracks++;
+      else if (GES_IS_VIDEO_TRACK (tmptrack->data))
+        n_videotracks++;
     }
-
     g_list_free_full (tracks, gst_object_unref);
+
+    for (; tmpprofiles; tmpprofiles = tmpprofiles->next) {
+      if ((GST_IS_ENCODING_AUDIO_PROFILE (tmpprofiles->data) && n_audiotracks))
+        n_audiotracks--;
+      else if ((GST_IS_ENCODING_VIDEO_PROFILE (tmpprofiles->data)
+              && n_videotracks))
+        n_videotracks--;
+      else
+        continue;
+
+      GST_DEBUG_OBJECT (pipeline, "Setting presence to 1!");
+      gst_encoding_profile_set_presence (tmpprofiles->data, 1);
+      gst_encoding_profile_set_allow_dynamic_output (tmpprofiles->data, FALSE);
+    }
   }
 
   /* Clear previous URI sink if it existed */