blob: 14ec3c1f68411f3846721bb110b5ffbc84fc8362 [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;
Danil Chapovalov31e4e802016-08-03 18:27:40 +020038class RtcEventLog;
39class RtpPacketToSend;
niklase@google.com470e71d2011-07-07 08:21:25 +000040class RTPSenderAudio;
41class RTPSenderVideo;
42
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000043class RTPSenderInterface {
44 public:
45 RTPSenderInterface() {}
46 virtual ~RTPSenderInterface() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000047
pbos@webrtc.org2f446732013-04-08 11:08:41 +000048 virtual uint32_t SSRC() const = 0;
49 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Sergey Ulanovec4f0682016-07-28 15:19:10 -070051 // Deprecated version of BuildRtpHeader(). |timestamp_provided| and
52 // |inc_sequence_number| are ignored.
53 // TODO(sergeyu): Remove this method.
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000054 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000055 int8_t payload_type,
56 bool marker_bit,
57 uint32_t capture_timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000058 int64_t capture_time_ms,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000059 bool timestamp_provided = true,
60 bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
Sergey Ulanovec4f0682016-07-28 15:19:10 -070062 virtual int32_t BuildRtpHeader(uint8_t* data_buffer,
63 int8_t payload_type,
64 bool marker_bit,
65 uint32_t capture_timestamp,
66 int64_t capture_time_ms) = 0;
67
isheriff6b4b5f32016-06-08 00:24:21 -070068 // This returns the expected header length taking into consideration
69 // the optional RTP header extensions that may not be currently active.
70 virtual size_t RtpHeaderLength() const = 0;
mflodmanfcf54bd2015-04-14 21:28:08 +020071 // Returns the next sequence number to use for a packet and allocates
72 // 'packets_to_send' number of sequence numbers. It's important all allocated
73 // sequence numbers are used in sequence to avoid perceived packet loss.
74 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000075 virtual uint16_t SequenceNumber() const = 0;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000076 virtual size_t MaxPayloadLength() const = 0;
77 virtual size_t MaxDataPayloadLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000078 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
Sergey Ulanov525df3f2016-08-02 17:46:41 -070080 virtual bool SendToNetwork(uint8_t* data_buffer,
81 size_t payload_length,
82 size_t rtp_header_length,
83 int64_t capture_time_ms,
84 StorageType storage,
85 RtpPacketSender::Priority priority) = 0;
guoweis@webrtc.org45362892015-03-04 22:55:15 +000086
87 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
88 size_t rtp_packet_length,
89 const RTPHeader& rtp_header,
90 VideoRotation rotation) const = 0;
91 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0;
isheriff6b4b5f32016-06-08 00:24:21 -070092 virtual bool ActivateCVORtpHeaderExtension() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000093};
94
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000095class RTPSender : public RTPSenderInterface {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000096 public:
Peter Boströmac547a62015-09-17 23:03:57 +020097 RTPSender(bool audio,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000098 Clock* clock,
99 Transport* transport,
sprangebbf8a82015-09-21 15:11:14 -0700100 RtpPacketSender* paced_sender,
101 TransportSequenceNumberAllocator* sequence_number_allocator,
sprang5e023eb2015-09-14 06:42:43 -0700102 TransportFeedbackObserver* transport_feedback_callback,
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000103 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000104 FrameCountObserver* frame_count_observer,
terelius429c3452016-01-21 05:42:04 -0800105 SendSideDelayObserver* send_side_delay_observer,
asapersson35151f32016-05-02 23:44:01 -0700106 RtcEventLog* event_log,
sprangcd349d92016-07-13 09:11:28 -0700107 SendPacketObserver* send_packet_observer,
108 RateLimiter* nack_rate_limiter);
asapersson35151f32016-05-02 23:44:01 -0700109
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000110 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000112 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000114 uint16_t ActualSendBitrateKbit() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000116 uint32_t VideoBitrateSent() const;
117 uint32_t FecOverheadRate() const;
118 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000119
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000120 // Includes size of RTP and FEC headers.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000121 size_t MaxDataPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
Peter Boström8b79b072016-02-26 16:31:37 +0100123 int32_t RegisterPayload(const char* payload_name,
124 const int8_t payload_type,
125 const uint32_t frequency,
126 const size_t channels,
127 const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000129 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +0000131 void SetSendPayloadType(int8_t payload_type);
132
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000133 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000135 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000137 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000139 void SetSendingMediaStatus(bool enabled);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000140 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000142 void GetDataCounters(StreamDataCounters* rtp_stats,
143 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000145 uint32_t StartTimestamp() const;
146 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000148 uint32_t GenerateNewSSRC();
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000149 void SetSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000151 uint16_t SequenceNumber() const override;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000152 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000154 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
danilchap41befce2016-03-30 11:11:51 -0700156 void SetMaxPayloadLength(size_t max_payload_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700158 bool SendOutgoingData(FrameType frame_type,
159 int8_t payload_type,
160 uint32_t timestamp,
161 int64_t capture_time_ms,
162 const uint8_t* payload_data,
163 size_t payload_size,
164 const RTPFragmentationHeader* fragmentation,
165 const RTPVideoHeader* rtp_header,
166 uint32_t* transport_frame_id_out);
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000168 // RTP header extension
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000169 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset);
170 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000171 void SetVideoRotation(VideoRotation rotation);
sprang@webrtc.org30933902015-03-17 14:33:12 +0000172 int32_t SetTransportSequenceNumber(uint16_t sequence_number);
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000174 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
danilchap162abd32015-12-10 02:39:40 -0800175 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000176 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000177
isheriff6b4b5f32016-06-08 00:24:21 -0700178 size_t RtpHeaderExtensionLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000179
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700180 uint16_t BuildRtpHeaderExtension(uint8_t* data_buffer, bool marker_bit) const
stefana23fc622016-07-28 07:56:38 -0700181 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000182
stefana23fc622016-07-28 07:56:38 -0700183 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t* data_buffer) const
184 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
185 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const
186 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
187 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const
188 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
189 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const
190 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700191 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer,
stefana23fc622016-07-28 07:56:38 -0700192 uint16_t sequence_number) const
193 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
isheriff6b4b5f32016-06-08 00:24:21 -0700194 uint8_t BuildPlayoutDelayExtension(uint8_t* data_buffer,
195 uint16_t min_playout_delay_ms,
stefana23fc622016-07-28 07:56:38 -0700196 uint16_t max_playout_delay_ms) const
197 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700198
199 // Verifies that the specified extension is registered, and that it is
200 // present in rtp packet. If extension is not registered kNotRegistered is
201 // returned. If extension cannot be found in the rtp header, or if it is
202 // malformed, kError is returned. Otherwise *extension_offset is set to the
203 // offset of the extension from the beginning of the rtp packet and kOk is
204 // returned.
205 enum class ExtensionStatus {
206 kNotRegistered,
207 kOk,
208 kError,
209 };
210 ExtensionStatus VerifyExtension(RTPExtensionType extension_type,
211 uint8_t* rtp_packet,
212 size_t rtp_packet_length,
213 const RTPHeader& rtp_header,
214 size_t extension_length_bytes,
215 size_t* extension_offset) const
tommiae695e92016-02-02 08:31:45 -0800216 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000217
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000218 bool UpdateAudioLevel(uint8_t* rtp_packet,
219 size_t rtp_packet_length,
220 const RTPHeader& rtp_header,
221 bool is_voiced,
222 uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000223
danilchap162abd32015-12-10 02:39:40 -0800224 bool UpdateVideoRotation(uint8_t* rtp_packet,
225 size_t rtp_packet_length,
226 const RTPHeader& rtp_header,
227 VideoRotation rotation) const override;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000228
philipela1ed0b32016-06-01 06:31:17 -0700229 bool TimeToSendPacket(uint16_t sequence_number,
230 int64_t capture_time_ms,
231 bool retransmission,
232 int probe_cluster_id);
233 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000234
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000235 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000236 int SelectiveRetransmissions() const;
237 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000238 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000239 int64_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000240
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000241 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000243 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000245 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
isheriff6b4b5f32016-06-08 00:24:21 -0700247 // Feedback to decide when to stop sending playout delay.
248 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks);
249
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000250 // RTX.
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000251 void SetRtxStatus(int mode);
252 int RtxStatus() const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000253
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000254 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000255 void SetRtxSsrc(uint32_t ssrc);
256
Shao Changbine62202f2015-04-21 20:24:50 +0800257 void SetRtxPayloadType(int payload_type, int associated_payload_type);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000258
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000259 // Functions wrapping RTPSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000260 int32_t BuildRTPheader(uint8_t* data_buffer,
261 int8_t payload_type,
262 bool marker_bit,
263 uint32_t capture_timestamp,
264 int64_t capture_time_ms,
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700265 bool timestamp_provided = true,
266 bool inc_sequence_number = true) override;
267 int32_t BuildRtpHeader(uint8_t* data_buffer,
268 int8_t payload_type,
269 bool marker_bit,
270 uint32_t capture_timestamp,
271 int64_t capture_time_ms) override;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000272
isheriff6b4b5f32016-06-08 00:24:21 -0700273 size_t RtpHeaderLength() const override;
mflodmanfcf54bd2015-04-14 21:28:08 +0200274 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000275 size_t MaxPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000277 // Current timestamp.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000278 uint32_t Timestamp() const override;
279 uint32_t SSRC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200281 // Deprecated. Create RtpPacketToSend instead and use next function.
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700282 bool SendToNetwork(uint8_t* data_buffer,
283 size_t payload_length,
284 size_t rtp_header_length,
285 int64_t capture_time_ms,
286 StorageType storage,
287 RtpPacketSender::Priority priority) override;
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200288 bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet,
289 StorageType storage,
290 RtpPacketSender::Priority priority);
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000291
292 // Audio.
293
294 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000295 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000296
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000297 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000298 // packet in silence (CNG).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000299 int32_t SetAudioPacketSize(uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000301 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000302 // header-extension-for-audio-level-indication.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000303 int32_t SetAudioLevel(uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000305 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000306 int32_t SetRED(int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000307
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000308 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000309 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000311 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000312
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000313 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000314
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000315 // FEC.
pbosba8c15b2015-07-14 09:36:34 -0700316 void SetGenericFECStatus(bool enable,
317 uint8_t payload_type_red,
318 uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000319
pbosba8c15b2015-07-14 09:36:34 -0700320 void GenericFECStatus(bool* enable,
321 uint8_t* payload_type_red,
322 uint8_t* payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000323
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000324 int32_t SetFecParameters(const FecProtectionParams *delta_params,
325 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000326
Stefan Holmer586b19b2015-09-18 11:14:31 +0200327 size_t SendPadData(size_t bytes,
328 bool timestamp_provided,
329 uint32_t timestamp,
philipel46948c12016-06-01 04:04:40 -0700330 int64_t capture_time_ms);
philipela1ed0b32016-06-01 06:31:17 -0700331 size_t SendPadData(size_t bytes,
332 bool timestamp_provided,
333 uint32_t timestamp,
334 int64_t capture_time_ms,
335 int probe_cluster_id);
336
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000337 // Called on update of RTP statistics.
338 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
339 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
340
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000341 uint32_t BitrateSent() const;
342
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000343 void SetRtpState(const RtpState& rtp_state);
344 RtpState GetRtpState() const;
345 void SetRtxRtpState(const RtpState& rtp_state);
346 RtpState GetRtxRtpState() const;
isheriff6b4b5f32016-06-08 00:24:21 -0700347 bool ActivateCVORtpHeaderExtension() override;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000348
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000349 protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000350 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000352 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000353 // Maps capture time in milliseconds to send-side delay in milliseconds.
354 // Send-side delay is the difference between transmission time and capture
355 // time.
356 typedef std::map<int64_t, int> SendDelayMap;
357
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000358 size_t CreateRtpHeader(uint8_t* header,
359 int8_t payload_type,
360 uint32_t ssrc,
361 bool marker_bit,
362 uint32_t timestamp,
363 uint16_t sequence_number,
stefana23fc622016-07-28 07:56:38 -0700364 const std::vector<uint32_t>& csrcs) const
365 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000366
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200367 bool PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000368 bool send_over_rtx,
philipela1ed0b32016-06-01 06:31:17 -0700369 bool is_retransmit,
370 int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000371
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000372 // Return the number of bytes sent. Note that both of these functions may
373 // return a larger value that their argument.
philipela1ed0b32016-06-01 06:31:17 -0700374 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000375
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200376 std::unique_ptr<RtpPacketToSend> BuildRtxPacket(
377 const RtpPacketToSend& packet);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000378
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200379 bool SendPacketToNetwork(const RtpPacketToSend& packet,
stefan1d8a5062015-10-02 03:39:33 -0700380 const PacketOptions& options);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000381
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000382 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
asapersson35151f32016-05-02 23:44:01 -0700383 void UpdateOnSendPacket(int packet_id,
384 int64_t capture_time_ms,
385 uint32_t ssrc);
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000386
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000387 // Find the byte position of the RTP extension as indicated by |type| in
388 // |rtp_packet|. Return false if such extension doesn't exist.
389 bool FindHeaderExtensionPosition(RTPExtensionType type,
390 const uint8_t* rtp_packet,
391 size_t rtp_packet_length,
392 const RTPHeader& rtp_header,
stefana23fc622016-07-28 07:56:38 -0700393 size_t* position) const
394 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000395
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200396 bool UpdateTransportSequenceNumber(RtpPacketToSend* packet,
397 int* packet_id) const;
asapersson35151f32016-05-02 23:44:01 -0700398
isheriff6b4b5f32016-06-08 00:24:21 -0700399 void UpdatePlayoutDelayLimits(uint8_t* rtp_packet,
400 size_t rtp_packet_length,
401 const RTPHeader& rtp_header,
402 uint16_t min_playout_delay,
403 uint16_t max_playout_delay) const;
404
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200405 void UpdateRtpStats(const RtpPacketToSend& packet,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000406 bool is_rtx,
407 bool is_retransmit);
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200408 bool IsFecPacket(const RtpPacketToSend& packet) const;
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000409
tommiae695e92016-02-02 08:31:45 -0800410 Clock* const clock_;
411 const int64_t clock_delta_ms_;
danilchap47a740b2015-12-15 00:30:07 -0800412 Random random_ GUARDED_BY(send_critsect_);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000413
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000414 const bool audio_configured_;
kwiberg84be5112016-04-27 01:19:58 -0700415 const std::unique_ptr<RTPSenderAudio> audio_;
416 const std::unique_ptr<RTPSenderVideo> video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000417
sprangebbf8a82015-09-21 15:11:14 -0700418 RtpPacketSender* const paced_sender_;
419 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
sprang5e023eb2015-09-14 06:42:43 -0700420 TransportFeedbackObserver* const transport_feedback_observer_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000421 int64_t last_capture_time_ms_sent_;
tommiae695e92016-02-02 08:31:45 -0800422 rtc::CriticalSection send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000423
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000424 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000425 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000426
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000427 size_t max_payload_length_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000428
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000429 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000430 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000431
stefana23fc622016-07-28 07:56:38 -0700432 RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000433 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000434 uint32_t absolute_send_time_;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000435 VideoRotation rotation_;
isheriff6b4b5f32016-06-08 00:24:21 -0700436 bool video_rotation_active_;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000437 uint16_t transport_sequence_number_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000438
isheriff6b4b5f32016-06-08 00:24:21 -0700439 // Tracks the current request for playout delay limits from application
440 // and decides whether the current RTP frame should include the playout
441 // delay extension on header.
442 PlayoutDelayOracle playout_delay_oracle_;
443 bool playout_delay_active_ GUARDED_BY(send_critsect_);
444
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200445 RtpPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000446
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000447 // Statistics
danilchap7c9426c2016-04-14 03:05:31 -0700448 rtc::CriticalSection statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000449 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000450 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000451 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
452 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
453 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
sprangcd349d92016-07-13 09:11:28 -0700454 RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_);
455 RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000456 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000457 SendSideDelayObserver* const send_side_delay_observer_;
terelius429c3452016-01-21 05:42:04 -0800458 RtcEventLog* const event_log_;
asapersson35151f32016-05-02 23:44:01 -0700459 SendPacketObserver* const send_packet_observer_;
sprangcd349d92016-07-13 09:11:28 -0700460 BitrateStatisticsObserver* const bitrate_callback_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000461
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000462 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000463 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
464 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
tommiae695e92016-02-02 08:31:45 -0800465 SSRCDatabase* const ssrc_db_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000466 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
467 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
468 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
469 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
470 bool ssrc_forced_ GUARDED_BY(send_critsect_);
471 uint32_t ssrc_ GUARDED_BY(send_critsect_);
472 uint32_t timestamp_ GUARDED_BY(send_critsect_);
473 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
474 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000475 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000476 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000477 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000478 int rtx_ GUARDED_BY(send_critsect_);
479 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
Shao Changbine62202f2015-04-21 20:24:50 +0800480 // Mapping rtx_payload_type_map_[associated] = rtx.
481 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000482
sprangcd349d92016-07-13 09:11:28 -0700483 RateLimiter* const retransmission_rate_limiter_;
terelius429c3452016-01-21 05:42:04 -0800484
485 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
niklase@google.com470e71d2011-07-07 08:21:25 +0000486};
niklase@google.com470e71d2011-07-07 08:21:25 +0000487
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000488} // namespace webrtc
489
490#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_