milan-avb: streams: seperate legacy-avb and milan-avb

This commit is contained in:
hackerman-kl 2026-04-24 17:29:00 +02:00 committed by Wim Taymans
parent 6cb03f8e04
commit 5bc1eafd3e

View file

@ -85,7 +85,7 @@ set_iovec(struct spa_ringbuffer *rbuf, void *buffer, uint32_t size,
iov[1].iov_base = buffer;
}
static int flush_write(struct stream *stream, uint64_t current_time)
static int flush_write_milan_v12(struct stream *stream, uint64_t current_time)
{
int32_t avail;
uint32_t index;
@ -93,7 +93,7 @@ static int flush_write(struct stream *stream, uint64_t current_time)
int pdu_count;
ssize_t n;
struct avb_frame_header *h = (void*)stream->pdu;
bool is_milan = stream->server->avb_mode == AVB_MODE_MILAN_V12;
struct avb_packet_aaf *p = SPA_PTROFF(h, sizeof(*h), void);
avail = spa_ringbuffer_get_read_index(&stream->ring, &index);
@ -102,9 +102,6 @@ static int flush_write(struct stream *stream, uint64_t current_time)
txtime = current_time + stream->t_uncertainty;
ptime = txtime + stream->mtt;
if (is_milan) {
struct avb_packet_aaf *p = SPA_PTROFF(h, sizeof(*h), void);
while (pdu_count--) {
*(uint64_t*)CMSG_DATA(stream->cmsg) = txtime;
@ -127,10 +124,29 @@ static int flush_write(struct stream *stream, uint64_t current_time)
ptime += stream->pdu_period;
index += stream->payload_size;
}
} else {
spa_ringbuffer_read_update(&stream->ring, index);
return 0;
}
static int flush_write_legacy(struct stream *stream, uint64_t current_time)
{
int32_t avail;
uint32_t index;
uint64_t ptime, txtime;
int pdu_count;
ssize_t n;
struct avb_frame_header *h = (void*)stream->pdu;
struct avb_packet_iec61883 *p = SPA_PTROFF(h, sizeof(*h), void);
uint8_t dbc = stream->dbc;
avail = spa_ringbuffer_get_read_index(&stream->ring, &index);
pdu_count = (avail / stream->stride) / stream->frames_per_pdu;
txtime = current_time + stream->t_uncertainty;
ptime = txtime + stream->mtt;
while (pdu_count--) {
*(uint64_t*)CMSG_DATA(stream->cmsg) = txtime;
@ -156,7 +172,6 @@ static int flush_write(struct stream *stream, uint64_t current_time)
dbc += stream->frames_per_pdu;
}
stream->dbc = dbc;
}
spa_ringbuffer_read_update(&stream->ring, index);
return 0;
@ -198,23 +213,23 @@ static void on_sink_stream_process(void *data)
pw_stream_queue_buffer(stream->stream, buf);
clock_gettime(CLOCK_TAI, &now);
flush_write(stream, SPA_TIMESPEC_TO_NSEC(&now));
if (stream->server->avb_mode == AVB_MODE_MILAN_V12)
flush_write_milan_v12(stream, SPA_TIMESPEC_TO_NSEC(&now));
else
flush_write_legacy(stream, SPA_TIMESPEC_TO_NSEC(&now));
}
static void setup_pdu(struct stream *stream)
static void setup_pdu_milan_v12(struct stream *stream)
{
struct avb_frame_header *h;
struct avb_packet_aaf *p;
ssize_t payload_size, hdr_size, pdu_size;
bool is_milan = stream->server->avb_mode == AVB_MODE_MILAN_V12;
spa_memzero(stream->pdu, sizeof(stream->pdu));
h = (struct avb_frame_header*)stream->pdu;
p = SPA_PTROFF(h, sizeof(*h), void);
payload_size = stream->stride * stream->frames_per_pdu;
if (is_milan) {
struct avb_packet_aaf *p = SPA_PTROFF(h, sizeof(*h), void);
hdr_size = sizeof(*h) + sizeof(*p);
pdu_size = hdr_size + payload_size;
@ -235,9 +250,23 @@ static void setup_pdu(struct stream *stream)
p->seq_num = 0;
p->data_len = htons(payload_size);
}
} else {
struct avb_packet_iec61883 *p = SPA_PTROFF(h, sizeof(*h), void);
stream->hdr_size = hdr_size;
stream->payload_size = payload_size;
stream->pdu_size = pdu_size;
}
static void setup_pdu_legacy(struct stream *stream)
{
struct avb_frame_header *h;
struct avb_packet_iec61883 *p;
ssize_t payload_size, hdr_size, pdu_size;
spa_memzero(stream->pdu, sizeof(stream->pdu));
h = (struct avb_frame_header*)stream->pdu;
p = SPA_PTROFF(h, sizeof(*h), void);
payload_size = stream->stride * stream->frames_per_pdu;
hdr_size = sizeof(*h) + sizeof(*p);
pdu_size = hdr_size + payload_size;
@ -260,7 +289,6 @@ static void setup_pdu(struct stream *stream)
p->fdf = 0x2;
p->syt = htons(0x0008);
}
}
stream->hdr_size = hdr_size;
stream->payload_size = payload_size;
@ -373,7 +401,10 @@ struct stream *server_create_stream(struct server *server, struct stream *stream
stream->pdu_period = SPA_NSEC_PER_SEC * stream->frames_per_pdu /
stream->info.info.raw.rate;
setup_pdu(stream);
if (server->avb_mode == AVB_MODE_MILAN_V12)
setup_pdu_milan_v12(stream);
else
setup_pdu_legacy(stream);
setup_msg(stream);
res = avb_msrp_attribute_new(server->msrp, &common->lstream_attr,
@ -398,10 +429,12 @@ struct stream *server_create_stream(struct server *server, struct stream *stream
}
common->tastream_attr.attr.talker.vlan_id = htons(stream->vlan_id);
if (server->avb_mode == AVB_MODE_MILAN_V12)
common->tastream_attr.attr.talker.tspec_max_frame_size =
htons(stream->server->avb_mode == AVB_MODE_MILAN_V12
? (uint16_t)stream->pdu_size
: (uint16_t)(32 + stream->frames_per_pdu * stream->stride));
htons((uint16_t)stream->pdu_size);
else
common->tastream_attr.attr.talker.tspec_max_frame_size =
htons((uint16_t)(32 + stream->frames_per_pdu * stream->stride));
common->tastream_attr.attr.talker.tspec_max_interval_frames =
htons(AVB_MSRP_TSPEC_MAX_INTERVAL_FRAMES_DEFAULT);
common->tastream_attr.attr.talker.priority = stream->prio;