Skip to content
Permalink
Browse files

changed: allow multiple callbacks in AE

  • Loading branch information
notspiff authored and popcornmix committed Sep 16, 2015
1 parent ff3df35 commit 37f10ae1e1b66daef60d0e50850bfcbbc316f4ed
@@ -169,7 +169,7 @@ void CVisualisation::Render()

void CVisualisation::Stop()
{
CAEFactory::UnregisterAudioCallback();
CAEFactory::UnregisterAudioCallback(this);
if (Initialized())
{
CAddonDll<DllVisualisation, Visualisation, VIS_PROPS>::Stop();
@@ -372,10 +372,10 @@ void CAEFactory::RegisterAudioCallback(IAudioCallback* pCallback)
AE->RegisterAudioCallback(pCallback);
}

void CAEFactory::UnregisterAudioCallback()
void CAEFactory::UnregisterAudioCallback(IAudioCallback* pCallback)
{
if (AE)
AE->UnregisterAudioCallback();
AE->UnregisterAudioCallback(pCallback);
}

bool CAEFactory::IsSettingVisible(const std::string &condition, const std::string &value, const CSetting *setting, void *data)
@@ -72,7 +72,7 @@ class CAEFactory
static void DeviceChange();

static void RegisterAudioCallback(IAudioCallback* pCallback);
static void UnregisterAudioCallback();
static void UnregisterAudioCallback(IAudioCallback* pCallback);

private:
static IAE *AE;
@@ -227,7 +227,6 @@ CActiveAE::CActiveAE() :
m_aeMuted = false;
m_mode = MODE_PCM;
m_encoder = NULL;
m_audioCallback = NULL;
m_vizInitialized = false;
m_sinkHasVolume = false;
m_aeGUISoundForce = false;
@@ -1249,7 +1248,7 @@ void CActiveAE::Configure(AEAudioFormat *desiredFmt)
m_discardBufferPools.push_back(m_vizBuffersInput);
m_vizBuffersInput = NULL;
}
if (!m_vizBuffers && m_audioCallback)
if (!m_vizBuffers && !m_audioCallback.empty())
{
AEAudioFormat vizFormat = m_internalFormat;
vizFormat.m_channelLayout = AE_CH_LAYOUT_2_0;
@@ -2099,12 +2098,13 @@ bool CActiveAE::RunStages()
// viz
{
CSingleLock lock(m_vizLock);
if (m_audioCallback && !m_streams.empty())
if (!m_audioCallback.empty() && !m_streams.empty())
{
if (!m_vizInitialized || !m_vizBuffers)
{
Configure();
m_audioCallback->OnInitialize(2, m_vizBuffers->m_format.m_sampleRate, 32);
for (auto& it : m_audioCallback)
it->OnInitialize(2, m_vizBuffers->m_format.m_sampleRate, 32);
m_vizInitialized = true;
}

@@ -2136,7 +2136,8 @@ bool CActiveAE::RunStages()
else
{
int samples = buf->pkt->nb_samples;
m_audioCallback->OnAudioData((float*)(buf->pkt->data[0]), samples);
for (auto& it : m_audioCallback)
it->OnAudioData((float*)(buf->pkt->data[0]), samples);
buf->Return();
m_vizBuffers->m_outputSamples.pop_front();
}
@@ -3186,12 +3187,14 @@ void CActiveAE::SetStreamFade(CActiveAEStream *stream, float from, float target,
void CActiveAE::RegisterAudioCallback(IAudioCallback* pCallback)
{
CSingleLock lock(m_vizLock);
m_audioCallback = pCallback;
m_audioCallback.push_back(pCallback);
m_vizInitialized = false;
}

void CActiveAE::UnregisterAudioCallback()
void CActiveAE::UnregisterAudioCallback(IAudioCallback* pCallback)
{
CSingleLock lock(m_vizLock);
m_audioCallback = NULL;
auto it = std::find(m_audioCallback.begin(), m_audioCallback.end(), pCallback);
if (it != m_audioCallback.end())
m_audioCallback.erase(it);
}
@@ -260,7 +260,7 @@ class CActiveAE : public IAE, private CThread
virtual AEAudioFormat GetCurrentSinkFormat();

virtual void RegisterAudioCallback(IAudioCallback* pCallback);
virtual void UnregisterAudioCallback();
virtual void UnregisterAudioCallback(IAudioCallback* pCallback);

virtual void OnLostDevice();
virtual void OnResetDevice();
@@ -379,7 +379,7 @@ class CActiveAE : public IAE, private CThread
bool m_sinkHasVolume;

// viz
IAudioCallback *m_audioCallback;
std::vector<IAudioCallback*> m_audioCallback;
bool m_vizInitialized;
CCriticalSection m_vizLock;

@@ -227,7 +227,7 @@ class IAE

virtual void RegisterAudioCallback(IAudioCallback* pCallback) {}

virtual void UnregisterAudioCallback() {}
virtual void UnregisterAudioCallback(IAudioCallback* pCallback) {}

/**
* Returns true if AudioEngine supports specified quality level

0 comments on commit 37f10ae

Please sign in to comment.
You can’t perform that action at this time.