|
Lines 44-50
Link Here
|
| 44 |
#endif |
44 |
#endif |
| 45 |
|
45 |
|
| 46 |
#include <stdlib.h> |
46 |
#include <stdlib.h> |
|
|
47 |
#include <FLAC/export.h> |
| 48 |
|
| 49 |
/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ |
| 50 |
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
| 51 |
#define LEGACY_FLAC |
| 52 |
#else |
| 53 |
#undef LEGACY_FLAC |
| 54 |
#endif |
| 55 |
|
| 56 |
#ifdef LEGACY_FLAC |
| 47 |
#include <FLAC/seekable_stream_decoder.h> |
57 |
#include <FLAC/seekable_stream_decoder.h> |
|
|
58 |
#else |
| 59 |
#include <FLAC/stream_decoder.h> |
| 60 |
#endif |
| 48 |
#include <FLAC/metadata.h> |
61 |
#include <FLAC/metadata.h> |
| 49 |
|
62 |
|
| 50 |
#include "QF/cvar.h" |
63 |
#include "QF/cvar.h" |
|
Lines 56-62
Link Here
|
| 56 |
#include "snd_render.h" |
69 |
#include "snd_render.h" |
| 57 |
|
70 |
|
| 58 |
typedef struct { |
71 |
typedef struct { |
|
|
72 |
#ifdef LEGACY_FLAC |
| 59 |
FLAC__SeekableStreamDecoder *decoder; |
73 |
FLAC__SeekableStreamDecoder *decoder; |
|
|
74 |
#else |
| 75 |
FLAC__StreamDecoder *decoder; |
| 76 |
#endif |
| 60 |
QFile *file; |
77 |
QFile *file; |
| 61 |
FLAC__StreamMetadata_StreamInfo info; |
78 |
FLAC__StreamMetadata_StreamInfo info; |
| 62 |
FLAC__StreamMetadata *vorbis_info; |
79 |
FLAC__StreamMetadata *vorbis_info; |
|
Lines 66-121
Link Here
|
| 66 |
} flacfile_t; |
83 |
} flacfile_t; |
| 67 |
|
84 |
|
| 68 |
static void |
85 |
static void |
|
|
86 |
#ifdef LEGACY_FLAC |
| 69 |
error_func (const FLAC__SeekableStreamDecoder *decoder, |
87 |
error_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
88 |
#else |
| 89 |
error_func (const FLAC__StreamDecoder *decoder, |
| 90 |
#endif |
| 70 |
FLAC__StreamDecoderErrorStatus status, void *client_data) |
91 |
FLAC__StreamDecoderErrorStatus status, void *client_data) |
| 71 |
{ |
92 |
{ |
| 72 |
} |
93 |
} |
| 73 |
|
94 |
|
|
|
95 |
#ifdef LEGACY_FLAC |
| 74 |
static FLAC__SeekableStreamDecoderReadStatus |
96 |
static FLAC__SeekableStreamDecoderReadStatus |
| 75 |
read_func (const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], |
97 |
read_func (const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], |
| 76 |
unsigned *bytes, void *client_data) |
98 |
unsigned *bytes, void *client_data) |
|
|
99 |
#else |
| 100 |
static FLAC__StreamDecoderReadStatus |
| 101 |
read_func (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], |
| 102 |
size_t *bytes, void *client_data) |
| 103 |
#endif |
| 77 |
{ |
104 |
{ |
| 78 |
flacfile_t *ff = (flacfile_t *) client_data; |
105 |
flacfile_t *ff = (flacfile_t *) client_data; |
| 79 |
*bytes = Qread (ff->file, buffer, *bytes); |
106 |
*bytes = Qread (ff->file, buffer, *bytes); |
|
|
107 |
#ifdef LEGACY_FLAC |
| 80 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
108 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
|
|
109 |
#else |
| 110 |
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; |
| 111 |
#endif |
| 81 |
} |
112 |
} |
| 82 |
|
113 |
|
|
|
114 |
#ifdef LEGACY_FLAC |
| 83 |
static FLAC__SeekableStreamDecoderSeekStatus |
115 |
static FLAC__SeekableStreamDecoderSeekStatus |
| 84 |
seek_func (const FLAC__SeekableStreamDecoder *decoder, |
116 |
seek_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
117 |
#else |
| 118 |
static FLAC__StreamDecoderSeekStatus |
| 119 |
seek_func (const FLAC__StreamDecoder *decoder, |
| 120 |
#endif |
| 85 |
FLAC__uint64 absolute_byte_offset, void *client_data) |
121 |
FLAC__uint64 absolute_byte_offset, void *client_data) |
| 86 |
{ |
122 |
{ |
| 87 |
flacfile_t *ff = (flacfile_t *) client_data; |
123 |
flacfile_t *ff = (flacfile_t *) client_data; |
| 88 |
Qseek (ff->file, absolute_byte_offset, SEEK_SET); |
124 |
Qseek (ff->file, absolute_byte_offset, SEEK_SET); |
|
|
125 |
#ifdef LEGACY_FLAC |
| 89 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; |
126 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; |
|
|
127 |
#else |
| 128 |
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; |
| 129 |
#endif |
| 90 |
} |
130 |
} |
| 91 |
|
131 |
|
|
|
132 |
#ifdef LEGACY_FLAC |
| 92 |
static FLAC__SeekableStreamDecoderTellStatus |
133 |
static FLAC__SeekableStreamDecoderTellStatus |
| 93 |
tell_func (const FLAC__SeekableStreamDecoder *decoder, |
134 |
tell_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
135 |
#else |
| 136 |
static FLAC__StreamDecoderTellStatus |
| 137 |
tell_func (const FLAC__StreamDecoder *decoder, |
| 138 |
#endif |
| 94 |
FLAC__uint64 *absolute_byte_offset, void *client_data) |
139 |
FLAC__uint64 *absolute_byte_offset, void *client_data) |
| 95 |
{ |
140 |
{ |
| 96 |
flacfile_t *ff = (flacfile_t *) client_data; |
141 |
flacfile_t *ff = (flacfile_t *) client_data; |
| 97 |
*absolute_byte_offset = Qtell (ff->file); |
142 |
*absolute_byte_offset = Qtell (ff->file); |
|
|
143 |
#ifdef LEGACY_FLAC |
| 98 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
144 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
|
|
145 |
#else |
| 146 |
return FLAC__STREAM_DECODER_TELL_STATUS_OK; |
| 147 |
#endif |
| 99 |
} |
148 |
} |
| 100 |
|
149 |
|
|
|
150 |
#ifdef LEGACY_FLAC |
| 101 |
static FLAC__SeekableStreamDecoderLengthStatus |
151 |
static FLAC__SeekableStreamDecoderLengthStatus |
| 102 |
length_func (const FLAC__SeekableStreamDecoder *decoder, |
152 |
length_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
153 |
#else |
| 154 |
static FLAC__StreamDecoderLengthStatus |
| 155 |
length_func (const FLAC__StreamDecoder *decoder, |
| 156 |
#endif |
| 103 |
FLAC__uint64 *stream_length, void *client_data) |
157 |
FLAC__uint64 *stream_length, void *client_data) |
| 104 |
{ |
158 |
{ |
| 105 |
flacfile_t *ff = (flacfile_t *) client_data; |
159 |
flacfile_t *ff = (flacfile_t *) client_data; |
| 106 |
*stream_length = Qfilesize (ff->file); |
160 |
*stream_length = Qfilesize (ff->file); |
|
|
161 |
#ifdef LEGACY_FLAC |
| 107 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
162 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
|
|
163 |
#else |
| 164 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; |
| 165 |
#endif |
| 108 |
} |
166 |
} |
| 109 |
|
167 |
|
| 110 |
static FLAC__bool |
168 |
static FLAC__bool |
|
|
169 |
#ifdef LEGACY_FLAC |
| 111 |
eof_func (const FLAC__SeekableStreamDecoder *decoder, void *client_data) |
170 |
eof_func (const FLAC__SeekableStreamDecoder *decoder, void *client_data) |
|
|
171 |
#else |
| 172 |
eof_func (const FLAC__StreamDecoder *decoder, void *client_data) |
| 173 |
#endif |
| 112 |
{ |
174 |
{ |
| 113 |
flacfile_t *ff = (flacfile_t *) client_data; |
175 |
flacfile_t *ff = (flacfile_t *) client_data; |
| 114 |
return Qeof (ff->file); |
176 |
return Qeof (ff->file); |
| 115 |
} |
177 |
} |
| 116 |
|
178 |
|
| 117 |
static FLAC__StreamDecoderWriteStatus |
179 |
static FLAC__StreamDecoderWriteStatus |
|
|
180 |
#ifdef LEGACY_FLAC |
| 118 |
write_func (const FLAC__SeekableStreamDecoder *decoder, |
181 |
write_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
182 |
#else |
| 183 |
write_func (const FLAC__StreamDecoder *decoder, |
| 184 |
#endif |
| 119 |
const FLAC__Frame *frame, const FLAC__int32 * const buffer[], |
185 |
const FLAC__Frame *frame, const FLAC__int32 * const buffer[], |
| 120 |
void *client_data) |
186 |
void *client_data) |
| 121 |
{ |
187 |
{ |
|
Lines 168-174
Link Here
|
| 168 |
} |
234 |
} |
| 169 |
|
235 |
|
| 170 |
static void |
236 |
static void |
|
|
237 |
#ifdef LEGACY_FLAC |
| 171 |
meta_func (const FLAC__SeekableStreamDecoder *decoder, |
238 |
meta_func (const FLAC__SeekableStreamDecoder *decoder, |
|
|
239 |
#else |
| 240 |
meta_func (const FLAC__StreamDecoder *decoder, |
| 241 |
#endif |
| 172 |
const FLAC__StreamMetadata *metadata, void *client_data) |
242 |
const FLAC__StreamMetadata *metadata, void *client_data) |
| 173 |
{ |
243 |
{ |
| 174 |
flacfile_t *ff = (flacfile_t *) client_data; |
244 |
flacfile_t *ff = (flacfile_t *) client_data; |
|
Lines 182-190
Link Here
|
| 182 |
open_flac (QFile *file) |
252 |
open_flac (QFile *file) |
| 183 |
{ |
253 |
{ |
| 184 |
flacfile_t *ff = calloc (1, sizeof (flacfile_t)); |
254 |
flacfile_t *ff = calloc (1, sizeof (flacfile_t)); |
|
|
255 |
#ifdef LEGACY_FLAC |
| 185 |
ff->decoder = FLAC__seekable_stream_decoder_new (); |
256 |
ff->decoder = FLAC__seekable_stream_decoder_new (); |
|
|
257 |
#else |
| 258 |
ff->decoder = FLAC__stream_decoder_new (); |
| 259 |
#endif |
| 186 |
ff->file = file; |
260 |
ff->file = file; |
| 187 |
|
261 |
|
|
|
262 |
#ifdef LEGACY_FLAC |
| 188 |
FLAC__seekable_stream_decoder_set_error_callback (ff->decoder, error_func); |
263 |
FLAC__seekable_stream_decoder_set_error_callback (ff->decoder, error_func); |
| 189 |
FLAC__seekable_stream_decoder_set_read_callback (ff->decoder, read_func); |
264 |
FLAC__seekable_stream_decoder_set_read_callback (ff->decoder, read_func); |
| 190 |
FLAC__seekable_stream_decoder_set_seek_callback (ff->decoder, seek_func); |
265 |
FLAC__seekable_stream_decoder_set_seek_callback (ff->decoder, seek_func); |
|
Lines 201-214
Link Here
|
| 201 |
|
276 |
|
| 202 |
FLAC__seekable_stream_decoder_init (ff->decoder); |
277 |
FLAC__seekable_stream_decoder_init (ff->decoder); |
| 203 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata (ff->decoder); |
278 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata (ff->decoder); |
|
|
279 |
#else |
| 280 |
FLAC__stream_decoder_set_metadata_respond (ff->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); |
| 281 |
FLAC__stream_decoder_init_stream(ff->decoder, read_func, seek_func, tell_func, length_func, eof_func, write_func, meta_func, error_func, ff); |
| 282 |
FLAC__stream_decoder_process_until_end_of_metadata (ff->decoder); |
| 283 |
#endif |
| 204 |
return ff; |
284 |
return ff; |
| 205 |
} |
285 |
} |
| 206 |
|
286 |
|
| 207 |
static void |
287 |
static void |
| 208 |
close_flac (flacfile_t *ff) |
288 |
close_flac (flacfile_t *ff) |
| 209 |
{ |
289 |
{ |
|
|
290 |
#ifdef LEGACY_FLAC |
| 210 |
FLAC__seekable_stream_decoder_finish (ff->decoder); |
291 |
FLAC__seekable_stream_decoder_finish (ff->decoder); |
| 211 |
FLAC__seekable_stream_decoder_delete (ff->decoder); |
292 |
FLAC__seekable_stream_decoder_delete (ff->decoder); |
|
|
293 |
#else |
| 294 |
FLAC__stream_decoder_finish (ff->decoder); |
| 295 |
FLAC__stream_decoder_delete (ff->decoder); |
| 296 |
#endif |
| 212 |
|
297 |
|
| 213 |
if (ff->vorbis_info) |
298 |
if (ff->vorbis_info) |
| 214 |
FLAC__metadata_object_delete (ff->vorbis_info); |
299 |
FLAC__metadata_object_delete (ff->vorbis_info); |
|
Lines 229-235
Link Here
|
| 229 |
while (len) { |
314 |
while (len) { |
| 230 |
int res = 0; |
315 |
int res = 0; |
| 231 |
if (ff->size == ff->pos) |
316 |
if (ff->size == ff->pos) |
|
|
317 |
#ifdef LEGACY_FLAC |
| 232 |
FLAC__seekable_stream_decoder_process_single (ff->decoder); |
318 |
FLAC__seekable_stream_decoder_process_single (ff->decoder); |
|
|
319 |
#else |
| 320 |
FLAC__stream_decoder_process_single (ff->decoder); |
| 321 |
#endif |
| 233 |
res = ff->size - ff->pos; |
322 |
res = ff->size - ff->pos; |
| 234 |
if (res > len) |
323 |
if (res > len) |
| 235 |
res = len; |
324 |
res = len; |
|
Lines 343-349
Link Here
|
| 343 |
flacfile_t *ff = file; |
432 |
flacfile_t *ff = file; |
| 344 |
|
433 |
|
| 345 |
ff->pos = ff->size = 0; |
434 |
ff->pos = ff->size = 0; |
|
|
435 |
#ifdef LEGACY_FLAC |
| 346 |
return FLAC__seekable_stream_decoder_seek_absolute (ff->decoder, pos); |
436 |
return FLAC__seekable_stream_decoder_seek_absolute (ff->decoder, pos); |
|
|
437 |
#else |
| 438 |
return FLAC__stream_decoder_seek_absolute (ff->decoder, pos); |
| 439 |
#endif |
| 347 |
} |
440 |
} |
| 348 |
|
441 |
|
| 349 |
static void |
442 |
static void |