Skip to content

Commit

Permalink
Reuse common channel maps for A2DP configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Dec 20, 2024
1 parent 951d31b commit b95fd60
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 124 deletions.
31 changes: 4 additions & 27 deletions src/a2dp-aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,11 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_aac_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_aac_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const enum ba_transport_pcm_channel a2dp_aac_channel_map_5_1[] = {
BA_TRANSPORT_PCM_CHANNEL_FC,
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
BA_TRANSPORT_PCM_CHANNEL_RL, BA_TRANSPORT_PCM_CHANNEL_RR,
BA_TRANSPORT_PCM_CHANNEL_LFE,
};

static const enum ba_transport_pcm_channel a2dp_aac_channel_map_7_1[] = {
BA_TRANSPORT_PCM_CHANNEL_FC,
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
BA_TRANSPORT_PCM_CHANNEL_SL, BA_TRANSPORT_PCM_CHANNEL_SR,
BA_TRANSPORT_PCM_CHANNEL_RL, BA_TRANSPORT_PCM_CHANNEL_RR,
BA_TRANSPORT_PCM_CHANNEL_LFE,
};

static const struct a2dp_bit_mapping a2dp_aac_channels[] = {
{ AAC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_aac_channel_map_mono } },
{ AAC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_aac_channel_map_stereo } },
{ AAC_CHANNEL_MODE_5_1, .ch = { 6, a2dp_aac_channel_map_5_1 } },
{ AAC_CHANNEL_MODE_7_1, .ch = { 8, a2dp_aac_channel_map_7_1 } },
{ AAC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ AAC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ AAC_CHANNEL_MODE_5_1, .ch = { 6, a2dp_channel_map_5_1 } },
{ AAC_CHANNEL_MODE_7_1, .ch = { 8, a2dp_channel_map_7_1 } },
{ 0 }
};

Expand Down
12 changes: 2 additions & 10 deletions src/a2dp-aptx-hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,9 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_aptx_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_aptx_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_aptx_channels[] = {
{ APTX_CHANNEL_MODE_MONO, .ch = { 1, a2dp_aptx_channel_map_mono } },
{ APTX_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_aptx_channel_map_stereo } },
{ APTX_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ APTX_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
12 changes: 2 additions & 10 deletions src/a2dp-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_aptx_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_aptx_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_aptx_channels[] = {
{ APTX_CHANNEL_MODE_MONO, .ch = { 1, a2dp_aptx_channel_map_mono } },
{ APTX_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_aptx_channel_map_stereo } },
{ APTX_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ APTX_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
20 changes: 6 additions & 14 deletions src/a2dp-faststream.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_fs_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_fs_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_fs_rates_music[] = {
{ FASTSTREAM_SAMPLING_FREQ_MUSIC_44100, { 44100 } },
{ FASTSTREAM_SAMPLING_FREQ_MUSIC_48000, { 48000 } },
Expand Down Expand Up @@ -73,9 +65,9 @@ static int a2dp_fs_caps_foreach_channel_mode(
void *userdata) {
(void)capabilities;
const struct a2dp_bit_mapping channels_mono = {
.ch = { 1, a2dp_fs_channel_map_mono } };
.ch = { 1, a2dp_channel_map_mono } };
const struct a2dp_bit_mapping channels_stereo = {
.ch = { 2, a2dp_fs_channel_map_stereo } };
.ch = { 2, a2dp_channel_map_stereo } };
if (stream == A2DP_MAIN)
return func(channels_stereo, userdata);
return func(channels_mono, userdata);
Expand Down Expand Up @@ -416,8 +408,8 @@ static int a2dp_fs_transport_init(struct ba_transport *t) {
t->a2dp.pcm.channels = 2;
t->a2dp.pcm.rate = a2dp_fs_rates_music[rate_i].value;

memcpy(t->a2dp.pcm.channel_map,
a2dp_fs_channel_map_stereo, sizeof(a2dp_fs_channel_map_stereo));
memcpy(t->a2dp.pcm.channel_map, a2dp_channel_map_stereo,
2 * sizeof(*a2dp_channel_map_stereo));

}

Expand All @@ -432,8 +424,8 @@ static int a2dp_fs_transport_init(struct ba_transport *t) {
t->a2dp.pcm_bc.channels = 1;
t->a2dp.pcm_bc.rate = a2dp_fs_rates_voice[rate_i].value;

memcpy(t->a2dp.pcm_bc.channel_map,
a2dp_fs_channel_map_mono, sizeof(a2dp_fs_channel_map_mono));
memcpy(t->a2dp.pcm_bc.channel_map, a2dp_channel_map_mono,
1 * sizeof(*a2dp_channel_map_stereo));

}

Expand Down
12 changes: 2 additions & 10 deletions src/a2dp-lc3plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_lc3plus_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_lc3plus_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_lc3plus_channels[] = {
{ LC3PLUS_CHANNEL_MODE_MONO, .ch = { 1, a2dp_lc3plus_channel_map_mono } },
{ LC3PLUS_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_lc3plus_channel_map_stereo } },
{ LC3PLUS_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ LC3PLUS_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
14 changes: 3 additions & 11 deletions src/a2dp-ldac.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,10 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_ldac_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_ldac_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_ldac_channels[] = {
{ LDAC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_ldac_channel_map_mono } },
{ LDAC_CHANNEL_MODE_DUAL, .ch = { 2, a2dp_ldac_channel_map_stereo } },
{ LDAC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_ldac_channel_map_stereo } },
{ LDAC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ LDAC_CHANNEL_MODE_DUAL, .ch = { 2, a2dp_channel_map_stereo } },
{ LDAC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
10 changes: 3 additions & 7 deletions src/a2dp-lhdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_lhdc_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_lhdc_rates[] = {
{ LHDC_SAMPLING_FREQ_44100, { 44100 } },
{ LHDC_SAMPLING_FREQ_48000, { 48000 } },
Expand All @@ -62,7 +58,7 @@ static int a2dp_lhdc_caps_foreach_channel_mode(
void *userdata) {
(void)capabilities;
static const struct a2dp_bit_mapping channels_stereo = {
.ch = { 2, a2dp_lhdc_channel_map_stereo } };
.ch = { 2, a2dp_channel_map_stereo } };
if (stream == A2DP_MAIN)
return func(channels_stereo, userdata);
return -1;
Expand Down Expand Up @@ -486,8 +482,8 @@ static int a2dp_lhdc_transport_init(struct ba_transport *t) {
t->a2dp.pcm.channels = 2;
t->a2dp.pcm.rate = a2dp_lhdc_rates[rate_i].value;

memcpy(t->a2dp.pcm.channel_map,
a2dp_lhdc_channel_map_stereo, sizeof(a2dp_lhdc_channel_map_stereo));
memcpy(t->a2dp.pcm.channel_map, a2dp_channel_map_stereo,
2 * sizeof(*a2dp_channel_map_stereo));

return 0;
}
Expand Down
16 changes: 4 additions & 12 deletions src/a2dp-mpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,11 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_mpeg_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_mpeg_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_mpeg_channels[] = {
{ MPEG_CHANNEL_MODE_MONO, .ch = { 1, a2dp_mpeg_channel_map_mono } },
{ MPEG_CHANNEL_MODE_DUAL_CHANNEL, .ch = { 2, a2dp_mpeg_channel_map_stereo } },
{ MPEG_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_mpeg_channel_map_stereo } },
{ MPEG_CHANNEL_MODE_JOINT_STEREO, .ch = { 2, a2dp_mpeg_channel_map_stereo } },
{ MPEG_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ MPEG_CHANNEL_MODE_DUAL_CHANNEL, .ch = { 2, a2dp_channel_map_stereo } },
{ MPEG_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ MPEG_CHANNEL_MODE_JOINT_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
14 changes: 3 additions & 11 deletions src/a2dp-opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,10 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_opus_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_opus_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_opus_channels[] = {
{ OPUS_CHANNEL_MODE_MONO, .ch = { 1, a2dp_opus_channel_map_mono } },
{ OPUS_CHANNEL_MODE_DUAL, .ch = { 2, a2dp_opus_channel_map_stereo } },
{ OPUS_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_opus_channel_map_stereo } },
{ OPUS_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ OPUS_CHANNEL_MODE_DUAL, .ch = { 2, a2dp_channel_map_stereo } },
{ OPUS_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 }
};

Expand Down
16 changes: 4 additions & 12 deletions src/a2dp-sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,11 @@
#include "shared/log.h"
#include "shared/rt.h"

static const enum ba_transport_pcm_channel a2dp_sbc_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

static const enum ba_transport_pcm_channel a2dp_sbc_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

static const struct a2dp_bit_mapping a2dp_sbc_channels[] = {
{ SBC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_sbc_channel_map_mono } },
{ SBC_CHANNEL_MODE_DUAL_CHANNEL, .ch = { 2, a2dp_sbc_channel_map_stereo } },
{ SBC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_sbc_channel_map_stereo } },
{ SBC_CHANNEL_MODE_JOINT_STEREO, .ch = { 2, a2dp_sbc_channel_map_stereo } },
{ SBC_CHANNEL_MODE_MONO, .ch = { 1, a2dp_channel_map_mono } },
{ SBC_CHANNEL_MODE_DUAL_CHANNEL, .ch = { 2, a2dp_channel_map_stereo } },
{ SBC_CHANNEL_MODE_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ SBC_CHANNEL_MODE_JOINT_STEREO, .ch = { 2, a2dp_channel_map_stereo } },
{ 0 },
};

Expand Down
23 changes: 23 additions & 0 deletions src/a2dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@
#include "shared/a2dp-codecs.h"
#include "shared/log.h"

const enum ba_transport_pcm_channel a2dp_channel_map_mono[] = {
BA_TRANSPORT_PCM_CHANNEL_MONO,
};

const enum ba_transport_pcm_channel a2dp_channel_map_stereo[] = {
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
};

const enum ba_transport_pcm_channel a2dp_channel_map_5_1[] = {
BA_TRANSPORT_PCM_CHANNEL_FC,
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
BA_TRANSPORT_PCM_CHANNEL_RL, BA_TRANSPORT_PCM_CHANNEL_RR,
BA_TRANSPORT_PCM_CHANNEL_LFE,
};

const enum ba_transport_pcm_channel a2dp_channel_map_7_1[] = {
BA_TRANSPORT_PCM_CHANNEL_FC,
BA_TRANSPORT_PCM_CHANNEL_FL, BA_TRANSPORT_PCM_CHANNEL_FR,
BA_TRANSPORT_PCM_CHANNEL_SL, BA_TRANSPORT_PCM_CHANNEL_SR,
BA_TRANSPORT_PCM_CHANNEL_RL, BA_TRANSPORT_PCM_CHANNEL_RR,
BA_TRANSPORT_PCM_CHANNEL_LFE,
};

/**
* Callback function which returns bitmask for the best channel mode.
*
Expand Down
5 changes: 5 additions & 0 deletions src/a2dp.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ typedef int (*a2dp_bit_mapping_foreach_func)(
struct a2dp_bit_mapping mapping,
void *userdata);

extern const enum ba_transport_pcm_channel a2dp_channel_map_mono[];
extern const enum ba_transport_pcm_channel a2dp_channel_map_stereo[];
extern const enum ba_transport_pcm_channel a2dp_channel_map_5_1[];
extern const enum ba_transport_pcm_channel a2dp_channel_map_7_1[];

int a2dp_bit_mapping_foreach_get_best_channel_mode(
struct a2dp_bit_mapping mapping,
void *userdata);
Expand Down

0 comments on commit b95fd60

Please sign in to comment.