2008-07-23 19:06:40 +02:00
|
|
|
/*
|
|
|
|
* VC-1 test bitstreams format muxer.
|
|
|
|
* Copyright (c) 2008 Konstantin Shishkov
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2008-07-23 19:06:40 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2008-07-23 19:06:40 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2008-07-23 19:06:40 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2008-07-23 19:06:40 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#include "avformat.h"
|
|
|
|
|
|
|
|
typedef struct RCVContext {
|
|
|
|
int frames;
|
|
|
|
} RCVContext;
|
|
|
|
|
|
|
|
static int vc1test_write_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVCodecContext *avc = s->streams[0]->codec;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-07-23 19:06:40 +02:00
|
|
|
|
|
|
|
if (avc->codec_id != CODEC_ID_WMV3) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-02-21 19:28:17 +01:00
|
|
|
avio_wl24(pb, 0); //frames count will be here
|
|
|
|
avio_w8(pb, 0xC5);
|
|
|
|
avio_wl32(pb, 4);
|
|
|
|
avio_write(pb, avc->extradata, 4);
|
|
|
|
avio_wl32(pb, avc->height);
|
|
|
|
avio_wl32(pb, avc->width);
|
|
|
|
avio_wl32(pb, 0xC);
|
|
|
|
avio_wl24(pb, 0); // hrd_buffer
|
|
|
|
avio_w8(pb, 0x80); // level|cbr|res1
|
|
|
|
avio_wl32(pb, 0); // hrd_rate
|
2008-07-23 19:06:40 +02:00
|
|
|
if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1)
|
2011-02-21 19:28:17 +01:00
|
|
|
avio_wl32(pb, s->streams[0]->r_frame_rate.den);
|
2008-07-23 19:06:40 +02:00
|
|
|
else
|
2011-02-21 19:28:17 +01:00
|
|
|
avio_wl32(pb, 0xFFFFFFFF); //variable framerate
|
2011-01-29 13:44:34 +01:00
|
|
|
av_set_pts_info(s->streams[0], 32, 1, 1000);
|
2008-07-23 19:06:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
RCVContext *ctx = s->priv_data;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-07-23 19:06:40 +02:00
|
|
|
|
|
|
|
if (!pkt->size)
|
|
|
|
return 0;
|
2011-02-21 19:28:17 +01:00
|
|
|
avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0));
|
|
|
|
avio_wl32(pb, pkt->pts);
|
|
|
|
avio_write(pb, pkt->data, pkt->size);
|
2011-03-14 20:39:06 +01:00
|
|
|
avio_flush(pb);
|
2008-07-23 19:06:40 +02:00
|
|
|
ctx->frames++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vc1test_write_trailer(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
RCVContext *ctx = s->priv_data;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-07-23 19:06:40 +02:00
|
|
|
|
2011-03-05 21:06:46 +01:00
|
|
|
if (s->pb->seekable) {
|
2011-02-28 14:57:54 +01:00
|
|
|
avio_seek(pb, 0, SEEK_SET);
|
2011-02-21 19:28:17 +01:00
|
|
|
avio_wl24(pb, ctx->frames);
|
2011-03-14 20:39:06 +01:00
|
|
|
avio_flush(pb);
|
2008-07-23 19:06:40 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:03:28 +01:00
|
|
|
AVOutputFormat ff_vc1t_muxer = {
|
2008-07-23 19:06:40 +02:00
|
|
|
"rcv",
|
|
|
|
NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
|
|
|
|
"",
|
|
|
|
"rcv",
|
|
|
|
sizeof(RCVContext),
|
|
|
|
CODEC_ID_NONE,
|
|
|
|
CODEC_ID_WMV3,
|
|
|
|
vc1test_write_header,
|
|
|
|
vc1test_write_packet,
|
|
|
|
vc1test_write_trailer,
|
|
|
|
};
|