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

Commit 633d2ed2 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "audiopolicy: stop output if it's still active before being released."

parents ee75d6f3 7bf382e5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ public:
     * Active ref count of the client will be incremented/decremented through setActive API
     */
    virtual void setClientActive(const sp<TrackClientDescriptor>& client, bool active);
    bool isClientActive(const sp<TrackClientDescriptor>& client);

    bool isActive(uint32_t inPastMs) const;
    bool isActive(VolumeSource volumeSource = VOLUME_SOURCE_NONE,
+6 −0
Original line number Diff line number Diff line
@@ -123,6 +123,12 @@ void AudioOutputDescriptor::setClientActive(const sp<TrackClientDescriptor>& cli
    client->setActive(active);
}

bool AudioOutputDescriptor::isClientActive(const sp<TrackClientDescriptor>& client)
{
    return client != nullptr &&
            std::find(begin(mActiveClients), end(mActiveClients), client) != end(mActiveClients);
}

bool AudioOutputDescriptor::isActive(VolumeSource vs, uint32_t inPastMs, nsecs_t sysTime) const
{
    return (vs == VOLUME_SOURCE_NONE) ?
+7 −3
Original line number Diff line number Diff line
@@ -1954,6 +1954,12 @@ void AudioPolicyManager::releaseOutput(audio_port_handle_t portId)

    ALOGV("releaseOutput() %d", outputDesc->mIoHandle);

    sp<TrackClientDescriptor> client = outputDesc->getClient(portId);
    if (outputDesc->isClientActive(client)) {
        ALOGW("releaseOutput() inactivates portId %d in good faith", portId);
        stopOutput(portId);
    }

    if (outputDesc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT) {
        if (outputDesc->mDirectOpenCount <= 0) {
            ALOGW("releaseOutput() invalid open count %d for output %d",
@@ -1965,9 +1971,7 @@ void AudioPolicyManager::releaseOutput(audio_port_handle_t portId)
            mpClientInterface->onAudioPortListUpdate();
        }
    }
    // stopOutput() needs to be successfully called before releaseOutput()
    // otherwise there may be inaccurate stream reference counts.
    // This is checked in outputDesc->removeClient below.

    outputDesc->removeClient(portId);
}