ActiveAE: AEStream::AddData returned wrong number in some cases
authorRainer Hochecker <fernetmenta@online.de>
Thu, 30 Jan 2014 13:11:43 +0000 (14:11 +0100)
committerRainer Hochecker <fernetmenta@online.de>
Fri, 31 Jan 2014 20:41:02 +0000 (21:41 +0100)
xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp

index c6e1a6e..1b7d67f 100644 (file)
@@ -199,7 +199,7 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
 
   while(copied < size)
   {
-    buf = (uint8_t*)data;
+    buf = ((uint8_t*)data) + copied;
     bytesToCopy = size - copied;
 
     if (m_currentBuffer)
@@ -208,9 +208,8 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
       if (m_leftoverBytes && bytesToCopy >= (m_format.m_frameSize - m_leftoverBytes))
       {
         int fillbytes = m_format.m_frameSize - m_leftoverBytes;
-        memcpy(m_leftoverBuffer+m_leftoverBytes, (uint8_t*)data, fillbytes);
-        data = (uint8_t*)data + fillbytes;
-        size -= fillbytes;
+        memcpy(m_leftoverBuffer+m_leftoverBytes, buf, fillbytes);
+        copied += fillbytes;
         // leftover buffer will be copied on next cycle
         buf = m_leftoverBuffer;
         bytesToCopy = m_format.m_frameSize;
@@ -228,7 +227,7 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
       // if we don't have a full frame, copy to leftover buffer
       if (!availableSamples && bytesToCopy)
       {
-        memcpy(m_leftoverBuffer+m_leftoverBytes, buf+copied, bytesToCopy);
+        memcpy(m_leftoverBuffer+m_leftoverBytes, buf, bytesToCopy);
         m_leftoverBytes = bytesToCopy;
         copied += bytesToCopy;
       }
@@ -238,9 +237,9 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
 
       //TODO: handle planar formats
       if (m_convertFn)
-        m_convertFn(buf+copied, samples*m_currentBuffer->pkt->config.channels, (float*)(m_currentBuffer->pkt->data[0] + start));
+        m_convertFn(buf, samples*m_currentBuffer->pkt->config.channels, (float*)(m_currentBuffer->pkt->data[0] + start));
       else
-        memcpy(m_currentBuffer->pkt->data[0] + start, buf+copied, bytes);
+        memcpy(m_currentBuffer->pkt->data[0] + start, buf, bytes);
       {
         CSingleLock lock(*m_statsLock);
         m_currentBuffer->pkt->nb_samples += samples;