From e75a1bf45fb66f384701c375e77af3fe833b68cd Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Wed, 18 Sep 2013 11:52:42 +0000 Subject: [PATCH] Break out glue for old->new Transport. Reduces multiple inheritance and code duplication. BUG= R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2239004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4774 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/video_engine/internal/call.h | 4 +-- .../internal/transport_adapter.cc | 36 +++++++++++++++++++ .../video_engine/internal/transport_adapter.h | 34 ++++++++++++++++++ .../internal/video_receive_stream.cc | 21 ++--------- .../internal/video_receive_stream.h | 11 ++---- .../internal/video_send_stream.cc | 24 ++----------- .../video_engine/internal/video_send_stream.h | 12 ++----- webrtc/video_engine/video_engine_core.gypi | 2 ++ 8 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 webrtc/video_engine/internal/transport_adapter.cc create mode 100644 webrtc/video_engine/internal/transport_adapter.h diff --git a/webrtc/video_engine/internal/call.h b/webrtc/video_engine/internal/call.h index 13cdd893bc..7891bfd885 100644 --- a/webrtc/video_engine/internal/call.h +++ b/webrtc/video_engine/internal/call.h @@ -7,8 +7,8 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_VIDEO_ENGINE_CALL_IMPL_H_ -#define WEBRTC_VIDEO_ENGINE_CALL_IMPL_H_ +#ifndef WEBRTC_VIDEO_ENGINE_INTERNAL_CALL_H_ +#define WEBRTC_VIDEO_ENGINE_INTERNAL_CALL_H_ #include #include diff --git a/webrtc/video_engine/internal/transport_adapter.cc b/webrtc/video_engine/internal/transport_adapter.cc new file mode 100644 index 0000000000..635586ad1b --- /dev/null +++ b/webrtc/video_engine/internal/transport_adapter.cc @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/video_engine/internal/transport_adapter.h" + +namespace webrtc { +namespace internal { + +TransportAdapter::TransportAdapter(newapi::Transport* transport) + : transport_(transport) {} + +int TransportAdapter::SendPacket(int /*channel*/, + const void* packet, + int length) { + bool success = transport_->SendRTP(static_cast(packet), + static_cast(length)); + return success ? length : -1; +} + +int TransportAdapter::SendRTCPPacket(int /*channel*/, + const void* packet, + int length) { + bool success = transport_->SendRTCP(static_cast(packet), + static_cast(length)); + return success ? length : -1; +} + +} // namespace internal +} // namespace webrtc diff --git a/webrtc/video_engine/internal/transport_adapter.h b/webrtc/video_engine/internal/transport_adapter.h new file mode 100644 index 0000000000..a5e2e281bf --- /dev/null +++ b/webrtc/video_engine/internal/transport_adapter.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef WEBRTC_VIDEO_ENGINE_INTERNAL_TRANSPORT_ADAPTER_H_ +#define WEBRTC_VIDEO_ENGINE_INTERNAL_TRANSPORT_ADAPTER_H_ + +#include "webrtc/common_types.h" +#include "webrtc/video_engine/new_include/transport.h" + +namespace webrtc { +namespace internal { + +class TransportAdapter : public webrtc::Transport { + public: + explicit TransportAdapter(newapi::Transport* transport); + + virtual int SendPacket(int /*channel*/, const void* packet, int length) + OVERRIDE; + virtual int SendRTCPPacket(int /*channel*/, const void* packet, int length) + OVERRIDE; + + private: + newapi::Transport *transport_; +}; +} // namespace internal +} // namespace webrtc + +#endif // WEBRTC_VIDEO_ENGINE_INTERNAL_TRANSPORT_ADAPTER_H_ diff --git a/webrtc/video_engine/internal/video_receive_stream.cc b/webrtc/video_engine/internal/video_receive_stream.cc index ed24508e8f..07f120cb09 100644 --- a/webrtc/video_engine/internal/video_receive_stream.cc +++ b/webrtc/video_engine/internal/video_receive_stream.cc @@ -30,7 +30,7 @@ namespace internal { VideoReceiveStream::VideoReceiveStream(webrtc::VideoEngine* video_engine, const VideoReceiveStream::Config& config, newapi::Transport* transport) - : transport_(transport), config_(config), channel_(-1) { + : transport_adapter_(transport), config_(config), channel_(-1) { video_engine_base_ = ViEBase::GetInterface(video_engine); // TODO(mflodman): Use the other CreateChannel method. video_engine_base_->CreateChannel(channel_); @@ -48,7 +48,7 @@ VideoReceiveStream::VideoReceiveStream(webrtc::VideoEngine* video_engine, network_ = ViENetwork::GetInterface(video_engine); assert(network_ != NULL); - network_->RegisterSendTransport(channel_, *this); + network_->RegisterSendTransport(channel_, transport_adapter_); codec_ = ViECodec::GetInterface(video_engine); @@ -177,22 +177,5 @@ int VideoReceiveStream::DeliverFrame(uint8_t* frame, bool VideoReceiveStream::IsTextureSupported() { return false; } -int VideoReceiveStream::SendPacket(int /*channel*/, - const void* packet, - int length) { - assert(length >= 0); - bool success = transport_->SendRTP(static_cast(packet), - static_cast(length)); - return success ? 0 : -1; -} - -int VideoReceiveStream::SendRTCPPacket(int /*channel*/, - const void* packet, - int length) { - assert(length >= 0); - bool success = transport_->SendRTCP(static_cast(packet), - static_cast(length)); - return success ? 0 : -1; -} } // internal } // webrtc diff --git a/webrtc/video_engine/internal/video_receive_stream.h b/webrtc/video_engine/internal/video_receive_stream.h index e13a2e1697..b6b53190e4 100644 --- a/webrtc/video_engine/internal/video_receive_stream.h +++ b/webrtc/video_engine/internal/video_receive_stream.h @@ -16,6 +16,7 @@ #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/system_wrappers/interface/clock.h" #include "webrtc/video_engine/include/vie_render.h" +#include "webrtc/video_engine/internal/transport_adapter.h" #include "webrtc/video_engine/new_include/video_receive_stream.h" namespace webrtc { @@ -31,8 +32,7 @@ class ViERTP_RTCP; namespace internal { class VideoReceiveStream : public webrtc::VideoReceiveStream, - public webrtc::ExternalRenderer, - public webrtc::Transport { + public webrtc::ExternalRenderer { public: VideoReceiveStream(webrtc::VideoEngine* video_engine, const VideoReceiveStream::Config& config, @@ -51,17 +51,12 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream, virtual bool IsTextureSupported() OVERRIDE; - virtual int SendPacket(int /*channel*/, const void* packet, int length) - OVERRIDE; - virtual int SendRTCPPacket(int /*channel*/, const void* packet, int length) - OVERRIDE; - public: virtual bool DeliverRtcp(const uint8_t* packet, size_t length); virtual bool DeliverRtp(const uint8_t* packet, size_t length); private: - newapi::Transport* transport_; + TransportAdapter transport_adapter_; VideoReceiveStream::Config config_; Clock* clock_; diff --git a/webrtc/video_engine/internal/video_send_stream.cc b/webrtc/video_engine/internal/video_send_stream.cc index 5adf8b9562..799cec7d43 100644 --- a/webrtc/video_engine/internal/video_send_stream.cc +++ b/webrtc/video_engine/internal/video_send_stream.cc @@ -80,7 +80,7 @@ VideoSendStream::VideoSendStream(newapi::Transport* transport, bool overuse_detection, webrtc::VideoEngine* video_engine, const VideoSendStream::Config& config) - : transport_(transport), config_(config), external_codec_(NULL) { + : transport_adapter_(transport), config_(config), external_codec_(NULL) { if (config_.codec.numberOfSimulcastStreams > 0) { assert(config_.rtp.ssrcs.size() == config_.codec.numberOfSimulcastStreams); @@ -146,7 +146,7 @@ VideoSendStream::VideoSendStream(newapi::Transport* transport, network_ = ViENetwork::GetInterface(video_engine); assert(network_ != NULL); - network_->RegisterSendTransport(channel_, *this); + network_->RegisterSendTransport(channel_, transport_adapter_); if (config.encoder) { external_codec_ = ViEExternalCodec::GetInterface(video_engine); @@ -250,26 +250,6 @@ void VideoSendStream::GetSendCodec(VideoCodec* send_codec) { *send_codec = config_.codec; } -int VideoSendStream::SendPacket(int /*channel*/, - const void* packet, - int length) { - // TODO(pbos): Lock these methods and the destructor so it can't be processing - // a packet when the destructor has been called. - assert(length >= 0); - bool success = transport_->SendRTP(static_cast(packet), - static_cast(length)); - return success ? length : -1; -} - -int VideoSendStream::SendRTCPPacket(int /*channel*/, - const void* packet, - int length) { - assert(length >= 0); - bool success = transport_->SendRTCP(static_cast(packet), - static_cast(length)); - return success ? length : -1; -} - bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { return network_->ReceivedRTCPPacket( channel_, packet, static_cast(length)) == 0; diff --git a/webrtc/video_engine/internal/video_send_stream.h b/webrtc/video_engine/internal/video_send_stream.h index bd3494f507..1241b483d4 100644 --- a/webrtc/video_engine/internal/video_send_stream.h +++ b/webrtc/video_engine/internal/video_send_stream.h @@ -14,6 +14,7 @@ #include #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" +#include "webrtc/video_engine/internal/transport_adapter.h" #include "webrtc/video_engine/new_include/video_receive_stream.h" #include "webrtc/video_engine/new_include/video_send_stream.h" @@ -33,8 +34,7 @@ namespace internal { class ResolutionAdaptor; class VideoSendStream : public webrtc::VideoSendStream, - public VideoSendStreamInput, - public webrtc::Transport { + public VideoSendStreamInput { public: VideoSendStream(newapi::Transport* transport, bool overuse_detection, @@ -58,17 +58,11 @@ class VideoSendStream : public webrtc::VideoSendStream, virtual void GetSendCodec(VideoCodec* send_codec) OVERRIDE; - virtual int SendPacket(int /*channel*/, const void* packet, int length) - OVERRIDE; - - virtual int SendRTCPPacket(int /*channel*/, const void* packet, int length) - OVERRIDE; - public: bool DeliverRtcp(const uint8_t* packet, size_t length); private: - newapi::Transport* transport_; + TransportAdapter transport_adapter_; VideoSendStream::Config config_; ViEBase* video_engine_base_; diff --git a/webrtc/video_engine/video_engine_core.gypi b/webrtc/video_engine/video_engine_core.gypi index b9756dd4a7..b68347481d 100644 --- a/webrtc/video_engine/video_engine_core.gypi +++ b/webrtc/video_engine/video_engine_core.gypi @@ -117,6 +117,8 @@ # New VideoEngine API 'internal/call.cc', 'internal/call.h', + 'internal/transport_adapter.cc', + 'internal/transport_adapter.h', 'internal/video_receive_stream.cc', 'internal/video_receive_stream.h', 'internal/video_send_stream.cc',