This component implements the Advanced Audio Distribution Profile (A2DP) as specified by the Bluetooth SIG in the official specification.
This means that you can use your Fuchsia device to play audio to Bluetooth headphones or speakers, or you can play audio from a phone or computer to your Fuchsia device, or both at once.
This profile requires the SBC codec and will not start if it cannot decode/encode SBC audio. It will also use and prefer the AAC codec for higher quality audio if it is available on the system.
The bt-a2dp
component uses the following services at runtime:
fuchsia.media.AudioDeviceEnumerator
API to create the audio output device for source audio. This is generally available on most Fuchsia devices, provided by the audio_core
package.fuchsia.media.CodecFactory
API to encode and decode audio. This is usually provided by the codec_factory
package.codec_runner_sw_sbc
package.Without too many extra dependencies, adding the audio
, codec_factory
, and codec_runner_sw_sbc
packages to the available packages will provide all the required services. Adding the following to your Fuchsia set configuration should build them all and make them available:
--with //src/connectivity/bluetooth/profiles/bt-a2dp --with //src/media/audio --with //src/media/codec:codec_factory --with //src/media/codec:codec_runner_sw_sbc
The profile attempts to determine if encoding SBC audio will fail, and quits with a message on startup if it cannot.
There are two ways that the A2DP profile can be started on a fuchsia system: automatically started on boot, or through service discovery.
When started through service discovery, the profile will not be started until the A2DP Audio Mode is set through the fuchsia.bluetooth.a2dp.AudioMode
FIDL service. To start the profile through service discovery, include the service_config
target in your fuchsia build set, for example by using --with //src/connectivity/bluetooth/profiles/bt-a2dp:service_config
on an fx set
line, or by depending on it alongside the bt-a2dp component in your product config target.
When started automatically, the fuchsia.bluetooth.a2dp.AudioMode
FIDL service will not be available. To start the A2DP profile automatically on startup include the startup_config
target in your fuchsia build set by using --with //src/connectivity/bluetooth/profiles/bt-a2dp:startup_config
on an fx set
line, or by depending on it alongside the bt-a2dp component in your product config target.
The bt-a2dp.cmx
component implements component inspection. To view the current state of the profile, use fx iquery show bt-a2dp.cmx
.
root: connected: preferred_peer_direction = Sink [or Source] local_streams: [repeated for each stream that will be provided to a newly connected peer] stream_1: endpoint_state = StreamEndpoint {id: 5, [...]} discovered: [below repeated for each peer encountered since starting A2DP] peer_14: id = 2c1044bce7b57143 desciriptor = ProfileDescriptor { profile_id: AdvancedAudioDistribution, [...] } connection_count = 3 [below repeated for each connected peer] peer_0: id = 2c1044bce7b57143 local_streams: stream_1: endpoint_state = StreamEndpoint { id: 5, [...] } stream_2: endpoint_state = StreamEndpoint { endpoint_type: Sink, media_type: Audio, state: Idle, capabilities: [MediaTransport, MediaCodec { media_type: Audio, codec_type: MediaCodecType::AUDIO_SBC, codec_extra: [63, 255, 2, 250] }], remote_id: None, configuration: [] } [repeated for each stream endpoint, connected enpoints will have a media_stream] stream_4: endpoint_state = [...] media_stream: bytes_per_second_current = 23672 start_time = 11227039005541 total_bytes = 125695
To play audio from Fuchsia to a Bluetooth speaker or headphones through the bt-a2dp component, start the component, then connect and pair to headphones or a speaker.
bt-a2dp
with run -d fuchsia-pkg://fuchsia.com/bt-a2dp#meta/bt-a2dp.cmx
bt-cli
start-discovery
and wait a few seconds.list-peers
and look for your device. If you know the name of the device, you can filter the results by adding part of the name as an argument. Repeat until your device shows up.stop-discovery
when your device shows up to stop discovery.connect <BT address>
- you can type a partial address and use tab completionsignal_generator
will produce a tone for a couple seconds.To play audio on the Fuchsia device from a Bluetooth source (phone or computer), start the component, then connect from a phone or computer.
bt-a2dp
with run -d fuchsia-pkg://fuchsia.com/bt-a2dp#meta/bt-a2dp.cmx
bt-cli
discoverable
command within the CLI to make the fuchsia device discoverablebt-cli
running until you have finished connectingTroubleshooting:
vol
to turn up the volume on the Fuchsia device, or turning up the volume at the speaker.