Skip to content
Merged
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
11 changes: 11 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ not get a line.
2026-10-11. Issue [#19](https://github.com/obs-rust/obs-studio/issues/19),
PRs [#162](https://github.com/obs-rust/obs-studio/pull/162),
[#181](https://github.com/obs-rust/obs-studio/pull/181).
- **Encrypted streaming where the service supports it.** Twitch, Vimeo,
niconico, BoxCast, Bitmovin, Eventials and EventLive.pro stream over RTMPS
(port 443) instead of plain RTMP, on every server checked to accept it;
existing profiles switch too, with no setting to change. If the encrypted
connection cannot be made, the shared fallback warning ("Streaming
unencrypted (RTMP)") counts down three seconds and then streams to the same
server over plain RTMP, unless you cancel; the fallback is written to the
log and to stderr. Without trusted root certificates on the system, the
warning says so and suggests installing the system's CA certificates. A
server certificate that does not verify stops the start instead. Custom servers are unchanged. *All*, pending merge. Issue
[#2205](https://github.com/obs-rust/obs-studio/issues/2205).

### Sources and filters

Expand Down
1 change: 1 addition & 0 deletions frontend/build/frontend-widgets.pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <models/SceneCollection.hpp>
#include <settings/OBSBasicSettings.hpp>
#include <utility/QuickTransition.hpp>
#include <utility/RtmpsFallback.hpp>
#include <utility/SceneRenameDelegate.hpp>
#include <utility/ScreenshotObj.hpp>
#if defined(_WIN32) || defined(WHATSNEW_ENABLED)
Expand Down
1 change: 1 addition & 0 deletions frontend/build/source-sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
"utility/RemuxQueueModel.hpp",
"utility/RemuxWorker.hpp",
"utility/ResizeSignaler.hpp",
"utility/RtmpsFallback.hpp",
"build/frontend.utility-3+.hpp.cpp",
"utility/SceneRenameDelegate.hpp",
"build/frontend.utility-screenshotobj+.hpp.cpp",
Expand Down
4 changes: 4 additions & 0 deletions frontend/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ Output.ConnectFail.InvalidStream="Could not access the specified channel or stre
Output.ConnectFail.HdrDisabled="HDR output is currently disabled for this output."
Output.ConnectFail.Error="An unexpected error occurred when trying to connect to the server. More information in the log file."
Output.ConnectFail.Disconnected="Disconnected from server."
Output.RtmpsFallback.Title="Streaming unencrypted (RTMP)"
Output.RtmpsFallback.Message="OBS could not make an encrypted connection (RTMPS) to the server.\n\nOBS streams to %1 unencrypted instead. To stop the stream from starting, select Cancel; to stream encrypted, check that your network or firewall allows connections on port 443."
Output.RtmpsFallback.NoRootCerts="OBS could not find your system's trusted certificates, so it could not make a secure connection (RTMPS) to the server.\n\nOBS streams to %1 unencrypted over RTMP instead. To stream encrypted, install your system's CA certificates package and start the stream again; to stop the stream from starting, select Cancel."
Output.RtmpsFallback.Tray="Streaming unencrypted (RTMP): the encrypted connection failed."

# output streaming-related messages
Output.StreamEncodeError.Title="Encoding error"
Expand Down
111 changes: 111 additions & 0 deletions frontend/utility/RtmpsFallback.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#pragma once

#include <obs-frontend-api.h>
#include <obs.h>

#include <QByteArray>
#include <QString>

#include <cstring>
#include <functional>
#include <string>
#include <utility>

/* The RTMPS fallback (obs-rust/obs-studio#2205): a stream that rtmp-services
* upgraded to RTMPS fails to connect, and OBS offers to stream to the same
* server over plain RTMP. The warning is the shared fallback warning
* (obs_frontend_warn_fallback, docs/fallback-warning.md): logged at error
* level and on stderr, a dialog with a three-second countdown that accepts,
* and Cancel, which stops the start. */
namespace RtmpsFallback {

/* How often to ask: the shared warning shows its dialog once per id in an
* OBS session, and the id names the server, so each server asks once per
* session. A second failure to the same server only logs and continues over
* RTMP. */
inline constexpr bool IdPerServer = true;

/* With the main window hidden (OBS in the tray) the shared warning logs and
* accepts at once; OBS then shows a tray notice and waits HiddenCountdownMs
* before it restarts over RTMP. */
inline constexpr bool CountdownWhenHidden = true;
inline constexpr int HiddenCountdownMs = 3000;

/* Why the RTMPS connection failed, as the RTMP output's rtmp_tls_failure proc
* reports it. */
enum class Cause {
Connection, /* timeout, refused, reset, other handshake failure */
CertUnverified, /* "cert_unverified": the server's certificate */
NoRootCerts, /* "no_root_certs": the system has no trusted roots */
};

inline Cause ParseCause(const char *failure)
{
if (!failure) {
return Cause::Connection;
}
if (strcmp(failure, "cert_unverified") == 0) {
return Cause::CertUnverified;
}
if (strcmp(failure, "no_root_certs") == 0) {
return Cause::NoRootCerts;
}
return Cause::Connection;
}

inline constexpr const char *BaseId = "rtmp.unencrypted";
inline constexpr const char *NoRootCertsId = "rtmp.unencrypted.nocerts";

/* The fallback warning's id for a stream to plainUrl. The missing root
* certificates have their own id, so that warning is shown once per server
* even when an ordinary failure was shown first. */
inline std::string Id(const std::string &plainUrl, Cause cause = Cause::Connection)
{
std::string base = cause == Cause::NoRootCerts ? NoRootCertsId : BaseId;
if (!IdPerServer || plainUrl.empty()) {
return base;
}
return base + ":" + plainUrl;
}

/* The locale key of the warning's message (%1 is the plain RTMP URL). */
inline const char *MessageKey(Cause cause)
{
return cause == Cause::NoRootCerts ? "Output.RtmpsFallback.NoRootCerts" : "Output.RtmpsFallback.Message";
}

/* Whether a stream that stopped with code may retry over plain RTMP: only a
* connection failure of a service stream (multitrack video brings its own
* URLs), and never when the server's certificate did not verify. That is no
* network trouble, and plain RTMP would send the stream key unencrypted to a
* server that could not prove who it is. */
inline bool Allowed(int code, bool multitrack, Cause cause)
{
return code == OBS_OUTPUT_CONNECT_FAILED && !multitrack && cause != Cause::CertUnverified;
}

using Answer = std::function<void(bool accepted)>;

/* Raises the shared warning for a fallback to plainUrl. message is translated
* and has %1 for the URL. answer is called once, on the UI thread: true for
* the countdown or "Accept anyway" (restart over plain RTMP), false for
* Cancel or a closed dialog. */
inline void Warn(const QString &title, const QString &message, const std::string &plainUrl, Cause cause, Answer answer)
{
std::string id = Id(plainUrl, cause);
QByteArray t = title.toUtf8();
QByteArray m = message.arg(QString::fromStdString(plainUrl)).toUtf8();
auto *held = new Answer(std::move(answer));
obs_frontend_warn_fallback(
id.c_str(), t.constData(), m.constData(), true,
[](void *param, bool accepted) {
Answer *a = static_cast<Answer *>(param);
if (*a) {
(*a)(accepted);
}
delete a;
},
held);
}

} // namespace RtmpsFallback
10 changes: 10 additions & 0 deletions frontend/widgets/OBSBasic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,16 @@ private slots:
bool streamingStopping = false;
bool streamingStarting = false;

/* RTMPS fallback (utility/RtmpsFallback.hpp): whether the next start
* keeps plain RTMP after "Accept anyway", and whether the stream being
* started takes its URLs from multitrack video instead of the service. */
bool rtmpsFallbackRestart = false;
bool streamUsesMultitrack = false;
std::string RtmpsFallbackUrl();
std::string StreamTlsFailure();
void SetPlainRtmp(bool enabled);
void OfferRtmpsFallback(const std::string &plainUrl, const std::string &tlsFailure);

public slots:
void DisplayStreamStartError();
void StartStreaming();
Expand Down
100 changes: 100 additions & 0 deletions frontend/widgets/OBSBasic_Streaming.cpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void OBSBasic::StartStreaming()
}
}

/* A start the user asks for tries RTMPS again; only the restart after
* "Proceed anyway" keeps plain RTMP. */
SetPlainRtmp(rtmpsFallbackRestart);
rtmpsFallbackRestart = false;

emit StreamingPreparing();

if (sysTrayStream) {
Expand All @@ -92,6 +97,8 @@ void OBSBasic::StartStreaming()
sysTrayStream->setText("Basic.Main.Connecting");
}

streamUsesMultitrack = outputHandler->multitrackVideoActive;

if (!outputHandler->StartStreaming(service)) {
DisplayStreamStartError();
return;
Expand Down Expand Up @@ -335,6 +342,21 @@ void OBSBasic::StreamingStop(int code, QString last_error)
errorDescription = Str("Output.ConnectFail.Disconnected");
}

/* A service connection that rtmp-services upgraded to RTMPS can retry
* over plain RTMP; multitrack video brings its own URLs. */
std::string rtmpsPlainUrl;
std::string rtmpsTlsFailure;
if (code == OBS_OUTPUT_CONNECT_FAILED && !streamUsesMultitrack) {
rtmpsTlsFailure = StreamTlsFailure();
RtmpsFallback::Cause cause = RtmpsFallback::ParseCause(rtmpsTlsFailure.c_str());
if (RtmpsFallback::Allowed(code, streamUsesMultitrack, cause)) {
rtmpsPlainUrl = RtmpsFallbackUrl();
} else if (cause == RtmpsFallback::Cause::CertUnverified && !RtmpsFallbackUrl().empty()) {
blog(LOG_ERROR, "RTMPS: the server's certificate did not verify; "
"the stream is not started and does not fall back to RTMP");
}
}

if (use_last_error && !last_error.isEmpty()) {
dstr_printf(errorMessage, "%s\n\n%s", errorDescription, QT_TO_UTF8(last_error));
} else {
Expand Down Expand Up @@ -368,6 +390,9 @@ void OBSBasic::StreamingStop(int code, QString last_error)
: QTStr("Output.StreamEncodeError.Msg.LastError").arg(last_error);
OBSMessageBox::information(this, QTStr("Output.StreamEncodeError.Title"), msg);

} else if (!rtmpsPlainUrl.empty()) {
OfferRtmpsFallback(rtmpsPlainUrl, rtmpsTlsFailure);

} else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
OBSMessageBox::information(this, QTStr("Output.ConnectFail.Title"), QT_UTF8(errorMessage));

Expand All @@ -384,6 +409,81 @@ void OBSBasic::StreamingStop(int code, QString last_error)
}
}

std::string OBSBasic::RtmpsFallbackUrl()
{
calldata_t cd = {0};
const char *plain = nullptr;
std::string url;

calldata_set_ptr(&cd, "service", GetService());
if (proc_handler_call(obs_get_proc_handler(), "rtmp_services_rtmps_fallback", &cd) &&
calldata_get_string(&cd, "plain_url", &plain) && plain) {
url = plain;
}
calldata_free(&cd);
return url;
}

void OBSBasic::SetPlainRtmp(bool enabled)
{
calldata_t cd = {0};
calldata_set_ptr(&cd, "service", GetService());
calldata_set_bool(&cd, "enabled", enabled);
proc_handler_call(obs_get_proc_handler(), "rtmp_services_set_plain_rtmp", &cd);
calldata_free(&cd);
}

/* Why the stream output's last connect failed its TLS handshake, as
* obs-outputs' rtmp output reports it: "cert_unverified", "no_root_certs",
* or empty for anything else (also for outputs without the proc). */
std::string OBSBasic::StreamTlsFailure()
{
obs_output_t *output = outputHandler ? outputHandler->streamOutput.Get() : nullptr;
if (!output) {
return "";
}

calldata_t cd = {0};
const char *failure = nullptr;
std::string result;
if (proc_handler_call(obs_output_get_proc_handler(output), "rtmp_tls_failure", &cd) &&
calldata_get_string(&cd, "failure", &failure) && failure) {
result = failure;
}
calldata_free(&cd);
return result;
}

/* The RTMPS connection failed: the shared fallback warning counts down three
* seconds and then OBS restarts the stream over plain RTMP, unless the user
* cancels. The warning logs the fallback. Without trusted root certificates
* its message says so. */
void OBSBasic::OfferRtmpsFallback(const std::string &plainUrl, const std::string &tlsFailure)
{
RtmpsFallback::Cause cause = RtmpsFallback::ParseCause(tlsFailure.c_str());
auto restart = [this]() {
if (isClosing() || outputHandler->StreamingActive()) {
return;
}
rtmpsFallbackRestart = true;
QMetaObject::invokeMethod(this, &OBSBasic::StartStreaming, Qt::QueuedConnection);
};

RtmpsFallback::Warn(QTStr("Output.RtmpsFallback.Title"), QTStr(RtmpsFallback::MessageKey(cause)), plainUrl,
cause, [this, restart](bool accepted) {
if (!accepted) {
blog(LOG_INFO, "RTMPS fallback cancelled; the stream was not started");
return;
}
if (RtmpsFallback::CountdownWhenHidden && !isVisible()) {
SysTrayNotify(QTStr("Output.RtmpsFallback.Tray"), QSystemTrayIcon::Warning);
QTimer::singleShot(RtmpsFallback::HiddenCountdownMs, this, restart);
return;
}
restart();
});
}

void OBSBasic::StreamActionTriggered()
{
if (outputHandler->StreamingActive()) {
Expand Down
Loading
Loading