Skip to content

Commit bf0bc00

Browse files
Fixed enhanced broadcasting crash for unsupported GPU (#1674)
* Fixed enhanced broadcasting crash for unsupported GPU * Minor comment update * Test fix
1 parent b3175ad commit bf0bc00

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

obs-studio-server/source/osn-enhanced-broadcasting-advanced-streaming.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "shared.hpp"
2424
#include "nodeobs_audio_encoders.h"
2525
#include "osn-audio-track.hpp"
26+
#include <exception>
2627
#include <osn-video.hpp>
2728

2829
void osn::IEnhancedBroadcastingAdvancedStreaming::Register(ipc::server &srv)
@@ -118,7 +119,13 @@ void osn::IEnhancedBroadcastingAdvancedStreaming::Start(void *data, const int64_
118119
}
119120

120121
auto vod_track_mixer = (streaming->twitchVODSupported && streaming->enableTwitchVOD) ? std::optional{streaming->twitchTrack} : std::nullopt;
121-
streaming->StartEnhancedBroadcastingStream(vod_track_mixer);
122+
try {
123+
streaming->StartEnhancedBroadcastingStream(vod_track_mixer);
124+
} catch (const std::exception &error) {
125+
PRETTY_ERROR_RETURN(ErrorCode::Error, error.what());
126+
} catch (...) {
127+
PRETTY_ERROR_RETURN(ErrorCode::Error, "Failed to start enhanced broadcasting stream.");
128+
}
122129

123130
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
124131
AUTO_DEBUG;

obs-studio-server/source/osn-enhanced-broadcasting-simple-streaming.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "shared.hpp"
2424
#include "nodeobs_audio_encoders.h"
2525
#include "osn-audio-track.hpp"
26+
#include <exception>
2627
#include <osn-video.hpp>
2728

2829
void osn::IEnhancedBroadcastingSimpleStreaming::Register(ipc::server &srv)
@@ -115,7 +116,13 @@ void osn::IEnhancedBroadcastingSimpleStreaming::Start(void *data, const int64_t
115116
}
116117

117118
// Note: unlike advanced mode, there is no Twitch VOD track for simple mode
118-
streaming->StartEnhancedBroadcastingStream();
119+
try {
120+
streaming->StartEnhancedBroadcastingStream();
121+
} catch (const std::exception &error) {
122+
PRETTY_ERROR_RETURN(ErrorCode::Error, error.what());
123+
} catch (...) {
124+
PRETTY_ERROR_RETURN(ErrorCode::Error, "Failed to start enhanced broadcasting stream.");
125+
}
119126

120127
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
121128
AUTO_DEBUG;

tests/osn-tests/src/test_osn_enhanced_broadcasting_advanced_streaming.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,55 @@ describe(testName, () => {
7171
// TODO: more tests:
7272
// - vertical primary canvas
7373

74+
it('Enhanced Broadcasting Advanced Streaming rejects without crashing in CI', function() {
75+
// This test is CI only because CI is expected to hit a Twitch Enhanced Broadcasting rejection.
76+
if (obs.isDarwin()) {
77+
this.skip();
78+
}
79+
80+
if (!obs.isCI()) {
81+
this.skip();
82+
}
83+
84+
const stream = osn.EnhancedBroadcastingAdvancedStreamingFactory.create();
85+
let startError: Error = null;
86+
87+
try {
88+
expect(stream).to.not.be.null;
89+
stream.service = osn.ServiceFactory.legacySettings;
90+
stream.service.update({
91+
service: 'Twitch',
92+
server: 'auto',
93+
key: obs.userStreamKey,
94+
});
95+
stream.delay = osn.DelayFactory.create();
96+
stream.reconnect = osn.ReconnectFactory.create();
97+
stream.network = osn.NetworkFactory.create();
98+
stream.video = obs.defaultVideoContext;
99+
const track1 = osn.AudioTrackFactory.create(160, 'track1');
100+
osn.AudioTrackFactory.setAtIndex(track1, 1);
101+
102+
try {
103+
stream.start();
104+
} catch (error) {
105+
startError = error as Error;
106+
}
107+
108+
expect(startError).to.not.be.null;
109+
expect(osn.ServiceFactory.types()).to.include('rtmp_common');
110+
} finally {
111+
if (!startError) {
112+
try {
113+
stream.stop();
114+
} catch (error) {
115+
// Best-effort cleanup if the stream unexpectedly started.
116+
}
117+
}
118+
119+
osn.EnhancedBroadcastingAdvancedStreamingFactory.destroy(stream);
120+
}
121+
});
122+
74123
it('Enhanced Broadcasting Advanced Streaming Single Canvas', async function() {
75124
if (obs.isDarwin()) {
76125
this.skip();

0 commit comments

Comments
 (0)