Skip to content

Commit

Permalink
Add option to attach custom object to an rtp packet
Browse files Browse the repository at this point in the history
As an alternative to attaching custom array of bytes.

Bug: b/178094662
Change-Id: I92dcbf04998d8206091125febc520ebfcc4bcebf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203264
Reviewed-by: Christoffer Rodbro <[email protected]>
Reviewed-by: Harald Alvestrand <[email protected]>
Reviewed-by: Emil Lundmark <[email protected]>
Commit-Queue: Danil Chapovalov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33069}
  • Loading branch information
DanilChapovalov authored and Commit Bot committed Jan 25, 2021
1 parent ded6636 commit 5312a8f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ rtc_library("transport_api") {
"call/transport.cc",
"call/transport.h",
]
deps = [
":refcountedbase",
":scoped_refptr",
]
}

rtc_source_set("bitrate_allocation") {
Expand Down
7 changes: 6 additions & 1 deletion api/call/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#include <vector>

#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"

namespace webrtc {

// TODO(holmer): Look into unifying this with the PacketOptions in
Expand All @@ -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<uint8_t> application_data;
// Additional data bound to the RTP packet for use in application code,
// outside of WebRTC.
std::vector<uint8_t> application_data;
rtc::scoped_refptr<rtc::RefCountedBase> additional_data;
// Whether this is a retransmission of an earlier packet.
bool is_retransmit = false;
bool included_in_feedback = false;
Expand Down
2 changes: 2 additions & 0 deletions modules/rtp_rtcp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 18 additions & 2 deletions modules/rtp_rtcp/source/rtp_packet_received.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@

#include <stdint.h>

#include <utility>
#include <vector>

#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();
Expand Down Expand Up @@ -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<const uint8_t> application_data() const {
return application_data_;
}
RTC_DEPRECATED
void set_application_data(rtc::ArrayView<const uint8_t> data) {
application_data_.assign(data.begin(), data.end());
}
rtc::scoped_refptr<rtc::RefCountedBase> additional_data() const {
return additional_data_;
}
void set_additional_data(rtc::scoped_refptr<rtc::RefCountedBase> data) {
additional_data_ = std::move(data);
}

private:
int64_t arrival_time_ms_ = 0;
int payload_type_frequency_ = 0;
bool recovered_ = false;
rtc::scoped_refptr<rtc::RefCountedBase> additional_data_;
std::vector<uint8_t> application_data_;
};

Expand Down
19 changes: 17 additions & 2 deletions modules/rtp_rtcp/source/rtp_packet_to_send.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@
#include <stddef.h>
#include <stdint.h>

#include <utility>
#include <vector>

#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"
#include "modules/rtp_rtcp/source/rtp_packet.h"

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.
Expand Down Expand Up @@ -64,15 +69,22 @@ 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<const uint8_t> application_data() const {
return application_data_;
}

void set_application_data(rtc::ArrayView<const uint8_t> data) {
application_data_.assign(data.begin(), data.end());
}
rtc::scoped_refptr<rtc::RefCountedBase> additional_data() const {
return additional_data_;
}
void set_additional_data(rtc::scoped_refptr<rtc::RefCountedBase> data) {
additional_data_ = std::move(data);
}

void set_packetization_finish_time_ms(int64_t time) {
SetExtension<VideoTimingExtension>(
Expand Down Expand Up @@ -122,7 +134,10 @@ class RtpPacketToSend : public RtpPacket {
absl::optional<RtpPacketMediaType> packet_type_;
bool allow_retransmission_ = false;
absl::optional<uint16_t> retransmitted_sequence_number_;
// TODO(danilchap): Remove applicaion_data_ when application switched to use
// additional_data instead.
std::vector<uint8_t> application_data_;
rtc::scoped_refptr<rtc::RefCountedBase> additional_data_;
bool is_first_packet_of_frame_ = false;
bool is_key_frame_ = false;
bool fec_protect_packet_ = false;
Expand Down
1 change: 1 addition & 0 deletions modules/rtp_rtcp/source/rtp_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ std::unique_ptr<RtpPacketToSend> 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());
Expand Down
1 change: 1 addition & 0 deletions modules/rtp_rtcp/source/rtp_sender_egress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5312a8f

Please sign in to comment.