diff --git a/api/video_codecs/video_encoder_factory.h b/api/video_codecs/video_encoder_factory.h index a84a297719..630b7aa70c 100644 --- a/api/video_codecs/video_encoder_factory.h +++ b/api/video_codecs/video_encoder_factory.h @@ -49,9 +49,9 @@ class VideoEncoderFactory { // used. virtual void OnCurrentEncoder(const SdpVideoFormat& format) = 0; - // Called every time the encoding bitrate is updated. Should return a + // Called every time the available bitrate is updated. Should return a // non-empty if an encoder switch should be performed. - virtual absl::optional OnEncodingBitrate( + virtual absl::optional OnAvailableBitrate( const DataRate& rate) = 0; // Called if the currently used encoder reports itself as broken. Should diff --git a/sdk/android/api/org/webrtc/VideoEncoderFactory.java b/sdk/android/api/org/webrtc/VideoEncoderFactory.java index 9c0f2b437c..3c598694be 100644 --- a/sdk/android/api/org/webrtc/VideoEncoderFactory.java +++ b/sdk/android/api/org/webrtc/VideoEncoderFactory.java @@ -19,16 +19,32 @@ public interface VideoEncoderFactory { @CalledByNative("VideoEncoderSelector") void onCurrentEncoder(VideoCodecInfo info); /** - * Called with the current encoding bitrate. Returns null if the encoder - * selector which to keep the current encoder or a VideoCodecInfo if a - * new encoder is preferred. + * Called with the current encoding bitrate. Returns null if the encoder selector prefers to + * keep the current encoder or a VideoCodecInfo if a new encoder is preferred. + * + *

TODO(bugs.webrtc.org/11341): Delete onEncodingBitrate and remove the default + * implementation for onAvailableBitrate once downstream project is updated. */ - @Nullable @CalledByNative("VideoEncoderSelector") VideoCodecInfo onEncodingBitrate(int kbps); + @Deprecated + @Nullable + default VideoCodecInfo onEncodingBitrate(int kbps) { + throw new UnsupportedOperationException("Not implemented."); + } /** - * Called when the currently used encoder signal itself as broken. Returns - * null if the encoder selector which to keep the current encoder or a - * VideoCodecInfo if a new encoder is preferred. + * Called with the current available bitrate. Returns null if the encoder selector prefers to + * keep the current encoder or a VideoCodecInfo if a new encoder is preferred. + */ + @Nullable + @CalledByNative("VideoEncoderSelector") + default VideoCodecInfo onAvailableBitrate(int kbps) { + return onEncodingBitrate(kbps); + } + + /** + * Called when the currently used encoder signal itself as broken. Returns null if the encoder + * selector prefers to keep the current encoder or a VideoCodecInfo if a new encoder is + * preferred. */ @Nullable @CalledByNative("VideoEncoderSelector") VideoCodecInfo onEncoderBroken(); } diff --git a/sdk/android/src/jni/video_encoder_factory_wrapper.cc b/sdk/android/src/jni/video_encoder_factory_wrapper.cc index 795f82bd8f..d6a6cfaf2d 100644 --- a/sdk/android/src/jni/video_encoder_factory_wrapper.cc +++ b/sdk/android/src/jni/video_encoder_factory_wrapper.cc @@ -36,12 +36,12 @@ class VideoEncoderSelectorWrapper j_codec_info); } - absl::optional OnEncodingBitrate( + absl::optional OnAvailableBitrate( const DataRate& rate) override { JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedJavaLocalRef codec_info = - Java_VideoEncoderSelector_onEncodingBitrate(jni, encoder_selector_, - rate.kbps()); + Java_VideoEncoderSelector_onAvailableBitrate(jni, encoder_selector_, + rate.kbps()); if (codec_info.is_null()) { return absl::nullopt; } diff --git a/test/video_encoder_proxy_factory.h b/test/video_encoder_proxy_factory.h index 46caf8df2d..70e2c8aaf2 100644 --- a/test/video_encoder_proxy_factory.h +++ b/test/video_encoder_proxy_factory.h @@ -140,9 +140,9 @@ class VideoEncoderProxyFactory final : public VideoEncoderFactory { encoder_selector_->OnCurrentEncoder(format); } - absl::optional OnEncodingBitrate( + absl::optional OnAvailableBitrate( const DataRate& rate) override { - return encoder_selector_->OnEncodingBitrate(rate); + return encoder_selector_->OnAvailableBitrate(rate); } absl::optional OnEncoderBroken() override { diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index eae5c0f2b4..b99e91185d 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -1565,7 +1565,8 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate, if (!video_is_suspended && settings_.encoder_switch_request_callback) { if (encoder_selector_) { - if (auto encoder = encoder_selector_->OnEncodingBitrate(target_bitrate)) { + if (auto encoder = + encoder_selector_->OnAvailableBitrate(link_allocation)) { settings_.encoder_switch_request_callback->RequestEncoderSwitch( *encoder); } diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index a8e51e891a..485543a39a 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -430,7 +430,7 @@ class MockEncoderSelector : public VideoEncoderFactory::EncoderSelectorInterface { public: MOCK_METHOD1(OnCurrentEncoder, void(const SdpVideoFormat& format)); - MOCK_METHOD1(OnEncodingBitrate, + MOCK_METHOD1(OnAvailableBitrate, absl::optional(const DataRate& rate)); MOCK_METHOD0(OnEncoderBroken, absl::optional()); }; @@ -5414,7 +5414,7 @@ TEST_F(VideoStreamEncoderTest, EncoderSelectorBitrateSwitch) { // Reset encoder for new configuration to take effect. ConfigureEncoder(video_encoder_config_.Copy()); - ON_CALL(encoder_selector, OnEncodingBitrate(_)) + ON_CALL(encoder_selector, OnAvailableBitrate(_)) .WillByDefault(Return(SdpVideoFormat("AV1"))); EXPECT_CALL(switch_callback, RequestEncoderSwitch(Matcher(