diff --git a/api/BUILD.gn b/api/BUILD.gn index a9217400fe..ca5a869a40 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -796,6 +796,7 @@ rtc_library("transport_api") { "call/transport.h", ] deps = [ + ":array_view", ":refcountedbase", ":scoped_refptr", ] diff --git a/api/call/transport.h b/api/call/transport.h index 387ce8d15b..dc3f165767 100644 --- a/api/call/transport.h +++ b/api/call/transport.h @@ -14,6 +14,7 @@ #include #include +#include "api/array_view.h" #include "api/ref_counted_base.h" #include "api/scoped_refptr.h" @@ -44,6 +45,17 @@ struct PacketOptions { class Transport { public: + // New style functions. Default implementations are to accomodate + // subclasses that haven't been converted to new style yet. + // TODO(bugs.webrtc.org/14870): Deprecate and remove old functions. + virtual bool SendRtp(rtc::ArrayView packet, + const PacketOptions& options) { + return SendRtp(packet.data(), packet.size(), options); + } + virtual bool SendRtcp(rtc::ArrayView packet) { + return SendRtcp(packet.data(), packet.size()); + } + // Old style functions. virtual bool SendRtp(const uint8_t* packet, size_t length, const PacketOptions& options) = 0; diff --git a/media/base/media_channel_impl.cc b/media/base/media_channel_impl.cc index bd5b513e91..88aa279470 100644 --- a/media/base/media_channel_impl.cc +++ b/media/base/media_channel_impl.cc @@ -201,8 +201,13 @@ MediaChannelUtil::TransportForMediaChannels::~TransportForMediaChannels() { bool MediaChannelUtil::TransportForMediaChannels::SendRtcp(const uint8_t* data, size_t len) { + return SendRtcp(rtc::MakeArrayView(data, len)); +} + +bool MediaChannelUtil::TransportForMediaChannels::SendRtcp( + rtc::ArrayView packet) { auto send = [this, packet = rtc::CopyOnWriteBuffer( - data, len, kMaxRtpPacketLen)]() mutable { + packet, kMaxRtpPacketLen)]() mutable { rtc::PacketOptions rtc_options; if (DscpEnabled()) { rtc_options.dscp = PreferredDscp(); @@ -222,13 +227,19 @@ bool MediaChannelUtil::TransportForMediaChannels::SendRtp( const uint8_t* data, size_t len, const webrtc::PacketOptions& options) { + return SendRtp(rtc::ArrayView(data, len), options); +} + +bool MediaChannelUtil::TransportForMediaChannels::SendRtp( + rtc::ArrayView packet, + const webrtc::PacketOptions& options) { auto send = [this, packet_id = options.packet_id, included_in_feedback = options.included_in_feedback, included_in_allocation = options.included_in_allocation, batchable = options.batchable, last_packet_in_batch = options.last_packet_in_batch, - packet = rtc::CopyOnWriteBuffer(data, len, kMaxRtpPacketLen)]() mutable { + packet = rtc::CopyOnWriteBuffer(packet, kMaxRtpPacketLen)]() mutable { rtc::PacketOptions rtc_options; rtc_options.packet_id = packet_id; if (DscpEnabled()) { diff --git a/media/base/media_channel_impl.h b/media/base/media_channel_impl.h index 1583e346d6..1e7fa649d0 100644 --- a/media/base/media_channel_impl.h +++ b/media/base/media_channel_impl.h @@ -140,6 +140,9 @@ class MediaChannelUtil { size_t length, const webrtc::PacketOptions& options) override; bool SendRtcp(const uint8_t* packet, size_t length) override; + bool SendRtp(rtc::ArrayView packet, + const webrtc::PacketOptions& options) override; + bool SendRtcp(rtc::ArrayView packet) override; // Not implementation of webrtc::Transport void SetInterface(MediaChannelNetworkInterface* iface); diff --git a/rtc_base/copy_on_write_buffer.h b/rtc_base/copy_on_write_buffer.h index af6e868d7d..8332ee6f62 100644 --- a/rtc_base/copy_on_write_buffer.h +++ b/rtc_base/copy_on_write_buffer.h @@ -83,6 +83,17 @@ class RTC_EXPORT CopyOnWriteBuffer { explicit CopyOnWriteBuffer(const VecT& v) : CopyOnWriteBuffer(v.data(), v.size()) {} + // Construct a buffer from a vector like type and a capacity argument + template ().data())>, + typename std::enable_if_t< + !std::is_same::value && + HasDataAndSize::value && + internal::BufferCompat::value>* = nullptr> + explicit CopyOnWriteBuffer(const VecT& v, size_t capacity) + : CopyOnWriteBuffer(v.data(), v.size(), capacity) {} + ~CopyOnWriteBuffer(); // Get a pointer to the data. Just .data() will give you a (const) uint8_t*,