Skip to content

Commit

Permalink
Merge pull request #2075 from Memphiz/streamsilence
Browse files Browse the repository at this point in the history
[AE/CA] - implement the advancedsetting for streamsilence
  • Loading branch information
huceke committed Jan 17, 2013
2 parents 7d4b8a8 + c570270 commit c5d4690
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
40 changes: 36 additions & 4 deletions xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "utils/log.h"
#include "utils/TimeUtils.h"
#include "utils/MathUtils.h"
#include "threads/SystemClock.h"

#define DELAY_FRAME_TIME 20
#define BUFFERSIZE 16416
Expand All @@ -50,7 +51,9 @@ CCoreAudioAE::CCoreAudioAE() :
m_muted (false ),
m_soundMode (AE_SOUND_OFF ),
m_streamsPlaying (false ),
m_isSuspended (false )
m_isSuspended (false ),
m_softSuspend (false ),
m_softSuspendTimer (0 )
{
HAL = new CCoreAudioAEHAL;
}
Expand Down Expand Up @@ -428,7 +431,7 @@ IAEStream* CCoreAudioAE::MakeStream(enum AEDataFormat dataFormat,
{
// if we are suspended we don't
// want anyone to mess with us
if (m_isSuspended)
if (m_isSuspended && !m_softSuspend)
return NULL;

CAEChannelInfo channelInfo(channelLayout);
Expand Down Expand Up @@ -510,7 +513,7 @@ IAEStream* CCoreAudioAE::FreeStream(IAEStream *stream)

void CCoreAudioAE::PlaySound(IAESound *sound)
{
if (m_soundMode == AE_SOUND_OFF || (m_soundMode == AE_SOUND_IDLE && m_streamsPlaying) || m_isSuspended)
if (m_soundMode == AE_SOUND_OFF || (m_soundMode == AE_SOUND_IDLE && m_streamsPlaying) || (m_isSuspended && !m_softSuspend))
return;

float *samples = ((CCoreAudioAESound*)sound)->GetSamples();
Expand Down Expand Up @@ -632,11 +635,40 @@ void CCoreAudioAE::MixSounds(float *buffer, unsigned int samples)

void CCoreAudioAE::GarbageCollect()
{
if (g_advancedSettings.m_streamSilence)
return;

if (!m_streamsPlaying && m_playing_sounds.empty())
{
if (!m_softSuspend)
{
m_softSuspend = true;
m_softSuspendTimer = XbmcThreads::SystemClockMillis() + 10000; //10.0 second delay for softSuspend
}
}
else
{
if (m_isSuspended)
{
CLog::Log(LOGDEBUG, "CCoreAudioAE::GarbageCollect - Acquire CA HAL.");
Start();
m_isSuspended = false;
}
m_softSuspend = false;
}

unsigned int curSystemClock = XbmcThreads::SystemClockMillis();
if (!m_isSuspended && m_softSuspend && curSystemClock > m_softSuspendTimer)
{
Stop();
m_isSuspended = true;
CLog::Log(LOGDEBUG, "CCoreAudioAE::GarbageCollect - Release CA HAL.");
}
}

void CCoreAudioAE::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
{
if (m_isSuspended)
if (m_isSuspended && !m_softSuspend)
return;

HAL->EnumerateOutputDevices(devices, passthrough);
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,6 @@ class CCoreAudioAE : public IAE, public ICoreAudioSource
int m_soundMode;
bool m_streamsPlaying;
bool m_isSuspended;
bool m_softSuspend;
unsigned int m_softSuspendTimer;
};

0 comments on commit c5d4690

Please sign in to comment.