FFmpeg/libavformat/md5enc.c
Michael Niedermayer 3b46daa31f Merge remote-tracking branch 'qatar/master'
* qatar/master:
  dsputil: remove debug message in dsputil_init().
  movdec: Avoid av_malloc(0) in stss
  build: Drop YASM-OBJS-FFT from SUBDIR_VARS.
  build: Drop unused X86-OBJS variable.
  avconv: remove debugging cruft from do_video_out().
  avconv: factorize setting stream_index for the output packet.
  frame{crc/md5}: set the stream timebase from codec timebase.
  apedec: remove unneeded #include of get_bits.h and associated macro
  apedec: av_fast_malloc() instead of av_realloc()
  apedec: fix handling of packet sizes that are not a multiple of 4 bytes

Conflicts:
	libavcodec/apedec.c
	tests/ref/fate/4xm-1
	tests/ref/fate/4xm-2
	tests/ref/fate/aasc
	tests/ref/fate/armovie-escape124
	tests/ref/fate/bethsoft-vid
	tests/ref/fate/cljr
	tests/ref/fate/creatureshock-avs
	tests/ref/fate/cscd
	tests/ref/fate/cvid-partial
	tests/ref/fate/deluxepaint-anm
	tests/ref/fate/dfa1
	tests/ref/fate/dfa10
	tests/ref/fate/dfa11
	tests/ref/fate/dfa2
	tests/ref/fate/dfa3
	tests/ref/fate/dfa4
	tests/ref/fate/dfa5
	tests/ref/fate/dfa6
	tests/ref/fate/dfa7
	tests/ref/fate/dfa8
	tests/ref/fate/dfa9
	tests/ref/fate/film-cvid-pcm-stereo-8bit
	tests/ref/fate/flic-af11-palette-change
	tests/ref/fate/flic-magiccarpet
	tests/ref/fate/fraps-v2
	tests/ref/fate/fraps-v3
	tests/ref/fate/h264-lossless
	tests/ref/fate/interplay-mve-16bit
	tests/ref/fate/interplay-mve-8bit
	tests/ref/fate/mimic
	tests/ref/fate/motionpixels
	tests/ref/fate/mpeg2-field-enc
	tests/ref/fate/msvideo1-16bit
	tests/ref/fate/mtv
	tests/ref/fate/nuv
	tests/ref/fate/pictor
	tests/ref/fate/prores-alpha
	tests/ref/fate/ptx
	tests/ref/fate/qtrle-16bit
	tests/ref/fate/qtrle-1bit
	tests/ref/fate/quickdraw
	tests/ref/fate/rpza
	tests/ref/fate/sierra-vmd
	tests/ref/fate/targa-conformance-CCM8
	tests/ref/fate/targa-conformance-UCM8
	tests/ref/fate/tiertex-seq
	tests/ref/fate/truemotion1-15
	tests/ref/fate/truemotion1-24
	tests/ref/fate/tscc-15bit
	tests/ref/fate/tscc-32bit
	tests/ref/fate/v210
	tests/ref/fate/vc1-ism
	tests/ref/fate/vc1_sa00040
	tests/ref/fate/vc1_sa00050
	tests/ref/fate/vc1_sa10091
	tests/ref/fate/vc1_sa20021
	tests/ref/fate/vmnc-16bit
	tests/ref/fate/vmnc-32bit
	tests/ref/fate/vp5
	tests/ref/fate/vp8-sign-bias
	tests/ref/fate/vqa-cc
	tests/ref/fate/wmv8-drm
	tests/ref/fate/yop
	tests/ref/fate/zmbv-8bit

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-02-04 02:34:14 +01:00

110 lines
3.2 KiB
C

/*
* MD5 encoder (for codec/format testing)
* Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/md5.h"
#include "avformat.h"
#include "internal.h"
#define PRIVSIZE 512
static void md5_finish(struct AVFormatContext *s, char *buf)
{
uint8_t md5[16];
int i, offset = strlen(buf);
av_md5_final(s->priv_data, md5);
for (i = 0; i < sizeof(md5); i++) {
snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
offset += 2;
}
buf[offset] = '\n';
buf[offset+1] = 0;
avio_write(s->pb, buf, strlen(buf));
avio_flush(s->pb);
}
#if CONFIG_MD5_MUXER
static int write_header(struct AVFormatContext *s)
{
if (PRIVSIZE < av_md5_size) {
av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
return -1;
}
av_md5_init(s->priv_data);
return 0;
}
static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
av_md5_update(s->priv_data, pkt->data, pkt->size);
return 0;
}
static int write_trailer(struct AVFormatContext *s)
{
char buf[64] = "MD5=";
md5_finish(s, buf);
return 0;
}
AVOutputFormat ff_md5_muxer = {
.name = "md5",
.long_name = NULL_IF_CONFIG_SMALL("MD5 testing format"),
.priv_data_size = PRIVSIZE,
.audio_codec = CODEC_ID_PCM_S16LE,
.video_codec = CODEC_ID_RAWVIDEO,
.write_header = write_header,
.write_packet = write_packet,
.write_trailer = write_trailer,
.flags = AVFMT_NOTIMESTAMPS,
};
#endif
#if CONFIG_FRAMEMD5_MUXER
static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
char buf[256];
if (PRIVSIZE < av_md5_size) {
av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
return -1;
}
av_md5_init(s->priv_data);
av_md5_update(s->priv_data, pkt->data, pkt->size);
snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
md5_finish(s, buf);
return 0;
}
AVOutputFormat ff_framemd5_muxer = {
.name = "framemd5",
.long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
.priv_data_size = PRIVSIZE,
.audio_codec = CODEC_ID_PCM_S16LE,
.video_codec = CODEC_ID_RAWVIDEO,
.write_header = ff_framehash_write_header,
.write_packet = framemd5_write_packet,
.flags = AVFMT_VARIABLE_FPS,
};
#endif