Skip to content

Commit 9454b2c

Browse files
committed
Clarify publisher stats API
1 parent fe6ba73 commit 9454b2c

5 files changed

Lines changed: 70 additions & 9 deletions

File tree

docs/publisher-api.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,36 @@ For service-style integration:
209209
5. For continuous input, run `publish_live(...)` in a worker thread.
210210
6. Use `TransportStatus` messages for metrics and retry decisions.
211211

212-
## 11. Runtime Stats (`stats_json`)
212+
## 11. Publish Summary (`stats`)
213213

214-
You can query publisher runtime state at any time:
214+
The publisher API is blocking: `publish(...)`, `publish_file(...)`,
215+
`publish_stream(...)`, and `publish_live(...)` run the session on the calling
216+
thread. Because there is no built-in polling loop, stats are exposed as a
217+
structured summary of the current or most recent publish operation rather than
218+
as a live telemetry stream.
215219

216220
```cpp
217-
const std::string stats = publisher.stats_json();
218-
std::cout << stats << "\n";
221+
const auto stats = publisher.stats();
222+
std::cout << "bytes=" << stats.bytes_published
223+
<< " objects=" << stats.objects_published
224+
<< " groups=" << stats.groups_published << "\n";
219225
```
220226

221-
Current JSON fields:
227+
Current fields:
222228

223-
- `active`: whether a session is currently active
224-
- `connected`: whether transport is currently connected
225229
- `publishingLive`: whether the active session is live-publish mode
226230
- `bytesPublished`: total payload bytes published in the current/last session
227231
- `objectsPublished`: total objects published in the current/last session
228232
- `groupsPublished`: total (track, group) units published in the current/last session
229233
- `splitCmafChunks`: current packaging mode (`true` = split chunks, `false` = coalesced chunks)
230234
- `includeSap`: whether SAP track/object packaging is enabled
235+
- `transport`, `host`, `port`, `path`: endpoint context for the current/last session
236+
- `connectionId`: last known transport connection ID
237+
- `lastError`: last publisher-level error, if any
238+
239+
`stats_json()` remains available for existing integrations, but it is deprecated
240+
because a JSON polling API implies runtime telemetry support that the blocking
241+
publisher API does not provide.
231242
- `transport`: `"raw_quic"` or `"webtransport"`
232243
- `host`: configured endpoint host
233244
- `port`: configured endpoint port

examples/psychedelic/Psychedelic.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ int main(int argc, char** argv) {
221221
throw std::runtime_error("disconnect failed: " + disconnect_status.message);
222222
}
223223

224+
const auto stats = publisher.stats();
224225
std::cout << "[psychedelic] done (single namespace, separate A/V tracks)\n";
225-
std::cout << "[psychedelic] stats: " << publisher.stats_json() << '\n';
226+
std::cout << "[psychedelic] published bytes=" << stats.bytes_published
227+
<< " objects=" << stats.objects_published
228+
<< " groups=" << stats.groups_published << '\n';
226229
return 0;
227230
} catch (const std::exception& error) {
228231
std::cerr << "error: " << error.what() << '\n';

examples/psychedelic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It now:
99
- publishes via one `Publisher::publish_live(...)` session
1010
- uses one namespace containing separate video/audio tracks
1111
- performs explicit graceful teardown with `disconnect(0)`
12-
- prints `stats_json()`
12+
- prints the structured post-publish `Publisher::stats()` summary
1313

1414
## Prerequisites
1515

include/openmoq/publisher/publisher_api.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ struct PreparedPublish {
3535
PublishPlan plan;
3636
};
3737

38+
struct PublisherStats {
39+
bool publishing_live = false;
40+
std::uint64_t bytes_published = 0;
41+
std::uint64_t objects_published = 0;
42+
std::uint64_t groups_published = 0;
43+
bool split_cmaf_chunks = true;
44+
bool include_sap = false;
45+
transport::TransportKind transport = transport::TransportKind::kRawQuic;
46+
std::string host;
47+
std::uint16_t port = 0;
48+
std::string path;
49+
std::string connection_id;
50+
std::string last_error;
51+
};
52+
3853
class Publisher {
3954
public:
4055
using TransportFactory = std::function<std::unique_ptr<transport::PublisherTransport>(transport::TransportKind)>;
@@ -68,6 +83,8 @@ class Publisher {
6883
const transport::TlsConfig& tls = {},
6984
bool endpoint_alpn_overridden = false) const;
7085
transport::TransportStatus disconnect(std::uint64_t application_error_code = 0) const;
86+
PublisherStats stats() const;
87+
[[deprecated("Use stats(); live polling is not supported by the blocking publish API.")]]
7188
std::string stats_json() const;
7289

7390
private:

src/publisher_api.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,36 @@ transport::TransportStatus Publisher::disconnect(std::uint64_t application_error
261261
return status;
262262
}
263263

264+
PublisherStats Publisher::stats() const {
265+
StatsSnapshot snapshot;
266+
bool split_cmaf_chunks = true;
267+
bool include_sap = false;
268+
{
269+
std::lock_guard<std::mutex> lock(state_mutex_);
270+
snapshot = stats_;
271+
split_cmaf_chunks = config_.split_cmaf_chunks;
272+
include_sap = config_.include_sap;
273+
if (active_session_ && active_session_->transport) {
274+
snapshot.connection_id = active_session_->transport->connection_id();
275+
}
276+
}
277+
278+
return PublisherStats{
279+
.publishing_live = snapshot.publishing_live,
280+
.bytes_published = snapshot.bytes_published,
281+
.objects_published = snapshot.objects_published,
282+
.groups_published = snapshot.groups_published,
283+
.split_cmaf_chunks = split_cmaf_chunks,
284+
.include_sap = include_sap,
285+
.transport = snapshot.transport,
286+
.host = snapshot.host,
287+
.port = snapshot.port,
288+
.path = snapshot.path,
289+
.connection_id = snapshot.connection_id,
290+
.last_error = snapshot.last_error,
291+
};
292+
}
293+
264294
std::string Publisher::stats_json() const {
265295
StatsSnapshot snapshot;
266296
bool split_cmaf_chunks = true;

0 commit comments

Comments
 (0)