interfaces: Import a2dp
* From https://gitlab.com/Linaro/96boards/e850-96/platform/vendor/samsung_slsi/-/tree/8263c898ccfbbee41e30b405b1f858c5a417ff33/hardware/ExynosA2DPOffload
Change-Id: Iedc293ce0cb786e912785630572c2e12fbe8f64a
Signed-off-by: Francescodario Cuzzocrea <bosconovic@gmail.com>
diff --git a/a2dp/1.0/Android.bp b/a2dp/1.0/Android.bp
new file mode 100644
index 0000000..f39b6fa
--- /dev/null
+++ b/a2dp/1.0/Android.bp
@@ -0,0 +1,15 @@
+cc_library_shared {
+ name: "android.hardware.bluetooth.a2dp@1.0-impl-exynos",
+ relative_install_path: "hw",
+ vendor: true,
+ srcs: [
+ "BluetoothAudioOffload.cpp",
+ ],
+ shared_libs: [
+ "libhidlbase",
+ "libutils",
+ "liblog",
+ "vendor.samsung_slsi.hardware.ExynosA2DPOffload@2.0",
+ "android.hardware.bluetooth.a2dp@1.0",
+ ],
+}
diff --git a/a2dp/1.0/BluetoothAudioOffload.cpp b/a2dp/1.0/BluetoothAudioOffload.cpp
new file mode 100644
index 0000000..d0bb942
--- /dev/null
+++ b/a2dp/1.0/BluetoothAudioOffload.cpp
@@ -0,0 +1,140 @@
+/*
+ * 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 "android.hardware.bluetooth.a2dp-exynos"
+
+#include <log/log.h>
+
+#include "BluetoothAudioOffload.h"
+
+#include <vendor/samsung_slsi/hardware/ExynosA2DPOffload/2.0/IExynosA2DPOffload.h>
+
+namespace android {
+namespace hardware {
+namespace bluetooth {
+namespace a2dp {
+namespace V1_0 {
+namespace implementation {
+
+using ::vendor::samsung_slsi::hardware::ExynosA2DPOffload::V2_0::IExynosA2DPOffload;
+
+static android::sp<IExynosA2DPOffload> exynos_a2dp = nullptr;
+
+IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* /* name */) {
+ return new BluetoothAudioOffload();
+}
+
+// Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
+Return<::android::hardware::bluetooth::a2dp::V1_0::Status> BluetoothAudioOffload::startSession(
+ const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf,
+ const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig) {
+
+ ::android::hardware::bluetooth::a2dp::V1_0::Status ret = Status::FAILURE;
+
+ ALOGI("%s: enter", __func__);
+
+ /**
+ * Initialize the audio platform if codecConfiguration is supported.
+ * Save the the IBluetoothAudioHost interface, so that it can be used
+ * later to send stream control commands to the HAL client, based on
+ * interaction with Audio framework.
+ */
+
+ ALOGI("%s: codec info from BT stack: %d, %d, %hhu, %hhu, %d, %hhu, %hhu, %hhu, %hhu", __func__,
+ codecConfig.codecType, codecConfig.sampleRate, codecConfig.bitsPerSample, codecConfig.channelMode,
+ codecConfig.encodedAudioBitrate, codecConfig.codecSpecific.sbcData.codecParameters,
+ codecConfig.codecSpecific.sbcData.minBitpool, codecConfig.codecSpecific.sbcData.maxBitpool,
+ codecConfig.codecSpecific.ldacData.bitrateIndex);
+
+ if (exynos_a2dp == nullptr) {
+ exynos_a2dp = IExynosA2DPOffload::getService();
+ if (exynos_a2dp == nullptr) {
+ ALOGE("%s: fail to get Exynos a2dp hidl impl", __func__);
+ return Status::FAILURE;
+ }
+ }
+
+ this->hostIF = hostIf;
+
+ ret = exynos_a2dp->session_start(hostIf, codecConfig);
+
+ ALOGI("%s: return from exynos a2dp hidl is %hhu", __func__, ret);
+
+ return ret;
+}
+
+Return<void> BluetoothAudioOffload::streamStarted(
+ ::android::hardware::bluetooth::a2dp::V1_0::Status status)
+{
+ ALOGI("%s: enter with Status: %hhu", __func__, status);
+
+ /**
+ * Streaming on control path has started,
+ * HAL server should start the streaming on data path.
+ */
+
+ if (exynos_a2dp == nullptr) {
+ ALOGE("%s: There is no Exynos a2dp hidl impl", __func__);
+ return Void();
+ }
+
+ exynos_a2dp->a2dp_start_ack(status);
+
+ return Void();
+}
+
+Return<void> BluetoothAudioOffload::streamSuspended(
+ ::android::hardware::bluetooth::a2dp::V1_0::Status status)
+{
+ int32_t ret = 0;
+
+ ALOGI("%s: enter with Status: %hhu", __func__, status);
+
+ /**
+ * Streaming on control path has suspend,
+ * HAL server should suspend the streaming on data path.
+ */
+
+ if (exynos_a2dp == nullptr) {
+ ALOGE("%s: There is no Exynos a2dp hidl impl", __func__);
+ return Void();
+ }
+
+ exynos_a2dp->a2dp_suspend_ack(status);
+
+ return Void();
+}
+
+Return<void> BluetoothAudioOffload::endSession() {
+
+ ALOGI("%s: enter", __func__);
+ /**
+ * Cleanup the audio platform as remote A2DP Sink device is no
+ * longer active
+ */
+
+ this->hostIF = nullptr;
+ exynos_a2dp = nullptr;
+
+ return Void();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace a2dp
+} // namespace bluetooth
+} // namespace hardware
+} // namespace android
diff --git a/a2dp/1.0/BluetoothAudioOffload.h b/a2dp/1.0/BluetoothAudioOffload.h
new file mode 100644
index 0000000..a5ede15
--- /dev/null
+++ b/a2dp/1.0/BluetoothAudioOffload.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2018 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_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H
+#define ANDROID_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H
+
+#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace bluetooth {
+namespace a2dp {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+typedef enum {
+ SUCCESS = 0,
+ FAILURE,
+ UNSUPPORTED_CODEC_CONFIGURATION,
+ PENDING,
+} Stat;
+
+struct BluetoothAudioOffload : public IBluetoothAudioOffload {
+ BluetoothAudioOffload() {}
+ // Methods from ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload follow.
+ Return<::android::hardware::bluetooth::a2dp::V1_0::Status> startSession(
+ const sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost>& hostIf,
+ const ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration& codecConfig) override;
+ Return<void> streamStarted(::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+ Return<void> streamSuspended(
+ ::android::hardware::bluetooth::a2dp::V1_0::Status status) override;
+ Return<void> endSession() override;
+
+ private:
+ sp<::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost> hostIF;
+
+};
+
+extern "C" IBluetoothAudioOffload* HIDL_FETCH_IBluetoothAudioOffload(const char* name);
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace a2dp
+} // namespace bluetooth
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_BLUETOOTH_A2DP_V1_0_BLUETOOTHAUDIOOFFLOAD_H