00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/md5.h"
00023 #include "avformat.h"
00024 #include "internal.h"
00025
00026 #define PRIVSIZE 512
00027
00028 static void md5_finish(struct AVFormatContext *s, char *buf)
00029 {
00030 uint8_t md5[16];
00031 int i, offset = strlen(buf);
00032 av_md5_final(s->priv_data, md5);
00033 for (i = 0; i < sizeof(md5); i++) {
00034 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
00035 offset += 2;
00036 }
00037 buf[offset] = '\n';
00038 buf[offset+1] = 0;
00039
00040 avio_write(s->pb, buf, strlen(buf));
00041 avio_flush(s->pb);
00042 }
00043
00044 #if CONFIG_MD5_MUXER
00045 static int write_header(struct AVFormatContext *s)
00046 {
00047 if (PRIVSIZE < av_md5_size) {
00048 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
00049 return -1;
00050 }
00051 av_md5_init(s->priv_data);
00052 return 0;
00053 }
00054
00055 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
00056 {
00057 av_md5_update(s->priv_data, pkt->data, pkt->size);
00058 return 0;
00059 }
00060
00061 static int write_trailer(struct AVFormatContext *s)
00062 {
00063 char buf[64] = "MD5=";
00064
00065 md5_finish(s, buf);
00066 return 0;
00067 }
00068
00069 AVOutputFormat ff_md5_muxer = {
00070 .name = "md5",
00071 .long_name = NULL_IF_CONFIG_SMALL("MD5 testing format"),
00072 .priv_data_size = PRIVSIZE,
00073 .audio_codec = CODEC_ID_PCM_S16LE,
00074 .video_codec = CODEC_ID_RAWVIDEO,
00075 .write_header = write_header,
00076 .write_packet = write_packet,
00077 .write_trailer = write_trailer,
00078 .flags = AVFMT_NOTIMESTAMPS,
00079 };
00080 #endif
00081
00082 #if CONFIG_FRAMEMD5_MUXER
00083 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
00084 {
00085 char buf[256];
00086 if (PRIVSIZE < av_md5_size) {
00087 av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
00088 return -1;
00089 }
00090 av_md5_init(s->priv_data);
00091 av_md5_update(s->priv_data, pkt->data, pkt->size);
00092
00093 snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
00094 pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
00095 md5_finish(s, buf);
00096 return 0;
00097 }
00098
00099 AVOutputFormat ff_framemd5_muxer = {
00100 .name = "framemd5",
00101 .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
00102 .priv_data_size = PRIVSIZE,
00103 .audio_codec = CODEC_ID_PCM_S16LE,
00104 .video_codec = CODEC_ID_RAWVIDEO,
00105 .write_header = ff_framehash_write_header,
00106 .write_packet = framemd5_write_packet,
00107 .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
00108 };
00109 #endif