Mercurial > libavformat.hg
annotate md5enc.c @ 6296:7e7f9248ec87 libavformat
rtpdec_asf: Handle RTSP-MS packet splitting
author | mstorsjo |
---|---|
date | Wed, 21 Jul 2010 17:17:35 +0000 |
parents | 5a9972bd90b6 |
children |
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 | 27 static void md5_finish(struct AVFormatContext *s, char *buf) |
28 { | |
29 uint8_t md5[16]; | |
30 int i, offset = strlen(buf); | |
31 av_md5_final(s->priv_data, md5); | |
32 for (i = 0; i < sizeof(md5); i++) { | |
33 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]); | |
34 offset += 2; | |
35 } | |
36 buf[offset] = '\n'; | |
37 buf[offset+1] = 0; | |
38 | |
39 put_buffer(s->pb, buf, strlen(buf)); | |
40 put_flush_packet(s->pb); | |
41 } | |
42 | |
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 | 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 | 80 #endif |
81 | |
82 #if CONFIG_FRAMEMD5_MUXER | |
83 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt) | |
84 { | |
85 char buf[256]; | |
86 if (PRIVSIZE < av_md5_size) { | |
87 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n"); | |
88 return -1; | |
89 } | |
90 av_md5_init(s->priv_data); | |
91 av_md5_update(s->priv_data, pkt->data, pkt->size); | |
92 | |
93 snprintf(buf, sizeof(buf) - 64, "%d, %"PRId64", %d, ", pkt->stream_index, pkt->dts, pkt->size); | |
94 md5_finish(s, buf); | |
95 return 0; | |
96 } | |
97 | |
98 AVOutputFormat framemd5_muxer = { | |
99 "framemd5", | |
100 NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"), | |
101 NULL, | |
102 "", | |
103 PRIVSIZE, | |
104 CODEC_ID_PCM_S16LE, | |
105 CODEC_ID_RAWVIDEO, | |
106 NULL, | |
107 framemd5_write_packet, | |
108 NULL, | |
109 }; | |
110 #endif |