| // Copyright 2026 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| use crate::types::{CodecCapabilitySetting, Configuration}; |
| use bt_pacs::PacRecord; |
| use std::collections::HashMap; |
| |
| /// Maps discovered capabilities and endpoints to supported configurations. |
| pub fn map_capabilities( |
| pac_records: &[PacRecord], |
| sink_ase_count: usize, |
| source_ase_count: usize, |
| ) -> HashMap<Configuration, Vec<CodecCapabilitySetting>> { |
| let mut mapping = HashMap::new(); |
| |
| // TODO: Implement actual mapping logic based on PAC records. |
| // This is a skeleton implementation that returns hardcoded values if resources |
| // are available. |
| |
| if pac_records.is_empty() { |
| return mapping; |
| } |
| |
| // Configuration 1: Mono Audio Sink (Client to Server) |
| // Requires 1 Sink ASE. |
| if sink_ase_count >= 1 { |
| mapping.insert( |
| Configuration::MonoAudioSink, |
| vec![CodecCapabilitySetting::Lc3_48_2, CodecCapabilitySetting::Lc3_16_2], |
| ); |
| } |
| |
| // Configuration 3: Conversational (Bidirectional) |
| // Requires 1 Sink ASE and 1 Source ASE. |
| if sink_ase_count >= 1 && source_ase_count >= 1 { |
| mapping.insert(Configuration::Conversational, vec![CodecCapabilitySetting::Lc3_16_2]); |
| } |
| |
| mapping |
| } |
| |
| #[cfg(test)] |
| mod tests { |
| use super::*; |
| |
| #[test] |
| fn test_map_capabilities_empty() { |
| let mapping = map_capabilities(&[], 0, 0); |
| assert!(mapping.is_empty()); |
| } |
| |
| #[test] |
| fn test_map_capabilities_with_resources() { |
| // Create a dummy PacRecord |
| // We need to mock it or use a real one if easy. |
| // For now, we just need a non-empty slice to trigger the skeleton logic. |
| let pac_records = vec![PacRecord { |
| codec_id: bt_common::core::CodecId::Assigned(bt_common::core::CodingFormat::Lc3), |
| codec_specific_capabilities: vec![], |
| metadata: vec![], |
| }]; |
| |
| let mapping = map_capabilities(&pac_records, 1, 1); |
| assert!(mapping.contains_key(&Configuration::MonoAudioSink)); |
| assert!(mapping.contains_key(&Configuration::Conversational)); |
| } |
| } |