Mercurial > libavformat.hg
annotate segafilm.c @ 1324:024cf76ac4d1 libavformat
WavPack lossless audio decoder
author | kostya |
---|---|
date | Tue, 26 Sep 2006 03:41:51 +0000 |
parents | d18cc9a1fd02 |
children | 0899bfe4105c |
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 * Sega FILM Format (CPK) Demuxer |
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 * |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
6 * 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
|
7 * License as published by the Free Software Foundation; either |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
9 * |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * Lesser General Public License for more details. |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
14 * |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
17 * 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
|
18 */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
19 |
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 * @file segafilm.c |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
22 * Sega FILM (.cpk) file demuxer |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
23 * by Mike Melanson (melanson@pcisys.net) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
24 * For more information regarding the Sega FILM file format, visit: |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
25 * http://www.pcisys.net/~melanson/codecs/ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
26 */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
27 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
28 #include "avformat.h" |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
29 |
386
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
268
diff
changeset
|
30 #define FILM_TAG MKBETAG('F', 'I', 'L', 'M') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
268
diff
changeset
|
31 #define FDSC_TAG MKBETAG('F', 'D', 'S', 'C') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
268
diff
changeset
|
32 #define STAB_TAG MKBETAG('S', 'T', 'A', 'B') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
268
diff
changeset
|
33 #define CVID_TAG MKBETAG('c', 'v', 'i', 'd') |
266
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 typedef struct { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
36 int stream; |
268 | 37 offset_t sample_offset; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
38 unsigned int sample_size; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
39 int64_t pts; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
40 int keyframe; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
41 } film_sample_t; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
42 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
43 typedef struct FilmDemuxContext { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
44 int video_stream_index; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
45 int audio_stream_index; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
46 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
47 unsigned int audio_type; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
48 unsigned int audio_samplerate; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
49 unsigned int audio_bits; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
50 unsigned int audio_channels; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
51 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
52 unsigned int video_type; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
53 unsigned int sample_count; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
54 film_sample_t *sample_table; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
55 unsigned int current_sample; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
56 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
57 unsigned int base_clock; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
58 unsigned int version; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
59 int cvid_extra_bytes; /* the number of bytes thrown into the Cinepak |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
60 * chunk header to throw off decoders */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
61 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
62 /* buffer used for interleaving stereo PCM data */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
63 unsigned char *stereo_buffer; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
64 int stereo_buffer_size; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
65 } FilmDemuxContext; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
66 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
67 static int film_probe(AVProbeData *p) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
68 { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
69 if (p->buf_size < 4) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
70 return 0; |
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 if (BE_32(&p->buf[0]) != FILM_TAG) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
73 return 0; |
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 return AVPROBE_SCORE_MAX; |
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 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
78 static int film_read_header(AVFormatContext *s, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
79 AVFormatParameters *ap) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
80 { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
81 FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
82 ByteIOContext *pb = &s->pb; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
83 AVStream *st; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
84 unsigned char scratch[256]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
85 int i; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
86 unsigned int data_offset; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
87 unsigned int audio_frame_counter; |
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 film->sample_table = NULL; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
90 film->stereo_buffer = NULL; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
91 film->stereo_buffer_size = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
92 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
93 /* load the main FILM header */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
94 if (get_buffer(pb, scratch, 16) != 16) |
482 | 95 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
96 data_offset = BE_32(&scratch[4]); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
97 film->version = BE_32(&scratch[8]); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
98 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
99 /* load the FDSC chunk */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
100 if (film->version == 0) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
101 /* special case for Lemmings .film files; 20-byte header */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
102 if (get_buffer(pb, scratch, 20) != 20) |
482 | 103 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
104 /* make some assumptions about the audio parameters */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
105 film->audio_type = CODEC_ID_PCM_S8; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
106 film->audio_samplerate = 22050; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
107 film->audio_channels = 1; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
108 film->audio_bits = 8; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
109 } else { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
110 /* normal Saturn .cpk files; 32-byte header */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
111 if (get_buffer(pb, scratch, 32) != 32) |
482 | 112 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
113 film->audio_samplerate = BE_16(&scratch[24]);; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
114 film->audio_channels = scratch[21]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
115 film->audio_bits = scratch[22]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
116 if (film->audio_bits == 8) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
117 film->audio_type = CODEC_ID_PCM_S8; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
118 else if (film->audio_bits == 16) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
119 film->audio_type = CODEC_ID_PCM_S16BE; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
120 else |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
121 film->audio_type = 0; |
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 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
124 if (BE_32(&scratch[0]) != FDSC_TAG) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
125 return AVERROR_INVALIDDATA; |
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 film->cvid_extra_bytes = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
128 if (BE_32(&scratch[8]) == CVID_TAG) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
129 film->video_type = CODEC_ID_CINEPAK; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
130 if (film->version) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
131 film->cvid_extra_bytes = 2; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
132 else |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
133 film->cvid_extra_bytes = 6; /* Lemmings 3DO case */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
134 } else |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
135 film->video_type = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
136 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
137 /* initialize the decoder streams */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
138 if (film->video_type) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
139 st = av_new_stream(s, 0); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
140 if (!st) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
141 return AVERROR_NOMEM; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
142 film->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
|
143 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
|
144 st->codec->codec_id = film->video_type; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
145 st->codec->codec_tag = 0; /* no fourcc */ |
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->width = BE_32(&scratch[16]); |
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->height = BE_32(&scratch[12]); |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
148 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
149 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
150 if (film->audio_type) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
151 st = av_new_stream(s, 0); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
152 if (!st) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
153 return AVERROR_NOMEM; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
154 film->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
|
155 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
|
156 st->codec->codec_id = film->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
|
157 st->codec->codec_tag = 1; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
158 st->codec->channels = film->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
|
159 st->codec->bits_per_sample = film->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
|
160 st->codec->sample_rate = film->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
|
161 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
|
162 st->codec->bits_per_sample; |
885 | 163 st->codec->block_align = st->codec->channels * |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
164 st->codec->bits_per_sample / 8; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
165 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
166 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
167 /* load the sample table */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
168 if (get_buffer(pb, scratch, 16) != 16) |
482 | 169 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
170 if (BE_32(&scratch[0]) != STAB_TAG) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
171 return AVERROR_INVALIDDATA; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
172 film->base_clock = BE_32(&scratch[8]); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
173 film->sample_count = BE_32(&scratch[12]); |
639 | 174 if(film->sample_count >= UINT_MAX / sizeof(film_sample_t)) |
175 return -1; | |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
176 film->sample_table = av_malloc(film->sample_count * sizeof(film_sample_t)); |
885 | 177 |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
178 for(i=0; i<s->nb_streams; i++) |
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
179 av_set_pts_info(s->streams[i], 33, 1, film->base_clock); |
885 | 180 |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
181 audio_frame_counter = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
182 for (i = 0; i < film->sample_count; i++) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
183 /* load the next sample record and transfer it to an internal struct */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
184 if (get_buffer(pb, scratch, 16) != 16) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
185 av_free(film->sample_table); |
482 | 186 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
187 } |
885 | 188 film->sample_table[i].sample_offset = |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
189 data_offset + BE_32(&scratch[0]); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
190 film->sample_table[i].sample_size = BE_32(&scratch[4]); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
191 if (BE_32(&scratch[8]) == 0xFFFFFFFF) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
192 film->sample_table[i].stream = film->audio_stream_index; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
193 film->sample_table[i].pts = audio_frame_counter; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
194 film->sample_table[i].pts *= film->base_clock; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
195 film->sample_table[i].pts /= film->audio_samplerate; |
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 audio_frame_counter += (film->sample_table[i].sample_size / |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
198 (film->audio_channels * film->audio_bits / 8)); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
199 } else { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
200 film->sample_table[i].stream = film->video_stream_index; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
201 film->sample_table[i].pts = BE_32(&scratch[8]) & 0x7FFFFFFF; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
202 film->sample_table[i].keyframe = (scratch[8] & 0x80) ? 0 : 1; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
203 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
204 } |
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 film->current_sample = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
207 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
208 return 0; |
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 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
211 static int film_read_packet(AVFormatContext *s, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
212 AVPacket *pkt) |
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 FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
215 ByteIOContext *pb = &s->pb; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
216 film_sample_t *sample; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
217 int ret = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
218 int i; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
219 int left, right; |
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 if (film->current_sample >= film->sample_count) |
482 | 222 return AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
223 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
224 sample = &film->sample_table[film->current_sample]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
225 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
226 /* position the stream (will probably be there anyway) */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
227 url_fseek(pb, sample->sample_offset, SEEK_SET); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
228 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
229 /* do a special song and dance when loading FILM Cinepak chunks */ |
885 | 230 if ((sample->stream == film->video_stream_index) && |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
231 (film->video_type == CODEC_ID_CINEPAK)) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
232 if (av_new_packet(pkt, sample->sample_size - film->cvid_extra_bytes)) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
233 return AVERROR_NOMEM; |
643 | 234 if(pkt->size < 10) |
235 return -1; | |
775 | 236 pkt->pos= url_ftell(pb); |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
237 ret = get_buffer(pb, pkt->data, 10); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
238 /* skip the non-spec CVID bytes */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
239 url_fseek(pb, film->cvid_extra_bytes, SEEK_CUR); |
885 | 240 ret += get_buffer(pb, pkt->data + 10, |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
241 sample->sample_size - 10 - film->cvid_extra_bytes); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
242 if (ret != sample->sample_size - film->cvid_extra_bytes) |
482 | 243 ret = AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
244 } else if ((sample->stream == film->audio_stream_index) && |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
245 (film->audio_channels == 2)) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
246 /* stereo PCM needs to be interleaved */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
247 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
248 if (av_new_packet(pkt, sample->sample_size)) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
249 return AVERROR_NOMEM; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
250 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
251 /* make sure the interleave buffer is large enough */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
252 if (sample->sample_size > film->stereo_buffer_size) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
253 av_free(film->stereo_buffer); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
254 film->stereo_buffer_size = sample->sample_size; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
255 film->stereo_buffer = av_malloc(film->stereo_buffer_size); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
256 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
257 |
775 | 258 pkt->pos= url_ftell(pb); |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
259 ret = get_buffer(pb, film->stereo_buffer, sample->sample_size); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
260 if (ret != sample->sample_size) |
482 | 261 ret = AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
262 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
263 left = 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
264 right = sample->sample_size / 2; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
265 for (i = 0; i < sample->sample_size; ) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
266 if (film->audio_bits == 8) { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
267 pkt->data[i++] = film->stereo_buffer[left++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
268 pkt->data[i++] = film->stereo_buffer[right++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
269 } else { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
270 pkt->data[i++] = film->stereo_buffer[left++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
271 pkt->data[i++] = film->stereo_buffer[left++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
272 pkt->data[i++] = film->stereo_buffer[right++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
273 pkt->data[i++] = film->stereo_buffer[right++]; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
274 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
275 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
276 } else { |
775 | 277 ret= av_get_packet(pb, pkt, sample->sample_size); |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
278 if (ret != sample->sample_size) |
482 | 279 ret = AVERROR_IO; |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
280 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
281 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
282 pkt->stream_index = sample->stream; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
283 pkt->pts = sample->pts; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
284 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
285 film->current_sample++; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
286 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
287 return ret; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
288 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
289 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
290 static int film_read_close(AVFormatContext *s) |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
291 { |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
292 FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
293 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
294 av_free(film->sample_table); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
295 av_free(film->stereo_buffer); |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
296 |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
297 return 0; |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
298 } |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
299 |
1169 | 300 AVInputFormat segafilm_demuxer = { |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
301 "film_cpk", |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
302 "Sega FILM/CPK format", |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
303 sizeof(FilmDemuxContext), |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
304 film_probe, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
305 film_read_header, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
306 film_read_packet, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
307 film_read_close, |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff
changeset
|
308 }; |