-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
320 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
struct WHIPSimulcastEncoders { | ||
public: | ||
void Create(const char *encoderId, OBSBasic *main) | ||
{ | ||
int rescaleFilter = config_get_int(main->Config(), "AdvOut", "RescaleFilter"); | ||
if (rescaleFilter == OBS_SCALE_DISABLE) { | ||
rescaleFilter = OBS_SCALE_BICUBIC; | ||
} | ||
|
||
std::string encoder_name = "whip_simulcast_0"; | ||
auto whipSimulcastTotalLayers = config_get_int(main->Config(), "Stream1", "WHIPSimulcastTotalLayers"); | ||
if (whipSimulcastTotalLayers <= 1) { | ||
return; | ||
} | ||
|
||
auto widthStep = video_output_get_width(obs_get_video()) / whipSimulcastTotalLayers; | ||
auto heightStep = video_output_get_height(obs_get_video()) / whipSimulcastTotalLayers; | ||
|
||
for (auto i = whipSimulcastTotalLayers - 1; i > 0; i--) { | ||
uint32_t width = widthStep * i; | ||
width -= width % 2; | ||
|
||
uint32_t height = heightStep * i; | ||
height -= height % 2; | ||
|
||
encoder_name[encoder_name.size() - 1] = std::to_string(i).at(0); | ||
auto whip_simulcast_encoder = | ||
obs_video_encoder_create(encoderId, encoder_name.c_str(), nullptr, nullptr); | ||
|
||
if (whip_simulcast_encoder) { | ||
obs_encoder_set_video(whip_simulcast_encoder, obs_get_video()); | ||
obs_encoder_set_scaled_size(whip_simulcast_encoder, width, height); | ||
obs_encoder_set_gpu_scale_type(whip_simulcast_encoder, (obs_scale_type)rescaleFilter); | ||
whipSimulcastEncoders.push_back(whip_simulcast_encoder); | ||
obs_encoder_release(whip_simulcast_encoder); | ||
} else { | ||
blog(LOG_WARNING, | ||
"Failed to create video streaming WHIP Simulcast encoders (BasicOutputHandler)"); | ||
} | ||
} | ||
} | ||
|
||
void Update(obs_data_t *videoSettings, int videoBitrate) | ||
{ | ||
auto bitrateStep = videoBitrate / static_cast<int>(whipSimulcastEncoders.size() + 1); | ||
for (auto &whipSimulcastEncoder : whipSimulcastEncoders) { | ||
videoBitrate -= bitrateStep; | ||
obs_data_set_int(videoSettings, "bitrate", videoBitrate); | ||
obs_encoder_update(whipSimulcastEncoder, videoSettings); | ||
} | ||
} | ||
|
||
void SetVideoFormat(enum video_format format) | ||
{ | ||
for (auto enc : whipSimulcastEncoders) | ||
obs_encoder_set_preferred_video_format(enc, format); | ||
} | ||
|
||
void SetStreamOutput(obs_output_t *streamOutput) | ||
{ | ||
for (size_t i = 0; i < whipSimulcastEncoders.size(); i++) | ||
obs_output_set_video_encoder2(streamOutput, whipSimulcastEncoders[i], i + 1); | ||
} | ||
|
||
private: | ||
std::vector<OBSEncoder> whipSimulcastEncoders; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.