mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00
Add ArrayView versions of SendRtp and SendRtcp
This is part of the long term plan to stop using pointer + length to pass around buffers. Bug: webrtc:14870 Change-Id: Ibaf5258fd326b56132b9b5a8a6b1563a763ef2f8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/314960 Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40512}
This commit is contained in:
parent
cad3aed5fc
commit
b38d9d2b6f
5 changed files with 40 additions and 2 deletions
|
@ -796,6 +796,7 @@ rtc_library("transport_api") {
|
||||||
"call/transport.h",
|
"call/transport.h",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
|
":array_view",
|
||||||
":refcountedbase",
|
":refcountedbase",
|
||||||
":scoped_refptr",
|
":scoped_refptr",
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "api/array_view.h"
|
||||||
#include "api/ref_counted_base.h"
|
#include "api/ref_counted_base.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
|
|
||||||
|
@ -44,6 +45,17 @@ struct PacketOptions {
|
||||||
|
|
||||||
class Transport {
|
class Transport {
|
||||||
public:
|
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<const uint8_t> packet,
|
||||||
|
const PacketOptions& options) {
|
||||||
|
return SendRtp(packet.data(), packet.size(), options);
|
||||||
|
}
|
||||||
|
virtual bool SendRtcp(rtc::ArrayView<const uint8_t> packet) {
|
||||||
|
return SendRtcp(packet.data(), packet.size());
|
||||||
|
}
|
||||||
|
// Old style functions.
|
||||||
virtual bool SendRtp(const uint8_t* packet,
|
virtual bool SendRtp(const uint8_t* packet,
|
||||||
size_t length,
|
size_t length,
|
||||||
const PacketOptions& options) = 0;
|
const PacketOptions& options) = 0;
|
||||||
|
|
|
@ -201,8 +201,13 @@ MediaChannelUtil::TransportForMediaChannels::~TransportForMediaChannels() {
|
||||||
|
|
||||||
bool MediaChannelUtil::TransportForMediaChannels::SendRtcp(const uint8_t* data,
|
bool MediaChannelUtil::TransportForMediaChannels::SendRtcp(const uint8_t* data,
|
||||||
size_t len) {
|
size_t len) {
|
||||||
|
return SendRtcp(rtc::MakeArrayView(data, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MediaChannelUtil::TransportForMediaChannels::SendRtcp(
|
||||||
|
rtc::ArrayView<const uint8_t> packet) {
|
||||||
auto send = [this, packet = rtc::CopyOnWriteBuffer(
|
auto send = [this, packet = rtc::CopyOnWriteBuffer(
|
||||||
data, len, kMaxRtpPacketLen)]() mutable {
|
packet, kMaxRtpPacketLen)]() mutable {
|
||||||
rtc::PacketOptions rtc_options;
|
rtc::PacketOptions rtc_options;
|
||||||
if (DscpEnabled()) {
|
if (DscpEnabled()) {
|
||||||
rtc_options.dscp = PreferredDscp();
|
rtc_options.dscp = PreferredDscp();
|
||||||
|
@ -222,13 +227,19 @@ bool MediaChannelUtil::TransportForMediaChannels::SendRtp(
|
||||||
const uint8_t* data,
|
const uint8_t* data,
|
||||||
size_t len,
|
size_t len,
|
||||||
const webrtc::PacketOptions& options) {
|
const webrtc::PacketOptions& options) {
|
||||||
|
return SendRtp(rtc::ArrayView<const uint8_t>(data, len), options);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MediaChannelUtil::TransportForMediaChannels::SendRtp(
|
||||||
|
rtc::ArrayView<const uint8_t> packet,
|
||||||
|
const webrtc::PacketOptions& options) {
|
||||||
auto send =
|
auto send =
|
||||||
[this, packet_id = options.packet_id,
|
[this, packet_id = options.packet_id,
|
||||||
included_in_feedback = options.included_in_feedback,
|
included_in_feedback = options.included_in_feedback,
|
||||||
included_in_allocation = options.included_in_allocation,
|
included_in_allocation = options.included_in_allocation,
|
||||||
batchable = options.batchable,
|
batchable = options.batchable,
|
||||||
last_packet_in_batch = options.last_packet_in_batch,
|
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::PacketOptions rtc_options;
|
||||||
rtc_options.packet_id = packet_id;
|
rtc_options.packet_id = packet_id;
|
||||||
if (DscpEnabled()) {
|
if (DscpEnabled()) {
|
||||||
|
|
|
@ -140,6 +140,9 @@ class MediaChannelUtil {
|
||||||
size_t length,
|
size_t length,
|
||||||
const webrtc::PacketOptions& options) override;
|
const webrtc::PacketOptions& options) override;
|
||||||
bool SendRtcp(const uint8_t* packet, size_t length) override;
|
bool SendRtcp(const uint8_t* packet, size_t length) override;
|
||||||
|
bool SendRtp(rtc::ArrayView<const uint8_t> packet,
|
||||||
|
const webrtc::PacketOptions& options) override;
|
||||||
|
bool SendRtcp(rtc::ArrayView<const uint8_t> packet) override;
|
||||||
|
|
||||||
// Not implementation of webrtc::Transport
|
// Not implementation of webrtc::Transport
|
||||||
void SetInterface(MediaChannelNetworkInterface* iface);
|
void SetInterface(MediaChannelNetworkInterface* iface);
|
||||||
|
|
|
@ -83,6 +83,17 @@ class RTC_EXPORT CopyOnWriteBuffer {
|
||||||
explicit CopyOnWriteBuffer(const VecT& v)
|
explicit CopyOnWriteBuffer(const VecT& v)
|
||||||
: CopyOnWriteBuffer(v.data(), v.size()) {}
|
: CopyOnWriteBuffer(v.data(), v.size()) {}
|
||||||
|
|
||||||
|
// Construct a buffer from a vector like type and a capacity argument
|
||||||
|
template <typename VecT,
|
||||||
|
typename ElemT = typename std::remove_pointer_t<
|
||||||
|
decltype(std::declval<VecT>().data())>,
|
||||||
|
typename std::enable_if_t<
|
||||||
|
!std::is_same<VecT, CopyOnWriteBuffer>::value &&
|
||||||
|
HasDataAndSize<VecT, ElemT>::value &&
|
||||||
|
internal::BufferCompat<uint8_t, ElemT>::value>* = nullptr>
|
||||||
|
explicit CopyOnWriteBuffer(const VecT& v, size_t capacity)
|
||||||
|
: CopyOnWriteBuffer(v.data(), v.size(), capacity) {}
|
||||||
|
|
||||||
~CopyOnWriteBuffer();
|
~CopyOnWriteBuffer();
|
||||||
|
|
||||||
// Get a pointer to the data. Just .data() will give you a (const) uint8_t*,
|
// Get a pointer to the data. Just .data() will give you a (const) uint8_t*,
|
||||||
|
|
Loading…
Reference in a new issue