annotate libmpdemux/demux_film.c @ 11786:06474b60be53

EDL section moved into usage.
author diego
date Wed, 14 Jan 2004 19:56:36 +0000
parents 8a357300d0ec
children bef6d46722ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
1 /*
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
2 FILM file parser for the MPlayer program
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
3 by Mike Melanson
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
4
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
5 This demuxer handles FILM (a.k.a. CPK) files commonly found on
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
6 Sega Saturn CD-ROM games. FILM files have also been found on 3DO
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
7 games.
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
8
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
9 Details of the FILM file format can be found at:
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
10 http://www.pcisys.net/~melanson/codecs/
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
11 */
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
12
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
13 #include <stdio.h>
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
14 #include <stdlib.h>
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
15 #include <unistd.h>
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
16
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
17 #include "config.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
18 #include "mp_msg.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
19 #include "help_mp.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
20
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
21 #include "stream.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
22 #include "demuxer.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
23 #include "stheader.h"
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
24
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
25 // chunk types found in a FILM file
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
26 #define CHUNK_FILM mmioFOURCC('F', 'I', 'L', 'M')
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
27 #define CHUNK_FDSC mmioFOURCC('F', 'D', 'S', 'C')
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
28 #define CHUNK_STAB mmioFOURCC('S', 'T', 'A', 'B')
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
29
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
30 typedef struct _film_chunk_t
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
31 {
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
32 off_t chunk_offset;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
33 int chunk_size;
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
34 unsigned int syncinfo1;
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
35 unsigned int syncinfo2;
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
36
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
37 float pts;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
38 } film_chunk_t;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
39
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
40 typedef struct _film_data_t
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
41 {
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
42 unsigned int total_chunks;
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
43 unsigned int current_chunk;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
44 film_chunk_t *chunks;
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
45 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
46 unsigned int film_version;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
47 } film_data_t;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
48
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
49 void demux_seek_film(demuxer_t *demuxer, float rel_seek_secs, int flags)
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
50 {
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
51 film_data_t *film_data = (film_data_t *)demuxer->priv;
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
52 int new_current_chunk=(flags&1)?0:film_data->current_chunk;
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
53
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
54 if(flags&2)
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
55 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
56 else
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
57 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
58
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
59
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
60 printf ("current, total chunks = %d, %d; seek %5.3f sec, new chunk guess = %d\n",
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
61 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
62 rel_seek_secs, new_current_chunk);
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
63
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
64 // 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
65 if (new_current_chunk < 0)
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
66 new_current_chunk = 0;
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
67 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
68 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
69
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
70 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
71 (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
72 (new_current_chunk > 0))
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
73 new_current_chunk--;
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
74
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
75 film_data->current_chunk = new_current_chunk;
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
76
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
77 printf (" (flags = %X) actual new chunk = %d (syncinfo1 = %08X)\n",
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
78 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
79 demuxer->video->pts=film_data->chunks[film_data->current_chunk].pts;
bc20fe5676ff seeking fixed (variable fps videos needs to reset PTS after seeking)
arpi
parents: 5438
diff changeset
80
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
81 }
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
82
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
83 // return value:
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
84 // 0 = EOF or no stream found
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
85 // 1 = successfully read a packet
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
86 int demux_film_fill_buffer(demuxer_t *demuxer)
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
87 {
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
88 int i;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
89 unsigned char byte_swap;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
90 int cvid_size;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
91 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
92 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
93 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
94 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
95 int length_fix_bytes;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
96 demux_packet_t* dp;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
97
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
98 // 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
99 if (film_data->current_chunk >= film_data->total_chunks)
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
100 return 0;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
101
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
102 film_chunk = film_data->chunks[film_data->current_chunk];
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
103
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
104 // position stream and fetch chunk
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
105 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
106
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
107 // 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
108 // they require some adjustment
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
109 // (all ones in syncinfo1 indicates an audio chunk)
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
110 if (film_chunk.syncinfo1 == 0xFFFFFFFF)
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
111 {
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
112 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
113 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
114 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
115 film_chunk.chunk_size)
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
116 return 0;
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
117 dp->pts = film_chunk.pts;
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
118 dp->pos = film_chunk.chunk_offset;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
119 dp->flags = 0;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
120
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
121 // adjust the data before queuing it:
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
122 // 8-bit: signed -> unsigned
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
123 // 16-bit: big-endian -> little-endian
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
124 if (sh_audio->wf->wBitsPerSample == 8)
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
125 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
126 dp->buffer[i] += 128;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
127 else
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
128 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
129 {
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
130 byte_swap = dp->buffer[i];
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
131 dp->buffer[i] = dp->buffer[i + 1];
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
132 dp->buffer[i + 1] = byte_swap;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
133 }
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
134
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
135 // append packet to DS stream
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
136 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
137 }
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
138 }
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
139 else
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
140 {
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
141 // if the demuxer is dealing with CVID data, deal with it a special way
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
142 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
143 {
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
144 if (film_data->film_version)
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
145 length_fix_bytes = 2;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
146 else
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
147 length_fix_bytes = 6;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
148
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
149 // 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
150 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
151
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
152 // 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
153 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
154 return 0;
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
155 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
156
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
157 if (stream_read(demuxer->stream, dp->buffer + 10,
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
158 film_chunk.chunk_size - (10 + length_fix_bytes)) !=
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
159 (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
160 return 0;
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
161
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
162 dp->pts = film_chunk.pts;
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
163 dp->pos = film_chunk.chunk_offset;
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
164 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
165
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
166 // fix the CVID chunk size
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
167 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
168 dp->buffer[1] = (cvid_size >> 16) & 0xFF;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
169 dp->buffer[2] = (cvid_size >> 8) & 0xFF;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
170 dp->buffer[3] = (cvid_size >> 0) & 0xFF;
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
171
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->video, dp);
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
174 }
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
175 else
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
176 {
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
177 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
178 film_chunk.pts,
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
179 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
180 }
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
181 }
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
182 film_data->current_chunk++;
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
183
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
184 return 1;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
185 }
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
186
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
187 demuxer_t* demux_open_film(demuxer_t* demuxer)
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
188 {
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
189 sh_video_t *sh_video = NULL;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
190 sh_audio_t *sh_audio = NULL;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
191 film_data_t *film_data;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
192 film_chunk_t film_chunk;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
193 int header_size;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
194 unsigned int chunk_type;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
195 unsigned int chunk_size;
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
196 unsigned int i;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
197 unsigned int video_format;
4226
63baf6de03e1 made a little more headway but it still doesn't work properly
melanson
parents: 4189
diff changeset
198 int audio_channels;
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
199 int counting_chunks;
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
200 unsigned int total_audio_bytes = 0;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
201
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
202 film_data = (film_data_t *)malloc(sizeof(film_data_t));
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
203 film_data->total_chunks = 0;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
204 film_data->current_chunk = 0;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
205 film_data->chunks = NULL;
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
206 film_data->chunks_per_second = 0;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
207
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
208 // go back to the beginning
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
209 stream_reset(demuxer->stream);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
210 stream_seek(demuxer->stream, 0);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
211
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
212 // read the master chunk type
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
213 chunk_type = stream_read_fourcc(demuxer->stream);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
214 // validate the chunk type
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
215 if (chunk_type != CHUNK_FILM)
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
216 {
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
217 mp_msg(MSGT_DEMUX, MSGL_ERR, "Not a FILM file\n");
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
218 return(NULL);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
219 }
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
220
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
221 // get the header size, which implicitly points past the header and
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
222 // to the start of the data
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
223 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
224 film_data->film_version = stream_read_fourcc(demuxer->stream);
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
225 demuxer->movi_start = header_size;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
226 demuxer->movi_end = demuxer->stream->end_pos;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
227 header_size -= 16;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
228
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
229 mp_msg(MSGT_DEMUX, MSGL_HINT, "FILM version %.4s\n",
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
230 &film_data->film_version);
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
231
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
232 // 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
233 stream_skip(demuxer->stream, 4);
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
234
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
235 // traverse through the header
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
236 while (header_size > 0)
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
237 {
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
238 // fetch the chunk type and size
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
239 chunk_type = stream_read_fourcc(demuxer->stream);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
240 chunk_size = stream_read_dword(demuxer->stream);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
241 header_size -= chunk_size;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
242
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
243 switch (chunk_type)
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
244 {
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
245 case CHUNK_FDSC:
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
246 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
247
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
248 // 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
249 video_format = stream_read_fourcc(demuxer->stream);
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
250 if (video_format)
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
251 {
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
252 // create and initialize the video stream header
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
253 sh_video = new_sh_video(demuxer, 0);
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
254 demuxer->video->sh = sh_video;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
255 sh_video->ds = demuxer->video;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
256
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
257 sh_video->format = video_format;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
258 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
259 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
260 mp_msg(MSGT_DECVIDEO, MSGL_V,
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
261 " 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
262 sh_video->disp_h);
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
263 }
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
264 else
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
265 // 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
266 stream_skip(demuxer->stream, 8);
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
267
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
268 if(demuxer->audio->id<-1){
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
269 printf("chunk size = 0x%X \n",chunk_size);
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
270 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
271 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
272 }
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
273
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
274 // 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
275 if (film_data->film_version)
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
276 stream_skip(demuxer->stream, 1);
4226
63baf6de03e1 made a little more headway but it still doesn't work properly
melanson
parents: 4189
diff changeset
277
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
278 // 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
279 // 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
280 if (film_data->film_version)
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
281 {
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
282 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
283 if (audio_channels > 0)
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
284 {
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
285 // create and initialize the audio stream header
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
286 sh_audio = new_sh_audio(demuxer, 0);
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
287 demuxer->audio->sh = sh_audio;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
288 sh_audio->ds = demuxer->audio;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
289
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
290 sh_audio->wf = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX));
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
291
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
292 // uncompressed PCM format
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
293 sh_audio->wf->wFormatTag = 1;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
294 sh_audio->format = 1;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
295 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
296 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
297 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
298 sh_audio->wf->nSamplesPerSec = stream_read_word(demuxer->stream);
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
299 sh_audio->wf->nAvgBytesPerSec =
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
300 sh_audio->wf->nSamplesPerSec * sh_audio->wf->wBitsPerSample
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
301 * sh_audio->wf->nChannels / 8;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
302 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
303
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
304 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
305 " FILM audio: %d channels, %d bits, %d Hz\n",
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
306 sh_audio->wf->nChannels, 8 * sh_audio->wf->wBitsPerSample,
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
307 sh_audio->wf->nSamplesPerSec);
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
308 }
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
309 else
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
310 stream_skip(demuxer->stream, 10);
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
311 }
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
312 else
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
313 {
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
314 // 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
315
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
316 // create and initialize the audio stream header
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
317 sh_audio = new_sh_audio(demuxer, 0);
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
318 demuxer->audio->sh = sh_audio;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
319 sh_audio->ds = demuxer->audio;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
320
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
321 sh_audio->wf = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX));
4226
63baf6de03e1 made a little more headway but it still doesn't work properly
melanson
parents: 4189
diff changeset
322
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
323 // uncompressed PCM format
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
324 sh_audio->wf->wFormatTag = 1;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
325 sh_audio->format = 1;
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
326 sh_audio->wf->nChannels = 1;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
327 sh_audio->wf->wBitsPerSample = 8;
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
328 sh_audio->wf->nSamplesPerSec = 22050;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
329 sh_audio->wf->nAvgBytesPerSec =
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
330 sh_audio->wf->nSamplesPerSec * sh_audio->wf->wBitsPerSample
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
331 * sh_audio->wf->nChannels / 8;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
332
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
333 mp_msg(MSGT_DECVIDEO, MSGL_V,
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
334 " FILM audio: %d channels, %d bits, %d Hz\n",
5413
2a449fba2049 fixed to be able to handle extra-quirky .film files on Lemmings 3DO
melanson
parents: 5181
diff changeset
335 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
336 sh_audio->wf->nSamplesPerSec);
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
337 }
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
338 break;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
339
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
340 case CHUNK_STAB:
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
341 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
342
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
343 if (sh_video)
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
344 {
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
345 sh_video->fps = stream_read_dword(demuxer->stream);
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
346 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
347 }
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
348
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
349 // fetch the number of chunks
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
350 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
351 film_data->current_chunk = 0;
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
352 mp_msg(MSGT_DECVIDEO, MSGL_V,
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
353 " STAB chunk contains %d chunks\n", film_data->total_chunks);
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
354
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
355 // allocate enough entries for the chunk
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
356 film_data->chunks =
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
357 (film_chunk_t *)malloc(film_data->total_chunks * sizeof(film_chunk_t));
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
358
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
359 // build the chunk index
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
360 counting_chunks = 1;
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
361 for (i = 0; i < film_data->total_chunks; i++)
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
362 {
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
363 film_chunk = film_data->chunks[i];
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
364 film_chunk.chunk_offset =
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
365 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
366 film_chunk.chunk_size = stream_read_dword(demuxer->stream);
5143
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
367 film_chunk.syncinfo1 = stream_read_dword(demuxer->stream);
3958674b696b added proper PTS support for FILM demuxer
melanson
parents: 4628
diff changeset
368 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
369
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
370 // 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
371 if (counting_chunks)
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
372 {
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
373 // if we're counting chunks, always count an audio chunk
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
374 if (film_chunk.syncinfo1 == 0xFFFFFFFF)
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
375 film_data->chunks_per_second++;
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
376 // 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
377 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
378 counting_chunks = 0;
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
379 else
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
380 film_data->chunks_per_second++;
4628
1504901deed8 Fixed FILM demuxer so that it now plays (my) FILM files
melanson
parents: 4564
diff changeset
381 }
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
382
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
383 // precalculate PTS
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
384 if (film_chunk.syncinfo1 == 0xFFFFFFFF)
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
385 {
5438
607d437c1d9d fixed new_chunk calculation at seeking (seeking not work yet) and added -nosound support
arpi
parents: 5413
diff changeset
386 if(demuxer->audio->id>=-1)
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
387 film_chunk.pts =
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
388 (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
389 total_audio_bytes += film_chunk.chunk_size;
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
390 }
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
391 else
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
392 film_chunk.pts =
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
393 (film_chunk.syncinfo1 & 0x7FFFFFFF) / sh_video->fps;
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
394
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
395 film_data->chunks[i] = film_chunk;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
396 }
5157
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
397
5181
81ef0f0b285f added PTS for audio, but seeking still doesn't work
melanson
parents: 5157
diff changeset
398 // 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
399 // follows different rules
f67b321e1eda FILM demuxer is leaner, meaner, and cleaner, also with proper bailout on
melanson
parents: 5143
diff changeset
400 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
401 header_size -= 16;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
402 break;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
403
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
404 default:
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
405 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unrecognized FILM header chunk: %08X\n",
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
406 chunk_type);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
407 return(NULL);
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
408 break;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
409 }
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
410 }
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
411
4564
5e1221d4655e completely reworked FILM demuxer to support both audio and video...neither
melanson
parents: 4226
diff changeset
412 demuxer->priv = film_data;
4189
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
413
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
414 return demuxer;
6871d97e4261 initial support for FILM file demuxing
melanson
parents:
diff changeset
415 }
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
416
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
417 void demux_close_film(demuxer_t* demuxer) {
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
418 film_data_t *film_data = demuxer->priv;
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
419
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
420 if(!film_data)
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
421 return;
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
422 if(film_data->chunks)
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
423 free(film_data->chunks);
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
424 free(film_data);
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
425
8a357300d0ec Added demuxer uninit
albeu
parents: 5439
diff changeset
426 }