hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
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
86
87
88
89
90
91
92
93
94
From df1feed17457ac7ca54f78e5f3867c9a0d909d13 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Tue, 11 Jun 2019 10:19:22 +0800
Subject: [PATCH 3/5] autodetect: Add preferred for autovideosink/autoaudiosink
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 gst/autodetect/gstautoaudiosink.c |  3 +++
 gst/autodetect/gstautodetect.c    | 14 ++++++++++++++
 gst/autodetect/gstautodetect.h    |  1 +
 gst/autodetect/gstautovideosink.c |  3 +++
 4 files changed, 21 insertions(+)
 
diff --git a/gst/autodetect/gstautoaudiosink.c b/gst/autodetect/gstautoaudiosink.c
index 26d9f4f..2fad9e6 100644
--- a/gst/autodetect/gstautoaudiosink.c
+++ b/gst/autodetect/gstautoaudiosink.c
@@ -39,6 +39,8 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
+
 #include "gstautoaudiosink.h"
 
 #define DEFAULT_TS_OFFSET           0
@@ -95,6 +97,7 @@ gst_auto_audio_sink_init (GstAutoAudioSink * sink)
 
   autodetect->media_klass = "Audio";
   autodetect->flag = GST_ELEMENT_FLAG_SINK;
+  autodetect->preferred = g_getenv ("AUTOAUDIOSINK_PREFERRED");
 
   sink->ts_offset = DEFAULT_TS_OFFSET;
 }
diff --git a/gst/autodetect/gstautodetect.c b/gst/autodetect/gstautodetect.c
index d6224fa..50ef12b 100644
--- a/gst/autodetect/gstautodetect.c
+++ b/gst/autodetect/gstautodetect.c
@@ -279,6 +279,20 @@ gst_auto_detect_find_best (GstAutoDetect * self)
   GST_LOG_OBJECT (self, "Trying to find usable %s elements ...",
       self->media_klass_lc);
 
+  if (self->preferred) {
+    for (item = list; item != NULL; item = item->next) {
+      GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
+
+      if (!strcmp (self->preferred, GST_OBJECT_NAME (f))) {
+        GST_DEBUG_OBJECT (self, "Preferred %s", GST_OBJECT_NAME (f));
+
+        list = g_list_delete_link (list, item);
+        list = g_list_prepend (list, f);
+        break;
+      }
+    }
+  }
+
   for (item = list; item != NULL; item = item->next) {
     GstElementFactory *f = GST_ELEMENT_FACTORY (item->data);
     GstElement *el;
diff --git a/gst/autodetect/gstautodetect.h b/gst/autodetect/gstautodetect.h
index 05ae89f..f12a31e 100644
--- a/gst/autodetect/gstautodetect.h
+++ b/gst/autodetect/gstautodetect.h
@@ -41,6 +41,7 @@ typedef struct _GstAutoDetect {
   GstBin parent;
   
   /* configuration for subclasses */
+  const gchar *preferred;
   const gchar *media_klass; /* Audio/Video/... */
   GstElementFlags flag; /* GST_ELEMENT_FLAG_{SINK/SOURCE} */
 
diff --git a/gst/autodetect/gstautovideosink.c b/gst/autodetect/gstautovideosink.c
index d46aa69..c5dc963 100644
--- a/gst/autodetect/gstautovideosink.c
+++ b/gst/autodetect/gstautovideosink.c
@@ -39,6 +39,8 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
+
 #include "gstautovideosink.h"
 
 #define DEFAULT_TS_OFFSET           0
@@ -95,6 +97,7 @@ gst_auto_video_sink_init (GstAutoVideoSink * sink)
 
   autodetect->media_klass = "Video";
   autodetect->flag = GST_ELEMENT_FLAG_SINK;
+  autodetect->preferred = g_getenv ("AUTOVIDEOSINK_PREFERRED");
 
   sink->ts_offset = DEFAULT_TS_OFFSET;
 }
-- 
2.17.1