diff --git a/talk/app/webrtc/statscollector_unittest.cc b/talk/app/webrtc/statscollector_unittest.cc index 2f4c1305b0..2e55af9b50 100644 --- a/talk/app/webrtc/statscollector_unittest.cc +++ b/talk/app/webrtc/statscollector_unittest.cc @@ -90,9 +90,8 @@ class MockWebRtcSession : public webrtc::WebRtcSession { class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel { public: - MockVideoMediaChannel() - : cricket::FakeVideoMediaChannel(NULL) { - } + MockVideoMediaChannel() : cricket::FakeVideoMediaChannel(NULL) {} + // MOCK_METHOD0(transport_channel, cricket::TransportChannel*()); MOCK_METHOD2(GetStats, bool(const StatsOptions&, cricket::VideoMediaInfo*)); }; diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc index 13e2128223..402edc2acb 100644 --- a/talk/app/webrtc/webrtcsession.cc +++ b/talk/app/webrtc/webrtcsession.cc @@ -1533,12 +1533,8 @@ bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) { bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) { video_channel_.reset(channel_manager_->CreateVideoChannel( - this, content->name, true, voice_channel_.get())); - if (!video_channel_.get()) - return false; - - video_channel_->SetChannelOptions(video_options_); - return true; + this, content->name, true, video_options_, voice_channel_.get())); + return video_channel_.get() != NULL; } bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) { diff --git a/talk/media/base/fakemediaengine.h b/talk/media/base/fakemediaengine.h index 8c73cfcd27..87bc8a3ee6 100644 --- a/talk/media/base/fakemediaengine.h +++ b/talk/media/base/fakemediaengine.h @@ -477,6 +477,7 @@ class FakeVideoMediaChannel : public RtpHelper { sent_intra_frame_(false), requested_intra_frame_(false), max_bps_(-1) {} + ~FakeVideoMediaChannel(); const std::vector& recv_codecs() const { return recv_codecs_; } @@ -885,12 +886,14 @@ class FakeVideoEngine : public FakeBaseEngine { return default_encoder_config_; } - VideoMediaChannel* CreateChannel(VoiceMediaChannel* channel) { + VideoMediaChannel* CreateChannel(const VideoOptions& options, + VoiceMediaChannel* channel) { if (fail_create_channel_) { return NULL; } FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this); + ch->SetOptions(options); channels_.push_back(ch); return ch; } diff --git a/talk/media/base/filemediaengine.cc b/talk/media/base/filemediaengine.cc index 460b2050a8..6e1411a4c6 100644 --- a/talk/media/base/filemediaengine.cc +++ b/talk/media/base/filemediaengine.cc @@ -88,6 +88,7 @@ VoiceMediaChannel* FileMediaEngine::CreateChannel() { } VideoMediaChannel* FileMediaEngine::CreateVideoChannel( + const VideoOptions& options, VoiceMediaChannel* voice_ch) { rtc::FileStream* input_file_stream = NULL; rtc::FileStream* output_file_stream = NULL; @@ -114,8 +115,10 @@ VideoMediaChannel* FileMediaEngine::CreateVideoChannel( } } - return new FileVideoChannel(input_file_stream, output_file_stream, - rtp_sender_thread_); + FileVideoChannel* channel = new FileVideoChannel( + input_file_stream, output_file_stream, rtp_sender_thread_); + channel->SetOptions(options); + return channel; } /////////////////////////////////////////////////////////////////////////// diff --git a/talk/media/base/filemediaengine.h b/talk/media/base/filemediaengine.h index 5d90f01c77..9cc066d142 100644 --- a/talk/media/base/filemediaengine.h +++ b/talk/media/base/filemediaengine.h @@ -84,7 +84,8 @@ class FileMediaEngine : public MediaEngineInterface { virtual void Terminate() {} virtual int GetCapabilities(); virtual VoiceMediaChannel* CreateChannel(); - virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch); + virtual VideoMediaChannel* CreateVideoChannel(const VideoOptions& options, + VoiceMediaChannel* voice_ch); virtual SoundclipMedia* CreateSoundclip() { return NULL; } virtual AudioOptions GetAudioOptions() const { return AudioOptions(); } virtual bool SetAudioOptions(const AudioOptions& options) { return true; } diff --git a/talk/media/base/filemediaengine_unittest.cc b/talk/media/base/filemediaengine_unittest.cc index c542bafba2..2987dbab79 100644 --- a/talk/media/base/filemediaengine_unittest.cc +++ b/talk/media/base/filemediaengine_unittest.cc @@ -139,7 +139,7 @@ class FileMediaEngineTest : public testing::Test { engine_->set_rtp_sender_thread(rtc::Thread::Current()); voice_channel_.reset(engine_->CreateChannel()); - video_channel_.reset(engine_->CreateVideoChannel(NULL)); + video_channel_.reset(engine_->CreateVideoChannel(VideoOptions(), NULL)); return ret; } @@ -247,7 +247,7 @@ TEST_F(FileMediaEngineTest, TestBadFilePath) { engine_->set_voice_input_filename(kFakeFileName); engine_->set_video_input_filename(kFakeFileName); EXPECT_TRUE(engine_->CreateChannel() == NULL); - EXPECT_TRUE(engine_->CreateVideoChannel(NULL) == NULL); + EXPECT_TRUE(engine_->CreateVideoChannel(VideoOptions(), NULL) == NULL); } TEST_F(FileMediaEngineTest, TestCodecs) { diff --git a/talk/media/base/mediaengine.h b/talk/media/base/mediaengine.h index f30e3b1c30..e7222f2d4e 100644 --- a/talk/media/base/mediaengine.h +++ b/talk/media/base/mediaengine.h @@ -80,7 +80,8 @@ class MediaEngineInterface { virtual VoiceMediaChannel *CreateChannel() = 0; // Creates a video media channel, paired with the specified voice channel. // Returns NULL on failure. - virtual VideoMediaChannel *CreateVideoChannel( + virtual VideoMediaChannel* CreateVideoChannel( + const VideoOptions& options, VoiceMediaChannel* voice_media_channel) = 0; // Creates a soundclip object for playing sounds on. Returns NULL on failure. @@ -198,8 +199,9 @@ class CompositeMediaEngine : public MediaEngineInterface { virtual VoiceMediaChannel *CreateChannel() { return voice_.CreateChannel(); } - virtual VideoMediaChannel *CreateVideoChannel(VoiceMediaChannel* channel) { - return video_.CreateChannel(channel); + virtual VideoMediaChannel* CreateVideoChannel(const VideoOptions& options, + VoiceMediaChannel* channel) { + return video_.CreateChannel(options, channel); } virtual SoundclipMedia *CreateSoundclip() { return voice_.CreateSoundclip(); diff --git a/talk/media/base/videoengine_unittest.h b/talk/media/base/videoengine_unittest.h index 691bef8d41..6ea5b8cff5 100644 --- a/talk/media/base/videoengine_unittest.h +++ b/talk/media/base/videoengine_unittest.h @@ -495,7 +495,7 @@ class VideoMediaChannelTest : public testing::Test, virtual void SetUp() { cricket::Device device("test", "device"); EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - channel_.reset(engine_.CreateChannel(NULL)); + channel_.reset(engine_.CreateChannel(cricket::VideoOptions(), NULL)); EXPECT_TRUE(channel_.get() != NULL); ConnectVideoChannelError(); network_interface_.SetDestination(channel_.get()); diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc index 8cc5fed66b..a42491f20e 100644 --- a/talk/media/webrtc/webrtcvideoengine.cc +++ b/talk/media/webrtc/webrtcvideoengine.cc @@ -1113,11 +1113,21 @@ bool WebRtcVideoEngine::SetDefaultCodec(const VideoCodec& codec) { WebRtcVideoMediaChannel* WebRtcVideoEngine::CreateChannel( VoiceMediaChannel* voice_channel) { + return CreateChannel(VideoOptions(), voice_channel); +} + +WebRtcVideoMediaChannel* WebRtcVideoEngine::CreateChannel( + const VideoOptions& options, + VoiceMediaChannel* voice_channel) { WebRtcVideoMediaChannel* channel = new WebRtcVideoMediaChannel(this, voice_channel); if (!channel->Init()) { delete channel; - channel = NULL; + return NULL; + } + + if (!channel->SetOptions(options)) { + LOG(LS_WARNING) << "Failed to set options while creating channel."; } return channel; } diff --git a/talk/media/webrtc/webrtcvideoengine.h b/talk/media/webrtc/webrtcvideoengine.h index 9dd8dc8f16..72ba9df75e 100644 --- a/talk/media/webrtc/webrtcvideoengine.h +++ b/talk/media/webrtc/webrtcvideoengine.h @@ -110,8 +110,12 @@ class WebRtcVideoEngine : public sigslot::has_slots<>, bool SetDefaultEncoderConfig(const VideoEncoderConfig& config); VideoEncoderConfig GetDefaultEncoderConfig() const; + // TODO(pbos): Remove when all call sites use VideoOptions. virtual WebRtcVideoMediaChannel* CreateChannel( VoiceMediaChannel* voice_channel); + virtual WebRtcVideoMediaChannel* CreateChannel( + const VideoOptions& options, + VoiceMediaChannel* voice_channel); const std::vector& codecs() const; const std::vector& rtp_header_extensions() const; diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index 628ed509ec..96df0f7f0c 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -414,6 +414,7 @@ VideoEncoderConfig WebRtcVideoEngine2::GetDefaultEncoderConfig() const { } WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( + const VideoOptions& options, VoiceMediaChannel* voice_channel) { assert(initialized_); LOG(LS_INFO) << "CreateChannel: " @@ -429,6 +430,7 @@ WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( delete channel; return NULL; } + channel->SetOptions(options); channel->SetRecvCodecs(video_codecs_); return channel; } diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index 6b9eaa76f5..8831a1b9c5 100644 --- a/talk/media/webrtc/webrtcvideoengine2.h +++ b/talk/media/webrtc/webrtcvideoengine2.h @@ -147,7 +147,8 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { bool SetDefaultEncoderConfig(const VideoEncoderConfig& config); VideoEncoderConfig GetDefaultEncoderConfig() const; - WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel); + WebRtcVideoChannel2* CreateChannel(const VideoOptions& options, + VoiceMediaChannel* voice_channel); const std::vector& codecs() const; const std::vector& rtp_header_extensions() const; diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index 0cac1d525d..85b7b9e55b 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -427,7 +427,8 @@ TEST_F(WebRtcVideoEngine2Test, SupportsAbsoluteSenderTimeHeaderExtension) { TEST_F(WebRtcVideoEngine2Test, SetSendFailsBeforeSettingCodecs) { engine_.Init(rtc::Thread::Current()); - rtc::scoped_ptr channel(engine_.CreateChannel(NULL)); + rtc::scoped_ptr channel( + engine_.CreateChannel(cricket::VideoOptions(), NULL)); EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); @@ -439,7 +440,8 @@ TEST_F(WebRtcVideoEngine2Test, SetSendFailsBeforeSettingCodecs) { TEST_F(WebRtcVideoEngine2Test, GetStatsWithoutSendCodecsSetDoesNotCrash) { engine_.Init(rtc::Thread::Current()); - rtc::scoped_ptr channel(engine_.CreateChannel(NULL)); + rtc::scoped_ptr channel( + engine_.CreateChannel(cricket::VideoOptions(), NULL)); EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); VideoMediaInfo info; channel->GetStats(&info); @@ -483,7 +485,8 @@ VideoMediaChannel* WebRtcVideoEngine2Test::SetUpForExternalEncoderFactory( engine_.SetExternalEncoderFactory(encoder_factory); engine_.Init(rtc::Thread::Current()); - VideoMediaChannel* channel = engine_.CreateChannel(NULL); + VideoMediaChannel* channel = + engine_.CreateChannel(cricket::VideoOptions(), NULL); EXPECT_TRUE(channel->SetSendCodecs(codecs)); return channel; @@ -685,7 +688,7 @@ class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test, virtual void SetUp() OVERRIDE { engine_.SetCallFactory(this); engine_.Init(rtc::Thread::Current()); - channel_.reset(engine_.CreateChannel(NULL)); + channel_.reset(engine_.CreateChannel(cricket::VideoOptions(), NULL)); ASSERT_TRUE(fake_call_ != NULL) << "Call not created through factory."; last_ssrc_ = 123; ASSERT_TRUE(channel_->SetSendCodecs(engine_.codecs())); diff --git a/talk/media/webrtc/webrtcvideoengine_unittest.cc b/talk/media/webrtc/webrtcvideoengine_unittest.cc index c65e2cafd7..b471ff7e89 100644 --- a/talk/media/webrtc/webrtcvideoengine_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine_unittest.cc @@ -101,7 +101,7 @@ class WebRtcVideoEngineTestFake : public testing::Test, bool SetupEngine() { bool result = engine_.Init(rtc::Thread::Current()); if (result) { - channel_ = engine_.CreateChannel(voice_channel_); + channel_ = engine_.CreateChannel(cricket::VideoOptions(), voice_channel_); channel_->SignalMediaError.connect(this, &WebRtcVideoEngineTestFake::OnMediaError); result = (channel_ != NULL); @@ -342,7 +342,7 @@ TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) { // Tests that we can create and destroy a channel. TEST_F(WebRtcVideoEngineTestFake, CreateChannel) { EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - channel_ = engine_.CreateChannel(voice_channel_); + channel_ = engine_.CreateChannel(cricket::VideoOptions(), voice_channel_); EXPECT_TRUE(channel_ != NULL); EXPECT_EQ(1, engine_.GetNumOfChannels()); delete channel_; @@ -354,7 +354,7 @@ TEST_F(WebRtcVideoEngineTestFake, CreateChannel) { TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) { vie_.set_fail_create_channel(true); EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - channel_ = engine_.CreateChannel(voice_channel_); + channel_ = engine_.CreateChannel(cricket::VideoOptions(), voice_channel_); EXPECT_TRUE(channel_ == NULL); } @@ -362,7 +362,7 @@ TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) { TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) { vie_.set_fail_alloc_capturer(true); EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - channel_ = engine_.CreateChannel(voice_channel_); + channel_ = engine_.CreateChannel(cricket::VideoOptions(), voice_channel_); EXPECT_TRUE(channel_ == NULL); } @@ -2311,7 +2311,8 @@ TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) { TEST_F(WebRtcVideoEngineTest, CreateChannel) { EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL); + cricket::VideoMediaChannel* channel = + engine_.CreateChannel(cricket::VideoOptions(), NULL); EXPECT_TRUE(channel != NULL); delete channel; } diff --git a/talk/session/media/call.cc b/talk/session/media/call.cc index 4fbdd0faf3..ad28130328 100644 --- a/talk/session/media/call.cc +++ b/talk/session/media/call.cc @@ -282,7 +282,11 @@ bool Call::AddSession(Session* session, const SessionDescription* offer) { if (has_video_ && succeeded) { media_session.video_channel = session_client_->channel_manager()->CreateVideoChannel( - session, video_offer->name, true, media_session.voice_channel); + session, + video_offer->name, + true, + VideoOptions(), + media_session.voice_channel); // video_channel can be NULL in case of NullVideoEngine. if (media_session.video_channel) { media_session.video_channel->SignalMediaMonitor.connect( diff --git a/talk/session/media/channelmanager.cc b/talk/session/media/channelmanager.cc index f40396d928..ecfe851ad9 100644 --- a/talk/session/media/channelmanager.cc +++ b/talk/session/media/channelmanager.cc @@ -362,22 +362,48 @@ void ChannelManager::DestroyVoiceChannel_w(VoiceChannel* voice_channel) { } VideoChannel* ChannelManager::CreateVideoChannel( - BaseSession* session, const std::string& content_name, bool rtcp, + BaseSession* session, + const std::string& content_name, + bool rtcp, VoiceChannel* voice_channel) { return worker_thread_->Invoke( - Bind(&ChannelManager::CreateVideoChannel_w, this, session, - content_name, rtcp, voice_channel)); + Bind(&ChannelManager::CreateVideoChannel_w, + this, + session, + content_name, + rtcp, + VideoOptions(), + voice_channel)); +} + +VideoChannel* ChannelManager::CreateVideoChannel( + BaseSession* session, + const std::string& content_name, + bool rtcp, + const VideoOptions& options, + VoiceChannel* voice_channel) { + return worker_thread_->Invoke( + Bind(&ChannelManager::CreateVideoChannel_w, + this, + session, + content_name, + rtcp, + options, + voice_channel)); } VideoChannel* ChannelManager::CreateVideoChannel_w( - BaseSession* session, const std::string& content_name, bool rtcp, + BaseSession* session, + const std::string& content_name, + bool rtcp, + const VideoOptions& options, VoiceChannel* voice_channel) { // This is ok to alloc from a thread other than the worker thread ASSERT(initialized_); VideoMediaChannel* media_channel = // voice_channel can be NULL in case of NullVoiceEngine. - media_engine_->CreateVideoChannel(voice_channel ? - voice_channel->media_channel() : NULL); + media_engine_->CreateVideoChannel( + options, voice_channel ? voice_channel->media_channel() : NULL); if (media_channel == NULL) return NULL; diff --git a/talk/session/media/channelmanager.h b/talk/session/media/channelmanager.h index fa7901417c..98a3c96a8b 100644 --- a/talk/session/media/channelmanager.h +++ b/talk/session/media/channelmanager.h @@ -113,11 +113,18 @@ class ChannelManager : public rtc::MessageHandler, BaseSession* session, const std::string& content_name, bool rtcp); // Destroys a voice channel created with the Create API. void DestroyVoiceChannel(VoiceChannel* voice_channel); + // TODO(pbos): Remove as soon as all call sites specify VideoOptions. + VideoChannel* CreateVideoChannel(BaseSession* session, + const std::string& content_name, + bool rtcp, + VoiceChannel* voice_channel); // Creates a video channel, synced with the specified voice channel, and // associated with the specified session. - VideoChannel* CreateVideoChannel( - BaseSession* session, const std::string& content_name, bool rtcp, - VoiceChannel* voice_channel); + VideoChannel* CreateVideoChannel(BaseSession* session, + const std::string& content_name, + bool rtcp, + const VideoOptions& options, + VoiceChannel* voice_channel); // Destroys a video channel created with the Create API. void DestroyVideoChannel(VideoChannel* video_channel); DataChannel* CreateDataChannel( @@ -261,9 +268,11 @@ class ChannelManager : public rtc::MessageHandler, VoiceChannel* CreateVoiceChannel_w( BaseSession* session, const std::string& content_name, bool rtcp); void DestroyVoiceChannel_w(VoiceChannel* voice_channel); - VideoChannel* CreateVideoChannel_w( - BaseSession* session, const std::string& content_name, bool rtcp, - VoiceChannel* voice_channel); + VideoChannel* CreateVideoChannel_w(BaseSession* session, + const std::string& content_name, + bool rtcp, + const VideoOptions& options, + VoiceChannel* voice_channel); void DestroyVideoChannel_w(VideoChannel* video_channel); DataChannel* CreateDataChannel_w( BaseSession* session, const std::string& content_name, diff --git a/talk/session/media/channelmanager_unittest.cc b/talk/session/media/channelmanager_unittest.cc index 98f14007ae..13633646a5 100644 --- a/talk/session/media/channelmanager_unittest.cc +++ b/talk/session/media/channelmanager_unittest.cc @@ -127,9 +127,8 @@ TEST_F(ChannelManagerTest, CreateDestroyChannels) { cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( session_, cricket::CN_AUDIO, false); EXPECT_TRUE(voice_channel != NULL); - cricket::VideoChannel* video_channel = - cm_->CreateVideoChannel(session_, cricket::CN_VIDEO, - false, voice_channel); + cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( + session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); EXPECT_TRUE(video_channel != NULL); cricket::DataChannel* data_channel = cm_->CreateDataChannel(session_, cricket::CN_DATA, @@ -151,9 +150,8 @@ TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( session_, cricket::CN_AUDIO, false); EXPECT_TRUE(voice_channel != NULL); - cricket::VideoChannel* video_channel = - cm_->CreateVideoChannel(session_, cricket::CN_VIDEO, - false, voice_channel); + cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( + session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); EXPECT_TRUE(video_channel != NULL); cricket::DataChannel* data_channel = cm_->CreateDataChannel(session_, cricket::CN_DATA, @@ -178,9 +176,8 @@ TEST_F(ChannelManagerTest, NoTransportChannelTest) { cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( session_, cricket::CN_AUDIO, false); EXPECT_TRUE(voice_channel == NULL); - cricket::VideoChannel* video_channel = - cm_->CreateVideoChannel(session_, cricket::CN_VIDEO, - false, voice_channel); + cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( + session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); EXPECT_TRUE(video_channel == NULL); cricket::DataChannel* data_channel = cm_->CreateDataChannel(session_, cricket::CN_DATA,