~ubuntu-branches/debian/sid/mplayer/sid

« back to all changes in this revision

Viewing changes to libavformat/westwood.c

  • Committer: Bazaar Package Importer
  • Author(s): A Mennucc1
  • Date: 2009-03-23 10:05:45 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090323100545-x8h79obawnnte7kk
Tags: 1.0~rc2+svn20090303-5
debian/control : move docbook-xml,docbook-xsl,xsltproc from 
Build-Depends-Indep to Build-Depends, since they are needed to run
configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
/**
23
 
 * @file westwood.c
 
23
 * @file libavformat/westwood.c
24
24
 * Westwood Studios VQA & AUD file demuxers
25
25
 * by Mike Melanson (melanson@pcisys.net)
26
26
 * for more information on the Westwood file formats, visit:
33
33
 * qualify a file. Refer to wsaud_probe() for the precise parameters.
34
34
 */
35
35
 
 
36
#include "libavutil/intreadwrite.h"
36
37
#include "avformat.h"
37
38
 
38
39
#define AUD_HEADER_SIZE 12
66
67
    int audio_samplerate;
67
68
    int audio_channels;
68
69
    int audio_bits;
69
 
    int audio_type;
 
70
    enum CodecID audio_type;
70
71
    int audio_stream_index;
71
72
    int64_t audio_frame_counter;
72
73
} WsAudDemuxContext;
90
91
    /* Probabilistic content detection strategy: There is no file signature
91
92
     * so perform sanity checks on various header parameters:
92
93
     *   8000 <= sample rate (16 bits) <= 48000  ==> 40001 acceptable numbers
 
94
     *   flags <= 0x03 (2 LSBs are used)         ==> 4 acceptable numbers
93
95
     *   compression type (8 bits) = 1 or 99     ==> 2 acceptable numbers
94
 
     * There is a total of 24 bits. The number space contains 2^24 =
95
 
     * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations
96
 
     * of numbers. There is a 80002/16777216 = 0.48% chance of a false
97
 
     * positive.
 
96
     *   first audio chunk signature (32 bits)   ==> 1 acceptable number
 
97
     * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 =
 
98
     * 320008 acceptable number combinations.
98
99
     */
99
100
 
100
 
    if (p->buf_size < AUD_HEADER_SIZE)
 
101
    if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE)
101
102
        return 0;
102
103
 
103
104
    /* check sample rate */
105
106
    if ((field < 8000) || (field > 48000))
106
107
        return 0;
107
108
 
 
109
    /* enforce the rule that the top 6 bits of this flags field are reserved (0);
 
110
     * this might not be true, but enforce it until deemed unnecessary */
 
111
    if (p->buf[10] & 0xFC)
 
112
        return 0;
 
113
 
108
114
    /* note: only check for WS IMA (type 99) right now since there is no
109
115
     * support for type 1 */
110
116
    if (p->buf[11] != 99)
111
117
        return 0;
112
118
 
 
119
    /* read ahead to the first audio chunk and validate the first header signature */
 
120
    if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE)
 
121
        return 0;
 
122
 
113
123
    /* return 1/2 certainty since this file check is a little sketchy */
114
124
    return AVPROBE_SCORE_MAX / 2;
115
125
}
118
128
                             AVFormatParameters *ap)
119
129
{
120
130
    WsAudDemuxContext *wsaud = s->priv_data;
121
 
    ByteIOContext *pb = &s->pb;
 
131
    ByteIOContext *pb = s->pb;
122
132
    AVStream *st;
123
133
    unsigned char header[AUD_HEADER_SIZE];
124
134
 
145
155
    st->codec->codec_tag = 0;  /* no tag */
146
156
    st->codec->channels = wsaud->audio_channels;
147
157
    st->codec->sample_rate = wsaud->audio_samplerate;
148
 
    st->codec->bits_per_sample = wsaud->audio_bits;
 
158
    st->codec->bits_per_coded_sample = wsaud->audio_bits;
149
159
    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
150
 
        st->codec->bits_per_sample / 4;
151
 
    st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
 
160
        st->codec->bits_per_coded_sample / 4;
 
161
    st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
152
162
 
153
163
    wsaud->audio_stream_index = st->index;
154
164
    wsaud->audio_frame_counter = 0;
160
170
                             AVPacket *pkt)
161
171
{
162
172
    WsAudDemuxContext *wsaud = s->priv_data;
163
 
    ByteIOContext *pb = &s->pb;
 
173
    ByteIOContext *pb = s->pb;
164
174
    unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
165
175
    unsigned int chunk_size;
166
176
    int ret = 0;
187
197
    return ret;
188
198
}
189
199
 
190
 
static int wsaud_read_close(AVFormatContext *s)
191
 
{
192
 
//    WsAudDemuxContext *wsaud = s->priv_data;
193
 
 
194
 
    return 0;
195
 
}
196
 
 
197
 
 
198
200
static int wsvqa_probe(AVProbeData *p)
199
201
{
200
202
    /* need 12 bytes to qualify */
213
215
                             AVFormatParameters *ap)
214
216
{
215
217
    WsVqaDemuxContext *wsvqa = s->priv_data;
216
 
    ByteIOContext *pb = &s->pb;
 
218
    ByteIOContext *pb = s->pb;
217
219
    AVStream *st;
218
220
    unsigned char *header;
219
221
    unsigned char scratch[VQA_PREAMBLE_SIZE];
263
265
        st->codec->channels = header[26];
264
266
        if (!st->codec->channels)
265
267
            st->codec->channels = 1;
266
 
        st->codec->bits_per_sample = 16;
 
268
        st->codec->bits_per_coded_sample = 16;
267
269
        st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
268
 
            st->codec->bits_per_sample / 4;
269
 
        st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
 
270
            st->codec->bits_per_coded_sample / 4;
 
271
        st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
270
272
 
271
273
        wsvqa->audio_stream_index = st->index;
272
274
        wsvqa->audio_samplerate = st->codec->sample_rate;
315
317
                             AVPacket *pkt)
316
318
{
317
319
    WsVqaDemuxContext *wsvqa = s->priv_data;
318
 
    ByteIOContext *pb = &s->pb;
 
320
    ByteIOContext *pb = s->pb;
319
321
    int ret = -1;
320
322
    unsigned char preamble[VQA_PREAMBLE_SIZE];
321
323
    unsigned int chunk_type;
369
371
    return ret;
370
372
}
371
373
 
372
 
static int wsvqa_read_close(AVFormatContext *s)
373
 
{
374
 
//    WsVqaDemuxContext *wsvqa = s->priv_data;
375
 
 
376
 
    return 0;
377
 
}
378
 
 
379
 
#ifdef CONFIG_WSAUD_DEMUXER
 
374
#if CONFIG_WSAUD_DEMUXER
380
375
AVInputFormat wsaud_demuxer = {
381
376
    "wsaud",
382
 
    "Westwood Studios audio format",
 
377
    NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
383
378
    sizeof(WsAudDemuxContext),
384
379
    wsaud_probe,
385
380
    wsaud_read_header,
386
381
    wsaud_read_packet,
387
 
    wsaud_read_close,
388
382
};
389
383
#endif
390
 
#ifdef CONFIG_WSVQA_DEMUXER
 
384
#if CONFIG_WSVQA_DEMUXER
391
385
AVInputFormat wsvqa_demuxer = {
392
386
    "wsvqa",
393
 
    "Westwood Studios VQA format",
 
387
    NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
394
388
    sizeof(WsVqaDemuxContext),
395
389
    wsvqa_probe,
396
390
    wsvqa_read_header,
397
391
    wsvqa_read_packet,
398
 
    wsvqa_read_close,
399
392
};
400
393
#endif