obs-webrtc: Avoid crashing on invalid answer

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.
This commit is contained in:
Aleks Todorov 2024-02-28 21:30:39 +00:00 committed by Ryan Foster
parent e4ec414690
commit 4953c5d517

View file

@ -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;
}