Revision 20f269dc

View differences:

libavformat/westwood.c
61 61
#define SND2_TAG FOURCC_TAG('S', 'N', 'D', '2')
62 62
#define VQFR_TAG FOURCC_TAG('V', 'Q', 'F', 'R')
63 63

  
64
/* don't know what these tags are for, but acknowledge their existence */
65
#define CINF_TAG FOURCC_TAG('C', 'I', 'N', 'F')
66
#define CINH_TAG FOURCC_TAG('C', 'I', 'N', 'H')
67
#define CIND_TAG FOURCC_TAG('C', 'I', 'N', 'D')
68
#define PINF_TAG FOURCC_TAG('P', 'I', 'N', 'F')
69
#define PINH_TAG FOURCC_TAG('P', 'I', 'N', 'H')
70
#define PIND_TAG FOURCC_TAG('P', 'I', 'N', 'D')
71

  
64 72
#define VQA_HEADER_SIZE 0x2A
65 73
#define VQA_FRAMERATE 15
66 74
#define VQA_VIDEO_PTS_INC (90000 / VQA_FRAMERATE)
......
227 235
    AVStream *st;
228 236
    unsigned char *header;
229 237
    unsigned char scratch[VQA_PREAMBLE_SIZE];
238
    unsigned int chunk_tag;
239
    unsigned int chunk_size;
230 240

  
231 241
    /* set the pts reference (1 pts = 1/90000) */
232 242
    s->pts_num = 1;
......
256 266
    st->codec.width = LE_16(&header[6]);
257 267
    st->codec.height = LE_16(&header[8]);
258 268

  
259
    /* initialize the audio decoder stream */
260
    st = av_new_stream(s, 0);
261
    if (!st)
262
        return AVERROR_NOMEM;
263
    st->codec.codec_type = CODEC_TYPE_AUDIO;
264
    st->codec.codec_id = CODEC_ID_ADPCM_IMA_WS;
265
    st->codec.codec_tag = 0;  /* no tag */
266
    st->codec.sample_rate = LE_16(&header[24]);
267
    st->codec.channels = header[26];
268
    st->codec.bits_per_sample = 16;
269
    st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
270
        st->codec.bits_per_sample / 4;
271
    st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
269
    /* initialize the audio decoder stream is sample rate is non-zero */
270
    if (LE_16(&header[24])) {
271
        st = av_new_stream(s, 0);
272
        if (!st)
273
            return AVERROR_NOMEM;
274
        st->codec.codec_type = CODEC_TYPE_AUDIO;
275
        st->codec.codec_id = CODEC_ID_ADPCM_IMA_WS;
276
        st->codec.codec_tag = 0;  /* no tag */
277
        st->codec.sample_rate = LE_16(&header[24]);
278
        st->codec.channels = header[26];
279
        st->codec.bits_per_sample = 16;
280
        st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
281
            st->codec.bits_per_sample / 4;
282
        st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
283

  
284
        wsvqa->audio_stream_index = st->index;
285
        wsvqa->audio_samplerate = st->codec.sample_rate;
286
        wsvqa->audio_channels = st->codec.channels;
287
        wsvqa->audio_frame_counter = 0;
288
    }
272 289

  
273
    wsvqa->audio_stream_index = st->index;
274
    wsvqa->audio_samplerate = st->codec.sample_rate;
275
    wsvqa->audio_channels = st->codec.channels;
276
    wsvqa->audio_frame_counter = 0;
290
    /* there are 0 or more chunks before the FINF chunk; iterate until
291
     * FINF has been skipped and the file will be ready to be demuxed */
292
    do {
293
        if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
294
            av_free(st->codec.extradata);
295
            return -EIO;
296
        }
297
        chunk_tag = BE_32(&scratch[0]);
298
        chunk_size = BE_32(&scratch[4]);
299

  
300
        /* catch any unknown header tags, for curiousity */
301
        switch (chunk_tag) {
302
        case CINF_TAG:
303
        case CINH_TAG:
304
        case CIND_TAG:
305
        case PINF_TAG:
306
        case PINH_TAG:
307
        case PIND_TAG:
308
        case FINF_TAG:
309
            break;
310

  
311
        default:
312
            printf (" note: unknown chunk seen (%c%c%c%c)\n",
313
                scratch[0], scratch[1],
314
                scratch[2], scratch[3]);
315
            break;
316
        }
317

  
318
        url_fseek(pb, chunk_size, SEEK_CUR);
319
    } while (chunk_tag != FINF_TAG);
277 320

  
278
    /* skip the useless FINF chunk index */
279
    if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
280
        av_free(st->codec.extradata);
281
        return -EIO;
282
    }
283
    url_fseek(pb, BE_32(&scratch[4]), SEEK_CUR);
284 321
    wsvqa->video_pts = wsvqa->audio_frame_counter = 0;
285 322

  
286 323
    return 0;

Also available in: Unified diff