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 #include "internal.h"
00032
00033 #define VC1_EXTRADATA_SIZE 4
00034
00035 static int vc1t_probe(AVProbeData *p)
00036 {
00037 if (p->buf_size < 24)
00038 return 0;
00039 if (p->buf[3] != 0xC5 || AV_RL32(&p->buf[4]) != 4 || AV_RL32(&p->buf[20]) != 0xC)
00040 return 0;
00041
00042 return AVPROBE_SCORE_MAX/2;
00043 }
00044
00045 static int vc1t_read_header(AVFormatContext *s)
00046 {
00047 AVIOContext *pb = s->pb;
00048 AVStream *st;
00049 int frames;
00050 uint32_t fps;
00051
00052 frames = avio_rl24(pb);
00053 if(avio_r8(pb) != 0xC5 || avio_rl32(pb) != 4)
00054 return -1;
00055
00056
00057 st = avformat_new_stream(s, NULL);
00058 if (!st)
00059 return -1;
00060
00061 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00062 st->codec->codec_id = AV_CODEC_ID_WMV3;
00063
00064 st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
00065 st->codec->extradata_size = VC1_EXTRADATA_SIZE;
00066 avio_read(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
00067 st->codec->height = avio_rl32(pb);
00068 st->codec->width = avio_rl32(pb);
00069 if(avio_rl32(pb) != 0xC)
00070 return -1;
00071 avio_skip(pb, 8);
00072 fps = avio_rl32(pb);
00073 if(fps == 0xFFFFFFFF)
00074 avpriv_set_pts_info(st, 32, 1, 1000);
00075 else{
00076 if (!fps) {
00077 av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n");
00078 fps = 1;
00079 }
00080 avpriv_set_pts_info(st, 24, 1, fps);
00081 st->duration = frames;
00082 }
00083
00084 return 0;
00085 }
00086
00087 static int vc1t_read_packet(AVFormatContext *s,
00088 AVPacket *pkt)
00089 {
00090 AVIOContext *pb = s->pb;
00091 int frame_size;
00092 int keyframe = 0;
00093 uint32_t pts;
00094
00095 if(url_feof(pb))
00096 return AVERROR(EIO);
00097
00098 frame_size = avio_rl24(pb);
00099 if(avio_r8(pb) & 0x80)
00100 keyframe = 1;
00101 pts = avio_rl32(pb);
00102 if(av_get_packet(pb, pkt, frame_size) < 0)
00103 return AVERROR(EIO);
00104 if(s->streams[0]->time_base.den == 1000)
00105 pkt->pts = pts;
00106 pkt->flags |= keyframe ? AV_PKT_FLAG_KEY : 0;
00107 pkt->pos -= 8;
00108
00109 return pkt->size;
00110 }
00111
00112 AVInputFormat ff_vc1t_demuxer = {
00113 .name = "vc1test",
00114 .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
00115 .read_probe = vc1t_probe,
00116 .read_header = vc1t_read_header,
00117 .read_packet = vc1t_read_packet,
00118 .flags = AVFMT_GENERIC_INDEX,
00119 };