00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/intreadwrite.h"
00023 #include "libavutil/intfloat.h"
00024 #include "avformat.h"
00025 #include "riff.h"
00026
00027 static int read_probe(AVProbeData *p)
00028 {
00029 if (AV_RB32(p->buf ) != 0x000E ||
00030 AV_RB32(p->buf + 4) != 0x0050 ||
00031 AV_RB32(p->buf + 12) != 0x0034)
00032 return 0;
00033 return AVPROBE_SCORE_MAX;
00034 }
00035
00036 static int read_header(AVFormatContext *s)
00037 {
00038 AVIOContext *pb = s->pb;
00039 AVStream *st;
00040 AVRational fps;
00041 uint32_t chunk_size;
00042
00043 avio_skip(pb, 4);
00044 chunk_size = avio_rb32(pb);
00045 if (chunk_size != 80)
00046 return AVERROR(EIO);
00047 avio_skip(pb, 20);
00048
00049 st = avformat_new_stream(s, 0);
00050 if (!st)
00051 return AVERROR(ENOMEM);
00052
00053 st->need_parsing = AVSTREAM_PARSE_HEADERS;
00054 st->start_time = 0;
00055 st->nb_frames =
00056 st->duration = avio_rb32(pb);
00057 fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
00058 st->codec->width = avio_rb32(pb);
00059 st->codec->height = avio_rb32(pb);
00060 avio_skip(pb, 12);
00061 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00062 st->codec->codec_tag = avio_rb32(pb);
00063 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
00064 st->codec->codec_tag);
00065 avpriv_set_pts_info(st, 64, fps.den, fps.num);
00066 avio_skip(pb, 20);
00067
00068 return 0;
00069 }
00070
00071 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00072 {
00073 AVIOContext *pb = s->pb;
00074 uint32_t chunk_size, payload_size;
00075 int ret;
00076
00077 if (url_feof(pb))
00078 return AVERROR_EOF;
00079
00080 avio_skip(pb, 4);
00081 chunk_size = avio_rb32(pb);
00082 avio_skip(pb, 4);
00083 payload_size = avio_rb32(pb);
00084
00085 if (chunk_size < payload_size + 16)
00086 return AVERROR(EIO);
00087
00088 ret = av_get_packet(pb, pkt, payload_size);
00089 if (ret < 0)
00090 return ret;
00091
00092 pkt->pos -= 16;
00093 pkt->duration = 1;
00094 avio_skip(pb, chunk_size - (ret + 16));
00095
00096 return ret;
00097 }
00098
00099 AVInputFormat ff_mgsts_demuxer = {
00100 .name = "mgsts",
00101 .long_name = NULL_IF_CONFIG_SMALL("Metal Gear Solid: The Twin Snakes"),
00102 .read_probe = read_probe,
00103 .read_header = read_header,
00104 .read_packet = read_packet,
00105 .flags = AVFMT_GENERIC_INDEX,
00106 };