Lines 31-37
Link Here
|
31 |
#include "sound/audiocd.h" |
31 |
#include "sound/audiocd.h" |
32 |
|
32 |
|
33 |
#define FLAC__NO_DLL // that MS-magic gave me headaches - just link the library you like |
33 |
#define FLAC__NO_DLL // that MS-magic gave me headaches - just link the library you like |
|
|
34 |
#include <FLAC/export.h> |
35 |
// check if we have FLAC >= 1.1.3; LEGACY_FLAC code can be removed once FLAC-1.1.3 propagates everywhere |
36 |
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
37 |
#define LEGACY_FLAC |
38 |
#else |
39 |
#undef LEGACY_FLAC |
40 |
#endif |
41 |
#ifdef LEGACY_FLAC |
34 |
#include <FLAC/seekable_stream_decoder.h> |
42 |
#include <FLAC/seekable_stream_decoder.h> |
|
|
43 |
#else |
44 |
#include <FLAC/stream_decoder.h> |
45 |
#endif |
35 |
|
46 |
|
36 |
|
47 |
|
37 |
using Common::File; |
48 |
using Common::File; |
Lines 67-73
Link Here
|
67 |
|
78 |
|
68 |
const FLAC__StreamMetadata_StreamInfo& getStreamInfo() const {return _streaminfo;} |
79 |
const FLAC__StreamMetadata_StreamInfo& getStreamInfo() const {return _streaminfo;} |
69 |
|
80 |
|
|
|
81 |
#ifdef LEGACY_FLAC |
70 |
inline FLAC__SeekableStreamDecoderState getState() const; |
82 |
inline FLAC__SeekableStreamDecoderState getState() const; |
|
|
83 |
#else |
84 |
inline FLAC__StreamDecoderState getState() const; |
85 |
#endif |
71 |
inline FLAC__StreamDecoderState getStreamDecoderState() const; |
86 |
inline FLAC__StreamDecoderState getStreamDecoderState() const; |
72 |
|
87 |
|
73 |
|
88 |
|
Lines 81-98
Link Here
|
81 |
inline void setLastSample(FLAC__uint64 absoluteSample); |
96 |
inline void setLastSample(FLAC__uint64 absoluteSample); |
82 |
|
97 |
|
83 |
protected: |
98 |
protected: |
|
|
99 |
#ifdef LEGACY_FLAC |
84 |
inline ::FLAC__SeekableStreamDecoderReadStatus callbackRead(FLAC__byte buffer[], uint *bytes); |
100 |
inline ::FLAC__SeekableStreamDecoderReadStatus callbackRead(FLAC__byte buffer[], uint *bytes); |
85 |
inline ::FLAC__SeekableStreamDecoderSeekStatus callbackSeek(FLAC__uint64 absoluteByteOffset); |
101 |
inline ::FLAC__SeekableStreamDecoderSeekStatus callbackSeek(FLAC__uint64 absoluteByteOffset); |
86 |
inline ::FLAC__SeekableStreamDecoderTellStatus callbackTell(FLAC__uint64 *absoluteByteOffset); |
102 |
inline ::FLAC__SeekableStreamDecoderTellStatus callbackTell(FLAC__uint64 *absoluteByteOffset); |
87 |
inline ::FLAC__SeekableStreamDecoderLengthStatus callbackLength(FLAC__uint64 *streamLength); |
103 |
inline ::FLAC__SeekableStreamDecoderLengthStatus callbackLength(FLAC__uint64 *streamLength); |
|
|
104 |
#else |
105 |
inline ::FLAC__StreamDecoderReadStatus callbackRead(FLAC__byte buffer[], size_t *bytes); |
106 |
inline ::FLAC__StreamDecoderSeekStatus callbackSeek(FLAC__uint64 absoluteByteOffset); |
107 |
inline ::FLAC__StreamDecoderTellStatus callbackTell(FLAC__uint64 *absoluteByteOffset); |
108 |
inline ::FLAC__StreamDecoderLengthStatus callbackLength(FLAC__uint64 *streamLength); |
109 |
#endif |
88 |
inline bool callbackEOF(); |
110 |
inline bool callbackEOF(); |
89 |
inline ::FLAC__StreamDecoderWriteStatus callbackWrite(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); |
111 |
inline ::FLAC__StreamDecoderWriteStatus callbackWrite(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); |
90 |
inline void callbackMetadata(const ::FLAC__StreamMetadata *metadata); |
112 |
inline void callbackMetadata(const ::FLAC__StreamMetadata *metadata); |
91 |
inline void callbackError(::FLAC__StreamDecoderErrorStatus status); |
113 |
inline void callbackError(::FLAC__StreamDecoderErrorStatus status); |
92 |
|
114 |
|
|
|
115 |
#ifdef LEGACY_FLAC |
93 |
::FLAC__SeekableStreamDecoder *_decoder; |
116 |
::FLAC__SeekableStreamDecoder *_decoder; |
|
|
117 |
#else |
118 |
::FLAC__StreamDecoder *_decoder; |
119 |
#endif |
94 |
|
120 |
|
95 |
private: |
121 |
private: |
|
|
122 |
#ifdef LEGACY_FLAC |
96 |
static ::FLAC__SeekableStreamDecoderReadStatus callWrapRead(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], uint *bytes, void *clientData); |
123 |
static ::FLAC__SeekableStreamDecoderReadStatus callWrapRead(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], uint *bytes, void *clientData); |
97 |
static ::FLAC__SeekableStreamDecoderSeekStatus callWrapSeek(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData); |
124 |
static ::FLAC__SeekableStreamDecoderSeekStatus callWrapSeek(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData); |
98 |
static ::FLAC__SeekableStreamDecoderTellStatus callWrapTell(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData); |
125 |
static ::FLAC__SeekableStreamDecoderTellStatus callWrapTell(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData); |
Lines 101-106
Link Here
|
101 |
static ::FLAC__StreamDecoderWriteStatus callWrapWrite(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData); |
128 |
static ::FLAC__StreamDecoderWriteStatus callWrapWrite(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData); |
102 |
static void callWrapMetadata(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData); |
129 |
static void callWrapMetadata(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData); |
103 |
static void callWrapError(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData); |
130 |
static void callWrapError(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData); |
|
|
131 |
#else |
132 |
static ::FLAC__StreamDecoderReadStatus callWrapRead(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *clientData); |
133 |
static ::FLAC__StreamDecoderSeekStatus callWrapSeek(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData); |
134 |
static ::FLAC__StreamDecoderTellStatus callWrapTell(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData); |
135 |
static ::FLAC__StreamDecoderLengthStatus callWrapLength(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *streamLength, void *clientData); |
136 |
static FLAC__bool callWrapEOF(const ::FLAC__StreamDecoder *decoder, void *clientData); |
137 |
static ::FLAC__StreamDecoderWriteStatus callWrapWrite(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData); |
138 |
static void callWrapMetadata(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData); |
139 |
static void callWrapError(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData); |
140 |
#endif |
104 |
// Private and undefined so you can't use them: |
141 |
// Private and undefined so you can't use them: |
105 |
FlacInputStream(const FlacInputStream &); |
142 |
FlacInputStream(const FlacInputStream &); |
106 |
void operator=(const FlacInputStream &); |
143 |
void operator=(const FlacInputStream &); |
Lines 157-163
Link Here
|
157 |
}; |
194 |
}; |
158 |
|
195 |
|
159 |
FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart) |
196 |
FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart) |
160 |
: _decoder(::FLAC__seekable_stream_decoder_new()), _firstSample(0), _lastSample(0), |
197 |
#ifdef LEGACY_FLAC |
|
|
198 |
: _decoder(::FLAC__seekable_stream_decoder_new()), |
199 |
#else |
200 |
: _decoder(::FLAC__stream_decoder_new()), |
201 |
#endif |
202 |
_firstSample(0), _lastSample(0), |
161 |
_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(true), |
203 |
_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(true), |
162 |
_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric) |
204 |
_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric) |
163 |
{ |
205 |
{ |
Lines 178-184
Link Here
|
178 |
} |
220 |
} |
179 |
|
221 |
|
180 |
FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart, const uint32 fileStop) |
222 |
FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart, const uint32 fileStop) |
181 |
: _decoder(::FLAC__seekable_stream_decoder_new()), _firstSample(0), _lastSample(0), |
223 |
#ifdef LEGACY_FLAC |
|
|
224 |
: _decoder(::FLAC__seekable_stream_decoder_new()), |
225 |
#else |
226 |
: _decoder(::FLAC__stream_decoder_new()), |
227 |
#endif |
228 |
_firstSample(0), _lastSample(0), |
182 |
_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(true), |
229 |
_outBuffer(NULL), _requestedSamples(0), _lastSampleWritten(true), |
183 |
_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric) |
230 |
_methodConvertBuffers(&FlacInputStream::convertBuffersGeneric) |
184 |
{ |
231 |
{ |
Lines 201-208
Link Here
|
201 |
|
248 |
|
202 |
FlacInputStream::~FlacInputStream() { |
249 |
FlacInputStream::~FlacInputStream() { |
203 |
if (_decoder != NULL) { |
250 |
if (_decoder != NULL) { |
|
|
251 |
#ifdef LEGACY_FLAC |
204 |
(void) ::FLAC__seekable_stream_decoder_finish(_decoder); |
252 |
(void) ::FLAC__seekable_stream_decoder_finish(_decoder); |
205 |
::FLAC__seekable_stream_decoder_delete(_decoder); |
253 |
::FLAC__seekable_stream_decoder_delete(_decoder); |
|
|
254 |
#else |
255 |
(void) ::FLAC__stream_decoder_finish(_decoder); |
256 |
::FLAC__stream_decoder_delete(_decoder); |
257 |
#endif |
206 |
} |
258 |
} |
207 |
if (_preBuffer.bufData != NULL) |
259 |
if (_preBuffer.bufData != NULL) |
208 |
delete[] _preBuffer.bufData; |
260 |
delete[] _preBuffer.bufData; |
Lines 210-223
Link Here
|
210 |
_fileInfo.fileHandle->decRef(); |
262 |
_fileInfo.fileHandle->decRef(); |
211 |
} |
263 |
} |
212 |
|
264 |
|
213 |
inline FLAC__SeekableStreamDecoderState FlacInputStream::getState() const { |
265 |
#ifdef LEGACY_FLAC |
|
|
266 |
inline FLAC__SeekableStreamDecoderState FlacInputStream::getState() const |
267 |
#else |
268 |
inline FLAC__StreamDecoderState FlacInputStream::getState() const |
269 |
#endif |
270 |
{ |
214 |
assert(isValid()); |
271 |
assert(isValid()); |
|
|
272 |
#ifdef LEGACY_FLAC |
215 |
return ::FLAC__seekable_stream_decoder_get_state(_decoder); |
273 |
return ::FLAC__seekable_stream_decoder_get_state(_decoder); |
|
|
274 |
#else |
275 |
return ::FLAC__stream_decoder_get_state(_decoder); |
276 |
#endif |
216 |
} |
277 |
} |
217 |
|
278 |
|
218 |
inline FLAC__StreamDecoderState FlacInputStream::getStreamDecoderState() const { |
279 |
inline FLAC__StreamDecoderState FlacInputStream::getStreamDecoderState() const { |
219 |
assert(isValid()); |
280 |
assert(isValid()); |
|
|
281 |
#ifdef LEGACY_FLAC |
220 |
return ::FLAC__seekable_stream_decoder_get_stream_decoder_state(_decoder); |
282 |
return ::FLAC__seekable_stream_decoder_get_stream_decoder_state(_decoder); |
|
|
283 |
#else |
284 |
return ::FLAC__stream_decoder_get_state(_decoder); |
285 |
#endif |
221 |
} |
286 |
} |
222 |
|
287 |
|
223 |
bool FlacInputStream::init() { |
288 |
bool FlacInputStream::init() { |
Lines 229-234
Link Here
|
229 |
_lastSampleWritten = false; |
294 |
_lastSampleWritten = false; |
230 |
_methodConvertBuffers = &FlacInputStream::convertBuffersGeneric; |
295 |
_methodConvertBuffers = &FlacInputStream::convertBuffersGeneric; |
231 |
|
296 |
|
|
|
297 |
#ifdef LEGACY_FLAC |
232 |
::FLAC__seekable_stream_decoder_set_read_callback(_decoder, &FlacInputStream::callWrapRead); |
298 |
::FLAC__seekable_stream_decoder_set_read_callback(_decoder, &FlacInputStream::callWrapRead); |
233 |
::FLAC__seekable_stream_decoder_set_seek_callback(_decoder, &FlacInputStream::callWrapSeek); |
299 |
::FLAC__seekable_stream_decoder_set_seek_callback(_decoder, &FlacInputStream::callWrapSeek); |
234 |
::FLAC__seekable_stream_decoder_set_tell_callback(_decoder, &FlacInputStream::callWrapTell); |
300 |
::FLAC__seekable_stream_decoder_set_tell_callback(_decoder, &FlacInputStream::callWrapTell); |
Lines 247-252
Link Here
|
247 |
} |
313 |
} |
248 |
} |
314 |
} |
249 |
} |
315 |
} |
|
|
316 |
#else |
317 |
if (::FLAC__stream_decoder_init_stream( |
318 |
_decoder, |
319 |
&FlacInputStream::callWrapRead, |
320 |
&FlacInputStream::callWrapSeek, |
321 |
&FlacInputStream::callWrapTell, |
322 |
&FlacInputStream::callWrapLength, |
323 |
&FlacInputStream::callWrapEOF, |
324 |
&FlacInputStream::callWrapWrite, |
325 |
&FlacInputStream::callWrapMetadata, |
326 |
&FlacInputStream::callWrapError, |
327 |
(void*)this |
328 |
) == FLAC__STREAM_DECODER_INIT_STATUS_OK) { |
329 |
if (processUntilEndOfMetadata() && _streaminfo.channels > 0) { |
330 |
if (_firstSample == 0 || 0 != ::FLAC__stream_decoder_seek_absolute(_decoder, _firstSample)) { |
331 |
// FLAC__StreamDecoderState state = getStreamDecoderState(); |
332 |
return true; // no error occured |
333 |
} |
334 |
} |
335 |
} |
336 |
#endif |
250 |
|
337 |
|
251 |
warning("FlacInputStream: could not create an Audiostream from File %s", _fileInfo.fileHandle->name()); |
338 |
warning("FlacInputStream: could not create an Audiostream from File %s", _fileInfo.fileHandle->name()); |
252 |
return false; |
339 |
return false; |
Lines 255-282
Link Here
|
255 |
bool FlacInputStream::finish() { |
342 |
bool FlacInputStream::finish() { |
256 |
assert(isValid()); |
343 |
assert(isValid()); |
257 |
deleteBuffer(); |
344 |
deleteBuffer(); |
|
|
345 |
#ifdef LEGACY_FLAC |
258 |
return 0 != ::FLAC__seekable_stream_decoder_finish(_decoder); |
346 |
return 0 != ::FLAC__seekable_stream_decoder_finish(_decoder); |
|
|
347 |
#else |
348 |
return 0 != ::FLAC__stream_decoder_finish(_decoder); |
349 |
#endif |
259 |
} |
350 |
} |
260 |
|
351 |
|
261 |
bool FlacInputStream::flush() { |
352 |
bool FlacInputStream::flush() { |
262 |
assert(isValid()); |
353 |
assert(isValid()); |
263 |
flushBuffer(); |
354 |
flushBuffer(); |
|
|
355 |
#ifdef LEGACY_FLAC |
264 |
return 0 != ::FLAC__seekable_stream_decoder_flush(_decoder); |
356 |
return 0 != ::FLAC__seekable_stream_decoder_flush(_decoder); |
|
|
357 |
#else |
358 |
return 0 != ::FLAC__stream_decoder_flush(_decoder); |
359 |
#endif |
265 |
} |
360 |
} |
266 |
|
361 |
|
267 |
inline bool FlacInputStream::processSingleBlock() { |
362 |
inline bool FlacInputStream::processSingleBlock() { |
268 |
assert(isValid()); |
363 |
assert(isValid()); |
|
|
364 |
#ifdef LEGACY_FLAC |
269 |
return 0 != ::FLAC__seekable_stream_decoder_process_single(_decoder); |
365 |
return 0 != ::FLAC__seekable_stream_decoder_process_single(_decoder); |
|
|
366 |
#else |
367 |
return 0 != ::FLAC__stream_decoder_process_single(_decoder); |
368 |
#endif |
270 |
} |
369 |
} |
271 |
|
370 |
|
272 |
inline bool FlacInputStream::processUntilEndOfMetadata() { |
371 |
inline bool FlacInputStream::processUntilEndOfMetadata() { |
273 |
assert(isValid()); |
372 |
assert(isValid()); |
|
|
373 |
#ifdef LEGACY_FLAC |
274 |
return 0 != ::FLAC__seekable_stream_decoder_process_until_end_of_metadata(_decoder); |
374 |
return 0 != ::FLAC__seekable_stream_decoder_process_until_end_of_metadata(_decoder); |
|
|
375 |
#else |
376 |
return 0 != ::FLAC__stream_decoder_process_until_end_of_metadata(_decoder); |
377 |
#endif |
275 |
} |
378 |
} |
276 |
|
379 |
|
277 |
bool FlacInputStream::seekAbsolute(FLAC__uint64 sample) { |
380 |
bool FlacInputStream::seekAbsolute(FLAC__uint64 sample) { |
278 |
assert(isValid()); |
381 |
assert(isValid()); |
|
|
382 |
#ifdef LEGACY_FLAC |
279 |
const bool result = (0 != ::FLAC__seekable_stream_decoder_seek_absolute(_decoder, sample)); |
383 |
const bool result = (0 != ::FLAC__seekable_stream_decoder_seek_absolute(_decoder, sample)); |
|
|
384 |
#else |
385 |
const bool result = (0 != ::FLAC__stream_decoder_seek_absolute(_decoder, sample)); |
386 |
#endif |
280 |
if (result) { |
387 |
if (result) { |
281 |
flushBuffer(); |
388 |
flushBuffer(); |
282 |
_lastSampleWritten = (_lastSample != 0 && sample >= _lastSample); // only set if we are SURE |
389 |
_lastSampleWritten = (_lastSample != 0 && sample >= _lastSample); // only set if we are SURE |
Lines 349-359
Link Here
|
349 |
return decoderOk ? samples : -1; |
456 |
return decoderOk ? samples : -1; |
350 |
} |
457 |
} |
351 |
|
458 |
|
352 |
inline ::FLAC__SeekableStreamDecoderReadStatus FlacInputStream::callbackRead(FLAC__byte buffer[], uint *bytes) { |
459 |
#ifdef LEGACY_FLAC |
|
|
460 |
inline ::FLAC__SeekableStreamDecoderReadStatus FlacInputStream::callbackRead(FLAC__byte buffer[], uint *bytes) |
461 |
#else |
462 |
inline ::FLAC__StreamDecoderReadStatus FlacInputStream::callbackRead(FLAC__byte buffer[], size_t *bytes) |
463 |
#endif |
464 |
{ |
353 |
assert(_fileInfo.fileHandle != NULL); |
465 |
assert(_fileInfo.fileHandle != NULL); |
354 |
|
466 |
|
355 |
if (*bytes == 0) |
467 |
if (*bytes == 0) |
|
|
468 |
#ifdef LEGACY_FLAC |
356 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; /* abort to avoid a deadlock */ |
469 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; /* abort to avoid a deadlock */ |
|
|
470 |
#else |
471 |
return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ |
472 |
#endif |
357 |
|
473 |
|
358 |
const uint32 length = MIN(_fileInfo.fileEndPos - _fileInfo.filePos, static_cast<uint32>(*bytes)); |
474 |
const uint32 length = MIN(_fileInfo.fileEndPos - _fileInfo.filePos, static_cast<uint32>(*bytes)); |
359 |
|
475 |
|
Lines 361-371
Link Here
|
361 |
const uint32 bytesRead = _fileInfo.fileHandle->read(buffer, length); |
477 |
const uint32 bytesRead = _fileInfo.fileHandle->read(buffer, length); |
362 |
|
478 |
|
363 |
if (bytesRead == 0 && _fileInfo.fileHandle->ioFailed()) |
479 |
if (bytesRead == 0 && _fileInfo.fileHandle->ioFailed()) |
|
|
480 |
#ifdef LEGACY_FLAC |
364 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; |
481 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; |
|
|
482 |
#else |
483 |
return FLAC__STREAM_DECODER_READ_STATUS_ABORT; |
484 |
#endif |
365 |
|
485 |
|
366 |
_fileInfo.filePos += bytesRead; |
486 |
_fileInfo.filePos += bytesRead; |
367 |
*bytes = static_cast<uint>(bytesRead); |
487 |
*bytes = static_cast<uint>(bytesRead); |
|
|
488 |
#ifdef LEGACY_FLAC |
368 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
489 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; |
|
|
490 |
#else |
491 |
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; |
492 |
#endif |
369 |
} |
493 |
} |
370 |
|
494 |
|
371 |
inline void FlacInputStream::setLastSample(FLAC__uint64 absoluteSample) { |
495 |
inline void FlacInputStream::setLastSample(FLAC__uint64 absoluteSample) { |
Lines 637-666
Link Here
|
637 |
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
761 |
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
638 |
} |
762 |
} |
639 |
|
763 |
|
640 |
inline ::FLAC__SeekableStreamDecoderSeekStatus FlacInputStream::callbackSeek(FLAC__uint64 absoluteByteOffset) { |
764 |
#ifdef LEGACY_FLAC |
|
|
765 |
inline ::FLAC__SeekableStreamDecoderSeekStatus FlacInputStream::callbackSeek(FLAC__uint64 absoluteByteOffset) |
766 |
#else |
767 |
inline ::FLAC__StreamDecoderSeekStatus FlacInputStream::callbackSeek(FLAC__uint64 absoluteByteOffset) |
768 |
#endif |
769 |
{ |
641 |
FLAC__uint64 newPos = absoluteByteOffset + _fileInfo.fileStartPos; |
770 |
FLAC__uint64 newPos = absoluteByteOffset + _fileInfo.fileStartPos; |
642 |
const bool result = (newPos < _fileInfo.fileEndPos); |
771 |
const bool result = (newPos < _fileInfo.fileEndPos); |
643 |
|
772 |
|
644 |
if (result) |
773 |
if (result) |
645 |
_fileInfo.filePos = static_cast<uint32>(newPos); |
774 |
_fileInfo.filePos = static_cast<uint32>(newPos); |
646 |
|
775 |
|
|
|
776 |
#ifdef LEGACY_FLAC |
647 |
return result ? FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK : FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; |
777 |
return result ? FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK : FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; |
648 |
|
778 |
#else |
|
|
779 |
return result ? FLAC__STREAM_DECODER_SEEK_STATUS_OK : FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; |
780 |
#endif |
649 |
} |
781 |
} |
650 |
|
782 |
|
651 |
inline ::FLAC__SeekableStreamDecoderTellStatus FlacInputStream::callbackTell(FLAC__uint64 *absoluteByteOffset) { |
783 |
#ifdef LEGACY_FLAC |
|
|
784 |
inline ::FLAC__SeekableStreamDecoderTellStatus FlacInputStream::callbackTell(FLAC__uint64 *absoluteByteOffset) |
785 |
#else |
786 |
inline ::FLAC__StreamDecoderTellStatus FlacInputStream::callbackTell(FLAC__uint64 *absoluteByteOffset) |
787 |
#endif |
788 |
{ |
652 |
/*if () |
789 |
/*if () |
653 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;*/ |
790 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;*/ |
654 |
*absoluteByteOffset = static_cast<FLAC__uint64>(_fileInfo.filePos-_fileInfo.fileStartPos); |
791 |
*absoluteByteOffset = static_cast<FLAC__uint64>(_fileInfo.filePos-_fileInfo.fileStartPos); |
|
|
792 |
#ifdef LEGACY_FLAC |
655 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
793 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; |
|
|
794 |
#else |
795 |
return FLAC__STREAM_DECODER_TELL_STATUS_OK; |
796 |
#endif |
656 |
} |
797 |
} |
657 |
|
798 |
|
658 |
inline ::FLAC__SeekableStreamDecoderLengthStatus FlacInputStream::callbackLength(FLAC__uint64 *streamLength) { |
799 |
#ifdef LEGACY_FLAC |
|
|
800 |
inline ::FLAC__SeekableStreamDecoderLengthStatus FlacInputStream::callbackLength(FLAC__uint64 *streamLength) |
801 |
#else |
802 |
inline ::FLAC__StreamDecoderLengthStatus FlacInputStream::callbackLength(FLAC__uint64 *streamLength) |
803 |
#endif |
804 |
{ |
659 |
if (_fileInfo.fileStartPos > _fileInfo.fileEndPos) |
805 |
if (_fileInfo.fileStartPos > _fileInfo.fileEndPos) |
|
|
806 |
#ifdef LEGACY_FLAC |
660 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; |
807 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; |
|
|
808 |
#else |
809 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; |
810 |
#endif |
661 |
|
811 |
|
662 |
*streamLength = static_cast<FLAC__uint64>(_fileInfo.fileEndPos - _fileInfo.fileStartPos); |
812 |
*streamLength = static_cast<FLAC__uint64>(_fileInfo.fileEndPos - _fileInfo.fileStartPos); |
|
|
813 |
#ifdef LEGACY_FLAC |
663 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
814 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; |
|
|
815 |
#else |
816 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; |
817 |
#endif |
664 |
} |
818 |
} |
665 |
|
819 |
|
666 |
inline bool FlacInputStream::callbackEOF() { |
820 |
inline bool FlacInputStream::callbackEOF() { |
Lines 682-737
Link Here
|
682 |
} |
836 |
} |
683 |
|
837 |
|
684 |
/* Static Callback Wrappers */ |
838 |
/* Static Callback Wrappers */ |
685 |
::FLAC__SeekableStreamDecoderReadStatus FlacInputStream::callWrapRead(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], uint *bytes, void *clientData) { |
839 |
#ifdef LEGACY_FLAC |
|
|
840 |
::FLAC__SeekableStreamDecoderReadStatus FlacInputStream::callWrapRead(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], uint *bytes, void *clientData) |
841 |
#else |
842 |
::FLAC__StreamDecoderReadStatus FlacInputStream::callWrapRead(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *clientData) |
843 |
#endif |
844 |
{ |
686 |
assert(0 != clientData); |
845 |
assert(0 != clientData); |
687 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
846 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
688 |
assert(0 != instance); |
847 |
assert(0 != instance); |
689 |
return instance->callbackRead(buffer, bytes); |
848 |
return instance->callbackRead(buffer, bytes); |
690 |
} |
849 |
} |
691 |
|
850 |
|
692 |
::FLAC__SeekableStreamDecoderSeekStatus FlacInputStream::callWrapSeek(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData) { |
851 |
#ifdef LEGACY_FLAC |
|
|
852 |
::FLAC__SeekableStreamDecoderSeekStatus FlacInputStream::callWrapSeek(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData) |
853 |
#else |
854 |
::FLAC__StreamDecoderSeekStatus FlacInputStream::callWrapSeek(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absoluteByteOffset, void *clientData) |
855 |
#endif |
856 |
{ |
693 |
assert(0 != clientData); |
857 |
assert(0 != clientData); |
694 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
858 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
695 |
assert(0 != instance); |
859 |
assert(0 != instance); |
696 |
return instance->callbackSeek(absoluteByteOffset); |
860 |
return instance->callbackSeek(absoluteByteOffset); |
697 |
} |
861 |
} |
698 |
|
862 |
|
699 |
::FLAC__SeekableStreamDecoderTellStatus FlacInputStream::callWrapTell(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData) { |
863 |
#ifdef LEGACY_FLAC |
|
|
864 |
::FLAC__SeekableStreamDecoderTellStatus FlacInputStream::callWrapTell(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData) |
865 |
#else |
866 |
::FLAC__StreamDecoderTellStatus FlacInputStream::callWrapTell(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absoluteByteOffset, void *clientData) |
867 |
#endif |
868 |
{ |
700 |
assert(0 != clientData); |
869 |
assert(0 != clientData); |
701 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
870 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
702 |
assert(0 != instance); |
871 |
assert(0 != instance); |
703 |
return instance->callbackTell(absoluteByteOffset); |
872 |
return instance->callbackTell(absoluteByteOffset); |
704 |
} |
873 |
} |
705 |
|
874 |
|
706 |
::FLAC__SeekableStreamDecoderLengthStatus FlacInputStream::callWrapLength(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *streamLength, void *clientData) { |
875 |
#ifdef LEGACY_FLAC |
|
|
876 |
::FLAC__SeekableStreamDecoderLengthStatus FlacInputStream::callWrapLength(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *streamLength, void *clientData) |
877 |
#else |
878 |
::FLAC__StreamDecoderLengthStatus FlacInputStream::callWrapLength(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *streamLength, void *clientData) |
879 |
#endif |
880 |
{ |
707 |
assert(0 != clientData); |
881 |
assert(0 != clientData); |
708 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
882 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
709 |
assert(0 != instance); |
883 |
assert(0 != instance); |
710 |
return instance->callbackLength(streamLength); |
884 |
return instance->callbackLength(streamLength); |
711 |
} |
885 |
} |
712 |
|
886 |
|
713 |
FLAC__bool FlacInputStream::callWrapEOF(const ::FLAC__SeekableStreamDecoder *decoder, void *clientData) { |
887 |
#ifdef LEGACY_FLAC |
|
|
888 |
FLAC__bool FlacInputStream::callWrapEOF(const ::FLAC__SeekableStreamDecoder *decoder, void *clientData) |
889 |
#else |
890 |
FLAC__bool FlacInputStream::callWrapEOF(const ::FLAC__StreamDecoder *decoder, void *clientData) |
891 |
#endif |
892 |
{ |
714 |
assert(0 != clientData); |
893 |
assert(0 != clientData); |
715 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
894 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
716 |
assert(0 != instance); |
895 |
assert(0 != instance); |
717 |
return instance->callbackEOF(); |
896 |
return instance->callbackEOF(); |
718 |
} |
897 |
} |
719 |
|
898 |
|
720 |
::FLAC__StreamDecoderWriteStatus FlacInputStream::callWrapWrite(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData) { |
899 |
#ifdef LEGACY_FLAC |
|
|
900 |
::FLAC__StreamDecoderWriteStatus FlacInputStream::callWrapWrite(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData) |
901 |
#else |
902 |
::FLAC__StreamDecoderWriteStatus FlacInputStream::callWrapWrite(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *clientData) |
903 |
#endif |
904 |
{ |
721 |
assert(0 != clientData); |
905 |
assert(0 != clientData); |
722 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
906 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
723 |
assert(0 != instance); |
907 |
assert(0 != instance); |
724 |
return instance->callbackWrite(frame, buffer); |
908 |
return instance->callbackWrite(frame, buffer); |
725 |
} |
909 |
} |
726 |
|
910 |
|
727 |
void FlacInputStream::callWrapMetadata(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData) { |
911 |
#ifdef LEGACY_FLAC |
|
|
912 |
void FlacInputStream::callWrapMetadata(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData) |
913 |
#else |
914 |
void FlacInputStream::callWrapMetadata(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *clientData) |
915 |
#endif |
916 |
{ |
728 |
assert(0 != clientData); |
917 |
assert(0 != clientData); |
729 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
918 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
730 |
assert(0 != instance); |
919 |
assert(0 != instance); |
731 |
instance->callbackMetadata(metadata); |
920 |
instance->callbackMetadata(metadata); |
732 |
} |
921 |
} |
733 |
|
922 |
|
734 |
void FlacInputStream::callWrapError(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData) { |
923 |
#ifdef LEGACY_FLAC |
|
|
924 |
void FlacInputStream::callWrapError(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData) |
925 |
#else |
926 |
void FlacInputStream::callWrapError(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *clientData) |
927 |
#endif |
928 |
{ |
735 |
assert(0 != clientData); |
929 |
assert(0 != clientData); |
736 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
930 |
FlacInputStream *instance = reinterpret_cast<FlacInputStream *>(clientData); |
737 |
assert(0 != instance); |
931 |
assert(0 != instance); |