Report available instead of encoding bitrate to VideoEncoderSelector.

The encoding bitrate might be limited depending on the current encoder.

Bug: webrtc:11341
Change-Id: I734fce12734b1e703e7948847cdb1365c08a137b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169123
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Mirta Dvornicic <mirtad@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30619}
This commit is contained in:
Mirta Dvornicic 2020-02-26 13:01:19 +01:00 committed by Commit Bot
parent e6994bc1f5
commit 4f34d78c85
6 changed files with 34 additions and 17 deletions

View File

@ -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<SdpVideoFormat> OnEncodingBitrate(
virtual absl::optional<SdpVideoFormat> OnAvailableBitrate(
const DataRate& rate) = 0;
// Called if the currently used encoder reports itself as broken. Should

View File

@ -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.
*
* <p>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();
}

View File

@ -36,12 +36,12 @@ class VideoEncoderSelectorWrapper
j_codec_info);
}
absl::optional<SdpVideoFormat> OnEncodingBitrate(
absl::optional<SdpVideoFormat> OnAvailableBitrate(
const DataRate& rate) override {
JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedJavaLocalRef<jobject> codec_info =
Java_VideoEncoderSelector_onEncodingBitrate(jni, encoder_selector_,
rate.kbps<int>());
Java_VideoEncoderSelector_onAvailableBitrate(jni, encoder_selector_,
rate.kbps<int>());
if (codec_info.is_null()) {
return absl::nullopt;
}

View File

@ -140,9 +140,9 @@ class VideoEncoderProxyFactory final : public VideoEncoderFactory {
encoder_selector_->OnCurrentEncoder(format);
}
absl::optional<SdpVideoFormat> OnEncodingBitrate(
absl::optional<SdpVideoFormat> OnAvailableBitrate(
const DataRate& rate) override {
return encoder_selector_->OnEncodingBitrate(rate);
return encoder_selector_->OnAvailableBitrate(rate);
}
absl::optional<SdpVideoFormat> OnEncoderBroken() override {

View File

@ -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);
}

View File

@ -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<SdpVideoFormat>(const DataRate& rate));
MOCK_METHOD0(OnEncoderBroken, absl::optional<SdpVideoFormat>());
};
@ -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<const SdpVideoFormat&>(