Set up start bitrate in WebRtcVideoEngine2.

R=stefan@webrtc.org
BUG=1788

Review URL: https://webrtc-codereview.appspot.com/27789004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7476 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org 2014-10-20 11:07:07 +00:00
parent b35b136480
commit fa553ef605
3 changed files with 69 additions and 4 deletions

View File

@ -419,10 +419,11 @@ WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel(
assert(initialized_);
LOG(LS_INFO) << "CreateChannel: "
<< (voice_channel != NULL ? "With" : "Without")
<< " voice channel.";
<< " voice channel. Options: " << options.ToString();
WebRtcVideoChannel2* channel =
new WebRtcVideoChannel2(call_factory_,
voice_channel,
options,
external_encoder_factory_,
external_decoder_factory_,
GetVideoEncoderFactory());
@ -430,7 +431,6 @@ WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel(
delete channel;
return NULL;
}
channel->SetOptions(options);
channel->SetRecvCodecs(video_codecs_);
return channel;
}
@ -745,6 +745,7 @@ class WebRtcVideoRenderFrame : public VideoFrame {
WebRtcVideoChannel2::WebRtcVideoChannel2(
WebRtcCallFactory* call_factory,
VoiceMediaChannel* voice_channel,
const VideoOptions& options,
WebRtcVideoEncoderFactory* external_encoder_factory,
WebRtcVideoDecoderFactory* external_decoder_factory,
WebRtcVideoEncoderFactory2* encoder_factory)
@ -753,15 +754,21 @@ WebRtcVideoChannel2::WebRtcVideoChannel2(
external_decoder_factory_(external_decoder_factory),
encoder_factory_(encoder_factory) {
// TODO(pbos): Connect the video and audio with |voice_channel|.
SetDefaultOptions();
options_.SetAll(options);
webrtc::Call::Config config(this);
config.overuse_callback = this;
// Set start bitrate for the call. A default is provided by SetDefaultOptions.
int start_bitrate_kbps;
options_.video_start_bitrate.Get(&start_bitrate_kbps);
config.stream_start_bitrate_bps = start_bitrate_kbps * 1000;
call_.reset(call_factory->CreateCall(config));
rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc;
sending_ = false;
default_send_ssrc_ = 0;
SetDefaultOptions();
}
void WebRtcVideoChannel2::SetDefaultOptions() {
@ -769,6 +776,8 @@ void WebRtcVideoChannel2::SetDefaultOptions() {
options_.suspend_below_min_bitrate.Set(false);
options_.use_payload_padding.Set(false);
options_.video_noise_reduction.Set(true);
options_.video_start_bitrate.Set(
webrtc::Call::Config::kDefaultStartBitrateBps / 1000);
}
WebRtcVideoChannel2::~WebRtcVideoChannel2() {

View File

@ -212,6 +212,7 @@ class WebRtcVideoChannel2 : public rtc::MessageHandler,
public:
WebRtcVideoChannel2(WebRtcCallFactory* call_factory,
VoiceMediaChannel* voice_channel,
const VideoOptions& options,
WebRtcVideoEncoderFactory* external_encoder_factory,
WebRtcVideoDecoderFactory* external_decoder_factory,
WebRtcVideoEncoderFactory2* encoder_factory);

View File

@ -330,6 +330,9 @@ class WebRtcVideoEngine2Test : public ::testing::Test {
VideoMediaChannel* SetUpForExternalEncoderFactory(
cricket::WebRtcVideoEncoderFactory* encoder_factory,
const std::vector<VideoCodec>& codecs);
void TestStartBitrate(bool override_start_bitrate, int start_bitrate_bps);
WebRtcVideoEngine2 engine_;
VideoCodec default_codec_;
VideoCodec default_red_codec_;
@ -425,6 +428,58 @@ TEST_F(WebRtcVideoEngine2Test, SupportsAbsoluteSenderTimeHeaderExtension) {
FAIL() << "Absolute Sender Time extension not in header-extension list.";
}
void WebRtcVideoEngine2Test::TestStartBitrate(bool override_start_bitrate,
int start_bitrate_bps) {
class FakeCallFactory : public WebRtcCallFactory {
public:
FakeCallFactory() : fake_call_(NULL) {}
FakeCall* GetCall() {
return fake_call_;
}
private:
virtual webrtc::Call* CreateCall(
const webrtc::Call::Config& config) OVERRIDE {
assert(fake_call_ == NULL);
fake_call_ = new FakeCall(config);
return fake_call_;
}
FakeCall* fake_call_;
};
FakeCallFactory call_factory;
engine_.SetCallFactory(&call_factory);
engine_.Init(rtc::Thread::Current());
cricket::VideoOptions options;
if (override_start_bitrate) {
options.video_start_bitrate.Set(start_bitrate_bps / 1000);
}
rtc::scoped_ptr<VideoMediaChannel> channel(
engine_.CreateChannel(options, NULL));
EXPECT_EQ(override_start_bitrate
? start_bitrate_bps
: webrtc::Call::Config::kDefaultStartBitrateBps,
call_factory.GetCall()->GetConfig().stream_start_bitrate_bps);
}
TEST_F(WebRtcVideoEngine2Test, UsesCorrectDefaultStartBitrate) {
TestStartBitrate(false, -1);
}
TEST_F(WebRtcVideoEngine2Test, CreateChannelCanUseIncreasedStartBitrate) {
TestStartBitrate(true, 2 * webrtc::Call::Config::kDefaultStartBitrateBps);
}
TEST_F(WebRtcVideoEngine2Test, CreateChannelCanUseDecreasedStartBitrate) {
TestStartBitrate(true, webrtc::Call::Config::kDefaultStartBitrateBps / 2);
}
TEST_F(WebRtcVideoEngine2Test, SetSendFailsBeforeSettingCodecs) {
engine_.Init(rtc::Thread::Current());
rtc::scoped_ptr<VideoMediaChannel> channel(