#include <stdlib.h>
#include "libavutil/avstring.h"
+#include "libavutil/base64.h"
#include "libavutil/bswap.h"
#include "libavutil/dict.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/get_bits.h"
#include "libavcodec/vorbis_parser.h"
#include "avformat.h"
+#include "flac_picture.h"
#include "internal.h"
#include "oggdec.h"
#include "vorbiscomment.h"
+#include "replaygain.h"
static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val)
{
}
int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
- const uint8_t *buf, int size)
+ const uint8_t *buf, int size,
+ int parse_picture)
{
const uint8_t *p = buf;
const uint8_t *end = buf + size;
if (!tt || !ct) {
av_freep(&tt);
av_freep(&ct);
- av_log(as, AV_LOG_WARNING,
- "out-of-memory error. skipping VorbisComment tag.\n");
- continue;
+ return AVERROR(ENOMEM);
}
for (j = 0; j < tl; j++)
memcpy(ct, v, vl);
ct[vl] = 0;
- if (!ogm_chapter(as, tt, ct))
+ /* The format in which the pictures are stored is the FLAC format.
+ * Xiph says: "The binary FLAC picture structure is base64 encoded
+ * and placed within a VorbisComment with the tag name
+ * 'METADATA_BLOCK_PICTURE'. This is the preferred and
+ * recommended way of embedding cover art within VorbisComments."
+ */
+ if (!strcmp(tt, "METADATA_BLOCK_PICTURE") && parse_picture) {
+ int ret;
+ char *pict = av_malloc(vl);
+
+ if (!pict) {
+ av_freep(&tt);
+ av_freep(&ct);
+ return AVERROR(ENOMEM);
+ }
+ if ((ret = av_base64_decode(pict, ct, vl)) > 0)
+ ret = ff_flac_parse_picture(as, pict, ret);
+ av_freep(&tt);
+ av_freep(&ct);
+ av_freep(&pict);
+ if (ret < 0) {
+ av_log(as, AV_LOG_WARNING, "Failed to parse cover art block.\n");
+ continue;
+ }
+ } else if (!ogm_chapter(as, tt, ct))
av_dict_set(m, tt, ct,
AV_DICT_DONT_STRDUP_KEY |
AV_DICT_DONT_STRDUP_VAL);
int final_duration;
};
-static unsigned int fixup_vorbis_headers(AVFormatContext *as,
- struct oggvorbis_private *priv,
- uint8_t **buf)
+static int fixup_vorbis_headers(AVFormatContext *as,
+ struct oggvorbis_private *priv,
+ uint8_t **buf)
{
int i, offset, len, err;
unsigned char *ptr;
len = priv->len[0] + priv->len[1] + priv->len[2];
ptr = *buf = av_mallocz(len + len / 255 + 64);
+ if (!ptr)
+ return AVERROR(ENOMEM);
ptr[0] = 2;
offset = 1;
priv->len[pkt_type >> 1] = os->psize;
priv->packet[pkt_type >> 1] = av_mallocz(os->psize);
+ if (!priv->packet[pkt_type >> 1])
+ return AVERROR(ENOMEM);
memcpy(priv->packet[pkt_type >> 1], os->buf + os->pstart, os->psize);
if (os->buf[os->pstart] == 1) {
const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */
} else if (os->buf[os->pstart] == 3) {
if (os->psize > 8 &&
ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7,
- os->psize - 8) >= 0) {
+ os->psize - 8, 1) >= 0) {
+ unsigned new_len;
+
+ int ret = ff_replaygain_export(st, st->metadata);
+ if (ret < 0)
+ return ret;
+
// drop all metadata we parsed and which is not required by libvorbis
- unsigned new_len = 7 + 4 + AV_RL32(priv->packet[1] + 7) + 4 + 1;
+ new_len = 7 + 4 + AV_RL32(priv->packet[1] + 7) + 4 + 1;
if (new_len >= 16 && new_len < os->psize) {
AV_WL32(priv->packet[1] + new_len - 5, 0);
priv->packet[1][new_len - 1] = 1;