Merge "AudioFlinger: add audio session for device effects"
diff --git a/media/codec2/vndk/platform/C2BqBuffer.cpp b/media/codec2/vndk/platform/C2BqBuffer.cpp
index 8304f74..62936f6 100644
--- a/media/codec2/vndk/platform/C2BqBuffer.cpp
+++ b/media/codec2/vndk/platform/C2BqBuffer.cpp
@@ -576,10 +576,11 @@
             }
         }
         int migrated = 0;
+        // poolDatas dtor should not be called during lock is held.
+        std::shared_ptr<C2BufferQueueBlockPoolData>
+                poolDatas[NUM_BUFFER_SLOTS];
         {
             sp<GraphicBuffer> buffers[NUM_BUFFER_SLOTS];
-            std::weak_ptr<C2BufferQueueBlockPoolData>
-                    poolDatas[NUM_BUFFER_SLOTS];
             std::scoped_lock<std::mutex> lock(mMutex);
             bool noInit = false;
             for (int i = 0; i < NUM_BUFFER_SLOTS; ++i) {
diff --git a/services/audiopolicy/engine/common/include/LastRemovableMediaDevices.h b/services/audiopolicy/engine/common/include/LastRemovableMediaDevices.h
index 88ac7a1..a3053a4 100755
--- a/services/audiopolicy/engine/common/include/LastRemovableMediaDevices.h
+++ b/services/audiopolicy/engine/common/include/LastRemovableMediaDevices.h
@@ -1,52 +1,52 @@
-/*

- * Copyright (C) 2019 The Android Open Source Project

- *

- * Licensed under the Apache License, Version 2.0 (the "License");

- * you may not use this file except in compliance with the License.

- * You may obtain a copy of the License at

- *

- *      http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing, software

- * distributed under the License is distributed on an "AS IS" BASIS,

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- * See the License for the specific language governing permissions and

- * limitations under the License.

- */

-

-#ifndef ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H

-#define ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H

-

-#include <vector>

-#include <HwModule.h>

-#include <system/audio_policy.h>

-

-namespace android {

-

-typedef enum {

-    GROUP_NONE = -1,

-    GROUP_WIRED,

-    GROUP_BT_A2DP,

-    NUM_GROUP

-} device_out_group_t;

-

-class LastRemovableMediaDevices

-{

-public:

-    void setRemovableMediaDevices(sp<DeviceDescriptor> desc, audio_policy_dev_state_t state);

-    std::vector<audio_devices_t> getLastRemovableMediaDevices(

-            device_out_group_t group = GROUP_NONE) const;

-

-private:

-    struct DeviceGroupDescriptor {

-        sp<DeviceDescriptor> desc;

-        device_out_group_t group;

-    };

-    std::vector<DeviceGroupDescriptor> mMediaDevices;

-

-    device_out_group_t getDeviceOutGroup(audio_devices_t device) const;

-};

-

-} // namespace android

-

-#endif // ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H
\ No newline at end of file
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H
+#define ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H
+
+#include <vector>
+#include <HwModule.h>
+#include <system/audio_policy.h>
+
+namespace android {
+
+typedef enum {
+    GROUP_NONE = -1,
+    GROUP_WIRED,
+    GROUP_BT_A2DP,
+    NUM_GROUP
+} device_out_group_t;
+
+class LastRemovableMediaDevices
+{
+public:
+    void setRemovableMediaDevices(sp<DeviceDescriptor> desc, audio_policy_dev_state_t state);
+    std::vector<audio_devices_t> getLastRemovableMediaDevices(
+            device_out_group_t group = GROUP_NONE) const;
+
+private:
+    struct DeviceGroupDescriptor {
+        sp<DeviceDescriptor> desc;
+        device_out_group_t group;
+    };
+    std::vector<DeviceGroupDescriptor> mMediaDevices;
+
+    device_out_group_t getDeviceOutGroup(audio_devices_t device) const;
+};
+
+} // namespace android
+
+#endif // ANDROID_LAST_REMOVABLE_MEDIA_DEVICES_H
diff --git a/services/audiopolicy/engine/common/src/LastRemovableMediaDevices.cpp b/services/audiopolicy/engine/common/src/LastRemovableMediaDevices.cpp
index 0eb22ce..87b6aaf 100755
--- a/services/audiopolicy/engine/common/src/LastRemovableMediaDevices.cpp
+++ b/services/audiopolicy/engine/common/src/LastRemovableMediaDevices.cpp
@@ -1,78 +1,78 @@
-/*

- * Copyright (C) 2019 The Android Open Source Project

- *

- * Licensed under the Apache License, Version 2.0 (the "License");

- * you may not use this file except in compliance with the License.

- * You may obtain a copy of the License at

- *

- *      http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing, software

- * distributed under the License is distributed on an "AS IS" BASIS,

- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

- * See the License for the specific language governing permissions and

- * limitations under the License.

- */

-

-#define LOG_TAG "APM::AudioPolicyEngine/LastRemovableMediaDevices"

-//#define LOG_NDEBUG 0

-

-#include "LastRemovableMediaDevices.h"

-#include <log/log.h>

-

-namespace android {

-

-void LastRemovableMediaDevices::setRemovableMediaDevices(sp<DeviceDescriptor> desc,

-                                                         audio_policy_dev_state_t state)

-{

-    if (desc == nullptr) {

-        return;

-    } else {

-        if ((state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) &&

-                (getDeviceOutGroup(desc->type()) != GROUP_NONE)) {

-            setRemovableMediaDevices(desc, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE);

-            mMediaDevices.insert(mMediaDevices.begin(), {desc, getDeviceOutGroup(desc->type())});

-        } else if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {

-            for (auto iter = mMediaDevices.begin(); iter != mMediaDevices.end(); ++iter) {

-                if ((iter->desc)->equals(desc)) {

-                    mMediaDevices.erase(iter);

-                    break;

-                }

-            }

-        }

-    }

-}

-

-std::vector<audio_devices_t> LastRemovableMediaDevices::getLastRemovableMediaDevices(

-        device_out_group_t group) const

-{

-    std::vector<audio_devices_t> ret;

-    for (auto iter = mMediaDevices.begin(); iter != mMediaDevices.end(); ++iter) {

-        if ((group == GROUP_NONE) || (group == getDeviceOutGroup((iter->desc)->type()))) {

-            ret.push_back((iter->desc)->type());

-        }

-    }

-    return ret;

-}

-

-device_out_group_t LastRemovableMediaDevices::getDeviceOutGroup(audio_devices_t device) const

-{

-    switch (device) {

-    case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:

-    case AUDIO_DEVICE_OUT_LINE:

-    case AUDIO_DEVICE_OUT_WIRED_HEADSET:

-    case AUDIO_DEVICE_OUT_USB_HEADSET:

-    case AUDIO_DEVICE_OUT_USB_ACCESSORY:

-    case AUDIO_DEVICE_OUT_USB_DEVICE:

-    case AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET:

-        return GROUP_WIRED;

-    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:

-    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:

-    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:

-        return GROUP_BT_A2DP;

-    default:

-        return GROUP_NONE;

-    }

-}

-

-} // namespace android
\ No newline at end of file
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "APM::AudioPolicyEngine/LastRemovableMediaDevices"
+//#define LOG_NDEBUG 0
+
+#include "LastRemovableMediaDevices.h"
+#include <log/log.h>
+
+namespace android {
+
+void LastRemovableMediaDevices::setRemovableMediaDevices(sp<DeviceDescriptor> desc,
+                                                         audio_policy_dev_state_t state)
+{
+    if (desc == nullptr) {
+        return;
+    } else {
+        if ((state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) &&
+                (getDeviceOutGroup(desc->type()) != GROUP_NONE)) {
+            setRemovableMediaDevices(desc, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE);
+            mMediaDevices.insert(mMediaDevices.begin(), {desc, getDeviceOutGroup(desc->type())});
+        } else if (state == AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
+            for (auto iter = mMediaDevices.begin(); iter != mMediaDevices.end(); ++iter) {
+                if ((iter->desc)->equals(desc)) {
+                    mMediaDevices.erase(iter);
+                    break;
+                }
+            }
+        }
+    }
+}
+
+std::vector<audio_devices_t> LastRemovableMediaDevices::getLastRemovableMediaDevices(
+        device_out_group_t group) const
+{
+    std::vector<audio_devices_t> ret;
+    for (auto iter = mMediaDevices.begin(); iter != mMediaDevices.end(); ++iter) {
+        if ((group == GROUP_NONE) || (group == getDeviceOutGroup((iter->desc)->type()))) {
+            ret.push_back((iter->desc)->type());
+        }
+    }
+    return ret;
+}
+
+device_out_group_t LastRemovableMediaDevices::getDeviceOutGroup(audio_devices_t device) const
+{
+    switch (device) {
+    case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+    case AUDIO_DEVICE_OUT_LINE:
+    case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+    case AUDIO_DEVICE_OUT_USB_HEADSET:
+    case AUDIO_DEVICE_OUT_USB_ACCESSORY:
+    case AUDIO_DEVICE_OUT_USB_DEVICE:
+    case AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET:
+        return GROUP_WIRED;
+    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
+    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
+    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
+        return GROUP_BT_A2DP;
+    default:
+        return GROUP_NONE;
+    }
+}
+
+} // namespace android