Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/rust/fake-tests/layout_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ static const moq5_layout_entry_t entries[] = {
F(moq_media_sender_cfg_t, catalog_refresh_interval_us),
F(moq_media_sender_cfg_t, companion_profile),
F(moq_media_sender_cfg_t, resource_auth),
F(moq_media_sender_cfg_t, initial_group_id),
F(moq_media_sender_cfg_t, has_initial_group_id),
S(moq_media_track_cfg_t), F(moq_media_track_cfg_t, struct_size), F(moq_media_track_cfg_t, name),
F(moq_media_track_cfg_t, media_type), F(moq_media_track_cfg_t, packaging),
F(moq_media_track_cfg_t, codec), F(moq_media_track_cfg_t, timescale),
Expand Down
3 changes: 2 additions & 1 deletion bindings/rust/fake-tests/moq5-fake-tests/tests/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ fn rust_side() -> BTreeMap<String, Entry> {
queue_max_objects, queue_max_bytes, pre_ready_max_objects, pre_ready_max_bytes,
validate_cmaf, content_protections, content_protection_count, callbacks,
publish_tracks, drop_without_demand, catalog_refresh_interval_us, companion_profile,
resource_auth,
resource_auth, initial_group_id,
has_initial_group_id,
}
moq_media_track_cfg_t {
struct_size, name, media_type, packaging, codec, timescale, init_data, role, lang,
Expand Down
9 changes: 8 additions & 1 deletion bindings/rust/moq5-sys/docs/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11197,10 +11197,13 @@ pub struct moq_media_sender_cfg {
pub _reserved_companion_profile: [u8; 4usize],
#[doc = " Optional resource credentials, independent of endpoint SETUP tokens.\n Copied at construction, including all static token bytes. Selectors\n and local outcomes follow media_auth.h. Absent/partial/NULL means\n anonymous; a configured source never falls back to anonymous access.\n Use a sized initializer to enable this complete pointer field."]
pub resource_auth: *const moq_media_auth_cfg_t,
#[doc = " Optional first Group ID of every track of this sender instance (media,\n generated timeline and catalog alike). Honored only when\n has_initial_group_id is true; use a sized initializer to enable this\n appended pair. It replaces the companion's default base: 0 for the\n legacy companion, the wallclock milliseconds read at creation for\n D22_MSF01_LOC04_PUBLIC. An AUTO sender keeps the value whichever\n companion it resolves to.\n\n A publisher that restarts a Track must not reuse the Locations of\n Objects it already published (draft-ietf-moq-transport-22 2.5; MSF-01\n 6.1). An application that remembers the Groups it used before, such as\n one that reconnects after a failed session, sets this to a value above\n them. Values above MOQ_QUIC_VARINT_MAX, the largest Group ID the\n library writes, fail creation with MOQ_ERR_LIMIT. A value of exactly\n MOQ_QUIC_VARINT_MAX is valid; the next group is then refused with\n MOQ_ERR_LIMIT where it is requested."]
pub initial_group_id: u64,
pub has_initial_group_id: bool,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of moq_media_sender_cfg"][::std::mem::size_of::<moq_media_sender_cfg>() - 192usize];
["Size of moq_media_sender_cfg"][::std::mem::size_of::<moq_media_sender_cfg>() - 208usize];
["Alignment of moq_media_sender_cfg"][::std::mem::align_of::<moq_media_sender_cfg>() - 8usize];
["Offset of field: moq_media_sender_cfg::struct_size"]
[::std::mem::offset_of!(moq_media_sender_cfg, struct_size) - 0usize];
Expand Down Expand Up @@ -11242,6 +11245,10 @@ const _: () = {
[::std::mem::offset_of!(moq_media_sender_cfg, _reserved_companion_profile) - 180usize];
["Offset of field: moq_media_sender_cfg::resource_auth"]
[::std::mem::offset_of!(moq_media_sender_cfg, resource_auth) - 184usize];
["Offset of field: moq_media_sender_cfg::initial_group_id"]
[::std::mem::offset_of!(moq_media_sender_cfg, initial_group_id) - 192usize];
["Offset of field: moq_media_sender_cfg::has_initial_group_id"]
[::std::mem::offset_of!(moq_media_sender_cfg, has_initial_group_id) - 200usize];
};
impl Default for moq_media_sender_cfg {
fn default() -> Self {
Expand Down
18 changes: 18 additions & 0 deletions service/include/moq/media_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ typedef struct moq_media_sender_cfg {
* anonymous; a configured source never falls back to anonymous access.
* Use a sized initializer to enable this complete pointer field. */
const moq_media_auth_cfg_t *resource_auth;
/* Optional first Group ID of every track of this sender instance (media,
* generated timeline and catalog alike). Honored only when
* has_initial_group_id is true; use a sized initializer to enable this
* appended pair. It replaces the companion's default base: 0 for the
* legacy companion, the wallclock milliseconds read at creation for
* D22_MSF01_LOC04_PUBLIC. An AUTO sender keeps the value whichever
* companion it resolves to.
*
* A publisher that restarts a Track must not reuse the Locations of
* Objects it already published (draft-ietf-moq-transport-22 2.5; MSF-01
* 6.1). An application that remembers the Groups it used before, such as
* one that reconnects after a failed session, sets this to a value above
* them. Values above MOQ_QUIC_VARINT_MAX, the largest Group ID the
* library writes, fail creation with MOQ_ERR_LIMIT. A value of exactly
* MOQ_QUIC_VARINT_MAX is valid; the next group is then refused with
* MOQ_ERR_LIMIT where it is requested. */
uint64_t initial_group_id;
bool has_initial_group_id;
} moq_media_sender_cfg_t;

/* Plain init leaves backpressure UNSET on purpose -- the choice is forced,
Expand Down
16 changes: 14 additions & 2 deletions service/src/media_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,19 @@ moq_result_t sender_prepare(const moq_media_sender_cfg_t *cfg,
* are numbered from it, and a legacy resolution moves them down by it. */
bool msf01 = sender_cfg_companion(cfg) !=
MOQ_MEDIA_COMPANION_LEGACY_MSF01_LOC01;
rc = sender_resolve_group_base(msf01, &sz->group_base);
if (rc != MOQ_OK) return rc;
if (cfg->struct_size >= offsetof(moq_media_sender_cfg_t, has_initial_group_id) +
sizeof(cfg->has_initial_group_id) &&
cfg->has_initial_group_id) {
/* The application's base replaces the companion's, so the clock is
* not read. A base past the largest Group ID is a limit error before
* any allocation or endpoint effect, as for the clock. */
if (cfg->initial_group_id > MOQ_QUIC_VARINT_MAX) return MOQ_ERR_LIMIT;
sz->group_base = cfg->initial_group_id;
sz->group_base_explicit = true;
} else {
rc = sender_resolve_group_base(msf01, &sz->group_base);
if (rc != MOQ_OK) return rc;
}
sz->alloc = *SENDER_CTOR_ALLOC();
const moq_media_auth_cfg_t *auth = NULL;
if (cfg->struct_size >= offsetof(moq_media_sender_cfg_t, resource_auth) +
Expand Down Expand Up @@ -645,6 +656,7 @@ moq_result_t sender_new(moq_endpoint_t *ep, bool owns,
s->validate_cmaf = cfg->validate_cmaf;
sender_copy_cfg_tail(s, cfg);
s->group_base = sz->group_base;
s->group_base_explicit = sz->group_base_explicit;
s->block_timeout_us = cfg->block_timeout_us
? cfg->block_timeout_us : SENDER_DEFAULT_BLOCK_TIMEOUT_US;
s->queue_cap = sz->queue_cap;
Expand Down
7 changes: 5 additions & 2 deletions service/src/media_sender_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,9 @@ struct moq_media_sender {
resolved and range-checked before
the sender exists (sender_prepare);
an AUTO sender resolving to legacy
resets it to 0 (under mu) */
resets it to 0 (under mu) unless
the application configured it */
bool group_base_explicit; /* cfg->initial_group_id was set */
moq_rcbuf_t *published_catalog; /* last committed catalog bytes (the
independent base / no-op dedup) */
/* MSF §5.1.2 generatedAt of the bytes in published_catalog. Paired with the
Expand Down Expand Up @@ -721,7 +723,8 @@ typedef struct sender_sizes {
size_t ring_bytes;
size_t ns_bytes;
size_t ns_data_size; /* namespace bytes + catalog name bytes */
uint64_t group_base; /* sender_resolve_group_base */
uint64_t group_base; /* sender_resolve_group_base, or the configured one */
bool group_base_explicit; /* cfg->initial_group_id: kept on resolve */
} sender_sizes_t;
#define SENDER_NS_PER_S 1000000000L

Expand Down
6 changes: 4 additions & 2 deletions service/src/media_sender_pump.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ static void sender_resolve_companion_locked(moq_media_sender_t *s)
s->companion_profile = MOQ_MEDIA_COMPANION_D22_MSF01_LOC04_PUBLIC;
} else if (v == MOQ_VERSION_DRAFT_16 || v == MOQ_VERSION_DRAFT_18) {
s->companion_profile = MOQ_MEDIA_COMPANION_LEGACY_MSF01_LOC01;
uint64_t base = s->group_base;
/* A configured initial Group ID is the application's, for either
* companion: nothing moves down by it. */
uint64_t base = s->group_base_explicit ? 0 : s->group_base;
for (size_t i = 0; i < s->track_count; i++) {
moq_media_track_t *t = s->tracks[i];
if (t->group_started) t->group_seq -= base;
Expand All @@ -570,7 +572,7 @@ static void sender_resolve_companion_locked(moq_media_sender_t *s)
sender_preq_entry_t *e = &s->preq[i % s->ring_cap];
if (e->track && e->track->group_started) e->group_seq -= base;
}
s->group_base = 0;
if (!s->group_base_explicit) s->group_base = 0;
}
}
}
Expand Down
135 changes: 131 additions & 4 deletions service/tests/test_sender_companion.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ PIN(sizeof(moq_media_send_object_t) ==
ALIGNOF(old_send_object_t)) * ALIGNOF(old_send_object_t), "full object extent");
PIN(sizeof(old_companion_sender_cfg_t) == sizeof(old_sender_cfg_t) + ALIGNOF(old_sender_cfg_t), "frozen companion cfg extent");
PIN(offsetof(moq_media_sender_cfg_t, resource_auth) >= sizeof(old_companion_sender_cfg_t), "auth never uses old companion padding");
PIN(sizeof(moq_media_sender_cfg_t) ==
PIN(offsetof(moq_media_sender_cfg_t, initial_group_id) >=
((offsetof(moq_media_sender_cfg_t, resource_auth) + sizeof(void *) + ALIGNOF(old_sender_cfg_t) - 1) /
ALIGNOF(old_sender_cfg_t)) * ALIGNOF(old_sender_cfg_t), "initial Group ID never uses the auth padding");
PIN(sizeof(moq_media_sender_cfg_t) ==
((offsetof(moq_media_sender_cfg_t, has_initial_group_id) + sizeof(bool) + ALIGNOF(old_sender_cfg_t) - 1) /
ALIGNOF(old_sender_cfg_t)) * ALIGNOF(old_sender_cfg_t), "full cfg extent");
#if UINTPTR_MAX == UINT64_MAX
PIN(sizeof(old_sender_cfg_t) == 176 && sizeof(old_companion_sender_cfg_t) == 184 && sizeof(moq_media_sender_cfg_t) == 192, "LP64 cfg pin");
PIN(sizeof(old_sender_cfg_t) == 176 && sizeof(old_companion_sender_cfg_t) == 184 && sizeof(moq_media_sender_cfg_t) == 208, "LP64 cfg pin");
PIN(sizeof(old_send_object_t) == 72 && sizeof(moq_media_send_object_t) == 80, "LP64 object pin");
#elif defined(__arm__)
PIN(sizeof(old_sender_cfg_t) == 112 && sizeof(old_companion_sender_cfg_t) == 120 && sizeof(moq_media_sender_cfg_t) == 128, "ARM cfg pin");
PIN(sizeof(old_sender_cfg_t) == 112 && sizeof(old_companion_sender_cfg_t) == 120 && sizeof(moq_media_sender_cfg_t) == 144, "ARM cfg pin");
PIN(sizeof(old_send_object_t) == 56 && sizeof(moq_media_send_object_t) == 64, "ARM object pin");
#elif defined(__i386__)
PIN(sizeof(old_sender_cfg_t) == 104 && sizeof(old_companion_sender_cfg_t) == 108 && sizeof(moq_media_sender_cfg_t) == 116, "i686 cfg pin");
PIN(sizeof(old_sender_cfg_t) == 104 && sizeof(old_companion_sender_cfg_t) == 108 && sizeof(moq_media_sender_cfg_t) == 128, "i686 cfg pin");
PIN(sizeof(old_send_object_t) == (sizeof(moq_sap_type_t) == 1 ? 48 : 52), "i686 old object pin");
PIN(sizeof(moq_media_send_object_t) == (sizeof(moq_sap_type_t) == 1 ? 52 : 56), "i686 full object pin");
#endif
Expand Down Expand Up @@ -820,6 +823,89 @@ static void group_ids(bool d22)
finish(&f);
}

/* cfg->initial_group_id replaces the companion's default base for every track
* and the catalog, on either companion, and the clock is not read for it. A
* struct too short to hold the pair leaves the default in place. */
static void group_ids_configured(unsigned kind)
{
static const char *const names[] = {
"initial-group-id-legacy", "initial-group-id-d22-ignores-clock",
"initial-group-id-short-struct-ignored",
};
label = names[kind]; ++rows;
const bool d22 = kind == 1;
const uint64_t initial = 7000;
moq_media_sender_cfg_t full;
moq_media_sender_cfg_init_live_sized(&full, sizeof(full));
full.namespace_ = (moq_namespace_t){&ns_part, 1};
full.backpressure = MOQ_MEDIA_SEND_BP_RETURN_WOULD_BLOCK;
full.validate_cmaf = false;
full.pre_ready_max_bytes = full.queue_max_bytes = 1024;
full.companion_profile = d22 ? MOQ_MEDIA_COMPANION_D22_MSF01_LOC04_PUBLIC
: MOQ_MEDIA_COMPANION_LEGACY_MSF01_LOC01;
full.initial_group_id = initial;
full.has_initial_group_id = true;
if (kind == 2) full.struct_size = (uint32_t)offsetof(moq_media_sender_cfg_t, has_initial_group_id);
/* The default draft-22 base would need the clock; configured, it is not read. */
g_clock_rc = d22 ? -1 : 0; g_clock_ts = ms_clock(1700000000123ull);
moq_media_sender_test_set_clock_hook(scripted_clock, NULL);
fixture_t f = {0};
bool started = start(&f, (old_sender_cfg_t *)&full,
d22 ? MOQ_VERSION_DRAFT_22 : MOQ_VERSION_DRAFT_18, MOQ_MEDIA_PACKAGING_RAW);
moq_media_sender_test_set_clock_hook(NULL, NULL);
g_clock_rc = 0;
if (!started) { finish(&f); return; }
const uint64_t first = kind == 2 ? 0 : initial;
moq_media_metadata_t m; metadata(&m,false,7,0);
for (unsigned g = 0; g < 2; ++g) {
old_send_object_t *o = object(d22 ? sizeof(void *) : 0, &m);
CHECK(write_object(&f, o) == MOQ_OK);
free(o);
}
if (arm_peer(&f)) {
CHECK(moq_media_sender_test_catalog_group(f.sender) == first);
uint64_t groups[4]; unsigned n = 0;
moq_event_t e;
while (moq_session_poll_events(f.peer, &e, 1)) {
if (e.kind == MOQ_EVENT_OBJECT_RECEIVED && n < 4)
groups[n++] = e.u.object_received.group_id;
moq_event_cleanup(&e);
}
CHECK(n == 2);
if (n == 2) {
CHECK(groups[0] == first);
CHECK(groups[1] == first + 1);
}
}
finish(&f);
}

/* A configured initial Group ID above MOQ_QUIC_VARINT_MAX fails creation
* with MOQ_ERR_LIMIT and leaves nothing allocated; exactly
* MOQ_QUIC_VARINT_MAX is valid. */
static void initial_group_id_limit(bool valid)
{
label = valid ? "initial-group-id-varint-max-valid" : "initial-group-id-past-varint-max"; ++rows;
moq_media_sender_cfg_t full;
moq_media_sender_cfg_init_live_sized(&full, sizeof(full));
full.namespace_ = (moq_namespace_t){&ns_part, 1};
full.backpressure = MOQ_MEDIA_SEND_BP_RETURN_WOULD_BLOCK;
full.validate_cmaf = false;
full.pre_ready_max_bytes = full.queue_max_bytes = 1024;
full.companion_profile = MOQ_MEDIA_COMPANION_LEGACY_MSF01_LOC01;
full.initial_group_id = valid ? MOQ_QUIC_VARINT_MAX : MOQ_QUIC_VARINT_MAX + 1u;
full.has_initial_group_id = true;
allocation_t memory = {0};
moq_alloc_t alloc = {.ctx=&memory,.alloc=allocate,.realloc=resize,.free=release};
moq_media_sender_test_set_alloc(&alloc);
moq_media_sender_t *s = (moq_media_sender_t *)(uintptr_t)1;
CHECK(moq_media_sender_test_construct(&full, &s) == (valid ? MOQ_OK : MOQ_ERR_LIMIT));
if (valid) CHECK(s != NULL); else CHECK(s == NULL);
if (s) moq_media_sender_test_free(s);
moq_media_sender_test_set_alloc(NULL);
CHECK(memory.live == 0);
}

/* The Group ID base is resolved before the sender exists: a clock that
* cannot be read, or reads before the epoch, is MOQ_ERR_INTERNAL; a reading
* past MOQ_QUIC_VARINT_MAX is MOQ_ERR_LIMIT. Nothing is left allocated, and
Expand Down Expand Up @@ -1013,6 +1099,43 @@ static bool observe_session(fixture_t *f, moq_version_t version)
* presentation time alone is media time, sent with Timescale 1000000
* (2.3.1.2). With a tail, the tail is authoritative on draft 22. Drafts 16/18
* keep LOC-01 and ignore the tail. */
/* An AUTO sender keeps a configured initial Group ID when it resolves to the
* legacy companion, which would otherwise move its groups down to 0. */
static void group_ids_configured_auto_legacy(void)
{
label = "initial-group-id-auto-resolves-legacy-keeps-base"; ++rows;
const uint64_t initial = 7000;
moq_media_sender_cfg_t full;
moq_media_sender_cfg_init_live_sized(&full, sizeof(full));
full.namespace_ = (moq_namespace_t){&ns_part, 1};
full.backpressure = MOQ_MEDIA_SEND_BP_RETURN_WOULD_BLOCK;
full.validate_cmaf = false;
full.pre_ready_max_bytes = full.queue_max_bytes = 1024;
full.companion_profile = MOQ_MEDIA_COMPANION_AUTO;
full.initial_group_id = initial;
full.has_initial_group_id = true;
g_clock_rc = 0; g_clock_ts = ms_clock(1700000000123ull);
moq_media_sender_test_set_clock_hook(scripted_clock, NULL);
fixture_t f = {0};
static const uint8_t init[] = {0x01,0x02,0x03};
bool started = start_auto(&f, (old_sender_cfg_t *)&full, 1700000000123ull, MOQ_MEDIA_PACKAGING_RAW,
(moq_bytes_t){init, sizeof(init)});
moq_media_sender_test_set_clock_hook(NULL, NULL);
if (!started) { finish(&f); return; }
moq_media_metadata_t m; metadata(&m,false,7,0);
old_send_object_t *o = object(0, NULL);
/* Written before the draft is known, so numbered from the base, then
* resolved to legacy: the base stays instead of dropping to 0. */
CHECK(write_object(&f, o) == MOQ_OK);
(void)m;
if (observe_session(&f, MOQ_VERSION_DRAFT_18)) {
CHECK(moq_media_sender_test_companion(f.sender) == MOQ_MEDIA_COMPANION_LEGACY_MSF01_LOC01);
CHECK(moq_media_sender_test_catalog_group(f.sender) == initial);
}
free(o);
finish(&f);
}

static void auto_resolution(moq_version_t version, bool before_latch, bool with_metadata,
bool pts_only, uint64_t pts)
{
Expand Down Expand Up @@ -1578,6 +1701,10 @@ int main(void)
group_ids(true);
group_ids(false);
for (unsigned i = 0; i < 7; ++i) group_base_refusal(i);
for (unsigned i = 0; i < 3; ++i) group_ids_configured(i);
group_ids_configured_auto_legacy();
initial_group_id_limit(false);
initial_group_id_limit(true);
group_id_ceiling();
catalog_last_group();
unobserved_and_future_metadata();
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_abi_layout_d22.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,10 @@ PIN_AFTER(moq_media_receiver_stats_t, reorder_refused, tracks_malformed);
PIN_THROUGH(moq_media_sender_cfg_t, companion_profile, 184, 108, 120, 8, 4, 8);
PIN_AFTER(moq_media_sender_cfg_t, companion_profile, resource_auth);
PIN_AT(moq_media_sender_cfg_t, resource_auth, 184, 112, 120);
PIN_SIZE(moq_media_sender_cfg_t, 192, 116, 128);
PIN_AFTER(moq_media_sender_cfg_t, resource_auth, initial_group_id);
PIN_AT(moq_media_sender_cfg_t, initial_group_id, 192, 116, 128);
PIN_AT(moq_media_sender_cfg_t, has_initial_group_id, 200, 124, 136);
PIN_SIZE(moq_media_sender_cfg_t, 208, 128, 144);
/* The media track's Track Properties start exactly at the sizeof of the
* layout that ends at the MPEG2TS block (its enum members change that sizeof
* under short enums, so the pin is relational), never in its tail padding.
Expand Down
Loading