Skip to content
Open
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
17 changes: 16 additions & 1 deletion src/moq-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "moq-output.h"
#include "util/util_uint64.h"
#include "util/threading.h"

extern "C" {
#include "moq.h"
Expand All @@ -15,7 +16,8 @@ MoQOutput::MoQOutput(obs_data_t *, obs_output_t *output)
connect_time_ms(0),
origin(moq_origin_create()),
session(0),
broadcast(moq_publish_create())
broadcast(moq_publish_create()),
reconnecting(false)
{
}

Expand Down Expand Up @@ -81,8 +83,19 @@ bool MoQOutput::Start()
self->connect_time_ms = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count());
LOG_INFO("MoQ session established (%d ms): %s", self->connect_time_ms,
self->server_url.c_str());

if (self->reconnecting)
os_atomic_set_bool(&self->reconnecting, false);
Comment on lines +86 to +88
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Inconsistent atomic access to reconnecting.

Line 87 reads self->reconnecting non-atomically (direct access), but line 88 writes it atomically using os_atomic_set_bool. For proper thread safety, both read and write operations should use atomic functions. Use os_atomic_load_bool(&self->reconnecting) for the read.

🔒 Proposed fix for consistent atomic access
-			if (self->reconnecting)
-				os_atomic_set_bool(&self->reconnecting, false);
+			if (os_atomic_load_bool(&self->reconnecting))
+				os_atomic_set_bool(&self->reconnecting, false);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.cpp` around lines 86 - 88, The access to the boolean flag
reconnecting is inconsistent: replace the non-atomic read self->reconnecting
with an atomic load using os_atomic_load_bool(&self->reconnecting) so both read
and write use the same atomic API; update the check that currently reads
self->reconnecting and keep the atomic write via
os_atomic_set_bool(&self->reconnecting, false) unchanged to ensure thread-safe
access to reconnecting.

} else if (error_code == -2) {
//on swrver disconnection. Signal to attempt to reconnect
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix typo in comment.

"swrver" should be "server".

📝 Proposed fix
-			//on swrver disconnection. Signal to attempt to reconnect
+			//on server disconnection. Signal to attempt to reconnect
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//on swrver disconnection. Signal to attempt to reconnect
//on server disconnection. Signal to attempt to reconnect
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.cpp` at line 90, Update the inline comment that currently
reads "on swrver disconnection. Signal to attempt to reconnect" to correct the
typo so it reads "on server disconnection. Signal to attempt to reconnect";
locate the comment string (e.g., within the moq-output component where that
disconnection/reconnect logic is implemented) and replace "swrver" with "server"
so the comment is clear and accurate.

LOG_INFO("MoQ session disconnected (%d): %s", error_code, self->server_url.c_str());
obs_output_signal_stop(self->output, OBS_OUTPUT_DISCONNECTED);
os_atomic_set_bool(&self->reconnecting, true);
} else {
LOG_INFO("MoQ session closed (%d): %s", error_code, self->server_url.c_str());
// signal connection failure and stop the broadcast
obs_output_signal_stop(self->output, OBS_OUTPUT_CONNECT_FAILED);
os_atomic_set_bool(&self->reconnecting, false);
}
};

Expand Down Expand Up @@ -133,6 +146,8 @@ void MoQOutput::Stop(bool signal)
obs_output_signal_stop(output, OBS_OUTPUT_SUCCESS);
}

os_atomic_set_bool(&reconnecting, false);

return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/moq-output.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class MoQOutput
int broadcast;
std::map<obs_encoder_t *, int> video_tracks;
std::map<obs_encoder_t *, int> audio_tracks;

volatile bool reconnecting;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check OBS threading utility signatures for atomic bool operations

# Search for os_atomic_set_bool and os_atomic_load_bool declarations
rg -n -A2 -B2 'os_atomic_(set|load)_bool' --type=c --type=cpp

Repository: moq-dev/obs

Length of output: 1220


🏁 Script executed:

# Find where os_atomic_set_bool is declared/defined
rg -n 'os_atomic_set_bool|define.*os_atomic_set_bool' --type=c --type=h --type=hpp

Repository: moq-dev/obs

Length of output: 83


🏁 Script executed:

# Also search in common OBS headers or utility files for atomic macros/functions
fd -e h -e hpp | xargs rg -l 'atomic' | head -20

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Check the actual declaration in moq-output.h around line 50
cat -n src/moq-output.h | sed -n '45,55p'

Repository: moq-dev/obs

Length of output: 317


🏁 Script executed:

# Search for os_atomic_set_bool definition across header and source files (.h, .c)
rg -n 'os_atomic_set_bool' --type=c --type=h -B3 -A3

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Look for the definition in typical OBS locations or macros
rg -n 'define.*atomic|#define.*set_bool' --type=c --type=h

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Check what headers are included in moq-output.h to understand where os_atomic comes from
head -30 src/moq-output.h

Repository: moq-dev/obs

Length of output: 591


🏁 Script executed:

# Search for all os_atomic usages in the codebase to see the pattern
rg -n 'os_atomic' --type=c --type=h

Repository: moq-dev/obs

Length of output: 37


🏁 Script executed:

# Look for other volatile declarations in the codebase
rg -n 'volatile' --type=c --type=h

Repository: moq-dev/obs

Length of output: 107


🏁 Script executed:

# Check for any compilation or type-related issues - look at build configuration
find . -name "CMakeLists.txt" -o -name "Makefile" -o -name "build.sh" | head -5

Repository: moq-dev/obs

Length of output: 72


🏁 Script executed:

# Check CMakeLists.txt to understand build configuration and dependencies
head -50 ./CMakeLists.txt

Repository: moq-dev/obs

Length of output: 1646


🏁 Script executed:

# Look at actual usage context in moq-output.cpp around the os_atomic_set_bool calls
sed -n '85,100p' src/moq-output.cpp

Repository: moq-dev/obs

Length of output: 740


🏁 Script executed:

# Check if there are any warnings or issues related to type mismatches
# Look for any casting or type conversions around reconnecting variable
rg -n 'reconnecting' --type=c --type=h -B1 -A1

Repository: moq-dev/obs

Length of output: 151


Remove volatile qualifier from reconnecting member—it conflicts with atomic operation semantics.

The reconnecting member is declared as volatile bool but accessed using os_atomic_set_bool in the implementation. In C++, volatile does not provide atomicity or memory ordering guarantees—it only prevents compiler optimizations. When using atomic operations, the variable should be declared as a plain bool, allowing the OBS atomic functions to handle all necessary synchronization.

Proposed fix
-    volatile bool reconnecting;
+    bool reconnecting;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
volatile bool reconnecting;
bool reconnecting;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/moq-output.h` at line 50, Remove the volatile qualifier from the member
declaration "reconnecting" so it is a plain bool; the code uses OBS atomic
helpers like os_atomic_set_bool/os_atomic_get_bool which expect a regular bool
(or the type they manage) and provide the necessary synchronization, so update
the declaration of reconnecting accordingly and ensure any other uses rely on
os_atomic_* functions rather than volatile semantics.

};

void register_moq_output();