Statistics
| Branch: | Revision:

ffmpeg / libavformat / iss.c @ 055dc116

History | View | Annotate | Download (3.75 KB)

1
/*
2
 * ISS (.iss) file demuxer
3
 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
/**
23
 * @file iss.c
24
 * Funcom ISS file demuxer
25
 * @author Jaikrishnan Menon
26
 * for more information on the .iss file format, visit:
27
 * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
28
 */
29

    
30
#include "avformat.h"
31
#include "libavutil/avstring.h"
32

    
33
#define ISS_SIG "IMA_ADPCM_Sound"
34
#define ISS_SIG_LEN 15
35
#define MAX_TOKEN_SIZE 20
36

    
37
typedef struct {
38
    int packet_size;
39
    int sample_start_pos;
40
} IssDemuxContext;
41

    
42
static void get_token(ByteIOContext *s, char *buf, int maxlen)
43
{
44
    int i = 0;
45
    char c;
46

    
47
    while ((c = get_byte(s))) {
48
        if(c == ' ')
49
            break;
50
        if (i < maxlen-1)
51
            buf[i++] = c;
52
    }
53

    
54
    buf[i] = 0; /* Ensure null terminated, but may be truncated */
55
}
56

    
57
static int iss_probe(AVProbeData *p)
58
{
59
    if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
60
        return 0;
61

    
62
    return AVPROBE_SCORE_MAX;
63
}
64

    
65
static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
66
{
67
    IssDemuxContext *iss = s->priv_data;
68
    ByteIOContext *pb = s->pb;
69
    AVStream *st;
70
    char token[MAX_TOKEN_SIZE];
71
    int stereo, rate_divisor;
72

    
73
    get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
74
    get_token(pb, token, sizeof(token)); //packet size
75
    sscanf(token, "%d", &iss->packet_size);
76
    get_token(pb, token, sizeof(token)); //File ID
77
    get_token(pb, token, sizeof(token)); //out size
78
    get_token(pb, token, sizeof(token)); //stereo
79
    sscanf(token, "%d", &stereo);
80
    get_token(pb, token, sizeof(token)); //Unknown1
81
    get_token(pb, token, sizeof(token)); //RateDivisor
82
    sscanf(token, "%d", &rate_divisor);
83
    get_token(pb, token, sizeof(token)); //Unknown2
84
    get_token(pb, token, sizeof(token)); //Version ID
85
    get_token(pb, token, sizeof(token)); //Size
86

    
87
    iss->sample_start_pos = url_ftell(pb);
88

    
89
    st = av_new_stream(s, 0);
90
    if (!st)
91
        return AVERROR(ENOMEM);
92
    st->codec->codec_type = CODEC_TYPE_AUDIO;
93
    st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
94
    st->codec->channels = stereo ? 2 : 1;
95
    st->codec->sample_rate = 44100;
96
    if(rate_divisor > 0)
97
         st->codec->sample_rate /= rate_divisor;
98
    st->codec->bits_per_coded_sample = 4;
99
    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
100
                                      * st->codec->bits_per_coded_sample;
101
    st->codec->block_align = iss->packet_size;
102
    av_set_pts_info(st, 32, 1, st->codec->sample_rate);
103

    
104
    return 0;
105
}
106

    
107
static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
108
{
109
    IssDemuxContext *iss = s->priv_data;
110
    int ret = av_get_packet(s->pb, pkt, iss->packet_size);
111

    
112
    if(ret < 0)
113
        return ret;
114

    
115
    pkt->stream_index = 0;
116
    pkt->pts = url_ftell(s->pb) - iss->sample_start_pos;
117
    if(s->streams[0]->codec->channels > 0)
118
        pkt->pts /= s->streams[0]->codec->channels*2;
119
    return 0;
120
}
121

    
122
AVInputFormat iss_demuxer = {
123
    "ISS",
124
    NULL_IF_CONFIG_SMALL("Funcom ISS format"),
125
    sizeof(IssDemuxContext),
126
    iss_probe,
127
    iss_read_header,
128
    iss_read_packet,
129
};
130