annotate md5enc.c @ 6297:241c4063d058 libavformat

Reindent, rewrap long comment lines to keep line length below 80 chars
author mstorsjo
date Wed, 21 Jul 2010 17:25:09 +0000
parents 5a9972bd90b6
children
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
6051
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
27 static void md5_finish(struct AVFormatContext *s, char *buf)
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
28 {
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
29 uint8_t md5[16];
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
30 int i, offset = strlen(buf);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
31 av_md5_final(s->priv_data, md5);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
32 for (i = 0; i < sizeof(md5); i++) {
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
33 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
34 offset += 2;
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
35 }
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
36 buf[offset] = '\n';
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
37 buf[offset+1] = 0;
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
38
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
39 put_buffer(s->pb, buf, strlen(buf));
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
40 put_flush_packet(s->pb);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
41 }
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
42
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
43 #if CONFIG_MD5_MUXER
6037
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
44 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
45 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
46 if (PRIVSIZE < av_md5_size) {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
47 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
48 return -1;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
49 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
50 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
51 return 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
52 }
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 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
55 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
56 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
57 return 0;
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
58 }
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
59
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
60 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
61 {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
62 char buf[64] = "MD5=";
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
63
6051
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
64 md5_finish(s, buf);
6037
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
65 return 0;
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
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
68 AVOutputFormat md5_muxer = {
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
69 "md5",
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
70 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
71 NULL,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
72 "",
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
73 PRIVSIZE,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
74 CODEC_ID_PCM_S16LE,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
75 CODEC_ID_RAWVIDEO,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
76 write_header,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
77 write_packet,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
78 write_trailer,
ea60b0454e78 Add a md5 muxer that allows checking the md5 sums of generated streams without
reimar
parents:
diff changeset
79 };
6051
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
80 #endif
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
81
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
82 #if CONFIG_FRAMEMD5_MUXER
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
83 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
84 {
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
85 char buf[256];
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
86 if (PRIVSIZE < av_md5_size) {
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
87 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
88 return -1;
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
89 }
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
90 av_md5_init(s->priv_data);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
91 av_md5_update(s->priv_data, pkt->data, pkt->size);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
92
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
93 snprintf(buf, sizeof(buf) - 64, "%d, %"PRId64", %d, ", pkt->stream_index, pkt->dts, pkt->size);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
94 md5_finish(s, buf);
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
95 return 0;
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
96 }
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
97
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
98 AVOutputFormat framemd5_muxer = {
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
99 "framemd5",
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
100 NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
101 NULL,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
102 "",
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
103 PRIVSIZE,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
104 CODEC_ID_PCM_S16LE,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
105 CODEC_ID_RAWVIDEO,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
106 NULL,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
107 framemd5_write_packet,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
108 NULL,
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
109 };
5a9972bd90b6 Add -f framemd5 muxer similar to framecrc.
reimar
parents: 6037
diff changeset
110 #endif