diff --git a/api/BUILD.gn b/api/BUILD.gn index 3c73d516bb..0cb649055c 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -575,6 +575,10 @@ rtc_library("transport_api") { "call/transport.cc", "call/transport.h", ] + deps = [ + ":refcountedbase", + ":scoped_refptr", + ] } rtc_source_set("bitrate_allocation") { diff --git a/api/call/transport.h b/api/call/transport.h index 2a2a87a5f6..6cb4c1107d 100644 --- a/api/call/transport.h +++ b/api/call/transport.h @@ -16,6 +16,9 @@ #include +#include "api/ref_counted_base.h" +#include "api/scoped_refptr.h" + namespace webrtc { // TODO(holmer): Look into unifying this with the PacketOptions in @@ -28,9 +31,11 @@ struct PacketOptions { // A 16 bits positive id. Negative ids are invalid and should be interpreted // as packet_id not being set. int packet_id = -1; + // Deprecated: use `additional_data` instead of `application_data`. + std::vector application_data; // Additional data bound to the RTP packet for use in application code, // outside of WebRTC. - std::vector application_data; + rtc::scoped_refptr additional_data; // Whether this is a retransmission of an earlier packet. bool is_retransmit = false; bool included_in_feedback = false; diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 23cbd47cfd..1067d30a33 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -103,8 +103,10 @@ rtc_library("rtp_rtcp_format") { "..:module_api_public", "../../api:array_view", "../../api:function_view", + "../../api:refcountedbase", "../../api:rtp_headers", "../../api:rtp_parameters", + "../../api:scoped_refptr", "../../api/audio_codecs:audio_codecs_api", "../../api/transport:network_control", "../../api/transport/rtp:dependency_descriptor", diff --git a/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc b/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc index 6cb9d9330c..a4cc10bb90 100644 --- a/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc +++ b/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc @@ -178,6 +178,7 @@ void DEPRECATED_RtpSenderEgress::SendPacket( options.application_data.assign(packet->application_data().begin(), packet->application_data().end()); + options.additional_data = packet->additional_data(); if (packet->packet_type() != RtpPacketMediaType::kPadding && packet->packet_type() != RtpPacketMediaType::kRetransmission) { diff --git a/modules/rtp_rtcp/source/rtp_packet_received.h b/modules/rtp_rtcp/source/rtp_packet_received.h index 6727b67750..64348bdce2 100644 --- a/modules/rtp_rtcp/source/rtp_packet_received.h +++ b/modules/rtp_rtcp/source/rtp_packet_received.h @@ -12,14 +12,20 @@ #include +#include #include #include "api/array_view.h" +#include "api/ref_counted_base.h" #include "api/rtp_headers.h" +#include "api/scoped_refptr.h" #include "modules/rtp_rtcp/source/rtp_packet.h" +#include "rtc_base/deprecation.h" namespace webrtc { // Class to hold rtp packet with metadata for receiver side. +// The metadata is not parsed from the rtp packet, but may be derived from the +// data that is parsed from the rtp packet. class RtpPacketReceived : public RtpPacket { public: RtpPacketReceived(); @@ -50,19 +56,29 @@ class RtpPacketReceived : public RtpPacket { payload_type_frequency_ = value; } - // Additional data bound to the RTP packet for use in application code, - // outside of WebRTC. + // An application can attach arbitrary data to an RTP packet using + // `application_data` or `additional_data`. + // The additional data does not affect WebRTC processing. + RTC_DEPRECATED rtc::ArrayView application_data() const { return application_data_; } + RTC_DEPRECATED void set_application_data(rtc::ArrayView data) { application_data_.assign(data.begin(), data.end()); } + rtc::scoped_refptr additional_data() const { + return additional_data_; + } + void set_additional_data(rtc::scoped_refptr data) { + additional_data_ = std::move(data); + } private: int64_t arrival_time_ms_ = 0; int payload_type_frequency_ = 0; bool recovered_ = false; + rtc::scoped_refptr additional_data_; std::vector application_data_; }; diff --git a/modules/rtp_rtcp/source/rtp_packet_to_send.h b/modules/rtp_rtcp/source/rtp_packet_to_send.h index 9aaf9a52e6..396198fed8 100644 --- a/modules/rtp_rtcp/source/rtp_packet_to_send.h +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.h @@ -13,10 +13,13 @@ #include #include +#include #include #include "absl/types/optional.h" #include "api/array_view.h" +#include "api/ref_counted_base.h" +#include "api/scoped_refptr.h" #include "api/video/video_timing.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" @@ -24,6 +27,8 @@ namespace webrtc { // Class to hold rtp packet with metadata for sender side. +// The metadata is not send over the wire, but packet sender may use it to +// create rtp header extensions or other data that is sent over the wire. class RtpPacketToSend : public RtpPacket { public: // RtpPacketToSend::Type is deprecated. Use RtpPacketMediaType directly. @@ -64,8 +69,9 @@ class RtpPacketToSend : public RtpPacket { } bool allow_retransmission() { return allow_retransmission_; } - // Additional data bound to the RTP packet for use in application code, - // outside of WebRTC. + // An application can attach arbitrary data to an RTP packet using + // `application_data` or `additional_data`. + // The additional data does not affect WebRTC processing. rtc::ArrayView application_data() const { return application_data_; } @@ -73,6 +79,12 @@ class RtpPacketToSend : public RtpPacket { void set_application_data(rtc::ArrayView data) { application_data_.assign(data.begin(), data.end()); } + rtc::scoped_refptr additional_data() const { + return additional_data_; + } + void set_additional_data(rtc::scoped_refptr data) { + additional_data_ = std::move(data); + } void set_packetization_finish_time_ms(int64_t time) { SetExtension( @@ -122,7 +134,10 @@ class RtpPacketToSend : public RtpPacket { absl::optional packet_type_; bool allow_retransmission_ = false; absl::optional retransmitted_sequence_number_; + // TODO(danilchap): Remove applicaion_data_ when application switched to use + // additional_data instead. std::vector application_data_; + rtc::scoped_refptr additional_data_; bool is_first_packet_of_frame_ = false; bool is_key_frame_ = false; bool fec_protect_packet_ = false; diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index 584fced397..510c5122c9 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -811,6 +811,7 @@ std::unique_ptr RTPSender::BuildRtxPacket( // Add original application data. rtx_packet->set_application_data(packet.application_data()); + rtx_packet->set_additional_data(packet.additional_data()); // Copy capture time so e.g. TransmissionOffset is correctly set. rtx_packet->set_capture_time_ms(packet.capture_time_ms()); diff --git a/modules/rtp_rtcp/source/rtp_sender_egress.cc b/modules/rtp_rtcp/source/rtp_sender_egress.cc index aba23ddc4b..fc628217d9 100644 --- a/modules/rtp_rtcp/source/rtp_sender_egress.cc +++ b/modules/rtp_rtcp/source/rtp_sender_egress.cc @@ -252,6 +252,7 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet, options.application_data.assign(packet->application_data().begin(), packet->application_data().end()); + options.additional_data = packet->additional_data(); if (packet->packet_type() != RtpPacketMediaType::kPadding && packet->packet_type() != RtpPacketMediaType::kRetransmission) {