• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/md5enc.c

Go to the documentation of this file.
00001 /*
00002  * MD5 encoder (for codec/format testing)
00003  * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavutil/md5.h"
00023 #include "avformat.h"
00024 
00025 #define PRIVSIZE 512
00026 
00027 static void md5_finish(struct AVFormatContext *s, char *buf)
00028 {
00029     uint8_t md5[16];
00030     int i, offset = strlen(buf);
00031     av_md5_final(s->priv_data, md5);
00032     for (i = 0; i < sizeof(md5); i++) {
00033         snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
00034         offset += 2;
00035     }
00036     buf[offset] = '\n';
00037     buf[offset+1] = 0;
00038 
00039     avio_write(s->pb, buf, strlen(buf));
00040     avio_flush(s->pb);
00041 }
00042 
00043 #if CONFIG_MD5_MUXER
00044 static int write_header(struct AVFormatContext *s)
00045 {
00046     if (PRIVSIZE < av_md5_size) {
00047         av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
00048         return -1;
00049     }
00050     av_md5_init(s->priv_data);
00051     return 0;
00052 }
00053 
00054 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
00055 {
00056     av_md5_update(s->priv_data, pkt->data, pkt->size);
00057     return 0;
00058 }
00059 
00060 static int write_trailer(struct AVFormatContext *s)
00061 {
00062     char buf[64] = "MD5=";
00063 
00064     md5_finish(s, buf);
00065     return 0;
00066 }
00067 
00068 AVOutputFormat ff_md5_muxer = {
00069     .name              = "md5",
00070     .long_name         = NULL_IF_CONFIG_SMALL("MD5 testing format"),
00071     .priv_data_size    = PRIVSIZE,
00072     .audio_codec       = CODEC_ID_PCM_S16LE,
00073     .video_codec       = CODEC_ID_RAWVIDEO,
00074     .write_header      = write_header,
00075     .write_packet      = write_packet,
00076     .write_trailer     = write_trailer,
00077     .flags             = AVFMT_NOTIMESTAMPS,
00078 };
00079 #endif
00080 
00081 #if CONFIG_FRAMEMD5_MUXER
00082 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
00083 {
00084     char buf[256];
00085     if (PRIVSIZE < av_md5_size) {
00086         av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
00087         return -1;
00088     }
00089     av_md5_init(s->priv_data);
00090     av_md5_update(s->priv_data, pkt->data, pkt->size);
00091 
00092     snprintf(buf, sizeof(buf) - 64, "%d, %"PRId64", %d, ", pkt->stream_index, pkt->dts, pkt->size);
00093     md5_finish(s, buf);
00094     return 0;
00095 }
00096 
00097 AVOutputFormat ff_framemd5_muxer = {
00098     .name              = "framemd5",
00099     .long_name         = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
00100     .priv_data_size    = PRIVSIZE,
00101     .audio_codec       = CODEC_ID_PCM_S16LE,
00102     .video_codec       = CODEC_ID_RAWVIDEO,
00103     .write_packet      = framemd5_write_packet,
00104     .flags             = AVFMT_VARIABLE_FPS,
00105 };
00106 #endif
Generated on Fri Feb 1 2013 14:34:52 for FFmpeg by doxygen 1.7.1