From b0c68a1a07f546fe22a7d76b1a15bb2b39aa550f Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Mon, 17 Mar 2014 08:44:24 +0400 Subject: Add support for running on big-endian systems Now qtmultimedia test suite passes on powerpc. Change-Id: I540dff93195115ad1dc5725af7293e3b8540403f Reviewed-by: Thiago Macieira Reviewed-by: Yoann Lopes --- src/multimedia/audio/qwavedecoder_p.cpp | 20 ++++++++++++++------ src/multimedia/audio/qwavedecoder_p.h | 2 +- tests/auto/unit/qaudioformat/tst_qaudioformat.cpp | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/multimedia/audio/qwavedecoder_p.cpp b/src/multimedia/audio/qwavedecoder_p.cpp index 497a146df..974a8f509 100644 --- a/src/multimedia/audio/qwavedecoder_p.cpp +++ b/src/multimedia/audio/qwavedecoder_p.cpp @@ -166,6 +166,8 @@ void QWaveDecoder::handleData() // Swizzle this if (bigEndian) { wave.audioFormat = qFromBigEndian(wave.audioFormat); + } else { + wave.audioFormat = qFromLittleEndian(wave.audioFormat); } if (wave.audioFormat != 0 && wave.audioFormat != 1) { @@ -207,6 +209,8 @@ void QWaveDecoder::handleData() source->read(reinterpret_cast(&descriptor), sizeof(chunk)); if (bigEndian) descriptor.size = qFromBigEndian(descriptor.size); + else + descriptor.size = qFromLittleEndian(descriptor.size); dataSize = descriptor.size; @@ -227,13 +231,15 @@ void QWaveDecoder::handleData() bool QWaveDecoder::enoughDataAvailable() { chunk descriptor; - if (!peekChunk(&descriptor)) + if (!peekChunk(&descriptor, false)) return false; // This is only called for the RIFF/RIFX header, before bigEndian is set, // so we have to manually swizzle if (qstrncmp(descriptor.id, "RIFX", 4) == 0) descriptor.size = qFromBigEndian(descriptor.size); + if (qstrncmp(descriptor.id, "RIFF", 4) == 0) + descriptor.size = qFromLittleEndian(descriptor.size); if (source->bytesAvailable() < qint64(sizeof(chunk) + descriptor.size)) return false; @@ -270,16 +276,18 @@ bool QWaveDecoder::findChunk(const char *chunkId) return false; } -// Handles endianness -bool QWaveDecoder::peekChunk(chunk *pChunk) +bool QWaveDecoder::peekChunk(chunk *pChunk, bool handleEndianness) { if (source->bytesAvailable() < qint64(sizeof(chunk))) return false; source->peek(reinterpret_cast(pChunk), sizeof(chunk)); - if (bigEndian) - pChunk->size = qFromBigEndian(pChunk->size); - + if (handleEndianness) { + if (bigEndian) + pChunk->size = qFromBigEndian(pChunk->size); + else + pChunk->size = qFromLittleEndian(pChunk->size); + } return true; } diff --git a/src/multimedia/audio/qwavedecoder_p.h b/src/multimedia/audio/qwavedecoder_p.h index c21d8cb5b..24cdb7885 100644 --- a/src/multimedia/audio/qwavedecoder_p.h +++ b/src/multimedia/audio/qwavedecoder_p.h @@ -103,7 +103,7 @@ private: char id[4]; quint32 size; }; - bool peekChunk(chunk* pChunk); + bool peekChunk(chunk* pChunk, bool handleEndianness = true); struct RIFFHeader { diff --git a/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp index ee1651304..22a5dc135 100644 --- a/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp +++ b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp @@ -323,10 +323,10 @@ void tst_QAudioFormat::debugOperator_data() // A small sampling QAudioFormat f; + f.setByteOrder(QAudioFormat::LittleEndian); QTest::newRow("plain") << f << QString::fromLatin1("QAudioFormat(-1Hz, -1bit, channelCount=-1, sampleType=Unknown, byteOrder=LittleEndian, codec=\"\") "); f.setSampleRate(22050); - f.setByteOrder(QAudioFormat::LittleEndian); f.setChannelCount(4); f.setCodec("audio/pcm"); f.setSampleType(QAudioFormat::Float); -- cgit v1.2.3