Skip to content

Commit

Permalink
Unify local and external SEP configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jun 26, 2024
1 parent 14670ed commit 1bafbd9
Show file tree
Hide file tree
Showing 31 changed files with 296 additions and 334 deletions.
56 changes: 28 additions & 28 deletions src/a2dp-aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,11 @@ static const struct a2dp_sampling a2dp_aac_samplings[] = {
};

static int a2dp_aac_capabilities_filter(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
const void *capabilities_mask,
void *capabilities) {

(void)codec;
(void)sep;
const a2dp_aac_t *caps_mask = capabilities_mask;
a2dp_aac_t *caps = capabilities;

Expand All @@ -522,14 +522,14 @@ static int a2dp_aac_capabilities_filter(
}

static int a2dp_aac_configuration_select(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
void *capabilities) {

a2dp_aac_t *caps = capabilities;
const a2dp_aac_t saved = *caps;

/* narrow capabilities to values supported by BlueALSA */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
caps, sizeof(*caps)) != 0)
return -1;

Expand Down Expand Up @@ -569,7 +569,7 @@ static int a2dp_aac_configuration_select(
return errno = ENOTSUP, -1;
}

unsigned int ba_bitrate = A2DP_AAC_GET_BITRATE(codec->capabilities.aac);
unsigned int ba_bitrate = A2DP_AAC_GET_BITRATE(sep->capabilities.aac);
unsigned int cap_bitrate = A2DP_AAC_GET_BITRATE(*caps);
if (cap_bitrate == 0)
/* fix bitrate value if it was not set */
Expand All @@ -583,14 +583,14 @@ static int a2dp_aac_configuration_select(
}

static int a2dp_aac_configuration_check(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
const void *configuration) {

const a2dp_aac_t *conf = configuration;
a2dp_aac_t conf_v = *conf;

/* validate configuration against BlueALSA capabilities */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
&conf_v, sizeof(conf_v)) != 0)
return A2DP_CHECK_ERR_SIZE;

Expand Down Expand Up @@ -641,7 +641,7 @@ static int a2dp_aac_transport_init(struct ba_transport *t) {
return 0;
}

static int a2dp_aac_source_init(struct a2dp_codec *codec) {
static int a2dp_aac_source_init(struct a2dp_sep *sep) {

LIB_INFO info[16] = {
[15] = { .module_id = ~FDK_NONE } };
Expand All @@ -658,25 +658,25 @@ static int a2dp_aac_source_init(struct a2dp_codec *codec) {
}

if (caps_aac & CAPF_ER_AAC_SCAL)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_SCA;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_SCA;
if (caps_sbr & CAPF_SBR_HQ)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE;
if (caps_sbr & CAPF_SBR_PS_MPEG)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE2;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE2;
if (caps_aac & CAPF_ER_AAC_ELDV2)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_ELD2;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_ELD2;
if (caps_aac & CAPF_AAC_UNIDRC)
codec->capabilities.aac.drc = 1;
sep->capabilities.aac.drc = 1;

if (config.a2dp.force_mono)
codec->capabilities.aac.channels = AAC_CHANNELS_1;
sep->capabilities.aac.channels = AAC_CHANNELS_1;
if (config.a2dp.force_44100)
A2DP_AAC_SET_FREQUENCY(codec->capabilities.aac, AAC_SAMPLING_FREQ_44100);
A2DP_AAC_SET_FREQUENCY(sep->capabilities.aac, AAC_SAMPLING_FREQ_44100);

if (!config.aac_prefer_vbr)
codec->capabilities.aac.vbr = 0;
sep->capabilities.aac.vbr = 0;

A2DP_AAC_SET_BITRATE(codec->capabilities.aac, config.aac_bitrate);
A2DP_AAC_SET_BITRATE(sep->capabilities.aac, config.aac_bitrate);

return 0;
}
Expand All @@ -685,7 +685,7 @@ static int a2dp_aac_source_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aac_enc_thread, "ba-a2dp-aac");
}

struct a2dp_codec a2dp_aac_source = {
struct a2dp_sep a2dp_aac_source = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_MPEG24,
.synopsis = "A2DP Source (AAC)",
Expand Down Expand Up @@ -726,7 +726,7 @@ struct a2dp_codec a2dp_aac_source = {
.enabled = true,
};

static int a2dp_aac_sink_init(struct a2dp_codec *codec) {
static int a2dp_aac_sink_init(struct a2dp_sep *sep) {

LIB_INFO info[16] = {
[15] = { .module_id = ~FDK_NONE } };
Expand All @@ -745,21 +745,21 @@ static int a2dp_aac_sink_init(struct a2dp_codec *codec) {
}

if (caps_aac & CAPF_ER_AAC_SCAL)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_SCA;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_SCA;
if (caps_sbr & CAPF_SBR_HQ)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE;
if (caps_sbr & CAPF_SBR_PS_MPEG)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE2;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_HE2;
if (caps_aac & CAPF_ER_AAC_ELDV2)
codec->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_ELD2;
sep->capabilities.aac.object_type |= AAC_OBJECT_TYPE_MPEG4_ELD2;
if (caps_aac & CAPF_AAC_UNIDRC)
codec->capabilities.aac.drc = 1;
sep->capabilities.aac.drc = 1;
if (caps_dmx & CAPF_DMX_6_CH)
codec->capabilities.aac.channels |= AAC_CHANNELS_6;
sep->capabilities.aac.channels |= AAC_CHANNELS_6;
if (caps_dmx & CAPF_DMX_8_CH)
codec->capabilities.aac.channels |= AAC_CHANNELS_8;
sep->capabilities.aac.channels |= AAC_CHANNELS_8;

A2DP_AAC_SET_BITRATE(codec->capabilities.aac, config.aac_bitrate);
A2DP_AAC_SET_BITRATE(sep->capabilities.aac, config.aac_bitrate);

return 0;
}
Expand All @@ -768,7 +768,7 @@ static int a2dp_aac_sink_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aac_dec_thread, "ba-a2dp-aac");
}

struct a2dp_codec a2dp_aac_sink = {
struct a2dp_sep a2dp_aac_sink = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_MPEG24,
.synopsis = "A2DP Sink (AAC)",
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aac.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "a2dp.h"

extern struct a2dp_codec a2dp_aac_source;
extern struct a2dp_codec a2dp_aac_sink;
extern struct a2dp_sep a2dp_aac_source;
extern struct a2dp_sep a2dp_aac_sink;

#endif
16 changes: 8 additions & 8 deletions src/a2dp-aptx-hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ static const struct a2dp_sampling a2dp_aptx_hd_samplings[] = {
};

static int a2dp_aptx_hd_configuration_select(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
void *capabilities) {

a2dp_aptx_hd_t *caps = capabilities;
const a2dp_aptx_hd_t saved = *caps;

/* narrow capabilities to values supported by BlueALSA */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
caps, sizeof(*caps)) != 0)
return -1;

Expand All @@ -312,14 +312,14 @@ static int a2dp_aptx_hd_configuration_select(
}

static int a2dp_aptx_hd_configuration_check(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
const void *configuration) {

const a2dp_aptx_hd_t *conf = configuration;
a2dp_aptx_hd_t conf_v = *conf;

/* validate configuration against BlueALSA capabilities */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
&conf_v, sizeof(conf_v)) != 0)
return A2DP_CHECK_ERR_SIZE;

Expand Down Expand Up @@ -355,19 +355,19 @@ static int a2dp_aptx_hd_transport_init(struct ba_transport *t) {
return 0;
}

static int a2dp_aptx_hd_source_init(struct a2dp_codec *codec) {
static int a2dp_aptx_hd_source_init(struct a2dp_sep *sep) {
if (config.a2dp.force_mono)
warn("apt-X HD: Mono channel mode not supported");
if (config.a2dp.force_44100)
codec->capabilities.aptx_hd.aptx.frequency = APTX_SAMPLING_FREQ_44100;
sep->capabilities.aptx_hd.aptx.frequency = APTX_SAMPLING_FREQ_44100;
return 0;
}

static int a2dp_aptx_hd_source_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aptx_hd_enc_thread, "ba-a2dp-aptx-hd");
}

struct a2dp_codec a2dp_aptx_hd_source = {
struct a2dp_sep a2dp_aptx_hd_source = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.synopsis = "A2DP Source (apt-X HD)",
Expand Down Expand Up @@ -397,7 +397,7 @@ static int a2dp_aptx_hd_sink_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aptx_hd_dec_thread, "ba-a2dp-aptx-hd");
}

struct a2dp_codec a2dp_aptx_hd_sink = {
struct a2dp_sep a2dp_aptx_hd_sink = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_VENDOR_APTX_HD,
.synopsis = "A2DP Sink (apt-X HD)",
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aptx-hd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "a2dp.h"

extern struct a2dp_codec a2dp_aptx_hd_source;
extern struct a2dp_codec a2dp_aptx_hd_sink;
extern struct a2dp_sep a2dp_aptx_hd_source;
extern struct a2dp_sep a2dp_aptx_hd_sink;

#endif
16 changes: 8 additions & 8 deletions src/a2dp-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ static const struct a2dp_sampling a2dp_aptx_samplings[] = {
};

static int a2dp_aptx_configuration_select(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
void *capabilities) {

a2dp_aptx_t *caps = capabilities;
const a2dp_aptx_t saved = *caps;

/* narrow capabilities to values supported by BlueALSA */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
caps, sizeof(*caps)) != 0)
return -1;

Expand All @@ -274,14 +274,14 @@ static int a2dp_aptx_configuration_select(
}

static int a2dp_aptx_configuration_check(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
const void *configuration) {

const a2dp_aptx_t *conf = configuration;
a2dp_aptx_t conf_v = *conf;

/* validate configuration against BlueALSA capabilities */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
&conf_v, sizeof(conf_v)) != 0)
return A2DP_CHECK_ERR_SIZE;

Expand Down Expand Up @@ -317,19 +317,19 @@ static int a2dp_aptx_transport_init(struct ba_transport *t) {
return 0;
}

static int a2dp_aptx_source_init(struct a2dp_codec *codec) {
static int a2dp_aptx_source_init(struct a2dp_sep *sep) {
if (config.a2dp.force_mono)
warn("apt-X: Mono channel mode not supported");
if (config.a2dp.force_44100)
codec->capabilities.aptx.frequency = APTX_SAMPLING_FREQ_44100;
sep->capabilities.aptx.frequency = APTX_SAMPLING_FREQ_44100;
return 0;
}

static int a2dp_aptx_source_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aptx_enc_thread, "ba-a2dp-aptx");
}

struct a2dp_codec a2dp_aptx_source = {
struct a2dp_sep a2dp_aptx_source = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_APTX,
.synopsis = "A2DP Source (apt-X)",
Expand Down Expand Up @@ -359,7 +359,7 @@ static int a2dp_aptx_sink_transport_start(struct ba_transport *t) {
return ba_transport_pcm_start(&t->a2dp.pcm, a2dp_aptx_dec_thread, "ba-a2dp-aptx");
}

struct a2dp_codec a2dp_aptx_sink = {
struct a2dp_sep a2dp_aptx_sink = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_VENDOR_APTX,
.synopsis = "A2DP Sink (apt-X)",
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aptx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "a2dp.h"

extern struct a2dp_codec a2dp_aptx_source;
extern struct a2dp_codec a2dp_aptx_sink;
extern struct a2dp_sep a2dp_aptx_source;
extern struct a2dp_sep a2dp_aptx_sink;

#endif
16 changes: 8 additions & 8 deletions src/a2dp-faststream.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ static const struct a2dp_sampling a2dp_faststream_samplings_voice[] = {
};

static int a2dp_faststream_configuration_select(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
void *capabilities) {

a2dp_faststream_t *caps = capabilities;
const a2dp_faststream_t saved = *caps;

/* narrow capabilities to values supported by BlueALSA */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
caps, sizeof(*caps)) != 0)
return -1;

Expand Down Expand Up @@ -287,14 +287,14 @@ static int a2dp_faststream_configuration_select(
}

static int a2dp_faststream_configuration_check(
const struct a2dp_codec *codec,
const struct a2dp_sep *sep,
const void *configuration) {

const a2dp_faststream_t *conf = configuration;
a2dp_faststream_t conf_v = *conf;

/* validate configuration against BlueALSA capabilities */
if (a2dp_filter_capabilities(codec, &codec->capabilities,
if (a2dp_filter_capabilities(sep, &sep->capabilities,
&conf_v, sizeof(conf_v)) != 0)
return A2DP_CHECK_ERR_SIZE;

Expand Down Expand Up @@ -349,11 +349,11 @@ static int a2dp_faststream_transport_init(struct ba_transport *t) {
return 0;
}

static int a2dp_faststream_source_init(struct a2dp_codec *codec) {
static int a2dp_faststream_source_init(struct a2dp_sep *sep) {
if (config.a2dp.force_mono)
warn("FastStream: Mono channel mode not supported");
if (config.a2dp.force_44100)
codec->capabilities.faststream.frequency_music = FASTSTREAM_SAMPLING_FREQ_MUSIC_44100;
sep->capabilities.faststream.frequency_music = FASTSTREAM_SAMPLING_FREQ_MUSIC_44100;
return 0;
}

Expand All @@ -371,7 +371,7 @@ static int a2dp_faststream_source_transport_start(struct ba_transport *t) {
return rv;
}

struct a2dp_codec a2dp_faststream_source = {
struct a2dp_sep a2dp_faststream_source = {
.dir = A2DP_SOURCE,
.codec_id = A2DP_CODEC_VENDOR_FASTSTREAM,
.synopsis = "A2DP Source (FastStream)",
Expand Down Expand Up @@ -406,7 +406,7 @@ static int a2dp_faststream_sink_transport_start(struct ba_transport *t) {
return rv;
}

struct a2dp_codec a2dp_faststream_sink = {
struct a2dp_sep a2dp_faststream_sink = {
.dir = A2DP_SINK,
.codec_id = A2DP_CODEC_VENDOR_FASTSTREAM,
.synopsis = "A2DP Sink (FastStream)",
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-faststream.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "a2dp.h"

extern struct a2dp_codec a2dp_faststream_source;
extern struct a2dp_codec a2dp_faststream_sink;
extern struct a2dp_sep a2dp_faststream_source;
extern struct a2dp_sep a2dp_faststream_sink;

#endif
Loading

0 comments on commit 1bafbd9

Please sign in to comment.