bluetooth: Change A2DP codec API of reset() method to indicate failure

SBC codec reset() method may fail, so propagate this failure to caller.
This commit is contained in:
Pali Rohár 2019-07-21 17:07:01 +02:00 committed by Tanu Kaskinen
parent 018b38ec39
commit 064277b4ee
3 changed files with 18 additions and 10 deletions

View file

@ -69,8 +69,9 @@ typedef struct pa_a2dp_codec {
void *(*init)(bool for_encoding, bool for_backchannel, const uint8_t *config_buffer, uint8_t config_size, pa_sample_spec *sample_spec); void *(*init)(bool for_encoding, bool for_backchannel, const uint8_t *config_buffer, uint8_t config_size, pa_sample_spec *sample_spec);
/* Deinitialize and release codec info data in codec_info */ /* Deinitialize and release codec info data in codec_info */
void (*deinit)(void *codec_info); void (*deinit)(void *codec_info);
/* Reset internal state of codec info data in codec_info */ /* Reset internal state of codec info data in codec_info, returns
void (*reset)(void *codec_info); * a negative value on failure */
int (*reset)(void *codec_info);
/* Get read block size for codec, it is minimal size of buffer /* Get read block size for codec, it is minimal size of buffer
* needed to decode read_link_mtu bytes of encoded data */ * needed to decode read_link_mtu bytes of encoded data */

View file

@ -466,20 +466,21 @@ static void set_bitpool(struct sbc_info *sbc_info, uint8_t bitpool) {
pa_log_debug("Bitpool has changed to %u", sbc_info->sbc.bitpool); pa_log_debug("Bitpool has changed to %u", sbc_info->sbc.bitpool);
} }
static void reset(void *codec_info) { static int reset(void *codec_info) {
struct sbc_info *sbc_info = (struct sbc_info *) codec_info; struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
int ret; int ret;
ret = sbc_reinit(&sbc_info->sbc, 0); ret = sbc_reinit(&sbc_info->sbc, 0);
if (ret != 0) { if (ret != 0) {
pa_log_error("SBC reinitialization failed: %d", ret); pa_log_error("SBC reinitialization failed: %d", ret);
return; return -1;
} }
/* sbc_reinit() sets also default parameters, so reset them back */ /* sbc_reinit() sets also default parameters, so reset them back */
set_params(sbc_info); set_params(sbc_info);
sbc_info->seq_num = 0; sbc_info->seq_num = 0;
return 0;
} }
static size_t get_block_size(void *codec_info, size_t link_mtu) { static size_t get_block_size(void *codec_info, size_t link_mtu) {

View file

@ -769,7 +769,7 @@ static void transport_config_mtu(struct userdata *u) {
} }
/* Run from I/O thread */ /* Run from I/O thread */
static void setup_stream(struct userdata *u) { static int setup_stream(struct userdata *u) {
struct pollfd *pollfd; struct pollfd *pollfd;
int one; int one;
@ -777,16 +777,18 @@ static void setup_stream(struct userdata *u) {
/* return if stream is already set up */ /* return if stream is already set up */
if (u->stream_setup_done) if (u->stream_setup_done)
return; return 0;
pa_log_info("Transport %s resuming", u->transport->path); pa_log_info("Transport %s resuming", u->transport->path);
if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK) { if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK) {
pa_assert(u->a2dp_codec); pa_assert(u->a2dp_codec);
u->a2dp_codec->reset(u->encoder_info); if (u->a2dp_codec->reset(u->encoder_info) < 0)
return -1;
} else if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SOURCE) { } else if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SOURCE) {
pa_assert(u->a2dp_codec); pa_assert(u->a2dp_codec);
u->a2dp_codec->reset(u->decoder_info); if (u->a2dp_codec->reset(u->decoder_info) < 0)
return -1;
} }
transport_config_mtu(u); transport_config_mtu(u);
@ -811,6 +813,8 @@ static void setup_stream(struct userdata *u) {
if (u->source) if (u->source)
u->read_smoother = pa_smoother_new(PA_USEC_PER_SEC, 2*PA_USEC_PER_SEC, true, true, 10, pa_rtclock_now(), true); u->read_smoother = pa_smoother_new(PA_USEC_PER_SEC, 2*PA_USEC_PER_SEC, true, true, 10, pa_rtclock_now(), true);
return 0;
} }
/* Called from I/O thread, returns true if the transport was acquired or /* Called from I/O thread, returns true if the transport was acquired or
@ -822,8 +826,10 @@ static bool setup_transport_and_stream(struct userdata *u) {
if (transport_error < 0) { if (transport_error < 0) {
if (transport_error != -EAGAIN) if (transport_error != -EAGAIN)
return false; return false;
} else } else {
setup_stream(u); if (setup_stream(u) < 0)
return false;
}
return true; return true;
} }