MixerControl: Add more safeness for Roster() errors

This commit is contained in:
Dario Casalinuovo
2015-08-28 18:27:16 +02:00
parent d15321ff90
commit 1c3d7e0c68
2 changed files with 15 additions and 10 deletions
+14 -10
View File
@@ -28,8 +28,10 @@ MixerControl::MixerControl(int32 volumeWhich)
fMuteParameter(NULL), fMuteParameter(NULL),
fMin(0.0f), fMin(0.0f),
fMax(0.0f), fMax(0.0f),
fStep(0.0f) fStep(0.0f),
fRoster(NULL)
{ {
fRoster = BMediaRoster::Roster();
} }
@@ -47,22 +49,22 @@ MixerControl::Connect(int32 volumeWhich, float* _value, const char** _error)
_Disconnect(); _Disconnect();
status_t status = B_OK; status_t status = B_OK;
// BMediaRoster::Roster() doesn't set it if all is ok
const char* errorString = NULL; const char* errorString = NULL;
BMediaRoster* roster = BMediaRoster::Roster(&status); if (fRoster == NULL)
fRoster = BMediaRoster::Roster(&status);
if (BMediaRoster::IsRunning() && roster != NULL if (BMediaRoster::IsRunning() && fRoster != NULL
&& status == B_OK) { && status == B_OK) {
switch (volumeWhich) { switch (volumeWhich) {
case VOLUME_USE_MIXER: case VOLUME_USE_MIXER:
status = roster->GetAudioMixer(&fGainMediaNode); status = fRoster->GetAudioMixer(&fGainMediaNode);
break; break;
case VOLUME_USE_PHYS_OUTPUT: case VOLUME_USE_PHYS_OUTPUT:
status = roster->GetAudioOutput(&fGainMediaNode); status = fRoster->GetAudioOutput(&fGainMediaNode);
break; break;
} }
if (status == B_OK) { if (status == B_OK) {
status = roster->GetParameterWebFor(fGainMediaNode, &fParameterWeb); status = fRoster->GetParameterWebFor(fGainMediaNode, &fParameterWeb);
if (status == B_OK) { if (status == B_OK) {
// Finding the Mixer slider in the audio output ParameterWeb // Finding the Mixer slider in the audio output ParameterWeb
int32 numParams = fParameterWeb->CountParameters(); int32 numParams = fParameterWeb->CountParameters();
@@ -252,9 +254,11 @@ MixerControl::_Disconnect()
fParameterWeb = NULL; fParameterWeb = NULL;
fMixerParameter = NULL; fMixerParameter = NULL;
BMediaRoster* roster = BMediaRoster::CurrentRoster(); if (fRoster == NULL)
if (roster != NULL && fGainMediaNode != media_node::null) fRoster = BMediaRoster::Roster();
roster->ReleaseNode(fGainMediaNode);
if (fRoster != NULL && fGainMediaNode != media_node::null)
fRoster->ReleaseNode(fGainMediaNode);
fGainMediaNode = media_node::null; fGainMediaNode = media_node::null;
} }
+1
View File
@@ -56,6 +56,7 @@ private:
float fMin; float fMin;
float fMax; float fMax;
float fStep; float fStep;
BMediaRoster* fRoster;
}; };
#endif // MIXER_CONTROL_H #endif // MIXER_CONTROL_H