diff options
author | Laszlo Papp <lpapp@kde.org> | 2011-12-07 18:46:00 +0200 |
---|---|---|
committer | Laszlo Papp <ext-laszlo.papp@nokia.com> | 2011-12-07 18:46:00 +0200 |
commit | 3b2a6b7496300f6a6706b49a55dd75d1c8d06cac (patch) | |
tree | ca9157512d83d6d70da212e27bf6948c5e079611 | |
parent | db6ca75ce76d213f6e0fa697d6bea491aac9d8e2 (diff) |
Implement the seek callback and add the proper retval and args for read
-rw-r--r-- | src/decoders/qalflacaudiodecoder.cpp | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/src/decoders/qalflacaudiodecoder.cpp b/src/decoders/qalflacaudiodecoder.cpp index 38e441c..3babe56 100644 --- a/src/decoders/qalflacaudiodecoder.cpp +++ b/src/decoders/qalflacaudiodecoder.cpp @@ -53,56 +53,37 @@ class QALFlacAudioDecoder::Private FLAC__StreamDecoder *flacStreamDecoder; }; -FLAC__StreamDecoderLengthStatus -QALFlacAudioDecoder::Private::lengthCallback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) +FLAC__StreamDecoderReadStatus +QALFlacAudioDecoder::Private::readCallback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) { - reinterpret_cast<QALFlacAudioDecoder::Private*>(user_data)->file.size(); + return reinterpret_cast<QALFlacAudioDecoder::Private*>(client_data)->file.read(reinterpret_cast<char*>(ptr), count); } -sf_count_t -QALFlacAudioDecoder::Private::seekCallback(sf_count_t offset, int whence, void *user_data) +FLAC__StreamDecoderSeekStatus +QALFlacAudioDecoder::Private::seekCallback(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) { - QFile &tmpFile = reinterpret_cast<QALFlacAudioDecoder::Private*>(user_data)->file; - switch (whence) { - case SEEK_SET: - if (tmpFile.seek(offset) == true) - return offset; - - break; - - case SEEK_CUR: - offset += tmpFile.pos(); - if (tmpFile.seek(offset) == true) - return offset; - - break; - - case SEEK_END: - offset += tmpFile.size(); - if (tmpFile.seek(offset) == true) - return offset; - - break; - - default: - qWarning() << Q_FUNC_INFO << "Failed to seek the file:" << tmpFile.fileName() << "Invalid whence value:" << whence; - break; + if (reinterpret_cast<QALFlacAudioDecoder::Private*>(client_data)->file.seek(absolute_byte_offset) == false) { + qWarning() << Q_FUNC_INFO << "Failed to seek in the file"; + return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; } - qWarning() << Q_FUNC_INFO << "Failed to seek the file:" << tmpFile.fileName(); - return -1; + return FLAC__STREAM_DECODER_SEEK_STATUS_OK; } sf_count_t -QALFlacAudioDecoder::Private::readCallback(void *ptr, sf_count_t count, void *user_data) +QALFlacAudioDecoder::Private::tellCallback(void *user_data) { - return reinterpret_cast<QALFlacAudioDecoder::Private*>(user_data)->file.read(reinterpret_cast<char*>(ptr), count); + return reinterpret_cast<QALFlacAudioDecoder::Private*>(user_data)->file.pos(); } -sf_count_t -QALFlacAudioDecoder::Private::tellCallback(void *user_data) +FLAC__StreamDecoderLengthStatus +QALFlacAudioDecoder::Private::lengthCallback(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) { - return reinterpret_cast<QALFlacAudioDecoder::Private*>(user_data)->file.pos(); + Q_UNUSED(decoder) + + *stream_length = reinterpret_cast<QALFlacAudioDecoder::Private*>(client_data)->file.size(); + + return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; } QALFlacAudioDecoder::QALFlacAudioDecoder() |