annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6037
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
1 /*
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
2 * MD5 encoder (for codec/format testing)
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
3 * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
4 *
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
5 * This file is part of FFmpeg.
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
6 *
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
11 *
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
15 * Lesser General Public License for more details.
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
16 *
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
20 */
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
21
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
22 #include "libavutil/md5.h"
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
23 #include "avformat.h"
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
24
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
25 #define PRIVSIZE 512
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
26
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
27 static int write_header(struct AVFormatContext *s)
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
28 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
29 if (PRIVSIZE < av_md5_size) {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
30 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
31 return -1;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
32 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
33 av_md5_init(s->priv_data);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
34 return 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
35 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
36
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
37 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
38 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
39 av_md5_update(s->priv_data, pkt->data, pkt->size);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
40 return 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
41 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
42
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
43 static int write_trailer(struct AVFormatContext *s)
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
44 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
45 uint8_t md5[16];
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
46 char buf[64] = "MD5=";
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
47 int i, offset = strlen(buf);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
48
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
49 av_md5_final(s->priv_data, md5);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
50 for (i = 0; i < sizeof(md5); i++) {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
51 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
52 offset += 2;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
53 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
54 buf[offset] = '\n';
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
55 buf[offset+1] = 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
56
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
57 put_buffer(s->pb, buf, strlen(buf));
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
58 put_flush_packet(s->pb);
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
59 return 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
60 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
61
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
62 AVOutputFormat md5_muxer = {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
63 "md5",
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
64 NULL_IF_CONFIG_SMALL("MD5 testing format"),
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
65 NULL,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
66 "",
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
67 PRIVSIZE,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
68 CODEC_ID_PCM_S16LE,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
69 CODEC_ID_RAWVIDEO,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
70 write_header,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
71 write_packet,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
72 write_trailer,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
73 };