Debian Codegraph @

gst-libs/gst/codecparsers/gstlcevcmeta.c

raw symbols SCIP
1 /* GStreamer LCEVC meta
2 * Copyright (C) <2024> V-Nova International Limited
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "gstlcevcmeta.h"
24
25 /**
26 * SECTION:gstlcevcmeta
27 * @title: GstMeta for LCEVC
28 * @short_description: LCEVC related GstMeta
29 *
30 */
31
32 #define GST_CAT_DEFAULT lcevcmeta_debug
33 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
34
35 static gboolean
36 gst_lcevc_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
37 {
38 GstLcevcMeta *emeta = (GstLcevcMeta *) meta;
39
40 emeta->id = 0;
41 emeta->enhancement_data = NULL;
42
43 return TRUE;
44 }
45
46 static void
47 gst_lcevc_meta_free (GstMeta * meta, GstBuffer * buffer)
48 {
49 GstLcevcMeta *emeta = (GstLcevcMeta *) meta;
50
51 g_clear_pointer (&emeta->enhancement_data, gst_buffer_unref);
52 }
53
54 static gboolean
55 gst_lcevc_meta_transform (GstBuffer * dest, GstMeta * meta,
56 GstBuffer * buffer, GQuark type, gpointer data)
57 {
58 GstLcevcMeta *dmeta, *smeta;
59
60 smeta = (GstLcevcMeta *) meta;
61
62 if (GST_META_TRANSFORM_IS_COPY (type)) {
63 GstMetaTransformCopy *copy = data;
64
65 if (!copy->region) {
66 /* only copy if the complete data is copied as well */
67 dmeta = (GstLcevcMeta *) gst_buffer_add_meta (dest,
68 GST_LCEVC_META_INFO, NULL);
69
70 if (!dmeta)
71 return FALSE;
72
73 GST_TRACE ("copying lcevc metadata");
74 dmeta->id = smeta->id;
75
76 g_clear_pointer (&dmeta->enhancement_data, gst_buffer_unref);
77 dmeta->enhancement_data = gst_buffer_copy (smeta->enhancement_data);
78 }
79 } else {
80 /* return FALSE, if transform type is not supported */
81 return FALSE;
82 }
83 return TRUE;
84 }
85
86
87 /**
88 * gst_lcevc_meta_api_get_type:
89 *
90 * Gets the #GType of the LCEVC meta API.
91 *
92 * Returns: the #GType of the LCEVC meta API.
93 *
94 * Since: 1.26
95 */
96 GType
97 gst_lcevc_meta_api_get_type (void)
98 {
99 static GType type = 0;
100 static const gchar *tags[] = { "video", NULL };
101
102 if (g_once_init_enter (&type)) {
103 GType _type = gst_meta_api_type_register ("GstLcevcMetaAPI", tags);
104 g_once_init_leave (&type, _type);
105 }
106 return type;
107 }
108
109 /**
110 * gst_lcevc_meta_get_info:
111 *
112 * Gets the #GstMetaInfo of the LCEVC meta.
113 *
114 * Returns: (transfer none) : the #GstLcevcMeta of the LCEVC meta.
115 *
116 * Since: 1.26
117 */
118 const GstMetaInfo *
119 gst_lcevc_meta_get_info (void)
120 {
121 static const GstMetaInfo *lcevc_meta_info = NULL;
122
123 if (g_once_init_enter ((GstMetaInfo **) & lcevc_meta_info)) {
124 GST_DEBUG_CATEGORY_INIT (lcevcmeta_debug, "lcevcmeta", 0, "LCEVC Metadata");
125
126 const GstMetaInfo *meta = gst_meta_register (GST_LCEVC_META_API_TYPE,
127 "GstLcevcMeta",
128 sizeof (GstLcevcMeta),
129 (GstMetaInitFunction) gst_lcevc_meta_init,
130 (GstMetaFreeFunction) gst_lcevc_meta_free,
131 gst_lcevc_meta_transform);
132 g_once_init_leave ((GstMetaInfo **) & lcevc_meta_info,
133 (GstMetaInfo *) meta);
134 }
135 return lcevc_meta_info;
136 }
137
138 /**
139 * gst_buffer_get_lcevc_meta:
140 * @buffer: a #GstBuffer
141 *
142 * Find the #GstLcevcMeta on @buffer with the lowest @id.
143 *
144 * Buffers can contain multiple #GstLcevcMeta metadata items when dealing with
145 * multiview buffers.
146 *
147 * Returns: (transfer none) (nullable): the #GstLcevcMeta with lowest id (usually 0) or %NULL when there
148 * is no such metadata on @buffer.
149 *
150 * Since: 1.26
151 */
152 GstLcevcMeta *
153 gst_buffer_get_lcevc_meta (GstBuffer * buffer)
154 {
155 gpointer state = NULL;
156 GstLcevcMeta *out = NULL;
157 GstMeta *meta;
158 const GstMetaInfo *info = GST_LCEVC_META_INFO;
159
160 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
161 if (meta->info->api == info->api) {
162 GstLcevcMeta *vmeta = (GstLcevcMeta *) meta;
163 if (vmeta->id == 0)
164 return vmeta; /* Early out for id 0 */
165 if (out == NULL || vmeta->id < out->id)
166 out = vmeta;
167 }
168 }
169 return out;
170 }
171
172 /**
173 * gst_buffer_get_lcevc_meta_id:
174 * @buffer: a #GstBuffer
175 * @id: a metadata id
176 *
177 * Find the #GstLcevcMeta on @buffer with the given @id.
178 *
179 * Buffers can contain multiple #GstLcevcMeta metadata items when dealing with
180 * multiview buffers.
181 *
182 * Returns: (transfer none) (nullable): the #GstLcevcMeta with @id or %NULL when there is no such metadata
183 * on @buffer.
184 *
185 * Since: 1.26
186 */
187 GstLcevcMeta *
188 gst_buffer_get_lcevc_meta_id (GstBuffer * buffer, gint id)
189 {
190 gpointer state = NULL;
191 GstMeta *meta;
192 const GstMetaInfo *info = GST_LCEVC_META_INFO;
193
194 while ((meta = gst_buffer_iterate_meta (buffer, &state))) {
195 if (meta->info->api == info->api) {
196 GstLcevcMeta *vmeta = (GstLcevcMeta *) meta;
197 if (vmeta->id == id)
198 return vmeta;
199 }
200 }
201 return NULL;
202 }
203
204 /**
205 * gst_buffer_add_lcevc_meta:
206 * @buffer: a #GstBuffer
207 * @enhancement_data: (transfer none): the parsed LCEVC enhancement data
208 *
209 * Attaches GstLcevcMeta metadata to @buffer.
210 *
211 * Returns: (transfer none): the #GstLcevcMeta on @buffer.
212 *
213 * Since: 1.26
214 */
215 GstLcevcMeta *
216 gst_buffer_add_lcevc_meta (GstBuffer * buffer, GstBuffer * enhancement_data)
217 {
218 GstLcevcMeta *meta;
219
220 meta = (GstLcevcMeta *) gst_buffer_add_meta (buffer, GST_LCEVC_META_INFO,
221 NULL);
222 if (!meta)
223 return NULL;
224
225 meta->id = 0;
226 g_clear_pointer (&meta->enhancement_data, gst_buffer_unref);
227 meta->enhancement_data = gst_buffer_ref (enhancement_data);
228
229 return meta;
230 }