Mercurial > mplayer.hg
annotate libmpdemux/demux_film.c @ 35418:cedb0ba2b5c6
Move the code to set guiInfo's Track, Chapter and Angle start values.
Set them before checking whether there is any media opened, because
with no media opened we clear the counters.
author | ib |
---|---|
date | Thu, 29 Nov 2012 14:11:03 +0000 |
parents | 249053c3da2b |
children | 2398517e5bda |
rev | line source |
---|---|
4189 | 1 /* |
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
2 * FILM file parser |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
3 * Copyright (C) 2002 Mike Melanson |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
4 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
5 * This demuxer handles FILM (a.k.a. CPK) files commonly found on Sega |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
6 * Saturn CD-ROM games. FILM files have also been found on 3DO games. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
7 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
8 * details of the FILM file format can be found at: |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
9 * http://www.pcisys.net/~melanson/codecs/ |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
10 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
11 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
12 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
13 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
14 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
15 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
16 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
17 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
18 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
21 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
22 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
23 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
24 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26758
diff
changeset
|
26 */ |
4189 | 27 |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <unistd.h> | |
31 | |
32 #include "config.h" | |
33 #include "mp_msg.h" | |
34 #include "help_mp.h" | |
35 | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
18885
diff
changeset
|
36 #include "stream/stream.h" |
4189 | 37 #include "demuxer.h" |
38 #include "stheader.h" | |
39 | |
40 // chunk types found in a FILM file | |
41 #define CHUNK_FILM mmioFOURCC('F', 'I', 'L', 'M') | |
42 #define CHUNK_FDSC mmioFOURCC('F', 'D', 'S', 'C') | |
43 #define CHUNK_STAB mmioFOURCC('S', 'T', 'A', 'B') | |
44 | |
25607
9d0b189ce1b2
Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents:
22605
diff
changeset
|
45 typedef struct film_chunk_t |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
46 { |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
47 off_t chunk_offset; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
48 int chunk_size; |
5143 | 49 unsigned int syncinfo1; |
50 unsigned int syncinfo2; | |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
51 |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
52 float pts; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
53 } film_chunk_t; |
4189 | 54 |
25607
9d0b189ce1b2
Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents:
22605
diff
changeset
|
55 typedef struct film_data_t |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
56 { |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
57 unsigned int total_chunks; |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
58 unsigned int current_chunk; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
59 film_chunk_t *chunks; |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
60 unsigned int chunks_per_second; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
61 unsigned int film_version; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
62 } film_data_t; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
63 |
17636 | 64 static void demux_seek_film(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
65 { |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
66 film_data_t *film_data = (film_data_t *)demuxer->priv; |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
67 int new_current_chunk=(flags&SEEK_ABSOLUTE)?0:film_data->current_chunk; |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
68 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
69 if(flags&SEEK_FACTOR) |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
70 new_current_chunk += rel_seek_secs * film_data->total_chunks; // 0..1 |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
71 else |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
72 new_current_chunk += rel_seek_secs * film_data->chunks_per_second; // secs |
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
73 |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
74 |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
17805
diff
changeset
|
75 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"current, total chunks = %d, %d; seek %5.3f sec, new chunk guess = %d\n", |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
76 film_data->current_chunk, film_data->total_chunks, |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
77 rel_seek_secs, new_current_chunk); |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
78 |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
79 // check if the new chunk number is valid |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
80 if (new_current_chunk < 0) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
81 new_current_chunk = 0; |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
82 if ((unsigned int)new_current_chunk > film_data->total_chunks) |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
83 new_current_chunk = film_data->total_chunks - 1; |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
84 |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
85 while (((film_data->chunks[new_current_chunk].syncinfo1 == 0xFFFFFFFF) || |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
86 (film_data->chunks[new_current_chunk].syncinfo1 & 0x80000000)) && |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
87 (new_current_chunk > 0)) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
88 new_current_chunk--; |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
89 |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
90 film_data->current_chunk = new_current_chunk; |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
91 |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
17805
diff
changeset
|
92 mp_msg(MSGT_DECVIDEO, MSGL_INFO," (flags = %X) actual new chunk = %d (syncinfo1 = %08X)\n", |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
93 flags, film_data->current_chunk, film_data->chunks[film_data->current_chunk].syncinfo1); |
5439
bc20fe5676ff
seeking fixed (variable fps videos needs to reset PTS after seeking)
arpi
parents:
5438
diff
changeset
|
94 demuxer->video->pts=film_data->chunks[film_data->current_chunk].pts; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
95 |
4189 | 96 } |
97 | |
98 // return value: | |
99 // 0 = EOF or no stream found | |
100 // 1 = successfully read a packet | |
16175 | 101 static int demux_film_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds) |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
102 { |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
103 int i; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
104 unsigned char byte_swap; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
105 int cvid_size; |
4189 | 106 sh_video_t *sh_video = demuxer->video->sh; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
107 sh_audio_t *sh_audio = demuxer->audio->sh; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
108 film_data_t *film_data = (film_data_t *)demuxer->priv; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
109 film_chunk_t film_chunk; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
110 int length_fix_bytes; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
111 demux_packet_t* dp; |
4189 | 112 |
113 // see if the end has been reached | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
114 if (film_data->current_chunk >= film_data->total_chunks) |
4189 | 115 return 0; |
116 | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
117 film_chunk = film_data->chunks[film_data->current_chunk]; |
4189 | 118 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
119 // position stream and fetch chunk |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
120 stream_seek(demuxer->stream, film_chunk.chunk_offset); |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
121 |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
122 // load the chunks manually (instead of using ds_read_packet()), since |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
123 // they require some adjustment |
5143 | 124 // (all ones in syncinfo1 indicates an audio chunk) |
125 if (film_chunk.syncinfo1 == 0xFFFFFFFF) | |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
126 { |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
127 if(demuxer->audio->id>=-1){ // audio not disabled |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
128 dp = new_demux_packet(film_chunk.chunk_size); |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
129 if (stream_read(demuxer->stream, dp->buffer, film_chunk.chunk_size) != |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
130 film_chunk.chunk_size) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
131 return 0; |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
132 dp->pts = film_chunk.pts; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
133 dp->pos = film_chunk.chunk_offset; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
134 dp->flags = 0; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
135 |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
136 // adjust the data before queuing it: |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
137 // 8-bit: signed -> unsigned |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
138 // 16-bit: big-endian -> little-endian |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
139 if (sh_audio->wf->wBitsPerSample == 8) |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
140 for (i = 0; i < film_chunk.chunk_size; i++) |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
141 dp->buffer[i] += 128; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
142 else |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
143 for (i = 0; i < film_chunk.chunk_size; i += 2) |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
144 { |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
145 byte_swap = dp->buffer[i]; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
146 dp->buffer[i] = dp->buffer[i + 1]; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
147 dp->buffer[i + 1] = byte_swap; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
148 } |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
149 |
15468 | 150 /* for SegaSaturn .cpk file, translate audio data if stereo */ |
151 if (sh_audio->wf->nChannels == 2) { | |
152 if (sh_audio->wf->wBitsPerSample == 8) { | |
153 unsigned char* tmp = dp->buffer; | |
154 unsigned char buf[film_chunk.chunk_size]; | |
155 for(i = 0; i < film_chunk.chunk_size/2; i++) { | |
156 buf[i*2] = tmp[i]; | |
157 buf[i*2+1] = tmp[film_chunk.chunk_size/2+i]; | |
158 } | |
159 memcpy( tmp, buf, film_chunk.chunk_size ); | |
160 } | |
161 else {/* for 16bit */ | |
162 unsigned short* tmp = dp->buffer; | |
163 unsigned short buf[film_chunk.chunk_size/2]; | |
164 for(i = 0; i < film_chunk.chunk_size/4; i++) { | |
165 buf[i*2] = tmp[i]; | |
166 buf[i*2+1] = tmp[film_chunk.chunk_size/4+i]; | |
167 } | |
168 memcpy( tmp, buf, film_chunk.chunk_size ); | |
169 } | |
170 } | |
171 | |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
172 // append packet to DS stream |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
173 ds_add_packet(demuxer->audio, dp); |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
174 } |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
175 } |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
176 else |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
177 { |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
178 // if the demuxer is dealing with CVID data, deal with it a special way |
5143 | 179 if (sh_video->format == mmioFOURCC('c', 'v', 'i', 'd')) |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
180 { |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
181 if (film_data->film_version) |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
182 length_fix_bytes = 2; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
183 else |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
184 length_fix_bytes = 6; |
4189 | 185 |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
186 // account for the fix bytes when allocating the buffer |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
187 dp = new_demux_packet(film_chunk.chunk_size - length_fix_bytes); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
188 |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
189 // these CVID data chunks have a few extra bytes; skip them |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
190 if (stream_read(demuxer->stream, dp->buffer, 10) != 10) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
191 return 0; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
192 stream_skip(demuxer->stream, length_fix_bytes); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
193 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
194 if (stream_read(demuxer->stream, dp->buffer + 10, |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
195 film_chunk.chunk_size - (10 + length_fix_bytes)) != |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
196 (film_chunk.chunk_size - (10 + length_fix_bytes))) |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
197 return 0; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
198 |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
199 dp->pts = film_chunk.pts; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
200 dp->pos = film_chunk.chunk_offset; |
5143 | 201 dp->flags = (film_chunk.syncinfo1 & 0x80000000) ? 1 : 0; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
202 |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
203 // fix the CVID chunk size |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
204 cvid_size = film_chunk.chunk_size - length_fix_bytes; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
205 dp->buffer[1] = (cvid_size >> 16) & 0xFF; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
206 dp->buffer[2] = (cvid_size >> 8) & 0xFF; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
207 dp->buffer[3] = (cvid_size >> 0) & 0xFF; |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
208 |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
209 // append packet to DS stream |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
210 ds_add_packet(demuxer->video, dp); |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
211 } |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
212 else |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
213 { |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
214 ds_read_packet(demuxer->video, demuxer->stream, film_chunk.chunk_size, |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
215 film_chunk.pts, |
5143 | 216 film_chunk.chunk_offset, (film_chunk.syncinfo1 & 0x80000000) ? 1 : 0); |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
217 } |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
218 } |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
219 film_data->current_chunk++; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
220 |
4189 | 221 return 1; |
222 } | |
223 | |
16175 | 224 static demuxer_t* demux_open_film(demuxer_t* demuxer) |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
225 { |
4189 | 226 sh_video_t *sh_video = NULL; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
227 sh_audio_t *sh_audio = NULL; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
228 film_data_t *film_data; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
229 film_chunk_t film_chunk; |
4189 | 230 int header_size; |
231 unsigned int chunk_type; | |
232 unsigned int chunk_size; | |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
233 unsigned int i; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
234 unsigned int video_format; |
4226
63baf6de03e1
made a little more headway but it still doesn't work properly
melanson
parents:
4189
diff
changeset
|
235 int audio_channels; |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
236 int counting_chunks; |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
237 unsigned int total_audio_bytes = 0; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
238 |
18885 | 239 film_data = malloc(sizeof(film_data_t)); |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
240 film_data->total_chunks = 0; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
241 film_data->current_chunk = 0; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
242 film_data->chunks = NULL; |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
243 film_data->chunks_per_second = 0; |
4189 | 244 |
245 // go back to the beginning | |
246 stream_reset(demuxer->stream); | |
247 stream_seek(demuxer->stream, 0); | |
248 | |
249 // read the master chunk type | |
250 chunk_type = stream_read_fourcc(demuxer->stream); | |
251 // validate the chunk type | |
252 if (chunk_type != CHUNK_FILM) | |
253 { | |
254 mp_msg(MSGT_DEMUX, MSGL_ERR, "Not a FILM file\n"); | |
17805 | 255 free(film_data); |
26758
9fb1d2c3dbd4
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
26299
diff
changeset
|
256 return NULL; |
4189 | 257 } |
258 | |
259 // get the header size, which implicitly points past the header and | |
260 // to the start of the data | |
261 header_size = stream_read_dword(demuxer->stream); | |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
262 film_data->film_version = stream_read_fourcc(demuxer->stream); |
4189 | 263 demuxer->movi_start = header_size; |
264 demuxer->movi_end = demuxer->stream->end_pos; | |
265 header_size -= 16; | |
266 | |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
267 mp_msg(MSGT_DEMUX, MSGL_HINT, "FILM version %.4s\n", |
17366 | 268 (char *)&film_data->film_version); |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
269 |
4189 | 270 // skip to where the next chunk should be |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
271 stream_skip(demuxer->stream, 4); |
4189 | 272 |
273 // traverse through the header | |
274 while (header_size > 0) | |
275 { | |
276 // fetch the chunk type and size | |
277 chunk_type = stream_read_fourcc(demuxer->stream); | |
278 chunk_size = stream_read_dword(demuxer->stream); | |
279 header_size -= chunk_size; | |
280 | |
281 switch (chunk_type) | |
282 { | |
283 case CHUNK_FDSC: | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
284 mp_msg(MSGT_DECVIDEO, MSGL_V, "parsing FDSC chunk\n"); |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
285 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
286 // fetch the video codec fourcc to see if there's any video |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
287 video_format = stream_read_fourcc(demuxer->stream); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
288 if (video_format) |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
289 { |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
290 // create and initialize the video stream header |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
291 sh_video = new_sh_video(demuxer, 0); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
292 demuxer->video->sh = sh_video; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
293 sh_video->ds = demuxer->video; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
294 |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
295 sh_video->format = video_format; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
296 sh_video->disp_h = stream_read_dword(demuxer->stream); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
297 sh_video->disp_w = stream_read_dword(demuxer->stream); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
298 mp_msg(MSGT_DECVIDEO, MSGL_V, |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
299 " FILM video: %d x %d\n", sh_video->disp_w, |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
300 sh_video->disp_h); |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
301 } |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
302 else |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
303 // skip height and width if no video |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
304 stream_skip(demuxer->stream, 8); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
305 |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
306 if(demuxer->audio->id<-1){ |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
17805
diff
changeset
|
307 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"chunk size = 0x%X \n",chunk_size); |
5438
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
308 stream_skip(demuxer->stream, chunk_size-12-8); |
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
309 break; // audio disabled (or no soundcard) |
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
310 } |
607d437c1d9d
fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents:
5413
diff
changeset
|
311 |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
312 // skip over unknown byte, but only if file had non-NULL version |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
313 if (film_data->film_version) |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
314 stream_skip(demuxer->stream, 1); |
4226
63baf6de03e1
made a little more headway but it still doesn't work properly
melanson
parents:
4189
diff
changeset
|
315 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
316 // fetch the audio channels to see if there's any audio |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
317 // don't do this if the file is a quirky file with NULL version |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
318 if (film_data->film_version) |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
319 { |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
320 audio_channels = stream_read_char(demuxer->stream); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
321 if (audio_channels > 0) |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
322 { |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
323 // create and initialize the audio stream header |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
29263
diff
changeset
|
324 sh_audio = new_sh_audio(demuxer, 0, NULL); |
26299
4d56038ec730
Fix lots and lots of other demuxers broken by r26301
reimar
parents:
25883
diff
changeset
|
325 demuxer->audio->id = 0; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
326 demuxer->audio->sh = sh_audio; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
327 sh_audio->ds = demuxer->audio; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
328 |
32105 | 329 sh_audio->wf = malloc(sizeof(*sh_audio->wf)); |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
330 |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
331 // uncompressed PCM format |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
332 sh_audio->wf->wFormatTag = 1; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
333 sh_audio->format = 1; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
334 sh_audio->wf->nChannels = audio_channels; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
335 sh_audio->wf->wBitsPerSample = stream_read_char(demuxer->stream); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
336 stream_skip(demuxer->stream, 1); // skip unknown byte |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
337 sh_audio->wf->nSamplesPerSec = stream_read_word(demuxer->stream); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
338 sh_audio->wf->nAvgBytesPerSec = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
339 sh_audio->wf->nSamplesPerSec * sh_audio->wf->wBitsPerSample |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
340 * sh_audio->wf->nChannels / 8; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
341 stream_skip(demuxer->stream, 6); // skip the rest of the unknown |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
342 |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
343 mp_msg(MSGT_DECVIDEO, MSGL_V, |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
344 " FILM audio: %d channels, %d bits, %d Hz\n", |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
345 sh_audio->wf->nChannels, 8 * sh_audio->wf->wBitsPerSample, |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
346 sh_audio->wf->nSamplesPerSec); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
347 } |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
348 else |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
349 stream_skip(demuxer->stream, 10); |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
350 } |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
351 else |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
352 { |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
353 // otherwise, make some assumptions about the audio |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
354 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
355 // create and initialize the audio stream header |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
29263
diff
changeset
|
356 sh_audio = new_sh_audio(demuxer, 0, NULL); |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
357 demuxer->audio->sh = sh_audio; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
358 sh_audio->ds = demuxer->audio; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
359 |
32105 | 360 sh_audio->wf = malloc(sizeof(*sh_audio->wf)); |
4226
63baf6de03e1
made a little more headway but it still doesn't work properly
melanson
parents:
4189
diff
changeset
|
361 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
362 // uncompressed PCM format |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
363 sh_audio->wf->wFormatTag = 1; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
364 sh_audio->format = 1; |
5413
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
365 sh_audio->wf->nChannels = 1; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
366 sh_audio->wf->wBitsPerSample = 8; |
2a449fba2049
fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents:
5181
diff
changeset
|
367 sh_audio->wf->nSamplesPerSec = 22050; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
368 sh_audio->wf->nAvgBytesPerSec = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
369 sh_audio->wf->nSamplesPerSec * sh_audio->wf->wBitsPerSample |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
370 * sh_audio->wf->nChannels / 8; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
371 |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
372 mp_msg(MSGT_DECVIDEO, MSGL_V, |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
373 " FILM audio: %d channels, %d bits, %d Hz\n", |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
374 sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample, |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
375 sh_audio->wf->nSamplesPerSec); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
376 } |
4189 | 377 break; |
378 | |
379 case CHUNK_STAB: | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
380 mp_msg(MSGT_DECVIDEO, MSGL_V, "parsing STAB chunk\n"); |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
381 |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
382 if (sh_video) |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
383 { |
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
384 sh_video->fps = stream_read_dword(demuxer->stream); |
5143 | 385 sh_video->frametime = 1.0 / sh_video->fps; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
386 } |
4189 | 387 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
388 // fetch the number of chunks |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
389 film_data->total_chunks = stream_read_dword(demuxer->stream); |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
390 film_data->current_chunk = 0; |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
391 mp_msg(MSGT_DECVIDEO, MSGL_V, |
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
392 " STAB chunk contains %d chunks\n", film_data->total_chunks); |
4189 | 393 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
394 // allocate enough entries for the chunk |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
395 film_data->chunks = |
18885 | 396 calloc(film_data->total_chunks, sizeof(film_chunk_t)); |
4189 | 397 |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
398 // build the chunk index |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
399 counting_chunks = 1; |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
400 for (i = 0; i < film_data->total_chunks; i++) |
4189 | 401 { |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
402 film_chunk = film_data->chunks[i]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
403 film_chunk.chunk_offset = |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
404 demuxer->movi_start + stream_read_dword(demuxer->stream); |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
405 film_chunk.chunk_size = stream_read_dword(demuxer->stream); |
5143 | 406 film_chunk.syncinfo1 = stream_read_dword(demuxer->stream); |
407 film_chunk.syncinfo2 = stream_read_dword(demuxer->stream); | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
408 |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
409 // count chunks for the purposes of seeking |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
410 if (counting_chunks) |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
411 { |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
412 // if we're counting chunks, always count an audio chunk |
35313
2b211b058ee2
Avoid crash when parsing index for audio-only files.
reimar
parents:
35292
diff
changeset
|
413 if (!sh_video || film_chunk.syncinfo1 == 0xFFFFFFFF) |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
414 film_data->chunks_per_second++; |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
415 // if it's a video chunk, check if it's time to stop counting |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
416 else if ((film_chunk.syncinfo1 & 0x7FFFFFFF) >= sh_video->fps) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
417 counting_chunks = 0; |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
418 else |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
419 film_data->chunks_per_second++; |
4628
1504901deed8
Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents:
4564
diff
changeset
|
420 } |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
421 |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
422 // precalculate PTS |
35313
2b211b058ee2
Avoid crash when parsing index for audio-only files.
reimar
parents:
35292
diff
changeset
|
423 if (!sh_video || film_chunk.syncinfo1 == 0xFFFFFFFF) |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
424 { |
35318 | 425 if(sh_audio) |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
426 film_chunk.pts = |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
427 (float)total_audio_bytes / (float)sh_audio->wf->nAvgBytesPerSec; |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
428 total_audio_bytes += film_chunk.chunk_size; |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
429 } |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
430 else |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
431 film_chunk.pts = |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
432 (film_chunk.syncinfo1 & 0x7FFFFFFF) / sh_video->fps; |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
433 |
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
434 film_data->chunks[i] = film_chunk; |
4189 | 435 } |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
436 |
5181
81ef0f0b285f
added PTS for audio, but seeking still doesn't work
melanson
parents:
5157
diff
changeset
|
437 // in some FILM files (notably '1.09'), the length of the FDSC chunk |
5157
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
438 // follows different rules |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
439 if (chunk_size == (film_data->total_chunks * 16)) |
f67b321e1eda
FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents:
5143
diff
changeset
|
440 header_size -= 16; |
4189 | 441 break; |
442 | |
443 default: | |
444 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unrecognized FILM header chunk: %08X\n", | |
445 chunk_type); | |
35292 | 446 free(film_data->chunks); |
447 free(film_data); | |
26758
9fb1d2c3dbd4
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
26299
diff
changeset
|
448 return NULL; |
4189 | 449 } |
450 } | |
451 | |
4564
5e1221d4655e
completely reworked FILM demuxer to support both audio and video...neither
melanson
parents:
4226
diff
changeset
|
452 demuxer->priv = film_data; |
4189 | 453 |
454 return demuxer; | |
455 } | |
5810 | 456 |
16175 | 457 static void demux_close_film(demuxer_t* demuxer) { |
5810 | 458 film_data_t *film_data = demuxer->priv; |
459 | |
460 if(!film_data) | |
461 return; | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32105
diff
changeset
|
462 free(film_data->chunks); |
5810 | 463 free(film_data); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
464 |
5810 | 465 } |
16175 | 466 |
467 static int film_check_file(demuxer_t* demuxer) | |
468 { | |
469 int signature=stream_read_fourcc(demuxer->stream); | |
470 | |
471 // check for the FILM file magic number | |
472 if(signature==mmioFOURCC('F', 'I', 'L', 'M')) | |
473 return DEMUXER_TYPE_FILM; | |
474 | |
475 return 0; | |
476 } | |
477 | |
478 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25607
diff
changeset
|
479 const demuxer_desc_t demuxer_desc_film = { |
16175 | 480 "FILM/CPK demuxer for Sega Saturn CD-ROM games", |
481 "film", | |
482 "FILM", | |
483 "Mike Melanson", | |
484 "", | |
485 DEMUXER_TYPE_FILM, | |
486 0, // unsafe autodetect (short signature) | |
487 film_check_file, | |
488 demux_film_fill_buffer, | |
489 demux_open_film, | |
490 demux_close_film, | |
491 demux_seek_film, | |
492 NULL | |
493 }; |