1 | /* GStreamer |
---|
2 | * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> |
---|
3 | * |
---|
4 | * gsttaginterface.c: interface for tag setting on elements |
---|
5 | * |
---|
6 | * This library is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Library General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Library General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Library General Public |
---|
17 | * License along with this library; if not, write to the |
---|
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | * Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | # include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include "gst_private.h" |
---|
28 | #include "gsttaginterface.h" |
---|
29 | #include <gobject/gvaluecollector.h> |
---|
30 | #include <string.h> |
---|
31 | |
---|
32 | GST_DEBUG_CATEGORY_STATIC (gst_tag_interface_debug); |
---|
33 | #define GST_CAT_DEFAULT tag_tag_interface_debug |
---|
34 | |
---|
35 | static GQuark gst_tag_key; |
---|
36 | |
---|
37 | typedef struct |
---|
38 | { |
---|
39 | GstTagMergeMode mode; |
---|
40 | GstTagList *list; |
---|
41 | } |
---|
42 | GstTagData; |
---|
43 | |
---|
44 | GType |
---|
45 | gst_tag_setter_get_type (void) |
---|
46 | { |
---|
47 | static GType tag_setter_type = 0; |
---|
48 | |
---|
49 | if (!tag_setter_type) { |
---|
50 | static const GTypeInfo tag_setter_info = { |
---|
51 | sizeof (GstTagSetterIFace), /* class_size */ |
---|
52 | NULL, /* base_init */ |
---|
53 | NULL, /* base_finalize */ |
---|
54 | NULL, |
---|
55 | NULL, /* class_finalize */ |
---|
56 | NULL, /* class_data */ |
---|
57 | 0, |
---|
58 | 0, |
---|
59 | NULL |
---|
60 | }; |
---|
61 | |
---|
62 | GST_DEBUG_CATEGORY_INIT (gst_tag_interface_debug, "GstTagInterface", 0, |
---|
63 | "interfaces for tagging"); |
---|
64 | |
---|
65 | tag_setter_type = g_type_register_static (G_TYPE_INTERFACE, "GstTagSetter", |
---|
66 | &tag_setter_info, 0); |
---|
67 | |
---|
68 | g_type_interface_add_prerequisite (tag_setter_type, GST_TYPE_ELEMENT); |
---|
69 | |
---|
70 | gst_tag_key = g_quark_from_static_string ("GST_TAG_SETTER"); |
---|
71 | } |
---|
72 | |
---|
73 | return tag_setter_type; |
---|
74 | } |
---|
75 | static void |
---|
76 | gst_tag_data_free (gpointer p) |
---|
77 | { |
---|
78 | GstTagData *data = (GstTagData *) p; |
---|
79 | |
---|
80 | if (data->list) |
---|
81 | gst_tag_list_free (data->list); |
---|
82 | |
---|
83 | g_free (data); |
---|
84 | } |
---|
85 | static GstTagData * |
---|
86 | gst_tag_setter_get_data (GstTagSetter * setter) |
---|
87 | { |
---|
88 | GstTagData *data; |
---|
89 | |
---|
90 | data = g_object_get_qdata (G_OBJECT (setter), gst_tag_key); |
---|
91 | if (!data) { |
---|
92 | data = g_new (GstTagData, 1); |
---|
93 | data->list = NULL; |
---|
94 | data->mode = GST_TAG_MERGE_KEEP; |
---|
95 | g_object_set_qdata_full (G_OBJECT (setter), gst_tag_key, data, |
---|
96 | gst_tag_data_free); |
---|
97 | } |
---|
98 | |
---|
99 | return data; |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * gst_tag_setter_merge: |
---|
104 | * @setter: a #GstTagSetter |
---|
105 | * @list: a tag list to merge from |
---|
106 | * @mode: the mode to merge with |
---|
107 | * |
---|
108 | * Merges the given list into the setter's list using the given mode. |
---|
109 | */ |
---|
110 | void |
---|
111 | gst_tag_setter_merge (GstTagSetter * setter, const GstTagList * list, |
---|
112 | GstTagMergeMode mode) |
---|
113 | { |
---|
114 | GstTagData *data; |
---|
115 | |
---|
116 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
117 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
118 | |
---|
119 | data = gst_tag_setter_get_data (setter); |
---|
120 | if (!data->list) { |
---|
121 | data->list = gst_tag_list_copy (list); |
---|
122 | } else { |
---|
123 | gst_tag_list_merge (data->list, list, mode); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * gst_tag_setter_add: |
---|
129 | * @setter: a #GstTagSetter |
---|
130 | * @mode: the mode to use |
---|
131 | * @tag: tag to set |
---|
132 | * @...: more tag / value pairs to set |
---|
133 | * |
---|
134 | * Adds the given tag / value pairs on the setter using the given merge mode. |
---|
135 | * The list must be terminated with GST_TAG_INVALID. |
---|
136 | */ |
---|
137 | void |
---|
138 | gst_tag_setter_add (GstTagSetter * setter, GstTagMergeMode mode, |
---|
139 | const gchar * tag, ...) |
---|
140 | { |
---|
141 | va_list args; |
---|
142 | |
---|
143 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
144 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
145 | |
---|
146 | va_start (args, tag); |
---|
147 | gst_tag_setter_add_valist (setter, mode, tag, args); |
---|
148 | va_end (args); |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * gst_tag_setter_add_values: |
---|
153 | * @setter: a #GstTagSetter |
---|
154 | * @mode: the mode to use |
---|
155 | * @tag: tag to set |
---|
156 | * @...: more tag / GValue pairs to set |
---|
157 | * |
---|
158 | * Adds the given tag / GValue pairs on the setter using the given merge mode. |
---|
159 | * The list must be terminated with GST_TAG_INVALID. |
---|
160 | */ |
---|
161 | void |
---|
162 | gst_tag_setter_add_values (GstTagSetter * setter, GstTagMergeMode mode, |
---|
163 | const gchar * tag, ...) |
---|
164 | { |
---|
165 | va_list args; |
---|
166 | |
---|
167 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
168 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
169 | |
---|
170 | va_start (args, tag); |
---|
171 | gst_tag_setter_add_valist_values (setter, mode, tag, args); |
---|
172 | va_end (args); |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | * gst_tag_setter_add_valist: |
---|
177 | * @setter: a #GstTagSetter |
---|
178 | * @mode: the mode to use |
---|
179 | * @tag: tag to set |
---|
180 | * @var_args: tag / value pairs to set |
---|
181 | * |
---|
182 | * Adds the given tag / value pairs on the setter using the given merge mode. |
---|
183 | * The list must be terminated with GST_TAG_INVALID. |
---|
184 | */ |
---|
185 | void |
---|
186 | gst_tag_setter_add_valist (GstTagSetter * setter, GstTagMergeMode mode, |
---|
187 | const gchar * tag, va_list var_args) |
---|
188 | { |
---|
189 | GstTagData *data; |
---|
190 | |
---|
191 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
192 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
193 | |
---|
194 | data = gst_tag_setter_get_data (setter); |
---|
195 | if (!data->list) |
---|
196 | data->list = gst_tag_list_new (); |
---|
197 | |
---|
198 | gst_tag_list_add_valist (data->list, mode, tag, var_args); |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * gst_tag_setter_add_valist_values: |
---|
203 | * @setter: a #GstTagSetter |
---|
204 | * @mode: the mode to use |
---|
205 | * @tag: tag to set |
---|
206 | * @var_args: tag / GValue pairs to set |
---|
207 | * |
---|
208 | * Adds the given tag / GValue pairs on the setter using the given merge mode. |
---|
209 | * The list must be terminated with GST_TAG_INVALID. |
---|
210 | */ |
---|
211 | void |
---|
212 | gst_tag_setter_add_valist_values (GstTagSetter * setter, GstTagMergeMode mode, |
---|
213 | const gchar * tag, va_list var_args) |
---|
214 | { |
---|
215 | GstTagData *data; |
---|
216 | |
---|
217 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
218 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
219 | |
---|
220 | data = gst_tag_setter_get_data (setter); |
---|
221 | if (!data->list) |
---|
222 | data->list = gst_tag_list_new (); |
---|
223 | |
---|
224 | gst_tag_list_add_valist_values (data->list, mode, tag, var_args); |
---|
225 | } |
---|
226 | |
---|
227 | /** |
---|
228 | * gst_tag_setter_get_list: |
---|
229 | * @setter: a #GstTagSetter |
---|
230 | * |
---|
231 | * Retrieves a copy of the current list of tags the setter uses. |
---|
232 | * You need to gst_tag_list_free() the list after use. |
---|
233 | * |
---|
234 | * Returns: a current snapshot of the taglist used in the setter |
---|
235 | * or NULL if none is used. |
---|
236 | */ |
---|
237 | const GstTagList * |
---|
238 | gst_tag_setter_get_list (GstTagSetter * setter) |
---|
239 | { |
---|
240 | g_return_val_if_fail (GST_IS_TAG_SETTER (setter), NULL); |
---|
241 | |
---|
242 | return gst_tag_setter_get_data (setter)->list; |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * gst_tag_setter_set_merge_mode: |
---|
247 | * @setter: a #GstTagSetter |
---|
248 | * @mode: The mode with which tags are added |
---|
249 | * |
---|
250 | * Sets the given merge mode that is used for adding tags from events to tags |
---|
251 | * specified by this interface. The default is #GST_TAG_MERGE_KEEP, which keeps |
---|
252 | * the tags by this interface and discards tags from events. |
---|
253 | */ |
---|
254 | void |
---|
255 | gst_tag_setter_set_merge_mode (GstTagSetter * setter, GstTagMergeMode mode) |
---|
256 | { |
---|
257 | g_return_if_fail (GST_IS_TAG_SETTER (setter)); |
---|
258 | g_return_if_fail (GST_TAG_MODE_IS_VALID (mode)); |
---|
259 | |
---|
260 | gst_tag_setter_get_data (setter)->mode = mode; |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * gst_tag_setter_get_merge_mode: |
---|
265 | * @setter: a #GstTagSetter |
---|
266 | * |
---|
267 | * Queries the mode by which tags inside the setter are overwritten by tags |
---|
268 | * from events |
---|
269 | * |
---|
270 | * Returns: the merge mode used inside the element. |
---|
271 | */ |
---|
272 | GstTagMergeMode |
---|
273 | gst_tag_setter_get_merge_mode (GstTagSetter * setter) |
---|
274 | { |
---|
275 | g_return_val_if_fail (GST_IS_TAG_SETTER (setter), FALSE); |
---|
276 | |
---|
277 | return gst_tag_setter_get_data (setter)->mode; |
---|
278 | } |
---|