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;
|
||||
int number_of_cores;
|
||||
size_t max_payload_size;
|
||||
// Experimental API - currently only supported by LibvpxVp8Encoder.
|
||||
// If set, limits the number of encoder threads.
|
||||
// Experimental API - currently only supported by LibvpxVp8Encoder and
|
||||
// the OpenH264 encoder. If set, limits the number of encoder threads.
|
||||
absl::optional<int> encoder_thread_limit;
|
||||
};
|
||||
|
||||
|
|
|
@ -56,19 +56,30 @@ enum H264EncoderImplEvent {
|
|||
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,
|
||||
// see crbug.com/583348. Until further investigated, only use one thread.
|
||||
// if (width * height >= 1920 * 1080 && number_of_cores > 8) {
|
||||
// return 8; // 8 threads for 1080p on high perf machines.
|
||||
// } else if (width * height > 1280 * 960 && number_of_cores >= 6) {
|
||||
// return 3; // 3 threads for 1080p.
|
||||
// } else if (width * height > 640 * 480 && number_of_cores >= 3) {
|
||||
// return 2; // 2 threads for qHD/HD.
|
||||
// } else {
|
||||
// return 1; // 1 thread for VGA or less.
|
||||
// }
|
||||
// TODO(sprang): Also check sSliceArgument.uiSliceNum om GetEncoderPrams(),
|
||||
// While this limitation is gone, this changes the bitstream format (see
|
||||
// bugs.webrtc.org/14368) so still guarded by field trial to allow for
|
||||
// experimentation using th experimental
|
||||
// WebRTC-VideoEncoderSettings/encoder_thread_limit trial.
|
||||
if (encoder_thread_limit.has_value()) {
|
||||
int limit = encoder_thread_limit.value();
|
||||
RTC_DCHECK_GE(limit, 1);
|
||||
if (width * height >= 1920 * 1080 && number_of_cores > 8) {
|
||||
return std::min(limit, 8); // 8 threads for 1080p on high perf machines.
|
||||
} 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.
|
||||
return 1;
|
||||
}
|
||||
|
@ -223,8 +234,9 @@ int32_t H264EncoderImpl::InitEncode(const VideoCodec* inst,
|
|||
configurations_.resize(number_of_streams);
|
||||
tl0sync_limit_.resize(number_of_streams);
|
||||
|
||||
number_of_cores_ = settings.number_of_cores;
|
||||
max_payload_size_ = settings.max_payload_size;
|
||||
number_of_cores_ = settings.number_of_cores;
|
||||
encoder_thread_limit_ = settings.encoder_thread_limit;
|
||||
codec_ = *inst;
|
||||
|
||||
// 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)
|
||||
// 1: single thread (default value)
|
||||
// >1: number of threads
|
||||
encoder_params.iMultipleThreadIdc = NumberOfThreads(
|
||||
encoder_params.iPicWidth, encoder_params.iPicHeight, number_of_cores_);
|
||||
encoder_params.iMultipleThreadIdc =
|
||||
NumberOfThreads(encoder_thread_limit_, encoder_params.iPicWidth,
|
||||
encoder_params.iPicHeight, number_of_cores_);
|
||||
// The base spatial layer 0 is the only one we use.
|
||||
encoder_params.sSpatialLayers[0].iVideoWidth = encoder_params.iPicWidth;
|
||||
encoder_params.sSpatialLayers[0].iVideoHeight = encoder_params.iPicHeight;
|
||||
|
|
|
@ -110,6 +110,7 @@ class H264EncoderImpl : public H264Encoder {
|
|||
H264PacketizationMode packetization_mode_;
|
||||
size_t max_payload_size_;
|
||||
int32_t number_of_cores_;
|
||||
absl::optional<int> encoder_thread_limit_;
|
||||
EncodedImageCallback* encoded_image_callback_;
|
||||
|
||||
bool has_reported_init_;
|
||||
|
|
Loading…
Reference in a new issue