diff --git a/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl b/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl index 9a1557a488..cc3c6419de 100644 --- a/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl +++ b/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl @@ -40,4 +40,6 @@ interface IBluetoothAudioPort { void suspendStream(); void updateSourceMetadata(in android.hardware.audio.common.SourceMetadata sourceMetadata); void updateSinkMetadata(in android.hardware.audio.common.SinkMetadata sinkMetadata); + void setLatencyMode(in android.hardware.bluetooth.audio.LatencyMode latencyMode); + void setCodecType(in android.hardware.bluetooth.audio.CodecType codecType); } diff --git a/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/LatencyMode.aidl b/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/LatencyMode.aidl new file mode 100644 index 0000000000..5583679412 --- /dev/null +++ b/bluetooth/audio/aidl/aidl_api/android.hardware.bluetooth.audio/current/android/hardware/bluetooth/audio/LatencyMode.aidl @@ -0,0 +1,40 @@ +/* + * Copyright 2022 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.audio; +@Backing(type="int") @VintfStability +enum LatencyMode { + UNKNOWN = 0, + LOW_LATENCY = 1, + FREE = 2, +} diff --git a/bluetooth/audio/aidl/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl b/bluetooth/audio/aidl/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl index 827f57d91b..81c2ce29cd 100644 --- a/bluetooth/audio/aidl/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl +++ b/bluetooth/audio/aidl/android/hardware/bluetooth/audio/IBluetoothAudioPort.aidl @@ -18,6 +18,8 @@ package android.hardware.bluetooth.audio; import android.hardware.audio.common.SinkMetadata; import android.hardware.audio.common.SourceMetadata; +import android.hardware.bluetooth.audio.CodecType; +import android.hardware.bluetooth.audio.LatencyMode; import android.hardware.bluetooth.audio.PresentationPosition; /** @@ -78,4 +80,18 @@ interface IBluetoothAudioPort { * @param sinkMetadata as passed from Audio Framework */ void updateSinkMetadata(in SinkMetadata sinkMetadata); + + /** + * Called when latency mode is changed. + * + * @param latencyMode latency mode from audio + */ + void setLatencyMode(in LatencyMode latencyMode); + + /** + * Called when codec type is changed. + * + * @param codecType codec type from audio + */ + void setCodecType(in CodecType codecType); } diff --git a/bluetooth/audio/aidl/android/hardware/bluetooth/audio/LatencyMode.aidl b/bluetooth/audio/aidl/android/hardware/bluetooth/audio/LatencyMode.aidl new file mode 100644 index 0000000000..0c354f73d5 --- /dev/null +++ b/bluetooth/audio/aidl/android/hardware/bluetooth/audio/LatencyMode.aidl @@ -0,0 +1,25 @@ +/* + * Copyright 2022 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. + */ + +package android.hardware.bluetooth.audio; + +@VintfStability +@Backing(type="int") +enum LatencyMode { + UNKNOWN, + LOW_LATENCY, + FREE, +} diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index f626db83bd..96cd9ef6cb 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp @@ -508,6 +508,36 @@ void BluetoothAudioSession::UpdateSinkMetadata( } } +void BluetoothAudioSession::SetLatencyMode(LatencyMode latency_mode) { + std::lock_guard guard(mutex_); + if (!IsSessionReady()) { + LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) + << " has NO session"; + return; + } + + auto hal_retval = stack_iface_->setLatencyMode(latency_mode); + if (!hal_retval.isOk()) { + LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" + << toString(session_type_) << " failed"; + } +} + +void BluetoothAudioSession::SetCodecType(CodecType codec_type) { + std::lock_guard guard(mutex_); + if (!IsSessionReady()) { + LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_) + << " has NO session"; + return; + } + + auto hal_retval = stack_iface_->setCodecType(codec_type); + if (!hal_retval.isOk()) { + LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" + << toString(session_type_) << " failed"; + } +} + bool BluetoothAudioSession::IsAidlAvailable() { if (is_aidl_checked) return is_aidl_available; is_aidl_available = diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h index 73bc0f8b4e..5adc0e2f89 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -164,6 +165,8 @@ class BluetoothAudioSession { bool GetPresentationPosition(PresentationPosition& presentation_position); void UpdateSourceMetadata(const struct source_metadata& source_metadata); void UpdateSinkMetadata(const struct sink_metadata& sink_metadata); + void SetLatencyMode(LatencyMode latency_mode); + void SetCodecType(CodecType codec_type); // The control function writes stream to FMQ size_t OutWritePcmData(const void* buffer, size_t bytes);