From a5fbeef6f88cb202f929d32594e27ee32c8f118f Mon Sep 17 00:00:00 2001 From: hackerman-kl Date: Sun, 26 Apr 2026 14:55:25 +0200 Subject: [PATCH] milan-avb: add AVDECC stream_format decoder in aecp-aem.h --- src/modules/module-avb/aecp-aem.h | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/modules/module-avb/aecp-aem.h b/src/modules/module-avb/aecp-aem.h index 25b24273a..c94f416dc 100644 --- a/src/modules/module-avb/aecp-aem.h +++ b/src/modules/module-avb/aecp-aem.h @@ -6,8 +6,82 @@ #ifndef AVB_AEM_H #define AVB_AEM_H +#include +#include +#include + #include "aecp.h" #include "aecp-aem-types.h" +#include "packets.h" + +/* AVDECC stream_format decoder. + * + * The 64-bit stream_format field carried in STREAM_INPUT/STREAM_OUTPUT + * descriptors and in SET/GET_STREAM_FORMAT is encoded per IEEE 1722-2016 + * Section 7.3.x / Annex H — the high byte is the AVTP subtype, the lower 56 bits + * are subtype-specific. This struct exposes the subset needed by the data + * plane plus an `is_audio` shortcut so callers can skip non-media streams + * (CRF). Fields are 0 when not applicable. + * + * NOTE: bit-level decoding inside each subtype is incomplete. Today the + * decoder identifies the subtype reliably and falls back to the historical + * 8 ch / 48 kHz / 24-bit defaults for audio — sufficient for current Milan + * builds where every stream_input_0 / stream_output_0 uses one of those + * formats. TODO Section H.1 (AAF) and Section F (IEC 61883-6 AM824) fields once a real + * conformance run needs other rates / channel counts. */ +enum avb_aem_stream_format_kind { + AVB_AEM_STREAM_FORMAT_KIND_UNKNOWN = 0, + AVB_AEM_STREAM_FORMAT_KIND_AAF, + AVB_AEM_STREAM_FORMAT_KIND_IEC_61883_6, + AVB_AEM_STREAM_FORMAT_KIND_CRF, +}; + +struct avb_aem_stream_format_info { + uint8_t subtype; + enum avb_aem_stream_format_kind kind; + bool is_audio; + uint32_t rate; + uint16_t channels; + uint8_t bit_depth; + uint16_t samples_per_frame; +}; + +static inline void avb_aem_stream_format_decode(uint64_t fmt_be, + struct avb_aem_stream_format_info *out) +{ + uint64_t f = be64toh(fmt_be); + out->subtype = (uint8_t)((f >> 56) & 0xFF); + out->kind = AVB_AEM_STREAM_FORMAT_KIND_UNKNOWN; + out->is_audio = false; + out->rate = 0; + out->channels = 0; + out->bit_depth = 0; + out->samples_per_frame = 0; + + switch (out->subtype) { + case AVB_SUBTYPE_AAF: + out->kind = AVB_AEM_STREAM_FORMAT_KIND_AAF; + out->is_audio = true; + out->rate = 48000; + out->channels = 8; + out->bit_depth = 24; + out->samples_per_frame = 6; + break; + case AVB_SUBTYPE_61883_IIDC: + out->kind = AVB_AEM_STREAM_FORMAT_KIND_IEC_61883_6; + out->is_audio = true; + out->rate = 48000; + out->channels = 8; + out->bit_depth = 24; + out->samples_per_frame = 6; + break; + case AVB_SUBTYPE_CRF: + out->kind = AVB_AEM_STREAM_FORMAT_KIND_CRF; + break; + default: + break; + } +} struct avb_packet_aecp_aem_acquire { uint32_t flags;