Skip to content

Commit

Permalink
Command line option to enable all available codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Dec 5, 2024
1 parent 1367549 commit e909d9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ AC_SUBST([SYSTEMD_SYSTEM_UNIT_DIR], [$systemdsystemunitdir])

AC_ARG_WITH([systemdbluealsadargs],
AS_HELP_STRING([--with-systemdbluealsadargs=ARGS], [bluealsad arguments to be used in
bluealsa.service, defaults to '-S -p a2dp-source -p a2dp-sink' if not specified]),
bluealsa.service, defaults to '-S -p a2dp-source -p a2dp-sink --all-codecs' if not specified]),
[systemdbluealsadargs="${withval}"],
[systemdbluealsadargs="-S -p a2dp-source -p a2dp-sink"])
[systemdbluealsadargs="-S -p a2dp-source -p a2dp-sink --all-codecs"])
AC_SUBST([SYSTEMD_BLUEALSAD_ARGS], [$systemdbluealsadargs])

AC_ARG_WITH([systemdbluealsaaplayargs],
Expand Down
11 changes: 10 additions & 1 deletion doc/bluealsad.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bluealsad
Bluetooth Audio ALSA Backend
----------------------------

:Date: August 2024
:Date: December 2024
:Manual section: 8
:Manual group: System Manager's Manual
:Version: $VERSION$
Expand Down Expand Up @@ -90,6 +90,15 @@ OPTIONS
For the list of supported audio codecs see the "Available BT audio codecs"
section of the **bluealsad** command-line help message.

--all-codecs
Enable all available Bluetooth audio codecs.
This option is equivalent to enabling all available audio codecs by
specifying them with the ``--codec`` option.

After enabling all available codecs, it is still possible to disable some
of them by using the ``--codec`` option with the **-** prefix. However, the
``--codec`` option(s) must be specified after the ``--all-codecs`` option.

--initial-volume=NUM
Set the initial volume to *NUM* % when a device is first connected.
*NUM* must be an integer in the range from **0** to **100**.
Expand Down
41 changes: 26 additions & 15 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ static void g_bus_name_lost(GDBusConnection *conn, const char *name, void *userd
int main(int argc, char **argv) {

int opt;
const char *opts = "hVSB:i:p:c:";
const struct option longopts[] = {
static const char *opts = "hVSB:i:p:c:";
static const struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "syslog", no_argument, NULL, 'S' },
Expand All @@ -164,6 +164,7 @@ int main(int argc, char **argv) {
{ "device", required_argument, NULL, 'i' },
{ "profile", required_argument, NULL, 'p' },
{ "codec", required_argument, NULL, 'c' },
{ "all-codecs", no_argument, NULL, 25 },
{ "initial-volume", required_argument, NULL, 17 },
{ "keep-alive", required_argument, NULL, 8 },
{ "io-rt-priority", required_argument, NULL, 3 },
Expand Down Expand Up @@ -200,6 +201,19 @@ int main(int argc, char **argv) {
{ 0, 0, 0, 0 },
};

static const struct {
uint32_t codec_id;
bool *ptr;
} hfp_codecs[] = {
{ HFP_CODEC_CVSD, &config.hfp.codecs.cvsd },
#if ENABLE_MSBC
{ HFP_CODEC_MSBC, &config.hfp.codecs.msbc },
#endif
#if ENABLE_LC3_SWB
{ HFP_CODEC_LC3_SWB, &config.hfp.codecs.lc3_swb },
#endif
};

bool syslog = false;
char dbus_service[32] = BLUEALSA_SERVICE;

Expand All @@ -221,6 +235,7 @@ int main(int argc, char **argv) {
" -i, --device=hciX\t\tHCI device(s) to use\n"
" -p, --profile=NAME\t\tset enabled BT profiles\n"
" -c, --codec=NAME\t\tset enabled BT audio codecs\n"
" --all-codecs\t\t\tenable all available BT audio codecs\n"
" --initial-volume=NUM\t\tinitial volume level [0-100]\n"
" --keep-alive=SEC\t\tkeep Bluetooth transport alive\n"
" --io-rt-priority=NUM\t\treal-time priority for IO threads\n"
Expand Down Expand Up @@ -375,19 +390,6 @@ int main(int argc, char **argv) {

case 'c' /* --codec=NAME */ : {

static const struct {
uint32_t codec_id;
bool *ptr;
} hfp_codecs[] = {
{ HFP_CODEC_CVSD, &config.hfp.codecs.cvsd },
#if ENABLE_MSBC
{ HFP_CODEC_MSBC, &config.hfp.codecs.msbc },
#endif
#if ENABLE_LC3_SWB
{ HFP_CODEC_LC3_SWB, &config.hfp.codecs.lc3_swb },
#endif
};

bool enable = true;
bool matched = false;
if (optarg[0] == '+' || optarg[0] == '-') {
Expand Down Expand Up @@ -418,6 +420,15 @@ int main(int argc, char **argv) {
break;
}

case 25 /* --all-codecs */ : {
struct a2dp_sep * const * seps = a2dp_seps;
for (struct a2dp_sep *sep = *seps; sep != NULL; sep = *++seps)
sep->enabled = true;
for (size_t i = 0; i < ARRAYSIZE(hfp_codecs); i++)
*hfp_codecs[i].ptr = true;
break;
}

case 17 /* --initial-volume=NUM */ : {
unsigned int vol = atoi(optarg);
if (vol > 100) {
Expand Down

0 comments on commit e909d9a

Please sign in to comment.