@@ -72,6 +72,7 @@ void OBS_settings::Register(ipc::server &srv)
7272 cls->register_function (std::make_shared<ipc::function>(
7373 " OBS_settings_saveSettings" , std::vector<ipc::type>{ipc::type::String, ipc::type::UInt32, ipc::type::UInt32, ipc::type::Binary},
7474 OBS_settings_saveSettings));
75+ cls->register_function (std::make_shared<ipc::function>(" OBS_settings_isValidEncoder" , std::vector<ipc::type>{}, OBS_settings_isValidEncoder));
7576 cls->register_function (
7677 std::make_shared<ipc::function>(" OBS_settings_getInputAudioDevices" , std::vector<ipc::type>{}, OBS_settings_getInputAudioDevices));
7778 cls->register_function (
@@ -1196,6 +1197,60 @@ static void converOldJimNvencEncoder(config_t *config, const std::string &config
11961197 }
11971198}
11981199
1200+ static bool validateEncoderForService (StreamServiceId serviceId, const char *encoderToFind)
1201+ {
1202+ bool validEncoder = false ;
1203+
1204+ // have encoder - find in encoders_set, validate 'streaming' flag and check availability based on 'check_availability_streaming' flag
1205+ for (int i = 0 ; i < encoders_set.size (); i++) {
1206+ if (std::string (encoderToFind) == encoders_set[i].simple_name || std::string (encoderToFind) == encoders_set[i].advanced_name ) {
1207+ if (encoders_set[i].streaming ) {
1208+ if (encoders_set[i].check_availability_streaming ) {
1209+ if (isEncoderAvailableForStreaming (encoderToFind, OBS_service::getService (serviceId))) {
1210+ validEncoder = true ;
1211+ break ;
1212+ }
1213+ } else {
1214+ validEncoder = true ;
1215+ }
1216+ }
1217+ break ;
1218+ }
1219+ }
1220+
1221+ return validEncoder;
1222+ }
1223+
1224+ void OBS_settings::OBS_settings_isValidEncoder (void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
1225+ {
1226+ const char *mode = NULL ;
1227+ const char *curEncoder = NULL ;
1228+ bool validEncoder = false ;
1229+ std::string serviceToCheck = args[0 ].value_str ;
1230+
1231+ // get mode and configured encoder
1232+ mode = config_get_string (ConfigManager::getInstance ().getBasic (), " Output" , " Mode" );
1233+ if (mode == NULL ) {
1234+ mode = " Simple" ;
1235+ }
1236+ if (strcmp (mode, " Advanced" ) == 0 ) {
1237+ curEncoder = config_get_string (ConfigManager::getInstance ().getBasic (), " AdvOut" , " Encoder" );
1238+ } else {
1239+ curEncoder = config_get_string (ConfigManager::getInstance ().getBasic (), " SimpleOutput" , " StreamingEncoder" );
1240+ }
1241+
1242+ if (serviceToCheck == " Both" ) {
1243+ validEncoder = validateEncoderForService (StreamServiceId::Main, curEncoder) && validateEncoderForService (StreamServiceId::Second, curEncoder);
1244+ } else if (serviceToCheck == " Stream" ) {
1245+ validEncoder = validateEncoderForService (StreamServiceId::Main, curEncoder);
1246+ } else if (serviceToCheck == " StreamSecond" ) {
1247+ validEncoder = validateEncoderForService (StreamServiceId::Second, curEncoder);
1248+ }
1249+
1250+ rval.push_back (ipc::value ((uint64_t )ErrorCode::Ok));
1251+ rval.push_back (ipc::value (validEncoder));
1252+ }
1253+
11991254void OBS_settings::getSimpleOutputSettings (std::vector<SubCategory> *outputSettings, config_t *config, bool isCategoryEnabled)
12001255{
12011256 converOldJimNvencEncoder (config, " SimpleOutput" , " StreamEncoder" , " RecEncoder" );
0 commit comments