Skip to content

Commit 3cfa4ba

Browse files
RodrigoHolztrattnereddyStreamlabs
authored andcommitted
Add checks for invalid DIrectX version (#133)
* Detect errors when creating/reseting the graphical API * Pass the numeric video error (if there is any) directly to the frontend * Add a video error enum accessible from the frontend to handle the dx11 case
1 parent 3d977fd commit 3cfa4ba

5 files changed

Lines changed: 40 additions & 12 deletions

File tree

js/module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ export const enum EDeinterlaceFieldOrder {
5050
Bottom
5151
}
5252

53+
export const enum EVideoCodes {
54+
Success = 0,
55+
Fail = -1,
56+
NotSupported = -2,
57+
InvalidParam = -3,
58+
CurrentlyActive = -4,
59+
ModuleNotFound = -5
60+
}
61+
5362
export const enum EDeinterlaceMode {
5463
Disable,
5564
Discard,

obs-studio-server/source/nodeobs_api.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,14 @@ void OBS_API::OBS_API_initAPI(
498498
obs_data_set_bool(private_settings, "BrowserHWAccel", true);
499499
obs_apply_private_data(private_settings);
500500
obs_data_release(private_settings);
501-
502-
openAllModules();
501+
502+
int videoError;
503+
if (!openAllModules(videoError)) {
504+
rval.push_back(ipc::value((uint64_t)ErrorCode::Error));
505+
rval.push_back(ipc::value(videoError));
506+
AUTO_DEBUG;
507+
return;
508+
}
503509

504510
OBS_service::createService();
505511

@@ -818,9 +824,12 @@ typedef std::basic_string<char, ci_char_traits> istring;
818824

819825
/* This should be reusable outside of node-obs, especially
820826
* if we go a server/client route. */
821-
void OBS_API::openAllModules(void)
827+
bool OBS_API::openAllModules(int& video_err)
822828
{
823-
OBS_service::resetVideoContext(NULL);
829+
video_err = OBS_service::resetVideoContext(NULL);
830+
if (video_err != OBS_VIDEO_SUCCESS) {
831+
return false;
832+
}
824833

825834
std::string plugins_paths[] = {g_moduleDirectory + "/obs-plugins/64bit", g_moduleDirectory + "/obs-plugins", slobs_plugin + "/obs-plugins/64bit"};
826835

@@ -838,13 +847,13 @@ void OBS_API::openAllModules(void)
838847
* shared library. */
839848
if (!os_file_exists(plugins_path.c_str())) {
840849
std::cerr << "Plugin Path provided is invalid: " << plugins_path << std::endl;
841-
return;
850+
return false;
842851
}
843852

844853
os_dir_t* plugin_dir = os_opendir(plugins_path.c_str());
845854
if (!plugin_dir) {
846855
std::cerr << "Failed to open plugin diretory: " << plugins_path << std::endl;
847-
return;
856+
return false;
848857
}
849858

850859
for (os_dirent* ent = os_readdir(plugin_dir); ent != nullptr; ent = os_readdir(plugin_dir)) {
@@ -895,6 +904,8 @@ void OBS_API::openAllModules(void)
895904

896905
os_closedir(plugin_dir);
897906
}
907+
908+
return true;
898909
}
899910

900911
double OBS_API::getCPU_Percentage(void)

obs-studio-server/source/nodeobs_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class OBS_API
6767
private:
6868
static void initAPI(void);
6969
static void destroyOBS_API(void);
70-
static void openAllModules(void);
70+
static bool openAllModules(int& video_err);
7171

7272
static double getCPU_Percentage(void);
7373
static int getNumberOfDroppedFrames(void);

obs-studio-server/source/nodeobs_service.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ void OBS_service::OBS_service_resetVideoContext(
105105
const std::vector<ipc::value>& args,
106106
std::vector<ipc::value>& rval)
107107
{
108-
resetVideoContext(NULL);
109-
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
108+
int result = resetVideoContext(NULL);
109+
if (result == OBS_VIDEO_SUCCESS) {
110+
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
111+
} else {
112+
rval.push_back(ipc::value((uint64_t)ErrorCode::Error));
113+
rval.push_back(ipc::value(result));
114+
}
115+
110116
AUTO_DEBUG;
111117
}
112118

@@ -466,7 +472,7 @@ static const double vals[] = {1.0, 1.25, (1.0 / 0.75), 1.5, (1.0 / 0.6), 1.75, 2
466472

467473
static const size_t numVals = sizeof(vals) / sizeof(double);
468474

469-
bool OBS_service::resetVideoContext(const char* outputType)
475+
int OBS_service::resetVideoContext(const char* outputType)
470476
{
471477
config_t* basicConfig = OBS_API::openConfigFile(OBS_API::getBasicConfigPath());
472478

@@ -1762,7 +1768,9 @@ void OBS_service::updateRecordSettings(void)
17621768
} else if (strcmp(currentOutputMode, "Advanced") == 0) {
17631769
const char* recType = config_get_string(config, "AdvOut", "RecType");
17641770
if (recType != NULL && strcmp(recType, "Custom Output (FFmpeg)") == 0) {
1765-
resetVideoContext("Record");
1771+
if (!resetVideoContext("Record") != OBS_VIDEO_SUCCESS) {
1772+
return;
1773+
}
17661774
associateAudioAndVideoToTheCurrentRecordingContext();
17671775
UpdateFFmpegOutput();
17681776
return;

obs-studio-server/source/nodeobs_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class OBS_service
262262

263263
// Reset contexts
264264
static bool resetAudioContext(void);
265-
static bool resetVideoContext(const char* outputType);
265+
static int resetVideoContext(const char* outputType);
266266

267267
static void associateAudioAndVideoToTheCurrentStreamingContext(void);
268268
static void associateAudioAndVideoToTheCurrentRecordingContext(void);

0 commit comments

Comments
 (0)