VampireAE fixes, mmm'kay
authorS. Davilla <davilla@4pi.com>
Thu, 10 Jan 2013 17:13:27 +0000 (12:13 -0500)
committerS. Davilla <davilla@4pi.com>
Fri, 18 Jan 2013 15:29:29 +0000 (10:29 -0500)
xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
xbmc/powermanagement/PowerManager.cpp

index 2403bd1..bc15948 100644 (file)
@@ -935,7 +935,11 @@ double CSoftAE::GetCacheTotal()
 
 bool CSoftAE::IsSuspended()
 {
+#if defined(TARGET_WINDOWS)
   return m_isSuspended;
+#else
+  return false;
+#endif
 }
 
 float CSoftAE::GetVolume()
@@ -968,8 +972,8 @@ void CSoftAE::StopAllSounds()
 bool CSoftAE::Suspend()
 {
   CLog::Log(LOGDEBUG, "CSoftAE::Suspend - Suspending AE processing");
+#if defined(TARGET_WINDOWS)
   m_isSuspended = true;
-
   CSingleLock streamLock(m_streamLock);
   
   for (StreamList::iterator itt = m_playingStreams.begin(); itt != m_playingStreams.end(); ++itt)
@@ -977,6 +981,7 @@ bool CSoftAE::Suspend()
     CSoftAEStream *stream = *itt;
     stream->Flush();
   }
+#endif
 
   return true;
 }
@@ -984,8 +989,10 @@ bool CSoftAE::Suspend()
 bool CSoftAE::Resume()
 {
   CLog::Log(LOGDEBUG, "CSoftAE::Resume - Resuming AE processing");
+#if defined(TARGET_WINDOWS)
   m_isSuspended = false;
   m_reOpen = true;
+#endif
 
   return true;
 }
@@ -1021,7 +1028,7 @@ void CSoftAE::Run()
         restart = true;
     }
 
-#if !defined(TARGET_ANDROID)
+#if defined(TARGET_WINDOWS)
     /* Handle idle or forced suspend */
     ProcessSuspend();
 #endif
@@ -1033,6 +1040,17 @@ void CSoftAE::Run()
       InternalOpenSink();
       m_isSuspended = false; // exit Suspend state
     }
+#if defined(TARGET_ANDROID)
+    else if (m_playingStreams.empty() 
+      &&     m_playing_sounds.empty()
+      && !g_advancedSettings.m_streamSilence)
+    {
+      // if we have nothing to do, take a dirt nap.
+      // we do not have to take a lock just to check empty.
+      // this keeps AE from sucking CPU if nothing is going on.
+      m_wake.WaitMSec(SOFTAE_IDLE_WAIT_MSEC);
+    }
+#endif
   }
 }
 
@@ -1388,15 +1406,18 @@ inline void CSoftAE::RemoveStream(StreamList &streams, CSoftAEStream *stream)
 inline void CSoftAE::ProcessSuspend()
 {
   bool sinkIsSuspended = false;
+  unsigned int curSystemClock = 0;
 
-  if (m_playingStreams.empty() && m_playing_sounds.empty() && 
-     !m_softSuspend && !g_advancedSettings.m_streamSilence)
+  if (!m_softSuspend && m_playingStreams.empty() && m_playing_sounds.empty() &&
+      !g_advancedSettings.m_streamSilence)
   {
     m_softSuspend = true;
     m_softSuspendTimer = XbmcThreads::SystemClockMillis() + 10000; //10.0 second delay for softSuspend
+    Sleep(10);
   }
 
-  unsigned int curSystemClock = XbmcThreads::SystemClockMillis();
+  if (m_softSuspend)
+    curSystemClock = XbmcThreads::SystemClockMillis();
 
   /* idle while in Suspend() state until Resume() called */
   /* idle if nothing to play and user hasn't enabled     */
index 4e91c60..9f3e437 100644 (file)
@@ -21,6 +21,7 @@
 #include "system.h"
 #include "PowerManager.h"
 #include "Application.h"
+#include "cores/AudioEngine/AEFactory.h"
 #include "input/KeyboardStat.h"
 #include "settings/GUISettings.h"
 #include "windowing/WindowingFactory.h"
@@ -206,6 +207,7 @@ void CPowerManager::OnSleep()
   g_application.StopPlaying();
   g_application.StopShutdownTimer();
   g_application.StopScreenSaverTimer();
+  CAEFactory::Suspend();
 }
 
 void CPowerManager::OnWake()
@@ -245,6 +247,7 @@ void CPowerManager::OnWake()
   g_lcd->Initialize();
 #endif
 
+  CAEFactory::Resume();
   g_application.UpdateLibraries();
   g_weatherManager.Refresh();