Mercurial > libavformat.hg
comparison md5enc.c @ 6051:5a9972bd90b6 libavformat
Add -f framemd5 muxer similar to framecrc.
author | reimar |
---|---|
date | Mon, 24 May 2010 17:49:26 +0000 |
parents | ea60b0454e78 |
children |
comparison
equal
deleted
inserted
replaced
6050:8a4763913ae0 | 6051:5a9972bd90b6 |
---|---|
22 #include "libavutil/md5.h" | 22 #include "libavutil/md5.h" |
23 #include "avformat.h" | 23 #include "avformat.h" |
24 | 24 |
25 #define PRIVSIZE 512 | 25 #define PRIVSIZE 512 |
26 | 26 |
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 | |
27 static int write_header(struct AVFormatContext *s) | 44 static int write_header(struct AVFormatContext *s) |
28 { | 45 { |
29 if (PRIVSIZE < av_md5_size) { | 46 if (PRIVSIZE < av_md5_size) { |
30 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n"); | 47 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n"); |
31 return -1; | 48 return -1; |
40 return 0; | 57 return 0; |
41 } | 58 } |
42 | 59 |
43 static int write_trailer(struct AVFormatContext *s) | 60 static int write_trailer(struct AVFormatContext *s) |
44 { | 61 { |
45 uint8_t md5[16]; | |
46 char buf[64] = "MD5="; | 62 char buf[64] = "MD5="; |
47 int i, offset = strlen(buf); | |
48 | 63 |
49 av_md5_final(s->priv_data, md5); | 64 md5_finish(s, buf); |
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; | 65 return 0; |
60 } | 66 } |
61 | 67 |
62 AVOutputFormat md5_muxer = { | 68 AVOutputFormat md5_muxer = { |
63 "md5", | 69 "md5", |
69 CODEC_ID_RAWVIDEO, | 75 CODEC_ID_RAWVIDEO, |
70 write_header, | 76 write_header, |
71 write_packet, | 77 write_packet, |
72 write_trailer, | 78 write_trailer, |
73 }; | 79 }; |
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 |