comparison md5enc.c @ 6037:ea60b0454e78 libavformat

Add a md5 muxer that allows checking the md5 sums of generated streams without needing an external MD5 command.
author reimar
date Sun, 23 May 2010 13:07:33 +0000
parents
children 5a9972bd90b6
comparison
equal deleted inserted replaced
6036:201152a121b5 6037:ea60b0454e78
1 /*
2 * MD5 encoder (for codec/format testing)
3 * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "libavutil/md5.h"
23 #include "avformat.h"
24
25 #define PRIVSIZE 512
26
27 static int write_header(struct AVFormatContext *s)
28 {
29 if (PRIVSIZE < av_md5_size) {
30 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
31 return -1;
32 }
33 av_md5_init(s->priv_data);
34 return 0;
35 }
36
37 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
38 {
39 av_md5_update(s->priv_data, pkt->data, pkt->size);
40 return 0;
41 }
42
43 static int write_trailer(struct AVFormatContext *s)
44 {
45 uint8_t md5[16];
46 char buf[64] = "MD5=";
47 int i, offset = strlen(buf);
48
49 av_md5_final(s->priv_data, md5);
50 for (i = 0; i < sizeof(md5); i++) {
51 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
52 offset += 2;
53 }
54 buf[offset] = '\n';
55 buf[offset+1] = 0;
56
57 put_buffer(s->pb, buf, strlen(buf));
58 put_flush_packet(s->pb);
59 return 0;
60 }
61
62 AVOutputFormat md5_muxer = {
63 "md5",
64 NULL_IF_CONFIG_SMALL("MD5 testing format"),
65 NULL,
66 "",
67 PRIVSIZE,
68 CODEC_ID_PCM_S16LE,
69 CODEC_ID_RAWVIDEO,
70 write_header,
71 write_packet,
72 write_trailer,
73 };