From 5981bf2eb66858eeea2072a81ac122433b10a3b7 Mon Sep 17 00:00:00 2001 From: Peter Hanspers Date: Tue, 1 Jun 2021 07:31:00 +0200 Subject: [PATCH] Add resolution alignment properties to RTCVideoEncoder protocol. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this change, RTCVideoEncoder can specify: - requested_resolution_alignment, - apply_alignment_to_all_simulcast_layers in the same way scaling_settings is specified. Change-Id: I3de79a2eabaae581d6a9f2ef3e39496b9545a4f5 Bug: webrtc:12829 Change-Id: I3de79a2eabaae581d6a9f2ef3e39496b9545a4f5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/220933 Reviewed-by: Kári Helgason Reviewed-by: Åsa Persson Reviewed-by: Abby Yeh Commit-Queue: Peter Hanspers Cr-Commit-Position: refs/heads/master@{#34196} --- .../api/video_codec/RTCWrappedNativeVideoEncoder.mm | 10 ++++++++++ sdk/objc/base/RTCVideoEncoder.h | 7 +++++++ sdk/objc/components/video_codec/RTCVideoEncoderH264.mm | 8 ++++++++ sdk/objc/native/src/objc_video_encoder_factory.mm | 2 ++ 4 files changed, 27 insertions(+) diff --git a/sdk/objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm b/sdk/objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm index 843b6ad001..ea2a459360 100644 --- a/sdk/objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm +++ b/sdk/objc/api/video_codec/RTCWrappedNativeVideoEncoder.mm @@ -69,4 +69,14 @@ return nil; } +- (NSInteger)resolutionAlignment { + RTC_NOTREACHED(); + return 1; +} + +- (BOOL)applyAlignmentToAllSimulcastLayers { + RTC_NOTREACHED(); + return NO; +} + @end diff --git a/sdk/objc/base/RTCVideoEncoder.h b/sdk/objc/base/RTCVideoEncoder.h index 29e8a89901..f5b24d8fa5 100644 --- a/sdk/objc/base/RTCVideoEncoder.h +++ b/sdk/objc/base/RTCVideoEncoder.h @@ -43,6 +43,13 @@ RTC_OBJC_EXPORT * disables quality scaling. */ - (nullable RTC_OBJC_TYPE(RTCVideoEncoderQpThresholds) *)scalingSettings; +/** Resolutions should be aligned to this value. */ +@property(nonatomic, readonly) NSInteger resolutionAlignment; + +/** If enabled, resolution alignment is applied to all simulcast layers simultaneously so that when + scaled, all resolutions comply with 'resolutionAlignment'. */ +@property(nonatomic, readonly) BOOL applyAlignmentToAllSimulcastLayers; + @end NS_ASSUME_NONNULL_END diff --git a/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm b/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm index e64f61912a..ae03bf8c86 100644 --- a/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm +++ b/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm @@ -529,6 +529,14 @@ NSUInteger GetMaxSampleRate(const webrtc::H264ProfileLevelId &profile_level_id) return WEBRTC_VIDEO_CODEC_OK; } +- (NSInteger)resolutionAlignment { + return 1; +} + +- (BOOL)applyAlignmentToAllSimulcastLayers { + return NO; +} + #pragma mark - Private - (NSInteger)releaseEncoder { diff --git a/sdk/objc/native/src/objc_video_encoder_factory.mm b/sdk/objc/native/src/objc_video_encoder_factory.mm index e51fc9d319..13185aa9e0 100644 --- a/sdk/objc/native/src/objc_video_encoder_factory.mm +++ b/sdk/objc/native/src/objc_video_encoder_factory.mm @@ -95,6 +95,8 @@ class ObjCVideoEncoder : public VideoEncoder { info.scaling_settings = qp_thresholds ? ScalingSettings(qp_thresholds.low, qp_thresholds.high) : ScalingSettings::kOff; + info.requested_resolution_alignment = encoder_.resolutionAlignment > 0 ?: 1; + info.apply_alignment_to_all_simulcast_layers = encoder_.applyAlignmentToAllSimulcastLayers; info.is_hardware_accelerated = true; info.has_internal_source = false; return info;