Skip to content

Commit

Permalink
multi-client support
Browse files Browse the repository at this point in the history
  • Loading branch information
borine committed Jan 5, 2025
1 parent a6251b4 commit 88ebec6
Show file tree
Hide file tree
Showing 34 changed files with 2,144 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@

{ include: [ '<spandsp/plc.h>', private, '<spandsp.h>', public ] },

{ include: [ '<bits/types/struct_itimerspec.h>', private, '<sys/timerfd.h>', public ] },

]
3 changes: 3 additions & 0 deletions .github/spellcheck-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ BTRH
BTT
bttransport
btusb
# aspell considers PIPE_BUF to be 2 words :(
BUF
CCE
CIEV
CIND
Expand Down Expand Up @@ -191,6 +193,7 @@ eoc
EP
EPIPE
EPMR
epoll
EQMID
errno
FB
Expand Down
6 changes: 6 additions & 0 deletions doc/bluealsad.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ OPTIONS
Without this option, **bluealsad** registers itself as an "org.bluealsa"
D-Bus service. For more information see the EXAMPLES_ below.

-M, --multi-client
Permit multiple clients to connect to the same PCM stream.
Without this option, only one client can connect to a PCM.
With this option, for playback clients, the streams are mixed together;
for capture each client receives a copy of the stream.

-i hciX, --device=hciX
HCI device to use. Can be specified multiple times to select more than one
HCI. Because HCI numbering can change after a system reboot, this option
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ bluealsad_SOURCES = \
ba-transport-pcm.c \
bluealsa-dbus.c \
bluealsa-iface.xml \
bluealsa-mix-buffer.c \
bluealsa-pcm-client.c \
bluealsa-pcm-multi.c \
bluez.c \
bluez-iface.xml \
codec-sbc.c \
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -291,6 +292,11 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
/* Get the delay introduced by the encoder. */
t_pcm->codec_delay_dms = info.nDelay * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
/* initialize RTP header and get anchor for payload */
uint8_t *rtp_payload = rtp_a2dp_init(bt.data, &rtp_header, NULL, 0);
Expand Down Expand Up @@ -471,6 +477,11 @@ void *a2dp_aac_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to 90kHz */
rtp_state_init(&rtp, rate, 90000);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-aptx-hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "codec-aptx.h"
#include "io.h"
#include "rtp.h"
Expand Down Expand Up @@ -138,6 +139,11 @@ void *a2dp_aptx_hd_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
/* initialize RTP header and get anchor for payload */
uint8_t *rtp_payload = rtp_a2dp_init(bt.data, &rtp_header, NULL, 0);
Expand Down Expand Up @@ -271,6 +277,11 @@ void *a2dp_aptx_hd_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to PCM sample rate */
rtp_state_init(&rtp, rate, rate);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "codec-aptx.h"
#include "io.h"
#include "shared/a2dp-codecs.h"
Expand Down Expand Up @@ -135,6 +136,11 @@ void *a2dp_aptx_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

debug_transport_pcm_thread_loop(t_pcm, "START");
for (ba_transport_pcm_state_set_running(t_pcm);;) {

Expand Down Expand Up @@ -249,6 +255,11 @@ void *a2dp_aptx_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

debug_transport_pcm_thread_loop(t_pcm, "START");
for (ba_transport_pcm_state_set_running(t_pcm);;) {

Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-faststream.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "codec-sbc.h"
#include "io.h"
#include "shared/a2dp-codecs.h"
Expand Down Expand Up @@ -157,6 +158,11 @@ void *a2dp_fs_enc_thread(struct ba_transport_pcm *t_pcm) {
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = sbc_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

debug_transport_pcm_thread_loop(t_pcm, "START");
for (ba_transport_pcm_state_set_running(t_pcm);;) {

Expand Down Expand Up @@ -277,6 +283,11 @@ void *a2dp_fs_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

debug_transport_pcm_thread_loop(t_pcm, "START");
for (ba_transport_pcm_state_set_running(t_pcm);;) {

Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-lc3plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -254,6 +255,11 @@ void *a2dp_lc3plus_enc_thread(struct ba_transport_pcm *t_pcm) {
const int lc3plus_delay_frames = lc3plus_enc_get_delay(handle);
t_pcm->codec_delay_dms = lc3plus_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;
/* initialize RTP headers and get anchor for payload */
Expand Down Expand Up @@ -462,6 +468,11 @@ void *a2dp_lc3plus_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to the RTP clock rate */
rtp_state_init(&rtp, rate, rtp_ts_clockrate);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-ldac.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "ba-config.h"
#include "bluealsa-pcm-multi.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -170,6 +171,11 @@ void *a2dp_ldac_enc_thread(struct ba_transport_pcm *t_pcm) {
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = ldac_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;
/* initialize RTP headers and get anchor for payload */
Expand Down Expand Up @@ -327,6 +333,11 @@ void *a2dp_ldac_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to PCM sample rate */
rtp_state_init(&rtp, rate, rate);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-mpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -230,6 +231,11 @@ void *a2dp_mp3_enc_thread(struct ba_transport_pcm *t_pcm) {
const int mpeg_delay_frames = lame_get_encoder_delay(handle);
t_pcm->codec_delay_dms = mpeg_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
rtp_mpeg_audio_header_t *rtp_mpeg_audio_header;
/* initialize RTP headers and get anchor for payload */
Expand Down Expand Up @@ -415,6 +421,11 @@ void *a2dp_mpeg_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to 90kHz */
rtp_state_init(&rtp, rate, 90000);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-pcm-multi.h"
#include "io.h"
#include "rtp.h"
#include "shared/a2dp-codecs.h"
Expand Down Expand Up @@ -173,6 +174,11 @@ void *a2dp_opus_enc_thread(struct ba_transport_pcm *t_pcm) {
opus_encoder_ctl(opus, OPUS_GET_LOOKAHEAD(&opus_delay_frames));
t_pcm->codec_delay_dms = opus_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;
/* initialize RTP headers and get anchor for payload */
Expand Down Expand Up @@ -304,6 +310,11 @@ void *a2dp_opus_dec_thread(struct ba_transport_pcm *t_pcm) {
opus_decoder_ctl(opus, OPUS_GET_LOOKAHEAD(&opus_delay_frames));
t_pcm->codec_delay_dms = opus_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to PCM sample rate */
rtp_state_init(&rtp, rate, rate);
Expand Down
11 changes: 11 additions & 0 deletions src/a2dp-sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "ba-config.h"
#include "bluealsa-pcm-multi.h"
#include "codec-sbc.h"
#include "io.h"
#include "rtp.h"
Expand Down Expand Up @@ -181,6 +182,11 @@ void *a2dp_sbc_enc_thread(struct ba_transport_pcm *t_pcm) {
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = sbc_delay_frames * 10000 / rate;

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;

Expand Down Expand Up @@ -324,6 +330,11 @@ void *a2dp_sbc_dec_thread(struct ba_transport_pcm *t_pcm) {
goto fail_ffb;
}

/* start multi client thread if required. */
if (t_pcm->multi &&
!bluealsa_pcm_multi_init(t_pcm->multi, pcm.nmemb))
goto fail_ffb;

struct rtp_state rtp = { .synced = false };
/* RTP clock frequency equal to PCM sample rate */
rtp_state_init(&rtp, rate, rate);
Expand Down
Loading

0 comments on commit 88ebec6

Please sign in to comment.