2012-03-22 01:18:54 +03:00
|
|
|
/*
|
|
|
|
* Metar Gear Solid: The Twin Snakes demuxer
|
|
|
|
* Copyright (c) 2012 Paul B Mahol
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/intreadwrite.h"
|
|
|
|
#include "libavutil/intfloat.h"
|
|
|
|
#include "avformat.h"
|
|
|
|
#include "riff.h"
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int read_probe(const AVProbeData *p)
|
2012-03-22 01:18:54 +03:00
|
|
|
{
|
|
|
|
if (AV_RB32(p->buf ) != 0x000E ||
|
|
|
|
AV_RB32(p->buf + 4) != 0x0050 ||
|
|
|
|
AV_RB32(p->buf + 12) != 0x0034)
|
|
|
|
return 0;
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
AVStream *st;
|
|
|
|
AVRational fps;
|
|
|
|
uint32_t chunk_size;
|
|
|
|
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
chunk_size = avio_rb32(pb);
|
|
|
|
if (chunk_size != 80)
|
|
|
|
return AVERROR(EIO);
|
|
|
|
avio_skip(pb, 20);
|
|
|
|
|
|
|
|
st = avformat_new_stream(s, 0);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-05-02 04:28:18 +02:00
|
|
|
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
|
2012-03-22 01:18:54 +03:00
|
|
|
st->start_time = 0;
|
|
|
|
st->nb_frames =
|
|
|
|
st->duration = avio_rb32(pb);
|
|
|
|
fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = avio_rb32(pb);
|
|
|
|
st->codecpar->height = avio_rb32(pb);
|
2012-03-22 01:18:54 +03:00
|
|
|
avio_skip(pb, 12);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
st->codecpar->codec_tag = avio_rb32(pb);
|
|
|
|
st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
|
|
|
|
st->codecpar->codec_tag);
|
2012-03-22 01:18:54 +03:00
|
|
|
avpriv_set_pts_info(st, 64, fps.den, fps.num);
|
|
|
|
avio_skip(pb, 20);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
uint32_t chunk_size, payload_size;
|
|
|
|
int ret;
|
|
|
|
|
2014-08-07 23:12:41 +03:00
|
|
|
if (avio_feof(pb))
|
2012-03-22 01:18:54 +03:00
|
|
|
return AVERROR_EOF;
|
|
|
|
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
chunk_size = avio_rb32(pb);
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
payload_size = avio_rb32(pb);
|
|
|
|
|
|
|
|
if (chunk_size < payload_size + 16)
|
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
ret = av_get_packet(pb, pkt, payload_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-03-25 14:25:42 +03:00
|
|
|
pkt->pos -= 16;
|
2012-03-22 01:18:54 +03:00
|
|
|
pkt->duration = 1;
|
|
|
|
avio_skip(pb, chunk_size - (ret + 16));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-04-19 19:45:24 +02:00
|
|
|
const AVInputFormat ff_mgsts_demuxer = {
|
2012-03-22 01:18:54 +03:00
|
|
|
.name = "mgsts",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Metal Gear Solid: The Twin Snakes"),
|
|
|
|
.read_probe = read_probe,
|
|
|
|
.read_header = read_header,
|
|
|
|
.read_packet = read_packet,
|
2012-03-25 14:25:42 +03:00
|
|
|
.flags = AVFMT_GENERIC_INDEX,
|
2012-03-22 01:18:54 +03:00
|
|
|
};
|