Add support for running on big-endian systems

Now qtmultimedia test suite passes on powerpc.

Change-Id: I540dff93195115ad1dc5725af7293e3b8540403f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
Dmitry Shachnev
2014-03-17 08:44:24 +04:00
committed by The Qt Project
parent 3d51c9565d
commit b0c68a1a07
3 changed files with 16 additions and 8 deletions

View File

@@ -166,6 +166,8 @@ void QWaveDecoder::handleData()
// Swizzle this
if (bigEndian) {
wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
} else {
wave.audioFormat = qFromLittleEndian<quint16>(wave.audioFormat);
}
if (wave.audioFormat != 0 && wave.audioFormat != 1) {
@@ -207,6 +209,8 @@ void QWaveDecoder::handleData()
source->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
if (bigEndian)
descriptor.size = qFromBigEndian<quint32>(descriptor.size);
else
descriptor.size = qFromLittleEndian<quint32>(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<quint32>(descriptor.size);
if (qstrncmp(descriptor.id, "RIFF", 4) == 0)
descriptor.size = qFromLittleEndian<quint32>(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<char *>(pChunk), sizeof(chunk));
if (handleEndianness) {
if (bigEndian)
pChunk->size = qFromBigEndian<quint32>(pChunk->size);
else
pChunk->size = qFromLittleEndian<quint32>(pChunk->size);
}
return true;
}

View File

@@ -103,7 +103,7 @@ private:
char id[4];
quint32 size;
};
bool peekChunk(chunk* pChunk);
bool peekChunk(chunk* pChunk, bool handleEndianness = true);
struct RIFFHeader
{

View File

@@ -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);