Skip to content
This repository
Browse code

dvdplayer: don't call into audio device from non audio thread

CoreAE has a bug where AddPackets is a blocking operation. This causes
DVDAudio to blocked during this time. Since this is called from rendering
thread, we end up blocking GUI/video rendering.
  • Loading branch information...
commit a83ee9952e4164ce65e7f9f8a56b0bfef664b9da 1 parent 629b5c4
Joakim Plate authored May 25, 2013
34  xbmc/cores/dvdplayer/DVDPlayerAudio.cpp
@@ -503,6 +503,24 @@ void CDVDPlayerAudio::OnStartup()
503 503
 #endif
504 504
 }
505 505
 
  506
+void CDVDPlayerAudio::UpdatePlayerInfo()
  507
+{
  508
+  std::ostringstream s;
  509
+  s << "aq:"     << setw(2) << min(99,m_messageQueue.GetLevel() + MathUtils::round_int(100.0/8.0*m_dvdAudio.GetCacheTime())) << "%";
  510
+  s << ", Kb/s:" << fixed << setprecision(2) << (double)GetAudioBitrate() / 1024.0;
  511
+
  512
+  //print the inverse of the resample ratio, since that makes more sense
  513
+  //if the resample ratio is 0.5, then we're playing twice as fast
  514
+  if (m_synctype == SYNC_RESAMPLE)
  515
+    s << ", rr:" << fixed << setprecision(5) << 1.0 / m_resampleratio;
  516
+
  517
+  s << ", att:" << fixed << setprecision(1) << log(GetCurrentAttenuation()) * 20.0f << " dB";
  518
+
  519
+  { CSingleLock lock(m_info_section);
  520
+    m_info = s.str();
  521
+  }
  522
+}
  523
+
506 524
 void CDVDPlayerAudio::Process()
507 525
 {
508 526
   CLog::Log(LOGNOTICE, "running thread: CDVDPlayerAudio::Process()");
@@ -519,6 +537,8 @@ void CDVDPlayerAudio::Process()
519 537
     result = DecodeFrame(audioframe, m_speed > DVD_PLAYSPEED_NORMAL || m_speed < 0 ||
520 538
                          CAEFactory::IsSuspended()); // blocks if no audio is available, but leaves critical section before doing so
521 539
 
  540
+    UpdatePlayerInfo();
  541
+
522 542
     if( result & DECODE_FLAG_ERROR )
523 543
     {
524 544
       CLog::Log(LOGDEBUG, "CDVDPlayerAudio::Process - Decode Error");
@@ -858,18 +878,8 @@ bool CDVDPlayerAudio::SwitchCodecIfNeeded()
858 878
 
859 879
 string CDVDPlayerAudio::GetPlayerInfo()
860 880
 {
861  
-  std::ostringstream s;
862  
-  s << "aq:"     << setw(2) << min(99,m_messageQueue.GetLevel() + MathUtils::round_int(100.0/8.0*m_dvdAudio.GetCacheTime())) << "%";
863  
-  s << ", Kb/s:" << fixed << setprecision(2) << (double)GetAudioBitrate() / 1024.0;
864  
-
865  
-  //print the inverse of the resample ratio, since that makes more sense
866  
-  //if the resample ratio is 0.5, then we're playing twice as fast
867  
-  if (m_synctype == SYNC_RESAMPLE)
868  
-    s << ", rr:" << fixed << setprecision(5) << 1.0 / m_resampleratio;
869  
-
870  
-  s << ", att:" << fixed << setprecision(1) << log(GetCurrentAttenuation()) * 20.0f << " dB";
871  
-
872  
-  return s.str();
  881
+  CSingleLock lock(m_info_section);
  882
+  return m_info;
873 883
 }
874 884
 
875 885
 int CDVDPlayerAudio::GetAudioBitrate()
6  xbmc/cores/dvdplayer/DVDPlayerAudio.h
@@ -126,6 +126,8 @@ class CDVDPlayerAudio : public CThread
126 126
 
127 127
   int DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket);
128 128
 
  129
+  void UpdatePlayerInfo();
  130
+
129 131
   CDVDMessageQueue m_messageQueue;
130 132
   CDVDMessageQueue& m_messageParent;
131 133
 
@@ -206,5 +208,9 @@ class CDVDPlayerAudio : public CThread
206 208
   bool   m_prevskipped;
207 209
   double m_maxspeedadjust;
208 210
   double m_resampleratio; //resample ratio when using SYNC_RESAMPLE, used for the codec info
  211
+
  212
+
  213
+  CCriticalSection m_info_section;
  214
+  std::string      m_info;
209 215
 };
210 216
 

0 notes on commit a83ee99

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