hc
2023-02-14 0cc9b7c44253c93447ddf73e206fbdbb3d9f16b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From f1df814e7ff3f4dd817779fc0b8de3fa506aab37 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Fri, 14 Jun 2019 12:02:05 +0800
Subject: [PATCH 06/11] playbin2: Add preferred audio/video sink
 
Using env "PLAYBIN2_PREFERRED_VIDEOSINK" and
"PLAYBIN2_PREFERRED_AUDIOSINK".
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 gst/playback/gstplaybin2.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 
diff --git a/gst/playback/gstplaybin2.c b/gst/playback/gstplaybin2.c
index f71b97752..b0879dbd3 100644
--- a/gst/playback/gstplaybin2.c
+++ b/gst/playback/gstplaybin2.c
@@ -204,6 +204,7 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
 #include <string.h>
 #include <gst/gst.h>
 
@@ -480,6 +481,9 @@ struct _GstPlayBin
   GList *contexts;
 
   gboolean is_live;
+
+  const gchar *apreferred;
+  const gchar *vpreferred;
 };
 
 struct _GstPlayBinClass
@@ -1585,6 +1589,9 @@ gst_play_bin_init (GstPlayBin * playbin)
 
   playbin->multiview_mode = GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE;
   playbin->multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
+
+  playbin->apreferred = g_getenv ("PLAYBIN2_PREFERRED_AUDIOSINK");
+  playbin->vpreferred = g_getenv ("PLAYBIN2_PREFERRED_VIDEOSINK");
 }
 
 static void
@@ -4722,6 +4729,7 @@ autoplug_select_cb (GstElement * decodebin, GstPad * pad,
   GSequence *ave_seq = NULL;
   GSequenceIter *seq_iter;
   gboolean created_sink = FALSE;
+  const gchar *preferred = NULL;
 
   playbin = group->playbin;
 
@@ -4784,6 +4792,29 @@ autoplug_select_cb (GstElement * decodebin, GstPad * pad,
       ave_list = g_list_prepend (ave_list, NULL);
     }
 
+    if (isaudiodec)
+      preferred = playbin->apreferred;
+    else if (isvideodec)
+      preferred = playbin->vpreferred;
+
+    if (preferred) {
+      for (l = ave_list; l; l = l->next) {
+        ave = (GstAVElement *) l->data;
+
+        if (ave && ave->sink &&
+            !strcmp (preferred, GST_OBJECT_NAME (ave->sink))) {
+          GST_DEBUG_OBJECT (playbin,
+              "Preferred sink '%s' for decoder '%s'",
+              gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)),
+              gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
+
+          ave_list = g_list_delete_link (ave_list, l);
+          ave_list = g_list_prepend (ave_list, ave);
+          break;
+        }
+      }
+    }
+
     /* if it is a decoder and we don't have a fixed sink, then find out
      * the matching audio/video sink from GstAVElements list */
     for (l = ave_list; l; l = l->next) {
-- 
2.20.1