annotate westwood.c @ 4229:765fe37ec45b libavformat

support h264 extradata with 0x000001 startcode
author bcoudurier
date Fri, 16 Jan 2009 01:26:52 +0000
parents c3102b189cb6
children 49c1d3b27727
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
1 /*
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
2 * Westwood Studios Multimedia Formats Demuxer (VQA, AUD)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
3 * Copyright (c) 2003 The ffmpeg Project
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
15 * Lesser General Public License for more details.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
16 *
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
20 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
21
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
22 /**
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
23 * @file westwood.c
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
24 * Westwood Studios VQA & AUD file demuxers
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
25 * by Mike Melanson (melanson@pcisys.net)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
26 * for more information on the Westwood file formats, visit:
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
27 * http://www.pcisys.net/~melanson/codecs/
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
28 * http://www.geocities.com/SiliconValley/8682/aud3.txt
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
29 *
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
30 * Implementation note: There is no definite file signature for AUD files.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
31 * The demuxer uses a probabilistic strategy for content detection. This
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
32 * entails performing sanity checks on certain header values in order to
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
33 * qualify a file. Refer to wsaud_probe() for the precise parameters.
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
34 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
35
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_VIDEO_PTS_INC (90000 / VQA_FRAMERATE)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
64 #define VQA_PREAMBLE_SIZE 8
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
65
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
66 typedef struct WsAudDemuxContext {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
67 int audio_samplerate;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
68 int audio_channels;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
69 int audio_bits;
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
70 enum CodecID audio_type;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
71 int audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
72 int64_t audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
73 } WsAudDemuxContext;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
74
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
75 typedef struct WsVqaDemuxContext {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
76 int audio_samplerate;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
77 int audio_channels;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
78 int audio_bits;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
79
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
80 int audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
81 int video_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
82
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
83 int64_t audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
84 int64_t video_pts;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
85 } WsVqaDemuxContext;
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 static int wsaud_probe(AVProbeData *p)
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 int field;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
90
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
91 /* 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
92 * 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
93 * 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
94 * 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
95 * 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
96 * 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
97 * 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
98 * 320008 acceptable number combinations.
266
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
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
101 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
102 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
103
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
104 /* check sample rate */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
105 field = AV_RL16(&p->buf[0]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
106 if ((field < 8000) || (field > 48000))
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
107 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
108
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
109 /* 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
110 * 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
111 if (p->buf[10] & 0xFC)
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
112 return 0;
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
113
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
114 /* 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
115 * support for type 1 */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
116 if (p->buf[11] != 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
117 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
118
3232
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
119 /* 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
120 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
121 return 0;
12f41a1f8afc Tighten up the Westwood AUD detection. Probability of random detections
melanson
parents: 2771
diff changeset
122
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
123 /* 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
124 return AVPROBE_SCORE_MAX / 2;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
125 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
126
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
127 static int wsaud_read_header(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
128 AVFormatParameters *ap)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
129 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
130 WsAudDemuxContext *wsaud = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
131 ByteIOContext *pb = s->pb;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
132 AVStream *st;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
133 unsigned char header[AUD_HEADER_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
134
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
135 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
136 return AVERROR(EIO);
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
137 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
138 if (header[11] == 99)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
139 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
140 else
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
141 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
142
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
143 /* flag 0 indicates stereo */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
144 wsaud->audio_channels = (header[10] & 0x1) + 1;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
145 /* flag 1 indicates 16 bit audio */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
146 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
147
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
148 /* initialize the audio decoder stream */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
149 st = av_new_stream(s, 0);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
150 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
151 return AVERROR(ENOMEM);
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 386
diff changeset
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
163 wsaud->audio_stream_index = st->index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
164 wsaud->audio_frame_counter = 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 return 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
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
169 static int wsaud_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
170 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
171 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
172 WsAudDemuxContext *wsaud = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
173 ByteIOContext *pb = s->pb;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
174 unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
175 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
176 int ret = 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
177
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
178 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
179 AUD_CHUNK_PREAMBLE_SIZE)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
180 return AVERROR(EIO);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
181
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
182 /* validate the chunk */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
183 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
184 return AVERROR_INVALIDDATA;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
185
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
186 chunk_size = AV_RL16(&preamble[0]);
775
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
187 ret= av_get_packet(pb, pkt, chunk_size);
c5077fdab490 AVPacket.pos
michael
parents: 482
diff changeset
188 if (ret != chunk_size)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
189 return AVERROR(EIO);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
190 pkt->stream_index = wsaud->audio_stream_index;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
191 pkt->pts = wsaud->audio_frame_counter;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
192 pkt->pts /= wsaud->audio_samplerate;
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 /* 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
195 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
196
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
197 return ret;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
198 }
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 static int wsvqa_probe(AVProbeData *p)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
201 {
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
202 /* need 12 bytes to qualify */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
203 if (p->buf_size < 12)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
204 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
205
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
206 /* 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
207 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
208 (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
209 return 0;
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 return AVPROBE_SCORE_MAX;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
212 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
213
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
214 static int wsvqa_read_header(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
215 AVFormatParameters *ap)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
216 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
217 WsVqaDemuxContext *wsvqa = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
218 ByteIOContext *pb = s->pb;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
219 AVStream *st;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
220 unsigned char *header;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
221 unsigned char scratch[VQA_PREAMBLE_SIZE];
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
222 unsigned int chunk_tag;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
223 unsigned int chunk_size;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
224
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
225 /* initialize the video decoder stream */
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
226 st = av_new_stream(s, 0);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
227 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
228 return AVERROR(ENOMEM);
1550
4cb185273d4b Do not touch pkt->pts
kostya
parents: 1549
diff changeset
229 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
230 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
231 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
232 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
233 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
234
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
235 /* 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
236 url_fseek(pb, 20, SEEK_SET);
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
237
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
238 /* 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
239 st->codec->extradata_size = VQA_HEADER_SIZE;
884
2ece9c9dd94c malloc padding to avoid reading past the malloc()ed area.
henry
parents: 820
diff changeset
240 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
241 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
242 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
243 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
244 av_free(st->codec->extradata);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
245 return AVERROR(EIO);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
246 }
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
247 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
248 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
249
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
250 /* 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
251 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
252 st = av_new_stream(s, 0);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
253 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
254 return AVERROR(ENOMEM);
1550
4cb185273d4b Do not touch pkt->pts
kostya
parents: 1549
diff changeset
255 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
256 st->codec->codec_type = CODEC_TYPE_AUDIO;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
257 if (AV_RL16(&header[0]) == 1)
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
258 st->codec->codec_id = CODEC_ID_WESTWOOD_SND1;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
259 else
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
260 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
261 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
262 st->codec->sample_rate = AV_RL16(&header[24]);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
263 if (!st->codec->sample_rate)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
264 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
265 st->codec->channels = header[26];
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
266 if (!st->codec->channels)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
267 st->codec->channels = 1;
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 = 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
269 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
270 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
271 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
272
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
273 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
274 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
275 wsvqa->audio_channels = st->codec->channels;
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
276 wsvqa->audio_frame_counter = 0;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
277 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
278
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
279 /* 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
280 * 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
281 do {
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
282 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
283 av_free(st->codec->extradata);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
284 return AVERROR(EIO);
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
285 }
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1550
diff changeset
286 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
287 chunk_size = AV_RB32(&scratch[4]);
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
288
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
289 /* catch any unknown header tags, for curiousity */
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
290 switch (chunk_tag) {
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
291 case CINF_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
292 case CINH_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
293 case CIND_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
294 case PINF_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
295 case PINH_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
296 case PIND_TAG:
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
297 case FINF_TAG:
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
298 case CMDS_TAG:
275
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
299 break;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
300
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
301 default:
370
845f9de2c883 av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 275
diff changeset
302 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
303 scratch[0], scratch[1],
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
304 scratch[2], scratch[3]);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
305 break;
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
306 }
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
307
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
308 url_fseek(pb, chunk_size, SEEK_CUR);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
309 } while (chunk_tag != FINF_TAG);
377bd276adaa handle a wider variety of VQA files, including silent files
tmmm
parents: 266
diff changeset
310
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
311 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
312
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
313 return 0;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
314 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
315
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
316 static int wsvqa_read_packet(AVFormatContext *s,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
317 AVPacket *pkt)
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
318 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 1673
diff changeset
319 WsVqaDemuxContext *wsvqa = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
320 ByteIOContext *pb = s->pb;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
321 int ret = -1;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
322 unsigned char preamble[VQA_PREAMBLE_SIZE];
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
323 unsigned int chunk_type;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
324 unsigned int chunk_size;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
325 int skip_byte;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
326
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
327 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
328 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
329 chunk_size = AV_RB32(&preamble[4]);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
330 skip_byte = chunk_size & 0x01;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
331
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
332 if ((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
333
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
334 if (av_new_packet(pkt, chunk_size))
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 ret = get_buffer(pb, pkt->data, chunk_size);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
337 if (ret != chunk_size) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
338 av_free_packet(pkt);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
339 return AVERROR(EIO);
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
340 }
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
341
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
342 if (chunk_type == SND2_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 /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
345 wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
346 } else if(chunk_type == SND1_TAG) {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
347 pkt->stream_index = wsvqa->audio_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
348 /* 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
349 wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels;
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
350 } else {
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
351 pkt->stream_index = wsvqa->video_stream_index;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
352 wsvqa->video_pts += VQA_VIDEO_PTS_INC;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
353 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
354 /* stay on 16-bit alignment */
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
355 if (skip_byte)
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
356 url_fseek(pb, 1, SEEK_CUR);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
357
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
358 return ret;
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
359 } else {
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
360 switch(chunk_type){
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
361 case CMDS_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
362 case SND0_TAG:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
363 break;
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
364 default:
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
365 av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type);
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
366 }
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
367 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
368 }
1545
8811d543732e Better VQA demuxer
kostya
parents: 1358
diff changeset
369 }
266
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 return ret;
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
372 }
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
373
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
374 #if CONFIG_WSAUD_DEMUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
375 AVInputFormat wsaud_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
376 "wsaud",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3232
diff changeset
377 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
378 sizeof(WsAudDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
379 wsaud_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
380 wsaud_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
381 wsaud_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
382 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
383 #endif
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
384 #if CONFIG_WSVQA_DEMUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
385 AVInputFormat wsvqa_demuxer = {
266
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
386 "wsvqa",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3232
diff changeset
387 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
388 sizeof(WsVqaDemuxContext),
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
389 wsvqa_probe,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
390 wsvqa_read_header,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
391 wsvqa_read_packet,
8bb470d85249 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
392 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
393 #endif