1 /* GStreamer non-core tag registration and tag utility functions
2 * Copyright (C) 2005 Ross Burton <ross@burtonini.com>
3 * Copyright (C) 2006-2008 Tim-Philipp Müller <tim centricular net>
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
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/gst-i18n-plugin.h>
26 #include <gst/base/gsttypefindhelper.h>
27 #include <gst/gst.h>
28 #include "tag.h"
29 #include "id3v2.h"
30
31 #include <string.h>
32
33 /**
34 * SECTION:gsttag
35 * @title: Tags
36 * @short_description: additional tag definitions for plugins and applications
37 * @see_also: #GstTagList
38 *
39 * Contains additional standardized GStreamer tag definitions for plugins
40 * and applications, and functions to register them with the GStreamer
41 * tag system.
42 *
43 */
44
45 #ifndef GST_DISABLE_GST_DEBUG
46 #define GST_CAT_DEFAULT gst_tag_ensure_debug_category()
47
48 static GstDebugCategory *
gst_tag_ensure_debug_category(void)49 gst_tag_ensure_debug_category (void)
50 {
51 static gsize cat_gonce = 0;
52
53 if (g_once_init_enter (&cat_gonce)) {
54 GstDebugCategory *cat = NULL;
55
56 GST_DEBUG_CATEGORY_INIT (cat, "tag-tags", 0, "GstTag helper functions");
57
58 g_once_init_leave (&cat_gonce, (gsize) cat);
59 }
60
61 return (GstDebugCategory *) cat_gonce;
62 }
63 #endif /* GST_DISABLE_GST_DEBUG */
64
65 static gpointer
gst_tag_register_tags_internal(gpointer unused)66 gst_tag_register_tags_internal (gpointer unused)
67 {
68 #ifdef ENABLE_NLS
69 GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
70 LOCALEDIR);
71 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
72 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
73 #endif
74
75 /* musicbrainz tags */
76 gst_tag_register_static (GST_TAG_MUSICBRAINZ_TRACKID, GST_TAG_FLAG_META,
77 G_TYPE_STRING, _("track ID"), _("MusicBrainz track ID"), NULL);
78 gst_tag_register_static (GST_TAG_MUSICBRAINZ_ARTISTID, GST_TAG_FLAG_META,
79 G_TYPE_STRING, _("artist ID"), _("MusicBrainz artist ID"), NULL);
80 gst_tag_register_static (GST_TAG_MUSICBRAINZ_ALBUMID, GST_TAG_FLAG_META,
81 G_TYPE_STRING, _("album ID"), _("MusicBrainz album ID"), NULL);
82 gst_tag_register_static (GST_TAG_MUSICBRAINZ_ALBUMARTISTID, GST_TAG_FLAG_META,
83 G_TYPE_STRING,
84 _("album artist ID"), _("MusicBrainz album artist ID"), NULL);
85 gst_tag_register_static (GST_TAG_MUSICBRAINZ_TRMID, GST_TAG_FLAG_META,
86 G_TYPE_STRING, _("track TRM ID"), _("MusicBrainz TRM ID"), NULL);
87
88 /* CDDA tags */
89 gst_tag_register_static (GST_TAG_CDDA_CDDB_DISCID, GST_TAG_FLAG_META,
90 G_TYPE_STRING, "discid", "CDDB discid for metadata retrieval",
91 gst_tag_merge_use_first);
92
93 gst_tag_register_static (GST_TAG_CDDA_CDDB_DISCID_FULL, GST_TAG_FLAG_META,
94 G_TYPE_STRING, "discid full",
95 "CDDB discid for metadata retrieval (full)", gst_tag_merge_use_first);
96
97 gst_tag_register_static (GST_TAG_CDDA_MUSICBRAINZ_DISCID, GST_TAG_FLAG_META,
98 G_TYPE_STRING, "musicbrainz-discid",
99 "Musicbrainz discid for metadata retrieval", gst_tag_merge_use_first);
100
101 gst_tag_register_static (GST_TAG_CDDA_MUSICBRAINZ_DISCID_FULL,
102 GST_TAG_FLAG_META, G_TYPE_STRING, "musicbrainz-discid-full",
103 "Musicbrainz discid for metadata retrieval (full)",
104 gst_tag_merge_use_first);
105
106 /* photography tags */
107 gst_tag_register_static (GST_TAG_CAPTURING_SHUTTER_SPEED, GST_TAG_FLAG_META,
108 GST_TYPE_FRACTION, _("capturing shutter speed"),
109 _("Shutter speed used when capturing an image, in seconds"), NULL);
110
111 gst_tag_register_static (GST_TAG_CAPTURING_FOCAL_RATIO, GST_TAG_FLAG_META,
112 G_TYPE_DOUBLE, _("capturing focal ratio"),
113 _("Focal ratio (f-number) used when capturing the image"), NULL);
114
115 gst_tag_register_static (GST_TAG_CAPTURING_FOCAL_LENGTH, GST_TAG_FLAG_META,
116 G_TYPE_DOUBLE, _("capturing focal length"),
117 _("Focal length of the lens used capturing the image, in mm"), NULL);
118
119 gst_tag_register_static (GST_TAG_CAPTURING_FOCAL_LENGTH_35_MM,
120 GST_TAG_FLAG_META, G_TYPE_DOUBLE,
121 _("capturing 35 mm equivalent focal length"),
122 _("35 mm equivalent focal length of the lens used capturing the image, "
123 "in mm"), NULL);
124
125 gst_tag_register_static (GST_TAG_CAPTURING_DIGITAL_ZOOM_RATIO,
126 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("capturing digital zoom ratio"),
127 _("Digital zoom ratio used when capturing an image"), NULL);
128
129 gst_tag_register_static (GST_TAG_CAPTURING_ISO_SPEED, GST_TAG_FLAG_META,
130 G_TYPE_INT, _("capturing iso speed"),
131 _("The ISO speed used when capturing an image"), NULL);
132
133 gst_tag_register_static (GST_TAG_CAPTURING_EXPOSURE_PROGRAM,
134 GST_TAG_FLAG_META, G_TYPE_STRING, _("capturing exposure program"),
135 _("The exposure program used when capturing an image"), NULL);
136
137 gst_tag_register_static (GST_TAG_CAPTURING_EXPOSURE_MODE, GST_TAG_FLAG_META,
138 G_TYPE_STRING, _("capturing exposure mode"),
139 _("The exposure mode used when capturing an image"), NULL);
140
141 gst_tag_register_static (GST_TAG_CAPTURING_EXPOSURE_COMPENSATION,
142 GST_TAG_FLAG_META, G_TYPE_DOUBLE, _("capturing exposure compensation"),
143 _("The exposure compensation used when capturing an image"), NULL);
144
145 gst_tag_register_static (GST_TAG_CAPTURING_SCENE_CAPTURE_TYPE,
146 GST_TAG_FLAG_META, G_TYPE_STRING, _("capturing scene capture type"),
147 _("The scene capture mode used when capturing an image"), NULL);
148
149 gst_tag_register_static (GST_TAG_CAPTURING_GAIN_ADJUSTMENT, GST_TAG_FLAG_META,
150 G_TYPE_STRING, _("capturing gain adjustment"),
151 _("The overall gain adjustment applied on an image"), NULL);
152
153 gst_tag_register_static (GST_TAG_CAPTURING_WHITE_BALANCE, GST_TAG_FLAG_META,
154 G_TYPE_STRING, _("capturing white balance"),
155 _("The white balance mode set when capturing an image"), NULL);
156
157 gst_tag_register_static (GST_TAG_CAPTURING_CONTRAST, GST_TAG_FLAG_META,
158 G_TYPE_STRING, _("capturing contrast"),
159 _("The direction of contrast processing applied "
160 "when capturing an image"), NULL);
161
162 gst_tag_register_static (GST_TAG_CAPTURING_SATURATION, GST_TAG_FLAG_META,
163 G_TYPE_STRING, _("capturing saturation"),
164 _("The direction of saturation processing applied when "
165 "capturing an image"), NULL);
166
167 gst_tag_register_static (GST_TAG_CAPTURING_SHARPNESS, GST_TAG_FLAG_META,
168 G_TYPE_STRING, _("capturing sharpness"),
169 _("The direction of sharpness processing applied "
170 "when capturing an image"), NULL);
171
172 gst_tag_register_static (GST_TAG_CAPTURING_FLASH_FIRED, GST_TAG_FLAG_META,
173 G_TYPE_BOOLEAN, _("capturing flash fired"),
174 _("If the flash fired while capturing an image"), NULL);
175
176 gst_tag_register_static (GST_TAG_CAPTURING_FLASH_MODE, GST_TAG_FLAG_META,
177 G_TYPE_STRING, _("capturing flash mode"),
178 _("The selected flash mode while capturing an image"), NULL);
179
180 gst_tag_register_static (GST_TAG_CAPTURING_METERING_MODE, GST_TAG_FLAG_META,
181 G_TYPE_STRING, _("capturing metering mode"),
182 _("The metering mode used while determining exposure for capturing an"
183 " image"), NULL);
184
185 gst_tag_register_static (GST_TAG_CAPTURING_SOURCE, GST_TAG_FLAG_META,
186 G_TYPE_STRING, _("capturing source"),
187 _("The source or type of device used for the capture"), NULL);
188
189 gst_tag_register_static (GST_TAG_IMAGE_HORIZONTAL_PPI, GST_TAG_FLAG_META,
190 G_TYPE_DOUBLE, _("image horizontal ppi"),
191 _("Media (image/video) intended horizontal pixel density in ppi"), NULL);
192
193 gst_tag_register_static (GST_TAG_IMAGE_VERTICAL_PPI, GST_TAG_FLAG_META,
194 G_TYPE_DOUBLE, _("image vertical ppi"),
195 _("Media (image/video) intended vertical pixel density in ppi"), NULL);
196
197 gst_tag_register_static (GST_TAG_ID3V2_FRAME, GST_TAG_FLAG_META,
198 GST_TYPE_SAMPLE, _("ID3v2 frame"), _("unparsed id3v2 tag frame"),
199 gst_tag_merge_use_first);
200
201 gst_tag_register_static (GST_TAG_MUSICAL_KEY, GST_TAG_FLAG_META,
202 G_TYPE_STRING, _("musical-key"), _("Initial key in which the "
203 "sound starts"), gst_tag_merge_use_first);
204
205 return NULL;
206 }
207
208 /* FIXME 0.11: rename this to gst_tag_init() or gst_tag_register_tags() or
209 * even better: make tags auto-register themselves, either by defining them
210 * to a wrapper func that does the initing, or by adding tag factories so
211 * that the core can load+register tags automatically when needed. */
212
213 /**
214 * gst_tag_register_musicbrainz_tags:
215 *
216 * Registers additional musicbrainz-specific tags with the GStreamer tag
217 * system. Plugins and applications that use these tags should call this
218 * function before using them. Can be called multiple times.
219 */
220 void
gst_tag_register_musicbrainz_tags(void)221 gst_tag_register_musicbrainz_tags (void)
222 {
223 static GOnce mb_once = G_ONCE_INIT;
224
225 g_once (&mb_once, gst_tag_register_tags_internal, NULL);
226 }
227
228 static inline gboolean
gst_tag_image_type_is_valid(GstTagImageType type)229 gst_tag_image_type_is_valid (GstTagImageType type)
230 {
231 GEnumClass *klass;
232
233 gboolean res;
234
235 klass = g_type_class_ref (gst_tag_image_type_get_type ());
236 res = (g_enum_get_value (klass, type) != NULL);
237 g_type_class_unref (klass);
238
239 return res;
240 }
241
242 /**
243 * gst_tag_parse_extended_comment:
244 * @ext_comment: an extended comment string, see #GST_TAG_EXTENDED_COMMENT
245 * @key: (out) (nullable):
246 * return location for the comment description key, or NULL
247 * @lang: (out) (nullable):
248 * return location for the comment ISO-639 language code, or NULL
249 * @value: (out): return location for the actual comment string, or NULL
250 * @fail_if_no_key: whether to fail if strings are not in key=value form
251 *
252 * Convenience function to parse a GST_TAG_EXTENDED_COMMENT string and
253 * separate it into its components.
254 *
255 * If successful, @key, @lang and/or @value will be set to newly allocated
256 * strings that you need to free with g_free() when done. @key and @lang
257 * may also be set to NULL by this function if there is no key or no language
258 * code in the extended comment string.
259 *
260 * Returns: TRUE if the string could be parsed, otherwise FALSE
261 */
262 gboolean
gst_tag_parse_extended_comment(const gchar * ext_comment,gchar ** key,gchar ** lang,gchar ** value,gboolean fail_if_no_key)263 gst_tag_parse_extended_comment (const gchar * ext_comment, gchar ** key,
264 gchar ** lang, gchar ** value, gboolean fail_if_no_key)
265 {
266 const gchar *div, *bop, *bcl;
267
268 g_return_val_if_fail (ext_comment != NULL, FALSE);
269 g_return_val_if_fail (g_utf8_validate (ext_comment, -1, NULL), FALSE);
270
271 if (key)
272 *key = NULL;
273 if (lang)
274 *lang = NULL;
275
276 div = strchr (ext_comment, '=');
277 bop = strchr (ext_comment, '[');
278 bcl = strchr (ext_comment, ']');
279
280 if (div == NULL) {
281 if (fail_if_no_key)
282 return FALSE;
283 if (value)
284 *value = g_strdup (ext_comment);
285 return TRUE;
286 }
287
288 if (bop != NULL && bop < div) {
289 if (bcl < bop || bcl > div)
290 return FALSE;
291 if (key)
292 *key = g_strndup (ext_comment, bop - ext_comment);
293 if (lang)
294 *lang = g_strndup (bop + 1, bcl - bop - 1);
295 } else {
296 if (key)
297 *key = g_strndup (ext_comment, div - ext_comment);
298 }
299
300 if (value)
301 *value = g_strdup (div + 1);
302
303 return TRUE;
304 }
305
306 /**
307 * gst_tag_freeform_string_to_utf8:
308 * @data: (array length=size) (element-type gchar): string data
309 * @size: length of string data, or -1 if the string is NUL-terminated
310 * @env_vars: (array zero-terminated=1)
311 * a NULL-terminated string array of environment variable names, or NULL
312 *
313 * Convenience function to read a string with unknown character encoding. If
314 * the string is already in UTF-8 encoding, it will be returned right away.
315 * If not it tries to detect byte-order-mark for UTF-16/32 cases and use that.
316 * Otherwise, the environment will be searched for a number of environment
317 * variables (whose names are specified in the NULL-terminated string array
318 * @env_vars) containing a list of character encodings to try/use. If none
319 * are specified, the current locale will be tried. If that also doesn't work,
320 * WINDOWS-1252/ISO-8859-1 is assumed (which will almost always succeed).
321 *
322 * Returns: a newly-allocated string in UTF-8 encoding, or NULL
323 */
324 gchar *
gst_tag_freeform_string_to_utf8(const gchar * data,gint size,const gchar ** env_vars)325 gst_tag_freeform_string_to_utf8 (const gchar * data, gint size,
326 const gchar ** env_vars)
327 {
328 const gchar *cur_loc = NULL;
329
330 gsize bytes_read;
331
332 gchar *utf8 = NULL;
333
334 g_return_val_if_fail (data != NULL, NULL);
335
336 if (size < 0)
337 size = strlen (data);
338
339 /* chop off trailing string terminators to make sure utf8_validate doesn't
340 * get to see them (since that would make the utf8 check fail) */
341 while (size > 0 && data[size - 1] == '\0')
342 --size;
343
344 /* Should we try the charsets specified
345 * via environment variables FIRST ? */
346 if (g_utf8_validate (data, size, NULL)) {
347 utf8 = g_strndup (data, size);
348 GST_LOG ("String '%s' is valid UTF-8 already", utf8);
349 goto beach;
350 }
351
352 /* check for and use byte-order-mark for UTF-16/32 cases */
353 if (size >= 2) {
354 const gchar *c = NULL;
355 gint prefix, ssize;
356
357 if (size >= 4) {
358 prefix = 4;
359 ssize = GST_ROUND_DOWN_4 (size - 4);
360 switch (GST_READ_UINT32_BE (data)) {
361 case 0x0000FEFF:
362 c = "UTF-32BE";
363 break;
364 case 0xFFFE0000:
365 c = "UTF-32LE";
366 break;
367 default:
368 break;
369 }
370 }
371 if (!c) {
372 prefix = 2;
373 ssize = GST_ROUND_DOWN_2 (size - 2);
374 switch (GST_READ_UINT16_BE (data)) {
375 case 0xFEFF:
376 c = "UTF-16BE";
377 break;
378 case 0xFFFE:
379 c = "UTF-16LE";
380 break;
381 default:
382 break;
383 }
384 }
385 if (c) {
386 GST_LOG ("Trying to convert freeform string to UTF-8 from '%s'", c);
387 if ((utf8 =
388 g_convert (data + prefix, ssize, "UTF-8", c, &bytes_read, NULL,
389 NULL))) {
390 if (bytes_read == ssize)
391 goto beach;
392 g_free (utf8);
393 utf8 = NULL;
394 }
395 }
396 }
397
398 while (env_vars && *env_vars != NULL) {
399 const gchar *env = NULL;
400
401 /* Try charsets specified via the environment */
402 env = g_getenv (*env_vars);
403 if (env != NULL && *env != '\0') {
404 gchar **c, **csets;
405
406 csets = g_strsplit (env, G_SEARCHPATH_SEPARATOR_S, -1);
407
408 for (c = csets; c && *c; ++c) {
409 GST_LOG ("Trying to convert freeform string to UTF-8 from '%s'", *c);
410 if ((utf8 =
411 g_convert (data, size, "UTF-8", *c, &bytes_read, NULL, NULL))) {
412 if (bytes_read == size) {
413 g_strfreev (csets);
414 goto beach;
415 }
416 g_free (utf8);
417 utf8 = NULL;
418 }
419 }
420
421 g_strfreev (csets);
422 }
423 ++env_vars;
424 }
425
426 /* Try current locale (if not UTF-8) */
427 if (!g_get_charset (&cur_loc)) {
428 GST_LOG ("Trying to convert freeform string using locale ('%s')", cur_loc);
429 if ((utf8 = g_locale_to_utf8 (data, size, &bytes_read, NULL, NULL))) {
430 if (bytes_read == size) {
431 goto beach;
432 }
433 g_free (utf8);
434 utf8 = NULL;
435 }
436 }
437
438 /* Try Windows-1252 (which is a superset of ISO 8859-1 that uses a control
439 * character range in ISO 8859-1 for more printable characters) */
440 {
441 GError *err = NULL;
442
443 GST_LOG ("Trying to convert freeform string using Windows-1252/ISO-8859-1 "
444 "fallback");
445 utf8 = g_convert (data, size, "UTF-8", "WINDOWS-1252", &bytes_read, NULL,
446 &err);
447 if (err != NULL) {
448 /* fallback in case iconv implementation doesn't support windows-1252
449 * for some reason */
450 if (err->code == G_CONVERT_ERROR_NO_CONVERSION) {
451 g_free (utf8);
452 utf8 = g_convert (data, size, "UTF-8", "ISO-8859-1", &bytes_read,
453 NULL, NULL);
454 }
455 g_error_free (err);
456 }
457
458 if (utf8 != NULL && bytes_read == size)
459 goto beach;
460 }
461
462 g_free (utf8);
463 return NULL;
464
465 beach:
466
467 g_strchomp (utf8);
468 if (utf8 && utf8[0] != '\0') {
469 GST_LOG ("Returning '%s'", utf8);
470 return utf8;
471 }
472
473 g_free (utf8);
474 return NULL;
475 }
476
477 /**
478 * gst_tag_image_data_to_image_sample:
479 * @image_data: (array length=image_data_len): the (encoded) image
480 * @image_data_len: the length of the encoded image data at @image_data
481 * @image_type: type of the image, or #GST_TAG_IMAGE_TYPE_UNDEFINED. Pass
482 * #GST_TAG_IMAGE_TYPE_NONE if no image type should be set at all (e.g.
483 * for preview images)
484 *
485 * Helper function for tag-reading plugins to create a #GstSample suitable to
486 * add to a #GstTagList as an image tag (such as #GST_TAG_IMAGE or
487 * #GST_TAG_PREVIEW_IMAGE) from the encoded image data and an (optional) image
488 * type.
489 *
490 * Background: cover art and other images in tags are usually stored as a
491 * blob of binary image data, often accompanied by a MIME type or some other
492 * content type string (e.g. 'png', 'jpeg', 'jpg'). Sometimes there is also an
493 * 'image type' to indicate what kind of image this is (e.g. front cover,
494 * back cover, artist, etc.). The image data may also be an URI to the image
495 * rather than the image itself.
496 *
497 * In GStreamer, image tags are #GstSample<!-- -->s containing the raw image
498 * data, with the sample caps describing the content type of the image
499 * (e.g. image/jpeg, image/png, text/uri-list). The sample info may contain
500 * an additional 'image-type' field of #GST_TYPE_TAG_IMAGE_TYPE to describe
501 * the type of image (front cover, back cover etc.). #GST_TAG_PREVIEW_IMAGE
502 * tags should not carry an image type, their type is already indicated via
503 * the special tag name.
504 *
505 * This function will do various checks and typefind the encoded image
506 * data (we can't trust the declared mime type).
507 *
508 * Returns: a newly-allocated image sample for use in tag lists, or NULL
509 */
510 GstSample *
gst_tag_image_data_to_image_sample(const guint8 * image_data,guint image_data_len,GstTagImageType image_type)511 gst_tag_image_data_to_image_sample (const guint8 * image_data,
512 guint image_data_len, GstTagImageType image_type)
513 {
514 const gchar *name;
515 GstBuffer *image;
516 GstSample *sample;
517 GstCaps *caps;
518 GstMapInfo info;
519 GstStructure *image_info = NULL;
520
521 g_return_val_if_fail (image_data != NULL, NULL);
522 g_return_val_if_fail (image_data_len > 0, NULL);
523 g_return_val_if_fail (gst_tag_image_type_is_valid (image_type), NULL);
524
525 GST_DEBUG ("image data len: %u bytes", image_data_len);
526
527 /* allocate space for a NUL terminator for an uri too */
528 image = gst_buffer_new_and_alloc (image_data_len + 1);
529 if (image == NULL)
530 goto alloc_failed;
531
532 gst_buffer_map (image, &info, GST_MAP_WRITE);
533 memcpy (info.data, image_data, image_data_len);
534 info.data[image_data_len] = '\0';
535 gst_buffer_unmap (image, &info);
536
537 /* Find GStreamer media type, can't trust declared type */
538 caps = gst_type_find_helper_for_buffer (NULL, image, NULL);
539
540 if (caps == NULL)
541 goto no_type;
542
543 GST_DEBUG ("Found GStreamer media type: %" GST_PTR_FORMAT, caps);
544
545 /* sanity check: make sure typefound/declared caps are either URI or image */
546 name = gst_structure_get_name (gst_caps_get_structure (caps, 0));
547
548 if (!g_str_has_prefix (name, "image/") &&
549 !g_str_has_prefix (name, "video/") &&
550 !g_str_equal (name, "text/uri-list")) {
551 GST_DEBUG ("Unexpected image type '%s', ignoring image frame", name);
552 goto error;
553 }
554
555 /* Decrease size by 1 if we don't have an URI list
556 * to keep the original size of the image
557 */
558 if (!g_str_equal (name, "text/uri-list"))
559 gst_buffer_set_size (image, image_data_len);
560
561 if (image_type != GST_TAG_IMAGE_TYPE_NONE) {
562 GST_LOG ("Setting image type: %d", image_type);
563 image_info = gst_structure_new ("GstTagImageInfo",
564 "image-type", GST_TYPE_TAG_IMAGE_TYPE, image_type, NULL);
565 }
566 sample = gst_sample_new (image, caps, NULL, image_info);
567 gst_buffer_unref (image);
568 gst_caps_unref (caps);
569
570 return sample;
571
572 /* ERRORS */
573 no_type:
574 {
575 GST_DEBUG ("Could not determine GStreamer media type, ignoring image");
576 /* fall through */
577 }
578 error:
579 {
580 if (image)
581 gst_buffer_unref (image);
582 if (caps)
583 gst_caps_unref (caps);
584 return NULL;
585 }
586 alloc_failed:
587 {
588 GST_WARNING ("failed to allocate buffer of %d for image", image_data_len);
589 gst_buffer_unref (image);
590 return NULL;
591 }
592
593 }
594