@@ -33,6 +33,14 @@ osn::Streaming::~Streaming()
3333 }
3434}
3535
36+ void osn::Streaming::DeleteOutput () {
37+ blog (LOG_INFO, " osn::Streaming::DeleteOutput" );
38+ Output::DeleteOutput ();
39+ if (enhancedBroadcasting) {
40+ enhancedBroadcastingContext.reset ();
41+ }
42+ }
43+
3644void osn::IStreaming::GetService (void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
3745{
3846 Streaming *streaming = osn::IStreaming::Manager::GetInstance ().find (args[0 ].value_union .ui64 );
@@ -405,6 +413,79 @@ void osn::Streaming::setNetworkLegacySettings()
405413 config_set_bool (ConfigManager::getInstance ().getBasic (), " Output" , " LowLatencyEnable" , network->enableDynamicBitrate );
406414}
407415
416+ void osn::Streaming::StartEnhancedBroadcastingStream (std::optional<size_t > vod_track_mixer) {
417+ blog (LOG_INFO, " Streaming::StartEnhancedBroadcastingStream - service id: %s" , obs_service_get_id (this ->service ));
418+
419+ if (vod_track_mixer.has_value ()) {
420+ blog (LOG_INFO, " vod_track_mixer: %d" , vod_track_mixer.value ());
421+ }
422+
423+ const bool is_custom = strncmp (" rtmp_custom" , obs_service_get_type (this ->service ), 11 ) == 0 ;
424+
425+ OBSDataAutoRelease settings = obs_service_get_settings (this ->service );
426+ const std::string key = obs_data_get_string (settings, " key" );
427+
428+ const char *service_name = " <unknown>" ;
429+ if (is_custom && obs_data_has_user_value (settings, " service_name" )) {
430+ service_name = obs_data_get_string (settings, " service_name" );
431+ } else if (!is_custom) {
432+ service_name = obs_data_get_string (settings, " service" );
433+ }
434+
435+ std::optional<std::string> custom_rtmp_url;
436+ auto server = obs_data_get_string (settings, " server" );
437+ if (strcmp (server, " auto" ) != 0 ) {
438+ custom_rtmp_url = server;
439+ }
440+
441+ auto service_custom_server = obs_data_get_bool (settings, " using_custom_server" );
442+ if (custom_rtmp_url.has_value ()) {
443+ blog (LOG_INFO, " Using %s server '%s'" , service_custom_server ? " custom " : " " , custom_rtmp_url->c_str ());
444+ }
445+
446+ auto auto_config_url = osn::MultitrackVideoAutoConfigURL (this ->service );
447+ blog (LOG_INFO, " Auto config URL: %s" , auto_config_url.c_str ());
448+
449+ const bool dualStreamingMode = true ; // TODO: revise this??????? Make this dynamic?????
450+ auto go_live_post = osn::constructGoLivePost (StreamServiceId::Main, dualStreamingMode, key, std::nullopt , std::nullopt , vod_track_mixer.has_value ());
451+ std::optional<osn::Config> go_live_config = osn::DownloadGoLiveConfig (auto_config_url, go_live_post);
452+ if (!go_live_config.has_value ()) {
453+ throw std::runtime_error (" startStreaming - go live config is empty" );
454+ }
455+
456+ const auto audio_bitrate = osn::GetMultitrackAudioBitrate ();
457+ const auto audio_encoder_id = osn::GetSimpleAACEncoderForBitrate (audio_bitrate);
458+
459+ std::vector<OBSEncoderAutoRelease> audio_encoders;
460+ std::shared_ptr<obs_encoder_group_t > video_encoder_group;
461+ auto output =
462+ osn::SetupOBSOutput (" Enhanced Broadcasting" , go_live_config.value (), audio_encoders, video_encoder_group, audio_encoder_id, 0 , vod_track_mixer);
463+ if (!output) {
464+ throw std::runtime_error (" startStreaming - failed to create multitrack output" );
465+ }
466+
467+ // Stream key is defined by config from Twitch
468+ auto multitrack_video_service = osn::create_service (*go_live_config, std::nullopt , " " );
469+ if (!multitrack_video_service) {
470+ throw std::runtime_error (" startStreaming - failed to create multitrack video service" );
471+ }
472+
473+ this ->SetOutput (output.Get ());
474+ obs_output_set_service (output, multitrack_video_service);
475+
476+ // Register the BPM (Broadcast Performance Metrics) callback
477+ obs_output_add_packet_callback (output, bpm_inject, NULL );
478+
479+ this ->StartOutput ();
480+
481+ enhancedBroadcastingContext.emplace (EnhancedBroadcastOutputObjects{
482+ std::move (output),
483+ video_encoder_group,
484+ std::move (audio_encoders),
485+ std::move (multitrack_video_service),
486+ });
487+ }
488+
408489void osn::IStreaming::GetDroppedFrames (void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
409490{
410491 Streaming *streaming = osn::IStreaming::Manager::GetInstance ().find (args[0 ].value_union .ui64 );
@@ -507,4 +588,4 @@ void osn::IStreaming::GetDataOutput(void *data, const int64_t id, const std::vec
507588 rval.push_back (ipc::value ((uint64_t )ErrorCode::Ok));
508589 rval.push_back (ipc::value (dataOutput));
509590 AUTO_DEBUG;
510- }
591+ }
0 commit comments