Lines 305-334
gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
Link Here
|
305 |
} |
305 |
} |
306 |
|
306 |
|
307 |
static void |
307 |
static void |
308 |
gst_vorbis_tag_add_coverart (GstTagList * tags, const gchar * img_data_base64, |
308 |
gst_vorbis_tag_add_coverart (GstTagList * tags, gchar * img_data_base64, |
309 |
gint base64_len) |
309 |
gint base64_len) |
310 |
{ |
310 |
{ |
311 |
GstBuffer *img; |
311 |
GstBuffer *img; |
312 |
guchar *img_data; |
|
|
313 |
gsize img_len; |
312 |
gsize img_len; |
|
|
313 |
guchar *out; |
314 |
guint save = 0; |
314 |
guint save = 0; |
315 |
gint state = 0; |
315 |
gint state = 0; |
316 |
|
316 |
|
317 |
if (base64_len < 2) |
317 |
if (base64_len < 2) |
318 |
goto not_enough_data; |
318 |
goto not_enough_data; |
319 |
|
319 |
|
320 |
img_data = g_try_malloc0 (base64_len * 3 / 4); |
320 |
/* img_data_base64 points to a temporary copy of the base64 encoded data, so |
321 |
|
321 |
* it's safe to do inpace decoding here |
322 |
if (img_data == NULL) |
322 |
* TODO: glib 2.20 and later provides g_base64_decode_inplace, so change this |
323 |
goto alloc_failed; |
323 |
* to use glib's API instead once it's in wider use: |
324 |
|
324 |
* http://bugzilla.gnome.org/show_bug.cgi?id=564728 |
325 |
img_len = g_base64_decode_step (img_data_base64, base64_len, img_data, |
325 |
* http://svn.gnome.org/viewvc/glib?view=revision&revision=7807 */ |
326 |
&state, &save); |
326 |
out = (guchar *) img_data_base64; |
|
|
327 |
img_len = g_base64_decode_step (img_data_base64, base64_len, |
328 |
out, &state, &save); |
327 |
|
329 |
|
328 |
if (img_len == 0) |
330 |
if (img_len == 0) |
329 |
goto decode_failed; |
331 |
goto decode_failed; |
330 |
|
332 |
|
331 |
img = gst_tag_image_data_to_image_buffer (img_data, img_len, |
333 |
img = gst_tag_image_data_to_image_buffer (out, img_len, |
332 |
GST_TAG_IMAGE_TYPE_NONE); |
334 |
GST_TAG_IMAGE_TYPE_NONE); |
333 |
|
335 |
|
334 |
if (img == NULL) |
336 |
if (img == NULL) |
Lines 338-344
gst_vorbis_tag_add_coverart (GstTagList * tags, const gchar * img_data_base64,
Link Here
|
338 |
GST_TAG_PREVIEW_IMAGE, img, NULL); |
340 |
GST_TAG_PREVIEW_IMAGE, img, NULL); |
339 |
|
341 |
|
340 |
gst_buffer_unref (img); |
342 |
gst_buffer_unref (img); |
341 |
g_free (img_data); |
|
|
342 |
return; |
343 |
return; |
343 |
|
344 |
|
344 |
/* ERRORS */ |
345 |
/* ERRORS */ |
Lines 347-367
not_enough_data:
Link Here
|
347 |
GST_WARNING ("COVERART tag with too little base64-encoded data"); |
348 |
GST_WARNING ("COVERART tag with too little base64-encoded data"); |
348 |
return; |
349 |
return; |
349 |
} |
350 |
} |
350 |
alloc_failed: |
|
|
351 |
{ |
352 |
GST_WARNING ("Couldn't allocate enough memory to decode COVERART tag"); |
353 |
return; |
354 |
} |
355 |
decode_failed: |
351 |
decode_failed: |
356 |
{ |
352 |
{ |
357 |
GST_WARNING ("Couldn't decode bas64 image data from COVERART tag"); |
353 |
GST_WARNING ("Couldn't decode base64 image data from COVERART tag"); |
358 |
g_free (img_data); |
|
|
359 |
return; |
354 |
return; |
360 |
} |
355 |
} |
361 |
convert_failed: |
356 |
convert_failed: |
362 |
{ |
357 |
{ |
363 |
GST_WARNING ("Couldn't extract image or image type from COVERART tag"); |
358 |
GST_WARNING ("Couldn't extract image or image type from COVERART tag"); |
364 |
g_free (img_data); |
|
|
365 |
return; |
359 |
return; |
366 |
} |
360 |
} |
367 |
} |
361 |
} |
Lines 457-462
error:
Link Here
|
457 |
return NULL; |
451 |
return NULL; |
458 |
#undef ADVANCE |
452 |
#undef ADVANCE |
459 |
} |
453 |
} |
|
|
454 |
|
460 |
typedef struct |
455 |
typedef struct |
461 |
{ |
456 |
{ |
462 |
guint count; |
457 |
guint count; |