From 0d523eea831e616c415c61765127ed5eb17e5f11 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Thu, 5 Jun 2014 09:10:55 +0000 Subject: [PATCH] Remove static initializer from WebRtcVideoEngine2. BUG= R=pliard@google.com, pthatcher@webrtc.org, pliard@chromium.org Review URL: https://webrtc-codereview.appspot.com/15679005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6338 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/media/webrtc/webrtcvideoengine2.cc | 13 ++++++++----- talk/media/webrtc/webrtcvideoengine2.h | 5 ++++- talk/media/webrtc/webrtcvideoengine2_unittest.cc | 4 +--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index 13ed3d159..723ef1dd8 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -192,6 +192,9 @@ static std::vector DefaultVideoCodecs() { return codecs; } +WebRtcVideoEncoderFactory2::~WebRtcVideoEncoderFactory2() { +} + class DefaultVideoEncoderFactory : public WebRtcVideoEncoderFactory2 { public: virtual bool CreateEncoderSettings( @@ -239,7 +242,7 @@ class DefaultVideoEncoderFactory : public WebRtcVideoEncoderFactory2 { virtual bool SupportsCodec(const VideoCodec& codec) OVERRIDE { return _stricmp(codec.name.c_str(), kVp8PayloadName) == 0; } -} default_encoder_factory; +}; WebRtcVideoEngine2::WebRtcVideoEngine2() { // Construct without a factory or voice engine. @@ -265,6 +268,7 @@ void WebRtcVideoEngine2::Construct(WebRtcVideoChannelFactory* channel_factory, video_codecs_ = DefaultVideoCodecs(); default_codec_format_ = VideoFormat(kDefaultVideoFormat); + default_video_encoder_factory_.reset(new DefaultVideoEncoderFactory()); } WebRtcVideoEngine2::~WebRtcVideoEngine2() { @@ -328,7 +332,7 @@ WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( channel_factory_ != NULL ? channel_factory_->Create(this, voice_channel) : new WebRtcVideoChannel2( - this, voice_channel, GetDefaultVideoEncoderFactory()); + this, voice_channel, GetVideoEncoderFactory()); if (!channel->Init()) { delete channel; return NULL; @@ -463,9 +467,8 @@ bool WebRtcVideoEngine2::ShouldIgnoreTrace(const std::string& trace) { return false; } -WebRtcVideoEncoderFactory2* WebRtcVideoEngine2::GetDefaultVideoEncoderFactory() - const { - return &default_encoder_factory; +WebRtcVideoEncoderFactory2* WebRtcVideoEngine2::GetVideoEncoderFactory() const { + return default_video_encoder_factory_.get(); } // Thin map between cricket::VideoFrame and an existing webrtc::I420VideoFrame diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index e6b9598b1..10a160848 100644 --- a/talk/media/webrtc/webrtcvideoengine2.h +++ b/talk/media/webrtc/webrtcvideoengine2.h @@ -82,6 +82,7 @@ class WebRtcVideoChannel2; class WebRtcVideoEncoderFactory2 { public: + virtual ~WebRtcVideoEncoderFactory2(); virtual bool CreateEncoderSettings( webrtc::VideoSendStream::Config::EncoderSettings* encoder_settings, const VideoOptions& options, @@ -139,7 +140,7 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { talk_base::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); } - virtual WebRtcVideoEncoderFactory2* GetDefaultVideoEncoderFactory() const; + virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory() const; private: void Construct(WebRtcVideoChannelFactory* channel_factory, @@ -162,6 +163,8 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { talk_base::scoped_ptr cpu_monitor_; WebRtcVideoChannelFactory* channel_factory_; + talk_base::scoped_ptr + default_video_encoder_factory_; }; // Adapter between webrtc::VideoRenderer and cricket::VideoRenderer. diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index 1e402e0c2..bba14555f 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -243,9 +243,7 @@ class FakeWebRtcVideoChannel2 : public WebRtcVideoChannel2 { FakeWebRtcVideoChannel2(FakeCall* call, WebRtcVideoEngine2* engine, VoiceMediaChannel* voice_channel) - : WebRtcVideoChannel2(call, - engine, - engine->GetDefaultVideoEncoderFactory()), + : WebRtcVideoChannel2(call, engine, engine->GetVideoEncoderFactory()), fake_call_(call), voice_channel_(voice_channel) {}