Skip to content

Commit 07ecdce

Browse files
mondainclaude
andcommitted
Record published-object stats for non-live publish modes
Publisher::stats() returned zeros for objects/groups/bytes whenever the publish path went through the batch/file flow (publish, publish_file, publish_stream) because record_published_object() was only invoked from publish_live. Other paths funnel through serve_subscriptions / forward_published_tracks, which are free functions and had no access to the MoqtSession's stats. Pass a PublishedObjectSink std::function through those helpers; the MoqtSession callers bind it to record_published_object so every served object — whether emitted from the live loop or the batch loop — contributes to publish_stats_, and stats() reflects work-in-progress for all four publish APIs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 957d5cd commit 07ecdce

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

docs/publisher-api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ thread. Because there is no built-in polling loop, stats are exposed as a
217217
structured summary of the current or most recent publish operation rather than
218218
as a live telemetry stream.
219219

220+
`stats()` is safe to call from a separate thread while a `publish*` call is
221+
blocked; the counters update as objects are served. This is the supported
222+
way for a GUI front-end to drive a "stats pane" — poll on a timer (e.g. once
223+
per second) on the UI thread while the publish runs on a worker. The counters
224+
are updated for every publish mode (`publish`, `publish_file`,
225+
`publish_stream`, `publish_live`); earlier revisions only updated them for
226+
`publish_live`, which made `stats()` appear to be unimplemented for batch
227+
publishing.
228+
220229
```cpp
221230
const auto stats = publisher.stats();
222231
std::cout << "bytes=" << stats.bytes_published

src/transport/moqt_session.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,10 @@ TransportStatus publish_selected_tracks(PublisherTransport& transport,
13471347
std::map<std::uint64_t, std::uint64_t>* request_id_by_track_alias,
13481348
std::uint64_t first_request_id = 2);
13491349

1350+
using PublishedObjectSink = std::function<void(const std::string&, std::uint64_t, std::size_t)>;
1351+
13501352
TransportStatus serve_subscriptions(PublisherTransport& transport,
1353+
PublishedObjectSink published_sink,
13511354
std::uint64_t control_stream_id,
13521355
const openmoq::publisher::PublishPlan& plan,
13531356
const LoopState& loop_state,
@@ -1872,6 +1875,14 @@ TransportStatus serve_subscriptions(PublisherTransport& transport,
18721875
if (!write_status.ok) {
18731876
return write_status;
18741877
}
1878+
// Record stats for the batch/file path too. Without this,
1879+
// Publisher::stats() returns zeros for everything except
1880+
// publish_live, even though objects are flowing.
1881+
if (published_sink) {
1882+
published_sink(object.track_name,
1883+
object.group_id,
1884+
object_payload_size(source_object));
1885+
}
18751886
std::cerr << "[moqt-session] served object send_seq=" << send_seq
18761887
<< " now_ms=" << trace_elapsed_ms(std::chrono::steady_clock::now())
18771888
<< " track=" << object.track_name
@@ -1964,6 +1975,7 @@ TransportStatus serve_subscriptions(PublisherTransport& transport,
19641975
}
19651976

19661977
TransportStatus forward_published_tracks(PublisherTransport& transport,
1978+
PublishedObjectSink published_sink,
19671979
std::uint64_t control_stream_id,
19681980
const openmoq::publisher::PublishPlan& plan,
19691981
const LoopState& loop_state,
@@ -2139,6 +2151,7 @@ TransportStatus forward_published_tracks(PublisherTransport& transport,
21392151
std::cerr << "[moqt-session] waiting for downstream SUBSCRIBE on "
21402152
<< downgraded_tracks_by_name.size() << " track(s) after forward=0 reply" << '\n';
21412153
status = serve_subscriptions(transport,
2154+
published_sink,
21422155
control_stream_id,
21432156
plan,
21442157
loop_state,
@@ -2498,9 +2511,14 @@ TransportStatus MoqtSession::publish(const openmoq::publisher::PublishPlan& plan
24982511
tracks_by_name.emplace(track.name, track);
24992512
}
25002513

2514+
auto stats_sink = [this](const std::string& track, std::uint64_t group, std::size_t bytes) {
2515+
this->record_published_object(track, group, bytes);
2516+
};
2517+
25012518
if (auto_forward_) {
25022519
return forward_published_tracks(
25032520
transport_,
2521+
stats_sink,
25042522
control_stream_id_,
25052523
plan,
25062524
loop_state,
@@ -2540,6 +2558,7 @@ TransportStatus MoqtSession::publish(const openmoq::publisher::PublishPlan& plan
25402558
}
25412559

25422560
return serve_subscriptions(transport_,
2561+
stats_sink,
25432562
control_stream_id_,
25442563
plan,
25452564
loop_state,
@@ -2564,6 +2583,7 @@ TransportStatus MoqtSession::publish(const openmoq::publisher::PublishPlan& plan
25642583
std::cerr << '\n';
25652584

25662585
return serve_subscriptions(transport_,
2586+
stats_sink,
25672587
control_stream_id_,
25682588
plan,
25692589
loop_state,

0 commit comments

Comments
 (0)