annotate westwood.c @ 6128:c34ed49b26c6 libavformat

output-example: Set sample_fmt to SAMPLE_FMT_S16.
author ramiro
date Mon, 14 Jun 2010 07:05:59 +0000
parents 178de7695c6c
children
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 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5910
diff changeset
23 * @file
266
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
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3967
diff changeset
36 #include "libavutil/intreadwrite.h"
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
37 #include "avformat.h"
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
38
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
39 #define AUD_HEADER_SIZE 12
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
40 #define AUD_CHUNK_PREAMBLE_SIZE 8
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
41 #define AUD_CHUNK_SIGNATURE 0x0000DEAF
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
42
386
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
43 #define FORM_TAG MKBETAG('F', 'O', 'R', 'M')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
44 #define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
45 #define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
46 #define FINF_TAG MKBETAG('F', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
47 #define SND0_TAG MKBETAG('S', 'N', 'D', '0')
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
48 #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
49 #define SND2_TAG MKBETAG('S', 'N', 'D', '2')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
50 #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
51
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
52 /* 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
53 #define CINF_TAG MKBETAG('C', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
54 #define CINH_TAG MKBETAG('C', 'I', 'N', 'H')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
55 #define CIND_TAG MKBETAG('C', 'I', 'N', 'D')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
56 #define PINF_TAG MKBETAG('P', 'I', 'N', 'F')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
57 #define PINH_TAG MKBETAG('P', 'I', 'N', 'H')
c152849ee643 remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents: 370
diff changeset
58 #define PIND_TAG MKBETAG('P', 'I', 'N', 'D')
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
59 #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
60
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
61 #define VQA_HEADER_SIZE 0x2A
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
62 #define VQA_FRAMERATE 15
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;
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
69 enum CodecID audio_type;
266
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 } WsVqaDemuxContext;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
84
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
85 static int wsaud_probe(AVProbeData *p)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
86 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
87 int field;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
88
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
89 /* 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
90 * 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
91 * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
92 * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers
266
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
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
94 * first audio chunk signature (32 bits) ==> 1 acceptable number
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
95 * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 =
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
96 * 320008 acceptable number combinations.
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
97 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
98
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
99 if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE)
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
100 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
101
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
102 /* check sample rate */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
103 field = AV_RL16(&p->buf[0]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
104 if ((field < 8000) || (field > 48000))
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
105 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
106
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
107 /* enforce the rule that the top 6 bits of this flags field are reserved (0);
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
108 * this might not be true, but enforce it until deemed unnecessary */
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
109 if (p->buf[10] & 0xFC)
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
110 return 0;
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
111
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
112 /* 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
113 * support for type 1 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
114 if (p->buf[11] != 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
115 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
116
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
117 /* read ahead to the first audio chunk and validate the first header signature */
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
118 if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE)
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
119 return 0;
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
120
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
121 /* 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
122 return AVPROBE_SCORE_MAX / 2;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
123 }
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 static int wsaud_read_header(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
126 AVFormatParameters *ap)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
127 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
128 WsAudDemuxContext *wsaud = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
129 ByteIOContext *pb = s->pb;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
130 AVStream *st;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
131 unsigned char header[AUD_HEADER_SIZE];
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 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
134 return AVERROR(EIO);
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
135 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
136 if (header[11] == 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
137 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
138 else
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
139 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
140
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
141 /* flag 0 indicates stereo */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
142 wsaud->audio_channels = (header[10] & 0x1) + 1;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
143 /* flag 1 indicates 16 bit audio */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
144 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
145
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
146 /* initialize the audio decoder stream */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
147 st = av_new_stream(s, 0);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
148 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
149 return AVERROR(ENOMEM);
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
150 av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4880
diff changeset
151 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
152 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
153 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
154 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
155 st->codec->sample_rate = wsaud->audio_samplerate;
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
156 st->codec->bits_per_coded_sample = wsaud->audio_bits;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
157 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
158 st->codec->bits_per_coded_sample / 4;
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
159 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
160
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
161 wsaud->audio_stream_index = st->index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
162 wsaud->audio_frame_counter = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
163
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
164 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
165 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
166
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
167 static int wsaud_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
168 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
169 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
170 WsAudDemuxContext *wsaud = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
171 ByteIOContext *pb = s->pb;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
172 unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
173 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
174 int ret = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
175
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
176 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
177 AUD_CHUNK_PREAMBLE_SIZE)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
178 return AVERROR(EIO);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
179
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
180 /* validate the chunk */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
181 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
182 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
183
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
184 chunk_size = AV_RL16(&preamble[0]);
775
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
185 ret= av_get_packet(pb, pkt, chunk_size);
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
186 if (ret != chunk_size)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
187 return AVERROR(EIO);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
188 pkt->stream_index = wsaud->audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
189 pkt->pts = wsaud->audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
190 pkt->pts /= wsaud->audio_samplerate;
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 /* 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
193 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
194
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
195 return ret;
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 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
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
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;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4880
diff changeset
229 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
820
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
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)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
252 return AVERROR(ENOMEM);
1550
4cb185273d4b Do not touch pkt->pts
kostya
parents: 1549
diff changeset
253 av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4880
diff changeset
254 st->codec->codec_type = AVMEDIA_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;
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
266 st->codec->bits_per_coded_sample = 16;
820
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 *
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
268 st->codec->bits_per_coded_sample / 4;
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3484
diff changeset
269 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_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
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 return 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
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
312 static int wsvqa_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
313 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
314 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
315 WsVqaDemuxContext *wsvqa = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
316 ByteIOContext *pb = s->pb;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
317 int ret = -1;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
318 unsigned char preamble[VQA_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
319 unsigned int chunk_type;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
320 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
321 int skip_byte;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
322
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
323 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
324 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
325 chunk_size = AV_RB32(&preamble[4]);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
326 skip_byte = chunk_size & 0x01;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
327
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
328 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
329
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
330 if (av_new_packet(pkt, chunk_size))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
331 return AVERROR(EIO);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
332 ret = get_buffer(pb, pkt->data, chunk_size);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
333 if (ret != chunk_size) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
334 av_free_packet(pkt);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
335 return AVERROR(EIO);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
336 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
337
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
338 if (chunk_type == SND2_TAG) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
339 pkt->stream_index = wsvqa->audio_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
340 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
341 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
342 } else if(chunk_type == SND1_TAG) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
343 pkt->stream_index = wsvqa->audio_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
344 /* 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
345 wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
346 } else {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
347 pkt->stream_index = wsvqa->video_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
348 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
349 /* stay on 16-bit alignment */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
350 if (skip_byte)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
351 url_fseek(pb, 1, SEEK_CUR);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
352
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
353 return ret;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
354 } else {
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
355 switch(chunk_type){
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
356 case CMDS_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
357 case SND0_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
358 break;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
359 default:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
360 av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
361 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
362 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
363 }
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
364 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
365
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
366 return ret;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
367 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
368
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
369 #if CONFIG_WSAUD_DEMUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
370 AVInputFormat wsaud_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
371 "wsaud",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3232
diff changeset
372 NULL_IF_CONFIG_SMALL("Westwood Studios audio format"),
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
373 sizeof(WsAudDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
374 wsaud_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
375 wsaud_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
376 wsaud_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
377 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
378 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
379 #if CONFIG_WSVQA_DEMUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
380 AVInputFormat wsvqa_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
381 "wsvqa",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3232
diff changeset
382 NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"),
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
383 sizeof(WsVqaDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
384 wsvqa_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
385 wsvqa_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
386 wsvqa_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
387 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
388 #endif