Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e662cd5c authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Improve AudioTrack recovery from mediaserver death" into lmp-mr1-dev

parents 1609e451 d2d089fc
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -375,7 +375,10 @@ private:
    friend class AudioFlingerClient;
    friend class AudioPolicyServiceClient;

    static Mutex gLock;
    static Mutex gLock;     // protects all members except gAudioPolicyService,
                            // gAudioPolicyServiceClient, and gAudioPortCallback
    static Mutex gLockAPS;  // protects gAudioPolicyService and gAudioPolicyServiceClient
    static Mutex gLockAPC;  // protects gAudioPortCallback
    static sp<IAudioFlinger> gAudioFlinger;
    static audio_error_callback gAudioErrorCallback;

+30 −18
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ namespace android {

// client singleton for AudioFlinger binder interface
Mutex AudioSystem::gLock;
Mutex AudioSystem::gLockAPS;
Mutex AudioSystem::gLockAPC;
sp<IAudioFlinger> AudioSystem::gAudioFlinger;
sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
@@ -70,9 +72,9 @@ const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
        }
        binder->linkToDeath(gAudioFlingerClient);
        gAudioFlinger = interface_cast<IAudioFlinger>(binder);
        LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0);
        gAudioFlinger->registerClient(gAudioFlingerClient);
    }
    ALOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");

    return gAudioFlinger;
}
@@ -544,6 +546,7 @@ void AudioSystem::setErrorCallback(audio_error_callback cb)
}

// client singleton for AudioPolicyService binder interface
// protected by gLockAPS
sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient;

@@ -551,7 +554,7 @@ sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient
// establish binder interface to AudioPolicy service
const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service()
{
    gLock.lock();
    Mutex::Autolock _l(gLockAPS);
    if (gAudioPolicyService == 0) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
@@ -567,15 +570,10 @@ const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service()
        }
        binder->linkToDeath(gAudioPolicyServiceClient);
        gAudioPolicyService = interface_cast<IAudioPolicyService>(binder);
        gLock.unlock();
        // Registering the client takes the AudioPolicyService lock.
        // Don't hold the AudioSystem lock at the same time.
        LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0);
        gAudioPolicyService->registerClient(gAudioPolicyServiceClient);
    } else {
        // There exists a benign race condition where gAudioPolicyService
        // is set, but gAudioPolicyServiceClient is not yet registered.
        gLock.unlock();
    }

    return gAudioPolicyService;
}

@@ -841,9 +839,18 @@ status_t AudioSystem::setLowRamDevice(bool isLowRamDevice)

void AudioSystem::clearAudioConfigCache()
{
    Mutex::Autolock _l(gLock);
    // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances
    ALOGV("clearAudioConfigCache()");
    {
        Mutex::Autolock _l(gLock);
        gOutputs.clear();
        gAudioFlinger.clear();
    }
    {
        Mutex::Autolock _l(gLockAPS);
        gAudioPolicyService.clear();
    }
    // Do not clear gAudioPortCallback
}

bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
@@ -905,7 +912,7 @@ status_t AudioSystem::setAudioPortConfig(const struct audio_port_config *config)

void AudioSystem::setAudioPortCallback(sp<AudioPortCallback> callBack)
{
    Mutex::Autolock _l(gLock);
    Mutex::Autolock _l(gLockAPC);
    gAudioPortCallback = callBack;
}

@@ -937,18 +944,23 @@ audio_mode_t AudioSystem::getPhoneState()

void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused)
{
    Mutex::Autolock _l(gLock);
    {
        Mutex::Autolock _l(gLockAPC);
        if (gAudioPortCallback != 0) {
            gAudioPortCallback->onServiceDied();
        }
    }
    {
        Mutex::Autolock _l(gLockAPS);
        AudioSystem::gAudioPolicyService.clear();
    }

    ALOGW("AudioPolicyService server died!");
}

void AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate()
{
    Mutex::Autolock _l(gLock);
    Mutex::Autolock _l(gLockAPC);
    if (gAudioPortCallback != 0) {
        gAudioPortCallback->onAudioPortListUpdate();
    }
@@ -956,7 +968,7 @@ void AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate()

void AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate()
{
    Mutex::Autolock _l(gLock);
    Mutex::Autolock _l(gLockAPC);
    if (gAudioPortCallback != 0) {
        gAudioPortCallback->onAudioPatchListUpdate();
    }
+1 −1
Original line number Diff line number Diff line
@@ -1828,7 +1828,7 @@ status_t AudioTrack::restoreTrack_l(const char *from)
    status_t result;

    // refresh the audio configuration cache in this process to make sure we get new
    // output parameters in createTrack_l()
    // output parameters and new IAudioFlinger in createTrack_l()
    AudioSystem::clearAudioConfigCache();

    if (isOffloadedOrDirect_l()) {