Audio Source — Headset Side
A2DP Source + AVRCP Target. The display streams audio out to a headset, tells that headset what is playing, and receives its button presses.
The display is the Source because audio flows out. The headset is the A2DP Sink. This is the mirror image of Audio Sink, and the two together are what MediaRelay bridges.
Table of Contents
Where the Audio Actually Comes From
Capabilities
- Stream an A2DP audio stream out to a headset
- Act as AVRCP Target: publish now-playing metadata and playback status the headset can display
- Receive headset transport button presses as notifications
- AVRCP absolute volume where the headset supports it

This headset reports no AVRCP absolute volume, which is why the panel shows no volume controls — see Volume.
Client
using Ahsoka.Core;
using Ahsoka.Services.Bluetooth.Profiles.AudioSource;
using Ahsoka.Services.Bluetooth.Proto;
var audioSourceClient = new AudioSourceServiceClient();
Dispatcher.Default.RegisterCallback<AhsokaClientBase<AudioSourceProfileMessageTypes.Ids>.AhsokaNotificationArgs>(
OnAudioSourceNotification,
audioSourceClient);
audioSourceClient.Start();
The adapter must declare AudioSourceProfileService in SupportedProfileServiceTypes.
| Method | Purpose |
|---|---|
RequestConnectProfile(BluetoothDevicePairedInfo) |
Connect the profile (inherited) |
RequestDisconnectProfile(BluetoothDevicePairedInfo) |
Disconnect (inherited) |
SetNowPlaying(int adapterIndex, NowPlayingInfo info) |
Publish what is playing |
SetHeadsetVolume(int adapterIndex, uint volume) |
Set absolute volume on the headset |
| Notification | Payload |
|---|---|
ProfileConnectionStateChanged |
ProfileConnectionInfo |
AvrcpMediaButtonPressed |
MediaButtonInfo |
AvrcpVolumeChanged |
VolumeInfo |
Connecting
Filter for devices that can actually sink A2DP, and use Class of Device to keep phones out of your headset list:
bool isHeadset =
device.SupportedProfiles.HasFlag(BluetoothProfilesFlags.A2dpSink) &&
IsDeviceClassOrUnknown(device, BluetoothMajorDeviceClass.DeviceClassAudioVideo);
if (isHeadset)
audioSourceClient.RequestConnectProfile(device);
Headsets are especially likely to initiate the connection themselves — many connect to the last known
device the moment they power on. Expect unsolicited StateConnected, on whichever adapter the headset
chose if it is paired to more than one.
Publishing Now Playing
As AVRCP Target, the display answers the headset's metadata queries. You supply the answer:
audioSourceClient.SetNowPlaying(adapterIndex, new NowPlayingInfo
{
AdapterIndex = adapterIndex,
Track = new SongInfo
{
Title = "Title",
Artist = "Artist",
Album = "Album",
Genre = "Genre"
},
PlaybackStatus = "playing",
Position = 42000
});
| Property | Meaning |
|---|---|
AdapterIndex |
Which headset's adapter |
Track |
SongInfo — Title, Artist, Album, Genre, TrackNumber, NumberOfTracks, Duration (durations in milliseconds) |
PlaybackStatus |
"playing", "paused", or "stopped" |
Position |
Position in milliseconds |
Position is milliseconds. Do not pre-convert to any other unit.
Tip
Do not fabricate this data. If a phone is connected on the AudioSink side, its real PlayerInfo is the
correct source — forward it rather than inventing values.
MediaRelay does exactly that forwarding.
Headset Buttons
A headset acting as AVRCP Controller sends transport commands to the display:
if (e.TransportId == AudioSourceProfileMessageTypes.Ids.AvrcpMediaButtonPressed
&& e.NotificationObject is MediaButtonInfo buttonInfo
&& buttonInfo.AdapterIndex == myAdapterIndex)
{
switch (buttonInfo.Button)
{
case MediaControl.Play:
case MediaControl.Pause:
case MediaControl.Next:
case MediaControl.Previous:
break;
}
}
MediaButtonInfo carries just AdapterIndex and Button.
These notifications are reports of a press, not commands the display has to obey. What a press should do depends on your application: pause your own player, or relay it to a connected phone. The relay case is common enough to be packaged — see MediaRelay.
VolumeUp and VolumeDown can arrive here too, from headsets that lack absolute volume. They are
report-only — see Volume for why they are not acted on.
Important
Headset button presses reach the display through a Linux uinput/evdev input device, not through the
registered MPRIS player. This is BlueZ's design: when bluetoothd is AVRCP Target, incoming passthrough
commands are injected into a /dev/input/event* node named <device name> (AVRCP). The extension reads
that node for you and turns key events into AvrcpMediaButtonPressed, so from your side it is just a
notification. It matters when buttons do not arrive — see
Troubleshooting.
Volume
AvrcpVolumeChanged reports the headset's volume and, critically, whether absolute volume was negotiated
at all:
if (e.TransportId == AudioSourceProfileMessageTypes.Ids.AvrcpVolumeChanged
&& e.NotificationObject is VolumeInfo volumeInfo
&& volumeInfo.AdapterIndex == myAdapterIndex)
{
if (volumeInfo.AbsoluteVolumeSupported)
ShowVolumeControls(volumeInfo.Volume);
else
HideVolumeControls();
}
To set it:
audioSourceClient.SetHeadsetVolume(adapterIndex, 96);
0–127, the AVRCP scale.
Show volume controls only when AbsoluteVolumeSupported is true. Plenty of real headsets do not support
it — a headset with a physical volume knob commonly adjusts its own output locally and puts nothing on the
Bluetooth wire, so there is neither a level to read nor a level to write.
MediaControl.VolumeUp and VolumeDown arriving as button presses are report-only. They are not
relayed to a connected phone, and acting on them would need platform-level attenuation this extension does
not provide.
Where the Audio Actually Comes From
This extension manages the A2DP transport. Beyond a connected phone's audio, which
MediaRelay carries, it does not move audio samples and it
does not decide where they go.
Getting a connected phone's stream through to a connected headset is
MediaRelay's doing. Everything else about audio routing
on the platform — output selection, mixing, platform volume — belongs to the Audio extension
(Ahsoka.Extensions.AudioManager and its Ahsoka.Audio.service).
That extension also starts the platform's audio server, which A2DP depends on, so it is required: add
it in the OpenPV Developer Toolkit and reference the Ahsoka.Extensions.AudioManager package in your
application. Both are needed — without the package reference the application fails to publish, and without
the extension nothing starts the audio server, so connecting this profile may fail outright.
If metadata and button presses work but no sound reaches the headset, check that a relay route exists —
MediaRelay.GetHeadsetRoute. Audio only follows a route. "Let the user choose the output device" is still
not an API call here.
Gotchas
Sink and Source are named for the display's role. Source sends audio out to a headset. If you want to control a phone, use Audio Sink.
Check AdapterIndex on every notification. The profile service spans all adapters.
A headset paired to two adapters may connect to either one, and both work. Do not assume it will pick the adapter you last used.
Buttons that never arrive usually mean a missing evdev node, not a code problem. See Troubleshooting.
Not every headset sends every button. Jog-dial headsets often send Play and Pause as distinct
codes and no stop, rewind, or fast-forward at all. Handle the subset you receive and do not require the
full set.
Desktop Stack Behavior
The desktop AudioSource stub implements the full volume handshake, so AvrcpVolumeChanged,
AbsoluteVolumeSupported, and SetHeadsetVolume can all be exercised without hardware. Use it to test
your volume handling — a real headset may not support absolute volume, in which case the wire path cannot
be exercised on hardware at all.
SetNowPlaying and the button notification path are also exercisable on the stub, which means
MediaRelay can be developed and tested end to end on Windows.