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

Commit 8a537f2c authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

audio policy: optimize preferred device selection am: 72af8011

parents 712dbc15 72af8011
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -1684,13 +1684,21 @@ audio_io_handle_t AudioTrack::getOutput() const

status_t AudioTrack::setOutputDevice(audio_port_handle_t deviceId) {
    AutoMutex lock(mLock);
    ALOGV("%s(%d): deviceId=%d mSelectedDeviceId=%d",
            __func__, mPortId, deviceId, mSelectedDeviceId);
    ALOGV("%s(%d): deviceId=%d mSelectedDeviceId=%d mRoutedDeviceId %d",
            __func__, mPortId, deviceId, mSelectedDeviceId, mRoutedDeviceId);
    if (mSelectedDeviceId != deviceId) {
        mSelectedDeviceId = deviceId;
        if (mStatus == NO_ERROR) {
        if (mStatus == NO_ERROR && mSelectedDeviceId != mRoutedDeviceId) {
            if (isPlaying_l()) {
                android_atomic_or(CBLK_INVALID, &mCblk->mFlags);
                mProxy->interrupt();
            } else {
                // if the track is idle, try to restore now and
                // defer to next start if not possible
                if (restoreTrack_l("setOutputDevice") != OK) {
                    android_atomic_or(CBLK_INVALID, &mCblk->mFlags);
                }
            }
        }
    }
    return NO_ERROR;
+3 −0
Original line number Diff line number Diff line
@@ -1116,6 +1116,9 @@ public:

            bool isPlaying() {
                AutoMutex lock(mLock);
                return isPlaying_l();
            }
            bool isPlaying_l() {
                return mState == STATE_ACTIVE || mState == STATE_STOPPING;
            }

+0 −1
Original line number Diff line number Diff line
@@ -1836,7 +1836,6 @@ MediaPlayerService::AudioOutput::AudioOutput(audio_session_t sessionId,
    } else {
        mAttributes = NULL;
    }

    setMinBufferCount();
}

+4 −0
Original line number Diff line number Diff line
@@ -301,6 +301,10 @@ public:
        return mActiveClients;
    }

    // Returns 0 if not all active clients have the same exclusive preferred device
    // or the number of active clients with the same exclusive preferred device
    size_t sameExclusivePreferredDevicesCount() const;

    bool useHwGain() const
    {
        return !devices().isEmpty() ? devices().itemAt(0)->hasGainController() : false;
+21 −0
Original line number Diff line number Diff line
@@ -237,6 +237,27 @@ TrackClientVector AudioOutputDescriptor::clientsList(bool activeOnly, product_st
    return clients;
}

size_t AudioOutputDescriptor::sameExclusivePreferredDevicesCount() const
{
    audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE;
    size_t count = 0;
    for (const auto &client : getClientIterable()) {
        if (client->active()) {
            if (!(client->hasPreferredDevice() &&
                    client->isPreferredDeviceForExclusiveUse())) {
                return 0;
            }
            if (deviceId == AUDIO_PORT_HANDLE_NONE) {
                deviceId = client->preferredDeviceId();
            } else if (deviceId != client->preferredDeviceId()) {
                return 0;
            }
            count++;
        }
    }
    return count;
}

bool AudioOutputDescriptor::isAnyActive(VolumeSource volumeSourceToIgnore) const
{
    return std::find_if(begin(mActiveClients), end(mActiveClients),
Loading