1 /* 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ 11 #define MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ 12 13 #include <stddef.h> 14 #include <stdint.h> 15 16 #include <utility> 17 18 #include "absl/types/optional.h" 19 #include "api/array_view.h" 20 #include "api/ref_counted_base.h" 21 #include "api/scoped_refptr.h" 22 #include "api/units/time_delta.h" 23 #include "api/units/timestamp.h" 24 #include "api/video/video_timing.h" 25 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 26 #include "modules/rtp_rtcp/source/rtp_header_extensions.h" 27 #include "modules/rtp_rtcp/source/rtp_packet.h" 28 29 namespace webrtc { 30 // Class to hold rtp packet with metadata for sender side. 31 // The metadata is not send over the wire, but packet sender may use it to 32 // create rtp header extensions or other data that is sent over the wire. 33 class RtpPacketToSend : public RtpPacket { 34 public: 35 // RtpPacketToSend::Type is deprecated. Use RtpPacketMediaType directly. 36 using Type = RtpPacketMediaType; 37 38 explicit RtpPacketToSend(const ExtensionManager* extensions); 39 RtpPacketToSend(const ExtensionManager* extensions, size_t capacity); 40 RtpPacketToSend(const RtpPacketToSend& packet); 41 RtpPacketToSend(RtpPacketToSend&& packet); 42 43 RtpPacketToSend& operator=(const RtpPacketToSend& packet); 44 RtpPacketToSend& operator=(RtpPacketToSend&& packet); 45 46 ~RtpPacketToSend(); 47 48 // Time in local time base as close as it can to frame capture time. capture_time()49 webrtc::Timestamp capture_time() const { return capture_time_; } set_capture_time(webrtc::Timestamp time)50 void set_capture_time(webrtc::Timestamp time) { capture_time_ = time; } 51 set_packet_type(RtpPacketMediaType type)52 void set_packet_type(RtpPacketMediaType type) { packet_type_ = type; } packet_type()53 absl::optional<RtpPacketMediaType> packet_type() const { 54 return packet_type_; 55 } 56 57 // If this is a retransmission, indicates the sequence number of the original 58 // media packet that this packet represents. If RTX is used this will likely 59 // be different from SequenceNumber(). set_retransmitted_sequence_number(uint16_t sequence_number)60 void set_retransmitted_sequence_number(uint16_t sequence_number) { 61 retransmitted_sequence_number_ = sequence_number; 62 } retransmitted_sequence_number()63 absl::optional<uint16_t> retransmitted_sequence_number() const { 64 return retransmitted_sequence_number_; 65 } 66 set_allow_retransmission(bool allow_retransmission)67 void set_allow_retransmission(bool allow_retransmission) { 68 allow_retransmission_ = allow_retransmission; 69 } allow_retransmission()70 bool allow_retransmission() const { return allow_retransmission_; } 71 72 // An application can attach arbitrary data to an RTP packet using 73 // `additional_data`. The additional data does not affect WebRTC processing. additional_data()74 rtc::scoped_refptr<rtc::RefCountedBase> additional_data() const { 75 return additional_data_; 76 } set_additional_data(rtc::scoped_refptr<rtc::RefCountedBase> data)77 void set_additional_data(rtc::scoped_refptr<rtc::RefCountedBase> data) { 78 additional_data_ = std::move(data); 79 } 80 set_packetization_finish_time(webrtc::Timestamp time)81 void set_packetization_finish_time(webrtc::Timestamp time) { 82 SetExtension<VideoTimingExtension>( 83 VideoSendTiming::GetDeltaCappedMs(time - capture_time_), 84 VideoTimingExtension::kPacketizationFinishDeltaOffset); 85 } 86 set_pacer_exit_time(webrtc::Timestamp time)87 void set_pacer_exit_time(webrtc::Timestamp time) { 88 SetExtension<VideoTimingExtension>( 89 VideoSendTiming::GetDeltaCappedMs(time - capture_time_), 90 VideoTimingExtension::kPacerExitDeltaOffset); 91 } 92 set_network_time(webrtc::Timestamp time)93 void set_network_time(webrtc::Timestamp time) { 94 SetExtension<VideoTimingExtension>( 95 VideoSendTiming::GetDeltaCappedMs(time - capture_time_), 96 VideoTimingExtension::kNetworkTimestampDeltaOffset); 97 } 98 set_network2_time(webrtc::Timestamp time)99 void set_network2_time(webrtc::Timestamp time) { 100 SetExtension<VideoTimingExtension>( 101 VideoSendTiming::GetDeltaCappedMs(time - capture_time_), 102 VideoTimingExtension::kNetwork2TimestampDeltaOffset); 103 } 104 105 // Indicates if packet is the first packet of a video frame. set_first_packet_of_frame(bool is_first_packet)106 void set_first_packet_of_frame(bool is_first_packet) { 107 is_first_packet_of_frame_ = is_first_packet; 108 } is_first_packet_of_frame()109 bool is_first_packet_of_frame() const { return is_first_packet_of_frame_; } 110 111 // Indicates if packet contains payload for a video key-frame. set_is_key_frame(bool is_key_frame)112 void set_is_key_frame(bool is_key_frame) { is_key_frame_ = is_key_frame; } is_key_frame()113 bool is_key_frame() const { return is_key_frame_; } 114 115 // Indicates if packets should be protected by FEC (Forward Error Correction). set_fec_protect_packet(bool protect)116 void set_fec_protect_packet(bool protect) { fec_protect_packet_ = protect; } fec_protect_packet()117 bool fec_protect_packet() const { return fec_protect_packet_; } 118 119 // Indicates if packet is using RED encapsulation, in accordance with 120 // https://tools.ietf.org/html/rfc2198 set_is_red(bool is_red)121 void set_is_red(bool is_red) { is_red_ = is_red; } is_red()122 bool is_red() const { return is_red_; } 123 124 // The amount of time spent in the send queue, used for totalPacketSendDelay. 125 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-totalpacketsenddelay set_time_in_send_queue(TimeDelta time_in_send_queue)126 void set_time_in_send_queue(TimeDelta time_in_send_queue) { 127 time_in_send_queue_ = time_in_send_queue; 128 } time_in_send_queue()129 absl::optional<TimeDelta> time_in_send_queue() const { 130 return time_in_send_queue_; 131 } 132 133 private: 134 webrtc::Timestamp capture_time_ = webrtc::Timestamp::Zero(); 135 absl::optional<RtpPacketMediaType> packet_type_; 136 bool allow_retransmission_ = false; 137 absl::optional<uint16_t> retransmitted_sequence_number_; 138 rtc::scoped_refptr<rtc::RefCountedBase> additional_data_; 139 bool is_first_packet_of_frame_ = false; 140 bool is_key_frame_ = false; 141 bool fec_protect_packet_ = false; 142 bool is_red_ = false; 143 absl::optional<TimeDelta> time_in_send_queue_; 144 }; 145 146 } // namespace webrtc 147 #endif // MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ 148