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 <vector> 17 18 #include "absl/types/optional.h" 19 #include "api/array_view.h" 20 #include "api/video/video_timing.h" 21 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 22 #include "modules/rtp_rtcp/source/rtp_header_extensions.h" 23 #include "modules/rtp_rtcp/source/rtp_packet.h" 24 25 namespace webrtc { 26 // Class to hold rtp packet with metadata for sender side. 27 class RtpPacketToSend : public RtpPacket { 28 public: 29 // RtpPacketToSend::Type is deprecated. Use RtpPacketMediaType directly. 30 using Type = RtpPacketMediaType; 31 32 explicit RtpPacketToSend(const ExtensionManager* extensions); 33 RtpPacketToSend(const ExtensionManager* extensions, size_t capacity); 34 RtpPacketToSend(const RtpPacketToSend& packet); 35 RtpPacketToSend(RtpPacketToSend&& packet); 36 37 RtpPacketToSend& operator=(const RtpPacketToSend& packet); 38 RtpPacketToSend& operator=(RtpPacketToSend&& packet); 39 40 ~RtpPacketToSend(); 41 42 // Time in local time base as close as it can to frame capture time. capture_time_ms()43 int64_t capture_time_ms() const { return capture_time_ms_; } 44 set_capture_time_ms(int64_t time)45 void set_capture_time_ms(int64_t time) { capture_time_ms_ = time; } 46 set_packet_type(RtpPacketMediaType type)47 void set_packet_type(RtpPacketMediaType type) { packet_type_ = type; } packet_type()48 absl::optional<RtpPacketMediaType> packet_type() const { 49 return packet_type_; 50 } 51 52 // If this is a retransmission, indicates the sequence number of the original 53 // media packet that this packet represents. If RTX is used this will likely 54 // be different from SequenceNumber(). set_retransmitted_sequence_number(uint16_t sequence_number)55 void set_retransmitted_sequence_number(uint16_t sequence_number) { 56 retransmitted_sequence_number_ = sequence_number; 57 } retransmitted_sequence_number()58 absl::optional<uint16_t> retransmitted_sequence_number() { 59 return retransmitted_sequence_number_; 60 } 61 set_allow_retransmission(bool allow_retransmission)62 void set_allow_retransmission(bool allow_retransmission) { 63 allow_retransmission_ = allow_retransmission; 64 } allow_retransmission()65 bool allow_retransmission() { return allow_retransmission_; } 66 67 // Additional data bound to the RTP packet for use in application code, 68 // outside of WebRTC. application_data()69 rtc::ArrayView<const uint8_t> application_data() const { 70 return application_data_; 71 } 72 set_application_data(rtc::ArrayView<const uint8_t> data)73 void set_application_data(rtc::ArrayView<const uint8_t> data) { 74 application_data_.assign(data.begin(), data.end()); 75 } 76 set_packetization_finish_time_ms(int64_t time)77 void set_packetization_finish_time_ms(int64_t time) { 78 SetExtension<VideoTimingExtension>( 79 VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), 80 VideoTimingExtension::kPacketizationFinishDeltaOffset); 81 } 82 set_pacer_exit_time_ms(int64_t time)83 void set_pacer_exit_time_ms(int64_t time) { 84 SetExtension<VideoTimingExtension>( 85 VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), 86 VideoTimingExtension::kPacerExitDeltaOffset); 87 } 88 set_network_time_ms(int64_t time)89 void set_network_time_ms(int64_t time) { 90 SetExtension<VideoTimingExtension>( 91 VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), 92 VideoTimingExtension::kNetworkTimestampDeltaOffset); 93 } 94 set_network2_time_ms(int64_t time)95 void set_network2_time_ms(int64_t time) { 96 SetExtension<VideoTimingExtension>( 97 VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), 98 VideoTimingExtension::kNetwork2TimestampDeltaOffset); 99 } 100 101 // Indicates if packet is the first packet of a video frame. set_first_packet_of_frame(bool is_first_packet)102 void set_first_packet_of_frame(bool is_first_packet) { 103 is_first_packet_of_frame_ = is_first_packet; 104 } is_first_packet_of_frame()105 bool is_first_packet_of_frame() const { return is_first_packet_of_frame_; } 106 107 // Indicates if packet contains payload for a video key-frame. set_is_key_frame(bool is_key_frame)108 void set_is_key_frame(bool is_key_frame) { is_key_frame_ = is_key_frame; } is_key_frame()109 bool is_key_frame() const { return is_key_frame_; } 110 111 // Indicates if packets should be protected by FEC (Forward Error Correction). set_fec_protect_packet(bool protect)112 void set_fec_protect_packet(bool protect) { fec_protect_packet_ = protect; } fec_protect_packet()113 bool fec_protect_packet() const { return fec_protect_packet_; } 114 115 // Indicates if packet is using RED encapsulation, in accordance with 116 // https://tools.ietf.org/html/rfc2198 set_is_red(bool is_red)117 void set_is_red(bool is_red) { is_red_ = is_red; } is_red()118 bool is_red() const { return is_red_; } 119 120 private: 121 int64_t capture_time_ms_ = 0; 122 absl::optional<RtpPacketMediaType> packet_type_; 123 bool allow_retransmission_ = false; 124 absl::optional<uint16_t> retransmitted_sequence_number_; 125 std::vector<uint8_t> application_data_; 126 bool is_first_packet_of_frame_ = false; 127 bool is_key_frame_ = false; 128 bool fec_protect_packet_ = false; 129 bool is_red_ = false; 130 }; 131 132 } // namespace webrtc 133 #endif // MODULES_RTP_RTCP_SOURCE_RTP_PACKET_TO_SEND_H_ 134