From 69b5fe839553394965c347da641c08e9f206cd39 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 3 Mar 2025 11:48:27 +0530 Subject: [PATCH] bluez5: g722: Do not set sequence number in start_encode In ASHA, we might need to sync sequence numbers between left and right side media sink. If the sequence number is added in start encode, it becomes difficult to set the sequence number again when a call to reset_buffer in media sink might have happened already. This effectively reverts commit ab5f81b9a. --- spa/plugins/bluez5/asha-codec-g722.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spa/plugins/bluez5/asha-codec-g722.c b/spa/plugins/bluez5/asha-codec-g722.c index 1043b4fe8..3e2ec699a 100644 --- a/spa/plugins/bluez5/asha-codec-g722.c +++ b/spa/plugins/bluez5/asha-codec-g722.c @@ -18,6 +18,7 @@ static struct spa_log *spalog; struct impl { g722_encode_state_t encode; unsigned int codesize; + uint8_t seqnum; }; static int codec_reduce_bitpool(void *data) @@ -44,10 +45,12 @@ static int codec_get_block_size(void *data) static int codec_start_encode (void *data, void *dst, size_t dst_size, uint16_t seqnum, uint32_t timestamp) { - /* Payload for ASHA must be preceded by 1-byte sequence number */ - *(uint8_t *)dst = seqnum % 256; + struct impl *this = data; - return 1; + /* Payload for ASHA must be preceded by 1-byte sequence number */ + this->seqnum = seqnum % 256; + + return 0; } static int codec_enum_config(const struct media_codec *codec, uint32_t flags, @@ -118,6 +121,7 @@ static int codec_encode(void *data, size_t *dst_out, int *need_flush) { struct impl *this = data; + uint8_t *dest = (uint8_t *)dst; size_t src_sz; int ret; @@ -133,13 +137,16 @@ static int codec_encode(void *data, src_sz = (src_size > this->codesize) ? this->codesize : src_size; - ret = g722_encode(&this->encode, dst, src, src_sz / 2 /* S16LE */); + *dest = this->seqnum; + dest++; + + ret = g722_encode(&this->encode, dest, src, src_sz / 2 /* S16LE */); if (ret < 0) { spa_log_error(spalog, "encode error: %d", ret); return -EIO; } - *dst_out = ret; + *dst_out = ret + ASHA_HEADER_SZ; *need_flush = NEED_FLUSH_ALL; return src_sz;