annotate westwood.c @ 1425:00d9393a126f libavformat

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