annotate vc1testenc.c @ 3647:98eb4eb368fa libavformat

matroskadec: invert a test
author aurel
date Tue, 05 Aug 2008 00:40:46 +0000
parents b9898249bab0
children 460059833ae3
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 RCVContext *ctx = s->priv_data;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
30 AVCodecContext *avc = s->streams[0]->codec;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
31 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
32
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
33 if (avc->codec_id != CODEC_ID_WMV3) {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
34 av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
35 return -1;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
36 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
37 put_le24(pb, 0); //frames count will be here
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
38 put_byte(pb, 0xC5);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
39 put_le32(pb, 4);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
40 put_buffer(pb, avc->extradata, 4);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
41 put_le32(pb, avc->height);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
42 put_le32(pb, avc->width);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
43 put_le32(pb, 0xC);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
44 put_le24(pb, 0); // hrd_buffer
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
45 put_byte(pb, 0x80); // level|cbr|res1
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
46 put_le32(pb, 0); // hrd_rate
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
47 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
48 put_le32(pb, s->streams[0]->r_frame_rate.den);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
49 else
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
50 put_le32(pb, 0xFFFFFFFF); //variable framerate
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
51
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
52 return 0;
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
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
55 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
56 {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
57 RCVContext *ctx = s->priv_data;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
58 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
59
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
60 if (!pkt->size)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
61 return 0;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
62 put_le32(pb, pkt->size | ((pkt->flags & PKT_FLAG_KEY) ? 0x80000000 : 0));
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
63 put_le32(pb, pkt->pts);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
64 put_buffer(pb, pkt->data, pkt->size);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
65 put_flush_packet(pb);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
66 ctx->frames++;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
67
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
68 return 0;
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
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
71 static int vc1test_write_trailer(AVFormatContext *s)
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
72 {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
73 RCVContext *ctx = s->priv_data;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
74 ByteIOContext *pb = s->pb;
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
75
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
76 if (!url_is_streamed(s->pb)) {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
77 url_fseek(pb, 0, SEEK_SET);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
78 put_le24(pb, ctx->frames);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
79 put_flush_packet(pb);
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
80 }
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
81 return 0;
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
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
84 AVOutputFormat vc1t_muxer = {
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
85 "rcv",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
86 NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
87 "",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
88 "rcv",
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
89 sizeof(RCVContext),
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
90 CODEC_ID_NONE,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
91 CODEC_ID_WMV3,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
92 vc1test_write_header,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
93 vc1test_write_packet,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
94 vc1test_write_trailer,
b9898249bab0 SMPTE 421M Annex L (aka .rcv) muxer
kostya
parents:
diff changeset
95 };