1
0
Fork 0

flac: export vorbiscomment metadata in extradata

It can contain special metadata that informs us about the desired channel
layout for non-standard layouts, which means its crucial for correct
playback.
This commit is contained in:
Hendrik Leppkes 2013-04-30 15:53:35 +02:00
parent ae6a354433
commit 64047e9b53
Signed by: hendrik
GPG Key ID: 846079A4B0A7C1B5
1 changed files with 22 additions and 6 deletions

View File

@ -56,7 +56,7 @@ static int flac_read_header(AVFormatContext *s)
{
int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
uint8_t header[4];
uint8_t *buffer=NULL;
uint8_t *buffer=NULL, *tmp=NULL;
uint32_t marker;
FLACDecContext *flac = s->priv_data;
AVStream *st = avformat_new_stream(s, NULL);
@ -117,14 +117,20 @@ static int flac_read_header(AVFormatContext *s)
RETURN_ERROR(AVERROR_INVALIDDATA);
}
found_streaminfo = 1;
st->codecpar->extradata = buffer;
st->codecpar->extradata_size = metadata_size;
buffer = NULL;
st->codecpar->extradata = av_malloc(metadata_size + 8 + AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codecpar->extradata) {
RETURN_ERROR(AVERROR(ENOMEM));
}
st->codecpar->extradata_size = metadata_size + 8;
AV_WL32(st->codecpar->extradata, MKTAG('f','L','a','C'));
memcpy(st->codecpar->extradata + 4, header, 4);
memcpy(st->codecpar->extradata + 8, buffer, metadata_size);
av_freep(&buffer);
/* get sample rate and sample count from STREAMINFO header;
* other parameters will be extracted by the parser */
samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4;
samples = (AV_RB64(st->codecpar->extradata + 13) >> 24) & ((1ULL << 36) - 1);
samplerate = AV_RB24(st->codecpar->extradata + 8 + 10) >> 4;
samples = (AV_RB64(st->codecpar->extradata + 8 + 13) >> 24) & ((1ULL << 36) - 1);
/* set time base and duration */
if (samplerate > 0) {
@ -188,6 +194,16 @@ static int flac_read_header(AVFormatContext *s)
/* process supported blocks other than STREAMINFO */
if (metadata_type == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
AVDictionaryEntry *chmask;
/* append VorbisComment to extradata */
tmp = av_realloc(st->codecpar->extradata, st->codecpar->extradata_size + 4 + metadata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!tmp) {
RETURN_ERROR(AVERROR(ENOMEM));
}
st->codecpar->extradata = tmp;
tmp += st->codecpar->extradata_size;
memcpy(tmp, header, 4);
memcpy(tmp + 4, buffer, metadata_size);
st->codecpar->extradata_size = st->codecpar->extradata_size + 4 + metadata_size;
ret = ff_vorbis_comment(s, &s->metadata, buffer, metadata_size, 1);
if (ret < 0) {