1From 0ccc3d3bd930877c8e7bfd4133afa4b56bae46d9 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Tue, 11 Jun 2019 10:19:22 +0800
4Subject: [PATCH 3/5] autodetect: Add preferred for autovideosink/autoaudiosink
5
6Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
7---
8 gst/autodetect/gstautoaudiosink.c |  3 +++
9 gst/autodetect/gstautodetect.c    | 14 ++++++++++++++
10 gst/autodetect/gstautodetect.h    |  1 +
11 gst/autodetect/gstautovideosink.c |  3 +++
12 4 files changed, 21 insertions(+)
13
14diff --git a/gst/autodetect/gstautoaudiosink.c b/gst/autodetect/gstautoaudiosink.c
15index 5c18972..088c83e 100644
16--- a/gst/autodetect/gstautoaudiosink.c
17+++ b/gst/autodetect/gstautoaudiosink.c
18@@ -39,6 +39,8 @@
19 #include "config.h"
20 #endif
21
22+#include <stdlib.h>
23+
24 #include "gstautodetectelements.h"
25 #include "gstautodetect.h"
26 #include "gstautoaudiosink.h"
27@@ -99,6 +101,7 @@ gst_auto_audio_sink_init (GstAutoAudioSink * sink)
28
29   autodetect->media_klass = "Audio";
30   autodetect->flag = GST_ELEMENT_FLAG_SINK;
31+  autodetect->preferred = g_getenv ("AUTOAUDIOSINK_PREFERRED");
32
33   sink->ts_offset = DEFAULT_TS_OFFSET;
34 }
35diff --git a/gst/autodetect/gstautodetect.c b/gst/autodetect/gstautodetect.c
36index 864d465..56ce69d 100644
37--- a/gst/autodetect/gstautodetect.c
38+++ b/gst/autodetect/gstautodetect.c
39@@ -273,6 +273,20 @@ gst_auto_detect_find_best (GstAutoDetect * self)
40   GST_LOG_OBJECT (self, "Trying to find usable %s elements ...",
41       self->media_klass_lc);
42
43+  if (self->preferred) {
44+    for (item = list; item != NULL; item = item->next) {
45+      GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
46+
47+      if (!strcmp (self->preferred, GST_OBJECT_NAME (f))) {
48+        GST_DEBUG_OBJECT (self, "Preferred %s", GST_OBJECT_NAME (f));
49+
50+        list = g_list_delete_link (list, item);
51+        list = g_list_prepend (list, f);
52+        break;
53+      }
54+    }
55+  }
56+
57   for (item = list; item != NULL; item = item->next) {
58     GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
59     GstElement *el;
60diff --git a/gst/autodetect/gstautodetect.h b/gst/autodetect/gstautodetect.h
61index 3f54c14..85731c0 100644
62--- a/gst/autodetect/gstautodetect.h
63+++ b/gst/autodetect/gstautodetect.h
64@@ -41,6 +41,7 @@ typedef struct _GstAutoDetect {
65   GstBin parent;
66
67   /* configuration for subclasses */
68+  const gchar *preferred;
69   const gchar *media_klass; /* Audio/Video/... */
70   GstElementFlags flag; /* GST_ELEMENT_FLAG_{SINK/SOURCE} */
71
72diff --git a/gst/autodetect/gstautovideosink.c b/gst/autodetect/gstautovideosink.c
73index b3eaf1f..545e21c 100644
74--- a/gst/autodetect/gstautovideosink.c
75+++ b/gst/autodetect/gstautovideosink.c
76@@ -39,6 +39,8 @@
77 #include "config.h"
78 #endif
79
80+#include <stdlib.h>
81+
82 #include "gstautodetectelements.h"
83 #include "gstautodetect.h"
84 #include "gstautovideosink.h"
85@@ -99,6 +101,7 @@ gst_auto_video_sink_init (GstAutoVideoSink * sink)
86
87   autodetect->media_klass = "Video";
88   autodetect->flag = GST_ELEMENT_FLAG_SINK;
89+  autodetect->preferred = g_getenv ("AUTOVIDEOSINK_PREFERRED");
90
91   sink->ts_offset = DEFAULT_TS_OFFSET;
92 }
93--
942.20.1
95
96