From b648b9d85c5d07b0866ef45f5be587f71b0849b4 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 26 Aug 2014 11:08:06 +0000 Subject: [PATCH] Remove test constructor in WebRtcVideoEngine2. Removes the need for ::Construct(). BUG=1788 R=pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/15279004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6977 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../app/webrtc/java/jni/peerconnection_jni.cc | 2 +- talk/media/webrtc/webrtcvideoengine2.cc | 61 +++++++------------ talk/media/webrtc/webrtcvideoengine2.h | 13 ++-- .../webrtc/webrtcvideoengine2_unittest.cc | 3 +- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index 9b34fb596..0c26698e5 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -917,11 +917,11 @@ class DataChannelObserverWrapper : public DataChannelObserver { DataChannelObserverWrapper(JNIEnv* jni, jobject j_observer) : j_observer_global_(jni, j_observer), j_observer_class_(jni, GetObjectClass(jni, j_observer)), + j_buffer_class_(jni, FindClass(jni, "org/webrtc/DataChannel$Buffer")), j_on_state_change_mid_(GetMethodID(jni, *j_observer_class_, "onStateChange", "()V")), j_on_message_mid_(GetMethodID(jni, *j_observer_class_, "onMessage", "(Lorg/webrtc/DataChannel$Buffer;)V")), - j_buffer_class_(jni, FindClass(jni, "org/webrtc/DataChannel$Buffer")), j_buffer_ctor_(GetMethodID(jni, *j_buffer_class_, "", "(Ljava/nio/ByteBuffer;Z)V")) { } diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index a80e74e71..efd3df414 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -283,37 +283,17 @@ void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( } WebRtcVideoEngine2::WebRtcVideoEngine2() - : default_codec_format_(kDefaultVideoCodecPref.width, + : worker_thread_(NULL), + voice_engine_(NULL), + video_codecs_(DefaultVideoCodecs()), + default_codec_format_(kDefaultVideoCodecPref.width, kDefaultVideoCodecPref.height, FPS_TO_INTERVAL(kDefaultFramerate), - FOURCC_ANY) { - // Construct without a factory or voice engine. - Construct(NULL, NULL, new rtc::CpuMonitor(NULL)); -} - -WebRtcVideoEngine2::WebRtcVideoEngine2( - WebRtcVideoChannelFactory* channel_factory) - : default_codec_format_(kDefaultVideoCodecPref.width, - kDefaultVideoCodecPref.height, - FPS_TO_INTERVAL(kDefaultFramerate), - FOURCC_ANY) { - // Construct without a voice engine. - Construct(channel_factory, NULL, new rtc::CpuMonitor(NULL)); -} - -void WebRtcVideoEngine2::Construct(WebRtcVideoChannelFactory* channel_factory, - WebRtcVoiceEngine* voice_engine, - rtc::CpuMonitor* cpu_monitor) { - LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2"; - worker_thread_ = NULL; - voice_engine_ = voice_engine; - initialized_ = false; - capture_started_ = false; - cpu_monitor_.reset(cpu_monitor); - channel_factory_ = channel_factory; - - video_codecs_ = DefaultVideoCodecs(); - + FOURCC_ANY), + initialized_(false), + cpu_monitor_(new rtc::CpuMonitor(NULL)), + channel_factory_(NULL) { + LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; rtp_header_extensions_.push_back( RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, kRtpTimestampOffsetHeaderExtensionDefaultId)); @@ -322,6 +302,11 @@ void WebRtcVideoEngine2::Construct(WebRtcVideoChannelFactory* channel_factory, kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); } +void WebRtcVideoEngine2::SetChannelFactory( + WebRtcVideoChannelFactory* channel_factory) { + channel_factory_ = channel_factory; +} + WebRtcVideoEngine2::~WebRtcVideoEngine2() { LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; @@ -673,8 +658,8 @@ WebRtcVideoChannel2::WebRtcVideoChannel2( WebRtcVideoEngine2* engine, VoiceMediaChannel* voice_channel, WebRtcVideoEncoderFactory2* encoder_factory) - : encoder_factory_(encoder_factory), - unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_) { + : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), + encoder_factory_(encoder_factory) { // TODO(pbos): Connect the video and audio with |voice_channel|. webrtc::Call::Config config(this); Construct(webrtc::Call::Create(config), engine); @@ -684,8 +669,8 @@ WebRtcVideoChannel2::WebRtcVideoChannel2( webrtc::Call* call, WebRtcVideoEngine2* engine, WebRtcVideoEncoderFactory2* encoder_factory) - : encoder_factory_(encoder_factory), - unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_) { + : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), + encoder_factory_(encoder_factory) { Construct(call, engine); } @@ -1309,10 +1294,10 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( const StreamParams& sp, const std::vector& rtp_extensions) : call_(call), - parameters_(webrtc::VideoSendStream::Config(), options, codec_settings), encoder_factory_(encoder_factory), - capturer_(NULL), stream_(NULL), + parameters_(webrtc::VideoSendStream::Config(), options, codec_settings), + capturer_(NULL), sending_(false), muted_(false) { parameters_.config.rtp.max_packet_size = kVideoMtu; @@ -1684,11 +1669,11 @@ WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( const webrtc::VideoReceiveStream::Config& config, const std::vector& recv_codecs) : call_(call), - config_(config), stream_(NULL), + config_(config), + renderer_(NULL), last_width_(-1), - last_height_(-1), - renderer_(NULL) { + last_height_(-1) { config_.renderer = this; // SetRecvCodecs will also reset (start) the VideoReceiveStream. SetRecvCodecs(recv_codecs); diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index f665cb0f8..c961bd52f 100644 --- a/talk/media/webrtc/webrtcvideoengine2.h +++ b/talk/media/webrtc/webrtcvideoengine2.h @@ -134,9 +134,10 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { public: // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule. WebRtcVideoEngine2(); - // Custom WebRtcVideoChannelFactory for testing purposes. - explicit WebRtcVideoEngine2(WebRtcVideoChannelFactory* channel_factory); - ~WebRtcVideoEngine2(); + virtual ~WebRtcVideoEngine2(); + + // Use a custom WebRtcVideoChannelFactory (for testing purposes). + void SetChannelFactory(WebRtcVideoChannelFactory* channel_factory); // Basic video engine implementation. bool Init(rtc::Thread* worker_thread); @@ -179,10 +180,6 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory(); private: - void Construct(WebRtcVideoChannelFactory* channel_factory, - WebRtcVoiceEngine* voice_engine, - rtc::CpuMonitor* cpu_monitor); - rtc::Thread* worker_thread_; WebRtcVoiceEngine* voice_engine_; std::vector video_codecs_; @@ -191,8 +188,6 @@ class WebRtcVideoEngine2 : public sigslot::has_slots<> { bool initialized_; - bool capture_started_; - // Critical section to protect the media processor register/unregister // while processing a frame rtc::CriticalSection signal_media_critical_; diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index 9c313e63b..6aaa7bd3d 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -309,7 +309,8 @@ WebRtcVideoChannel2* FakeWebRtcVideoMediaChannelFactory::Create( class WebRtcVideoEngine2Test : public testing::Test { public: - WebRtcVideoEngine2Test() : engine_(&factory_) { + WebRtcVideoEngine2Test() { + engine_.SetChannelFactory(&factory_); std::vector engine_codecs = engine_.codecs(); assert(!engine_codecs.empty()); bool codec_set = false;