diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2011-10-11 16:38:34 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-11 08:59:51 +0200 |
commit | 0da05239d20eeaf6f24557ec018a41f602cbd864 (patch) | |
tree | d4ea356bf03148f250ae2aa2b3425f6ebce91ba1 /src/multimedia | |
parent | 8943111428929771774be73430c8a6d553b1ba21 (diff) |
Rename the parsing error signal to parsingError.
Refactor the error handling code a little.
Change-Id: I717b3aaacb24660b3f26769f19ac718b73106473
Reviewed-on: http://codereview.qt-project.org/6401
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: derick hawcroft <derick.hawcroft@nokia.com>
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/effects/qsamplecache_p.cpp | 2 | ||||
-rw-r--r-- | src/multimedia/effects/qwavedecoder_p.cpp | 31 | ||||
-rw-r--r-- | src/multimedia/effects/qwavedecoder_p.h | 3 |
3 files changed, 21 insertions, 15 deletions
diff --git a/src/multimedia/effects/qsamplecache_p.cpp b/src/multimedia/effects/qsamplecache_p.cpp index 1610a4382..c7e77d79a 100644 --- a/src/multimedia/effects/qsamplecache_p.cpp +++ b/src/multimedia/effects/qsamplecache_p.cpp @@ -351,7 +351,7 @@ void QSample::load() connect(m_stream, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(decoderError())); m_waveDecoder = new QWaveDecoder(m_stream); connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady())); - connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError())); + connect(m_waveDecoder, SIGNAL(parsingError()), SLOT(decoderError())); connect(m_waveDecoder, SIGNAL(readyRead()), SLOT(readSample())); } diff --git a/src/multimedia/effects/qwavedecoder_p.cpp b/src/multimedia/effects/qwavedecoder_p.cpp index ad4ecf26b..8ee0d59c2 100644 --- a/src/multimedia/effects/qwavedecoder_p.cpp +++ b/src/multimedia/effects/qwavedecoder_p.cpp @@ -105,6 +105,13 @@ qint64 QWaveDecoder::writeData(const char *data, qint64 len) return -1; } +void QWaveDecoder::parsingFailed() +{ + Q_ASSERT(source); + source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); + emit parsingError(); +} + void QWaveDecoder::handleData() { // As a special "state", if we have junk to skip, we do @@ -112,8 +119,12 @@ void QWaveDecoder::handleData() discardBytes(junkToSkip); // this also updates junkToSkip // If we couldn't skip all the junk, return - if (junkToSkip > 0) + if (junkToSkip > 0) { + // We might have run out + if (source->atEnd()) + parsingFailed(); return; + } } if (state == QWaveDecoder::InitialState) { @@ -124,11 +135,9 @@ void QWaveDecoder::handleData() source->read(reinterpret_cast<char *>(&riff), sizeof(RIFFHeader)); // RIFF = little endian RIFF, RIFX = big endian RIFF - if (((qstrncmp(riff.descriptor.id, "RIFF", 4) != 0) && (qstrncmp(riff.descriptor.id, "RIFX", 4) != 0)) || - qstrncmp(riff.type, "WAVE", 4) != 0) { - source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); - emit invalidFormat(); - + if (((qstrncmp(riff.descriptor.id, "RIFF", 4) != 0) && (qstrncmp(riff.descriptor.id, "RIFX", 4) != 0)) + || qstrncmp(riff.type, "WAVE", 4) != 0) { + parsingFailed(); return; } else { state = QWaveDecoder::WaitingForFormatState; @@ -160,9 +169,7 @@ void QWaveDecoder::handleData() if (wave.audioFormat != 0 && wave.audioFormat != 1) { // 32bit wave files have format == 0xFFFE (WAVE_FORMAT_EXTENSIBLE). // but don't support them at the moment. - source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); - emit invalidFormat(); - + parsingFailed(); return; } else { format.setCodec(QLatin1String("audio/pcm")); @@ -209,11 +216,9 @@ void QWaveDecoder::handleData() } } + // If we hit the end without finding data, it's a parsing error if (source->atEnd()) { - source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); - emit invalidFormat(); - - return; + parsingFailed(); } } diff --git a/src/multimedia/effects/qwavedecoder_p.h b/src/multimedia/effects/qwavedecoder_p.h index 0d26fec4b..1a7bef945 100644 --- a/src/multimedia/effects/qwavedecoder_p.h +++ b/src/multimedia/effects/qwavedecoder_p.h @@ -82,7 +82,7 @@ public: Q_SIGNALS: void formatKnown(); - void invalidFormat(); + void parsingError(); private Q_SLOTS: void handleData(); @@ -94,6 +94,7 @@ private: bool enoughDataAvailable(); bool findChunk(const char *chunkId); void discardBytes(qint64 numBytes); + void parsingFailed(); enum State { InitialState, |