• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/vc1testenc.c

Go to the documentation of this file.
00001 /*
00002  * VC-1 test bitstreams format muxer.
00003  * Copyright (c) 2008 Konstantin Shishkov
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 #include "avformat.h"
00022 #include "internal.h"
00023 
00024 typedef struct RCVContext {
00025     int frames;
00026 } RCVContext;
00027 
00028 static int vc1test_write_header(AVFormatContext *s)
00029 {
00030     AVCodecContext *avc = s->streams[0]->codec;
00031     AVIOContext *pb = s->pb;
00032 
00033     if (avc->codec_id != CODEC_ID_WMV3) {
00034         av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n");
00035         return -1;
00036     }
00037     avio_wl24(pb, 0); //frames count will be here
00038     avio_w8(pb, 0xC5);
00039     avio_wl32(pb, 4);
00040     avio_write(pb, avc->extradata, 4);
00041     avio_wl32(pb, avc->height);
00042     avio_wl32(pb, avc->width);
00043     avio_wl32(pb, 0xC);
00044     avio_wl24(pb, 0); // hrd_buffer
00045     avio_w8(pb, 0x80); // level|cbr|res1
00046     avio_wl32(pb, 0); // hrd_rate
00047     if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1)
00048         avio_wl32(pb, s->streams[0]->r_frame_rate.den);
00049     else
00050         avio_wl32(pb, 0xFFFFFFFF); //variable framerate
00051     avpriv_set_pts_info(s->streams[0], 32, 1, 1000);
00052 
00053     return 0;
00054 }
00055 
00056 static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt)
00057 {
00058     RCVContext *ctx = s->priv_data;
00059     AVIOContext *pb = s->pb;
00060 
00061     if (!pkt->size)
00062         return 0;
00063     avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0));
00064     avio_wl32(pb, pkt->pts);
00065     avio_write(pb, pkt->data, pkt->size);
00066     avio_flush(pb);
00067     ctx->frames++;
00068 
00069     return 0;
00070 }
00071 
00072 static int vc1test_write_trailer(AVFormatContext *s)
00073 {
00074     RCVContext *ctx = s->priv_data;
00075     AVIOContext *pb = s->pb;
00076 
00077     if (s->pb->seekable) {
00078         avio_seek(pb, 0, SEEK_SET);
00079         avio_wl24(pb, ctx->frames);
00080         avio_flush(pb);
00081     }
00082     return 0;
00083 }
00084 
00085 AVOutputFormat ff_vc1t_muxer = {
00086     .name              = "rcv",
00087     .long_name         = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
00088     .mime_type         = "",
00089     .extensions        = "rcv",
00090     .priv_data_size    = sizeof(RCVContext),
00091     .audio_codec       = CODEC_ID_NONE,
00092     .video_codec       = CODEC_ID_WMV3,
00093     .write_header      = vc1test_write_header,
00094     .write_packet      = vc1test_write_packet,
00095     .write_trailer     = vc1test_write_trailer,
00096 };
Generated on Thu Jul 11 2013 15:38:24 for Libav by doxygen 1.7.1