00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 #include "avformat.h"
00030
00031 #define VC1_EXTRADATA_SIZE 4
00032
00033 static int vc1t_probe(AVProbeData *p)
00034 {
00035 if (p->buf[3] != 0xC5 && AV_RL32(&p->buf[4]) != 4)
00036 return 0;
00037
00038 return AVPROBE_SCORE_MAX;
00039 }
00040
00041 static int vc1t_read_header(AVFormatContext *s,
00042 AVFormatParameters *ap)
00043 {
00044 ByteIOContext *pb = s->pb;
00045 AVStream *st;
00046 int fps, frames;
00047
00048 frames = get_le24(pb);
00049 if(get_byte(pb) != 0xC5 || get_le32(pb) != 4)
00050 return -1;
00051
00052
00053 st = av_new_stream(s, 0);
00054 if (!st)
00055 return -1;
00056
00057 st->codec->codec_type = CODEC_TYPE_VIDEO;
00058 st->codec->codec_id = CODEC_ID_WMV3;
00059
00060 st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
00061 st->codec->extradata_size = VC1_EXTRADATA_SIZE;
00062 get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
00063 st->codec->height = get_le32(pb);
00064 st->codec->width = get_le32(pb);
00065 if(get_le32(pb) != 0xC)
00066 return -1;
00067 url_fskip(pb, 8);
00068 fps = get_le32(pb);
00069 if(fps == -1)
00070 av_set_pts_info(st, 32, 1, 1000);
00071 else{
00072 av_set_pts_info(st, 24, 1, fps);
00073 st->duration = frames;
00074 }
00075
00076 return 0;
00077 }
00078
00079 static int vc1t_read_packet(AVFormatContext *s,
00080 AVPacket *pkt)
00081 {
00082 ByteIOContext *pb = s->pb;
00083 int frame_size;
00084 int keyframe = 0;
00085 uint32_t pts;
00086
00087 if(url_feof(pb))
00088 return AVERROR(EIO);
00089
00090 frame_size = get_le24(pb);
00091 if(get_byte(pb) & 0x80)
00092 keyframe = 1;
00093 pts = get_le32(pb);
00094 if(av_get_packet(pb, pkt, frame_size) < 0)
00095 return AVERROR(EIO);
00096 if(s->streams[0]->time_base.den == 1000)
00097 pkt->pts = pts;
00098 pkt->flags |= keyframe ? PKT_FLAG_KEY : 0;
00099 pkt->pos -= 8;
00100
00101 return pkt->size;
00102 }
00103
00104 AVInputFormat vc1t_demuxer = {
00105 "vc1test",
00106 "VC1 test bitstream format",
00107 0,
00108 vc1t_probe,
00109 vc1t_read_header,
00110 vc1t_read_packet,
00111 .flags = AVFMT_GENERIC_INDEX,
00112 };