diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2008-09-14 21:39:54 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2008-09-14 21:39:54 +0000 |
commit | a9f8587e152c16e943c645ff295e015384ccd76d (patch) | |
tree | 667dec0269e0002cf00b1e5fe27ca002e6f0a23e | |
parent | 2b905517646851a5a44e39736565ee374629c0f5 (diff) | |
download | ffmpeg-a9f8587e152c16e943c645ff295e015384ccd76d.tar.gz |
write MD5 checksum to FLAC header. update regression tests.
Originally committed as revision 15326 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/flacenc.c | 30 | ||||
-rw-r--r-- | tests/ffmpeg.regression.ref | 2 | ||||
-rw-r--r-- | tests/rotozoom.regression.ref | 2 |
3 files changed, 31 insertions, 3 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index d1002f3814..bdd4932c2b 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -21,6 +21,7 @@ #include "libavutil/crc.h" #include "libavutil/lls.h" +#include "libavutil/md5.h" #include "avcodec.h" #include "bitstream.h" #include "dsputil.h" @@ -97,10 +98,12 @@ typedef struct FlacEncodeContext { int max_framesize; uint32_t frame_count; uint64_t sample_count; + uint8_t md5sum[16]; FlacFrame frame; CompressionOptions options; AVCodecContext *avctx; DSPContext dsp; + struct AVMD5 *md5ctx; } FlacEncodeContext; static const int flac_samplerates[16] = { @@ -139,7 +142,7 @@ static void write_streaminfo(FlacEncodeContext *s, uint8_t *header) put_bits(&pb, 24, (s->sample_count & 0xFFFFFF000LL) >> 12); put_bits(&pb, 12, s->sample_count & 0x000000FFFLL); flush_put_bits(&pb); - /* MD5 signature = 0 */ + memcpy(&header[18], s->md5sum, 16); } /** @@ -372,6 +375,12 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) s->max_framesize = 14 + (s->avctx->frame_size * s->channels * 2); } + /* initialize MD5 context */ + s->md5ctx = av_malloc(av_md5_size); + if(!s->md5ctx) + return AVERROR_NOMEM; + av_md5_init(s->md5ctx); + streaminfo = av_malloc(FLAC_STREAMINFO_SIZE); write_streaminfo(s, streaminfo); avctx->extradata = streaminfo; @@ -1238,6 +1247,19 @@ static void output_frame_footer(FlacEncodeContext *s) flush_put_bits(&s->pb); } +static void update_md5_sum(FlacEncodeContext *s, int16_t *samples) +{ +#ifdef WORDS_BIGENDIAN + int i; + for(i = 0; i < s->frame.blocksize*s->channels; i++) { + int16_t smp = le2me_16(samples[i]); + av_md5_update(s->md5ctx, (uint8_t *)&smp, 2); + } +#else + av_md5_update(s->md5ctx, (uint8_t *)samples, s->frame.blocksize*s->channels*2); +#endif +} + static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data) { @@ -1256,6 +1278,7 @@ static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame, /* when the last block is reached, update the header in extradata */ if (!data) { + av_md5_final(s->md5ctx, s->md5sum); write_streaminfo(s, avctx->extradata); return 0; } @@ -1294,12 +1317,17 @@ write_frame: s->frame_count++; s->sample_count += avctx->frame_size; + update_md5_sum(s, samples); return out_bytes; } static av_cold int flac_encode_close(AVCodecContext *avctx) { + if (avctx->priv_data) { + FlacEncodeContext *s = avctx->priv_data; + av_freep(&s->md5ctx); + } av_freep(&avctx->extradata); avctx->extradata_size = 0; av_freep(&avctx->coded_frame); diff --git a/tests/ffmpeg.regression.ref b/tests/ffmpeg.regression.ref index fd050a6887..d1ce98c4ac 100644 --- a/tests/ffmpeg.regression.ref +++ b/tests/ffmpeg.regression.ref @@ -201,7 +201,7 @@ de1122d20d56c44cf49f028e25a67788 *./tests/data/a-adpcm_swf.flv 267073 ./tests/data/a-adpcm_swf.flv e48b800e2d9be6afcd430d4f08a34eb6 *./tests/data/adpcm_swf.vsynth.out.wav stddev: 934.28 PSNR: 36.91 bytes: 1056812/ 1058444 -77c20cb7d6846d6390e0615b7cea7401 *./tests/data/a-flac.flac +10a8bf5796004b150c7aed115cbafef5 *./tests/data/a-flac.flac 353368 ./tests/data/a-flac.flac 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/flac.vsynth.out.wav stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref index 470f85d127..dcc4b938d4 100644 --- a/tests/rotozoom.regression.ref +++ b/tests/rotozoom.regression.ref @@ -201,7 +201,7 @@ de1122d20d56c44cf49f028e25a67788 *./tests/data/a-adpcm_swf.flv 267073 ./tests/data/a-adpcm_swf.flv e48b800e2d9be6afcd430d4f08a34eb6 *./tests/data/adpcm_swf.rotozoom.out.wav stddev: 934.28 PSNR: 36.91 bytes: 1056812/ 1058444 -77c20cb7d6846d6390e0615b7cea7401 *./tests/data/a-flac.flac +10a8bf5796004b150c7aed115cbafef5 *./tests/data/a-flac.flac 353368 ./tests/data/a-flac.flac 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/flac.rotozoom.out.wav stddev: 0.00 PSNR:999.99 bytes: 1058444/ 1058444 |