From 1807d57ab82ef906fb32dc6cb4805f86fce30d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Radakovi=C4=87?= Date: Thu, 22 Feb 2018 14:18:06 +0100 Subject: [PATCH] Add application_data field(s) to RtpPacketToSend and PacketOptions. Pass pointer to application_data from RtpPacketToSend arriving via RtpSender::SendToNetwork through to Transport::SendRtp, in PacketOptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:8906 Change-Id: Ie75013ed472710f4efcfbcc160e46a6119a1f41d Reviewed-on: https://webrtc-review.googlesource.com/55600 Reviewed-by: Björn Terelius Reviewed-by: Stefan Holmer Reviewed-by: Danil Chapovalov Commit-Queue: Dino Radaković Cr-Commit-Position: refs/heads/master@{#22174} --- api/BUILD.gn | 1 + api/call/transport.cc | 19 +++++++++++++ api/call/transport.h | 7 +++++ modules/rtp_rtcp/BUILD.gn | 1 + modules/rtp_rtcp/source/rtp_packet_to_send.cc | 27 +++++++++++++++++++ modules/rtp_rtcp/source/rtp_packet_to_send.h | 26 +++++++++++++----- modules/rtp_rtcp/source/rtp_sender.cc | 7 +++++ 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 api/call/transport.cc create mode 100644 modules/rtp_rtcp/source/rtp_packet_to_send.cc diff --git a/api/BUILD.gn b/api/BUILD.gn index 280b7e745a..a238357edc 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -201,6 +201,7 @@ rtc_source_set("audio_options_api") { rtc_source_set("transport_api") { visibility = [ "*" ] sources = [ + "call/transport.cc", "call/transport.h", ] } diff --git a/api/call/transport.cc b/api/call/transport.cc new file mode 100644 index 0000000000..515f27c3f7 --- /dev/null +++ b/api/call/transport.cc @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 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 "api/call/transport.h" + +namespace webrtc { + +PacketOptions::PacketOptions() = default; + +PacketOptions::~PacketOptions() = default; + +} // namespace webrtc diff --git a/api/call/transport.h b/api/call/transport.h index 1cdb0d366d..df101fcf05 100644 --- a/api/call/transport.h +++ b/api/call/transport.h @@ -13,15 +13,22 @@ #include #include +#include namespace webrtc { // TODO(holmer): Look into unifying this with the PacketOptions in // asyncpacketsocket.h. struct PacketOptions { + PacketOptions(); + ~PacketOptions(); + // A 16 bits positive id. Negative ids are invalid and should be interpreted // as packet_id not being set. int packet_id = -1; + // Additional data bound to the RTP packet for use in application code, + // outside of WebRTC. + std::vector application_data; }; class Transport { diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index e53001b6bc..be3fd0354d 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -77,6 +77,7 @@ rtc_source_set("rtp_rtcp_format") { "source/rtp_header_extensions.cc", "source/rtp_packet.cc", "source/rtp_packet_received.cc", + "source/rtp_packet_to_send.cc", ] deps = [ diff --git a/modules/rtp_rtcp/source/rtp_packet_to_send.cc b/modules/rtp_rtcp/source/rtp_packet_to_send.cc new file mode 100644 index 0000000000..9a9a57dc23 --- /dev/null +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.cc @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 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 "modules/rtp_rtcp/source/rtp_packet_to_send.h" + +namespace webrtc { + +RtpPacketToSend::RtpPacketToSend(const ExtensionManager* extensions) + : RtpPacket(extensions) {} +RtpPacketToSend::RtpPacketToSend(const RtpPacketToSend& packet) = default; +RtpPacketToSend::RtpPacketToSend(const ExtensionManager* extensions, + size_t capacity) + : RtpPacket(extensions, capacity) {} + +RtpPacketToSend& RtpPacketToSend::operator=(const RtpPacketToSend& packet) = + default; + +RtpPacketToSend::~RtpPacketToSend() = default; + +} // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_packet_to_send.h b/modules/rtp_rtcp/source/rtp_packet_to_send.h index c287f0ca29..59992a1c58 100644 --- a/modules/rtp_rtcp/source/rtp_packet_to_send.h +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.h @@ -10,6 +10,9 @@ #ifndef MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ #define MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ +#include + +#include "api/array_view.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "modules/rtp_rtcp/source/rtp_packet.h" @@ -17,19 +20,29 @@ namespace webrtc { // Class to hold rtp packet with metadata for sender side. class RtpPacketToSend : public RtpPacket { public: - explicit RtpPacketToSend(const ExtensionManager* extensions) - : RtpPacket(extensions) {} - RtpPacketToSend(const RtpPacketToSend& packet) = default; - RtpPacketToSend(const ExtensionManager* extensions, size_t capacity) - : RtpPacket(extensions, capacity) {} + explicit RtpPacketToSend(const ExtensionManager* extensions); + RtpPacketToSend(const RtpPacketToSend& packet); + RtpPacketToSend(const ExtensionManager* extensions, size_t capacity); - RtpPacketToSend& operator=(const RtpPacketToSend& packet) = default; + RtpPacketToSend& operator=(const RtpPacketToSend& packet); + + ~RtpPacketToSend(); // Time in local time base as close as it can to frame capture time. int64_t capture_time_ms() const { return capture_time_ms_; } void set_capture_time_ms(int64_t time) { capture_time_ms_ = time; } + // Additional data bound to the RTP packet for use in application code, + // outside of WebRTC. + rtc::ArrayView application_data() const { + return application_data_; + } + + void set_application_data(rtc::ArrayView data) { + application_data_.assign(data.begin(), data.end()); + } + void set_packetization_finish_time_ms(int64_t time) { SetExtension( VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), @@ -56,6 +69,7 @@ class RtpPacketToSend : public RtpPacket { private: int64_t capture_time_ms_ = 0; + std::vector application_data_; }; } // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index c37c5ace4f..f8ef1300dd 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -782,6 +782,8 @@ bool RTPSender::PrepareAndSendPacket(std::unique_ptr packet, AddPacketToTransportFeedback(options.packet_id, *packet_to_send, pacing_info); } + options.application_data.assign(packet_to_send->application_data().begin(), + packet_to_send->application_data().end()); if (!is_retransmit && !send_over_rtx) { UpdateDelayStatistics(packet->capture_time_ms(), now_ms); @@ -914,6 +916,8 @@ bool RTPSender::SendToNetwork(std::unique_ptr packet, AddPacketToTransportFeedback(options.packet_id, *packet.get(), PacedPacketInfo()); } + options.application_data.assign(packet->application_data().begin(), + packet->application_data().end()); UpdateDelayStatistics(packet->capture_time_ms(), now_ms); UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), @@ -1211,6 +1215,9 @@ std::unique_ptr RTPSender::BuildRtxPacket( auto payload = packet.payload(); memcpy(rtx_payload + kRtxHeaderSize, payload.data(), payload.size()); + // Add original application data. + rtx_packet->set_application_data(packet.application_data()); + return rtx_packet; }