annotate ffmpeg/libavformat/md5enc.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * MD5 encoder (for codec/format testing)
yading@11 3 * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include "libavutil/md5.h"
yading@11 23 #include "avformat.h"
yading@11 24 #include "internal.h"
yading@11 25
yading@11 26 struct MD5Context {
yading@11 27 struct AVMD5 *md5;
yading@11 28 };
yading@11 29
yading@11 30 static void md5_finish(struct AVFormatContext *s, char *buf)
yading@11 31 {
yading@11 32 struct MD5Context *c = s->priv_data;
yading@11 33 uint8_t md5[16];
yading@11 34 int i, offset = strlen(buf);
yading@11 35 av_md5_final(c->md5, md5);
yading@11 36 for (i = 0; i < sizeof(md5); i++) {
yading@11 37 snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
yading@11 38 offset += 2;
yading@11 39 }
yading@11 40 buf[offset] = '\n';
yading@11 41 buf[offset+1] = 0;
yading@11 42
yading@11 43 avio_write(s->pb, buf, strlen(buf));
yading@11 44 avio_flush(s->pb);
yading@11 45 }
yading@11 46
yading@11 47 #if CONFIG_MD5_MUXER
yading@11 48 static int write_header(struct AVFormatContext *s)
yading@11 49 {
yading@11 50 struct MD5Context *c = s->priv_data;
yading@11 51 c->md5 = av_md5_alloc();
yading@11 52 if (!c->md5)
yading@11 53 return AVERROR(ENOMEM);
yading@11 54 av_md5_init(c->md5);
yading@11 55 return 0;
yading@11 56 }
yading@11 57
yading@11 58 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
yading@11 59 {
yading@11 60 struct MD5Context *c = s->priv_data;
yading@11 61 av_md5_update(c->md5, pkt->data, pkt->size);
yading@11 62 return 0;
yading@11 63 }
yading@11 64
yading@11 65 static int write_trailer(struct AVFormatContext *s)
yading@11 66 {
yading@11 67 struct MD5Context *c = s->priv_data;
yading@11 68 char buf[64] = "MD5=";
yading@11 69
yading@11 70 md5_finish(s, buf);
yading@11 71
yading@11 72 av_freep(&c->md5);
yading@11 73 return 0;
yading@11 74 }
yading@11 75
yading@11 76 AVOutputFormat ff_md5_muxer = {
yading@11 77 .name = "md5",
yading@11 78 .long_name = NULL_IF_CONFIG_SMALL("MD5 testing"),
yading@11 79 .priv_data_size = sizeof(struct MD5Context),
yading@11 80 .audio_codec = AV_CODEC_ID_PCM_S16LE,
yading@11 81 .video_codec = AV_CODEC_ID_RAWVIDEO,
yading@11 82 .write_header = write_header,
yading@11 83 .write_packet = write_packet,
yading@11 84 .write_trailer = write_trailer,
yading@11 85 .flags = AVFMT_NOTIMESTAMPS,
yading@11 86 };
yading@11 87 #endif
yading@11 88
yading@11 89 #if CONFIG_FRAMEMD5_MUXER
yading@11 90 static int framemd5_write_header(struct AVFormatContext *s)
yading@11 91 {
yading@11 92 struct MD5Context *c = s->priv_data;
yading@11 93 c->md5 = av_md5_alloc();
yading@11 94 if (!c->md5)
yading@11 95 return AVERROR(ENOMEM);
yading@11 96 return ff_framehash_write_header(s);
yading@11 97 }
yading@11 98
yading@11 99 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
yading@11 100 {
yading@11 101 struct MD5Context *c = s->priv_data;
yading@11 102 char buf[256];
yading@11 103 av_md5_init(c->md5);
yading@11 104 av_md5_update(c->md5, pkt->data, pkt->size);
yading@11 105
yading@11 106 snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
yading@11 107 pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
yading@11 108 md5_finish(s, buf);
yading@11 109 return 0;
yading@11 110 }
yading@11 111
yading@11 112 static int framemd5_write_trailer(struct AVFormatContext *s)
yading@11 113 {
yading@11 114 struct MD5Context *c = s->priv_data;
yading@11 115 av_freep(&c->md5);
yading@11 116 return 0;
yading@11 117 }
yading@11 118
yading@11 119 AVOutputFormat ff_framemd5_muxer = {
yading@11 120 .name = "framemd5",
yading@11 121 .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing"),
yading@11 122 .priv_data_size = sizeof(struct MD5Context),
yading@11 123 .audio_codec = AV_CODEC_ID_PCM_S16LE,
yading@11 124 .video_codec = AV_CODEC_ID_RAWVIDEO,
yading@11 125 .write_header = framemd5_write_header,
yading@11 126 .write_packet = framemd5_write_packet,
yading@11 127 .write_trailer = framemd5_write_trailer,
yading@11 128 .flags = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
yading@11 129 };
yading@11 130 #endif