00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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 };