Merge pull request #973 from anssih/fix/AE-byteswap
authorAnssi Hannula <anssi@xbmc.org>
Tue, 10 Jul 2012 16:12:54 +0000 (19:12 +0300)
committerAnssi Hannula <anssi@xbmc.org>
Tue, 10 Jul 2012 16:12:54 +0000 (19:12 +0300)
[AE] Fix issues related to endianness in passthrough

Conflicts:
xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp

1  2 
xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
xbmc/cores/AudioEngine/Utils/AEUtil.h
xbmc/utils/EndianSwap.h
xbmc/utils/Makefile

@@@ -1010,16 -1006,26 +1016,35 @@@ void CSoftAE::RunRawOutputStage(
    if(m_buffer.Used() < m_sinkBlockSize)
      return;
  
-   int wroteFrames = m_sink->AddPackets((uint8_t*)m_buffer.Raw(m_sinkBlockSize), m_sinkFormat.m_frames);
+   void *data = m_buffer.Raw(m_sinkBlockSize);
+   if (CAEUtil::S16NeedsByteSwap(AE_FMT_S16NE, m_sinkFormat.m_dataFormat))
+   {
+     /*
+      * It would really be preferable to handle this at packing stage, so that
+      * it could byteswap the data efficiently without wasting CPU time on
+      * swapping the huge IEC 61937 zero padding between frames (or not
+      * byteswap at all, if there are two byteswaps).
+      *
+      * Unfortunately packing is done on a higher level and we can't easily
+      * tell it the needed format from here, so do it here for now (better than
+      * nothing)...
+      */
+     AllocateConvIfNeeded(m_sinkBlockSize);
+     Endian_Swap16_buf((uint16_t *)m_converted, (uint16_t *)data, m_sinkBlockSize / 2);
+     data = m_converted;
+   }
+   int wroteFrames = m_sink->AddPackets((uint8_t *)data, m_sinkFormat.m_frames);
 +
 +  /* Return value of INT_MAX signals error in sink - restart */
 +  if (wroteFrames == INT_MAX)
 +  {
 +    CLog::Log(LOGERROR, "CSoftAE::RunRawOutputStage - sink error - reinit flagged");
 +    wroteFrames = 0;
 +    m_reOpen = true;
 +  }
 +
    m_buffer.Shift(NULL, wroteFrames * m_sinkFormat.m_frameSize);
  }
  
Simple merge
Simple merge
@@@ -9,9 -9,9 +9,10 @@@ SRCS=AlarmClock.cpp 
       CPUInfo.cpp \
       Crc32.cpp \
       CryptThreading.cpp \
 +     DatabaseUtils.cpp \
       DownloadQueue.cpp \
       DownloadQueueManager.cpp \
+      EndianSwap.cpp \
       Fanart.cpp \
       fastmemcpy.c \
       fastmemcpy-arm.S \