Skip to content
This repository
Browse code

Merge pull request #3158 from anssih/fix/AE-getdelay

SoftAE: Fix A/V sync issues caused by wrong buffer time calculation
  • Loading branch information...
commit 615fbe9d005faddfd81910f912fe8d2fa92ffd85 2 parents 18a4377 + bfc2e2e
Anssi Hannula authored August 29, 2013
17  xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
@@ -243,8 +243,6 @@ void CSoftAE::InternalOpenSink()
243 243
       {
244 244
         if (m_masterStream->m_initChannelLayout == AE_CH_LAYOUT_2_0)
245 245
           m_transcode = false;
246  
-        m_encoderInitFrameSizeMul  = 1.0 / (newFormat.m_channelLayout.Count() * 
247  
-                                           (CAEUtil::DataFormatToBits(newFormat.m_dataFormat) >> 3));
248 246
         m_encoderInitSampleRateMul = 1.0 / newFormat.m_sampleRate;
249 247
       }
250 248
     }
@@ -349,7 +347,6 @@ void CSoftAE::InternalOpenSink()
349 347
 
350 348
     m_sinkFormat              = newFormat;
351 349
     m_sinkFormatSampleRateMul = 1.0 / (double)newFormat.m_sampleRate;
352  
-    m_sinkFormatFrameSizeMul  = 1.0 / (double)newFormat.m_frameSize;
353 350
     m_sinkBlockSize           = newFormat.m_frames * newFormat.m_frameSize;
354 351
     m_sinkBlockTime           = 1000 * newFormat.m_frames / newFormat.m_sampleRate;
355 352
     // check if sink controls volume, if so, init the volume.
@@ -378,6 +375,7 @@ void CSoftAE::InternalOpenSink()
378 375
     m_convertFn      = NULL;
379 376
     m_bytesPerSample = CAEUtil::DataFormatToBits(m_sinkFormat.m_dataFormat) >> 3;
380 377
     m_frameSize      = m_sinkFormat.m_frameSize;
  378
+    m_frameSizeMul   = 1.0 / (double)m_frameSize;
381 379
     neededBufferSize = m_sinkFormat.m_frames * m_sinkFormat.m_frameSize;
382 380
   }
383 381
   else
@@ -430,6 +428,7 @@ void CSoftAE::InternalOpenSink()
430 428
 
431 429
     m_bytesPerSample = CAEUtil::DataFormatToBits(AE_FMT_FLOAT) >> 3;
432 430
     m_frameSize      = m_bytesPerSample * m_chLayout.Count();
  431
+    m_frameSizeMul   = 1.0 / (double)m_frameSize;
433 432
   }
434 433
 
435 434
   CLog::Log(LOGDEBUG, "CSoftAE::InternalOpenSink - Internal Buffer Size: %d", (int)neededBufferSize);
@@ -894,11 +893,11 @@ double CSoftAE::GetDelay()
894 893
  
895 894
   if (m_transcode && m_encoder && !m_rawPassthrough)
896 895
   {
897  
-    delayBuffer     = (double)m_buffer.Used() * m_encoderInitFrameSizeMul * m_encoderInitSampleRateMul;
  896
+    delayBuffer     = (double)m_buffer.Used() * m_frameSizeMul * m_encoderInitSampleRateMul;
898 897
     delayTranscoder = m_encoder->GetDelay((double)m_encodedBuffer.Used() * m_encoderFrameSizeMul);
899 898
   }
900 899
   else
901  
-    delayBuffer = (double)m_buffer.Used() * m_sinkFormatFrameSizeMul *m_sinkFormatSampleRateMul;
  900
+    delayBuffer = (double)m_buffer.Used() * m_frameSizeMul *m_sinkFormatSampleRateMul;
902 901
 
903 902
   return delayBuffer + delaySink + delayTranscoder;
904 903
 }
@@ -913,11 +912,11 @@ double CSoftAE::GetCacheTime()
913 912
 
914 913
   if (m_transcode && m_encoder && !m_rawPassthrough)
915 914
   {
916  
-    timeBuffer     = (double)m_buffer.Used() * m_encoderInitFrameSizeMul * m_encoderInitSampleRateMul;
  915
+    timeBuffer     = (double)m_buffer.Used() * m_frameSizeMul * m_encoderInitSampleRateMul;
917 916
     timeTranscoder = m_encoder->GetDelay((double)m_encodedBuffer.Used() * m_encoderFrameSizeMul);
918 917
   }
919 918
   else
920  
-    timeBuffer = (double)m_buffer.Used() * m_sinkFormatFrameSizeMul *m_sinkFormatSampleRateMul;
  919
+    timeBuffer = (double)m_buffer.Used() * m_frameSizeMul *m_sinkFormatSampleRateMul;
921 920
 
922 921
   return timeBuffer + timeSink + timeTranscoder;
923 922
 }
@@ -932,11 +931,11 @@ double CSoftAE::GetCacheTotal()
932 931
 
933 932
   if (m_transcode && m_encoder && !m_rawPassthrough)
934 933
   {
935  
-    timeBuffer     = (double)m_buffer.Size() * m_encoderInitFrameSizeMul * m_encoderInitSampleRateMul;
  934
+    timeBuffer     = (double)m_buffer.Size() * m_frameSizeMul * m_encoderInitSampleRateMul;
936 935
     timeTranscoder = m_encoder->GetDelay((double)m_encodedBuffer.Size() * m_encoderFrameSizeMul);
937 936
   }
938 937
   else
939  
-    timeBuffer = (double)m_buffer.Size() * m_sinkFormatFrameSizeMul *m_sinkFormatSampleRateMul;
  938
+    timeBuffer = (double)m_buffer.Size() * m_frameSizeMul *m_sinkFormatSampleRateMul;
940 939
 
941 940
   return timeBuffer + timeSink + timeTranscoder;
942 941
 }
3  xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.h
@@ -157,20 +157,19 @@ class CSoftAE : public IThreadedAE
157 157
   bool                m_muted;
158 158
   CAEChannelInfo      m_chLayout;
159 159
   unsigned int        m_frameSize;
  160
+  double              m_frameSizeMul;
160 161
 
161 162
   /* the sink, its format information, and conversion function */
162 163
   AESinkInfoList            m_sinkInfoList;
163 164
   IAESink                  *m_sink;
164 165
   AEAudioFormat             m_sinkFormat;
165 166
   double                    m_sinkFormatSampleRateMul;
166  
-  double                    m_sinkFormatFrameSizeMul;
167 167
   unsigned int              m_sinkBlockSize;
168 168
   unsigned int              m_sinkBlockTime;
169 169
   bool                      m_sinkHandlesVolume;
170 170
   AEAudioFormat             m_encoderFormat;
171 171
   double                    m_encoderFrameSizeMul;
172 172
   double                    m_encoderInitSampleRateMul;
173  
-  double                    m_encoderInitFrameSizeMul;
174 173
   unsigned int              m_bytesPerSample;
175 174
   CAEConvert::AEConvertFrFn m_convertFn;
176 175
 

0 notes on commit 615fbe9

Please sign in to comment.
Something went wrong with that request. Please try again.