tree: 5558bb574d6a8f9dd43cd80a49c3e1b9659c64da [path history] [tgz]
  1. meta/
  2. src/
  3. BUILD.gn
  4. README.md
  5. service.config
  6. startup.config
src/connectivity/bluetooth/profiles/bt-a2dp/README.md

Bluetooth Profile: A2DP

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.

Build Configuration

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.
  • The codec factory must be able to encode SBC audio. This is currently provided in the 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.

Profile Startup

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.

Inspection

The bt-a2dp.cmx component implements component inspection. To view the current state of the profile, use fx iquery show bt-a2dp.cmx.

Hierarchy

 root:
      connected:
        [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

Setting up Bluetooth Audio

A2DP Source

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.

  1. Start bt-a2dp with run -d fuchsia-pkg://fuchsia.com/bt-a2dp#meta/bt-a2dp.cmx
  2. If you have never paired with this device:
    1. Run bt-pairing-tool in a new fuchsia shell.
    2. Place the headphones/speaker in pairing mode (usually holding the power when turning it on will do this)
    3. If a prompt appears on the pairing tool in the next step, confirm it.
  3. Connect to the headphones/speaker:
    1. Run bt-cli
    2. Run start-discovery and wait a few seconds.
    3. Run 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.
    4. Run stop-discovery when your device shows up to stop discovery.
    5. Wait 10 seconds. (this is a (known bug)[http://fxbug.dev/2758] and will not be necessary soon)
    6. Run connect <BT address> - you can type a partial address and use tab completion
  4. You should be connected to the headphones/speaker - you may hear a tone on them to confirm.
  5. You should be able to play some audio on Fuchsia and hear it from your Bluetooth device:
    • signal_generator will produce a tone for a couple seconds.
    • Any other method of producing audio should also work.
  6. Dance 💃

A2DP Sink

To play audio on the Fuchsia device from a Bluetooth source (phone or computer), start the component, then connect from a phone or computer.

  1. Start bt-a2dp with run -d fuchsia-pkg://fuchsia.com/bt-a2dp#meta/bt-a2dp.cmx
  2. (if you have never paired this device) Make the fuchsia device discoverable:
    • Run bt-cli
    • Use the discoverable command within the CLI to make the fuchsia device discoverable
    • Keep the bt-cli running until you have finished connecting
  3. Connect and pair to the Fuchsia device from your source
  4. Done! You should be able to play audio on the Fuchsia device
  5. Dance 💃

Troubleshooting:

  • Volume low? Try turning up the volume on your source, using vol to turn up the volume on the Fuchsia device, or turning up the volume at the speaker.