On 8/4/2016 3:38 PM, Michael Niedermayer wrote: > On Sun, Jul 31, 2016 at 01:03:45PM -0300, James Almer wrote: >> Signed-off-by: James Almer <jamr...@gmail.com> > [...] >> +#include "apetag.h" >> +#include "avformat.h" >> +#include "avio_internal.h" >> +#include "internal.h" >> + >> +typedef struct TTAMuxContext { >> + AVIOContext *seek_table; >> + AVIOContext *data; >> + uint32_t nb_samples; >> + int frame_size; >> + int last_frame; >> +} TTAMuxContext; >> + >> +static int tta_write_header(AVFormatContext *s) >> +{ >> + TTAMuxContext *tta = s->priv_data; >> + AVCodecParameters *par = s->streams[0]->codecpar; >> + int ret; >> + >> + if (s->nb_streams > 1) { > > should be == 1, the code would not work with 0 streams
Fixed. > > >> + av_log(s, AV_LOG_ERROR, "Only one stream is supported\n"); >> + return AVERROR(EINVAL); >> + } >> + if (par->codec_id != AV_CODEC_ID_TTA) { >> + av_log(s, AV_LOG_ERROR, "Unsupported codec\n"); >> + return AVERROR(EINVAL); >> + } >> + if (par->extradata && par->extradata_size < 22) { >> + av_log(s, AV_LOG_ERROR, "Invalid TTA extradata\n"); >> + return AVERROR_INVALIDDATA; >> + } >> + >> + if ((ret = avio_open_dyn_buf(&tta->seek_table)) < 0) >> + return ret; >> + if ((ret = avio_open_dyn_buf(&tta->data)) < 0) { >> + ffio_free_dyn_buf(&tta->seek_table); >> + return ret; >> + } >> + >> + /* Ignore most extradata information if present. It can be innacurate >> + if for example remuxing from Matroska */ >> + ffio_init_checksum(s->pb, ff_crcEDB88320_update, UINT32_MAX); >> + ffio_init_checksum(tta->seek_table, ff_crcEDB88320_update, UINT32_MAX); >> + avio_write(s->pb, "TTA1", 4); >> + avio_wl16(s->pb, par->extradata ? AV_RL16(par->extradata + 4) : 1); >> + avio_wl16(s->pb, par->channels); >> + avio_wl16(s->pb, par->bits_per_raw_sample); >> + avio_wl32(s->pb, par->sample_rate); > >> + tta->frame_size = par->sample_rate * 256 / 245; > > should use 64bit to avoid overflow Added a check to make sure sample_rate is a sane value. > > > [...] >> diff --git a/tests/ref/acodec/tta b/tests/ref/acodec/tta >> index 0f60345..8e183f9 100644 >> --- a/tests/ref/acodec/tta >> +++ b/tests/ref/acodec/tta >> @@ -1,4 +1,4 @@ >> -6c260836d7a32e4bd714453a3546c0d5 *tests/data/fate/acodec-tta.matroska >> -331148 tests/data/fate/acodec-tta.matroska >> +847d065f082ac94825728b5f1af853eb *tests/data/fate/acodec-tta.tta >> +330583 tests/data/fate/acodec-tta.tta >> 95e54b261530a1bcf6de6fe3b21dc5f6 *tests/data/fate/acodec-tta.out.wav >> stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 >> diff --git a/tests/ref/lavf/mka b/tests/ref/lavf/mka >> new file mode 100644 >> index 0000000..962b254 >> --- /dev/null >> +++ b/tests/ref/lavf/mka >> @@ -0,0 +1,3 @@ >> +b2e3746787b885d0191a1a26f3faa58f *./tests/data/lavf/lavf.mka >> +43654 ./tests/data/lavf/lavf.mka >> +./tests/data/lavf/lavf.mka CRC=0x3a1da17e >> diff --git a/tests/ref/lavf/tta b/tests/ref/lavf/tta >> new file mode 100644 >> index 0000000..745e8d2 >> --- /dev/null >> +++ b/tests/ref/lavf/tta >> @@ -0,0 +1,3 @@ >> +f2721d06704ac43d89fdd25835b43598 *./tests/data/lavf/lavf.tta >> +43200 ./tests/data/lavf/lavf.tta >> +./tests/data/lavf/lavf.tta CRC=0x3a1da17e > > fate tests > Tested-by: Michael on x86 32 / 64, mingw 32/64, mips , arm > Reviewed-by: Michael Pushed, thanks. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel