md5enc.c
Go to the documentation of this file.
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 FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 struct MD5Context {
27  struct AVMD5 *md5;
28 };
29 
30 static void md5_finish(struct AVFormatContext *s, char *buf)
31 {
32  struct MD5Context *c = s->priv_data;
33  uint8_t md5[16];
34  int i, offset = strlen(buf);
35  av_md5_final(c->md5, md5);
36  for (i = 0; i < sizeof(md5); i++) {
37  snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
38  offset += 2;
39  }
40  buf[offset] = '\n';
41  buf[offset+1] = 0;
42 
43  avio_write(s->pb, buf, strlen(buf));
44  avio_flush(s->pb);
45 }
46 
47 #if CONFIG_MD5_MUXER
48 static int write_header(struct AVFormatContext *s)
49 {
50  struct MD5Context *c = s->priv_data;
51  c->md5 = av_md5_alloc();
52  if (!c->md5)
53  return AVERROR(ENOMEM);
54  av_md5_init(c->md5);
55  return 0;
56 }
57 
58 static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
59 {
60  struct MD5Context *c = s->priv_data;
61  av_md5_update(c->md5, pkt->data, pkt->size);
62  return 0;
63 }
64 
65 static int write_trailer(struct AVFormatContext *s)
66 {
67  struct MD5Context *c = s->priv_data;
68  char buf[64] = "MD5=";
69 
70  md5_finish(s, buf);
71 
72  av_freep(&c->md5);
73  return 0;
74 }
75 
76 AVOutputFormat ff_md5_muxer = {
77  .name = "md5",
78  .long_name = NULL_IF_CONFIG_SMALL("MD5 testing"),
79  .priv_data_size = sizeof(struct MD5Context),
80  .audio_codec = AV_CODEC_ID_PCM_S16LE,
81  .video_codec = AV_CODEC_ID_RAWVIDEO,
82  .write_header = write_header,
83  .write_packet = write_packet,
84  .write_trailer = write_trailer,
85  .flags = AVFMT_NOTIMESTAMPS,
86 };
87 #endif
88 
89 #if CONFIG_FRAMEMD5_MUXER
90 static int framemd5_write_header(struct AVFormatContext *s)
91 {
92  struct MD5Context *c = s->priv_data;
93  c->md5 = av_md5_alloc();
94  if (!c->md5)
95  return AVERROR(ENOMEM);
96  return ff_framehash_write_header(s);
97 }
98 
99 static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
100 {
101  struct MD5Context *c = s->priv_data;
102  char buf[256];
103  av_md5_init(c->md5);
104  av_md5_update(c->md5, pkt->data, pkt->size);
105 
106  snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
107  pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
108  md5_finish(s, buf);
109  return 0;
110 }
111 
112 static int framemd5_write_trailer(struct AVFormatContext *s)
113 {
114  struct MD5Context *c = s->priv_data;
115  av_freep(&c->md5);
116  return 0;
117 }
118 
119 AVOutputFormat ff_framemd5_muxer = {
120  .name = "framemd5",
121  .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing"),
122  .priv_data_size = sizeof(struct MD5Context),
123  .audio_codec = AV_CODEC_ID_PCM_S16LE,
124  .video_codec = AV_CODEC_ID_RAWVIDEO,
125  .write_header = framemd5_write_header,
126  .write_packet = framemd5_write_packet,
127  .write_trailer = framemd5_write_trailer,
129 };
130 #endif
const char * s
Definition: avisynth_c.h:668
struct AVMD5 * md5
Definition: md5enc.c:27
static int write_packet(AVFormatContext *s, AVPacket *pkt)
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:363
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
struct AVMD5 * av_md5_alloc(void)
Definition: md5.c:47
uint8_t
static AVPacket pkt
Definition: demuxing.c:56
uint8_t * data
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
Definition: md5.c:39
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int write_trailer(AVFormatContext *s)
void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
Definition: md5.c:142
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
int void avio_flush(AVIOContext *s)
Force flushing of buffered data to the output s.
Definition: aviobuf.c:193
const char * name
Definition: avformat.h:378
int ff_framehash_write_header(AVFormatContext *s)
Set the timebase for each stream from the corresponding codec timebase and print it.
Definition: framehash.c:23
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:352
AVIOContext * pb
I/O context.
Definition: avformat.h:977
void av_md5_init(AVMD5 *ctx)
Definition: md5.c:132
void * buf
Definition: avisynth_c.h:594
synthesis window for stochastic i
#define snprintf
Definition: snprintf.h:34
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Definition: md5.c:158
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
Main libavformat public API header.
static double c[64]
static void md5_finish(struct AVFormatContext *s, char *buf)
Definition: md5enc.c:30
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:355
void * priv_data
Format private data.
Definition: avformat.h:964
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:470
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...