Add support for running on big-endian systems
authorDmitry Shachnev <mitya57@gmail.com>
Mon, 17 Mar 2014 04:44:24 +0000 (08:44 +0400)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 3 Apr 2014 13:37:33 +0000 (15:37 +0200)
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>
src/multimedia/audio/qwavedecoder_p.cpp
src/multimedia/audio/qwavedecoder_p.h
tests/auto/unit/qaudioformat/tst_qaudioformat.cpp

index 497a146..974a8f5 100644 (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 (bigEndian)
-        pChunk->size = qFromBigEndian<quint32>(pChunk->size);
-
+    if (handleEndianness) {
+        if (bigEndian)
+            pChunk->size = qFromBigEndian<quint32>(pChunk->size);
+        else
+            pChunk->size = qFromLittleEndian<quint32>(pChunk->size);
+    }
     return true;
 }
 
index c21d8cb..24cdb78 100644 (file)
@@ -103,7 +103,7 @@ private:
         char        id[4];
         quint32     size;
     };
-    bool peekChunk(chunk* pChunk);
+    bool peekChunk(chunk* pChunk, bool handleEndianness = true);
 
     struct RIFFHeader
     {
index ee16513..22a5dc1 100644 (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);