media-sink: Fix sequence number sync for ASHA

The two sides of a ASHA pair rarely if ever start together and the
sequence number was always a bit off due to the stateful nature of
reset_buffer and ASHA needing the sequence number to be matched to
the other side.

Simplify this by setting the sequence number for ASHA just before
flushing.
This commit is contained in:
Sanchayan Maity 2025-05-06 16:11:19 +05:30 committed by Wim Taymans
parent a419f69bbb
commit e68111b4aa
2 changed files with 5 additions and 12 deletions

View file

@ -18,7 +18,6 @@ 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)
@ -45,11 +44,6 @@ 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)
{
struct impl *this = data;
/* Payload for ASHA must be preceded by 1-byte sequence number */
this->seqnum = seqnum % 256;
return 0;
}
@ -137,7 +131,8 @@ static int codec_encode(void *data,
src_sz = (src_size > this->codesize) ? this->codesize : src_size;
*dest = this->seqnum;
/* Sequence number will be set in media-sink before flushing */
*dest = 0;
dest++;
ret = g722_encode(&this->encode, dest, src, src_sz / 2 /* S16LE */);

View file

@ -1339,7 +1339,6 @@ static void media_asha_flush_timeout(struct spa_source *source)
struct timespec ts;
int res, written;
uint64_t exp, now;
uint8_t seqnum;
if (this->started) {
if ((res = spa_system_timerfd_read(this->data_system, asha->timerfd, &exp)) < 0) {
@ -1366,7 +1365,7 @@ static void media_asha_flush_timeout(struct spa_source *source)
}
if (asha->flush_pending) {
seqnum = asha->buf[0];
asha->buf[0] = this->seqnum;
written = send(asha->flush_source.fd, asha->buf,
ASHA_ENCODED_PKT_SZ, MSG_DONTWAIT | MSG_NOSIGNAL);
/*
@ -1386,14 +1385,14 @@ static void media_asha_flush_timeout(struct spa_source *source)
spa_loop_update_source(this->data_loop, &asha->flush_source);
spa_log_warn(this->log, "%p: ASHA failed to flush %d seqnum on timer for %s, written:%d",
this, seqnum, address, -errno);
this, this->seqnum, address, -errno);
goto skip_flush;
}
if (written > 0) {
asha->flush_pending = false;
spa_log_trace(this->log, "%p: ASHA flush %d seqnum for %s, ts:%u",
this, seqnum, address, this->timestamp);
this, this->seqnum, address, this->timestamp);
}
}
@ -2279,7 +2278,6 @@ static int impl_node_process(void *object)
if (other && other->asha->ref_t0 != 0) {
this->asha->ref_t0 = other->asha->ref_t0;
this->seqnum = asha_seqnum(this);
reset_buffer(this);
set_asha_timer(this, other);
} else {
this->asha->ref_t0 = get_reference_time(this, NULL);