blob: 467dd740860a0ead485d5f1e07fd87e610767081 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org12dc1a32013-08-05 16:22:53 +000013
danilchapb8b6fbb2015-12-10 05:05:27 -080014#include <list>
pwestin@webrtc.org00741872012-01-19 15:56:10 +000015#include <map>
kwiberg84be5112016-04-27 01:19:58 -070016#include <memory>
danilchapb8b6fbb2015-12-10 05:05:27 -080017#include <utility>
18#include <vector>
pwestin@webrtc.org00741872012-01-19 15:56:10 +000019
kwiberg4485ffb2016-04-26 08:14:39 -070020#include "webrtc/base/constructormagic.h"
tommiae695e92016-02-02 08:31:45 -080021#include "webrtc/base/criticalsection.h"
danilchap47a740b2015-12-15 00:30:07 -080022#include "webrtc/base/random.h"
sprangcd349d92016-07-13 09:11:28 -070023#include "webrtc/base/rate_statistics.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000024#include "webrtc/base/thread_annotations.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000025#include "webrtc/common_types.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
isheriff6b4b5f32016-06-08 00:24:21 -070027#include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000028#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000029#include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000030#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
mflodmanfcf54bd2015-04-14 21:28:08 +020031#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000032#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
pbos2d566682015-09-28 09:59:31 -070033#include "webrtc/transport.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000034
niklase@google.com470e71d2011-07-07 08:21:25 +000035namespace webrtc {
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000036
sprangcd349d92016-07-13 09:11:28 -070037class RateLimiter;
niklase@google.com470e71d2011-07-07 08:21:25 +000038class RTPSenderAudio;
39class RTPSenderVideo;
terelius429c3452016-01-21 05:42:04 -080040class RtcEventLog;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000042class RTPSenderInterface {
43 public:
44 RTPSenderInterface() {}
45 virtual ~RTPSenderInterface() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.org2f446732013-04-08 11:08:41 +000047 virtual uint32_t SSRC() const = 0;
48 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
Sergey Ulanovec4f0682016-07-28 15:19:10 -070050 // Deprecated version of BuildRtpHeader(). |timestamp_provided| and
51 // |inc_sequence_number| are ignored.
52 // TODO(sergeyu): Remove this method.
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000053 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000054 int8_t payload_type,
55 bool marker_bit,
56 uint32_t capture_timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000057 int64_t capture_time_ms,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000058 bool timestamp_provided = true,
59 bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
Sergey Ulanovec4f0682016-07-28 15:19:10 -070061 virtual int32_t BuildRtpHeader(uint8_t* data_buffer,
62 int8_t payload_type,
63 bool marker_bit,
64 uint32_t capture_timestamp,
65 int64_t capture_time_ms) = 0;
66
isheriff6b4b5f32016-06-08 00:24:21 -070067 // This returns the expected header length taking into consideration
68 // the optional RTP header extensions that may not be currently active.
69 virtual size_t RtpHeaderLength() const = 0;
mflodmanfcf54bd2015-04-14 21:28:08 +020070 // Returns the next sequence number to use for a packet and allocates
71 // 'packets_to_send' number of sequence numbers. It's important all allocated
72 // sequence numbers are used in sequence to avoid perceived packet loss.
73 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000074 virtual uint16_t SequenceNumber() const = 0;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000075 virtual size_t MaxPayloadLength() const = 0;
76 virtual size_t MaxDataPayloadLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000077 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
sprangebbf8a82015-09-21 15:11:14 -070079 virtual int32_t SendToNetwork(uint8_t* data_buffer,
80 size_t payload_length,
81 size_t rtp_header_length,
82 int64_t capture_time_ms,
83 StorageType storage,
84 RtpPacketSender::Priority priority) = 0;
guoweis@webrtc.org45362892015-03-04 22:55:15 +000085
86 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
87 size_t rtp_packet_length,
88 const RTPHeader& rtp_header,
89 VideoRotation rotation) const = 0;
90 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0;
isheriff6b4b5f32016-06-08 00:24:21 -070091 virtual bool ActivateCVORtpHeaderExtension() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000092};
93
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000094class RTPSender : public RTPSenderInterface {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000095 public:
Peter Boströmac547a62015-09-17 23:03:57 +020096 RTPSender(bool audio,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000097 Clock* clock,
98 Transport* transport,
sprangebbf8a82015-09-21 15:11:14 -070099 RtpPacketSender* paced_sender,
100 TransportSequenceNumberAllocator* sequence_number_allocator,
sprang5e023eb2015-09-14 06:42:43 -0700101 TransportFeedbackObserver* transport_feedback_callback,
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000102 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000103 FrameCountObserver* frame_count_observer,
terelius429c3452016-01-21 05:42:04 -0800104 SendSideDelayObserver* send_side_delay_observer,
asapersson35151f32016-05-02 23:44:01 -0700105 RtcEventLog* event_log,
sprangcd349d92016-07-13 09:11:28 -0700106 SendPacketObserver* send_packet_observer,
107 RateLimiter* nack_rate_limiter);
asapersson35151f32016-05-02 23:44:01 -0700108
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000109 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000111 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000113 uint16_t ActualSendBitrateKbit() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000115 uint32_t VideoBitrateSent() const;
116 uint32_t FecOverheadRate() const;
117 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000118
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000119 // Includes size of RTP and FEC headers.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000120 size_t MaxDataPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
Peter Boström8b79b072016-02-26 16:31:37 +0100122 int32_t RegisterPayload(const char* payload_name,
123 const int8_t payload_type,
124 const uint32_t frequency,
125 const size_t channels,
126 const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000128 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +0000130 void SetSendPayloadType(int8_t payload_type);
131
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000132 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000134 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000136 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000138 void SetSendingMediaStatus(bool enabled);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000139 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000141 void GetDataCounters(StreamDataCounters* rtp_stats,
142 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000144 uint32_t StartTimestamp() const;
145 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000147 uint32_t GenerateNewSSRC();
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000148 void SetSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000150 uint16_t SequenceNumber() const override;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000151 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000153 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
danilchap41befce2016-03-30 11:11:51 -0700155 void SetMaxPayloadLength(size_t max_payload_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000157 int32_t SendOutgoingData(FrameType frame_type,
158 int8_t payload_type,
159 uint32_t timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000160 int64_t capture_time_ms,
161 const uint8_t* payload_data,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000162 size_t payload_size,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000163 const RTPFragmentationHeader* fragmentation,
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700164 const RTPVideoHeader* rtp_header);
niklase@google.com470e71d2011-07-07 08:21:25 +0000165
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000166 // RTP header extension
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000167 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset);
168 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000169 void SetVideoRotation(VideoRotation rotation);
sprang@webrtc.org30933902015-03-17 14:33:12 +0000170 int32_t SetTransportSequenceNumber(uint16_t sequence_number);
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000172 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
danilchap162abd32015-12-10 02:39:40 -0800173 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000174 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000175
isheriff6b4b5f32016-06-08 00:24:21 -0700176 size_t RtpHeaderExtensionLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000177
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700178 uint16_t BuildRtpHeaderExtension(uint8_t* data_buffer, bool marker_bit) const
stefana23fc622016-07-28 07:56:38 -0700179 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000180
stefana23fc622016-07-28 07:56:38 -0700181 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t* data_buffer) const
182 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
183 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const
184 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
185 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const
186 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
187 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const
188 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700189 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer,
stefana23fc622016-07-28 07:56:38 -0700190 uint16_t sequence_number) const
191 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
isheriff6b4b5f32016-06-08 00:24:21 -0700192 uint8_t BuildPlayoutDelayExtension(uint8_t* data_buffer,
193 uint16_t min_playout_delay_ms,
stefana23fc622016-07-28 07:56:38 -0700194 uint16_t max_playout_delay_ms) const
195 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700196
197 // Verifies that the specified extension is registered, and that it is
198 // present in rtp packet. If extension is not registered kNotRegistered is
199 // returned. If extension cannot be found in the rtp header, or if it is
200 // malformed, kError is returned. Otherwise *extension_offset is set to the
201 // offset of the extension from the beginning of the rtp packet and kOk is
202 // returned.
203 enum class ExtensionStatus {
204 kNotRegistered,
205 kOk,
206 kError,
207 };
208 ExtensionStatus VerifyExtension(RTPExtensionType extension_type,
209 uint8_t* rtp_packet,
210 size_t rtp_packet_length,
211 const RTPHeader& rtp_header,
212 size_t extension_length_bytes,
213 size_t* extension_offset) const
tommiae695e92016-02-02 08:31:45 -0800214 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000215
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000216 bool UpdateAudioLevel(uint8_t* rtp_packet,
217 size_t rtp_packet_length,
218 const RTPHeader& rtp_header,
219 bool is_voiced,
220 uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000221
danilchap162abd32015-12-10 02:39:40 -0800222 bool UpdateVideoRotation(uint8_t* rtp_packet,
223 size_t rtp_packet_length,
224 const RTPHeader& rtp_header,
225 VideoRotation rotation) const override;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000226
philipela1ed0b32016-06-01 06:31:17 -0700227 bool TimeToSendPacket(uint16_t sequence_number,
228 int64_t capture_time_ms,
229 bool retransmission,
230 int probe_cluster_id);
231 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000232
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000233 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000234 int SelectiveRetransmissions() const;
235 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000236 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000237 int64_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000238
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000239 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000241 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000243 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
isheriff6b4b5f32016-06-08 00:24:21 -0700245 // Feedback to decide when to stop sending playout delay.
246 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks);
247
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000248 // RTX.
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000249 void SetRtxStatus(int mode);
250 int RtxStatus() const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000251
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000252 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000253 void SetRtxSsrc(uint32_t ssrc);
254
Shao Changbine62202f2015-04-21 20:24:50 +0800255 void SetRtxPayloadType(int payload_type, int associated_payload_type);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000256
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000257 // Functions wrapping RTPSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000258 int32_t BuildRTPheader(uint8_t* data_buffer,
259 int8_t payload_type,
260 bool marker_bit,
261 uint32_t capture_timestamp,
262 int64_t capture_time_ms,
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700263 bool timestamp_provided = true,
264 bool inc_sequence_number = true) override;
265 int32_t BuildRtpHeader(uint8_t* data_buffer,
266 int8_t payload_type,
267 bool marker_bit,
268 uint32_t capture_timestamp,
269 int64_t capture_time_ms) override;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000270
isheriff6b4b5f32016-06-08 00:24:21 -0700271 size_t RtpHeaderLength() const override;
mflodmanfcf54bd2015-04-14 21:28:08 +0200272 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000273 size_t MaxPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000274
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000275 // Current timestamp.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000276 uint32_t Timestamp() const override;
277 uint32_t SSRC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000278
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000279 int32_t SendToNetwork(uint8_t* data_buffer,
280 size_t payload_length,
281 size_t rtp_header_length,
282 int64_t capture_time_ms,
283 StorageType storage,
sprangebbf8a82015-09-21 15:11:14 -0700284 RtpPacketSender::Priority priority) override;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000285
286 // Audio.
287
288 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000289 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000291 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000292 // packet in silence (CNG).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000293 int32_t SetAudioPacketSize(uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000294
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000295 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000296 // header-extension-for-audio-level-indication.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000297 int32_t SetAudioLevel(uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000299 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000300 int32_t SetRED(int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000302 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000303 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000305 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000306
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000307 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000309 // FEC.
pbosba8c15b2015-07-14 09:36:34 -0700310 void SetGenericFECStatus(bool enable,
311 uint8_t payload_type_red,
312 uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000313
pbosba8c15b2015-07-14 09:36:34 -0700314 void GenericFECStatus(bool* enable,
315 uint8_t* payload_type_red,
316 uint8_t* payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000318 int32_t SetFecParameters(const FecProtectionParams *delta_params,
319 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
Stefan Holmer586b19b2015-09-18 11:14:31 +0200321 size_t SendPadData(size_t bytes,
322 bool timestamp_provided,
323 uint32_t timestamp,
philipel46948c12016-06-01 04:04:40 -0700324 int64_t capture_time_ms);
philipela1ed0b32016-06-01 06:31:17 -0700325 size_t SendPadData(size_t bytes,
326 bool timestamp_provided,
327 uint32_t timestamp,
328 int64_t capture_time_ms,
329 int probe_cluster_id);
330
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000331 // Called on update of RTP statistics.
332 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
333 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
334
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000335 uint32_t BitrateSent() const;
336
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000337 void SetRtpState(const RtpState& rtp_state);
338 RtpState GetRtpState() const;
339 void SetRtxRtpState(const RtpState& rtp_state);
340 RtpState GetRtxRtpState() const;
isheriff6b4b5f32016-06-08 00:24:21 -0700341 bool ActivateCVORtpHeaderExtension() override;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000342
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000343 protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000344 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000346 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000347 // Maps capture time in milliseconds to send-side delay in milliseconds.
348 // Send-side delay is the difference between transmission time and capture
349 // time.
350 typedef std::map<int64_t, int> SendDelayMap;
351
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000352 size_t CreateRtpHeader(uint8_t* header,
353 int8_t payload_type,
354 uint32_t ssrc,
355 bool marker_bit,
356 uint32_t timestamp,
357 uint16_t sequence_number,
stefana23fc622016-07-28 07:56:38 -0700358 const std::vector<uint32_t>& csrcs) const
359 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000360
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000361 bool PrepareAndSendPacket(uint8_t* buffer,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000362 size_t length,
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000363 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000364 bool send_over_rtx,
philipela1ed0b32016-06-01 06:31:17 -0700365 bool is_retransmit,
366 int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000367
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000368 // Return the number of bytes sent. Note that both of these functions may
369 // return a larger value that their argument.
philipela1ed0b32016-06-01 06:31:17 -0700370 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000371
Stefan Holmer586b19b2015-09-18 11:14:31 +0200372 void BuildPaddingPacket(uint8_t* packet,
373 size_t header_length,
374 size_t padding_length);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000375
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000376 void BuildRtxPacket(uint8_t* buffer, size_t* length,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000377 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000378
stefan1d8a5062015-10-02 03:39:33 -0700379 bool SendPacketToNetwork(const uint8_t* packet,
380 size_t size,
381 const PacketOptions& options);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000382
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000383 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
asapersson35151f32016-05-02 23:44:01 -0700384 void UpdateOnSendPacket(int packet_id,
385 int64_t capture_time_ms,
386 uint32_t ssrc);
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000387
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000388 // Find the byte position of the RTP extension as indicated by |type| in
389 // |rtp_packet|. Return false if such extension doesn't exist.
390 bool FindHeaderExtensionPosition(RTPExtensionType type,
391 const uint8_t* rtp_packet,
392 size_t rtp_packet_length,
393 const RTPHeader& rtp_header,
stefana23fc622016-07-28 07:56:38 -0700394 size_t* position) const
395 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000396
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000397 void UpdateTransmissionTimeOffset(uint8_t* rtp_packet,
398 size_t rtp_packet_length,
399 const RTPHeader& rtp_header,
400 int64_t time_diff_ms) const;
401 void UpdateAbsoluteSendTime(uint8_t* rtp_packet,
402 size_t rtp_packet_length,
403 const RTPHeader& rtp_header,
404 int64_t now_ms) const;
asapersson35151f32016-05-02 23:44:01 -0700405
stefana23fc622016-07-28 07:56:38 -0700406 bool UpdateTransportSequenceNumber(uint8_t* rtp_packet,
asapersson35151f32016-05-02 23:44:01 -0700407 size_t rtp_packet_length,
stefana23fc622016-07-28 07:56:38 -0700408 const RTPHeader& rtp_header,
409 int* sequence_number) const;
asapersson35151f32016-05-02 23:44:01 -0700410
isheriff6b4b5f32016-06-08 00:24:21 -0700411 void UpdatePlayoutDelayLimits(uint8_t* rtp_packet,
412 size_t rtp_packet_length,
413 const RTPHeader& rtp_header,
414 uint16_t min_playout_delay,
415 uint16_t max_playout_delay) const;
416
asapersson35151f32016-05-02 23:44:01 -0700417 bool AllocateTransportSequenceNumber(int* packet_id) const;
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000418
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000419 void UpdateRtpStats(const uint8_t* buffer,
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000420 size_t packet_length,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000421 const RTPHeader& header,
422 bool is_rtx,
423 bool is_retransmit);
424 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
425
tommiae695e92016-02-02 08:31:45 -0800426 Clock* const clock_;
427 const int64_t clock_delta_ms_;
danilchap47a740b2015-12-15 00:30:07 -0800428 Random random_ GUARDED_BY(send_critsect_);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000429
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000430 const bool audio_configured_;
kwiberg84be5112016-04-27 01:19:58 -0700431 const std::unique_ptr<RTPSenderAudio> audio_;
432 const std::unique_ptr<RTPSenderVideo> video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000433
sprangebbf8a82015-09-21 15:11:14 -0700434 RtpPacketSender* const paced_sender_;
435 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
sprang5e023eb2015-09-14 06:42:43 -0700436 TransportFeedbackObserver* const transport_feedback_observer_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000437 int64_t last_capture_time_ms_sent_;
tommiae695e92016-02-02 08:31:45 -0800438 rtc::CriticalSection send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000439
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000440 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000441 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000442
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000443 size_t max_payload_length_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000444
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000445 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000446 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000447
stefana23fc622016-07-28 07:56:38 -0700448 RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000449 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000450 uint32_t absolute_send_time_;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000451 VideoRotation rotation_;
isheriff6b4b5f32016-06-08 00:24:21 -0700452 bool video_rotation_active_;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000453 uint16_t transport_sequence_number_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
isheriff6b4b5f32016-06-08 00:24:21 -0700455 // Tracks the current request for playout delay limits from application
456 // and decides whether the current RTP frame should include the playout
457 // delay extension on header.
458 PlayoutDelayOracle playout_delay_oracle_;
459 bool playout_delay_active_ GUARDED_BY(send_critsect_);
460
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000461 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000462
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000463 // Statistics
danilchap7c9426c2016-04-14 03:05:31 -0700464 rtc::CriticalSection statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000465 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000466 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000467 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
468 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
469 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
sprangcd349d92016-07-13 09:11:28 -0700470 RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_);
471 RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000472 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000473 SendSideDelayObserver* const send_side_delay_observer_;
terelius429c3452016-01-21 05:42:04 -0800474 RtcEventLog* const event_log_;
asapersson35151f32016-05-02 23:44:01 -0700475 SendPacketObserver* const send_packet_observer_;
sprangcd349d92016-07-13 09:11:28 -0700476 BitrateStatisticsObserver* const bitrate_callback_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000477
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000478 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000479 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
480 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
tommiae695e92016-02-02 08:31:45 -0800481 SSRCDatabase* const ssrc_db_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000482 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
483 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
484 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
485 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
486 bool ssrc_forced_ GUARDED_BY(send_critsect_);
487 uint32_t ssrc_ GUARDED_BY(send_critsect_);
488 uint32_t timestamp_ GUARDED_BY(send_critsect_);
489 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
490 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000491 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000492 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000493 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000494 int rtx_ GUARDED_BY(send_critsect_);
495 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
Shao Changbine62202f2015-04-21 20:24:50 +0800496 // Mapping rtx_payload_type_map_[associated] = rtx.
497 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000498
sprangcd349d92016-07-13 09:11:28 -0700499 RateLimiter* const retransmission_rate_limiter_;
terelius429c3452016-01-21 05:42:04 -0800500
501 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
niklase@google.com470e71d2011-07-07 08:21:25 +0000502};
niklase@google.com470e71d2011-07-07 08:21:25 +0000503
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000504} // namespace webrtc
505
506#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_