Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dbus delay signals for internal processing delay. #734

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/a2dpconf.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OPTIONS
Print version and exit.

-v, --verbose
Sow verbose bit-stream details.
Show verbose bit-stream details.
Display each field as a binary mask with each bit represented by a single
character.

Expand Down
17 changes: 12 additions & 5 deletions src/a2dp-aac.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-aac.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -30,6 +30,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-dbus.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -290,6 +291,7 @@ 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;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

rtp_header_t *rtp_header;
/* initialize RTP header and get anchor for payload */
Expand Down Expand Up @@ -374,6 +376,13 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

/* resend RTP header */
len -= RTP_HEADER_LEN;

Expand All @@ -390,14 +399,11 @@ void *a2dp_aac_enc_thread(struct ba_transport_pcm *t_pcm) {
}

unsigned int pcm_frames = out_args.numInSamples / info.inputChannels;
/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);
/* move forward RTP timestamp clock */
rtp_state_update(&rtp, pcm_frames);

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

/* If the input buffer was not consumed, we have to append new data to
* the existing one. Since we do not use ring buffer, we will simply
* move unprocessed data to the front of our linear buffer. */
Expand Down Expand Up @@ -553,6 +559,7 @@ void *a2dp_aac_dec_thread(struct ba_transport_pcm *t_pcm) {

/* Update the delay introduced by the decoder. */
t_pcm->codec_delay_dms = info->outputDelay * 10000 / rate;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

/* update local state with decoded PCM frames */
rtp_state_update(&rtp, info->frameSize);
Expand Down
15 changes: 10 additions & 5 deletions src/a2dp-aptx-hd.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-aptx-hd.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand All @@ -26,6 +26,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-dbus.h"
#include "codec-aptx.h"
#include "io.h"
#include "rtp.h"
Expand Down Expand Up @@ -205,15 +206,19 @@ void *a2dp_aptx_hd_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

unsigned int pcm_frames = pcm_samples / channels;
/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);
/* move forward RTP timestamp clock */
rtp.ts_pcm_frames += pcm_frames;

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

/* reinitialize output buffer */
ffb_rewind(&bt);

Expand Down
16 changes: 11 additions & 5 deletions src/a2dp-aptx.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-aptx.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand All @@ -16,6 +16,7 @@

#include <errno.h>
#include <pthread.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -25,6 +26,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-dbus.h"
#include "codec-aptx.h"
#include "io.h"
#include "shared/a2dp-codecs.h"
Expand Down Expand Up @@ -189,11 +191,15 @@ void *a2dp_aptx_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

/* keep data transfer at a constant bit rate */
asrsync_sync(&io.asrs, pcm_samples / channels);
if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_samples / channels);

/* reinitialize output buffer */
ffb_rewind(&bt);
Expand Down
16 changes: 11 additions & 5 deletions src/a2dp-faststream.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-faststream.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand All @@ -24,6 +24,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-dbus.h"
#include "codec-sbc.h"
#include "io.h"
#include "shared/a2dp-codecs.h"
Expand Down Expand Up @@ -156,6 +157,7 @@ void *a2dp_fs_enc_thread(struct ba_transport_pcm *t_pcm) {
const unsigned int sbc_delay_frames = 73;
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = sbc_delay_frames * 10000 / rate;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

debug_transport_pcm_thread_loop(t_pcm, "START");
for (ba_transport_pcm_state_set_running(t_pcm);;) {
Expand Down Expand Up @@ -213,15 +215,19 @@ void *a2dp_fs_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

/* make room for new FastStream frames */
ffb_rewind(&bt);

/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

/* If the input buffer was not consumed (due to codesize limit), we
* have to append new data to the existing one. Since we do not use
* ring buffer, we will simply move unprocessed data to the front
Expand Down
16 changes: 11 additions & 5 deletions src/a2dp-lc3plus.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-lc3plus.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand Down Expand Up @@ -30,6 +30,7 @@
#include "ba-config.h"
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "bluealsa-dbus.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -253,6 +254,7 @@ void *a2dp_lc3plus_enc_thread(struct ba_transport_pcm *t_pcm) {
* delay in the decoder thread. */
const int lc3plus_delay_frames = lc3plus_enc_get_delay(handle);
t_pcm->codec_delay_dms = lc3plus_delay_frames * 10000 / rate;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;
Expand Down Expand Up @@ -353,6 +355,13 @@ void *a2dp_lc3plus_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

/* resend RTP headers */
len -= rtp_headers_len;

Expand All @@ -370,14 +379,11 @@ void *a2dp_lc3plus_enc_thread(struct ba_transport_pcm *t_pcm) {

}

/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);
/* move forward RTP timestamp clock */
rtp_state_update(&rtp, pcm_frames);

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

/* If the input buffer was not consumed (due to codesize limit), we
* have to append new data to the existing one. Since we do not use
* ring buffer, we will simply move unprocessed data to the front
Expand Down
16 changes: 11 additions & 5 deletions src/a2dp-ldac.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-ldac.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
*
* This file is a part of bluez-alsa.
*
Expand All @@ -27,6 +27,7 @@
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "ba-config.h"
#include "bluealsa-dbus.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -169,6 +170,7 @@ void *a2dp_ldac_enc_thread(struct ba_transport_pcm *t_pcm) {
const unsigned int ldac_delay_frames = 128;
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = ldac_delay_frames * 10000 / rate;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

rtp_header_t *rtp_header;
rtp_media_header_t *rtp_media_header;
Expand Down Expand Up @@ -244,6 +246,13 @@ void *a2dp_ldac_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

if (errno == EAGAIN)
/* The io_bt_write() call was blocking due to not enough
* space in the BT socket. Set the queued_bytes to some
Expand All @@ -256,14 +265,11 @@ void *a2dp_ldac_enc_thread(struct ba_transport_pcm *t_pcm) {
}

unsigned int pcm_frames = pcm_samples / channels;
/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);
/* move forward RTP timestamp clock */
rtp_state_update(&rtp, pcm_frames);

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

}

/* If the input buffer was not consumed (due to codesize limit), we
Expand Down
16 changes: 11 additions & 5 deletions src/a2dp-lhdc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BlueALSA - a2dp-lhdc.c
* Copyright (c) 2016-2024 Arkadiusz Bokowy
* Copyright (c) 2016-2025 Arkadiusz Bokowy
* Copyright (c) 2023 anonymix007
*
* This file is a part of bluez-alsa.
Expand Down Expand Up @@ -29,6 +29,7 @@
#include "ba-transport.h"
#include "ba-transport-pcm.h"
#include "ba-config.h"
#include "bluealsa-dbus.h"
#include "io.h"
#include "rtp.h"
#include "utils.h"
Expand Down Expand Up @@ -197,6 +198,7 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
const unsigned int ldac_delay_frames = 1024;
/* Get the total delay introduced by the codec. */
t_pcm->codec_delay_dms = ldac_delay_frames * 10000 / rate;
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);

rtp_header_t *rtp_header;
rtp_lhdc_media_header_t *rtp_lhdc_media_header;
Expand Down Expand Up @@ -275,6 +277,13 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
goto fail;
}

if (!io.initiated) {
/* Get the delay due to codec processing. */
t_pcm->processing_delay_dms = asrsync_get_dms_since_last_sync(&io.asrs);
ba_transport_pcm_delay_sync(t_pcm, BA_DBUS_PCM_UPDATE_DELAY);
io.initiated = true;
}

if (errno == EAGAIN)
/* The io_bt_write() call was blocking due to not enough
* space in the BT socket. Set the queued_bytes to some
Expand All @@ -287,14 +296,11 @@ void *a2dp_lhdc_enc_thread(struct ba_transport_pcm *t_pcm) {
}

unsigned int pcm_frames = lhdc_pcm_samples / channels;
/* keep data transfer at a constant bit rate */
/* Keep data transfer at a constant bit rate. */
asrsync_sync(&io.asrs, pcm_frames);
/* move forward RTP timestamp clock */
rtp_state_update(&rtp, pcm_frames);

/* update busy delay (encoding overhead) */
t_pcm->processing_delay_dms = asrsync_get_busy_usec(&io.asrs) / 100;

}

/* If the input buffer was not consumed (due to codesize limit), we
Expand Down
Loading
Loading