]> git.sesse.net Git - ffmpeg/blob - libavformat/md5enc.c
lavf: deprecate r_frame_rate.
[ffmpeg] / libavformat / md5enc.c
1 /*
2  * MD5 encoder (for codec/format testing)
3  * Copyright (c) 2009 Reimar Döffinger, based on crcenc (c) 2002 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/md5.h"
23 #include "avformat.h"
24 #include "internal.h"
25
26 #define PRIVSIZE 512
27
28 static void md5_finish(struct AVFormatContext *s, char *buf)
29 {
30     uint8_t md5[16];
31     int i, offset = strlen(buf);
32     av_md5_final(s->priv_data, md5);
33     for (i = 0; i < sizeof(md5); i++) {
34         snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
35         offset += 2;
36     }
37     buf[offset] = '\n';
38     buf[offset+1] = 0;
39
40     avio_write(s->pb, buf, strlen(buf));
41     avio_flush(s->pb);
42 }
43
44 #if CONFIG_MD5_MUXER
45 static int write_header(struct AVFormatContext *s)
46 {
47     if (PRIVSIZE < av_md5_size) {
48         av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
49         return -1;
50     }
51     av_md5_init(s->priv_data);
52     return 0;
53 }
54
55 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
56 {
57     av_md5_update(s->priv_data, pkt->data, pkt->size);
58     return 0;
59 }
60
61 static int write_trailer(struct AVFormatContext *s)
62 {
63     char buf[64] = "MD5=";
64
65     md5_finish(s, buf);
66     return 0;
67 }
68
69 AVOutputFormat ff_md5_muxer = {
70     .name              = "md5",
71     .long_name         = NULL_IF_CONFIG_SMALL("MD5 testing format"),
72     .extensions        = "",
73     .priv_data_size    = PRIVSIZE,
74     .audio_codec       = CODEC_ID_PCM_S16LE,
75     .video_codec       = CODEC_ID_RAWVIDEO,
76     .write_header      = write_header,
77     .write_packet      = write_packet,
78     .write_trailer     = write_trailer,
79     .flags             = AVFMT_NOTIMESTAMPS,
80 };
81 #endif
82
83 #if CONFIG_FRAMEMD5_MUXER
84 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
85 {
86     char buf[256];
87     if (PRIVSIZE < av_md5_size) {
88         av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
89         return -1;
90     }
91     av_md5_init(s->priv_data);
92     av_md5_update(s->priv_data, pkt->data, pkt->size);
93
94     snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
95              pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
96     md5_finish(s, buf);
97     return 0;
98 }
99
100 AVOutputFormat ff_framemd5_muxer = {
101     .name              = "framemd5",
102     .long_name         = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
103     .extensions        = "",
104     .priv_data_size    = PRIVSIZE,
105     .audio_codec       = CODEC_ID_PCM_S16LE,
106     .video_codec       = CODEC_ID_RAWVIDEO,
107     .write_header      = ff_framehash_write_header,
108     .write_packet      = framemd5_write_packet,
109     .flags             = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
110 };
111 #endif