mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Enable multithreaded OpenH264 encoding behind field trial
This uses the field trial introduced is crbug.com/1406331 and extends the usage to OpenH264. This simplifies experimentation whether this change improves performance without requiring multi-slice encoding. BUG=webrtc:14368 Change-Id: I0031e59059f7113dd5453234869c957d46f311bb Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/294340 Reviewed-by: Erik Språng <sprang@webrtc.org> Reviewed-by: Sergey Silkin <ssilkin@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Philipp Hancke <phancke@microsoft.com> Cr-Commit-Position: refs/heads/main@{#39371}
This commit is contained in:
parent
b3c5bdb85a
commit
b660b7a89c
3 changed files with 30 additions and 16 deletions
|
@ -330,8 +330,8 @@ class RTC_EXPORT VideoEncoder {
|
||||||
Capabilities capabilities;
|
Capabilities capabilities;
|
||||||
int number_of_cores;
|
int number_of_cores;
|
||||||
size_t max_payload_size;
|
size_t max_payload_size;
|
||||||
// Experimental API - currently only supported by LibvpxVp8Encoder.
|
// Experimental API - currently only supported by LibvpxVp8Encoder and
|
||||||
// If set, limits the number of encoder threads.
|
// the OpenH264 encoder. If set, limits the number of encoder threads.
|
||||||
absl::optional<int> encoder_thread_limit;
|
absl::optional<int> encoder_thread_limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,19 +56,30 @@ enum H264EncoderImplEvent {
|
||||||
kH264EncoderEventMax = 16,
|
kH264EncoderEventMax = 16,
|
||||||
};
|
};
|
||||||
|
|
||||||
int NumberOfThreads(int width, int height, int number_of_cores) {
|
int NumberOfThreads(absl::optional<int> encoder_thread_limit,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int number_of_cores) {
|
||||||
// TODO(hbos): In Chromium, multiple threads do not work with sandbox on Mac,
|
// TODO(hbos): In Chromium, multiple threads do not work with sandbox on Mac,
|
||||||
// see crbug.com/583348. Until further investigated, only use one thread.
|
// see crbug.com/583348. Until further investigated, only use one thread.
|
||||||
// if (width * height >= 1920 * 1080 && number_of_cores > 8) {
|
// While this limitation is gone, this changes the bitstream format (see
|
||||||
// return 8; // 8 threads for 1080p on high perf machines.
|
// bugs.webrtc.org/14368) so still guarded by field trial to allow for
|
||||||
// } else if (width * height > 1280 * 960 && number_of_cores >= 6) {
|
// experimentation using th experimental
|
||||||
// return 3; // 3 threads for 1080p.
|
// WebRTC-VideoEncoderSettings/encoder_thread_limit trial.
|
||||||
// } else if (width * height > 640 * 480 && number_of_cores >= 3) {
|
if (encoder_thread_limit.has_value()) {
|
||||||
// return 2; // 2 threads for qHD/HD.
|
int limit = encoder_thread_limit.value();
|
||||||
// } else {
|
RTC_DCHECK_GE(limit, 1);
|
||||||
// return 1; // 1 thread for VGA or less.
|
if (width * height >= 1920 * 1080 && number_of_cores > 8) {
|
||||||
// }
|
return std::min(limit, 8); // 8 threads for 1080p on high perf machines.
|
||||||
// TODO(sprang): Also check sSliceArgument.uiSliceNum om GetEncoderPrams(),
|
} else if (width * height > 1280 * 960 && number_of_cores >= 6) {
|
||||||
|
return std::min(limit, 3); // 3 threads for 1080p.
|
||||||
|
} else if (width * height > 640 * 480 && number_of_cores >= 3) {
|
||||||
|
return std::min(limit, 2); // 2 threads for qHD/HD.
|
||||||
|
} else {
|
||||||
|
return 1; // 1 thread for VGA or less.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO(sprang): Also check sSliceArgument.uiSliceNum on GetEncoderParams(),
|
||||||
// before enabling multithreading here.
|
// before enabling multithreading here.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -223,8 +234,9 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
|
||||||
configurations_.resize(number_of_streams);
|
configurations_.resize(number_of_streams);
|
||||||
tl0sync_limit_.resize(number_of_streams);
|
tl0sync_limit_.resize(number_of_streams);
|
||||||
|
|
||||||
number_of_cores_ = settings.number_of_cores;
|
|
||||||
max_payload_size_ = settings.max_payload_size;
|
max_payload_size_ = settings.max_payload_size;
|
||||||
|
number_of_cores_ = settings.number_of_cores;
|
||||||
|
encoder_thread_limit_ = settings.encoder_thread_limit;
|
||||||
codec_ = *inst;
|
codec_ = *inst;
|
||||||
|
|
||||||
// Code expects simulcastStream resolutions to be correct, make sure they are
|
// Code expects simulcastStream resolutions to be correct, make sure they are
|
||||||
|
@ -626,8 +638,9 @@ SEncParamExt H264EncoderImpl::CreateEncoderParams(size_t i) const {
|
||||||
// 0: auto (dynamic imp. internal encoder)
|
// 0: auto (dynamic imp. internal encoder)
|
||||||
// 1: single thread (default value)
|
// 1: single thread (default value)
|
||||||
// >1: number of threads
|
// >1: number of threads
|
||||||
encoder_params.iMultipleThreadIdc = NumberOfThreads(
|
encoder_params.iMultipleThreadIdc =
|
||||||
encoder_params.iPicWidth, encoder_params.iPicHeight, number_of_cores_);
|
NumberOfThreads(encoder_thread_limit_, encoder_params.iPicWidth,
|
||||||
|
encoder_params.iPicHeight, number_of_cores_);
|
||||||
// The base spatial layer 0 is the only one we use.
|
// The base spatial layer 0 is the only one we use.
|
||||||
encoder_params.sSpatialLayers[0].iVideoWidth = encoder_params.iPicWidth;
|
encoder_params.sSpatialLayers[0].iVideoWidth = encoder_params.iPicWidth;
|
||||||
encoder_params.sSpatialLayers[0].iVideoHeight = encoder_params.iPicHeight;
|
encoder_params.sSpatialLayers[0].iVideoHeight = encoder_params.iPicHeight;
|
||||||
|
|
|
@ -110,6 +110,7 @@ class H264EncoderImpl : public H264Encoder {
|
||||||
H264PacketizationMode packetization_mode_;
|
H264PacketizationMode packetization_mode_;
|
||||||
size_t max_payload_size_;
|
size_t max_payload_size_;
|
||||||
int32_t number_of_cores_;
|
int32_t number_of_cores_;
|
||||||
|
absl::optional<int> encoder_thread_limit_;
|
||||||
EncodedImageCallback* encoded_image_callback_;
|
EncodedImageCallback* encoded_image_callback_;
|
||||||
|
|
||||||
bool has_reported_init_;
|
bool has_reported_init_;
|
||||||
|
|
Loading…
Reference in a new issue