diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index 96df0f7f0c..2d9879c2ef 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -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() { diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index 8831a1b9c5..2b2e107345 100644 --- a/talk/media/webrtc/webrtcvideoengine2.h +++ b/talk/media/webrtc/webrtcvideoengine2.h @@ -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); diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index 85b7b9e55b..814aa93644 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -330,6 +330,9 @@ class WebRtcVideoEngine2Test : public ::testing::Test { VideoMediaChannel* SetUpForExternalEncoderFactory( cricket::WebRtcVideoEncoderFactory* encoder_factory, const std::vector& 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 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 channel(