# HG changeset patch # User conrad # Date 1188951848 0 # Node ID 159f87f699a5d905c5b7d57c728eb954c9926cba # Parent 33544605696519a63db9e38387e61939fef8fe97 Write FLAC codec private correctly diff -r 335446056965 -r 159f87f699a5 matroskaenc.c --- a/matroskaenc.c Wed Sep 05 00:24:06 2007 +0000 +++ b/matroskaenc.c Wed Sep 05 00:24:08 2007 +0000 @@ -364,6 +364,28 @@ return 0; } +#define FLAC_STREAMINFO_SIZE 34 + +static int put_flac_codecpriv(ByteIOContext *pb, AVCodecContext *codec) +{ + offset_t codecpriv = start_ebml_master(pb, MATROSKA_ID_CODECPRIVATE); + + // if the extradata_size is greater than FLAC_STREAMINFO_SIZE, + // assume that it's in Matroska's format already + if (codec->extradata_size < FLAC_STREAMINFO_SIZE) { + av_log(codec, AV_LOG_ERROR, "Invalid FLAC extradata\n"); + return -1; + } else if (codec->extradata_size == FLAC_STREAMINFO_SIZE) { + // only the streaminfo packet + put_byte(pb, 0); + put_xiph_size(pb, codec->extradata_size); + av_log(codec, AV_LOG_ERROR, "Only one packet\n"); + } + put_buffer(pb, codec->extradata, codec->extradata_size); + end_ebml_master(pb, codecpriv); + return 0; +} + static void get_aac_sample_rates(AVCodecContext *codec, int *sample_rate, int *output_sample_rate) { static const int aac_sample_rates[] = { @@ -440,6 +462,9 @@ if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA) { if (put_xiph_codecpriv(pb, codec) < 0) return -1; + } else if (codec->codec_id == CODEC_ID_FLAC) { + if (put_flac_codecpriv(pb, codec) < 0) + return -1; } else if (codec->extradata_size) { put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codec->extradata, codec->extradata_size); }