niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
| 11 | #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 14 | #include <map> |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 15 | #include <memory> |
danilchap | b8b6fbb | 2015-12-10 05:05:27 -0800 | [diff] [blame] | 16 | #include <utility> |
| 17 | #include <vector> |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 18 | |
aleloi | a8eb756 | 2016-11-28 07:02:13 -0800 | [diff] [blame] | 19 | #include "webrtc/api/call/transport.h" |
kwiberg | 4485ffb | 2016-04-26 08:14:39 -0700 | [diff] [blame] | 20 | #include "webrtc/base/constructormagic.h" |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 21 | #include "webrtc/base/criticalsection.h" |
danilchap | 7bfe3a2 | 2016-09-19 05:37:56 -0700 | [diff] [blame] | 22 | #include "webrtc/base/deprecation.h" |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 23 | #include "webrtc/base/optional.h" |
danilchap | 47a740b | 2015-12-15 00:30:07 -0800 | [diff] [blame] | 24 | #include "webrtc/base/random.h" |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 25 | #include "webrtc/base/rate_statistics.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 26 | #include "webrtc/base/thread_annotations.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 27 | #include "webrtc/common_types.h" |
brandtr | dbdb3f1 | 2016-11-10 05:04:48 -0800 | [diff] [blame] | 28 | #include "webrtc/modules/rtp_rtcp/include/flexfec_sender.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 29 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 30 | #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 31 | #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 32 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 33 | #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
mflodman | fcf54bd | 2015-04-14 21:28:08 +0200 | [diff] [blame] | 34 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 35 | #include "webrtc/modules/rtp_rtcp/source/ssrc_database.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | namespace webrtc { |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 38 | |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 39 | class OverheadObserver; |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 40 | class RateLimiter; |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 41 | class RtcEventLog; |
| 42 | class RtpPacketToSend; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | class RTPSenderAudio; |
| 44 | class RTPSenderVideo; |
| 45 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 46 | class RTPSender { |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 47 | public: |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 48 | RTPSender(bool audio, |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 49 | Clock* clock, |
| 50 | Transport* transport, |
sprang | ebbf8a8 | 2015-09-21 15:11:14 -0700 | [diff] [blame] | 51 | RtpPacketSender* paced_sender, |
brandtr | dbdb3f1 | 2016-11-10 05:04:48 -0800 | [diff] [blame] | 52 | // TODO(brandtr): Remove |flexfec_sender| when that is hooked up |
| 53 | // to PacedSender instead. |
| 54 | FlexfecSender* flexfec_sender, |
sprang | ebbf8a8 | 2015-09-21 15:11:14 -0700 | [diff] [blame] | 55 | TransportSequenceNumberAllocator* sequence_number_allocator, |
sprang | 5e023eb | 2015-09-14 06:42:43 -0700 | [diff] [blame] | 56 | TransportFeedbackObserver* transport_feedback_callback, |
andresp@webrtc.org | 8f15121 | 2014-07-10 09:39:23 +0000 | [diff] [blame] | 57 | BitrateStatisticsObserver* bitrate_callback, |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 58 | FrameCountObserver* frame_count_observer, |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 59 | SendSideDelayObserver* send_side_delay_observer, |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 60 | RtcEventLog* event_log, |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 61 | SendPacketObserver* send_packet_observer, |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 62 | RateLimiter* nack_rate_limiter, |
| 63 | OverheadObserver* overhead_observer); |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 64 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 65 | ~RTPSender(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 67 | void ProcessBitrate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 69 | uint16_t ActualSendBitrateKbit() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 71 | uint32_t VideoBitrateSent() const; |
| 72 | uint32_t FecOverheadRate() const; |
| 73 | uint32_t NackOverheadRate() const; |
stefan@webrtc.org | d0bdab0 | 2011-10-14 14:24:54 +0000 | [diff] [blame] | 74 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 75 | // Excluding size of RTP and FEC headers. |
| 76 | size_t MaxPayloadSize() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 78 | int32_t RegisterPayload(const char* payload_name, |
| 79 | const int8_t payload_type, |
| 80 | const uint32_t frequency, |
| 81 | const size_t channels, |
| 82 | const uint32_t rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 84 | int32_t DeRegisterSendPayload(const int8_t payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
andresp@webrtc.org | c3c2911 | 2014-08-27 09:39:43 +0000 | [diff] [blame] | 86 | void SetSendPayloadType(int8_t payload_type); |
| 87 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 88 | int8_t SendPayloadType() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
pbos@webrtc.org | 59f20bb | 2013-09-09 16:02:19 +0000 | [diff] [blame] | 90 | void SetSendingStatus(bool enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 92 | void SetSendingMediaStatus(bool enabled); |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 93 | bool SendingMedia() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 95 | void GetDataCounters(StreamDataCounters* rtp_stats, |
| 96 | StreamDataCounters* rtx_stats) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 98 | uint32_t TimestampOffset() const; |
| 99 | void SetTimestampOffset(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 101 | uint32_t GenerateNewSSRC(); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 102 | void SetSSRC(uint32_t ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 104 | uint16_t SequenceNumber() const; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 105 | void SetSequenceNumber(uint16_t seq); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 107 | void SetCsrcs(const std::vector<uint32_t>& csrcs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 109 | void SetMaxRtpPacketSize(size_t max_packet_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 111 | bool SendOutgoingData(FrameType frame_type, |
| 112 | int8_t payload_type, |
| 113 | uint32_t timestamp, |
| 114 | int64_t capture_time_ms, |
| 115 | const uint8_t* payload_data, |
| 116 | size_t payload_size, |
| 117 | const RTPFragmentationHeader* fragmentation, |
| 118 | const RTPVideoHeader* rtp_header, |
| 119 | uint32_t* transport_frame_id_out); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 121 | // RTP header extension |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 122 | int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id); |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 123 | bool IsRtpHeaderExtensionRegistered(RTPExtensionType type); |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 124 | int32_t DeregisterRtpHeaderExtension(RTPExtensionType type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 125 | |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 126 | bool TimeToSendPacket(uint32_t ssrc, |
| 127 | uint16_t sequence_number, |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 128 | int64_t capture_time_ms, |
| 129 | bool retransmission, |
| 130 | int probe_cluster_id); |
| 131 | size_t TimeToSendPadding(size_t bytes, int probe_cluster_id); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 132 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 133 | // NACK. |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 134 | int SelectiveRetransmissions() const; |
| 135 | int SetSelectiveRetransmissions(uint8_t settings); |
Danil Chapovalov | 2800d74 | 2016-08-26 18:48:46 +0200 | [diff] [blame] | 136 | void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 137 | int64_t avg_rtt); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 138 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 139 | void SetStorePacketsStatus(bool enable, uint16_t number_to_store); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 141 | bool StorePackets() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 143 | int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 145 | // Feedback to decide when to stop sending playout delay. |
| 146 | void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks); |
| 147 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 148 | // RTX. |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 149 | void SetRtxStatus(int mode); |
| 150 | int RtxStatus() const; |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 +0000 | [diff] [blame] | 151 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 152 | uint32_t RtxSsrc() const; |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 153 | void SetRtxSsrc(uint32_t ssrc); |
| 154 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 155 | void SetRtxPayloadType(int payload_type, int associated_payload_type); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 156 | |
Danil Chapovalov | 5e57b17 | 2016-09-02 19:15:59 +0200 | [diff] [blame] | 157 | // Create empty packet, fills ssrc, csrcs and reserve place for header |
| 158 | // extensions RtpSender updates before sending. |
| 159 | std::unique_ptr<RtpPacketToSend> AllocatePacket() const; |
| 160 | // Allocate sequence number for provided packet. |
| 161 | // Save packet's fields to generate padding that doesn't break media stream. |
| 162 | // Return false if sending was turned off. |
| 163 | bool AssignSequenceNumber(RtpPacketToSend* packet); |
| 164 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 165 | size_t RtpHeaderLength() const; |
| 166 | uint16_t AllocateSequenceNumber(uint16_t packets_to_send); |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 167 | // Including RTP headers. |
| 168 | size_t MaxRtpPacketSize() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
danilchap | 5fb291a | 2016-08-09 07:43:25 -0700 | [diff] [blame] | 170 | uint32_t SSRC() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 172 | rtc::Optional<uint32_t> FlexfecSsrc() const; |
| 173 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 174 | bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
| 175 | StorageType storage, |
| 176 | RtpPacketSender::Priority priority); |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 177 | |
| 178 | // Audio. |
| 179 | |
| 180 | // Send a DTMF tone using RFC 2833 (4733). |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 181 | int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
ossu | 00bceb1 | 2016-12-02 02:40:02 -0800 | [diff] [blame] | 183 | // This function is deprecated. It was previously used to determine when it |
| 184 | // was time to send a DTMF packet in silence (CNG). |
| 185 | RTC_DEPRECATED int32_t SetAudioPacketSize(uint16_t packet_size_samples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 187 | // Store the audio level in d_bov for |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 188 | // header-extension-for-audio-level-indication. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 189 | int32_t SetAudioLevel(uint8_t level_d_bov); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 191 | RtpVideoCodecTypes VideoCodecType() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 193 | uint32_t MaxConfiguredBitrateVideo() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | |
brandtr | f1bb476 | 2016-11-07 03:05:06 -0800 | [diff] [blame] | 195 | // ULPFEC. |
| 196 | void SetUlpfecConfig(int red_payload_type, int ulpfec_payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | |
brandtr | 1743a19 | 2016-11-07 03:36:05 -0800 | [diff] [blame] | 198 | bool SetFecParameters(const FecProtectionParams& delta_params, |
| 199 | const FecProtectionParams& key_params); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 201 | // Called on update of RTP statistics. |
| 202 | void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); |
| 203 | StreamDataCountersCallback* GetRtpStatisticsCallback() const; |
| 204 | |
sprang@webrtc.org | 6811b6e | 2013-12-13 09:46:59 +0000 | [diff] [blame] | 205 | uint32_t BitrateSent() const; |
| 206 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 207 | void SetRtpState(const RtpState& rtp_state); |
| 208 | RtpState GetRtpState() const; |
| 209 | void SetRtxRtpState(const RtpState& rtp_state); |
| 210 | RtpState GetRtxRtpState() const; |
| 211 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 212 | protected: |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 213 | int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 215 | private: |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 216 | // Maps capture time in milliseconds to send-side delay in milliseconds. |
| 217 | // Send-side delay is the difference between transmission time and capture |
| 218 | // time. |
| 219 | typedef std::map<int64_t, int> SendDelayMap; |
| 220 | |
danilchap | 7bfe3a2 | 2016-09-19 05:37:56 -0700 | [diff] [blame] | 221 | size_t SendPadData(size_t bytes, int probe_cluster_id); |
| 222 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 223 | bool PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet, |
stefan@webrtc.org | 7c6ff2d | 2014-03-19 18:14:52 +0000 | [diff] [blame] | 224 | bool send_over_rtx, |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 225 | bool is_retransmit, |
| 226 | int probe_cluster_id); |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 227 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 228 | // Return the number of bytes sent. Note that both of these functions may |
| 229 | // return a larger value that their argument. |
philipel | a1ed0b3 | 2016-06-01 06:31:17 -0700 | [diff] [blame] | 230 | size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id); |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 231 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 232 | std::unique_ptr<RtpPacketToSend> BuildRtxPacket( |
| 233 | const RtpPacketToSend& packet); |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 234 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 235 | bool SendPacketToNetwork(const RtpPacketToSend& packet, |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 236 | const PacketOptions& options); |
pwestin@webrtc.org | b0061f9 | 2013-04-27 00:41:08 +0000 | [diff] [blame] | 237 | |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 238 | void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms); |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 239 | void UpdateOnSendPacket(int packet_id, |
| 240 | int64_t capture_time_ms, |
| 241 | uint32_t ssrc); |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 242 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 243 | bool UpdateTransportSequenceNumber(RtpPacketToSend* packet, |
| 244 | int* packet_id) const; |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 245 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 246 | void UpdateRtpStats(const RtpPacketToSend& packet, |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 247 | bool is_rtx, |
| 248 | bool is_retransmit); |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 249 | bool IsFecPacket(const RtpPacketToSend& packet) const; |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 250 | |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 251 | void AddPacketToTransportFeedback(uint16_t packet_id, |
| 252 | const RtpPacketToSend& packet, |
| 253 | int probe_cluster_id); |
| 254 | |
| 255 | void UpdateRtpOverhead(const RtpPacketToSend& packet); |
| 256 | |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 257 | Clock* const clock_; |
| 258 | const int64_t clock_delta_ms_; |
danilchap | 47a740b | 2015-12-15 00:30:07 -0800 | [diff] [blame] | 259 | Random random_ GUARDED_BY(send_critsect_); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 260 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 261 | const bool audio_configured_; |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 262 | const std::unique_ptr<RTPSenderAudio> audio_; |
| 263 | const std::unique_ptr<RTPSenderVideo> video_; |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 264 | |
sprang | ebbf8a8 | 2015-09-21 15:11:14 -0700 | [diff] [blame] | 265 | RtpPacketSender* const paced_sender_; |
| 266 | TransportSequenceNumberAllocator* const transport_sequence_number_allocator_; |
sprang | 5e023eb | 2015-09-14 06:42:43 -0700 | [diff] [blame] | 267 | TransportFeedbackObserver* const transport_feedback_observer_; |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 268 | int64_t last_capture_time_ms_sent_; |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 269 | rtc::CriticalSection send_critsect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 270 | |
brandtr | d804895 | 2016-11-07 02:08:51 -0800 | [diff] [blame] | 271 | Transport* transport_; |
sprang@webrtc.org | 5a320fb | 2014-03-13 15:12:37 +0000 | [diff] [blame] | 272 | bool sending_media_ GUARDED_BY(send_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 274 | size_t max_packet_size_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 275 | |
sprang@webrtc.org | efcad39 | 2014-03-25 16:51:35 +0000 | [diff] [blame] | 276 | int8_t payload_type_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 277 | std::map<int8_t, RtpUtility::Payload*> payload_type_map_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | |
stefan | a23fc62 | 2016-07-28 07:56:38 -0700 | [diff] [blame] | 279 | RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(send_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 281 | // Tracks the current request for playout delay limits from application |
| 282 | // and decides whether the current RTP frame should include the playout |
| 283 | // delay extension on header. |
| 284 | PlayoutDelayOracle playout_delay_oracle_; |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 285 | |
Danil Chapovalov | 31e4e80 | 2016-08-03 18:27:40 +0200 | [diff] [blame] | 286 | RtpPacketHistory packet_history_; |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 287 | // TODO(brandtr): Remove |flexfec_packet_history_| when the FlexfecSender |
| 288 | // is hooked up to the PacedSender. |
| 289 | RtpPacketHistory flexfec_packet_history_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 290 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 291 | // Statistics |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 292 | rtc::CriticalSection statistics_crit_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 293 | SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 294 | FrameCounts frame_counts_ GUARDED_BY(statistics_crit_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 295 | StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); |
| 296 | StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); |
| 297 | StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 298 | RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_); |
| 299 | RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_); |
andresp@webrtc.org | 8f15121 | 2014-07-10 09:39:23 +0000 | [diff] [blame] | 300 | FrameCountObserver* const frame_count_observer_; |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 301 | SendSideDelayObserver* const send_side_delay_observer_; |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 302 | RtcEventLog* const event_log_; |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 303 | SendPacketObserver* const send_packet_observer_; |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 304 | BitrateStatisticsObserver* const bitrate_callback_; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 305 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 306 | // RTP variables |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 307 | uint32_t timestamp_offset_ GUARDED_BY(send_critsect_); |
tommi | ae695e9 | 2016-02-02 08:31:45 -0800 | [diff] [blame] | 308 | SSRCDatabase* const ssrc_db_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 309 | uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); |
| 310 | bool sequence_number_forced_ GUARDED_BY(send_critsect_); |
| 311 | uint16_t sequence_number_ GUARDED_BY(send_critsect_); |
| 312 | uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); |
| 313 | bool ssrc_forced_ GUARDED_BY(send_critsect_); |
| 314 | uint32_t ssrc_ GUARDED_BY(send_critsect_); |
danilchap | e5b4141 | 2016-08-22 03:39:23 -0700 | [diff] [blame] | 315 | uint32_t last_rtp_timestamp_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 316 | int64_t capture_time_ms_ GUARDED_BY(send_critsect_); |
| 317 | int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); |
stefan@webrtc.org | 8b94e3d | 2014-07-17 16:10:14 +0000 | [diff] [blame] | 318 | bool media_has_been_sent_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 319 | bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 320 | std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 321 | int rtx_ GUARDED_BY(send_critsect_); |
| 322 | uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 323 | // Mapping rtx_payload_type_map_[associated] = rtx. |
| 324 | std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_); |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 325 | size_t rtp_overhead_bytes_per_packet_ GUARDED_BY(send_critsect_); |
andresp@webrtc.org | d09d074 | 2014-03-26 14:27:34 +0000 | [diff] [blame] | 326 | |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 327 | RateLimiter* const retransmission_rate_limiter_; |
michaelt | 4da3044 | 2016-11-17 01:38:43 -0800 | [diff] [blame] | 328 | OverheadObserver* overhead_observer_; |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 329 | |
elad.alon | c3dfff3 | 2017-01-26 02:46:55 -0800 | [diff] [blame^] | 330 | const bool send_side_bwe_with_overhead_; |
| 331 | |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 332 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 333 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 335 | } // namespace webrtc |
| 336 | |
| 337 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |