Skip to content

Commit e909d9a

Browse files
committed
Command line option to enable all available codecs
1 parent 1367549 commit e909d9a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ AC_SUBST([SYSTEMD_SYSTEM_UNIT_DIR], [$systemdsystemunitdir])
422422

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

430430
AC_ARG_WITH([systemdbluealsaaplayargs],

doc/bluealsad.8.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ bluealsad
66
Bluetooth Audio ALSA Backend
77
----------------------------
88

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

93+
--all-codecs
94+
Enable all available Bluetooth audio codecs.
95+
This option is equivalent to enabling all available audio codecs by
96+
specifying them with the ``--codec`` option.
97+
98+
After enabling all available codecs, it is still possible to disable some
99+
of them by using the ``--codec`` option with the **-** prefix. However, the
100+
``--codec`` option(s) must be specified after the ``--all-codecs`` option.
101+
93102
--initial-volume=NUM
94103
Set the initial volume to *NUM* % when a device is first connected.
95104
*NUM* must be an integer in the range from **0** to **100**.

src/main.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ static void g_bus_name_lost(GDBusConnection *conn, const char *name, void *userd
154154
int main(int argc, char **argv) {
155155

156156
int opt;
157-
const char *opts = "hVSB:i:p:c:";
158-
const struct option longopts[] = {
157+
static const char *opts = "hVSB:i:p:c:";
158+
static const struct option longopts[] = {
159159
{ "help", no_argument, NULL, 'h' },
160160
{ "version", no_argument, NULL, 'V' },
161161
{ "syslog", no_argument, NULL, 'S' },
@@ -164,6 +164,7 @@ int main(int argc, char **argv) {
164164
{ "device", required_argument, NULL, 'i' },
165165
{ "profile", required_argument, NULL, 'p' },
166166
{ "codec", required_argument, NULL, 'c' },
167+
{ "all-codecs", no_argument, NULL, 25 },
167168
{ "initial-volume", required_argument, NULL, 17 },
168169
{ "keep-alive", required_argument, NULL, 8 },
169170
{ "io-rt-priority", required_argument, NULL, 3 },
@@ -200,6 +201,19 @@ int main(int argc, char **argv) {
200201
{ 0, 0, 0, 0 },
201202
};
202203

204+
static const struct {
205+
uint32_t codec_id;
206+
bool *ptr;
207+
} hfp_codecs[] = {
208+
{ HFP_CODEC_CVSD, &config.hfp.codecs.cvsd },
209+
#if ENABLE_MSBC
210+
{ HFP_CODEC_MSBC, &config.hfp.codecs.msbc },
211+
#endif
212+
#if ENABLE_LC3_SWB
213+
{ HFP_CODEC_LC3_SWB, &config.hfp.codecs.lc3_swb },
214+
#endif
215+
};
216+
203217
bool syslog = false;
204218
char dbus_service[32] = BLUEALSA_SERVICE;
205219

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

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

378-
static const struct {
379-
uint32_t codec_id;
380-
bool *ptr;
381-
} hfp_codecs[] = {
382-
{ HFP_CODEC_CVSD, &config.hfp.codecs.cvsd },
383-
#if ENABLE_MSBC
384-
{ HFP_CODEC_MSBC, &config.hfp.codecs.msbc },
385-
#endif
386-
#if ENABLE_LC3_SWB
387-
{ HFP_CODEC_LC3_SWB, &config.hfp.codecs.lc3_swb },
388-
#endif
389-
};
390-
391393
bool enable = true;
392394
bool matched = false;
393395
if (optarg[0] == '+' || optarg[0] == '-') {
@@ -418,6 +420,15 @@ int main(int argc, char **argv) {
418420
break;
419421
}
420422

423+
case 25 /* --all-codecs */ : {
424+
struct a2dp_sep * const * seps = a2dp_seps;
425+
for (struct a2dp_sep *sep = *seps; sep != NULL; sep = *++seps)
426+
sep->enabled = true;
427+
for (size_t i = 0; i < ARRAYSIZE(hfp_codecs); i++)
428+
*hfp_codecs[i].ptr = true;
429+
break;
430+
}
431+
421432
case 17 /* --initial-volume=NUM */ : {
422433
unsigned int vol = atoi(optarg);
423434
if (vol > 100) {

0 commit comments

Comments
 (0)