Execute cached video encoder switching request if encoder switching is allowed after the switch request was made.
Bug: webrtc:10795 Change-Id: Ib045794bf7ecec67812e1fad2ec8db987f6011df Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161943 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30067}
This commit is contained in:
parent
1e51a388bc
commit
dcb4fcc361
@ -735,7 +735,8 @@ void WebRtcVideoChannel::RequestEncoderSwitch(
|
||||
|
||||
if (!allow_codec_switching_) {
|
||||
RTC_LOG(LS_INFO) << "Encoder switch requested but codec switching has"
|
||||
<< " not been enabled.";
|
||||
<< " not been enabled yet.";
|
||||
requested_encoder_switch_ = conf;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1642,6 +1643,14 @@ void WebRtcVideoChannel::SetVideoCodecSwitchingEnabled(bool enabled) {
|
||||
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_, [this, enabled] {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
allow_codec_switching_ = enabled;
|
||||
if (allow_codec_switching_) {
|
||||
RTC_LOG(LS_INFO) << "Encoder switching enabled.";
|
||||
if (requested_encoder_switch_) {
|
||||
RTC_LOG(LS_INFO) << "Executing cached video encoder switch request.";
|
||||
RequestEncoderSwitch(*requested_encoder_switch_);
|
||||
requested_encoder_switch_.reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -590,6 +590,8 @@ class WebRtcVideoChannel : public VideoMediaChannel,
|
||||
RTC_GUARDED_BY(thread_checker_);
|
||||
|
||||
bool allow_codec_switching_ = false;
|
||||
absl::optional<EncoderSwitchRequestCallback::Config>
|
||||
requested_encoder_switch_;
|
||||
|
||||
// In order for the |invoker_| to protect other members from being destructed
|
||||
// as they are used in asynchronous tasks it has to be destructed first.
|
||||
|
||||
@ -2362,6 +2362,41 @@ TEST_F(WebRtcVideoChannelBaseTest, RequestEncoderSwitchIncorrectParam) {
|
||||
EXPECT_THAT(codec.params, Contains(Pair(kParam, kPing)));
|
||||
}
|
||||
|
||||
TEST_F(WebRtcVideoChannelBaseTest,
|
||||
RequestEncoderSwitchWithConfigBeforeEnabling) {
|
||||
const std::string kParam = "the-param";
|
||||
const std::string kPing = "ping";
|
||||
const std::string kPong = "pong";
|
||||
|
||||
cricket::VideoSendParameters parameters;
|
||||
VideoCodec vp9 = GetEngineCodec("VP9");
|
||||
vp9.params[kParam] = kPong;
|
||||
parameters.codecs.push_back(vp9);
|
||||
|
||||
VideoCodec vp8 = GetEngineCodec("VP8");
|
||||
vp8.params[kParam] = kPing;
|
||||
parameters.codecs.push_back(vp8);
|
||||
|
||||
EXPECT_TRUE(channel_->SetSendParameters(parameters));
|
||||
|
||||
VideoCodec codec;
|
||||
ASSERT_TRUE(channel_->GetSendCodec(&codec));
|
||||
EXPECT_THAT(codec.name, Eq("VP9"));
|
||||
|
||||
webrtc::EncoderSwitchRequestCallback::Config conf{"VP8", kParam, kPing};
|
||||
channel_->RequestEncoderSwitch(conf);
|
||||
|
||||
// Enable codec switching after it has been requested.
|
||||
channel_->SetVideoCodecSwitchingEnabled(true);
|
||||
|
||||
// RequestEncoderSwitch will post a task to the worker thread (which is also
|
||||
// the current thread), hence the ProcessMessages call.
|
||||
rtc::Thread::Current()->ProcessMessages(30);
|
||||
ASSERT_TRUE(channel_->GetSendCodec(&codec));
|
||||
EXPECT_THAT(codec.name, Eq("VP8"));
|
||||
EXPECT_THAT(codec.params, Contains(Pair(kParam, kPing)));
|
||||
}
|
||||
|
||||
class WebRtcVideoChannelTest : public WebRtcVideoEngineTest {
|
||||
public:
|
||||
WebRtcVideoChannelTest() : WebRtcVideoChannelTest("") {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user