Merge "pal: update aim300 mixer path file to support smartrecorder app test case"
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 61d7ed2..ffd926e 100644
--- a/resource_manager/src/ResourceManager.cpp
+++ b/resource_manager/src/ResourceManager.cpp
@@ -8983,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;
@@ -9009,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();
@@ -9981,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;
@@ -10001,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();
             }