Lines 25-42
Link Here
|
25 |
#include <string.h> |
25 |
#include <string.h> |
26 |
#include <iostream> |
26 |
#include <iostream> |
27 |
|
27 |
|
28 |
#include <FLAC/format.h> |
|
|
29 |
#include <FLAC/seekable_stream_decoder.h> |
30 |
|
31 |
#ifdef HAVE_LIBOGGFLAC |
32 |
#include <OggFLAC/seekable_stream_decoder.h> |
33 |
#endif |
34 |
|
35 |
#include "audioframe.h" |
28 |
#include "audioframe.h" |
36 |
#include "decoder.h" |
29 |
#include "decoder.h" |
37 |
#include "file.h" |
30 |
#include "file.h" |
38 |
#include "flac_decoder.h" |
31 |
#include "flac_decoder.h" |
39 |
|
32 |
|
|
|
33 |
#include <FLAC/format.h> |
34 |
#ifdef LEGACY_FLAC |
35 |
#include <FLAC/seekable_stream_decoder.h> |
36 |
|
37 |
#ifdef HAVE_LIBOGGFLAC |
38 |
#include <OggFLAC/seekable_stream_decoder.h> |
39 |
#endif |
40 |
#else |
41 |
#include <FLAC/stream_decoder.h> |
42 |
#endif |
43 |
|
40 |
|
44 |
|
41 |
namespace aKode { |
45 |
namespace aKode { |
42 |
|
46 |
|
Lines 68-74
Link Here
|
68 |
|
72 |
|
69 |
extern "C" { FLACDecoderPlugin flac_decoder; } |
73 |
extern "C" { FLACDecoderPlugin flac_decoder; } |
70 |
|
74 |
|
71 |
#ifdef HAVE_LIBOGGFLAC |
75 |
// Starting with FLAC 1.1.3 libFLAC supports Ogg FLAC and there is no more libOggFLAC. |
|
|
76 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
72 |
bool OggFLACDecoderPlugin::canDecode(File* src) { |
77 |
bool OggFLACDecoderPlugin::canDecode(File* src) { |
73 |
char header[34]; |
78 |
char header[34]; |
74 |
bool res = false; |
79 |
bool res = false; |
Lines 89-95
Link Here
|
89 |
struct FLACDecoder::private_data { |
94 |
struct FLACDecoder::private_data { |
90 |
private_data() : decoder(0), valid(false), out(0), source(0), eof(false), error(false) {}; |
95 |
private_data() : decoder(0), valid(false), out(0), source(0), eof(false), error(false) {}; |
91 |
|
96 |
|
|
|
97 |
#ifdef LEGACY_FLAC |
92 |
FLAC__SeekableStreamDecoder *decoder; |
98 |
FLAC__SeekableStreamDecoder *decoder; |
|
|
99 |
#else |
100 |
FLAC__StreamDecoder *decoder; |
101 |
#endif |
93 |
const FLAC__StreamMetadata_StreamInfo* si; |
102 |
const FLAC__StreamMetadata_StreamInfo* si; |
94 |
const FLAC__StreamMetadata_VorbisComment* vc; |
103 |
const FLAC__StreamMetadata_VorbisComment* vc; |
95 |
|
104 |
|
Lines 104-114
Link Here
|
104 |
bool eof, error; |
113 |
bool eof, error; |
105 |
}; |
114 |
}; |
106 |
|
115 |
|
107 |
#ifdef HAVE_LIBOGGFLAC |
116 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
108 |
struct OggFLACDecoder::private_data { |
117 |
struct OggFLACDecoder::private_data { |
109 |
private_data() : decoder(0), valid(false), out(0), source(0), eof(false), error(false) {}; |
118 |
private_data() : decoder(0), valid(false), out(0), source(0), eof(false), error(false) {}; |
110 |
|
119 |
|
|
|
120 |
#ifdef LEGACY_FLAC |
111 |
OggFLAC__SeekableStreamDecoder *decoder; |
121 |
OggFLAC__SeekableStreamDecoder *decoder; |
|
|
122 |
#else |
123 |
FLAC__StreamDecoder *decoder; |
124 |
#endif |
112 |
const FLAC__StreamMetadata_StreamInfo* si; |
125 |
const FLAC__StreamMetadata_StreamInfo* si; |
113 |
const FLAC__StreamMetadata_VorbisComment* vc; |
126 |
const FLAC__StreamMetadata_VorbisComment* vc; |
114 |
|
127 |
|
Lines 124-149
Link Here
|
124 |
}; |
137 |
}; |
125 |
#endif |
138 |
#endif |
126 |
|
139 |
|
|
|
140 |
#ifdef LEGACY_FLAC |
127 |
static FLAC__SeekableStreamDecoderReadStatus flac_read_callback( |
141 |
static FLAC__SeekableStreamDecoderReadStatus flac_read_callback( |
128 |
const FLAC__SeekableStreamDecoder *, |
142 |
const FLAC__SeekableStreamDecoder *, |
129 |
FLAC__byte buffer[], |
143 |
FLAC__byte buffer[], |
130 |
unsigned *bytes, |
144 |
unsigned *bytes, |
131 |
void *client_data) |
145 |
void *client_data) |
|
|
146 |
#else |
147 |
static FLAC__StreamDecoderReadStatus flac_read_callback( |
148 |
const FLAC__StreamDecoder *, |
149 |
FLAC__byte buffer[], |
150 |
size_t *bytes, |
151 |
void *client_data) |
152 |
#endif |
132 |
{ |
153 |
{ |
133 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
154 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
134 |
|
155 |
|
135 |
long res = data->source->read((char*)buffer, *bytes); |
156 |
long res = data->source->read((char*)buffer, *bytes); |
136 |
if (res<=0) { |
157 |
if (res<=0) { |
137 |
if (data->source->eof()) data->eof = true; |
158 |
if (data->source->eof()) data->eof = true; |
|
|
159 |
#ifdef LEGACY_FLAC |
138 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; |
160 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; |
|
|
161 |
#else |
162 |
return FLAC__STREAM_DECODER_READ_STATUS_ABORT; |
163 |
#endif |
139 |
} |
164 |
} |
140 |
else { |
165 |
else { |
141 |
*bytes = res; |
166 |
*bytes = res; |
|
|
167 |
#ifdef LEGACY_FLAC |
142 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
168 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
|
|
169 |
#else |
170 |
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; |
171 |
#endif |
143 |
} |
172 |
} |
144 |
} |
173 |
} |
145 |
|
174 |
|
146 |
#ifdef HAVE_LIBOGGFLAC |
175 |
// we only need Ogg flavors of the callbacks for before FLAC 1.1.3 |
|
|
176 |
#if defined(HAVE_LIBOGGFLAC) && defined(LEGACY_FLAC) |
147 |
// God, I hate people doing OO in C! |
177 |
// God, I hate people doing OO in C! |
148 |
static OggFLAC__SeekableStreamDecoderReadStatus oggflac_read_callback( |
178 |
static OggFLAC__SeekableStreamDecoderReadStatus oggflac_read_callback( |
149 |
const OggFLAC__SeekableStreamDecoder *, |
179 |
const OggFLAC__SeekableStreamDecoder *, |
Lines 165-184
Link Here
|
165 |
} |
195 |
} |
166 |
#endif |
196 |
#endif |
167 |
|
197 |
|
|
|
198 |
#ifdef LEGACY_FLAC |
168 |
static FLAC__SeekableStreamDecoderSeekStatus flac_seek_callback( |
199 |
static FLAC__SeekableStreamDecoderSeekStatus flac_seek_callback( |
169 |
const FLAC__SeekableStreamDecoder *, |
200 |
const FLAC__SeekableStreamDecoder *, |
170 |
FLAC__uint64 absolute_byte_offset, |
201 |
FLAC__uint64 absolute_byte_offset, |
171 |
void *client_data) |
202 |
void *client_data) |
|
|
203 |
#else |
204 |
static FLAC__StreamDecoderSeekStatus flac_seek_callback( |
205 |
const FLAC__StreamDecoder *, |
206 |
FLAC__uint64 absolute_byte_offset, |
207 |
void *client_data) |
208 |
#endif |
172 |
{ |
209 |
{ |
173 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
210 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
174 |
|
211 |
|
175 |
if(data->source->seek(absolute_byte_offset)) |
212 |
if(data->source->seek(absolute_byte_offset)) |
|
|
213 |
#ifdef LEGACY_FLAC |
176 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; |
214 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; |
|
|
215 |
#else |
216 |
return FLAC__STREAM_DECODER_SEEK_STATUS_OK; |
217 |
#endif |
177 |
else |
218 |
else |
|
|
219 |
#ifdef LEGACY_FLAC |
178 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; |
220 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; |
|
|
221 |
#else |
222 |
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; |
223 |
#endif |
179 |
} |
224 |
} |
180 |
|
225 |
|
181 |
#ifdef HAVE_LIBOGGFLAC |
226 |
#if defined(HAVE_LIBOGGFLAC) && defined(LEGACY_FLAC) |
182 |
static OggFLAC__SeekableStreamDecoderSeekStatus oggflac_seek_callback( |
227 |
static OggFLAC__SeekableStreamDecoderSeekStatus oggflac_seek_callback( |
183 |
const OggFLAC__SeekableStreamDecoder *, |
228 |
const OggFLAC__SeekableStreamDecoder *, |
184 |
FLAC__uint64 absolute_byte_offset, |
229 |
FLAC__uint64 absolute_byte_offset, |
Lines 193-215
Link Here
|
193 |
} |
238 |
} |
194 |
#endif |
239 |
#endif |
195 |
|
240 |
|
|
|
241 |
#ifdef LEGACY_FLAC |
196 |
static FLAC__SeekableStreamDecoderTellStatus flac_tell_callback( |
242 |
static FLAC__SeekableStreamDecoderTellStatus flac_tell_callback( |
197 |
const FLAC__SeekableStreamDecoder *, |
243 |
const FLAC__SeekableStreamDecoder *, |
198 |
FLAC__uint64 *absolute_byte_offset, |
244 |
FLAC__uint64 *absolute_byte_offset, |
199 |
void *client_data) |
245 |
void *client_data) |
|
|
246 |
#else |
247 |
static FLAC__StreamDecoderTellStatus flac_tell_callback( |
248 |
const FLAC__StreamDecoder *, |
249 |
FLAC__uint64 *absolute_byte_offset, |
250 |
void *client_data) |
251 |
#endif |
200 |
{ |
252 |
{ |
201 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
253 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
202 |
|
254 |
|
203 |
long res = data->source->position(); |
255 |
long res = data->source->position(); |
204 |
if (res<0) |
256 |
if (res<0) |
|
|
257 |
#ifdef LEGACY_FLAC |
205 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR; |
258 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR; |
|
|
259 |
#else |
260 |
return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; |
261 |
#endif |
206 |
else { |
262 |
else { |
207 |
*absolute_byte_offset = res; |
263 |
*absolute_byte_offset = res; |
|
|
264 |
#ifdef LEGACY_FLAC |
208 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
265 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
|
|
266 |
#else |
267 |
return FLAC__STREAM_DECODER_TELL_STATUS_OK; |
268 |
#endif |
209 |
} |
269 |
} |
210 |
} |
270 |
} |
211 |
|
271 |
|
212 |
#ifdef HAVE_LIBOGGFLAC |
272 |
#if defined(HAVE_LIBOGGFLAC) && defined(LEGACY_FLAC) |
213 |
static OggFLAC__SeekableStreamDecoderTellStatus oggflac_tell_callback( |
273 |
static OggFLAC__SeekableStreamDecoderTellStatus oggflac_tell_callback( |
214 |
const OggFLAC__SeekableStreamDecoder *, |
274 |
const OggFLAC__SeekableStreamDecoder *, |
215 |
FLAC__uint64 *absolute_byte_offset, |
275 |
FLAC__uint64 *absolute_byte_offset, |
Lines 227-249
Link Here
|
227 |
} |
287 |
} |
228 |
#endif |
288 |
#endif |
229 |
|
289 |
|
|
|
290 |
#ifdef LEGACY_FLAC |
230 |
static FLAC__SeekableStreamDecoderLengthStatus flac_length_callback( |
291 |
static FLAC__SeekableStreamDecoderLengthStatus flac_length_callback( |
231 |
const FLAC__SeekableStreamDecoder *, |
292 |
const FLAC__SeekableStreamDecoder *, |
232 |
FLAC__uint64 *stream_length, |
293 |
FLAC__uint64 *stream_length, |
233 |
void *client_data) |
294 |
void *client_data) |
|
|
295 |
#else |
296 |
static FLAC__StreamDecoderLengthStatus flac_length_callback( |
297 |
const FLAC__StreamDecoder *, |
298 |
FLAC__uint64 *stream_length, |
299 |
void *client_data) |
300 |
#endif |
234 |
{ |
301 |
{ |
235 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
302 |
FLACDecoder::private_data *data = (FLACDecoder::private_data*)client_data; |
236 |
|
303 |
|
237 |
long res = data->source->length(); |
304 |
long res = data->source->length(); |
238 |
if (res<0) |
305 |
if (res<0) |
|
|
306 |
#ifdef LEGACY_FLAC |
239 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; |
307 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; |
|
|
308 |
#else |
309 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; |
310 |
#endif |
240 |
else { |
311 |
else { |
241 |
*stream_length = res; |
312 |
*stream_length = res; |
|
|
313 |
#ifdef LEGACY_FLAC |
242 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
314 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
|
|
315 |
#else |
316 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; |
317 |
#endif |
243 |
} |
318 |
} |
244 |
} |
319 |
} |
245 |
|
320 |
|
246 |
#ifdef HAVE_LIBOGGFLAC |
321 |
#if defined(HAVE_LIBOGGFLAC) && defined(LEGACY_FLAC) |
247 |
static OggFLAC__SeekableStreamDecoderLengthStatus oggflac_length_callback( |
322 |
static OggFLAC__SeekableStreamDecoderLengthStatus oggflac_length_callback( |
248 |
const OggFLAC__SeekableStreamDecoder *, |
323 |
const OggFLAC__SeekableStreamDecoder *, |
249 |
FLAC__uint64 *stream_length, |
324 |
FLAC__uint64 *stream_length, |
Lines 372-377
Link Here
|
372 |
break; |
447 |
break; |
373 |
case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH: |
448 |
case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH: |
374 |
break; |
449 |
break; |
|
|
450 |
#ifndef LEGACY_FLAC |
451 |
case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM: |
452 |
break; |
453 |
#endif |
375 |
} |
454 |
} |
376 |
//data->valid = false; |
455 |
//data->valid = false; |
377 |
} |
456 |
} |
Lines 380-386
Link Here
|
380 |
return &m_data->config; |
459 |
return &m_data->config; |
381 |
} |
460 |
} |
382 |
|
461 |
|
383 |
#ifdef HAVE_LIBOGGFLAC |
462 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
384 |
const AudioConfiguration* OggFLACDecoder::audioConfiguration() { |
463 |
const AudioConfiguration* OggFLACDecoder::audioConfiguration() { |
385 |
return &m_data->config; |
464 |
return &m_data->config; |
386 |
} |
465 |
} |
Lines 389-398
Link Here
|
389 |
FLACDecoder::FLACDecoder(File* src) { |
468 |
FLACDecoder::FLACDecoder(File* src) { |
390 |
m_data = new private_data; |
469 |
m_data = new private_data; |
391 |
m_data->out = 0; |
470 |
m_data->out = 0; |
392 |
m_data->decoder = FLAC__seekable_stream_decoder_new(); |
|
|
393 |
m_data->source = src; |
471 |
m_data->source = src; |
394 |
m_data->source->openRO(); |
472 |
m_data->source->openRO(); |
395 |
m_data->source->fadvise(); |
473 |
m_data->source->fadvise(); |
|
|
474 |
#ifdef LEGACY_FLAC |
475 |
m_data->decoder = FLAC__seekable_stream_decoder_new(); |
396 |
FLAC__seekable_stream_decoder_set_client_data(m_data->decoder, m_data); |
476 |
FLAC__seekable_stream_decoder_set_client_data(m_data->decoder, m_data); |
397 |
FLAC__seekable_stream_decoder_set_read_callback (m_data->decoder, flac_read_callback); |
477 |
FLAC__seekable_stream_decoder_set_read_callback (m_data->decoder, flac_read_callback); |
398 |
FLAC__seekable_stream_decoder_set_seek_callback (m_data->decoder, flac_seek_callback); |
478 |
FLAC__seekable_stream_decoder_set_seek_callback (m_data->decoder, flac_seek_callback); |
Lines 408-432
Link Here
|
408 |
metadata_callback<FLAC__SeekableStreamDecoder, private_data>); |
488 |
metadata_callback<FLAC__SeekableStreamDecoder, private_data>); |
409 |
FLAC__seekable_stream_decoder_set_metadata_respond (m_data->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); |
489 |
FLAC__seekable_stream_decoder_set_metadata_respond (m_data->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); |
410 |
|
490 |
|
411 |
FLAC__seekable_stream_decoder_init(m_data->decoder); |
491 |
FLAC__seekable_stream_decoder_init(m_data->decoder); // really should check the return value here |
412 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata(m_data->decoder); |
492 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata(m_data->decoder); |
|
|
493 |
#else |
494 |
m_data->decoder = FLAC__stream_decoder_new(); |
495 |
FLAC__stream_decoder_set_metadata_respond (m_data->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); |
496 |
|
497 |
// really should check the return value here |
498 |
FLAC__stream_decoder_init_stream( |
499 |
m_data->decoder, |
500 |
flac_read_callback, |
501 |
flac_seek_callback, |
502 |
flac_tell_callback, |
503 |
flac_length_callback, |
504 |
eof_callback<FLAC__StreamDecoder, private_data>, |
505 |
write_callback<FLAC__StreamDecoder, private_data>, |
506 |
metadata_callback<FLAC__StreamDecoder, private_data>, |
507 |
error_callback<FLAC__StreamDecoder, private_data>, |
508 |
m_data |
509 |
); |
510 |
FLAC__stream_decoder_process_until_end_of_metadata(m_data->decoder); |
511 |
#endif |
413 |
} |
512 |
} |
414 |
|
513 |
|
415 |
FLACDecoder::~FLACDecoder() { |
514 |
FLACDecoder::~FLACDecoder() { |
|
|
515 |
#ifdef LEGACY_FLAC |
416 |
FLAC__seekable_stream_decoder_finish(m_data->decoder); |
516 |
FLAC__seekable_stream_decoder_finish(m_data->decoder); |
417 |
FLAC__seekable_stream_decoder_delete(m_data->decoder); |
517 |
FLAC__seekable_stream_decoder_delete(m_data->decoder); |
|
|
518 |
#else |
519 |
FLAC__stream_decoder_finish(m_data->decoder); |
520 |
FLAC__stream_decoder_delete(m_data->decoder); |
521 |
#endif |
418 |
m_data->source->close(); |
522 |
m_data->source->close(); |
419 |
delete m_data; |
523 |
delete m_data; |
420 |
} |
524 |
} |
421 |
|
525 |
|
422 |
#ifdef HAVE_LIBOGGFLAC |
526 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
423 |
OggFLACDecoder::OggFLACDecoder(File* src) { |
527 |
OggFLACDecoder::OggFLACDecoder(File* src) { |
424 |
m_data = new private_data; |
528 |
m_data = new private_data; |
425 |
m_data->out = 0; |
529 |
m_data->out = 0; |
426 |
m_data->decoder = OggFLAC__seekable_stream_decoder_new(); |
|
|
427 |
m_data->source = src; |
530 |
m_data->source = src; |
428 |
m_data->source->openRO(); |
531 |
m_data->source->openRO(); |
429 |
m_data->source->fadvise(); |
532 |
m_data->source->fadvise(); |
|
|
533 |
#ifdef LEGACY_FLAC |
534 |
m_data->decoder = OggFLAC__seekable_stream_decoder_new(); |
430 |
OggFLAC__seekable_stream_decoder_set_client_data(m_data->decoder, m_data); |
535 |
OggFLAC__seekable_stream_decoder_set_client_data(m_data->decoder, m_data); |
431 |
OggFLAC__seekable_stream_decoder_set_read_callback (m_data->decoder, oggflac_read_callback); |
536 |
OggFLAC__seekable_stream_decoder_set_read_callback (m_data->decoder, oggflac_read_callback); |
432 |
OggFLAC__seekable_stream_decoder_set_seek_callback (m_data->decoder, oggflac_seek_callback); |
537 |
OggFLAC__seekable_stream_decoder_set_seek_callback (m_data->decoder, oggflac_seek_callback); |
Lines 444-454
Link Here
|
444 |
|
549 |
|
445 |
OggFLAC__seekable_stream_decoder_init(m_data->decoder); |
550 |
OggFLAC__seekable_stream_decoder_init(m_data->decoder); |
446 |
OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(m_data->decoder); |
551 |
OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(m_data->decoder); |
|
|
552 |
#else |
553 |
m_data->decoder = FLAC__stream_decoder_new(); |
554 |
FLAC__stream_decoder_set_metadata_respond (m_data->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); |
555 |
|
556 |
// really should check the return value here |
557 |
FLAC__stream_decoder_init_ogg_stream( |
558 |
m_data->decoder, |
559 |
flac_read_callback, |
560 |
flac_seek_callback, |
561 |
flac_tell_callback, |
562 |
flac_length_callback, |
563 |
eof_callback<FLAC__StreamDecoder, private_data>, |
564 |
write_callback<FLAC__StreamDecoder, private_data>, |
565 |
metadata_callback<FLAC__StreamDecoder, private_data>, |
566 |
error_callback<FLAC__StreamDecoder, private_data>, |
567 |
m_data |
568 |
); |
569 |
FLAC__stream_decoder_process_until_end_of_metadata(m_data->decoder); |
570 |
#endif |
447 |
} |
571 |
} |
448 |
|
572 |
|
449 |
OggFLACDecoder::~OggFLACDecoder() { |
573 |
OggFLACDecoder::~OggFLACDecoder() { |
|
|
574 |
#ifdef LEGACY_FLAC |
450 |
OggFLAC__seekable_stream_decoder_finish(m_data->decoder); |
575 |
OggFLAC__seekable_stream_decoder_finish(m_data->decoder); |
451 |
OggFLAC__seekable_stream_decoder_delete(m_data->decoder); |
576 |
OggFLAC__seekable_stream_decoder_delete(m_data->decoder); |
|
|
577 |
#else |
578 |
FLAC__stream_decoder_finish(m_data->decoder); |
579 |
FLAC__stream_decoder_delete(m_data->decoder); |
580 |
#endif |
452 |
m_data->source->close(); |
581 |
m_data->source->close(); |
453 |
delete m_data; |
582 |
delete m_data; |
454 |
} |
583 |
} |
Lines 467-478
Link Here
|
467 |
} |
596 |
} |
468 |
m_data->valid = false; |
597 |
m_data->valid = false; |
469 |
m_data->out = frame; |
598 |
m_data->out = frame; |
|
|
599 |
#ifdef LEGACY_FLAC |
470 |
bool ret = FLAC__seekable_stream_decoder_process_single(m_data->decoder); |
600 |
bool ret = FLAC__seekable_stream_decoder_process_single(m_data->decoder); |
|
|
601 |
#else |
602 |
bool ret = FLAC__stream_decoder_process_single(m_data->decoder); |
603 |
#endif |
471 |
m_data->out = 0; |
604 |
m_data->out = 0; |
472 |
if (ret && m_data->valid) { |
605 |
if (ret && m_data->valid) { |
473 |
frame->pos = position(); |
606 |
frame->pos = position(); |
474 |
return true; |
607 |
return true; |
475 |
} else { |
608 |
} else { |
|
|
609 |
#ifdef LEGACY_FLAC |
476 |
FLAC__SeekableStreamDecoderState state = FLAC__seekable_stream_decoder_get_state(m_data->decoder); |
610 |
FLAC__SeekableStreamDecoderState state = FLAC__seekable_stream_decoder_get_state(m_data->decoder); |
477 |
switch (state) { |
611 |
switch (state) { |
478 |
case FLAC__SEEKABLE_STREAM_DECODER_OK: |
612 |
case FLAC__SEEKABLE_STREAM_DECODER_OK: |
Lines 484-494
Link Here
|
484 |
m_data->error = true; |
618 |
m_data->error = true; |
485 |
break; |
619 |
break; |
486 |
} |
620 |
} |
|
|
621 |
#else |
622 |
FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(m_data->decoder); |
623 |
if (state == FLAC__STREAM_DECODER_END_OF_STREAM) |
624 |
m_data->eof = true; |
625 |
else if (state > FLAC__STREAM_DECODER_END_OF_STREAM) |
626 |
m_data->error = true; |
627 |
#endif |
487 |
return false; |
628 |
return false; |
488 |
} |
629 |
} |
489 |
} |
630 |
} |
490 |
|
631 |
|
491 |
#ifdef HAVE_LIBOGGFLAC |
632 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
492 |
bool OggFLACDecoder::readFrame(AudioFrame* frame) { |
633 |
bool OggFLACDecoder::readFrame(AudioFrame* frame) { |
493 |
if (m_data->error || m_data->eof) return false; |
634 |
if (m_data->error || m_data->eof) return false; |
494 |
|
635 |
|
Lines 502-513
Link Here
|
502 |
} |
643 |
} |
503 |
m_data->valid = false; |
644 |
m_data->valid = false; |
504 |
m_data->out = frame; |
645 |
m_data->out = frame; |
|
|
646 |
#ifdef LEGACY_FLAC |
505 |
bool ret = OggFLAC__seekable_stream_decoder_process_single(m_data->decoder); |
647 |
bool ret = OggFLAC__seekable_stream_decoder_process_single(m_data->decoder); |
|
|
648 |
#else |
649 |
bool ret = FLAC__stream_decoder_process_single(m_data->decoder); |
650 |
#endif |
506 |
m_data->out = 0; |
651 |
m_data->out = 0; |
507 |
if (ret && m_data->valid) { |
652 |
if (ret && m_data->valid) { |
508 |
frame->pos = position(); |
653 |
frame->pos = position(); |
509 |
return true; |
654 |
return true; |
510 |
} else { |
655 |
} else { |
|
|
656 |
#ifdef LEGACY_FLAC |
511 |
OggFLAC__SeekableStreamDecoderState state = OggFLAC__seekable_stream_decoder_get_state(m_data->decoder); |
657 |
OggFLAC__SeekableStreamDecoderState state = OggFLAC__seekable_stream_decoder_get_state(m_data->decoder); |
512 |
switch (state) { |
658 |
switch (state) { |
513 |
case OggFLAC__SEEKABLE_STREAM_DECODER_OK: |
659 |
case OggFLAC__SEEKABLE_STREAM_DECODER_OK: |
Lines 519-524
Link Here
|
519 |
m_data->error = true; |
665 |
m_data->error = true; |
520 |
break; |
666 |
break; |
521 |
} |
667 |
} |
|
|
668 |
#else |
669 |
FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(m_data->decoder); |
670 |
if (state == FLAC__STREAM_DECODER_END_OF_STREAM) |
671 |
m_data->eof = true; |
672 |
else if (state > FLAC__STREAM_DECODER_END_OF_STREAM) |
673 |
m_data->error = true; |
674 |
#endif |
522 |
return false; |
675 |
return false; |
523 |
} |
676 |
} |
524 |
} |
677 |
} |
Lines 550-559
Link Here
|
550 |
if (m_data->error) return false; |
703 |
if (m_data->error) return false; |
551 |
float samplePos = (float)pos * (float)m_data->config.sample_rate / 1000.0; |
704 |
float samplePos = (float)pos * (float)m_data->config.sample_rate / 1000.0; |
552 |
m_data->position = (uint64_t)samplePos; |
705 |
m_data->position = (uint64_t)samplePos; |
|
|
706 |
#ifdef LEGACY_FLAC |
553 |
return FLAC__seekable_stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
707 |
return FLAC__seekable_stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
|
|
708 |
#else |
709 |
return FLAC__stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
710 |
#endif |
554 |
} |
711 |
} |
555 |
|
712 |
|
556 |
#ifdef HAVE_LIBOGGFLAC |
713 |
#if defined(HAVE_LIBOGGFLAC) || !defined(LEGACY_FLAC) |
557 |
long OggFLACDecoder::length() { |
714 |
long OggFLACDecoder::length() { |
558 |
float pos = ((float)m_data->length)/m_data->config.sample_rate; |
715 |
float pos = ((float)m_data->length)/m_data->config.sample_rate; |
559 |
return (long)(pos*1000.0); |
716 |
return (long)(pos*1000.0); |
Lines 580-586
Link Here
|
580 |
if (m_data->error) return false; |
737 |
if (m_data->error) return false; |
581 |
float samplePos = (float)pos * (float)m_data->config.sample_rate / 1000.0; |
738 |
float samplePos = (float)pos * (float)m_data->config.sample_rate / 1000.0; |
582 |
m_data->position = (uint64_t)samplePos; |
739 |
m_data->position = (uint64_t)samplePos; |
|
|
740 |
#ifdef LEGACY_FLAC |
583 |
return OggFLAC__seekable_stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
741 |
return OggFLAC__seekable_stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
|
|
742 |
#else |
743 |
return FLAC__stream_decoder_seek_absolute(m_data->decoder, m_data->position); |
744 |
#endif |
584 |
} |
745 |
} |
585 |
#endif |
746 |
#endif |
586 |
|
747 |
|