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