annotate libmpdemux/demux_roq.c @ 32349:0e554fa55be8

Mark pva_get_payload() as static, it is not used outside of the file.
author diego
date Sun, 03 Oct 2010 15:39:50 +0000
parents 0e09b34b0c47
children 8fa2f43cb760
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
1 /*
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
2 * RoQ file demuxer
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
3 * copyright (c) 2002 Mike Melanson
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
4 * based on Dr. Tim Ferguson's RoQ document found at:
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
5 * http://www.csse.monash.edu.au/~timf/videocodec.html
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
6 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
7 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
10 * 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: 26299
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
12 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
17 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
18 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
19 * 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: 26299
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26299
diff changeset
22 */
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
23
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
24 #include <stdio.h>
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
25 #include <stdlib.h>
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
26 #include <unistd.h>
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
27
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
28 #include "config.h"
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
29 #include "mp_msg.h"
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
30 #include "help_mp.h"
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
31
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 19062
diff changeset
32 #include "stream/stream.h"
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
33 #include "demuxer.h"
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
34 #include "stheader.h"
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
35
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
36 #define RoQ_INFO 0x1001
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
37 #define RoQ_QUAD_CODEBOOK 0x1002
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
38 #define RoQ_QUAD_VQ 0x1011
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
39 #define RoQ_SOUND_MONO 0x1020
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
40 #define RoQ_SOUND_STEREO 0x1021
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
41
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
42 #define CHUNK_TYPE_AUDIO 0
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
43 #define CHUNK_TYPE_VIDEO 1
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
44
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
45 typedef struct roq_chunk_t
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
46 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
47 int chunk_type;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
48 off_t chunk_offset;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
49 int chunk_size;
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
50
5424
e6d180ceb1ef changed int -> float for proper PTS calculation (works just as well as the
melanson
parents: 5421
diff changeset
51 float video_chunk_number; // in the case of a video chunk
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
52 int running_audio_sample_count; // for an audio chunk
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
53 } roq_chunk_t;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
54
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
55 typedef struct roq_data_t
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
56 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
57 int total_chunks;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
58 int current_chunk;
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
59 int total_video_chunks;
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
60 int total_audio_sample_count;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
61 roq_chunk_t *chunks;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
62 } roq_data_t;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
63
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
64 // Check if a stream qualifies as a RoQ file based on the magic numbers
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
65 // at the start of the file:
4753
f3562b5411f9 fixed RoQ file detection and FPS determination (maybe)
melanson
parents: 4532
diff changeset
66 // 84 10 FF FF FF FF xx xx
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
67 static int roq_check_file(demuxer_t *demuxer)
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
68 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
69 if ((stream_read_dword(demuxer->stream) == 0x8410FFFF) &&
4753
f3562b5411f9 fixed RoQ file detection and FPS determination (maybe)
melanson
parents: 4532
diff changeset
70 ((stream_read_dword(demuxer->stream) & 0xFFFF0000) == 0xFFFF0000))
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
71 return DEMUXER_TYPE_ROQ;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
72 else
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
73 return 0;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
74 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
75
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
76 // return value:
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
77 // 0 = EOF or no stream found
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
78 // 1 = successfully read a packet
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
79 static int demux_roq_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
80 {
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
81 sh_video_t *sh_video = demuxer->video->sh;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
82 roq_data_t *roq_data = (roq_data_t *)demuxer->priv;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
83 roq_chunk_t roq_chunk;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
84
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
85 if (roq_data->current_chunk >= roq_data->total_chunks)
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
86 return 0;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
87
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
88 roq_chunk = roq_data->chunks[roq_data->current_chunk];
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
89
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
90 // make sure we're at the right place in the stream and fetch the chunk
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
91 stream_seek(demuxer->stream, roq_chunk.chunk_offset);
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
92
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
93 if (roq_chunk.chunk_type == CHUNK_TYPE_AUDIO)
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
94 ds_read_packet(demuxer->audio, demuxer->stream, roq_chunk.chunk_size,
5421
d1ff2c2f74f0 fixed RoQ framerate by multiplying PTS calculation by some absurd constant
melanson
parents: 4753
diff changeset
95 0,
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
96 roq_chunk.chunk_offset, 0);
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
97 else
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
98 ds_read_packet(demuxer->video, demuxer->stream, roq_chunk.chunk_size,
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
99 roq_chunk.video_chunk_number / sh_video->fps,
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
100 roq_chunk.chunk_offset, 0);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
101
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
102 roq_data->current_chunk++;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
103 return 1;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
104 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
105
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
106 static demuxer_t* demux_open_roq(demuxer_t* demuxer)
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
107 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
108 sh_video_t *sh_video = NULL;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
109 sh_audio_t *sh_audio = NULL;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
110
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 16175
diff changeset
111 roq_data_t *roq_data = malloc(sizeof(roq_data_t));
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
112 int chunk_id;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
113 int chunk_size;
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
114 int chunk_arg;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
115 int last_chunk_id = 0;
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
116 int largest_audio_chunk = 0;
4753
f3562b5411f9 fixed RoQ file detection and FPS determination (maybe)
melanson
parents: 4532
diff changeset
117 int fps;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
118
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
119 roq_data->total_chunks = 0;
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
120 roq_data->current_chunk = 0;
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
121 roq_data->total_video_chunks = 0;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
122 roq_data->chunks = NULL;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
123
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
124 // position the stream and start traversing
4753
f3562b5411f9 fixed RoQ file detection and FPS determination (maybe)
melanson
parents: 4532
diff changeset
125 stream_seek(demuxer->stream, 6);
f3562b5411f9 fixed RoQ file detection and FPS determination (maybe)
melanson
parents: 4532
diff changeset
126 fps = stream_read_word_le(demuxer->stream);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
127 while (!stream_eof(demuxer->stream))
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
128 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
129 chunk_id = stream_read_word_le(demuxer->stream);
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
130 chunk_size = stream_read_dword_le(demuxer->stream);
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
131 chunk_arg = stream_read_word_le(demuxer->stream);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
132
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
133 // this is the only useful header info in the file
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
134 if (chunk_id == RoQ_INFO)
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
135 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
136 // there should only be one RoQ_INFO chunk per file
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
137 if (sh_video)
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
138 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
139 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Found more than one RoQ_INFO chunk\n");
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
140 stream_skip(demuxer->stream, 8);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
141 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
142 else
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
143 {
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
144 // this is a good opportunity to create a video stream header
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
145 sh_video = new_sh_video(demuxer, 0);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
146 // make sure the demuxer knows about the new stream header
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
147 demuxer->video->sh = sh_video;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
148 // make sure that the video demuxer stream header knows about its
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
149 // parent video demuxer stream
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
150 sh_video->ds = demuxer->video;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
151
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
152 sh_video->disp_w = stream_read_word_le(demuxer->stream);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
153 sh_video->disp_h = stream_read_word_le(demuxer->stream);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
154 stream_skip(demuxer->stream, 4);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
155
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
156 // custom fourcc for internal MPlayer use
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
157 sh_video->format = mmioFOURCC('R', 'o', 'Q', 'V');
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
158
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
159 // constant frame rate
5424
e6d180ceb1ef changed int -> float for proper PTS calculation (works just as well as the
melanson
parents: 5421
diff changeset
160 sh_video->fps = fps;
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
161 sh_video->frametime = 1 / sh_video->fps;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
162 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
163 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
164 else if ((chunk_id == RoQ_SOUND_MONO) ||
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
165 (chunk_id == RoQ_SOUND_STEREO))
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
166 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
167 // create the audio stream header if it hasn't been created it
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
168 if (sh_audio == NULL)
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
169 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
170 // make the header first
31609
cd81fce1f010 Make the stream language an argument to the stream creation function
reimar
parents: 30702
diff changeset
171 sh_audio = new_sh_audio(demuxer, 0, NULL);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
172 // make sure the demuxer knows about the new stream header
26299
4d56038ec730 Fix lots and lots of other demuxers broken by r26301
reimar
parents: 25707
diff changeset
173 demuxer->audio->id = 0;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
174 demuxer->audio->sh = sh_audio;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
175 // make sure that the audio demuxer stream header knows about its
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
176 // parent audio demuxer stream
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
177 sh_audio->ds = demuxer->audio;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
178
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
179 // go through the bother of making a WAVEFORMATEX structure
32100
0e09b34b0c47 Replace some sizeof(type) by sizeof(*pointer)
reimar
parents: 31609
diff changeset
180 sh_audio->wf = malloc(sizeof(*sh_audio->wf));
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
181
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
182 // custom fourcc for internal MPlayer use
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
183 sh_audio->format = mmioFOURCC('R', 'o', 'Q', 'A');
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
184 if (chunk_id == RoQ_SOUND_STEREO)
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
185 sh_audio->wf->nChannels = 2;
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
186 else
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
187 sh_audio->wf->nChannels = 1;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
188 // always 22KHz, 16-bit
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
189 sh_audio->wf->nSamplesPerSec = 22050;
5421
d1ff2c2f74f0 fixed RoQ framerate by multiplying PTS calculation by some absurd constant
melanson
parents: 4753
diff changeset
190 sh_audio->wf->wBitsPerSample = 16;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
191 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
192
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
193 // index the chunk
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 29263
diff changeset
194 roq_data->chunks = realloc(roq_data->chunks,
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
195 (roq_data->total_chunks + 1) * sizeof (roq_chunk_t));
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
196 roq_data->chunks[roq_data->total_chunks].chunk_type = CHUNK_TYPE_AUDIO;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
197 roq_data->chunks[roq_data->total_chunks].chunk_offset =
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
198 stream_tell(demuxer->stream) - 8;
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
199 roq_data->chunks[roq_data->total_chunks].chunk_size = chunk_size + 8;
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
200 roq_data->chunks[roq_data->total_chunks].running_audio_sample_count =
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
201 roq_data->total_audio_sample_count;
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
202
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
203 // audio housekeeping
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
204 if (chunk_size > largest_audio_chunk)
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
205 largest_audio_chunk = chunk_size;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
206 roq_data->total_audio_sample_count +=
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
207 (chunk_size / sh_audio->wf->nChannels);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
208
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
209 stream_skip(demuxer->stream, chunk_size);
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
210 roq_data->total_chunks++;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
211 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
212 else if ((chunk_id == RoQ_QUAD_CODEBOOK) ||
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
213 ((chunk_id == RoQ_QUAD_VQ) && (last_chunk_id != RoQ_QUAD_CODEBOOK)))
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
214 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
215 // index a new chunk if it's a codebook or quad VQ not following a
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
216 // codebook
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 29263
diff changeset
217 roq_data->chunks = realloc(roq_data->chunks,
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
218 (roq_data->total_chunks + 1) * sizeof (roq_chunk_t));
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
219 roq_data->chunks[roq_data->total_chunks].chunk_type = CHUNK_TYPE_VIDEO;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
220 roq_data->chunks[roq_data->total_chunks].chunk_offset =
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
221 stream_tell(demuxer->stream) - 8;
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
222 roq_data->chunks[roq_data->total_chunks].chunk_size = chunk_size + 8;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
223 roq_data->chunks[roq_data->total_chunks].video_chunk_number =
5424
e6d180ceb1ef changed int -> float for proper PTS calculation (works just as well as the
melanson
parents: 5421
diff changeset
224 roq_data->total_video_chunks++;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
225
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
226 stream_skip(demuxer->stream, chunk_size);
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
227 roq_data->total_chunks++;
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
228 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
229 else if ((chunk_id == RoQ_QUAD_VQ) && (last_chunk_id == RoQ_QUAD_CODEBOOK))
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
230 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
231 // if it's a quad VQ chunk following a codebook chunk, extend the last
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
232 // chunk
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
233 roq_data->chunks[roq_data->total_chunks - 1].chunk_size += (chunk_size + 8);
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
234 stream_skip(demuxer->stream, chunk_size);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
235 }
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
236 else if (!stream_eof(demuxer->stream))
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
237 {
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
238 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Unknown RoQ chunk ID: %04X\n", chunk_id);
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
239 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
240
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
241 last_chunk_id = chunk_id;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
242 }
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
243
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
244 // minimum output buffer size = largest audio chunk * 2, since each byte
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
245 // in the DPCM encoding effectively represents 1 16-bit sample
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
246 // (store it in wf->nBlockAlign for the time being since init_audio() will
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
247 // step on it anyway)
4532
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
248 if (sh_audio)
f86c1915ca79 fixed FPS as well as crash bug when no audio chunks are present
melanson
parents: 4485
diff changeset
249 sh_audio->wf->nBlockAlign = largest_audio_chunk * 2;
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
250
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
251 roq_data->current_chunk = 0;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
252
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
253 demuxer->priv = roq_data;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
254
4485
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
255 stream_reset(demuxer->stream);
eaa4a2242552 demuxer is now more complete, though still not perfect
melanson
parents: 4451
diff changeset
256
4451
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
257 return demuxer;
5627d5b58083 implemented RoQ file demuxing
melanson
parents:
diff changeset
258 }
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
259
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
260 static void demux_close_roq(demuxer_t* demuxer) {
5810
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
261 roq_data_t *roq_data = demuxer->priv;
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
262
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
263 if(!roq_data)
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
264 return;
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
265 free(roq_data);
8a357300d0ec Added demuxer uninit
albeu
parents: 5424
diff changeset
266 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
267
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
268
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 22605
diff changeset
269 const demuxer_desc_t demuxer_desc_roq = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
270 "RoQ demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
271 "roq",
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
272 "ROQ",
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
273 "Mike Melanson",
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
274 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
275 DEMUXER_TYPE_ROQ,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
276 0, // unsafe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
277 roq_check_file,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
278 demux_roq_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
279 demux_open_roq,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
280 demux_close_roq,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
281 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
282 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 10037
diff changeset
283 };