Skip to content

Commit

Permalink
Merge pull request #8456 from AlwinEsch/adsp-fix
Browse files Browse the repository at this point in the history
[adsp] fix seg fault if DSP becomes enabled
  • Loading branch information
AlwinEsch committed Nov 29, 2015
2 parents 01d7be4 + 3c85a8d commit dc270bc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 75 deletions.
8 changes: 7 additions & 1 deletion xbmc/Application.cpp
Expand Up @@ -443,7 +443,6 @@ bool CApplication::Create()
CApplicationMessenger::GetInstance().RegisterReceiver(this);
CApplicationMessenger::GetInstance().RegisterReceiver(&g_playlistPlayer);
CApplicationMessenger::GetInstance().RegisterReceiver(&g_infoManager);
CApplicationMessenger::GetInstance().RegisterReceiver(&g_AEDSPManager);

for (int i = RES_HDTV_1080i; i <= RES_PAL60_16x9; i++)
{
Expand Down Expand Up @@ -2569,6 +2568,13 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg)
StopPVRManager();
break;

case TMSG_SETAUDIODSPSTATE:
if(pMsg->param1 == ACTIVE_AE_DSP_STATE_ON)
ActiveAE::CActiveAEDSP::GetInstance().Activate(pMsg->param2 == ACTIVE_AE_DSP_ASYNC_ACTIVATE);
else if(pMsg->param1 == ACTIVE_AE_DSP_STATE_OFF)
ActiveAE::CActiveAEDSP::GetInstance().Deactivate();
break;

case TMSG_START_ANDROID_ACTIVITY:
{
#if defined(TARGET_ANDROID)
Expand Down
76 changes: 18 additions & 58 deletions xbmc/cores/AudioEngine/DSPAddons/ActiveAEDSP.cpp
Expand Up @@ -86,42 +86,6 @@ CActiveAEDSP &CActiveAEDSP::GetInstance()
}
//@}

/*! @name message handling methods */
//@{
void CActiveAEDSP::OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg)
{
switch(pMsg->dwMessage)
{
case TMSG_SETAUDIODSPSTATE:
if(pMsg->param1 == ACTIVE_AE_DSP_STATE_ON)
{
if(pMsg->param2 == ACTIVE_AE_DSP_ASYNC_ACTIVATE)
{
Activate(true);
}
else
{
Activate();
}
}
else if(pMsg->param1 == ACTIVE_AE_DSP_STATE_OFF)
{
Deactivate();
}
break;

default:
CLog::Log(LOGERROR, "CActiveAEDSP received a invalid message! Nothing is processed.");
break;
}
}

int CActiveAEDSP::GetMessageMask()
{
return TMSG_MASK_AUDIO_DSP;
}
//@}

/*! @name initialization and configuration methods */
//@{
class CActiveAEDSPStartJob : public CJob
Expand All @@ -146,11 +110,11 @@ void CActiveAEDSP::Activate(bool bAsync /* = false */)
return;
}

CSingleLock lock(m_critSection);

/* first stop and remove any audio dsp add-on's */
Deactivate();

CSingleLock lock(m_critSection);

CLog::Log(LOGNOTICE, "ActiveAE DSP - starting");

/* don't start if Settings->System->Audio->Audio DSP isn't checked */
Expand Down Expand Up @@ -214,29 +178,29 @@ void CActiveAEDSP::TriggerModeUpdate(bool bAsync /* = true */)

void CActiveAEDSP::Deactivate(void)
{
CSingleLock lock(m_critSection);

/* check whether the audio dsp is loaded */
if (!m_isActive)
return;

CLog::Log(LOGNOTICE, "ActiveAE DSP - stopping");

/* stop thread */
StopThread(false);
StopThread();

/* unload all data */
Cleanup();
CSingleLock lock(m_critSection);

/* close database */
if (m_databaseDSP.IsOpen())
m_databaseDSP.Close();
CLog::Log(LOGNOTICE, "ActiveAE DSP - stopping");

/* destroy all addons */
for (AE_DSP_ADDONMAP_ITR itr = m_addonMap.begin(); itr != m_addonMap.end(); ++itr)
itr->second->Destroy();

m_addonMap.clear();

/* unload all data */
Cleanup();

/* close database */
if (m_databaseDSP.IsOpen())
m_databaseDSP.Close();
}

void CActiveAEDSP::Cleanup(void)
Expand Down Expand Up @@ -758,8 +722,7 @@ bool CActiveAEDSP::UpdateAddons(void)
{
dspAddon = std::dynamic_pointer_cast<CActiveAEDSPAddon>(*itr);

bool newRegistration = false;
if (RegisterAudioDSPAddon(dspAddon, &newRegistration) < 0 || newRegistration)
if (RegisterAudioDSPAddon(dspAddon) < 0)
{
CAddonMgr::GetInstance().DisableAddon(dspAddon->ID());
--usableAddons;
Expand Down Expand Up @@ -812,8 +775,10 @@ void CActiveAEDSP::Process(void)
else if (!m_noAddonWarningDisplayed)
ShowDialogNoAddonsEnabled();
}

Sleep(1000);
else
{
Sleep(1000);
}
}

m_isActive = false;
Expand All @@ -832,13 +797,10 @@ void CActiveAEDSP::ShowDialogNoAddonsEnabled(void)
g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params);
}

int CActiveAEDSP::RegisterAudioDSPAddon(AddonPtr addon, bool* newRegistration/*=NULL*/)
int CActiveAEDSP::RegisterAudioDSPAddon(AddonPtr addon)
{
int iAddonId(-1);

if (newRegistration)
*newRegistration = false;

if (!addon->Enabled())
return -1;

Expand All @@ -861,8 +823,6 @@ int CActiveAEDSP::RegisterAudioDSPAddon(AddonPtr addon, bool* newRegistration/*=
CLog::Log(LOGERROR, "ActiveAE DSP - %s - can't add dsp addon '%s' to the database", __FUNCTION__, addon->Name().c_str());
return -1;
}
else if (newRegistration)
*newRegistration = true;
}

AE_DSP_ADDON dspAddon;
Expand Down
16 changes: 5 additions & 11 deletions xbmc/cores/AudioEngine/DSPAddons/ActiveAEDSP.h
Expand Up @@ -31,9 +31,10 @@
#include "ActiveAEDSPDatabase.h"
#include "ActiveAEDSPMode.h"

#define ACTIVE_AE_DSP_STATE_ON 0
#define ACTIVE_AE_DSP_STATE_OFF 1
#define ACTIVE_AE_DSP_SYNC_ACTIVATE 0
#define ACTIVE_AE_DSP_STATE_OFF 0
#define ACTIVE_AE_DSP_STATE_ON 1

#define ACTIVE_AE_DSP_SYNC_ACTIVATE 0
#define ACTIVE_AE_DSP_ASYNC_ACTIVATE 1

extern "C" {
Expand Down Expand Up @@ -61,7 +62,6 @@ namespace ActiveAE
class CActiveAEDSP : public ADDON::IAddonMgrCallback,
public ISettingCallback,
public Observer,
public KODI::MESSAGING::IMessageTarget,
private CThread
{
/*! @name Master audio dsp control class */
Expand All @@ -85,12 +85,6 @@ namespace ActiveAE
static CActiveAEDSP &GetInstance();
//@}

/*! @name message handling methods */
//@{
virtual void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
virtual int GetMessageMask() override;
//@}

/*! @name initialization and configuration methods */
//@{
/*!
Expand Down Expand Up @@ -438,7 +432,7 @@ namespace ActiveAE
* @param newRegistration pass in pointer to bool to return whether the client was newly registered.
* @return The id of the addon if it was created or found in the existing addon map, -1 otherwise.
*/
int RegisterAudioDSPAddon(ADDON::AddonPtr addon, bool* newRegistration = NULL);
int RegisterAudioDSPAddon(ADDON::AddonPtr addon);

/*!
* @brief Get the instance of the dsp addon, if it's ready.
Expand Down
2 changes: 0 additions & 2 deletions xbmc/cores/AudioEngine/DSPAddons/ActiveAEDSPDatabase.cpp
Expand Up @@ -91,8 +91,6 @@ void CActiveAEDSPDatabase::CreateTables()
// disable all Audio DSP add-on when started the first time
ADDON::VECADDONS addons;
if (CAddonMgr::GetInstance().GetAddons(ADDON_ADSPDLL, addons, true))
CLog::Log(LOGERROR, "Audio DSP - %s - failed to get add-ons from the add-on manager", __FUNCTION__);
else
{
for (IVECADDONS it = addons.begin(); it != addons.end(); ++it)
CAddonMgr::GetInstance().DisableAddon(it->get()->ID());
Expand Down
4 changes: 1 addition & 3 deletions xbmc/messaging/ApplicationMessenger.h
Expand Up @@ -36,7 +36,6 @@
#define TMSG_MASK_GUIINFOMANAGER (1<<28)
#define TMSG_MASK_WINDOWMANAGER (1<<27)
#define TMSG_MASK_PERIPHERALS (1<<26)
#define TMSG_MASK_AUDIO_DSP (1<<25)

// defines here
#define TMSG_PLAYLISTPLAYER_PLAY TMSG_MASK_PLAYLISTPLAYER + 0
Expand Down Expand Up @@ -90,8 +89,7 @@
#define TMSG_PICTURE_SLIDESHOW TMSG_MASK_APPLICATION + 26
#define TMSG_LOADPROFILE TMSG_MASK_APPLICATION + 27
#define TMSG_VIDEORESIZE TMSG_MASK_APPLICATION + 28

#define TMSG_SETAUDIODSPSTATE TMSG_MASK_AUDIO_DSP + 0
#define TMSG_SETAUDIODSPSTATE TMSG_MASK_APPLICATION + 29

#define TMSG_GUI_INFOLABEL TMSG_MASK_GUIINFOMANAGER + 0
#define TMSG_GUI_INFOBOOL TMSG_MASK_GUIINFOMANAGER + 1
Expand Down

0 comments on commit dc270bc

Please sign in to comment.