~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavformat/md5enc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "libavutil/md5.h"
23
23
#include "avformat.h"
 
24
#include "internal.h"
24
25
 
25
 
#define PRIVSIZE 512
 
26
struct MD5Context {
 
27
    struct AVMD5 *md5;
 
28
};
26
29
 
27
30
static void md5_finish(struct AVFormatContext *s, char *buf)
28
31
{
 
32
    struct MD5Context *c = s->priv_data;
29
33
    uint8_t md5[16];
30
34
    int i, offset = strlen(buf);
31
 
    av_md5_final(s->priv_data, md5);
 
35
    av_md5_final(c->md5, md5);
32
36
    for (i = 0; i < sizeof(md5); i++) {
33
37
        snprintf(buf + offset, 3, "%02"PRIx8, md5[i]);
34
38
        offset += 2;
43
47
#if CONFIG_MD5_MUXER
44
48
static int write_header(struct AVFormatContext *s)
45
49
{
46
 
    if (PRIVSIZE < av_md5_size) {
47
 
        av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
48
 
        return -1;
49
 
    }
50
 
    av_md5_init(s->priv_data);
 
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);
51
55
    return 0;
52
56
}
53
57
 
54
58
static int write_packet(struct AVFormatContext *s, AVPacket *pkt)
55
59
{
56
 
    av_md5_update(s->priv_data, pkt->data, pkt->size);
 
60
    struct MD5Context *c = s->priv_data;
 
61
    av_md5_update(c->md5, pkt->data, pkt->size);
57
62
    return 0;
58
63
}
59
64
 
60
65
static int write_trailer(struct AVFormatContext *s)
61
66
{
 
67
    struct MD5Context *c = s->priv_data;
62
68
    char buf[64] = "MD5=";
63
69
 
64
70
    md5_finish(s, buf);
 
71
 
 
72
    av_freep(&c->md5);
65
73
    return 0;
66
74
}
67
75
 
68
76
AVOutputFormat ff_md5_muxer = {
69
77
    .name              = "md5",
70
 
    .long_name         = NULL_IF_CONFIG_SMALL("MD5 testing format"),
 
78
    .long_name         = NULL_IF_CONFIG_SMALL("MD5 testing"),
71
79
    .extensions        = "",
72
 
    .priv_data_size    = PRIVSIZE,
73
 
    .audio_codec       = CODEC_ID_PCM_S16LE,
74
 
    .video_codec       = CODEC_ID_RAWVIDEO,
 
80
    .priv_data_size    = sizeof(struct MD5Context),
 
81
    .audio_codec       = AV_CODEC_ID_PCM_S16LE,
 
82
    .video_codec       = AV_CODEC_ID_RAWVIDEO,
75
83
    .write_header      = write_header,
76
84
    .write_packet      = write_packet,
77
85
    .write_trailer     = write_trailer,
80
88
#endif
81
89
 
82
90
#if CONFIG_FRAMEMD5_MUXER
 
91
static int framemd5_write_header(struct AVFormatContext *s)
 
92
{
 
93
    struct MD5Context *c = s->priv_data;
 
94
    c->md5 = av_md5_alloc();
 
95
    if (!c->md5)
 
96
        return AVERROR(ENOMEM);
 
97
    return ff_framehash_write_header(s);
 
98
}
 
99
 
83
100
static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
84
101
{
 
102
    struct MD5Context *c = s->priv_data;
85
103
    char buf[256];
86
 
    if (PRIVSIZE < av_md5_size) {
87
 
        av_log(s, AV_LOG_ERROR, "Insuffient size for md5 context\n");
88
 
        return -1;
89
 
    }
90
 
    av_md5_init(s->priv_data);
91
 
    av_md5_update(s->priv_data, pkt->data, pkt->size);
 
104
    av_md5_init(c->md5);
 
105
    av_md5_update(c->md5, pkt->data, pkt->size);
92
106
 
93
 
    snprintf(buf, sizeof(buf) - 64, "%d, %"PRId64", %d, ", pkt->stream_index, pkt->dts, pkt->size);
 
107
    snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
 
108
             pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
94
109
    md5_finish(s, buf);
95
110
    return 0;
96
111
}
97
112
 
 
113
static int framemd5_write_trailer(struct AVFormatContext *s)
 
114
{
 
115
    struct MD5Context *c = s->priv_data;
 
116
    av_freep(&c->md5);
 
117
    return 0;
 
118
}
 
119
 
98
120
AVOutputFormat ff_framemd5_muxer = {
99
121
    .name              = "framemd5",
100
 
    .long_name         = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"),
 
122
    .long_name         = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing"),
101
123
    .extensions        = "",
102
 
    .priv_data_size    = PRIVSIZE,
103
 
    .audio_codec       = CODEC_ID_PCM_S16LE,
104
 
    .video_codec       = CODEC_ID_RAWVIDEO,
 
124
    .priv_data_size    = sizeof(struct MD5Context),
 
125
    .audio_codec       = AV_CODEC_ID_PCM_S16LE,
 
126
    .video_codec       = AV_CODEC_ID_RAWVIDEO,
 
127
    .write_header      = framemd5_write_header,
105
128
    .write_packet      = framemd5_write_packet,
106
 
    .flags             = AVFMT_VARIABLE_FPS,
 
129
    .write_trailer     = framemd5_write_trailer,
 
130
    .flags             = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT,
107
131
};
108
132
#endif