Browse code

"Metal Gear Solid: The Twin Snakes" demuxer

Signed-off-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Paul B Mahol authored on 2012/03/22 07:18:54
Showing 6 changed files
... ...
@@ -19,6 +19,7 @@ version next:
19 19
 - RealAudio Lossless decoder
20 20
 - ZeroCodec decoder
21 21
 - tile video filter
22
+- Metal Gear Solid: The Twin Snakes demuxer
22 23
 
23 24
 
24 25
 version 0.10:
... ...
@@ -210,6 +210,7 @@ library:
210 210
 @item MAXIS XA                  @tab   @tab X
211 211
     @tab Used in Sim City 3000; file extension .xa.
212 212
 @item MD Studio                 @tab   @tab X
213
+@item Metal Gear Solid: The Twin Snakes @tab @tab X
213 214
 @item Mobotix .mxg              @tab   @tab X
214 215
 @item Monkey's Audio            @tab   @tab X
215 216
 @item Motion Pixels MVI         @tab   @tab X
... ...
@@ -143,6 +143,7 @@ OBJS-$(CONFIG_MATROSKA_MUXER)            += matroskaenc.o matroska.o \
143 143
                                             isom.o avc.o \
144 144
                                             flacenc_header.o avlanguage.o
145 145
 OBJS-$(CONFIG_MD5_MUXER)                 += md5enc.o
146
+OBJS-$(CONFIG_MGSTS_DEMUXER)             += mgsts.o
146 147
 OBJS-$(CONFIG_MICRODVD_DEMUXER)          += microdvddec.o
147 148
 OBJS-$(CONFIG_MICRODVD_MUXER)            += microdvdenc.o rawenc.o
148 149
 OBJS-$(CONFIG_MJPEG_DEMUXER)             += rawdec.o
... ...
@@ -134,6 +134,7 @@ void av_register_all(void)
134 134
     REGISTER_MUXER    (MD5, md5);
135 135
     REGISTER_MUXDEMUX (MATROSKA, matroska);
136 136
     REGISTER_MUXER    (MATROSKA_AUDIO, matroska_audio);
137
+    REGISTER_DEMUXER  (MGSTS, mgsts);
137 138
     REGISTER_MUXDEMUX (MICRODVD, microdvd);
138 139
     REGISTER_MUXDEMUX (MJPEG, mjpeg);
139 140
     REGISTER_MUXDEMUX (MLP, mlp);
140 141
new file mode 100644
... ...
@@ -0,0 +1,103 @@
0
+/*
1
+ * Metar Gear Solid: The Twin Snakes demuxer
2
+ * Copyright (c) 2012 Paul B Mahol
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/intreadwrite.h"
22
+#include "libavutil/intfloat.h"
23
+#include "avformat.h"
24
+#include "riff.h"
25
+
26
+static int read_probe(AVProbeData *p)
27
+{
28
+    if (AV_RB32(p->buf     ) != 0x000E ||
29
+        AV_RB32(p->buf +  4) != 0x0050 ||
30
+        AV_RB32(p->buf + 12) != 0x0034)
31
+        return 0;
32
+    return AVPROBE_SCORE_MAX;
33
+}
34
+
35
+static int read_header(AVFormatContext *s)
36
+{
37
+    AVIOContext *pb = s->pb;
38
+    AVStream    *st;
39
+    AVRational  fps;
40
+    uint32_t chunk_size;
41
+
42
+    avio_skip(pb, 4);
43
+    chunk_size = avio_rb32(pb);
44
+    if (chunk_size != 80)
45
+        return AVERROR(EIO);
46
+    avio_skip(pb, 20);
47
+
48
+    st = avformat_new_stream(s, 0);
49
+    if (!st)
50
+        return AVERROR(ENOMEM);
51
+
52
+    st->start_time = 0;
53
+    st->nb_frames  =
54
+    st->duration   = avio_rb32(pb);
55
+    fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);
56
+    st->codec->width  = avio_rb32(pb);
57
+    st->codec->height = avio_rb32(pb);
58
+    avio_skip(pb, 12);
59
+    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
60
+    st->codec->codec_tag  = avio_rb32(pb);
61
+    st->codec->codec_id   = ff_codec_get_id(ff_codec_bmp_tags,
62
+                                            st->codec->codec_tag);
63
+    avpriv_set_pts_info(st, 64, fps.den, fps.num);
64
+    avio_skip(pb, 20);
65
+
66
+    return 0;
67
+}
68
+
69
+static int read_packet(AVFormatContext *s, AVPacket *pkt)
70
+{
71
+    AVIOContext *pb = s->pb;
72
+    uint32_t chunk_size, payload_size;
73
+    int ret;
74
+
75
+    if (url_feof(pb))
76
+        return AVERROR_EOF;
77
+
78
+    avio_skip(pb, 4);
79
+    chunk_size = avio_rb32(pb);
80
+    avio_skip(pb, 4);
81
+    payload_size = avio_rb32(pb);
82
+
83
+    if (chunk_size < payload_size + 16)
84
+        return AVERROR(EIO);
85
+
86
+    ret = av_get_packet(pb, pkt, payload_size);
87
+    if (ret < 0)
88
+        return ret;
89
+
90
+    pkt->duration = 1;
91
+    avio_skip(pb, chunk_size - (ret + 16));
92
+
93
+    return ret;
94
+}
95
+
96
+AVInputFormat ff_mgsts_demuxer = {
97
+    .name        = "mgsts",
98
+    .long_name   = NULL_IF_CONFIG_SMALL("Metal Gear Solid: The Twin Snakes"),
99
+    .read_probe  = read_probe,
100
+    .read_header = read_header,
101
+    .read_packet = read_packet,
102
+};
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33
-#define LIBAVFORMAT_VERSION_MINOR  2
33
+#define LIBAVFORMAT_VERSION_MINOR  3
34 34
 #define LIBAVFORMAT_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \