annotate vc1testenc.c @ 4209:020395b83a14 libavformat

compute pcr more accurately, regression tests need update
author bcoudurier
date Wed, 14 Jan 2009 02:20:26 +0000
parents 460059833ae3
children 11bb10c37225
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3594
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
1 /*
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
2 * VC-1 test bitstreams format muxer.
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
3 * Copyright (c) 2008 Konstantin Shishkov
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
4 *
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
6 *
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
11 *
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
16 *
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
20 */
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
21 #include "avformat.h"
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
22
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
23 typedef struct RCVContext {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
24 int frames;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
25 } RCVContext;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
26
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
27 static int vc1test_write_header(AVFormatContext *s)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
28 {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
29 AVCodecContext *avc = s->streams[0]->codec;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
30 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
31
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
32 if (avc->codec_id != CODEC_ID_WMV3) {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
33 av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
34 return -1;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
35 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
36 put_le24(pb, 0); //frames count will be here
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
37 put_byte(pb, 0xC5);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
38 put_le32(pb, 4);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
39 put_buffer(pb, avc->extradata, 4);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
40 put_le32(pb, avc->height);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
41 put_le32(pb, avc->width);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
42 put_le32(pb, 0xC);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
43 put_le24(pb, 0); // hrd_buffer
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
44 put_byte(pb, 0x80); // level|cbr|res1
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
45 put_le32(pb, 0); // hrd_rate
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
46 if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
47 put_le32(pb, s->streams[0]->r_frame_rate.den);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
48 else
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
49 put_le32(pb, 0xFFFFFFFF); //variable framerate
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
50
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
51 return 0;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
52 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
53
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
54 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
55 {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
56 RCVContext *ctx = s->priv_data;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
57 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
58
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
59 if (!pkt->size)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
60 return 0;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
61 put_le32(pb, pkt->size | ((pkt->flags & PKT_FLAG_KEY) ? 0x80000000 : 0));
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
62 put_le32(pb, pkt->pts);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
63 put_buffer(pb, pkt->data, pkt->size);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
64 put_flush_packet(pb);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
65 ctx->frames++;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
66
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
67 return 0;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
68 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
69
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
70 static int vc1test_write_trailer(AVFormatContext *s)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
71 {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
72 RCVContext *ctx = s->priv_data;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
73 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
74
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
75 if (!url_is_streamed(s->pb)) {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
76 url_fseek(pb, 0, SEEK_SET);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
77 put_le24(pb, ctx->frames);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
78 put_flush_packet(pb);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
79 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
80 return 0;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
81 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
82
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
83 AVOutputFormat vc1t_muxer = {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
84 "rcv",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
85 NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
86 "",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
87 "rcv",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
88 sizeof(RCVContext),
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
89 CODEC_ID_NONE,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
90 CODEC_ID_WMV3,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
91 vc1test_write_header,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
92 vc1test_write_packet,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
93 vc1test_write_trailer,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
94 };