Skip to content

Commit

Permalink
obs-webrtc: Avoid crashing on invalid answer
Browse files Browse the repository at this point in the history
PeerConnection::setRemoteDescription validates the input SDP, throwing
an exception whenever it is invalid.

Currently, instead of handling the exception, we just crash.

Instead, add an exception handler which logs a short description of the
issue as well as the error message from the exception.
  • Loading branch information
Aleksbgbg authored and RytoEX committed Mar 7, 2024
1 parent e4ec414 commit 4953c5d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plugins/obs-webrtc/whip-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,21 @@ bool WHIPOutput::Connect()
response.erase(0, response.find("v=0"));

rtc::Description answer(response, "answer");
peer_connection->setRemoteDescription(answer);
try {
peer_connection->setRemoteDescription(answer);
} catch (const std::invalid_argument &err) {
do_log(LOG_ERROR, "WHIP server responded with invalid SDP: %s",
err.what());
cleanup();
obs_output_signal_stop(output, OBS_OUTPUT_CONNECT_FAILED);
return false;
} catch (const std::exception &err) {
do_log(LOG_ERROR, "Failed to set remote description: %s",
err.what());
cleanup();
obs_output_signal_stop(output, OBS_OUTPUT_CONNECT_FAILED);
return false;
}
cleanup();
return true;
}
Expand Down

0 comments on commit 4953c5d

Please sign in to comment.