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

Commit 0c280aa1 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

AudioFlinger: update cache in/out configuration on device port id change



In case of creation of AudioPatch with the same device type but a different
device id (typically: a device has been connected / disconnection, so
removed and re-attached to its corresponding module, a new Id is assigned),
the cache configuration of the clients is not updated.
If the client calls getRoutedDevice, the id will not be up to date and even
may refer to unknown port id.

Test: as follows:
1 / Calls setDeviceConnectionState AUDIO_DEVICE_OUT_HDMI state=1 mame=y_dummy_hdmi @=my_dummy_hdmi
2 / Plays explicititely on this device (by getting the id
	AudioSystem::listAudioPorts

2 / Calls setDeviceConnectionState AUDIO_DEVICE_OUT_HDMI state=0

3 / Calls setDeviceConnectionState AUDIO_DEVICE_OUT_HDMI state=1  mame=y_dummy_hdmi @=my_dummy_hdmi
    Plays explicititely on this device (by getting the id
        AudioSystem::listAudioPorts

4 / Calls AudioTrack->getRoutedDeviceId()
	The id shall match the second one, NOT the first one
that does not exist any more

Change-Id: I608ed8d78907b5ea1c9b6ef13c6cbfe528d88f44
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 3305c11a
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -3850,6 +3850,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat
        type |= patch->sinks[i].ext.device.type;
    }

    audio_port_handle_t sinkPortId = patch->sinks[0].id;
#ifdef ADD_BATTERY_DATA
    // when changing the audio output device, call addBatteryData to notify
    // the change
@@ -3879,7 +3880,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat

    // mPrevOutDevice is the latest device set by createAudioPatch_l(). It is not set when
    // the thread is created so that the first patch creation triggers an ioConfigChanged callback
    bool configChanged = mPrevOutDevice != type;
    bool configChanged = (mPrevOutDevice != type) || (mDeviceId != sinkPortId);
    mOutDevice = type;
    mPatch = *patch;

@@ -3908,6 +3909,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat
    }
    if (configChanged) {
        mPrevOutDevice = type;
        mDeviceId = sinkPortId;
        sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED);
    }
    return status;
@@ -8145,6 +8147,7 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch

    // store new device and send to effects
    mInDevice = patch->sources[0].ext.device.type;
    audio_port_handle_t deviceId = patch->sources[0].id;
    mPatch = *patch;
    for (size_t i = 0; i < mEffectChains.size(); i++) {
        mEffectChains[i]->setDevice_l(mInDevice);
@@ -8186,9 +8189,10 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch
        *handle = AUDIO_PATCH_HANDLE_NONE;
    }

    if (mInDevice != mPrevInDevice) {
    if ((mInDevice != mPrevInDevice) || (mDeviceId != deviceId)) {
        sendIoConfigEvent_l(AUDIO_INPUT_CONFIG_CHANGED);
        mPrevInDevice = mInDevice;
        mDeviceId = deviceId;
    }

    return status;
@@ -8285,7 +8289,7 @@ AudioFlinger::MmapThread::MmapThread(
        audio_devices_t outDevice, audio_devices_t inDevice, bool systemReady)
    : ThreadBase(audioFlinger, id, outDevice, inDevice, MMAP, systemReady),
      mSessionId(AUDIO_SESSION_NONE),
      mDeviceId(AUDIO_PORT_HANDLE_NONE), mPortId(AUDIO_PORT_HANDLE_NONE),
      mPortId(AUDIO_PORT_HANDLE_NONE),
      mHalStream(stream), mHalDevice(hwDev->hwDevice()), mAudioHwDev(hwDev),
      mActiveTracks(&this->mLocalLog),
      mHalVolFloat(-1.0f), // Initialize to illegal value so it always gets set properly later.
@@ -8769,7 +8773,7 @@ status_t AudioFlinger::MmapThread::createAudioPatch_l(const struct audio_patch *
        *handle = AUDIO_PATCH_HANDLE_NONE;
    }

    if (isOutput() && mPrevOutDevice != mOutDevice) {
    if (isOutput() && (mPrevOutDevice != mOutDevice || mDeviceId != deviceId)) {
        mPrevOutDevice = type;
        sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED);
        sp<MmapStreamCallback> callback = mCallback.promote();
@@ -8780,7 +8784,7 @@ status_t AudioFlinger::MmapThread::createAudioPatch_l(const struct audio_patch *
        }
        mDeviceId = deviceId;
    }
    if (!isOutput() && mPrevInDevice != mInDevice) {
    if (!isOutput() && (mPrevInDevice != mInDevice || mDeviceId != deviceId)) {
        mPrevInDevice = type;
        sendIoConfigEvent_l(AUDIO_INPUT_CONFIG_CHANGED);
        sp<MmapStreamCallback> callback = mCallback.promote();
+4 −1
Original line number Diff line number Diff line
@@ -485,6 +485,10 @@ protected:
                audio_devices_t         mPrevOutDevice;   // previous output device
                audio_devices_t         mPrevInDevice;    // previous input device
                struct audio_patch      mPatch;
                /**
                 * @brief mDeviceId  current device port unique identifier
                 */
                audio_port_handle_t     mDeviceId = AUDIO_PORT_HANDLE_NONE;
                audio_source_t          mAudioSource;

                const audio_io_handle_t mId;
@@ -1704,7 +1708,6 @@ class MmapThread : public ThreadBase

                audio_attributes_t      mAttr;
                audio_session_t         mSessionId;
                audio_port_handle_t     mDeviceId;
                audio_port_handle_t     mPortId;

                wp<MmapStreamCallback>  mCallback;