Merge tag 'AUDIO.LA.8.0.r1-10800-KAILUA.0' into staging/lineage-21.0_merge-AUDIO.LA.8.0.r1-10800-KAILUA.0

AUDIO.LA.8.0.r1-10800-KAILUA.0

# By Brahmaiah (2) and others
# Via Gerrit - the friendly Code Review server (4) and others
* tag 'AUDIO.LA.8.0.r1-10800-KAILUA.0':
  Revert "Revert "PAL: set device rotation with parameters""
  pal: fix null pointer dereference issue during cts
  Revert "PAL: set device rotation with parameters"
  Set Orientation TKV for Enqore during device switch
  configs: kalama: use secondary mi2s backend for hdmi out for rb5gen2DVT
  pal: retry all active streams with BT_IN suspendedDevIds in a2dpCaptureResume
  pal: update aim300 mixer path file to support smartrecorder app test case
  pal: partially revert change 5149268 to fix regressions
  pal: add IDLE stream to shared BE active streams
  PAL: set device rotation with parameters

Change-Id: Iade05260beffcf274bf88a07e8d9555b460e8cae
diff --git a/configs/kalama/mixer_paths_kalama_aim.xml b/configs/kalama/mixer_paths_kalama_aim.xml
index dd4b367..c85fb7d 100644
--- a/configs/kalama/mixer_paths_kalama_aim.xml
+++ b/configs/kalama/mixer_paths_kalama_aim.xml
@@ -1094,17 +1094,12 @@
         <ctl name="TX_AIF1_CAP Mixer DEC3" value="1" />
         <ctl name="TX DEC2 MUX" value="SWR_MIC" />
         <ctl name="TX DEC3 MUX" value="SWR_MIC" />
-        <ctl name="TX SMIC MUX2" value="SWR_MIC4" />
-        <ctl name="TX SMIC MUX3" value="SWR_MIC5" />
-        <ctl name="TX0 MODE" value="ADC_LP" />
-        <ctl name="TX3 MODE" value="ADC_LP" />
-        <ctl name="ADC2 MUX" value="INP3" />
-        <ctl name="ADC1 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="ADC2 ChMap" value="SWRM_TX2_CH2" />
-        <ctl name="ADC1_MIXER Switch" value="1" />
-        <ctl name="ADC2_MIXER Switch" value="1" />
-        <ctl name="AMIC1_MIXER Switch" value="1" />
-        <ctl name="AMIC3_MIXER Switch" value="1" />
+        <ctl name="TX SMIC MUX2" value="SWR_MIC1" />
+        <ctl name="TX SMIC MUX3" value="SWR_MIC3" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
+        <ctl name="DMIC3 ChMap" value="SWRM_TX1_CH4" />
+        <ctl name="DMIC1_MIXER Switch" value="1" />
+        <ctl name="DMIC3_MIXER Switch" value="1" />
     </path>
 
     <path name="speaker-dmic-endfire">
diff --git a/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml b/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
index 6ef74c6..fec0183 100644
--- a/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
+++ b/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
@@ -28,7 +28,7 @@
 
 * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
 *
-* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+* Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted (subject to the limitations in the
@@ -912,11 +912,13 @@
         </out-device>
         <out-device>
             <id>PAL_DEVICE_OUT_HDMI</id>
-            <back_end_name>DISPLAY_PORT-RX</back_end_name>
-            <max_channels>32</max_channels>
+            <back_end_name>MI2S-LPAIF-RX-SECONDARY</back_end_name>
+            <max_channels>2</max_channels>
             <channels>2</channels>
             <fractional_sr>1</fractional_sr>
-            <snd_device_name>display-port</snd_device_name>
+            <snd_device_name>hdmi-port</snd_device_name>
+            <samplerate>48000</samplerate>
+            <bit_width>16</bit_width>
             <usecase>
                 <name>PAL_STREAM_VOICE_CALL</name>
                 <priority>1</priority>
diff --git a/resource_manager/src/ResourceManager.cpp b/resource_manager/src/ResourceManager.cpp
index b989f58..ffd926e 100644
--- a/resource_manager/src/ResourceManager.cpp
+++ b/resource_manager/src/ResourceManager.cpp
@@ -26,9 +26,9 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
  *
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
  */
 
@@ -6918,7 +6918,15 @@
         if (backEndName == listAllBackEndIds[i].second) {
             dev = Device::getObject((pal_device_id_t) i);
             if(dev) {
-                getActiveStream_l(activeStreams, dev);
+                std::list<Stream*>::iterator it;
+                for(it = mActiveStreams.begin(); it != mActiveStreams.end(); it++) {
+                    std::vector <std::shared_ptr<Device>> devices;
+                    (*it)->getAssociatedDevices(devices);
+                    typename std::vector<std::shared_ptr<Device>>::iterator result =
+                             std::find(devices.begin(), devices.end(), dev);
+                    if (result != devices.end())
+                        activeStreams.push_back(*it);
+                }
                 PAL_DBG(LOG_TAG, "got dev %d active streams on dev is %zu", i, activeStreams.size() );
                 for (int j=0; j < activeStreams.size(); j++) {
                     /*do not add if this is a dup*/
@@ -8975,7 +8983,7 @@
     }
 
     getOrphanStream_l(orphanStreams, retryStreams);
-    if (activeStreams.empty() && orphanStreams.empty()) {
+    if (activeStreams.empty() && orphanStreams.empty() && retryStreams.empty()) {
         PAL_DBG(LOG_TAG, "no active streams found");
         mActiveStreamMutex.unlock();
         goto exit;
@@ -9001,6 +9009,24 @@
         }
     }
 
+    // retry all streams which failed to switch to desired device previously.
+    for (sIter = retryStreams.begin(); sIter != retryStreams.end(); sIter++) {
+        (*sIter)->lockStreamMutex();
+        if (std::find((*sIter)->suspendedDevIds.begin(), (*sIter)->suspendedDevIds.end(),
+            a2dpDattr.id) != (*sIter)->suspendedDevIds.end()) {
+            std::vector<std::shared_ptr<Device>> devices;
+            (*sIter)->getAssociatedDevices(devices);
+            if (devices.size() > 0) {
+                for (auto device : devices) {
+                    streamDevDisconnect.push_back({ (*sIter), device->getSndDeviceId() });
+                }
+            }
+            restoredStreams.push_back((*sIter));
+            streamDevConnect.push_back({ (*sIter), &a2dpDattr });
+        }
+        (*sIter)->unlockStreamMutex();
+    }
+
     if (restoredStreams.empty()) {
         PAL_DBG(LOG_TAG, "no streams to be restored");
         mActiveStreamMutex.unlock();
@@ -9973,6 +9999,11 @@
                 struct pal_stream_attributes sAttr;
                 Stream* stream = NULL;
                 std::vector<Stream*> activestreams;
+                struct pal_device sco_tx_dattr;
+                std::shared_ptr<Device> sco_tx_dev = nullptr;
+                std::vector<Stream*>::iterator sIter;
+                pal_stream_type_t streamType;
+
 
                 mActiveStreamMutex.lock();
                 sco_rx_dattr.id = PAL_DEVICE_OUT_BLUETOOTH_SCO;
@@ -9993,6 +10024,26 @@
                         mActiveStreamMutex.lock();
                     }
                 }
+
+                /* Handle bt sco running usecase */
+                sco_tx_dattr.id = PAL_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
+                if (isDeviceAvailable(sco_tx_dattr.id)) {
+                    sco_tx_dev = Device::getInstance(&sco_tx_dattr, rm);
+                    getActiveStream_l(activestreams, sco_tx_dev);
+                    for (sIter = activestreams.begin(); sIter != activestreams.end(); sIter++) {
+                        status = (*sIter)->getStreamType(&streamType);
+                        if (0 != status) {
+                            PAL_ERR(LOG_TAG, "getStreamType failed with status = %d", status);
+                            continue;
+                        }
+                        if ((streamType == PAL_STREAM_VOIP_TX) ||
+                            (streamType == PAL_STREAM_DEEP_BUFFER)) {
+                            (*sIter)->suspendedDevIds.clear();
+                            (*sIter)->suspendedDevIds.push_back(a2dp_dattr.id);
+                            PAL_DBG(LOG_TAG, "a2dp resumed, mark sco streams as to route them later");
+                        }
+                    }
+                }
                 mActiveStreamMutex.unlock();
             }
 
diff --git a/session/src/SessionAlsaCompress.cpp b/session/src/SessionAlsaCompress.cpp
index e6b9e9e..abedfc9 100644
--- a/session/src/SessionAlsaCompress.cpp
+++ b/session/src/SessionAlsaCompress.cpp
@@ -939,17 +939,43 @@
     deviceToConnect->getDeviceAttributes(&dAttr);
 
     if (!rxAifBackEndsToConnect.empty()) {
-        status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
-            dAttr, compressDevIds, rxAifBackEndsToConnect);
         for (const auto &elem : rxAifBackEndsToConnect)
             rxAifBackEnds.push_back(elem);
+        status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
+            dAttr, compressDevIds, rxAifBackEndsToConnect);
+        if (status) {
+            int cnt = 0;
+            for (const auto &elem : rxAifBackEnds) {
+                cnt++;
+                for (const auto &connectElem : rxAifBackEndsToConnect) {
+                    if (std::get<0>(elem) == std::get<0>(connectElem)) {
+                        rxAifBackEnds.erase(rxAifBackEnds.begin() + cnt - 1, rxAifBackEnds.begin() + cnt);
+                        cnt--;
+                        break;
+                    }
+                }
+            }
+        }
     }
 
     if (!txAifBackEndsToConnect.empty()) {
-        status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
-            dAttr, compressDevIds, txAifBackEndsToConnect);
         for (const auto &elem : txAifBackEndsToConnect)
             txAifBackEnds.push_back(elem);
+        status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
+            dAttr, compressDevIds, txAifBackEndsToConnect);
+        if (status) {
+            int cnt = 0;
+            for (const auto &elem : txAifBackEnds) {
+                cnt++;
+                for (const auto &connectElem : txAifBackEndsToConnect) {
+                    if (std::get<0>(elem) == std::get<0>(connectElem)) {
+                        txAifBackEnds.erase(txAifBackEnds.begin() + cnt - 1, txAifBackEnds.begin() + cnt);
+                        cnt--;
+                        break;
+                    }
+                }
+            }
+        }
 
     }
 
diff --git a/session/src/SessionAlsaPcm.cpp b/session/src/SessionAlsaPcm.cpp
index efd5284..e34436a 100644
--- a/session/src/SessionAlsaPcm.cpp
+++ b/session/src/SessionAlsaPcm.cpp
@@ -2178,6 +2178,9 @@
     deviceToConnect->getDeviceAttributes(&dAttr);
 
     if (!rxAifBackEndsToConnect.empty()) {
+        for (const auto &elem : rxAifBackEndsToConnect)
+            rxAifBackEnds.push_back(elem);
+
         if (streamType != PAL_STREAM_ULTRASOUND &&
             streamType != PAL_STREAM_LOOPBACK)
             status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
@@ -2186,16 +2189,27 @@
             status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
                      dAttr, pcmDevTxIds, pcmDevRxIds, rxAifBackEndsToConnect);
 
-        if (!status) {
-            for (const auto &elem : rxAifBackEndsToConnect)
-                rxAifBackEnds.push_back(elem);
-        } else {
+        if (status) {
             PAL_ERR(LOG_TAG, "failed to connect rxAifBackEnds: %d",
                     (pcmDevIds.size() ? pcmDevIds.at(0) : pcmDevRxIds.at(0)));
+            int cnt = 0;
+            for (const auto &elem : rxAifBackEnds) {
+                cnt++;
+                for (const auto &connectElem : rxAifBackEndsToConnect) {
+                    if (std::get<0>(elem) == std::get<0>(connectElem)) {
+                        rxAifBackEnds.erase(rxAifBackEnds.begin() + cnt - 1, rxAifBackEnds.begin() + cnt);
+                        cnt--;
+                        break;
+                    }
+                }
+            }
         }
     }
 
     if (!txAifBackEndsToConnect.empty()) {
+        for (const auto &elem : txAifBackEndsToConnect)
+            txAifBackEnds.push_back(elem);
+
         if (streamType != PAL_STREAM_LOOPBACK)
             status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
                      dAttr, (pcmDevIds.size() ? pcmDevIds : pcmDevTxIds), txAifBackEndsToConnect);
@@ -2203,12 +2217,20 @@
             status = SessionAlsaUtils::connectSessionDevice(this, streamHandle, streamType, rm,
                      dAttr, pcmDevTxIds, pcmDevRxIds, txAifBackEndsToConnect);
 
-        if (!status) {
-            for (const auto &elem : txAifBackEndsToConnect)
-                txAifBackEnds.push_back(elem);
-        } else {
+        if (status) {
+            int cnt = 0;
             PAL_ERR(LOG_TAG, "failed to connect txAifBackEnds: %d",
                     (pcmDevIds.size() ? pcmDevIds.at(0) : pcmDevTxIds.at(0)));
+            for (const auto &elem : txAifBackEnds) {
+                cnt++;
+                for (const auto &connectElem : txAifBackEndsToConnect) {
+                    if (std::get<0>(elem) == std::get<0>(connectElem)) {
+                        txAifBackEnds.erase(txAifBackEnds.begin() + cnt - 1, txAifBackEnds.begin() + cnt);
+                        cnt--;
+                        break;
+                    }
+                }
+            }
         }
     }
 
@@ -2404,8 +2426,10 @@
         {
             pal_param_device_rotation_t *rotation =
                                          (pal_param_device_rotation_t *)payload;
-            status = handleDeviceRotation(streamHandle, rotation->rotation_type,
-                                          device, mixer, builder, rxAifBackEnds);
+            if (!rxAifBackEnds.empty()) {
+                status = handleDeviceRotation(streamHandle, rotation->rotation_type,
+                                              device, mixer, builder, rxAifBackEnds);
+            }
             goto exit;
         }
         case PAL_PARAM_ID_LOAD_SOUND_MODEL:
diff --git a/session/src/SessionAlsaUtils.cpp b/session/src/SessionAlsaUtils.cpp
index ce1fc9d..c9f7a7b 100644
--- a/session/src/SessionAlsaUtils.cpp
+++ b/session/src/SessionAlsaUtils.cpp
@@ -2313,6 +2313,7 @@
 
                 if (strcmp(dAttr.custom_config.custom_key, "mspp") &&
                     dAttr.id == PAL_DEVICE_OUT_SPEAKER &&
+                    dAttr.config.ch_info.channels == 2 &&
                     ((sAttr.type == PAL_STREAM_LOW_LATENCY) ||
                     (sAttr.type == PAL_STREAM_ULTRA_LOW_LATENCY) ||
                     (sAttr.type == PAL_STREAM_PCM_OFFLOAD) ||
@@ -2321,9 +2322,7 @@
                     pal_param_device_rotation_t rotation;
                     rotation.rotation_type = rm->mOrientation == ORIENTATION_270 ?
                                             PAL_SPEAKER_ROTATION_RL : PAL_SPEAKER_ROTATION_LR;
-                    status = sess->handleDeviceRotation(streamHandle, rotation.rotation_type,
-                                                    pcmDevIds.at(0), mixerHandle, builder,
-                                                    aifBackEndsToConnect);
+                    status = sess->setParameters(streamHandle, 0, PAL_PARAM_ID_DEVICE_ROTATION, &rotation);
                     if (status != 0) {
                         PAL_ERR(LOG_TAG,"handleDeviceRotation failed");
                         status = 0; //rotaton setting failed is not fatal.
@@ -2384,6 +2383,15 @@
                 goto exit;
             }
         }
+        if (sAttr.direction == PAL_AUDIO_INPUT) {
+            if (strstr(dAttr.custom_config.custom_key , "unprocessed-hdr-mic")) {
+                status = sess->setConfig(streamHandle, MODULE,  ORIENTATION_TAG);
+                if (0 != status) {
+                    PAL_ERR(LOG_TAG, "setting HDR record orientation config failed with status %d", status);
+                    goto exit;
+                }
+            }
+        }
     } else if (!(SessionAlsaUtils::isMmapUsecase(sAttr))) {
         if (sess) {
             SessionAlsaVoice *voiceSession = dynamic_cast<SessionAlsaVoice *>(sess);
diff --git a/stream/src/Stream.cpp b/stream/src/Stream.cpp
index 414711e..7cd64d8 100644
--- a/stream/src/Stream.cpp
+++ b/stream/src/Stream.cpp
@@ -1,6 +1,5 @@
 /*
  * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -27,8 +26,8 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted (subject to the limitations in the
@@ -1117,7 +1116,13 @@
     int32_t status = 0;
 
     if (currentState == STREAM_IDLE) {
-        PAL_DBG(LOG_TAG, "stream is in %d state, no need to switch device", currentState);
+        for (int i = 0; i < mDevices.size(); i++) {
+            if (dev_id == mDevices[i]->getSndDeviceId()) {
+                mDevices.erase(mDevices.begin() + i);
+                PAL_DBG(LOG_TAG, "stream is in IDLE state, erase device: %d", dev_id);
+                break;
+            }
+        }
         status = 0;
         goto exit;
     }
@@ -1207,7 +1212,8 @@
     dev->setDeviceAttributes(*dattr);
 
     if (currentState == STREAM_IDLE) {
-        PAL_DBG(LOG_TAG, "stream is in %d state, no need to switch device", currentState);
+        PAL_DBG(LOG_TAG, "stream is in IDLE state, insert %d to mDevices", dev->getSndDeviceId());
+        mDevices.push_back(dev);
         status = 0;
         goto exit;
     }
diff --git a/stream/src/StreamCommon.cpp b/stream/src/StreamCommon.cpp
index d9cf880..a2cd8d2 100644
--- a/stream/src/StreamCommon.cpp
+++ b/stream/src/StreamCommon.cpp
@@ -1,6 +1,5 @@
 /*
  * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -26,6 +25,10 @@
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
+ * SPDX-License-Identifier: BSD-3-Clause-Clear
  */
 
 #define LOG_TAG "PAL: StreamCommon"
diff --git a/stream/src/StreamCompress.cpp b/stream/src/StreamCompress.cpp
index 72a7ce1..d2068af 100644
--- a/stream/src/StreamCompress.cpp
+++ b/stream/src/StreamCompress.cpp
@@ -26,8 +26,8 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
  */
 
@@ -129,7 +129,9 @@
 
     session->registerCallBack(handleSessionCallBack, (uint64_t)this);
     PAL_VERBOSE(LOG_TAG,"Create new Devices with no_of_devices - %d", no_of_devices);
+    bool str_registered = false;
     for (uint32_t i = 0; i < no_of_devices; i++) {
+
         dev = Device::getInstance((struct pal_device *)&dattr[i] , rm);
         if (dev == nullptr) {
             PAL_ERR(LOG_TAG, "Device creation is failed");
@@ -140,6 +142,10 @@
         dev->insertStreamDeviceAttr(&dattr[i], this);
         mPalDevices.push_back(dev);
         mStreamMutex.unlock();
+        if (!str_registered) {
+            rm->registerStream(this);
+            str_registered = true;
+        }
         isDeviceConfigUpdated = rm->updateDeviceConfig(&dev, &dattr[i], sattr);
         mStreamMutex.lock();
 
@@ -150,7 +156,6 @@
         dev = nullptr;
     }
     mStreamMutex.unlock();
-    rm->registerStream(this);
     PAL_VERBOSE(LOG_TAG,"exit, state %d", currentState);
 }
 
diff --git a/stream/src/StreamPCM.cpp b/stream/src/StreamPCM.cpp
index 6646570..db300d4 100644
--- a/stream/src/StreamPCM.cpp
+++ b/stream/src/StreamPCM.cpp
@@ -26,8 +26,8 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
  */
 
@@ -123,6 +123,7 @@
     }
 
     PAL_VERBOSE(LOG_TAG, "Create new Devices with no_of_devices - %d", no_of_devices);
+    bool str_registered = false;
     for (int i = 0; i < no_of_devices; i++) {
         //Check with RM if the configuration given can work or not
         //for e.g., if incoming stream needs 24 bit device thats also
@@ -140,6 +141,14 @@
         dev->insertStreamDeviceAttr(&dattr[i], this);
         mPalDevices.push_back(dev);
         mStreamMutex.unlock();
+        /* Stream mutex is unlocked before calling stream specific API
+         * in resource manager to avoid deadlock issues between stream
+         * and active stream mutex from ResourceManager.
+         */
+        if (!str_registered) {
+            rm->registerStream(this);
+            str_registered = true;
+        }
         isDeviceConfigUpdated = rm->updateDeviceConfig(&dev, &dattr[i], sattr);
         mStreamMutex.lock();
 
@@ -159,11 +168,6 @@
         session->registerCallBack(handleSoftPauseCallBack, (uint64_t)this);
 
     mStreamMutex.unlock();
-    /* Stream mutex is unlocked before calling stream specific API
-     * in resource manager to avoid deadlock issues between stream
-     * and active stream mutex from ResourceManager.
-     */
-    rm->registerStream(this);
     PAL_DBG(LOG_TAG, "Exit. state %d", currentState);
     return;
 }
diff --git a/stream/src/StreamSensorPCMData.cpp b/stream/src/StreamSensorPCMData.cpp
index 3332ec5..b125c33 100644
--- a/stream/src/StreamSensorPCMData.cpp
+++ b/stream/src/StreamSensorPCMData.cpp
@@ -26,8 +26,8 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
  */
 
@@ -62,7 +62,6 @@
     }
 
     rm->registerStream(this);
-
     /* Print the concurrency feature flags supported */
     PAL_INFO(LOG_TAG, "capture conc enable %d,voice conc enable %d,voip conc enable %d",
              acd_info_->GetConcurrentCaptureEnable(),
diff --git a/stream/src/StreamUltraSound.cpp b/stream/src/StreamUltraSound.cpp
index 63827f1..8b6566d 100644
--- a/stream/src/StreamUltraSound.cpp
+++ b/stream/src/StreamUltraSound.cpp
@@ -26,8 +26,8 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Changes from Qualcomm Innovation Center are provided under the following license:
- * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
+ * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  * SPDX-License-Identifier: BSD-3-Clause-Clear
  */