Debian Codegraph @

gst/autoconvert/gstautovideo.c

raw symbols SCIP
1 /* GStreamer
2 * Copyright 2023 Igalia S.L.
3 * @author: Thibault Saunier <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <string.h>
25
26 #include "gstautovideo.h"
27
28 GST_DEBUG_CATEGORY (autovideo_debug);
29 #define GST_CAT_DEFAULT (autovideo_debug)
30
31 static gboolean
32 append_elements (GString * name, GString * bindesc,
33 const gchar * const *elements)
34 {
35 if (!elements) {
36 /* Nothing to do. */
37 return TRUE;
38 }
39
40 for (gint i = 0; elements[i]; i++) {
41 gchar **e = g_strsplit (elements[i], " ", 2);
42 GstElementFactory *factory = gst_element_factory_find (g_strchomp (e[0]));
43
44 if (!factory) {
45 GST_DEBUG_OBJECT (NULL, "Factory %s not found: %s", e[0], elements[i]);
46
47 g_strfreev (e);
48 return FALSE;
49 }
50
51 if (name) {
52 g_string_append (name, e[0]);
53 }
54 g_strfreev (e);
55
56 if (bindesc->len > 0) {
57 g_string_append (bindesc, " ! ");
58 }
59 g_string_append (bindesc, elements[i]);
60 }
61
62 return TRUE;
63 }
64
65 static void
66 register_known_bin (GstBaseAutoConvert * self,
67 const gchar * const *first_elements,
68 const gchar * const *colorspace_converters,
69 const gchar * const *last_elements,
70 const gchar * const *filters, GstRank rank)
71 {
72 GString *name = g_string_new ("autovideoconvert-");
73 GString *bindesc = g_string_new ("");
74
75 if (!append_elements (name, bindesc, first_elements))
76 goto abort;
77 if (!append_elements (name, bindesc, colorspace_converters))
78 goto abort;
79
80 for (gint i = 0; filters && filters[i]; i++) {
81 const gchar *tmp[2] = { filters[i], NULL };
82 if (!append_elements (name, bindesc, tmp))
83 goto abort;
84 if (!append_elements (NULL, bindesc, colorspace_converters))
85 goto abort;
86 }
87 if (!append_elements (name, bindesc, last_elements))
88 goto abort;
89
90 gst_base_auto_convert_register_filter (GST_BASE_AUTO_CONVERT (self),
91 g_string_free (name, FALSE), g_string_free (bindesc, FALSE), rank);
92 return;
93
94 abort:
95 g_string_free (name, TRUE);
96 g_string_free (bindesc, TRUE);
97 }
98
99
100 void
101 gst_auto_video_register_well_known_bins (GstBaseAutoConvert * self,
102 const GstAutoVideoFilterGenerator * gen)
103 {
104 static gsize gst_auto_video_register_well_known_bins_once = 0;
105
106 if (g_once_init_enter (&gst_auto_video_register_well_known_bins_once)) {
107 GST_DEBUG_CATEGORY_INIT (autovideo_debug, "autovideo", 0, "Auto video");
108 g_once_init_leave (&gst_auto_video_register_well_known_bins_once, TRUE);
109 }
110
111 for (gint i = 0; gen[i].colorspace_converters[0] || gen[i].first_elements[0]
112 || gen[i].last_elements[0] || gen[i].filters[0]; i++) {
113 register_known_bin (self, gen[i].first_elements,
114 gen[i].colorspace_converters, gen[i].last_elements, gen[i].filters,
115 gen[i].rank);
116 }
117 }