2 * MD5 encoder (for codec/format testing)
3 * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/md5.h"
30 static void md5_finish(struct AVFormatContext *s, char *buf)
32 struct MD5Context *c = s->priv_data;
34 int i, offset = strlen(buf);
35 av_md5_final(c->md5, md5);
36 for (i = 0; i < sizeof(md5); i++) {
37 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
43 avio_write(s->pb, buf, strlen(buf));
48 static int write_header(struct AVFormatContext *s)
50 struct MD5Context *c = s->priv_data;
51 c->md5 = av_md5_alloc();
53 return AVERROR(ENOMEM);
58 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
60 struct MD5Context *c = s->priv_data;
61 av_md5_update(c->md5, pkt->data, pkt->size);
65 static int write_trailer(struct AVFormatContext *s)
67 struct MD5Context *c = s->priv_data;
68 char buf[64] = "MD5=";
76 AVOutputFormat ff_md5_muxer = {
78 .long_name = NULL_IF_CONFIG_SMALL("MD5 testing"),
79 .priv_data_size = sizeof(struct MD5Context),
80 .audio_codec = AV_CODEC_ID_PCM_S16LE,
81 .video_codec = AV_CODEC_ID_RAWVIDEO,
82 .write_header = write_header,
83 .write_packet = write_packet,
84 .write_trailer = write_trailer,
85 .flags = AVFMT_NOTIMESTAMPS,
89 #if CONFIG_FRAMEMD5_MUXER
90 static int framemd5_write_header(struct AVFormatContext *s)
92 struct MD5Context *c = s->priv_data;
93 c->md5 = av_md5_alloc();
95 return AVERROR(ENOMEM);
96 return ff_framehash_write_header(s);
99 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
101 struct MD5Context *c = s->priv_data;
104 av_md5_update(c->md5, pkt->data, pkt->size);
106 snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
107 pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
112 static int framemd5_write_trailer(struct AVFormatContext *s)
114 struct MD5Context *c = s->priv_data;
119 AVOutputFormat ff_framemd5_muxer = {
121 .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing"),
122 .priv_data_size = sizeof(struct MD5Context),
123 .audio_codec = AV_CODEC_ID_PCM_S16LE,
124 .video_codec = AV_CODEC_ID_RAWVIDEO,
125 .write_header = framemd5_write_header,
126 .write_packet = framemd5_write_packet,
127 .write_trailer = framemd5_write_trailer,
128 .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,