annotate westwood.c @ 1680:9240521ca4fd libavformat

this is wrong but it was that way before the AVCodecTag change, only reason why it didnt broke regressions was that the table wasnt used
author michael
date Sun, 21 Jan 2007 12:30:44 +0000
parents a782462e2497
children 2f0154760e5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
1 /*
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
2 * Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
3 * Copyright (c) 2003 The ffmpeg Project
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
15 * Lesser General Public License for more details.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
16 *
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
20 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
21
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
22 /**
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
23 * @file westwood.c
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
24 * Westwood Studios VQA & AUD file demuxers
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
25 * by Mike Melanson (melanson@pcisys.net)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
26 * for more information on the Westwood file formats, visit:
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
27 * http://www.pcisys.net/~melanson/codecs/
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
28 * http://www.geocities.com/SiliconValley/8682/aud3.txt
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
29 *
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
30 * Implementation note: There is no definite file signature for AUD files.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
31 * The demuxer uses a probabilistic strategy for content detection. This
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
32 * entails performing sanity checks on certain header values in order to
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
33 * qualify a file. Refer to wsaud_probe() for the precise parameters.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
34 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
35
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
36 #include "avformat.h"
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
37
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
38 #define AUD_HEADER_SIZE 12
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
39 #define AUD_CHUNK_PREAMBLE_SIZE 8
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
40 #define AUD_CHUNK_SIGNATURE 0x0000DEAF
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
41
386
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
42 #define FORM_TAG MKBETAG('F', 'O', 'R', 'M')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
43 #define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
44 #define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
45 #define FINF_TAG MKBETAG('F', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
46 #define SND0_TAG MKBETAG('S', 'N', 'D', '0')
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
47 #define SND1_TAG MKBETAG('S', 'N', 'D', '1')
386
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
48 #define SND2_TAG MKBETAG('S', 'N', 'D', '2')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
49 #define VQFR_TAG MKBETAG('V', 'Q', 'F', 'R')
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
50
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
51 /* don't know what these tags are for, but acknowledge their existence */
386
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
52 #define CINF_TAG MKBETAG('C', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
53 #define CINH_TAG MKBETAG('C', 'I', 'N', 'H')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
54 #define CIND_TAG MKBETAG('C', 'I', 'N', 'D')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
55 #define PINF_TAG MKBETAG('P', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
56 #define PINH_TAG MKBETAG('P', 'I', 'N', 'H')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
57 #define PIND_TAG MKBETAG('P', 'I', 'N', 'D')
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
58 #define CMDS_TAG MKBETAG('C', 'M', 'D', 'S')
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
59
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
60 #define VQA_HEADER_SIZE 0x2A
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
61 #define VQA_FRAMERATE 15
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
62 #define VQA_VIDEO_PTS_INC (90000 / VQA_FRAMERATE)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
63 #define VQA_PREAMBLE_SIZE 8
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
64
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
65 typedef struct WsAudDemuxContext {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
66 int audio_samplerate;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
67 int audio_channels;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
68 int audio_bits;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
69 int audio_type;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
70 int audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
71 int64_t audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
72 } WsAudDemuxContext;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
73
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
74 typedef struct WsVqaDemuxContext {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
75 int audio_samplerate;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
76 int audio_channels;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
77 int audio_bits;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
78
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
79 int audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
80 int video_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
81
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
82 int64_t audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
83 int64_t video_pts;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
84 } WsVqaDemuxContext;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
85
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
86 static int wsaud_probe(AVProbeData *p)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
87 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
88 int field;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
89
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
90 /* Probabilistic content detection strategy: There is no file signature
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
91 * so perform sanity checks on various header parameters:
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
92 * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
93 * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
94 * There is a total of 24 bits. The number space contains 2^24 =
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
95 * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
96 * of numbers. There is a 80002/16777216 = 0.48% chance of a false
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
97 * positive.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
98 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
99
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
100 if (p->buf_size < AUD_HEADER_SIZE)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
101 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
102
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
103 /* check sample rate */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
104 field = AV_RL16(&p->buf[0]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
105 if ((field < 8000) || (field > 48000))
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
106 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
107
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
108 /* note: only check for WS IMA (type 99) right now since there is no
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
109 * support for type 1 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
110 if (p->buf[11] != 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
111 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
112
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
113 /* return 1/2 certainty since this file check is a little sketchy */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
114 return AVPROBE_SCORE_MAX / 2;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
115 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
116
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
117 static int wsaud_read_header(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
118 AVFormatParameters *ap)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
119 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
120 WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
121 ByteIOContext *pb = &s->pb;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
122 AVStream *st;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
123 unsigned char header[AUD_HEADER_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
124
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
125 if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
126 return AVERROR_IO;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
127 wsaud->audio_samplerate = AV_RL16(&header[0]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
128 if (header[11] == 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
129 wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
130 else
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
131 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
132
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
133 /* flag 0 indicates stereo */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
134 wsaud->audio_channels = (header[10] & 0x1) + 1;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
135 /* flag 1 indicates 16 bit audio */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
136 wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
137
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
138 /* initialize the audio decoder stream */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
139 st = av_new_stream(s, 0);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
140 if (!st)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
141 return AVERROR_NOMEM;
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
142 av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
143 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
144 st->codec->codec_id = wsaud->audio_type;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
145 st->codec->codec_tag = 0; /* no tag */
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
146 st->codec->channels = wsaud->audio_channels;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
147 st->codec->sample_rate = wsaud->audio_samplerate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
148 st->codec->bits_per_sample = wsaud->audio_bits;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
149 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
150 st->codec->bits_per_sample / 4;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
151 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
152
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
153 wsaud->audio_stream_index = st->index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
154 wsaud->audio_frame_counter = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
155
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
156 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
157 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
158
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
159 static int wsaud_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
160 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
161 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
162 WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
163 ByteIOContext *pb = &s->pb;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
164 unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
165 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
166 int ret = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
167
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
168 if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
169 AUD_CHUNK_PREAMBLE_SIZE)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
170 return AVERROR_IO;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
171
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
172 /* validate the chunk */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
173 if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE)
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
174 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
175
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
176 chunk_size = AV_RL16(&preamble[0]);
775
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
177 ret= av_get_packet(pb, pkt, chunk_size);
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
178 if (ret != chunk_size)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
179 return AVERROR_IO;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
180 pkt->stream_index = wsaud->audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
181 pkt->pts = wsaud->audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
182 pkt->pts /= wsaud->audio_samplerate;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
183
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
184 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
185 wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
186
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
187 return ret;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
188 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
189
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
190 static int wsaud_read_close(AVFormatContext *s)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
191 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
192 // WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
193
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
194 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
195 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
196
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
197
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
198 static int wsvqa_probe(AVProbeData *p)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
199 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
200 /* need 12 bytes to qualify */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
201 if (p->buf_size < 12)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
202 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
203
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
204 /* check for the VQA signatures */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
205 if ((AV_RB32(&p->buf[0]) != FORM_TAG) ||
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
206 (AV_RB32(&p->buf[8]) != WVQA_TAG))
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
207 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
208
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
209 return AVPROBE_SCORE_MAX;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
210 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
211
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
212 static int wsvqa_read_header(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
213 AVFormatParameters *ap)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
214 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
215 WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
216 ByteIOContext *pb = &s->pb;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
217 AVStream *st;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
218 unsigned char *header;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
219 unsigned char scratch[VQA_PREAMBLE_SIZE];
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
220 unsigned int chunk_tag;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
221 unsigned int chunk_size;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
222
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
223 /* initialize the video decoder stream */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
224 st = av_new_stream(s, 0);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
225 if (!st)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
226 return AVERROR_NOMEM;
1550
4cb185273d4b Do not touch pkt->pts
kostya
parents: 1549
diff changeset
227 av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
228 wsvqa->video_stream_index = st->index;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
229 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
230 st->codec->codec_id = CODEC_ID_WS_VQA;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
231 st->codec->codec_tag = 0; /* no fourcc */
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
232
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
233 /* skip to the start of the VQA header */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
234 url_fseek(pb, 20, SEEK_SET);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
235
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
236 /* the VQA header needs to go to the decoder */
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
237 st->codec->extradata_size = VQA_HEADER_SIZE;
884
2ece9c9dd94c malloc padding to avoid reading past the malloc()ed area.
henry
parents: 820
diff changeset
238 st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
239 header = (unsigned char *)st->codec->extradata;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
240 if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
241 VQA_HEADER_SIZE) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
242 av_free(st->codec->extradata);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
243 return AVERROR_IO;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
244 }
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
245 st->codec->width = AV_RL16(&header[6]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
246 st->codec->height = AV_RL16(&header[8]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
247
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
248 /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
249 if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
250 st = av_new_stream(s, 0);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
251 if (!st)
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
252 return AVERROR_NOMEM;
1550
4cb185273d4b Do not touch pkt->pts
kostya
parents: 1549
diff changeset
253 av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
254 st->codec->codec_type = CODEC_TYPE_AUDIO;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
255 if (AV_RL16(&header[0]) == 1)
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
256 st->codec->codec_id = CODEC_ID_WESTWOOD_SND1;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
257 else
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
258 st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
259 st->codec->codec_tag = 0; /* no tag */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
260 st->codec->sample_rate = AV_RL16(&header[24]);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
261 if (!st->codec->sample_rate)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
262 st->codec->sample_rate = 22050;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
263 st->codec->channels = header[26];
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
264 if (!st->codec->channels)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
265 st->codec->channels = 1;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
266 st->codec->bits_per_sample = 16;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
267 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
268 st->codec->bits_per_sample / 4;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
269 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
270
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
271 wsvqa->audio_stream_index = st->index;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
272 wsvqa->audio_samplerate = st->codec->sample_rate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
273 wsvqa->audio_channels = st->codec->channels;
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
274 wsvqa->audio_frame_counter = 0;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
275 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
276
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
277 /* there are 0 or more chunks before the FINF chunk; iterate until
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
278 * FINF has been skipped and the file will be ready to be demuxed */
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
279 do {
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
280 if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
281 av_free(st->codec->extradata);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 462
diff changeset
282 return AVERROR_IO;
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
283 }
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
284 chunk_tag = AV_RB32(&scratch[0]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
285 chunk_size = AV_RB32(&scratch[4]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
286
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
287 /* catch any unknown header tags, for curiousity */
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
288 switch (chunk_tag) {
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
289 case CINF_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
290 case CINH_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
291 case CIND_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
292 case PINF_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
293 case PINH_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
294 case PIND_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
295 case FINF_TAG:
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
296 case CMDS_TAG:
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
297 break;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
298
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
299 default:
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 275
diff changeset
300 av_log (s, AV_LOG_ERROR, " note: unknown chunk seen (%c%c%c%c)\n",
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
301 scratch[0], scratch[1],
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
302 scratch[2], scratch[3]);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
303 break;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
304 }
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
305
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
306 url_fseek(pb, chunk_size, SEEK_CUR);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
307 } while (chunk_tag != FINF_TAG);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
308
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
309 wsvqa->video_pts = wsvqa->audio_frame_counter = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
310
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
311 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
312 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
313
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
314 static int wsvqa_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
315 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
316 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
317 WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
318 ByteIOContext *pb = &s->pb;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
319 int ret = -1;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
320 unsigned char preamble[VQA_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
321 unsigned int chunk_type;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
322 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
323 int skip_byte;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
324
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
325 while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) {
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
326 chunk_type = AV_RB32(&preamble[0]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
327 chunk_size = AV_RB32(&preamble[4]);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
328 skip_byte = chunk_size & 0x01;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
329
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
330 if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
331
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
332 if (av_new_packet(pkt, chunk_size))
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
333 return AVERROR_IO;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
334 ret = get_buffer(pb, pkt->data, chunk_size);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
335 if (ret != chunk_size) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
336 av_free_packet(pkt);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
337 return AVERROR_IO;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
338 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
339
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
340 if (chunk_type == SND2_TAG) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
341 pkt->stream_index = wsvqa->audio_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
342 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
343 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
344 } else if(chunk_type == SND1_TAG) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
345 pkt->stream_index = wsvqa->audio_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
346 /* unpacked size is stored in header */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
347 wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
348 } else {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
349 pkt->stream_index = wsvqa->video_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
350 wsvqa->video_pts += VQA_VIDEO_PTS_INC;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
351 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
352 /* stay on 16-bit alignment */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
353 if (skip_byte)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
354 url_fseek(pb, 1, SEEK_CUR);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
355
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
356 return ret;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
357 } else {
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
358 switch(chunk_type){
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
359 case CMDS_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
360 case SND0_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
361 break;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
362 default:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
363 av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
364 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
365 url_fseek(pb, chunk_size + skip_byte, SEEK_CUR);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
366 }
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
367 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
368
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
369 return ret;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
370 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
371
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
372 static int wsvqa_read_close(AVFormatContext *s)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
373 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
374 // WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
375
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
376 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
377 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
378
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
379 #ifdef CONFIG_WSAUD_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
380 AVInputFormat wsaud_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
381 "wsaud",
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
382 "Westwood Studios audio format",
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
383 sizeof(WsAudDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
384 wsaud_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
385 wsaud_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
386 wsaud_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
387 wsaud_read_close,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
388 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
389 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
390 #ifdef CONFIG_WSVQA_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
391 AVInputFormat wsvqa_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
392 "wsvqa",
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
393 "Westwood Studios VQA format",
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
394 sizeof(WsVqaDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
395 wsvqa_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
396 wsvqa_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
397 wsvqa_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
398 wsvqa_read_close,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
399 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
400 #endif