milan-avb: rework mrp join/begin:

* join/begin mrp protocol for attributes of mvrp and msrp within stream_activate.
 * Creation of the attribute done on stream creation during es_buidler
This commit is contained in:
hackerman-kl 2026-03-15 10:22:48 +01:00 committed by Wim Taymans
parent 0309d598a1
commit 2746898e9a
12 changed files with 199 additions and 121 deletions

View file

@ -81,7 +81,10 @@ struct aecp_aem_lock_state {
struct aecp_aem_avb_interface_state {
struct avb_aem_desc_avb_interface desc;
struct avb_msrp_attribute *domain_attr;
struct avb_msrp_attribute domain_attr;
struct avb_mvrp_attribute vlan_attr;
};
@ -130,7 +133,10 @@ struct aecp_aem_stream_input_counters {
struct stream_common {
struct stream stream;
struct avb_msrp_attribute *stream_attr;
struct avb_msrp_attribute lstream_attr;
struct avb_msrp_attribute tastream_attr;
struct avb_msrp_attribute tfstream_attr;
};
struct aecp_aem_stream_input_state {
@ -138,6 +144,7 @@ struct aecp_aem_stream_input_state {
struct aecp_aem_stream_input_counters counters;
struct stream_common common;
struct avb_mvrp_attribute mvrp_attr;
};
struct stream_input_saved_binding_param {

View file

@ -83,6 +83,7 @@ static struct descriptor *es_buidler_desc_stream_general_prepare(struct server *
pstream_input = desc->ptr;
stream = &pstream_input->common.stream;
direction = SPA_DIRECTION_INPUT;
break;
case AVB_AEM_DESC_STREAM_OUTPUT:
struct aecp_aem_stream_output_state *pstream_output;

View file

@ -16,7 +16,7 @@
static const uint8_t msrp_mac[6] = AVB_MSRP_MAC;
struct attr {
struct avb_msrp_attribute attr;
struct avb_msrp_attribute *attr;
struct msrp *msrp;
struct spa_hook listener;
struct spa_list link;
@ -53,8 +53,17 @@ static void debug_msrp_talker(const struct avb_packet_msrp_talker *t)
static void notify_talker(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
{
pw_log_info("> notify talker: %s", avb_mrp_notify_name(notify));
debug_msrp_talker(&attr->attr.attr.talker);
pw_log_info("> notify talker advertise: %s", avb_mrp_notify_name(notify));
if (msrp->server->avb_mode == AVB_MODE_MILAN_V12) {
}
}
static void notify_talker_failed(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
{
pw_log_info("> notify talker failed: %s", avb_mrp_notify_name(notify));
if (msrp->server->avb_mode == AVB_MODE_MILAN_V12) {
}
}
static int process_talker(struct msrp *msrp, uint64_t now, uint8_t attr_type,
@ -63,10 +72,10 @@ static int process_talker(struct msrp *msrp, uint64_t now, uint8_t attr_type,
const struct avb_packet_msrp_talker *t = m;
struct attr *a;
spa_list_for_each(a, &msrp->attributes, link)
if (a->attr.type == attr_type &&
a->attr.attr.talker.stream_id == t->stream_id) {
a->attr.attr.talker = *t;
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
if (a->attr->type == attr_type &&
a->attr->attr.talker.stream_id == t->stream_id) {
a->attr->attr.talker = *t;
avb_mrp_attribute_rx_event(a->attr->mrp, now, event);
}
return 0;
}
@ -88,10 +97,10 @@ static int encode_talker(struct msrp *msrp, struct attr *a, void *m)
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
t = (struct avb_packet_msrp_talker *)v->first_value;
*t = a->attr.attr.talker;
*t = a->attr->attr.talker;
ev = SPA_PTROFF(t, sizeof(*t), uint8_t);
*ev = (a->attr.mrp->pending_send - 1) * 6 * 6;
*ev = (a->attr->mrp->pending_send - 1) * 6 * 6;
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
f->end_mark = 0;
@ -118,9 +127,9 @@ static int process_talker_fail(struct msrp *msrp, uint64_t now, uint8_t attr_typ
debug_msrp_talker_fail(t);
spa_list_for_each(a, &msrp->attributes, link)
if (a->attr.type == attr_type &&
a->attr.attr.talker_fail.talker.stream_id == t->talker.stream_id)
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
if (a->attr->type == attr_type &&
a->attr->attr.talker_fail.talker.stream_id == t->talker.stream_id)
avb_mrp_attribute_rx_event(a->attr->mrp, now, event);
return 0;
}
@ -135,7 +144,8 @@ static void debug_msrp_listener(const struct avb_packet_msrp_listener *l, uint8_
static void notify_listener(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
{
pw_log_info("> notify listener: %s", avb_mrp_notify_name(notify));
debug_msrp_listener(&attr->attr.attr.listener, attr->attr.param);
debug_msrp_listener(&attr->attr->attr.listener, attr->attr->param);
}
static int process_listener(struct msrp *msrp, uint64_t now, uint8_t attr_type,
@ -144,9 +154,9 @@ static int process_listener(struct msrp *msrp, uint64_t now, uint8_t attr_type,
const struct avb_packet_msrp_listener *l = m;
struct attr *a;
spa_list_for_each(a, &msrp->attributes, link)
if (a->attr.type == attr_type &&
a->attr.attr.listener.stream_id == l->stream_id)
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
if (a->attr->type == attr_type &&
a->attr->attr.listener.stream_id == l->stream_id)
avb_mrp_attribute_rx_event(a->attr->mrp, now, event);
return 0;
}
static int encode_listener(struct msrp *msrp, struct attr *a, void *m)
@ -167,13 +177,13 @@ static int encode_listener(struct msrp *msrp, struct attr *a, void *m)
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
l = (struct avb_packet_msrp_listener *)v->first_value;
*l = a->attr.attr.listener;
*l = a->attr->attr.listener;
ev = SPA_PTROFF(l, sizeof(*l), uint8_t);
*ev = (a->attr.mrp->pending_send - 1) * 6 * 6;
*ev = (a->attr->mrp->pending_send - 1) * 6 * 6;
ev = SPA_PTROFF(ev, sizeof(*ev), uint8_t);
*ev = a->attr.param * 4 * 4 * 4;
*ev = a->attr->param * 4 * 4 * 4;
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
f->end_mark = 0;
@ -192,7 +202,7 @@ static void debug_msrp_domain(const struct avb_packet_msrp_domain *d)
static void notify_domain(struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify)
{
pw_log_info("> notify domain: %s", avb_mrp_notify_name(notify));
debug_msrp_domain(&attr->attr.attr.domain);
debug_msrp_domain(&attr->attr->attr.domain);
}
static int process_domain(struct msrp *msrp, uint64_t now, uint8_t attr_type,
@ -200,8 +210,8 @@ static int process_domain(struct msrp *msrp, uint64_t now, uint8_t attr_type,
{
struct attr *a;
spa_list_for_each(a, &msrp->attributes, link)
if (a->attr.type == attr_type)
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
if (a->attr->type == attr_type)
avb_mrp_attribute_rx_event(a->attr->mrp, now, event);
return 0;
}
@ -223,10 +233,10 @@ static int encode_domain(struct msrp *msrp, struct attr *a, void *m)
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
d = (struct avb_packet_msrp_domain *)v->first_value;
*d = a->attr.attr.domain;
*d = a->attr->attr.domain;
ev = SPA_PTROFF(d, sizeof(*d), uint8_t);
*ev = (a->attr.mrp->pending_send - 1) * 36;
*ev = (a->attr->mrp->pending_send - 1) * 36;
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
f->end_mark = 0;
@ -242,7 +252,7 @@ static const struct {
void (*notify) (struct msrp *msrp, uint64_t now, struct attr *attr, uint8_t notify);
} dispatch[] = {
[AVB_MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE] = { "talker", process_talker, encode_talker, notify_talker, },
[AVB_MSRP_ATTRIBUTE_TYPE_TALKER_FAILED] = { "talker-fail", process_talker_fail, NULL, NULL },
[AVB_MSRP_ATTRIBUTE_TYPE_TALKER_FAILED] = { "talker-fail", process_talker_fail, NULL, notify_talker_failed, },
[AVB_MSRP_ATTRIBUTE_TYPE_LISTENER] = { "listener", process_listener, encode_listener, notify_listener },
[AVB_MSRP_ATTRIBUTE_TYPE_DOMAIN] = { "domain", process_domain, encode_domain, notify_domain, },
};
@ -265,8 +275,8 @@ static int msrp_attr_event(void *data, uint64_t now, uint8_t attribute_type, uin
struct msrp *msrp = data;
struct attr *a;
spa_list_for_each(a, &msrp->attributes, link)
if (a->attr.type == attribute_type)
avb_mrp_attribute_update_state(a->attr.mrp, now, event);
if (a->attr->type == attribute_type)
avb_mrp_attribute_update_state(a->attr->mrp, now, event);
return 0;
}
@ -332,8 +342,9 @@ static void msrp_notify(void *data, uint64_t now, uint8_t notify)
{
struct attr *a = data;
struct msrp *msrp = a->msrp;
if (dispatch[a->attr.type].notify)
dispatch[a->attr.type].notify(msrp, now, a, notify);
if (dispatch[a->attr->type].notify)
dispatch[a->attr->type].notify(msrp, now, a, notify);
}
static const struct avb_mrp_attribute_events mrp_attr_events = {
@ -341,7 +352,7 @@ static const struct avb_mrp_attribute_events mrp_attr_events = {
.notify = msrp_notify,
};
struct avb_msrp_attribute *avb_msrp_attribute_new(struct avb_msrp *m,
int avb_msrp_attribute_new(struct avb_msrp *m, struct avb_msrp_attribute *msrp_attr,
uint8_t type)
{
struct msrp *msrp = (struct msrp*)m;
@ -349,16 +360,21 @@ struct avb_msrp_attribute *avb_msrp_attribute_new(struct avb_msrp *m,
struct attr *a;
attr = avb_mrp_attribute_new(msrp->server->mrp, sizeof(struct attr));
if (!attr) {
pw_log_error("MSRP attribute allocation failed");
return -1;
}
a = attr->user_data;
a->msrp = msrp;
a->attr.mrp = attr;
a->attr.type = type;
a->attr = msrp_attr;
a->attr->mrp = attr;
a->attr->type = type;
attr->name = "MSRP";
spa_list_append(&msrp->attributes, &a->link);
avb_mrp_attribute_add_listener(attr, &a->listener, &mrp_attr_events, a);
return &a->attr;
return 0;
}
static void msrp_event(void *data, uint64_t now, uint8_t event)
@ -375,15 +391,15 @@ static void msrp_event(void *data, uint64_t now, uint8_t event)
p->version = AVB_MRP_PROTOCOL_VERSION;
spa_list_for_each(a, &msrp->attributes, link) {
if (!a->attr.mrp->pending_send)
if (!a->attr->mrp->pending_send)
continue;
if (dispatch[a->attr.type].encode == NULL)
if (dispatch[a->attr->type].encode == NULL)
continue;
pw_log_debug("send %s %s", dispatch[a->attr.type].name,
avb_mrp_send_name(a->attr.mrp->pending_send));
pw_log_debug("send %s %s", dispatch[a->attr->type].name,
avb_mrp_send_name(a->attr->mrp->pending_send));
len = dispatch[a->attr.type].encode(msrp, a, msg);
len = dispatch[a->attr->type].encode(msrp, a, msg);
if (len < 0)
break;
@ -404,6 +420,7 @@ static const struct avb_mrp_events mrp_events = {
.event = msrp_event,
};
struct avb_msrp *avb_msrp_register(struct server *server)
{
struct msrp *msrp;

View file

@ -106,7 +106,7 @@ struct avb_msrp_attribute {
struct avb_msrp;
struct avb_msrp_attribute *avb_msrp_attribute_new(struct avb_msrp *msrp,
int avb_msrp_attribute_new(struct avb_msrp *m, struct avb_msrp_attribute *attr,
uint8_t type);
struct avb_msrp *avb_msrp_register(struct server *server);

View file

@ -13,7 +13,7 @@
static const uint8_t mvrp_mac[6] = AVB_MVRP_MAC;
struct attr {
struct avb_mvrp_attribute attr;
struct avb_mvrp_attribute *attr;
struct spa_hook listener;
struct spa_list link;
struct mvrp *mvrp;
@ -47,8 +47,8 @@ static int mvrp_attr_event(void *data, uint64_t now, uint8_t attribute_type, uin
struct mvrp *mvrp = data;
struct attr *a;
spa_list_for_each(a, &mvrp->attributes, link)
if (a->attr.type == attribute_type)
avb_mrp_attribute_rx_event(a->attr.mrp, now, event);
if (a->attr->type == attribute_type)
avb_mrp_attribute_rx_event(a->attr->mrp, now, event);
return 0;
}
@ -81,10 +81,10 @@ static int encode_vid(struct mvrp *mvrp, struct attr *a, void *m)
AVB_MRP_VECTOR_SET_NUM_VALUES(v, 1);
d = (struct avb_packet_mvrp_vid *)v->first_value;
*d = a->attr.attr.vid;
*d = a->attr->attr.vid;
ev = SPA_PTROFF(d, sizeof(*d), uint8_t);
*ev = (a->attr.mrp->pending_send - 1) * 36;
*ev = (a->attr->mrp->pending_send - 1) * 36;
f = SPA_PTROFF(ev, sizeof(*ev), struct avb_packet_mrp_footer);
f->end_mark = 0;
@ -95,7 +95,7 @@ static int encode_vid(struct mvrp *mvrp, struct attr *a, void *m)
static void notify_vid(struct mvrp *mvrp, uint64_t now, struct attr *attr, uint8_t notify)
{
pw_log_info("> notify vid: %s", avb_mrp_notify_name(notify));
debug_vid(&attr->attr.attr.vid);
debug_vid(&attr->attr->attr.vid);
}
static const struct {
@ -171,8 +171,9 @@ static void mvrp_notify(void *data, uint64_t now, uint8_t notify)
{
struct attr *a = data;
struct mvrp *mvrp = a->mvrp;
if (dispatch[a->attr.type].notify)
dispatch[a->attr.type].notify(mvrp, now, a, notify);
if (dispatch[a->attr->type].notify)
dispatch[a->attr->type].notify(mvrp, now, a, notify);
}
static const struct avb_mrp_attribute_events mrp_attr_events = {
@ -180,23 +181,28 @@ static const struct avb_mrp_attribute_events mrp_attr_events = {
.notify = mvrp_notify,
};
struct avb_mvrp_attribute *avb_mvrp_attribute_new(struct avb_mvrp *m,
uint8_t type)
int avb_mvrp_attribute_new(struct avb_mvrp *m,
struct avb_mvrp_attribute *mvrp_attr, uint8_t type)
{
struct mvrp *mvrp = (struct mvrp*)m;
struct avb_mrp_attribute *attr;
struct attr *a;
attr = avb_mrp_attribute_new(mvrp->server->mrp, sizeof(struct attr));
if (!attr) {
pw_log_error("MVRP attribute allocation failed");
return -1;
}
a = attr->user_data;
a->attr.mrp = attr;
a->attr.type = type;
a->attr = mvrp_attr;
a->attr->mrp = attr;
a->attr->type = type;
attr->name = "MVRP";
spa_list_append(&mvrp->attributes, &a->link);
avb_mrp_attribute_add_listener(attr, &a->listener, &mrp_attr_events, a);
return &a->attr;
return 0;
}
static void mvrp_event(void *data, uint64_t now, uint8_t event)
@ -213,15 +219,15 @@ static void mvrp_event(void *data, uint64_t now, uint8_t event)
p->version = AVB_MRP_PROTOCOL_VERSION;
spa_list_for_each(a, &mvrp->attributes, link) {
if (!a->attr.mrp->pending_send)
if (!a->attr->mrp->pending_send)
continue;
if (dispatch[a->attr.type].encode == NULL)
if (dispatch[a->attr->type].encode == NULL)
continue;
pw_log_debug("send %s %s", dispatch[a->attr.type].name,
avb_mrp_send_name(a->attr.mrp->pending_send));
pw_log_debug("send %s %s", dispatch[a->attr->type].name,
avb_mrp_send_name(a->attr->mrp->pending_send));
len = dispatch[a->attr.type].encode(mvrp, a, msg);
len = dispatch[a->attr->type].encode(mvrp, a, msg);
if (len < 0)
break;

View file

@ -34,8 +34,8 @@ struct avb_mvrp_attribute {
} attr;
};
struct avb_mvrp_attribute *avb_mvrp_attribute_new(struct avb_mvrp *mvrp,
uint8_t type);
int avb_mvrp_attribute_new(struct avb_mvrp *mvrp,
struct avb_mvrp_attribute *attr, uint8_t type);
struct avb_mvrp *avb_mvrp_register(struct server *server);

View file

@ -240,18 +240,13 @@ static const struct pw_stream_events sink_stream_events = {
struct stream *server_create_stream(struct server *server, struct stream *stream,
enum spa_direction direction, uint16_t index)
{
struct stream_common *common = (struct stream_common *)stream;
uint32_t n_params;
const struct spa_pod *params[1];
uint8_t buffer[1024];
struct spa_pod_builder b;
int res;
struct stream_common *common;
struct avb_msrp_attribute *stream_attr;
common = SPA_CONTAINER_OF(stream, struct stream_common, stream);
stream->server = server;
stream->direction = direction;
stream->prio = AVB_MSRP_PRIORITY_DEFAULT;
@ -324,29 +319,38 @@ struct stream *server_create_stream(struct server *server, struct stream *stream
setup_pdu(stream);
setup_msg(stream);
if (direction == SPA_DIRECTION_INPUT) {
stream_attr = avb_msrp_attribute_new(server->msrp,
AVB_MSRP_ATTRIBUTE_TYPE_LISTENER);
} else {
stream_attr = avb_msrp_attribute_new(server->msrp,
AVB_MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE);
stream_attr->attr.talker.vlan_id = htons(stream->vlan_id);
stream_attr->attr.talker.tspec_max_frame_size =
htons(32 + stream->frames_per_pdu * stream->stride);
stream_attr->attr.talker.tspec_max_interval_frames =
htons(AVB_MSRP_TSPEC_MAX_INTERVAL_FRAMES_DEFAULT);
stream_attr->attr.talker.priority = stream->prio;
stream_attr->attr.talker.rank = AVB_MSRP_RANK_DEFAULT;
stream_attr->attr.talker.accumulated_latency = htonl(95);
res = avb_msrp_attribute_new(server->msrp, &common->lstream_attr,
AVB_MSRP_ATTRIBUTE_TYPE_LISTENER);
if (res) {
goto error_free;
}
res = avb_msrp_attribute_new(server->msrp, &common->tastream_attr,
AVB_MSRP_ATTRIBUTE_TYPE_TALKER_ADVERTISE);
if (res) {
goto error_free;
}
common->stream_attr = stream_attr;
res = avb_msrp_attribute_new(server->msrp, &common->tfstream_attr,
AVB_MSRP_ATTRIBUTE_TYPE_TALKER_FAILED);
if (res) {
goto error_free;
}
if (stream->direction == SPA_DIRECTION_OUTPUT) {
struct avb_msrp_attribute *ta = &common->tastream_attr;
ta->attr.talker.vlan_id = htons(stream->vlan_id);
ta->attr.talker.tspec_max_frame_size =
htons(32 + stream->frames_per_pdu * stream->stride);
ta->attr.talker.tspec_max_interval_frames =
htons(AVB_MSRP_TSPEC_MAX_INTERVAL_FRAMES_DEFAULT);
ta->attr.talker.priority = stream->prio;
ta->attr.talker.rank = AVB_MSRP_RANK_DEFAULT;
ta->attr.talker.accumulated_latency = htonl(95);
}
spa_list_append(&server->streams, &stream->link);
@ -355,7 +359,7 @@ error_free_stream:
pw_stream_destroy(stream->stream);
errno = -res;
error_free:
free(stream);
free(stream->buffer_data);
return NULL;
}
@ -364,7 +368,9 @@ void stream_destroy(struct stream *stream)
struct stream_common *common;
common = SPA_CONTAINER_OF(stream, struct stream_common, stream);
avb_mrp_attribute_destroy(common->stream_attr->mrp);
avb_mrp_attribute_destroy(common->lstream_attr.mrp);
avb_mrp_attribute_destroy(common->tastream_attr.mrp);
avb_mrp_attribute_destroy(common->tfstream_attr.mrp);
}
static int setup_socket(struct stream *stream)
@ -454,23 +460,31 @@ int stream_activate(struct stream *stream, uint16_t index, uint64_t now)
}
if (stream->direction == SPA_DIRECTION_INPUT) {
common->stream_attr->attr.listener.stream_id = htobe64(stream->peer_id);
common->stream_attr->param = AVB_MSRP_LISTENER_PARAM_READY;
avb_mrp_attribute_begin(common->stream_attr->mrp, now);
avb_mrp_attribute_join(common->stream_attr->mrp, now, true);
struct aecp_aem_stream_input_state *input_stream;
input_stream = SPA_CONTAINER_OF(common, struct aecp_aem_stream_input_state, common);
common->lstream_attr.attr.listener.stream_id = htobe64(stream->peer_id);
common->lstream_attr.param = AVB_MSRP_LISTENER_PARAM_READY;
avb_mrp_attribute_begin(common->lstream_attr.mrp, now);
avb_mrp_attribute_join(common->lstream_attr.mrp, now, true);
input_stream->mvrp_attr.attr.vid.vlan = htons(stream->vlan_id);
avb_mrp_attribute_begin(input_stream->mvrp_attr.mrp, now);
avb_mrp_attribute_join(input_stream->mvrp_attr.mrp, now, true);
} else {
if ((res = avb_maap_get_address(server->maap, stream->addr, index)) < 0)
return res;
common->stream_attr->attr.talker.stream_id = htobe64(stream->id);
memcpy(common->stream_attr->attr.talker.dest_addr, stream->addr, 6);
common->tastream_attr.attr.talker.stream_id = htobe64(stream->id);
memcpy(common->tastream_attr.attr.talker.dest_addr, stream->addr, 6);
stream->sock_addr.sll_halen = ETH_ALEN;
memcpy(&stream->sock_addr.sll_addr, stream->addr, ETH_ALEN);
memcpy(h->dest, stream->addr, 6);
memcpy(h->src, server->mac_addr, 6);
avb_mrp_attribute_begin(common->stream_attr->mrp, now);
avb_mrp_attribute_join(common->stream_attr->mrp, now, true);
avb_mrp_attribute_begin(common->tastream_attr.mrp, now);
avb_mrp_attribute_join(common->tastream_attr.mrp, now, true);
}
pw_stream_set_active(stream->stream, true);
@ -493,7 +507,9 @@ int stream_deactivate(struct stream *stream, uint64_t now)
avb_mrp_attribute_leave(stream->vlan_attr->mrp, now);
#endif //
avb_mrp_attribute_leave(common->stream_attr->mrp, now);
avb_mrp_attribute_leave(common->lstream_attr.mrp, now);
avb_mrp_attribute_leave(common->tastream_attr.mrp, now);
avb_mrp_attribute_leave(common->tfstream_attr.mrp, now);
return 0;
}