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:
committed by
The Qt Project
parent
3d51c9565d
commit
b0c68a1a07
@@ -166,6 +166,8 @@ void QWaveDecoder::handleData()
|
|||||||
// Swizzle this
|
// Swizzle this
|
||||||
if (bigEndian) {
|
if (bigEndian) {
|
||||||
wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
|
wave.audioFormat = qFromBigEndian<quint16>(wave.audioFormat);
|
||||||
|
} else {
|
||||||
|
wave.audioFormat = qFromLittleEndian<quint16>(wave.audioFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wave.audioFormat != 0 && wave.audioFormat != 1) {
|
if (wave.audioFormat != 0 && wave.audioFormat != 1) {
|
||||||
@@ -207,6 +209,8 @@ void QWaveDecoder::handleData()
|
|||||||
source->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
|
source->read(reinterpret_cast<char *>(&descriptor), sizeof(chunk));
|
||||||
if (bigEndian)
|
if (bigEndian)
|
||||||
descriptor.size = qFromBigEndian<quint32>(descriptor.size);
|
descriptor.size = qFromBigEndian<quint32>(descriptor.size);
|
||||||
|
else
|
||||||
|
descriptor.size = qFromLittleEndian<quint32>(descriptor.size);
|
||||||
|
|
||||||
dataSize = descriptor.size;
|
dataSize = descriptor.size;
|
||||||
|
|
||||||
@@ -227,13 +231,15 @@ void QWaveDecoder::handleData()
|
|||||||
bool QWaveDecoder::enoughDataAvailable()
|
bool QWaveDecoder::enoughDataAvailable()
|
||||||
{
|
{
|
||||||
chunk descriptor;
|
chunk descriptor;
|
||||||
if (!peekChunk(&descriptor))
|
if (!peekChunk(&descriptor, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// This is only called for the RIFF/RIFX header, before bigEndian is set,
|
// This is only called for the RIFF/RIFX header, before bigEndian is set,
|
||||||
// so we have to manually swizzle
|
// so we have to manually swizzle
|
||||||
if (qstrncmp(descriptor.id, "RIFX", 4) == 0)
|
if (qstrncmp(descriptor.id, "RIFX", 4) == 0)
|
||||||
descriptor.size = qFromBigEndian<quint32>(descriptor.size);
|
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))
|
if (source->bytesAvailable() < qint64(sizeof(chunk) + descriptor.size))
|
||||||
return false;
|
return false;
|
||||||
@@ -270,16 +276,18 @@ bool QWaveDecoder::findChunk(const char *chunkId)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles endianness
|
bool QWaveDecoder::peekChunk(chunk *pChunk, bool handleEndianness)
|
||||||
bool QWaveDecoder::peekChunk(chunk *pChunk)
|
|
||||||
{
|
{
|
||||||
if (source->bytesAvailable() < qint64(sizeof(chunk)))
|
if (source->bytesAvailable() < qint64(sizeof(chunk)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
source->peek(reinterpret_cast<char *>(pChunk), sizeof(chunk));
|
source->peek(reinterpret_cast<char *>(pChunk), sizeof(chunk));
|
||||||
if (bigEndian)
|
if (handleEndianness) {
|
||||||
pChunk->size = qFromBigEndian<quint32>(pChunk->size);
|
if (bigEndian)
|
||||||
|
pChunk->size = qFromBigEndian<quint32>(pChunk->size);
|
||||||
|
else
|
||||||
|
pChunk->size = qFromLittleEndian<quint32>(pChunk->size);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ private:
|
|||||||
char id[4];
|
char id[4];
|
||||||
quint32 size;
|
quint32 size;
|
||||||
};
|
};
|
||||||
bool peekChunk(chunk* pChunk);
|
bool peekChunk(chunk* pChunk, bool handleEndianness = true);
|
||||||
|
|
||||||
struct RIFFHeader
|
struct RIFFHeader
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -323,10 +323,10 @@ void tst_QAudioFormat::debugOperator_data()
|
|||||||
|
|
||||||
// A small sampling
|
// A small sampling
|
||||||
QAudioFormat f;
|
QAudioFormat f;
|
||||||
|
f.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
QTest::newRow("plain") << f << QString::fromLatin1("QAudioFormat(-1Hz, -1bit, channelCount=-1, sampleType=Unknown, byteOrder=LittleEndian, codec=\"\") ");
|
QTest::newRow("plain") << f << QString::fromLatin1("QAudioFormat(-1Hz, -1bit, channelCount=-1, sampleType=Unknown, byteOrder=LittleEndian, codec=\"\") ");
|
||||||
|
|
||||||
f.setSampleRate(22050);
|
f.setSampleRate(22050);
|
||||||
f.setByteOrder(QAudioFormat::LittleEndian);
|
|
||||||
f.setChannelCount(4);
|
f.setChannelCount(4);
|
||||||
f.setCodec("audio/pcm");
|
f.setCodec("audio/pcm");
|
||||||
f.setSampleType(QAudioFormat::Float);
|
f.setSampleType(QAudioFormat::Float);
|
||||||
|
|||||||
Reference in New Issue
Block a user