Browse code

added demuxer for FunCom ISS audio files, extended ADPCM decoder by ISS specific IMA variant

Originally committed as revision 16658 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefan Gehrer authored on 2009/01/18 05:08:43
Showing 9 changed files
... ...
@@ -226,6 +226,7 @@ version 0.4.9-pre1:
226 226
 - more accurate deblock filter
227 227
 - padding support
228 228
 - many optimizations and bugfixes
229
+- FunCom ISS audio file demuxer and according ADPCM decoding
229 230
 
230 231
 version 0.4.8:
231 232
 
... ...
@@ -74,6 +74,8 @@ library:
74 74
     @tab .fli/.flc files
75 75
 @item FLV                       @tab X @tab X
76 76
     @tab Macromedia Flash video files
77
+@item FunCom ISS                @tab   @tab X
78
+    @tab Audio format used in various games from FunCom like The Longest Journey.
77 79
 @item GXF                       @tab X @tab X
78 80
     @tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley
79 81
          playout servers.
... ...
@@ -385,6 +387,8 @@ following image formats are supported:
385 385
 @item Intel Music Coder      @tab     @tab  X
386 386
 @item Interplay MVE DPCM     @tab     @tab  X
387 387
     @tab Used in various Interplay computer games.
388
+@item ISS IMA ADPCM          @tab     @tab  X
389
+    @tab Used in FunCom games.
388 390
 @item MAXIS EA ADPCM         @tab     @tab  X
389 391
     @tab Used in Sim City 3000.
390 392
 @item Microsoft ADPCM        @tab  X  @tab  X
... ...
@@ -1131,6 +1131,33 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
1131 1131
             *samples++ = c->status[0].predictor - c->status[1].predictor;
1132 1132
         }
1133 1133
         break;
1134
+    case CODEC_ID_ADPCM_IMA_ISS:
1135
+        c->status[0].predictor  = (int16_t)AV_RL16(src + 0);
1136
+        c->status[0].step_index = src[2];
1137
+        src += 4;
1138
+        if(st) {
1139
+            c->status[1].predictor  = (int16_t)AV_RL16(src + 0);
1140
+            c->status[1].step_index = src[2];
1141
+            src += 4;
1142
+        }
1143
+
1144
+        while (src < buf + buf_size) {
1145
+
1146
+            if (st) {
1147
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1148
+                    src[0] >> 4  , 3);
1149
+                *samples++ = adpcm_ima_expand_nibble(&c->status[1],
1150
+                    src[0] & 0x0F, 3);
1151
+            } else {
1152
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1153
+                    src[0] & 0x0F, 3);
1154
+                *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1155
+                    src[0] >> 4  , 3);
1156
+            }
1157
+
1158
+            src++;
1159
+        }
1160
+        break;
1134 1161
     case CODEC_ID_ADPCM_IMA_WS:
1135 1162
         /* no per-block initialization; just start decoding the data */
1136 1163
         while (src < buf + buf_size) {
... ...
@@ -1641,6 +1668,7 @@ ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "IMA Duck DK3 ADPCM");
1641 1641
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "IMA Duck DK4 ADPCM");
1642 1642
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "IMA Electronic Arts EACS ADPCM");
1643 1643
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "IMA Electronic Arts SEAD ADPCM");
1644
+ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "IMA Funcom ISS ADPCM");
1644 1645
 ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "IMA QuickTime ADPCM");
1645 1646
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "IMA Loki SDL MJPEG ADPCM");
1646 1647
 ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "IMA Wav ADPCM");
... ...
@@ -264,6 +264,7 @@ void avcodec_register_all(void)
264 264
     REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4);
265 265
     REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
266 266
     REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
267
+    REGISTER_DECODER (ADPCM_IMA_ISS, adpcm_ima_iss);
267 268
     REGISTER_ENCDEC  (ADPCM_IMA_QT, adpcm_ima_qt);
268 269
     REGISTER_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
269 270
     REGISTER_ENCDEC  (ADPCM_IMA_WAV, adpcm_ima_wav);
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVCODEC_VERSION_MAJOR 52
33
-#define LIBAVCODEC_VERSION_MINOR 10
33
+#define LIBAVCODEC_VERSION_MINOR 11
34 34
 #define LIBAVCODEC_VERSION_MICRO  0
35 35
 
36 36
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -245,6 +245,7 @@ enum CodecID {
245 245
     CODEC_ID_ADPCM_IMA_EA_EACS,
246 246
     CODEC_ID_ADPCM_EA_XAS,
247 247
     CODEC_ID_ADPCM_EA_MAXIS_XA,
248
+    CODEC_ID_ADPCM_IMA_ISS,
248 249
 
249 250
     /* AMR */
250 251
     CODEC_ID_AMR_NB= 0x12000,
... ...
@@ -78,6 +78,7 @@ OBJS-$(CONFIG_IMAGE2PIPE_MUXER)          += img2.o
78 78
 OBJS-$(CONFIG_INGENIENT_DEMUXER)         += raw.o
79 79
 OBJS-$(CONFIG_IPMOVIE_DEMUXER)           += ipmovie.o
80 80
 OBJS-$(CONFIG_IPOD_MUXER)                += movenc.o riff.o isom.o avc.o
81
+OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
81 82
 OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
82 83
 OBJS-$(CONFIG_M4V_DEMUXER)               += raw.o
83 84
 OBJS-$(CONFIG_M4V_MUXER)                 += raw.o
... ...
@@ -101,6 +101,7 @@ void av_register_all(void)
101 101
     REGISTER_DEMUXER  (INGENIENT, ingenient);
102 102
     REGISTER_DEMUXER  (IPMOVIE, ipmovie);
103 103
     REGISTER_MUXER    (IPOD, ipod);
104
+    REGISTER_DEMUXER  (ISS, iss);
104 105
     REGISTER_DEMUXER  (LMLM4, lmlm4);
105 106
     REGISTER_MUXDEMUX (M4V, m4v);
106 107
     REGISTER_MUXDEMUX (MATROSKA, matroska);
... ...
@@ -22,7 +22,7 @@
22 22
 #define AVFORMAT_AVFORMAT_H
23 23
 
24 24
 #define LIBAVFORMAT_VERSION_MAJOR 52
25
-#define LIBAVFORMAT_VERSION_MINOR 23
25
+#define LIBAVFORMAT_VERSION_MINOR 24
26 26
 #define LIBAVFORMAT_VERSION_MICRO  1
27 27
 
28 28
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
29 29
new file mode 100644
... ...
@@ -0,0 +1,130 @@
0
+/*
1
+ * ISS (.iss) file demuxer
2
+ * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
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
+/**
22
+ * @file iss.c
23
+ * Funcom ISS file demuxer
24
+ * @author Jaikrishnan Menon
25
+ * for more information on the .iss file format, visit:
26
+ * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
27
+ */
28
+
29
+#include "avformat.h"
30
+#include "libavutil/avstring.h"
31
+
32
+#define ISS_SIG "IMA_ADPCM_Sound"
33
+#define ISS_SIG_LEN 15
34
+#define MAX_TOKEN_SIZE 20
35
+
36
+typedef struct {
37
+    int packet_size;
38
+    int sample_start_pos;
39
+} IssDemuxContext;
40
+
41
+static void get_token(ByteIOContext *s, char *buf, int maxlen)
42
+{
43
+    int i = 0;
44
+    char c;
45
+
46
+    while ((c = get_byte(s))) {
47
+        if(c == ' ')
48
+            break;
49
+        if (i < maxlen-1)
50
+            buf[i++] = c;
51
+    }
52
+
53
+    buf[i] = 0; /* Ensure null terminated, but may be truncated */
54
+}
55
+
56
+static int iss_probe(AVProbeData *p)
57
+{
58
+    if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
59
+        return 0;
60
+
61
+    return AVPROBE_SCORE_MAX;
62
+}
63
+
64
+static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
65
+{
66
+    IssDemuxContext *iss = s->priv_data;
67
+    ByteIOContext *pb = s->pb;
68
+    AVStream *st;
69
+    char token[MAX_TOKEN_SIZE];
70
+    int stereo, rate_divisor;
71
+
72
+    get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
73
+    get_token(pb, token, sizeof(token)); //packet size
74
+    sscanf(token, "%d", &iss->packet_size);
75
+    get_token(pb, token, sizeof(token)); //File ID
76
+    get_token(pb, token, sizeof(token)); //out size
77
+    get_token(pb, token, sizeof(token)); //stereo
78
+    sscanf(token, "%d", &stereo);
79
+    get_token(pb, token, sizeof(token)); //Unknown1
80
+    get_token(pb, token, sizeof(token)); //RateDivisor
81
+    sscanf(token, "%d", &rate_divisor);
82
+    get_token(pb, token, sizeof(token)); //Unknown2
83
+    get_token(pb, token, sizeof(token)); //Version ID
84
+    get_token(pb, token, sizeof(token)); //Size
85
+
86
+    iss->sample_start_pos = url_ftell(pb);
87
+
88
+    st = av_new_stream(s, 0);
89
+    if (!st)
90
+        return AVERROR(ENOMEM);
91
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
92
+    st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
93
+    st->codec->channels = stereo ? 2 : 1;
94
+    st->codec->sample_rate = 44100;
95
+    if(rate_divisor > 0)
96
+         st->codec->sample_rate /= rate_divisor;
97
+    st->codec->bits_per_coded_sample = 4;
98
+    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
99
+                                      * st->codec->bits_per_coded_sample;
100
+    st->codec->block_align = iss->packet_size;
101
+    av_set_pts_info(st, 32, 1, st->codec->sample_rate);
102
+
103
+    return 0;
104
+}
105
+
106
+static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
107
+{
108
+    IssDemuxContext *iss = s->priv_data;
109
+    int ret = av_get_packet(s->pb, pkt, iss->packet_size);
110
+
111
+    if(ret < 0)
112
+        return ret;
113
+
114
+    pkt->stream_index = 0;
115
+    pkt->pts = url_ftell(s->pb) - iss->sample_start_pos;
116
+    if(s->streams[0]->codec->channels > 0)
117
+        pkt->pts /= s->streams[0]->codec->channels*2;
118
+    return 0;
119
+}
120
+
121
+AVInputFormat iss_demuxer = {
122
+    "ISS",
123
+    NULL_IF_CONFIG_SMALL("Funcom ISS format"),
124
+    sizeof(IssDemuxContext),
125
+    iss_probe,
126
+    iss_read_header,
127
+    iss_read_packet,
128
+};
129
+