Introduce WebRTC-VideoEncoderSettings/encoder_thread_limit:X.
As requested by a CEF hosted application (https://crbug.com/1406331) who want to be able to limit the number of threads in a controlled environment, this CL adds a flag to control the max limit per encoder. For plumbing-reasons, this is placed in VideoEncoder::Settings but with a note that this is considered an experimental API with limited support. For now only LibvpxVp8Encoder uses it and there are no plans to roll this out. I have manually confirmed this is working with printf debugging, --force-fieldtrials=WebRTC-VideoEncoderSettings/encoder_thread_limit:2 and https://jsfiddle.net/henbos/2bd6m7Lt/ Bug: chromium:1406331 Change-Id: Ib02bd83e2071034874843d3aaa0d3b0adc5bbf46 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/293960 Reviewed-by: Markus Handell <handellm@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39349}
This commit is contained in:
parent
3637fe5117
commit
fbd0ddb32e
@ -330,6 +330,9 @@ class RTC_EXPORT VideoEncoder {
|
||||
Capabilities capabilities;
|
||||
int number_of_cores;
|
||||
size_t max_payload_size;
|
||||
// Experimental API - currently only supported by LibvpxVp8Encoder.
|
||||
// If set, limits the number of encoder threads.
|
||||
absl::optional<int> encoder_thread_limit;
|
||||
};
|
||||
|
||||
static VideoCodecVP8 GetDefaultVp8Settings();
|
||||
|
||||
@ -609,6 +609,12 @@ int LibvpxVp8Encoder::InitEncode(const VideoCodec* inst,
|
||||
// TODO(fbarchard): Consider number of Simulcast layers.
|
||||
vpx_configs_[0].g_threads = NumberOfThreads(
|
||||
vpx_configs_[0].g_w, vpx_configs_[0].g_h, settings.number_of_cores);
|
||||
if (settings.encoder_thread_limit.has_value()) {
|
||||
RTC_DCHECK_GE(settings.encoder_thread_limit.value(), 1);
|
||||
vpx_configs_[0].g_threads = std::min(
|
||||
vpx_configs_[0].g_threads,
|
||||
static_cast<unsigned int>(settings.encoder_thread_limit.value()));
|
||||
}
|
||||
|
||||
// Creating a wrapper to the image - setting image data to NULL.
|
||||
// Actual pointer will be set in encode. Setting align to 1, as it
|
||||
|
||||
@ -526,6 +526,13 @@ absl::optional<int> ParseVp9LowTierCoreCountThreshold(
|
||||
return max_core_count.Get();
|
||||
}
|
||||
|
||||
absl::optional<int> ParseEncoderThreadLimit(const FieldTrialsView& trials) {
|
||||
FieldTrialOptional<int> encoder_thread_limit("encoder_thread_limit");
|
||||
ParseFieldTrial({&encoder_thread_limit},
|
||||
trials.Lookup("WebRTC-VideoEncoderSettings"));
|
||||
return encoder_thread_limit.GetOptional();
|
||||
}
|
||||
|
||||
absl::optional<VideoSourceRestrictions> MergeRestrictions(
|
||||
const std::vector<absl::optional<VideoSourceRestrictions>>& list) {
|
||||
absl::optional<VideoSourceRestrictions> return_value;
|
||||
@ -718,6 +725,7 @@ VideoStreamEncoder::VideoStreamEncoder(
|
||||
kSwitchEncoderOnInitializationFailuresFieldTrial)),
|
||||
vp9_low_tier_core_threshold_(
|
||||
ParseVp9LowTierCoreCountThreshold(field_trials)),
|
||||
experimental_encoder_thread_limit_(ParseEncoderThreadLimit(field_trials)),
|
||||
encoder_queue_(std::move(encoder_queue)) {
|
||||
TRACE_EVENT0("webrtc", "VideoStreamEncoder::VideoStreamEncoder");
|
||||
RTC_DCHECK_RUN_ON(worker_queue_);
|
||||
@ -1274,10 +1282,10 @@ void VideoStreamEncoder::ReconfigureEncoder() {
|
||||
const size_t max_data_payload_length = max_data_payload_length_ > 0
|
||||
? max_data_payload_length_
|
||||
: kDefaultPayloadSize;
|
||||
if (encoder_->InitEncode(
|
||||
&send_codec_,
|
||||
VideoEncoder::Settings(settings_.capabilities, number_of_cores_,
|
||||
max_data_payload_length)) != 0) {
|
||||
VideoEncoder::Settings settings = VideoEncoder::Settings(
|
||||
settings_.capabilities, number_of_cores_, max_data_payload_length);
|
||||
settings.encoder_thread_limit = experimental_encoder_thread_limit_;
|
||||
if (encoder_->InitEncode(&send_codec_, settings) != 0) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
|
||||
"codec type: "
|
||||
<< CodecTypeToPayloadString(send_codec_.codecType)
|
||||
|
||||
@ -463,6 +463,7 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
||||
bool switch_encoder_on_init_failures_;
|
||||
|
||||
const absl::optional<int> vp9_low_tier_core_threshold_;
|
||||
const absl::optional<int> experimental_encoder_thread_limit_;
|
||||
|
||||
// These are copies of restrictions (glorified max_pixel_count) set by
|
||||
// a) OnVideoSourceRestrictionsUpdated
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user