Skip to content

Instantly share code, notes, and snippets.

@PatrickLang
Last active February 4, 2022 04:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickLang/71ef34da68c174380c8927940850db6d to your computer and use it in GitHub Desktop.
Save PatrickLang/71ef34da68c174380c8927940850db6d to your computer and use it in GitHub Desktop.
Tracing Bluetooth Audio in Windows 10

Collecting the trace

Windows has the tools needed to collect traces for the bluetooth stack built-in, they just need to be configured. There are step by step instructions and scripts at Microsoft/busiotools, but I have copied some of the relevant details below.

To start the trace, create a temporary directory, then run this from an admin PowerShell prompt:

wget https://github.com/Microsoft/busiotools/raw/master/bluetooth/tracing/BluetoothStack.wprp -outfile .\BluetoothStack.wprp
wpr.exe -start BluetoothStack.wprp!BluetoothStack -filemode

Now connect the bluetooth device - this is important so you can capture the capabilities before you start playing audio. Go ahead and play something, then pause it.

To stop the trace:

wpr.exe -stop BthTracing.etl

Analyzing the trace

I have not found full documentation on how to decode all of the events collected, but the key ones around bluetooth connection and codec negotiation seem to work.

Install Windows Performance Analyzer

This is part of the Windows SDK. Be sure to get the SDK version matching what you have installed. Press Start, then search for "About your PC". If the edition says "Insider Preview" - you're on an insider build. Otherwise, you're on a normal Windows 10 build.

Double click the ISO to mount it, then run WinSDKSetup. You don't need to install everything - just "Windows Performance Toolkit"

Using Windows Performance Analyzer

Now, Start > and search for "Windows Performance Analyzer" and open it.

Go to File > Open, and pick the BthTracing.etl file saved earlier.

Now, double click on Generic Events in the left pane. It will open up a table of events. As you scroll down, you will eventually see some interesting ones named Microsoft.Windows.Bluetooth.Avctp and Microsoft.Windows.Bluetooth.BthA2DP. Those ones will have a little chevron you can click to expand and see all the events in that category. The BthA2DP ones will give you more details on what audio codecs were used.

If you click on a specific row - the column labels at the top will change.

A2dpSetAacBitrate

Right click on a row, and choose "Copy Selection". It will copy all the data, including column headers, comma delimited. If you copy multiple events at once, the headers may be wrong.

Line #, Provider Name, Task Name, Opcode Name, Id, Process, Event Name, Cpu, ThreadId, PartA_PrivTags (Field 1), AacBitrate (Field 2), AacMtu (Field 3), AacL2capSize (Field 4), AacSampingFrequency (Field 5), AacNumChannels (Field 6), Field 7, Field 8, Field 9, Field 10, Field 11, Field 12, Field 13, Field 14, Field 15, Field 16, Field 17, Field 18, Field 19, Field 20, Field 21, Field 22, Field 23, Field 24, Field 25, Field 26, Field 27, Field 28, Field 29, Field 30, Field 31, Field 32, Field 33, Field 34, Field 35, Field 36, Field 37, Field 38, Field 39, Field 40, Field 41, Field 42, Field 43, Field 44, Field 45, Field 46, Field 47, Field 48, Field 49, Field 50, Field 51, Field 52, Field 53, Field 54, Field 55, Field 56, Field 57, Field 58, Field 59, Field 60, Field 61, Field 62, Field 63, Field 64, Field 65, Field 66, Field 67, Field 68, Field 69, Count, Time (s)
74, , A2dpSetAacBitrate, win:Info, 0, Unknown (0), A2dpSetAacBitrate, 0, 0, 50333696, 202500, 672, 672, 48000, 2, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 1, 11.227281700

That one showed a Bluetooth device negotiated to 2 channels, 48khz, and a AAC bitrate of 202500.

Here's another from a device that is not AAC capable:

Line #, Provider Name, Task Name, Opcode Name, Id, Process, Event Name, Cpu, ThreadId, PartA_PrivTags (Field 1), A2dpSbcBitRate (Field 2), A2dpSbcMediaFrameSize (Field 3), A2dpSbcBitPool (Field 4), A2dpSbcFramesPerPayload (Field 5), A2dpSbcFrameSize (Field 6), A2dpSbcBlocks (Field 7), A2dpSbcChannels (Field 8), A2dpSbcChannelMode (Field 9), BTDeviceAddress (Field 10), Field 11, Field 12, Field 13, Field 14, Field 15, Field 16, Field 17, Field 18, Field 19, Field 20, Field 21, Field 22, Field 23, Field 24, Field 25, Field 26, Field 27, Field 28, Field 29, Field 30, Field 31, Field 32, Field 33, Field 34, Field 35, Field 36, Field 37, Field 38, Field 39, Field 40, Field 41, Field 42, Field 43, Field 44, Field 45, Field 46, Field 47, Field 48, Field 49, Field 50, Field 51, Field 52, Field 53, Field 54, Field 55, Field 56, Field 57, Field 58, Field 59, Field 60, Field 61, Field 62, Field 63, Field 64, Field 65, Field 66, Field 67, Field 68, Field 69, Count, Time (s)
83, , A2dpSetSbcBitrate, win:Info, 0, Unknown (0), A2dpSetSbcBitrate, 0, 0, 50333696, 338400, 846, 53, 7, 119, 16, 2, 3, 277459084854864, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 1, 5.743885900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment