Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
78abc1f
chore(quest): claim quest/m1/api-audit/binding-state.md
kixelated Oct 23, 2026
16da1e7
refactor(bindings): observe native connection state coherently
kixelated Oct 23, 2026
98009ed
fix(bindings): retain terminal observations across immediate cancella…
kixelated Oct 23, 2026
4e0ac35
chore: merge main into binding state proposal
kixelated Oct 23, 2026
688e28d
chore: reconcile binding migrations with current main
kixelated Oct 23, 2026
cfc6bba
Merge remote-tracking branch 'origin/main' into binding-state-iterate
kixelated Oct 23, 2026
fe9bb92
feat: finish C and browser connection state ownership
kixelated Oct 23, 2026
b72a78d
docs(moq-c): name the state callback without a broken link
kixelated Oct 23, 2026
85f5385
test(go): wait for the connect a bandwidth grant needs
kixelated Oct 23, 2026
9f75604
Merge remote-tracking branch 'origin/main' into binding-state-iterate
kixelated Oct 23, 2026
0be0054
fix(moq-c): give the new C ABI lint expectations a reason
kixelated Oct 23, 2026
078c084
Merge remote-tracking branch 'origin/main' into binding-state-iterate-2
kixelated Oct 24, 2026
53b939f
refactor(moq-tokio): keep the lifecycle poll private
kixelated Oct 24, 2026
84ae40e
Merge remote-tracking branch 'origin/main' into binding-state-iterate-2
kixelated Oct 24, 2026
bf52e5b
fix(moq-tokio): end the connection loop in one lifecycle revision
kixelated Oct 24, 2026
821b51f
fix(moq-tokio): skip the Disconnected snapshot when a session ends th…
kixelated Oct 24, 2026
4716ead
Merge remote-tracking branch 'origin/main' into binding-state-iterate-2
kixelated Oct 24, 2026
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
4 changes: 4 additions & 0 deletions cpp/moq/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ How to update your code for each breaking change, newest first.

## Unreleased

### Connection state

`Client::connect` returns a connecting native session. Replace `status()`, `connects()`, and both `failure()` polls with `state()` and `state_changed(state.revision)`. `ConnectionState` carries `phase`, `connects`, `failure`, and `version`; `ConnectionPhase` replaces `ConnectionStatus`.

### Exact encoder rates and publication options

Raw video input framerates are exact numerator/denominator records, not integers.
Expand Down
2 changes: 2 additions & 0 deletions cpp/obs/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ How to update your OBS setup for each breaking change, newest first.

## Unreleased

Connection state and first-dial failures now arrive through one lifecycle watcher. UI reads no longer poll the Client or Session for failure separately.

### Key logging is opt-in (#5907)

`SSLKEYLOGFILE` alone no longer writes TLS session secrets.
Expand Down
153 changes: 33 additions & 120 deletions cpp/obs/src/moq-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@

namespace {

bool LooksGenericOffline(const std::string &reason)
{
if (reason.empty() || reason == "offline")
return true;
// Case-insensitive contains for "offline" only as a whole-ish token.
for (size_t i = 0; i + 6 < reason.size() + 1; i++) {
char buf[8] = {};
for (int j = 0; j < 7 && i + j < reason.size(); j++) {
char c = reason[i + j];
buf[j] = (c >= 'A' && c <= 'Z') ? static_cast<char>(c - 'A' + 'a') : c;
}
if (std::strncmp(buf, "offline", 7) == 0)
return true;
}
return false;
}

// Dial URL scheme only. https races WebTransport vs WebSocket, and the session
// does not report which won, so do not invent a transport name here.
std::string DialSchemeLabel(const std::string &url)
Expand Down Expand Up @@ -240,7 +223,6 @@ bool MoQOutput::Start()
std::lock_guard<std::mutex> lock(mutex);
url = server;
epoch = *route.epoch;
dialing = client;
}
{
std::lock_guard<std::mutex> lock(media_mutex);
Expand Down Expand Up @@ -268,85 +250,61 @@ void MoQOutput::OnConnect(const std::shared_ptr<Attempt> &current, moq::expected
return;
}

auto elapsed = std::chrono::steady_clock::now() - current->started;
auto ms = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
const int connects = static_cast<int>((*result)->connects());

// OBS and older dock paths treat connect_time_ms == 0 as "never connected".
// Clamp sub-millisecond connects to 1 so that sentinel stays honest. Set before
// the session reads as live, so nothing sees a live session that never connected.
connect_time_ms = ms > 0 ? ms : 1;

current->session = *result;
current->connected = true;
current->live = true;
// Before the session reads as live, so the first frame after can reserve.
{
std::lock_guard<std::mutex> lock(media_mutex);
bandwidth = current->session->bandwidth();
}
{
std::lock_guard<std::mutex> lock(mutex);
session = current->session;
dialing.reset();
recv_bandwidth = session->recv_bandwidth();
connected = true;
live = true;
last_failure_code = MoQError::None;
last_failure_reason.clear();
}

LOG_INFO("MoQ session connected (%d ms, connect %d): %s", ms, connects, MoQRedactUrl(current->url).c_str());

WatchStatus(current);
OnState(current, current->session->state());
}

void MoQOutput::WatchStatus(const std::shared_ptr<Attempt> &current)
void MoQOutput::WatchState(const std::shared_ptr<Attempt> &current)
{
// Replacing `pending` from inside its own continuation is fine: that call has
// already completed, so dropping it cancels nothing.
current->pending = current->session->status().then(
worker.Executor(), Current<moq::expected<moq::ConnectionStatus>>(
current, [this](const std::shared_ptr<Attempt> &current, auto result) {
OnStatus(current, std::move(result));
}));
current->pending = current->session->state_changed(current->revision)
.then(worker.Executor(),
Current<moq::expected<moq::ConnectionState>>(
current, [this](const std::shared_ptr<Attempt> &current, auto result) {
OnState(current, std::move(result));
}));
}

void MoQOutput::OnStatus(const std::shared_ptr<Attempt> &current, moq::expected<moq::ConnectionStatus> result)
void MoQOutput::OnState(const std::shared_ptr<Attempt> &current, moq::expected<moq::ConnectionState> result)
{
// The status stream ends in an error once reconnecting gives up for good.
if (!result) {
Fail(current, result.error());
return;
}

switch (*result) {
case moq::ConnectionStatus::kConnected: {
const int connects = static_cast<int>(current->session->connects());
current->live = true;
{
std::lock_guard<std::mutex> lock(mutex);
live = true;
const auto &state = *result;
current->revision = state.revision;
current->live = state.phase == moq::ConnectionPhase::kConnected ||
state.phase == moq::ConnectionPhase::kMigrating;
if (state.connects > 0 && !current->connected) {
auto elapsed = std::chrono::steady_clock::now() - current->started;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
connect_time_ms = ms > 0 ? static_cast<int>(ms) : 1;
current->connected = true;
}
{
std::lock_guard<std::mutex> lock(mutex);
connected = current->connected;
live = current->live;
if (state.failure) {
last_failure_code = FailureCode(*state.failure);
last_failure_reason = state.failure->to_string();
} else if (current->live) {
last_failure_code = MoQError::None;
last_failure_reason.clear();
}
LOG_INFO("MoQ session reconnected (connect %d): %s", connects, MoQRedactUrl(current->url).c_str());
break;
}
case moq::ConnectionStatus::kDisconnected: {
current->live = false;
std::lock_guard<std::mutex> lock(mutex);
live = false;
LOG_WARNING("MoQ session dropped, reconnecting: %s", MoQRedactUrl(current->url).c_str());
break;
}
case moq::ConnectionStatus::kMigrating:
// The old session keeps serving while the replacement dials.
LOG_INFO("MoQ session migrating: %s", MoQRedactUrl(current->url).c_str());
break;
}

WatchStatus(current);
LOG_INFO("MoQ connection state changed (connect %llu): %s", (unsigned long long)state.connects,
MoQRedactUrl(current->url).c_str());
// A second wait at the terminal revision returns its close reason through Fail.
WatchState(current);
}

void MoQOutput::Fail(const std::shared_ptr<Attempt> &current, const moq::Error &error)
Expand All @@ -361,7 +319,6 @@ void MoQOutput::Fail(const std::shared_ptr<Attempt> &current, const moq::Error &
std::lock_guard<std::mutex> lock(mutex);
recv_bandwidth.reset();
session.reset();
dialing.reset();
connected = false;
live = false;
last_failure_code = FailureCode(error);
Expand Down Expand Up @@ -404,7 +361,6 @@ void MoQOutput::Reset()
std::lock_guard<std::mutex> lock(mutex);
recv_bandwidth.reset();
session.reset();
dialing.reset();
connected = false;
live = false;
url.clear();
Expand Down Expand Up @@ -489,7 +445,6 @@ bool MoQOutput::TryGetConnectionStats(ConnectionStats *out)
}

if (!current_live) {
RecordReconnectFailure(current);
return false;
}

Expand Down Expand Up @@ -518,46 +473,6 @@ bool MoQOutput::TryGetConnectionStats(ConnectionStats *out)
return CommitConnectionStats(current, std::move(snapshot), out);
}

void MoQOutput::RecordReconnectFailure(const std::shared_ptr<moq::Session> &current)
{
// Read outside the lock: it calls into moq-ffi.
const auto failure = current->failure();

std::lock_guard<std::mutex> lock(mutex);
// A Stop(), restart, or reconnect while failure() ran made this one stale.
if (session != current || live)
return;
if (failure) {
last_failure_code = FailureCode(*failure);
last_failure_reason = failure->to_string();
} else if (last_failure_reason.empty() || LooksGenericOffline(last_failure_reason)) {
// Nothing named yet. Keep a more specific prior failure over a generic blip.
last_failure_code = MoQError::Offline;
last_failure_reason = "offline";
}
}

void MoQOutput::RecordDialFailure()
{
std::shared_ptr<moq::Client> current;
{
std::lock_guard<std::mutex> lock(mutex);
if (!dialing)
return;
current = dialing;
}

// Read outside the lock: it calls into moq-ffi.
const auto failure = current->failure();

std::lock_guard<std::mutex> lock(mutex);
// A Stop(), restart, or connect while failure() ran made this one stale.
if (dialing != current || !failure)
return;
last_failure_code = FailureCode(*failure);
last_failure_reason = failure->to_string();
}

bool MoQOutput::CommitConnectionStats(const std::shared_ptr<moq::Session> &current, ConnectionStats snapshot,
ConnectionStats *out)
{
Expand All @@ -577,9 +492,8 @@ int MoQOutput::GetReconnectCount()
std::lock_guard<std::mutex> lock(mutex);
current = session;
}
// Read live rather than tracked from status(), which coalesces a drop that
// reconnects before it is asked again.
const uint64_t connects = current ? current->connects() : 0;
// The cumulative count survives a reconnect that finishes between UI reads.
const uint64_t connects = current ? current->state().connects : 0;
return connects > 1 ? static_cast<int>(connects - 1) : 0;
}

Expand All @@ -591,7 +505,6 @@ bool MoQOutput::IsLiveSession()

void MoQOutput::CopyLastFailure(int *code, std::string *reason)
{
RecordDialFailure();

std::lock_guard<std::mutex> lock(mutex);
if (code)
Expand Down
13 changes: 4 additions & 9 deletions cpp/obs/src/moq-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MoQOutput {
};
bool TryGetConnectionStats(ConnectionStats *out);

// Successful (re)connects after the first for this Start(); 0 until connects() >= 2.
// Successful (re)connects after the first for this Start(); 0 until state().connects >= 2.
int GetReconnectCount();

// True while the current Start() attempt has an open MoQ session.
Expand Down Expand Up @@ -88,10 +88,6 @@ class MoQOutput {
friend struct MoQOutputStatsTest;
bool CommitConnectionStats(const std::shared_ptr<moq::Session> &current, ConnectionStats snapshot,
ConnectionStats *out);
// Between reconnects: name why the session is down, for CopyLastFailure.
void RecordReconnectFailure(const std::shared_ptr<moq::Session> &current);
// Before the first connect: name why the dial is retrying, for CopyLastFailure.
void RecordDialFailure();

// One Start()'s connection: the client dialing, the session once it connects,
// and the pending call whose continuation reports on it. Replaced wholesale by
Expand All @@ -104,6 +100,7 @@ class MoQOutput {
std::chrono::steady_clock::time_point started;
// Whether this attempt ever reached the server, which picks between telling
// OBS the connection failed and telling it the stream dropped.
uint64_t revision = 0;
bool connected = false;
// False while the session is between reconnects.
bool live = false;
Expand All @@ -115,8 +112,8 @@ class MoQOutput {
};

void OnConnect(const std::shared_ptr<Attempt> &attempt, moq::expected<std::shared_ptr<moq::Session>> result);
void OnStatus(const std::shared_ptr<Attempt> &attempt, moq::expected<moq::ConnectionStatus> result);
void WatchStatus(const std::shared_ptr<Attempt> &attempt);
void OnState(const std::shared_ptr<Attempt> &attempt, moq::expected<moq::ConnectionState> result);
void WatchState(const std::shared_ptr<Attempt> &attempt);
void Fail(const std::shared_ptr<Attempt> &attempt, const moq::Error &error);

// Runs `callback` on the worker if `attempt` is still the current one once it
Expand Down Expand Up @@ -176,8 +173,6 @@ class MoQOutput {
// Guards the group below, which the dock reads from the UI thread.
std::mutex mutex;
std::shared_ptr<moq::Session> session;
// The client while its first connect is pending, so the dock can ask why it retries.
std::shared_ptr<moq::Client> dialing;
std::shared_ptr<moq::BandwidthConsumer> recv_bandwidth;
bool connected = false;
bool live = false;
Expand Down
Loading
Loading