diff options
Diffstat (limited to 'bluetooth/audio/utils')
13 files changed, 159 insertions, 124 deletions
diff --git a/bluetooth/audio/utils/OWNERS b/bluetooth/audio/utils/OWNERS index ed9284766b..17ea46424f 100644 --- a/bluetooth/audio/utils/OWNERS +++ b/bluetooth/audio/utils/OWNERS @@ -1,3 +1,4 @@ include platform/packages/modules/Bluetooth:/OWNERS -cheneyni@google.com
\ No newline at end of file +cheneyni@google.com +aliceypkuo@google.com
\ No newline at end of file diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp index 92cd0f5b14..516ebe8d7a 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp @@ -78,7 +78,7 @@ static const AptxCapabilities kDefaultOffloadAptxHdCapability = { .bitsPerSample = {24}, }; -static const Lc3Capabilities kDefaultOffloadLc3Capability = { +static const Lc3Capabilities kDefaultA2dpOffloadLc3Capability = { .samplingFrequencyHz = {44100, 48000}, .frameDurationUs = {7500, 10000}, .channelMode = {ChannelMode::MONO, ChannelMode::STEREO}, @@ -285,11 +285,11 @@ bool BluetoothAudioCodecs::IsOffloadLc3ConfigurationValid( const Lc3Configuration lc3_data = codec_specific.get<CodecConfiguration::CodecSpecific::lc3Config>(); - if (ContainedInVector(kDefaultOffloadLc3Capability.samplingFrequencyHz, + if (ContainedInVector(kDefaultA2dpOffloadLc3Capability.samplingFrequencyHz, lc3_data.samplingFrequencyHz) && - ContainedInVector(kDefaultOffloadLc3Capability.frameDurationUs, + ContainedInVector(kDefaultA2dpOffloadLc3Capability.frameDurationUs, lc3_data.frameDurationUs) && - ContainedInVector(kDefaultOffloadLc3Capability.channelMode, + ContainedInVector(kDefaultA2dpOffloadLc3Capability.channelMode, lc3_data.channelMode)) { return true; } @@ -352,10 +352,10 @@ BluetoothAudioCodecs::GetA2dpOffloadCodecCapabilities( case CodecType::LC3: codec_capability.capabilities .set<CodecCapabilities::Capabilities::lc3Capabilities>( - kDefaultOffloadLc3Capability); + kDefaultA2dpOffloadLc3Capability); break; case CodecType::UNKNOWN: - codec_capability = {}; + case CodecType::VENDOR: break; } } @@ -420,6 +420,7 @@ bool BluetoothAudioCodecs::IsOffloadCodecConfigurationValid( } break; case CodecType::UNKNOWN: + case CodecType::VENDOR: break; } return false; diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h index c542ce5be7..0259a7e770 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h @@ -45,11 +45,7 @@ class BluetoothAudioCodecs { const SessionType& session_type, const CodecConfiguration& codec_config); static bool IsOffloadLeAudioConfigurationValid( - const SessionType& session_type, const Lc3Configuration& codec_config); - - static bool IsOffloadLeAudioConfigurationValid( - const SessionType& session_type, - const LeAudioConfiguration& codec_config); + const SessionType& session_type, const LeAudioConfiguration&); static std::vector<LeAudioCodecCapabilitiesSetting> GetLeAudioOffloadCodecCapabilities(const SessionType& session_type); @@ -77,8 +73,6 @@ class BluetoothAudioCodecs { const CodecConfiguration::CodecSpecific& codec_specific); static bool IsOffloadLc3ConfigurationValid( const CodecConfiguration::CodecSpecific& codec_specific); - static bool IsOffloadLeAudioConfigurationValid( - const SessionType& session_type, const LeAudioCodecConfiguration&); }; } // namespace audio diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp index 95e473e5b9..f626db83bd 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.cpp @@ -35,22 +35,8 @@ static constexpr int kFmqReceiveTimeoutMs = static constexpr int kWritePollMs = 1; // polled non-blocking interval static constexpr int kReadPollMs = 1; // polled non-blocking interval -const CodecConfiguration BluetoothAudioSession::kInvalidCodecConfiguration = {}; -const LeAudioConfiguration kInvalidLeAudioConfiguration = {}; -AudioConfiguration BluetoothAudioSession::invalidSoftwareAudioConfiguration = - {}; -AudioConfiguration BluetoothAudioSession::invalidOffloadAudioConfiguration = {}; -AudioConfiguration BluetoothAudioSession::invalidLeOffloadAudioConfig = {}; - BluetoothAudioSession::BluetoothAudioSession(const SessionType& session_type) - : session_type_(session_type), stack_iface_(nullptr), data_mq_(nullptr) { - invalidSoftwareAudioConfiguration.set<AudioConfiguration::pcmConfig>( - kInvalidPcmConfiguration); - invalidOffloadAudioConfiguration.set<AudioConfiguration::a2dpConfig>( - kInvalidCodecConfiguration); - invalidLeOffloadAudioConfig.set<AudioConfiguration::leAudioConfig>( - kInvalidLeAudioConfiguration); -} + : session_type_(session_type), stack_iface_(nullptr), data_mq_(nullptr) {} /*** * @@ -72,13 +58,7 @@ void BluetoothAudioSession::OnSessionStarted( } else if (!UpdateDataPath(mq_desc)) { LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_) << " MqDescriptor Invalid"; - if (session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { - audio_config_ = std::make_unique<AudioConfiguration>( - invalidOffloadAudioConfiguration); - } else { - audio_config_ = std::make_unique<AudioConfiguration>( - invalidSoftwareAudioConfiguration); - } + audio_config_ = nullptr; } else { stack_iface_ = stack_iface; LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_) @@ -91,13 +71,7 @@ void BluetoothAudioSession::OnSessionEnded() { std::lock_guard<std::recursive_mutex> guard(mutex_); bool toggled = IsSessionReady(); LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_); - if (session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { - audio_config_ = - std::make_unique<AudioConfiguration>(invalidOffloadAudioConfiguration); - } else { - audio_config_ = - std::make_unique<AudioConfiguration>(invalidSoftwareAudioConfiguration); - } + audio_config_ = nullptr; stack_iface_ = nullptr; UpdateDataPath(nullptr); if (toggled) { @@ -111,22 +85,17 @@ void BluetoothAudioSession::OnSessionEnded() { * ***/ -const AudioConfiguration& BluetoothAudioSession::GetAudioConfig() { +const AudioConfiguration BluetoothAudioSession::GetAudioConfig() { std::lock_guard<std::recursive_mutex> guard(mutex_); if (!IsSessionReady()) { - if (session_type_ == SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { - return invalidOffloadAudioConfiguration; - } else { - return invalidSoftwareAudioConfiguration; - } switch (session_type_) { case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH: - return invalidOffloadAudioConfiguration; + return AudioConfiguration(CodecConfiguration{}); case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: - return invalidLeOffloadAudioConfig; + return AudioConfiguration(LeAudioConfiguration{}); default: - return invalidSoftwareAudioConfiguration; + return AudioConfiguration(PcmConfiguration{}); } } return *audio_config_; @@ -169,7 +138,7 @@ bool BluetoothAudioSession::IsSessionReady() { session_type_ == SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH || (data_mq_ != nullptr && data_mq_->isValid())); - return stack_iface_ != nullptr && is_mq_valid; + return stack_iface_ != nullptr && is_mq_valid && audio_config_ != nullptr; } /*** diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h index 85fd571f28..73bc0f8b4e 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSession.h @@ -144,7 +144,7 @@ class BluetoothAudioSession { * The control function is for the bluetooth_audio module to get the current * AudioConfiguration ***/ - const AudioConfiguration& GetAudioConfig(); + const AudioConfiguration GetAudioConfig(); /*** * The report function is used to report that the Bluetooth stack has notified @@ -173,14 +173,6 @@ class BluetoothAudioSession { // Return if IBluetoothAudioProviderFactory implementation existed static bool IsAidlAvailable(); - static constexpr PcmConfiguration kInvalidPcmConfiguration = {}; - // can't be constexpr because of non-literal type - static const CodecConfiguration kInvalidCodecConfiguration; - - static AudioConfiguration invalidSoftwareAudioConfiguration; - static AudioConfiguration invalidOffloadAudioConfiguration; - static AudioConfiguration invalidLeOffloadAudioConfig; - private: // using recursive_mutex to allow hwbinder to re-enter again. std::recursive_mutex mutex_; diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h index a3ed42894c..aff01e5a26 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioSessionControl.h @@ -79,11 +79,15 @@ class BluetoothAudioSessionControl { BluetoothAudioSessionInstance::GetSessionInstance(session_type); if (session_ptr != nullptr) { return session_ptr->GetAudioConfig(); - } else if (session_type == - SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH) { - return BluetoothAudioSession::invalidOffloadAudioConfiguration; - } else { - return BluetoothAudioSession::invalidSoftwareAudioConfiguration; + } + switch (session_type) { + case SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH: + return AudioConfiguration(CodecConfiguration{}); + case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH: + case SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH: + return AudioConfiguration(LeAudioConfiguration{}); + default: + return AudioConfiguration(PcmConfiguration{}); } } diff --git a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware.cpp b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware.cpp index 91e0238783..632a389d8c 100644 --- a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware.cpp +++ b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware.cpp @@ -93,16 +93,6 @@ std::unordered_map< std::unordered_map<uint16_t, std::shared_ptr<PortStatusCallbacks_2_2>>> legacy_callback_table; -const static std::unordered_map<SessionType_2_0, SessionType> - session_type_2_0_to_aidl_map{ - {SessionType_2_0::A2DP_SOFTWARE_ENCODING_DATAPATH, - SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH}, - {SessionType_2_0::A2DP_HARDWARE_OFFLOAD_DATAPATH, - SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH}, - {SessionType_2_0::HEARING_AID_SOFTWARE_ENCODING_DATAPATH, - SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH}, - }; - const static std::unordered_map<SessionType_2_1, SessionType> session_type_2_1_to_aidl_map{ {SessionType_2_1::A2DP_SOFTWARE_ENCODING_DATAPATH, @@ -121,18 +111,6 @@ const static std::unordered_map<SessionType_2_1, SessionType> SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH}, }; -const static std::unordered_map<int32_t, SampleRate_2_0> - sample_rate_to_hidl_2_0_map{ - {44100, SampleRate_2_0::RATE_44100}, - {48000, SampleRate_2_0::RATE_48000}, - {88200, SampleRate_2_0::RATE_88200}, - {96000, SampleRate_2_0::RATE_96000}, - {176400, SampleRate_2_0::RATE_176400}, - {192000, SampleRate_2_0::RATE_192000}, - {16000, SampleRate_2_0::RATE_16000}, - {24000, SampleRate_2_0::RATE_24000}, - }; - const static std::unordered_map<int32_t, SampleRate_2_1> sample_rate_to_hidl_2_1_map{ {44100, SampleRate_2_1::RATE_44100}, @@ -211,20 +189,6 @@ const static std::unordered_map<LdacQualityIndex, LdacQualityIndex_2_0> {LdacQualityIndex::ABR, LdacQualityIndex_2_0::QUALITY_ABR}, }; -const static std::unordered_map<LeAudioMode, LeAudioMode_2_2> - leaudio_mode_to_hidl_map{ - {LeAudioMode::UNKNOWN, LeAudioMode_2_2::UNKNOWN}, - {LeAudioMode::UNICAST, LeAudioMode_2_2::UNICAST}, - {LeAudioMode::BROADCAST, LeAudioMode_2_2::BROADCAST}, - }; - -inline SessionType from_session_type_2_0( - const SessionType_2_0& session_type_hidl) { - auto it = session_type_2_0_to_aidl_map.find(session_type_hidl); - if (it != session_type_2_0_to_aidl_map.end()) return it->second; - return SessionType::UNKNOWN; -} - inline SessionType from_session_type_2_1( const SessionType_2_1& session_type_hidl) { auto it = session_type_2_1_to_aidl_map.find(session_type_hidl); @@ -232,6 +196,11 @@ inline SessionType from_session_type_2_1( return SessionType::UNKNOWN; } +inline SessionType from_session_type_2_0( + const SessionType_2_0& session_type_hidl) { + return from_session_type_2_1(static_cast<SessionType_2_1>(session_type_hidl)); +} + inline HidlStatus to_hidl_status(const BluetoothAudioStatus& status) { switch (status) { case BluetoothAudioStatus::SUCCESS: @@ -243,18 +212,19 @@ inline HidlStatus to_hidl_status(const BluetoothAudioStatus& status) { } } -inline SampleRate_2_0 to_hidl_sample_rate_2_0(const int32_t sample_rate_hz) { - auto it = sample_rate_to_hidl_2_0_map.find(sample_rate_hz); - if (it != sample_rate_to_hidl_2_0_map.end()) return it->second; - return SampleRate_2_0::RATE_UNKNOWN; -} - inline SampleRate_2_1 to_hidl_sample_rate_2_1(const int32_t sample_rate_hz) { auto it = sample_rate_to_hidl_2_1_map.find(sample_rate_hz); if (it != sample_rate_to_hidl_2_1_map.end()) return it->second; return SampleRate_2_1::RATE_UNKNOWN; } +inline SampleRate_2_0 to_hidl_sample_rate_2_0(const int32_t sample_rate_hz) { + auto it = sample_rate_to_hidl_2_1_map.find(sample_rate_hz); + if (it != sample_rate_to_hidl_2_1_map.end()) + return static_cast<SampleRate_2_0>(it->second); + return SampleRate_2_0::RATE_UNKNOWN; +} + inline BitsPerSample_2_0 to_hidl_bits_per_sample(const int8_t bit_per_sample) { switch (bit_per_sample) { case 16: @@ -449,18 +419,49 @@ inline Lc3Config_2_1 to_hidl_lc3_config_2_1( inline Lc3CodecConfig_2_1 to_hidl_leaudio_config_2_1( const LeAudioConfiguration& leaudio_config) { - auto& unicast_config = - leaudio_config.modeConfig - .get<LeAudioConfiguration::LeAudioModeConfig::unicastConfig>(); - - auto& le_codec_config = unicast_config.leAudioCodecConfig - .get<LeAudioCodecConfiguration::lc3Config>(); + Lc3CodecConfig_2_1 hidl_lc3_codec_config = { + .audioChannelAllocation = 0, + }; + if (leaudio_config.modeConfig.getTag() == + LeAudioConfiguration::LeAudioModeConfig::unicastConfig) { + auto& unicast_config = + leaudio_config.modeConfig + .get<LeAudioConfiguration::LeAudioModeConfig::unicastConfig>(); + if (unicast_config.leAudioCodecConfig.getTag() == + LeAudioCodecConfiguration::lc3Config) { + LOG(FATAL) << __func__ << ": unexpected codec type(vendor?)"; + } + auto& le_codec_config = unicast_config.leAudioCodecConfig + .get<LeAudioCodecConfiguration::lc3Config>(); - Lc3CodecConfig_2_1 hidl_lc3_codec_config; - hidl_lc3_codec_config.lc3Config = to_hidl_lc3_config_2_1(le_codec_config); + hidl_lc3_codec_config.lc3Config = to_hidl_lc3_config_2_1(le_codec_config); - hidl_lc3_codec_config.audioChannelAllocation = - unicast_config.streamMap.size(); + for (const auto& map : unicast_config.streamMap) { + hidl_lc3_codec_config.audioChannelAllocation |= + map.audioChannelAllocation; + } + } else { + // NOTE: Broadcast is not officially supported in HIDL + auto& bcast_config = + leaudio_config.modeConfig + .get<LeAudioConfiguration::LeAudioModeConfig::broadcastConfig>(); + if (bcast_config.streamMap.empty()) { + return hidl_lc3_codec_config; + } + if (bcast_config.streamMap[0].leAudioCodecConfig.getTag() != + LeAudioCodecConfiguration::lc3Config) { + LOG(FATAL) << __func__ << ": unexpected codec type(vendor?)"; + } + auto& le_codec_config = + bcast_config.streamMap[0] + .leAudioCodecConfig.get<LeAudioCodecConfiguration::lc3Config>(); + hidl_lc3_codec_config.lc3Config = to_hidl_lc3_config_2_1(le_codec_config); + + for (const auto& map : bcast_config.streamMap) { + hidl_lc3_codec_config.audioChannelAllocation |= + map.audioChannelAllocation; + } + } return hidl_lc3_codec_config; } @@ -468,13 +469,10 @@ inline Lc3CodecConfig_2_1 to_hidl_leaudio_config_2_1( inline LeAudioConfig_2_2 to_hidl_leaudio_config_2_2( const LeAudioConfiguration& leaudio_config) { LeAudioConfig_2_2 hidl_leaudio_config; - if (leaudio_mode_to_hidl_map.find(leaudio_config.mode) != - leaudio_mode_to_hidl_map.end()) { - hidl_leaudio_config.mode = leaudio_mode_to_hidl_map.at(leaudio_config.mode); - } if (leaudio_config.modeConfig.getTag() == LeAudioConfiguration::LeAudioModeConfig::unicastConfig) { + hidl_leaudio_config.mode = LeAudioMode_2_2::UNICAST; auto& unicast_config = leaudio_config.modeConfig .get<LeAudioConfiguration::LeAudioModeConfig::unicastConfig>(); @@ -497,6 +495,7 @@ inline LeAudioConfig_2_2 to_hidl_leaudio_config_2_2( } } else if (leaudio_config.modeConfig.getTag() == LeAudioConfiguration::LeAudioModeConfig::broadcastConfig) { + hidl_leaudio_config.mode = LeAudioMode_2_2::BROADCAST; auto bcast_config = leaudio_config.modeConfig .get<LeAudioConfiguration::LeAudioModeConfig::broadcastConfig>(); @@ -641,6 +640,12 @@ size_t HidlToAidlMiddleware_2_0::OutWritePcmData( from_session_type_2_0(session_type), buffer, bytes); } +size_t HidlToAidlMiddleware_2_0::InReadPcmData( + const SessionType_2_0& session_type, void* buffer, size_t bytes) { + return BluetoothAudioSessionControl::InReadPcmData( + from_session_type_2_0(session_type), buffer, bytes); +} + bool HidlToAidlMiddleware_2_0::IsAidlAvailable() { return BluetoothAudioSession::IsAidlAvailable(); } @@ -761,6 +766,13 @@ void HidlToAidlMiddleware_2_2::StopStream(const SessionType_2_1& session_type) { from_session_type_2_1(session_type)); } +void HidlToAidlMiddleware_2_2::UpdateTracksMetadata( + const SessionType_2_1& session_type, + const struct source_metadata* source_metadata) { + return BluetoothAudioSessionControl::UpdateSourceMetadata( + from_session_type_2_1(session_type), *source_metadata); +} + void HidlToAidlMiddleware_2_2::UpdateSinkMetadata( const SessionType_2_1& session_type, const struct sink_metadata* sink_metadata) { diff --git a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_0.h b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_0.h index d10ee3759a..b124d8ff0b 100644 --- a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_0.h +++ b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_0.h @@ -64,6 +64,9 @@ class HidlToAidlMiddleware_2_0 { static size_t OutWritePcmData(const SessionType_2_0& session_type, const void* buffer, size_t bytes); + + static size_t InReadPcmData(const SessionType_2_0& session_type, void* buffer, + size_t bytes); }; } // namespace audio diff --git a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_2.h b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_2.h index 149e4042d1..f6c3e5c731 100644 --- a/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_2.h +++ b/bluetooth/audio/utils/aidl_session/HidlToAidlMiddleware_2_2.h @@ -54,6 +54,10 @@ class HidlToAidlMiddleware_2_2 { static void StopStream(const SessionType_2_1& session_type); + static void UpdateTracksMetadata( + const SessionType_2_1& session_type, + const struct source_metadata* source_metadata); + static void UpdateSinkMetadata(const SessionType_2_1& session_type, const struct sink_metadata* sink_metadata); }; diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession.cpp index 6d5608b0a4..283952e52c 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession.cpp @@ -437,6 +437,9 @@ size_t BluetoothAudioSession::OutWritePcmData(const void* buffer, // The control function reads stream from FMQ size_t BluetoothAudioSession::InReadPcmData(void* buffer, size_t bytes) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_0::InReadPcmData(session_type_, buffer, + bytes); if (buffer == nullptr || !bytes) return 0; size_t totalRead = 0; int ms_timeout = kFmqReceiveTimeoutMs; diff --git a/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_2.h b/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_2.h index 368939e6f8..c270ef0d6b 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_2.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSessionControl_2_2.h @@ -152,7 +152,7 @@ class BluetoothAudioSessionControl_2_2 { std::shared_ptr<BluetoothAudioSession_2_2> session_ptr = BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type); if (session_ptr != nullptr) { - session_ptr->GetAudioSession()->UpdateTracksMetadata(source_metadata); + session_ptr->UpdateTracksMetadata(source_metadata); } } diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp index 4613ddc05a..ceb0662b0a 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.cpp @@ -31,9 +31,13 @@ namespace audio { using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_0; using ::aidl::android::hardware::bluetooth::audio::HidlToAidlMiddleware_2_2; +using ::android::hardware::audio::common::V5_0::AudioContentType; using ::android::hardware::audio::common::V5_0::AudioSource; +using ::android::hardware::audio::common::V5_0::AudioUsage; +using ::android::hardware::audio::common::V5_0::PlaybackTrackMetadata; using ::android::hardware::audio::common::V5_0::RecordTrackMetadata; using ::android::hardware::audio::common::V5_0::SinkMetadata; +using ::android::hardware::audio::common::V5_0::SourceMetadata; using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample; using ::android::hardware::bluetooth::audio::V2_0::ChannelMode; using ::android::hardware::bluetooth::audio::V2_2::LeAudioConfiguration; @@ -128,6 +132,53 @@ BluetoothAudioSession_2_2::GetAudioSession_2_1() { return audio_session_2_1; } +void BluetoothAudioSession_2_2::UpdateTracksMetadata( + const struct source_metadata* source_metadata) { + if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) + return HidlToAidlMiddleware_2_2::UpdateTracksMetadata(raw_session_type_, + source_metadata); + std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_); + if (!IsSessionReady()) { + LOG(DEBUG) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << " has NO session"; + return; + } + + ssize_t track_count = source_metadata->track_count; + LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << ", " << track_count << " track(s)"; + + if (session_type_2_1_ == SessionType_2_1::UNKNOWN) { + audio_session->UpdateTracksMetadata(source_metadata); + return; + } + + struct playback_track_metadata* track = source_metadata->tracks; + SourceMetadata sourceMetadata; + PlaybackTrackMetadata* halMetadata; + + sourceMetadata.tracks.resize(track_count); + halMetadata = sourceMetadata.tracks.data(); + while (track_count && track) { + halMetadata->usage = static_cast<AudioUsage>(track->usage); + halMetadata->contentType = + static_cast<AudioContentType>(track->content_type); + halMetadata->gain = track->gain; + LOG(VERBOSE) << __func__ << " - SessionType=" << toString(session_type_2_1_) + << ", usage=" << toString(halMetadata->usage) + << ", content=" << toString(halMetadata->contentType) + << ", gain=" << halMetadata->gain; + --track_count; + ++track; + ++halMetadata; + } + auto hal_retval = audio_session->stack_iface_->updateMetadata(sourceMetadata); + if (!hal_retval.isOk()) { + LOG(WARNING) << __func__ << " - IBluetoothAudioPort SessionType=" + << toString(session_type_2_1_) << " failed"; + } +} + void BluetoothAudioSession_2_2::UpdateSinkMetadata( const struct sink_metadata* sink_metadata) { if (HidlToAidlMiddleware_2_0::IsAidlAvailable()) diff --git a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h index b6f96ab25c..e04ad80ffa 100644 --- a/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h +++ b/bluetooth/audio/utils/session/BluetoothAudioSession_2_2.h @@ -152,6 +152,7 @@ class BluetoothAudioSession_2_2 { const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration GetAudioConfig(); + void UpdateTracksMetadata(const struct source_metadata* source_metadata); void UpdateSinkMetadata(const struct sink_metadata* sink_metadata); static constexpr ::android::hardware::bluetooth::audio::V2_2:: |