Skip to content

Commit

Permalink
Fix configuration for Android 13 A2DP Opus codec
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Oct 14, 2024
1 parent 4b7f1ce commit f93a6e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ unreleased
- renamed bluealsa-cli to bluealsactl (no backward compatibility)
- channel map and volume control for surround sound (5.1, 7.1) audio
- native A2DP volume control by default (dropped --a2dp-volume option)
- fix configuration for Android 13 A2DP Opus codec

bluez-alsa v4.3.1 (2024-08-30)
==============================
Expand Down
10 changes: 8 additions & 2 deletions src/a2dp-opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ static const struct a2dp_bit_mapping a2dp_opus_channels[] = {
};

static const struct a2dp_bit_mapping a2dp_opus_rates[] = {
{ OPUS_SAMPLING_FREQ_16000, { 16000 } },
{ OPUS_SAMPLING_FREQ_24000, { 24000 } },
{ OPUS_SAMPLING_FREQ_48000, { 48000 } },
{ 0 }
};
Expand Down Expand Up @@ -481,7 +483,9 @@ struct a2dp_sep a2dp_opus_source = {
.capabilities.opus = {
.info = A2DP_VENDOR_INFO_INIT(OPUS_VENDOR_ID, OPUS_CODEC_ID),
.sampling_freq =
OPUS_SAMPLING_FREQ_48000,
OPUS_SAMPLING_FREQ_48000 |
OPUS_SAMPLING_FREQ_24000 |
OPUS_SAMPLING_FREQ_16000,
.frame_duration =
OPUS_FRAME_DURATION_100 |
OPUS_FRAME_DURATION_200,
Expand Down Expand Up @@ -511,7 +515,9 @@ struct a2dp_sep a2dp_opus_sink = {
.capabilities.opus = {
.info = A2DP_VENDOR_INFO_INIT(OPUS_VENDOR_ID, OPUS_CODEC_ID),
.sampling_freq =
OPUS_SAMPLING_FREQ_48000,
OPUS_SAMPLING_FREQ_48000 |
OPUS_SAMPLING_FREQ_24000 |
OPUS_SAMPLING_FREQ_16000,
.frame_duration =
OPUS_FRAME_DURATION_100 |
OPUS_FRAME_DURATION_200,
Expand Down
3 changes: 3 additions & 0 deletions src/bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@ bool bluez_a2dp_set_configuration(

pthread_mutex_unlock(&bluez_mutex);

debug("A2DP requested codec: %s", a2dp_codecs_codec_id_to_string(remote_sep_cfg->codec_id));
hexdump("A2DP requested configuration blob", configuration, remote_sep_cfg->caps_size);

if ((rep = g_dbus_connection_send_message_with_reply_sync(config.dbus, msg,
G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, error)) == NULL ||
g_dbus_message_to_gerror(rep, error))
Expand Down
10 changes: 5 additions & 5 deletions src/shared/a2dp-codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ typedef struct a2dp_lhdc_v5 {
#define OPUS_VENDOR_ID BT_COMPID_GOOGLE
#define OPUS_CODEC_ID 0x0001

#define OPUS_SAMPLING_FREQ_48000 (1 << 0)
#define OPUS_SAMPLING_FREQ_48000 (1 << 2)
#define OPUS_SAMPLING_FREQ_24000 (1 << 1)
#define OPUS_SAMPLING_FREQ_16000 (1 << 0)

#define OPUS_FRAME_DURATION_100 (1 << 0)
#define OPUS_FRAME_DURATION_200 (1 << 1)
Expand All @@ -706,15 +708,13 @@ typedef struct a2dp_lhdc_v5 {
typedef struct a2dp_opus {
a2dp_vendor_info_t info;
#if __BYTE_ORDER == __BIG_ENDIAN
uint8_t rfa:2;
uint8_t sampling_freq:1;
uint8_t sampling_freq:3;
uint8_t frame_duration:2;
uint8_t channel_mode:3;
#else
uint8_t channel_mode:3;
uint8_t frame_duration:2;
uint8_t sampling_freq:1;
uint8_t rfa:2;
uint8_t sampling_freq:3;
#endif
} __attribute__ ((packed)) a2dp_opus_t;

Expand Down
5 changes: 3 additions & 2 deletions utils/a2dpconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,13 @@ static void dump_opus(const void *blob, size_t size) {
printf("Opus <hex:%s> {\n", bintohex(blob, size));
printf_vendor(&opus->info);
printf(""
" <reserved>:2\n"
" sample-rate:1 =%s\n"
" sample-rate:3 =%s%s%s\n"
" frame-duration:2 =%s%s\n"
" channel-mode:3 =%s%s%s\n"
"}\n",
opus->sampling_freq & OPUS_SAMPLING_FREQ_48000 ? " 48000" : "",
opus->sampling_freq & OPUS_SAMPLING_FREQ_24000 ? " 24000" : "",
opus->sampling_freq & OPUS_SAMPLING_FREQ_16000 ? " 16000" : "",
opus->frame_duration & OPUS_FRAME_DURATION_100 ? " 10ms" : "",
opus->frame_duration & OPUS_FRAME_DURATION_200 ? " 20ms" : "",
opus->channel_mode & OPUS_CHANNEL_MODE_STEREO ? " Stereo" : "",
Expand Down

0 comments on commit f93a6e8

Please sign in to comment.