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:
parent
e6994bc1f5
commit
4f34d78c85
@ -49,9 +49,9 @@ class VideoEncoderFactory {
|
|||||||
// used.
|
// used.
|
||||||
virtual void OnCurrentEncoder(const SdpVideoFormat& format) = 0;
|
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.
|
// non-empty if an encoder switch should be performed.
|
||||||
virtual absl::optional<SdpVideoFormat> OnEncodingBitrate(
|
virtual absl::optional<SdpVideoFormat> OnAvailableBitrate(
|
||||||
const DataRate& rate) = 0;
|
const DataRate& rate) = 0;
|
||||||
|
|
||||||
// Called if the currently used encoder reports itself as broken. Should
|
// Called if the currently used encoder reports itself as broken. Should
|
||||||
|
|||||||
@ -19,16 +19,32 @@ public interface VideoEncoderFactory {
|
|||||||
@CalledByNative("VideoEncoderSelector") void onCurrentEncoder(VideoCodecInfo info);
|
@CalledByNative("VideoEncoderSelector") void onCurrentEncoder(VideoCodecInfo info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called with the current encoding bitrate. Returns null if the encoder
|
* Called with the current encoding bitrate. Returns null if the encoder selector prefers to
|
||||||
* selector which to keep the current encoder or a VideoCodecInfo if a
|
* keep the current encoder or a VideoCodecInfo if a new encoder is preferred.
|
||||||
* 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
|
* Called with the current available bitrate. Returns null if the encoder selector prefers to
|
||||||
* null if the encoder selector which to keep the current encoder or a
|
* keep the current encoder or a VideoCodecInfo if a new encoder is preferred.
|
||||||
* 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();
|
@Nullable @CalledByNative("VideoEncoderSelector") VideoCodecInfo onEncoderBroken();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,11 +36,11 @@ class VideoEncoderSelectorWrapper
|
|||||||
j_codec_info);
|
j_codec_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<SdpVideoFormat> OnEncodingBitrate(
|
absl::optional<SdpVideoFormat> OnAvailableBitrate(
|
||||||
const DataRate& rate) override {
|
const DataRate& rate) override {
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
ScopedJavaLocalRef<jobject> codec_info =
|
ScopedJavaLocalRef<jobject> codec_info =
|
||||||
Java_VideoEncoderSelector_onEncodingBitrate(jni, encoder_selector_,
|
Java_VideoEncoderSelector_onAvailableBitrate(jni, encoder_selector_,
|
||||||
rate.kbps<int>());
|
rate.kbps<int>());
|
||||||
if (codec_info.is_null()) {
|
if (codec_info.is_null()) {
|
||||||
return absl::nullopt;
|
return absl::nullopt;
|
||||||
|
|||||||
@ -140,9 +140,9 @@ class VideoEncoderProxyFactory final : public VideoEncoderFactory {
|
|||||||
encoder_selector_->OnCurrentEncoder(format);
|
encoder_selector_->OnCurrentEncoder(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<SdpVideoFormat> OnEncodingBitrate(
|
absl::optional<SdpVideoFormat> OnAvailableBitrate(
|
||||||
const DataRate& rate) override {
|
const DataRate& rate) override {
|
||||||
return encoder_selector_->OnEncodingBitrate(rate);
|
return encoder_selector_->OnAvailableBitrate(rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<SdpVideoFormat> OnEncoderBroken() override {
|
absl::optional<SdpVideoFormat> OnEncoderBroken() override {
|
||||||
|
|||||||
@ -1565,7 +1565,8 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
|
|||||||
|
|
||||||
if (!video_is_suspended && settings_.encoder_switch_request_callback) {
|
if (!video_is_suspended && settings_.encoder_switch_request_callback) {
|
||||||
if (encoder_selector_) {
|
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(
|
settings_.encoder_switch_request_callback->RequestEncoderSwitch(
|
||||||
*encoder);
|
*encoder);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -430,7 +430,7 @@ class MockEncoderSelector
|
|||||||
: public VideoEncoderFactory::EncoderSelectorInterface {
|
: public VideoEncoderFactory::EncoderSelectorInterface {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD1(OnCurrentEncoder, void(const SdpVideoFormat& format));
|
MOCK_METHOD1(OnCurrentEncoder, void(const SdpVideoFormat& format));
|
||||||
MOCK_METHOD1(OnEncodingBitrate,
|
MOCK_METHOD1(OnAvailableBitrate,
|
||||||
absl::optional<SdpVideoFormat>(const DataRate& rate));
|
absl::optional<SdpVideoFormat>(const DataRate& rate));
|
||||||
MOCK_METHOD0(OnEncoderBroken, absl::optional<SdpVideoFormat>());
|
MOCK_METHOD0(OnEncoderBroken, absl::optional<SdpVideoFormat>());
|
||||||
};
|
};
|
||||||
@ -5414,7 +5414,7 @@ TEST_F(VideoStreamEncoderTest, EncoderSelectorBitrateSwitch) {
|
|||||||
// Reset encoder for new configuration to take effect.
|
// Reset encoder for new configuration to take effect.
|
||||||
ConfigureEncoder(video_encoder_config_.Copy());
|
ConfigureEncoder(video_encoder_config_.Copy());
|
||||||
|
|
||||||
ON_CALL(encoder_selector, OnEncodingBitrate(_))
|
ON_CALL(encoder_selector, OnAvailableBitrate(_))
|
||||||
.WillByDefault(Return(SdpVideoFormat("AV1")));
|
.WillByDefault(Return(SdpVideoFormat("AV1")));
|
||||||
EXPECT_CALL(switch_callback,
|
EXPECT_CALL(switch_callback,
|
||||||
RequestEncoderSwitch(Matcher<const SdpVideoFormat&>(
|
RequestEncoderSwitch(Matcher<const SdpVideoFormat&>(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user