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

Commit 72c8b066 authored by Kuowei Li's avatar Kuowei Li Committed by Dorin Drimus
Browse files

audio: support restoreTrack for direct and offload track

1. For direct and offload track, setOutputDevice() must be called
at stopped or flushed state.
2. Since mRoutedDeviceId will not be updated immediatly when default
device in policy is changed, do not check mRoutedDeviceId in
setOutputDevice().

Bug: 297164626
Test: Manual

Change-Id: I323a6bbf7be9f757851d3adf25681d034deb8b22
parent d971c58c
Loading
Loading
Loading
Loading
+29 −15
Original line number Diff line number Diff line
@@ -1699,12 +1699,24 @@ audio_io_handle_t AudioTrack::getOutput() const
}

status_t AudioTrack::setOutputDevice(audio_port_handle_t deviceId) {
    status_t result = NO_ERROR;
    AutoMutex lock(mLock);
    ALOGV("%s(%d): deviceId=%d mSelectedDeviceId=%d mRoutedDeviceId %d",
            __func__, mPortId, deviceId, mSelectedDeviceId, mRoutedDeviceId);
    ALOGV("%s(%d): deviceId=%d mSelectedDeviceId=%d",
            __func__, mPortId, deviceId, mSelectedDeviceId);
    if (mSelectedDeviceId != deviceId) {
        mSelectedDeviceId = deviceId;
        if (mStatus == NO_ERROR) {
            if (isOffloadedOrDirect_l()) {
                if (mState == STATE_STOPPED || mState == STATE_FLUSHED) {
                    ALOGD("%s(%d): creating a new AudioTrack", __func__, mPortId);
                    result = restoreTrack_l("setOutputDevice", true /* forceRestore */);
                } else {
                    ALOGW("%s(%d). Offloaded or Direct track is not STOPPED or FLUSHED. "
                          "State: %s.",
                            __func__, mPortId, stateToString(mState));
                    result = INVALID_OPERATION;
                }
            } else {
                // allow track invalidation when track is not playing to propagate
                // the updated mSelectedDeviceId
                if (isPlaying_l()) {
@@ -1721,7 +1733,8 @@ status_t AudioTrack::setOutputDevice(audio_port_handle_t deviceId) {
                }
            }
        }
    return NO_ERROR;
    }
    return result;
}

audio_port_handle_t AudioTrack::getOutputDevice() {
@@ -2835,7 +2848,7 @@ nsecs_t AudioTrack::processAudioBuffer()
    return 0;
}

status_t AudioTrack::restoreTrack_l(const char *from)
status_t AudioTrack::restoreTrack_l(const char *from, bool forceRestore)
{
    status_t result = NO_ERROR;  // logged: make sure to set this before returning.
    const int64_t beginNs = systemTime();
@@ -2856,7 +2869,8 @@ status_t AudioTrack::restoreTrack_l(const char *from)
    // output parameters and new IAudioFlinger in createTrack_l()
    AudioSystem::clearAudioConfigCache();

    if (isOffloadedOrDirect_l() || mDoNotReconnect) {
    if (!forceRestore &&
        (isOffloadedOrDirect_l() || mDoNotReconnect)) {
        // FIXME re-creation of offloaded and direct tracks is not yet implemented;
        // reconsider enabling for linear PCM encodings when position can be preserved.
        result = DEAD_OBJECT;
+1 −1
Original line number Diff line number Diff line
@@ -1220,7 +1220,7 @@ public:
            void setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount);

            // FIXME enum is faster than strcmp() for parameter 'from'
            status_t restoreTrack_l(const char *from);
            status_t restoreTrack_l(const char *from, bool forceRestore = false);

            uint32_t    getUnderrunCount_l() const;