Mercurial > libavformat.hg
annotate westwood.c @ 3206:55b18342ca1e libavformat
non-recursive makefiles
author | mru |
---|---|
date | Mon, 07 Apr 2008 21:16:31 +0000 |
parents | d52c718e83f9 |
children | 12f41a1f8afc |
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 | 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 | 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 | 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 | 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 { |
2006 | 120 WsAudDemuxContext *wsaud = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
121 ByteIOContext *pb = s->pb; |
266
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) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
126 return AVERROR(EIO); |
1673 | 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) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
141 return AVERROR(ENOMEM); |
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 { |
2006 | 162 WsAudDemuxContext *wsaud = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
163 ByteIOContext *pb = s->pb; |
266
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) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
170 return AVERROR(EIO); |
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 | 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 | 176 chunk_size = AV_RL16(&preamble[0]); |
775 | 177 ret= av_get_packet(pb, pkt, chunk_size); |
178 if (ret != chunk_size) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
179 return AVERROR(EIO); |
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 { |
2006 | 192 // WsAudDemuxContext *wsaud = s->priv_data; |
266
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 | 205 if ((AV_RB32(&p->buf[0]) != FORM_TAG) || |
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 { |
2006 | 215 WsVqaDemuxContext *wsvqa = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
216 ByteIOContext *pb = s->pb; |
266
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) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
226 return AVERROR(ENOMEM); |
1550 | 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); |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
243 return AVERROR(EIO); |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
244 } |
1673 | 245 st->codec->width = AV_RL16(&header[6]); |
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 | 248 /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */ |
1673 | 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) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
252 return AVERROR(ENOMEM); |
1550 | 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 | 255 if (AV_RL16(&header[0]) == 1) |
1545 | 256 st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; |
257 else | |
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 | 260 st->codec->sample_rate = AV_RL16(&header[24]); |
1545 | 261 if (!st->codec->sample_rate) |
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 | 264 if (!st->codec->channels) |
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); |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
282 return AVERROR(EIO); |
275
377bd276adaa
handle a wider variety of VQA files, including silent files
tmmm
parents:
266
diff
changeset
|
283 } |
1673 | 284 chunk_tag = AV_RB32(&scratch[0]); |
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 | 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 { |
2006 | 317 WsVqaDemuxContext *wsvqa = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
318 ByteIOContext *pb = s->pb; |
1545 | 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 | 325 while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) { |
1673 | 326 chunk_type = AV_RB32(&preamble[0]); |
327 chunk_size = AV_RB32(&preamble[4]); | |
1545 | 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 | 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 | 332 if (av_new_packet(pkt, chunk_size)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
333 return AVERROR(EIO); |
1545 | 334 ret = get_buffer(pb, pkt->data, chunk_size); |
335 if (ret != chunk_size) { | |
336 av_free_packet(pkt); | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
337 return AVERROR(EIO); |
1545 | 338 } |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
339 |
1545 | 340 if (chunk_type == SND2_TAG) { |
341 pkt->stream_index = wsvqa->audio_stream_index; | |
342 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ | |
343 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels; | |
344 } else if(chunk_type == SND1_TAG) { | |
345 pkt->stream_index = wsvqa->audio_stream_index; | |
346 /* unpacked size is stored in header */ | |
1673 | 347 wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels; |
1545 | 348 } else { |
349 pkt->stream_index = wsvqa->video_stream_index; | |
350 wsvqa->video_pts += VQA_VIDEO_PTS_INC; | |
351 } | |
352 /* stay on 16-bit alignment */ | |
353 if (skip_byte) | |
354 url_fseek(pb, 1, SEEK_CUR); | |
355 | |
356 return ret; | |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
357 } else { |
1545 | 358 switch(chunk_type){ |
359 case CMDS_TAG: | |
360 case SND0_TAG: | |
361 break; | |
362 default: | |
363 av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type); | |
364 } | |
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 | 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 { |
2006 | 374 // WsVqaDemuxContext *wsvqa = s->priv_data; |
266
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 | 379 #ifdef CONFIG_WSAUD_DEMUXER |
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 | 389 #endif |
390 #ifdef CONFIG_WSVQA_DEMUXER | |
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 | 400 #endif |