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

libavformat/vc1test.c

Go to the documentation of this file.
00001 /*
00002  * VC1 Test Bitstreams Format Demuxer
00003  * Copyright (c) 2006, 2008 Konstantin Shishkov
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00029 #include "libavutil/intreadwrite.h"
00030 #include "avformat.h"
00031 
00032 #define VC1_EXTRADATA_SIZE 4
00033 
00034 static int vc1t_probe(AVProbeData *p)
00035 {
00036     if (p->buf[3] != 0xC5 && AV_RL32(&p->buf[4]) != 4)
00037         return 0;
00038 
00039     return AVPROBE_SCORE_MAX/2;
00040 }
00041 
00042 static int vc1t_read_header(AVFormatContext *s,
00043                            AVFormatParameters *ap)
00044 {
00045     ByteIOContext *pb = s->pb;
00046     AVStream *st;
00047     int fps, frames;
00048 
00049     frames = get_le24(pb);
00050     if(get_byte(pb) != 0xC5 || get_le32(pb) != 4)
00051         return -1;
00052 
00053     /* init video codec */
00054     st = av_new_stream(s, 0);
00055     if (!st)
00056         return -1;
00057 
00058     st->codec->codec_type = CODEC_TYPE_VIDEO;
00059     st->codec->codec_id = CODEC_ID_WMV3;
00060 
00061     st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
00062     st->codec->extradata_size = VC1_EXTRADATA_SIZE;
00063     get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
00064     st->codec->height = get_le32(pb);
00065     st->codec->width = get_le32(pb);
00066     if(get_le32(pb) != 0xC)
00067         return -1;
00068     url_fskip(pb, 8);
00069     fps = get_le32(pb);
00070     if(fps == -1)
00071         av_set_pts_info(st, 32, 1, 1000);
00072     else{
00073         av_set_pts_info(st, 24, 1, fps);
00074         st->duration = frames;
00075     }
00076 
00077     return 0;
00078 }
00079 
00080 static int vc1t_read_packet(AVFormatContext *s,
00081                            AVPacket *pkt)
00082 {
00083     ByteIOContext *pb = s->pb;
00084     int frame_size;
00085     int keyframe = 0;
00086     uint32_t pts;
00087 
00088     if(url_feof(pb))
00089         return AVERROR(EIO);
00090 
00091     frame_size = get_le24(pb);
00092     if(get_byte(pb) & 0x80)
00093         keyframe = 1;
00094     pts = get_le32(pb);
00095     if(av_get_packet(pb, pkt, frame_size) < 0)
00096         return AVERROR(EIO);
00097     if(s->streams[0]->time_base.den == 1000)
00098         pkt->pts = pts;
00099     pkt->flags |= keyframe ? PKT_FLAG_KEY : 0;
00100     pkt->pos -= 8;
00101 
00102     return pkt->size;
00103 }
00104 
00105 AVInputFormat vc1t_demuxer = {
00106     "vc1test",
00107     NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"),
00108     0,
00109     vc1t_probe,
00110     vc1t_read_header,
00111     vc1t_read_packet,
00112     .flags = AVFMT_GENERIC_INDEX,
00113 };

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1