Skip to content

Commit

Permalink
Cleanup aptX sections and add new aptX codec IDs
Browse files Browse the repository at this point in the history
Also, this commit removes configuration warning stating that [open]aptx
library is not able to perform encoding, because now it supports FFmpeg
as an encoding back-end (with some limitations, though).
  • Loading branch information
arkq committed Aug 18, 2020
1 parent 80db29f commit b60a834
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 113 deletions.
8 changes: 0 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,3 @@ AM_COND_IF([ALSA_1_1_2], [
AC_MSG_WARN([Either compile alsa-lib without this feature or export])
AC_MSG_WARN([LIBASOUND_THREAD_SAFE=0 while using bluealsa PCM.])
])

# warn user that aptX support is not an open-source feature
AM_COND_IF([ENABLE_APTX], [
AC_MSG_WARN([ *** aptX encoder support ***])
AC_MSG_WARN([You have enabled support for aptX encoding. Note, that])
AC_MSG_WARN([by default bluez-alsa will use openaptx library, which])
AC_MSG_WARN([does NOT perform any encoding/decoding.])
])
12 changes: 6 additions & 6 deletions src/a2dp-audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1734,12 +1734,12 @@ static void *a2dp_source_aptx_hd(struct ba_transport *t) {
break;
}

bt.tail[0] = ((uint8_t *)code)[2];
bt.tail[1] = ((uint8_t *)code)[1];
bt.tail[2] = ((uint8_t *)code)[0];
bt.tail[3] = ((uint8_t *)code)[6];
bt.tail[4] = ((uint8_t *)code)[5];
bt.tail[5] = ((uint8_t *)code)[4];
bt.tail[0] = code[0] >> 16;
bt.tail[1] = code[0] >> 8;
bt.tail[2] = code[0];
bt.tail[3] = code[1] >> 16;
bt.tail[4] = code[1] >> 8;
bt.tail[5] = code[1];

input += 4 * channels;
input_len -= 4 * channels;
Expand Down
11 changes: 10 additions & 1 deletion src/a2dp-codecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@

/* Customized (BlueALSA) 16-bit vendor extension. */
#define A2DP_CODEC_VENDOR_APTX 0x4FFF
#define A2DP_CODEC_VENDOR_APTX_AD 0xADFF
#define A2DP_CODEC_VENDOR_APTX_HD 0x24FF
#define A2DP_CODEC_VENDOR_APTX_LL 0xA2FF
#define A2DP_CODEC_VENDOR_APTX_HD 0xD7FF
#define A2DP_CODEC_VENDOR_APTX_TWS 0x25FF
#define A2DP_CODEC_VENDOR_FASTSTREAM 0xA1FF
#define A2DP_CODEC_VENDOR_LDAC 0x2DFF
#define A2DP_CODEC_VENDOR_LHDC 0x4CFF
Expand Down Expand Up @@ -245,6 +247,7 @@

#define APTX_CHANNEL_MODE_MONO 0x01
#define APTX_CHANNEL_MODE_STEREO 0x02
#define APTX_CHANNEL_MODE_TWS 0x08

#define APTX_SAMPLING_FREQ_16000 0x08
#define APTX_SAMPLING_FREQ_32000 0x04
Expand Down Expand Up @@ -288,6 +291,12 @@
#define APTX_HD_VENDOR_ID BT_COMPID_QUALCOMM_TECH
#define APTX_HD_CODEC_ID 0x0024

#define APTX_TWS_VENDOR_ID BT_COMPID_QUALCOMM_TECH
#define APTX_TWS_CODEC_ID 0x0025

#define APTX_AD_VENDOR_ID BT_COMPID_QUALCOMM_TECH
#define APTX_AD_CODEC_ID 0x00ad

#define LDAC_VENDOR_ID BT_COMPID_SONY
#define LDAC_CODEC_ID 0x00aa

Expand Down
116 changes: 60 additions & 56 deletions src/a2dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,28 @@ static const struct a2dp_codec a2dp_codec_sink_aptx = {
.samplings_size[0] = ARRAYSIZE(a2dp_aptx_samplings),
};

static const struct a2dp_codec a2dp_codec_source_aptx_hd = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.capabilities = &a2dp_aptx_hd,
.capabilities_size = sizeof(a2dp_aptx_hd),
.channels[0] = a2dp_aptx_hd_channels,
.channels_size[0] = ARRAYSIZE(a2dp_aptx_hd_channels),
.samplings[0] = a2dp_aptx_hd_samplings,
.samplings_size[0] = ARRAYSIZE(a2dp_aptx_hd_samplings),
};

static const struct a2dp_codec a2dp_codec_sink_aptx_hd = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.capabilities = &a2dp_aptx_hd,
.capabilities_size = sizeof(a2dp_aptx_hd),
.channels[0] = a2dp_aptx_hd_channels,
.channels_size[0] = ARRAYSIZE(a2dp_aptx_hd_channels),
.samplings[0] = a2dp_aptx_hd_samplings,
.samplings_size[0] = ARRAYSIZE(a2dp_aptx_hd_samplings),
};

static const struct a2dp_codec a2dp_codec_source_faststream = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_FASTSTREAM,
Expand All @@ -418,28 +440,6 @@ static const struct a2dp_codec a2dp_codec_sink_faststream = {
.samplings_size[1] = ARRAYSIZE(a2dp_faststream_samplings_voice),
};

static const struct a2dp_codec a2dp_codec_source_aptx_hd = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.capabilities = &a2dp_aptx_hd,
.capabilities_size = sizeof(a2dp_aptx_hd),
.channels[0] = a2dp_aptx_hd_channels,
.channels_size[0] = ARRAYSIZE(a2dp_aptx_hd_channels),
.samplings[0] = a2dp_aptx_hd_samplings,
.samplings_size[0] = ARRAYSIZE(a2dp_aptx_hd_samplings),
};

static const struct a2dp_codec a2dp_codec_sink_aptx_hd = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.capabilities = &a2dp_aptx_hd,
.capabilities_size = sizeof(a2dp_aptx_hd),
.channels[0] = a2dp_aptx_hd_channels,
.channels_size[0] = ARRAYSIZE(a2dp_aptx_hd_channels),
.samplings[0] = a2dp_aptx_hd_samplings,
.samplings_size[0] = ARRAYSIZE(a2dp_aptx_hd_samplings),
};

static const struct a2dp_codec a2dp_codec_source_ldac = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_LDAC,
Expand Down Expand Up @@ -469,13 +469,13 @@ const struct a2dp_codec *a2dp_codecs[] = {
#if ENABLE_APTX_HD
&a2dp_codec_source_aptx_hd,
#endif
#if ENABLE_APTX
&a2dp_codec_source_aptx,
#endif
#if ENABLE_FASTSTREAM
&a2dp_codec_source_faststream,
&a2dp_codec_sink_faststream,
#endif
#if ENABLE_APTX
&a2dp_codec_source_aptx,
#endif
#if ENABLE_AAC
&a2dp_codec_source_aac,
&a2dp_codec_sink_aac,
Expand Down Expand Up @@ -550,6 +550,10 @@ uint16_t a2dp_get_vendor_codec_id(const void *capabilities, size_t size) {
switch (codec_id) {
case APTX_HD_CODEC_ID:
return A2DP_CODEC_VENDOR_APTX_HD;
case APTX_TWS_CODEC_ID:
return A2DP_CODEC_VENDOR_APTX_TWS;
case APTX_AD_CODEC_ID:
return A2DP_CODEC_VENDOR_APTX_AD;
} break;
case BT_COMPID_SONY:
switch (codec_id) {
Expand Down Expand Up @@ -713,15 +717,6 @@ uint32_t a2dp_check_configuration(
}
#endif

#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM: {
const a2dp_faststream_t *cap = configuration;
cap_freq = cap->frequency_music;
cap_freq_bc = cap->frequency_voice;
break;
}
#endif

#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD: {
const a2dp_aptx_hd_t *cap = configuration;
Expand All @@ -731,6 +726,15 @@ uint32_t a2dp_check_configuration(
}
#endif

#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM: {
const a2dp_faststream_t *cap = configuration;
cap_freq = cap->frequency_music;
cap_freq_bc = cap->frequency_voice;
break;
}
#endif

#if ENABLE_LDAC
case A2DP_CODEC_VENDOR_LDAC: {
const a2dp_ldac_t *cap = configuration;
Expand Down Expand Up @@ -810,14 +814,14 @@ int a2dp_filter_capabilities(
case A2DP_CODEC_VENDOR_APTX:
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
break;
#endif
#if ENABLE_LDAC
case A2DP_CODEC_VENDOR_LDAC:
break;
Expand Down Expand Up @@ -1049,41 +1053,41 @@ int a2dp_select_configuration(
}
#endif

#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM: {
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD: {

a2dp_faststream_t *cap = capabilities;
unsigned int cap_freq = cap->frequency_music;
unsigned int cap_freq_bc = cap->frequency_voice;
a2dp_aptx_hd_t *cap = capabilities;
unsigned int cap_chm = cap->aptx.channel_mode;
unsigned int cap_freq = cap->aptx.frequency;

if ((cap->frequency_music = a2dp_codec_select_sampling_freq(codec, cap_freq, false)) == 0) {
error("FastStream: No supported sampling frequencies: %#x", cap_freq);
if ((cap->aptx.channel_mode = a2dp_codec_select_channel_mode(codec, cap_chm, false)) == 0) {
error("apt-X HD: No supported channel modes: %#x", cap_chm);
goto fail;
}

if ((cap->frequency_voice = a2dp_codec_select_sampling_freq(codec, cap_freq_bc, true)) == 0) {
error("FastStream: No supported back-channel sampling frequencies: %#x", cap_freq_bc);
if ((cap->aptx.frequency = a2dp_codec_select_sampling_freq(codec, cap_freq, false)) == 0) {
error("apt-X HD: No supported sampling frequencies: %#x", cap_freq);
goto fail;
}

break;
}
#endif

#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD: {
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM: {

a2dp_aptx_hd_t *cap = capabilities;
unsigned int cap_chm = cap->aptx.channel_mode;
unsigned int cap_freq = cap->aptx.frequency;
a2dp_faststream_t *cap = capabilities;
unsigned int cap_freq = cap->frequency_music;
unsigned int cap_freq_bc = cap->frequency_voice;

if ((cap->aptx.channel_mode = a2dp_codec_select_channel_mode(codec, cap_chm, false)) == 0) {
error("apt-X HD: No supported channel modes: %#x", cap_chm);
if ((cap->frequency_music = a2dp_codec_select_sampling_freq(codec, cap_freq, false)) == 0) {
error("FastStream: No supported sampling frequencies: %#x", cap_freq);
goto fail;
}

if ((cap->aptx.frequency = a2dp_codec_select_sampling_freq(codec, cap_freq, false)) == 0) {
error("apt-X HD: No supported sampling frequencies: %#x", cap_freq);
if ((cap->frequency_voice = a2dp_codec_select_sampling_freq(codec, cap_freq_bc, true)) == 0) {
error("FastStream: No supported back-channel sampling frequencies: %#x", cap_freq_bc);
goto fail;
}

Expand Down
20 changes: 10 additions & 10 deletions src/ba-transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,17 @@ static void transport_update_channels(struct ba_transport *t) {
cfg_value = ((a2dp_aptx_t *)t->a2dp.configuration)->channel_mode;
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
cfg_value = ((a2dp_aptx_hd_t *)t->a2dp.configuration)->aptx.channel_mode;
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
t->a2dp.pcm.channels = 2;
t->a2dp.pcm_bc.channels = 1;
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
cfg_value = ((a2dp_aptx_hd_t *)t->a2dp.configuration)->aptx.channel_mode;
break;
#endif
#if ENABLE_LDAC
case A2DP_CODEC_VENDOR_LDAC:
cfg_value = ((a2dp_ldac_t *)t->a2dp.configuration)->channel_mode;
Expand Down Expand Up @@ -601,17 +601,17 @@ static void transport_update_sampling(struct ba_transport *t) {
cfg_value = ((a2dp_aptx_t *)t->a2dp.configuration)->frequency;
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
cfg_value = ((a2dp_aptx_hd_t *)t->a2dp.configuration)->aptx.frequency;
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
cfg_value = ((a2dp_faststream_t *)t->a2dp.configuration)->frequency_music;
cfg_value_bc = ((a2dp_faststream_t *)t->a2dp.configuration)->frequency_voice;
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
cfg_value = ((a2dp_aptx_hd_t *)t->a2dp.configuration)->aptx.frequency;
break;
#endif
#if ENABLE_LDAC
case A2DP_CODEC_VENDOR_LDAC:
cfg_value = ((a2dp_ldac_t *)t->a2dp.configuration)->frequency;
Expand Down
8 changes: 4 additions & 4 deletions src/bluealsa-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ static bool ba_variant_populate_sep(GVariantBuilder *props, const struct a2dp_se
case A2DP_CODEC_VENDOR_APTX:
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
break;
#endif
#if ENABLE_APTX_HD
case A2DP_CODEC_VENDOR_APTX_HD:
break;
#endif
#if ENABLE_FASTSTREAM
case A2DP_CODEC_VENDOR_FASTSTREAM:
break;
#endif
#if ENABLE_LDAC
case A2DP_CODEC_VENDOR_LDAC:
break;
Expand Down
Loading

0 comments on commit b60a834

Please sign in to comment.