blob: 7a6677b408e29b29a716d996b761d4059d0607d5 [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
pwestin@webrtc.org00741872012-01-19 15:56:10 +000014#include <map>
kwiberg84be5112016-04-27 01:19:58 -070015#include <memory>
danilchapb8b6fbb2015-12-10 05:05:27 -080016#include <utility>
17#include <vector>
pwestin@webrtc.org00741872012-01-19 15:56:10 +000018
kwiberg4485ffb2016-04-26 08:14:39 -070019#include "webrtc/base/constructormagic.h"
tommiae695e92016-02-02 08:31:45 -080020#include "webrtc/base/criticalsection.h"
danilchap47a740b2015-12-15 00:30:07 -080021#include "webrtc/base/random.h"
sprangcd349d92016-07-13 09:11:28 -070022#include "webrtc/base/rate_statistics.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000023#include "webrtc/base/thread_annotations.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000024#include "webrtc/common_types.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010025#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
isheriff6b4b5f32016-06-08 00:24:21 -070026#include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000027#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000028#include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000029#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
mflodmanfcf54bd2015-04-14 21:28:08 +020030#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000031#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
pbos2d566682015-09-28 09:59:31 -070032#include "webrtc/transport.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033
niklase@google.com470e71d2011-07-07 08:21:25 +000034namespace webrtc {
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000035
sprangcd349d92016-07-13 09:11:28 -070036class RateLimiter;
Danil Chapovalov31e4e802016-08-03 18:27:40 +020037class RtcEventLog;
38class RtpPacketToSend;
niklase@google.com470e71d2011-07-07 08:21:25 +000039class RTPSenderAudio;
40class RTPSenderVideo;
41
danilchap5fb291a2016-08-09 07:43:25 -070042class RTPSender {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000043 public:
Peter Boströmac547a62015-09-17 23:03:57 +020044 RTPSender(bool audio,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000045 Clock* clock,
46 Transport* transport,
sprangebbf8a82015-09-21 15:11:14 -070047 RtpPacketSender* paced_sender,
48 TransportSequenceNumberAllocator* sequence_number_allocator,
sprang5e023eb2015-09-14 06:42:43 -070049 TransportFeedbackObserver* transport_feedback_callback,
andresp@webrtc.org8f151212014-07-10 09:39:23 +000050 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000051 FrameCountObserver* frame_count_observer,
terelius429c3452016-01-21 05:42:04 -080052 SendSideDelayObserver* send_side_delay_observer,
asapersson35151f32016-05-02 23:44:01 -070053 RtcEventLog* event_log,
sprangcd349d92016-07-13 09:11:28 -070054 SendPacketObserver* send_packet_observer,
55 RateLimiter* nack_rate_limiter);
asapersson35151f32016-05-02 23:44:01 -070056
danilchap5fb291a2016-08-09 07:43:25 -070057 ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000058
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000059 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000060
danilchap5fb291a2016-08-09 07:43:25 -070061 uint16_t ActualSendBitrateKbit() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.org2f446732013-04-08 11:08:41 +000063 uint32_t VideoBitrateSent() const;
64 uint32_t FecOverheadRate() const;
65 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +000066
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000067 // Includes size of RTP and FEC headers.
danilchap5fb291a2016-08-09 07:43:25 -070068 size_t MaxDataPayloadLength() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Peter Boström8b79b072016-02-26 16:31:37 +010070 int32_t RegisterPayload(const char* payload_name,
71 const int8_t payload_type,
72 const uint32_t frequency,
73 const size_t channels,
74 const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
pbos@webrtc.org2f446732013-04-08 11:08:41 +000076 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +000078 void SetSendPayloadType(int8_t payload_type);
79
pbos@webrtc.org2f446732013-04-08 11:08:41 +000080 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000081
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000082 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +000084 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +000085
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000086 void SetSendingMediaStatus(bool enabled);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000087 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +000089 void GetDataCounters(StreamDataCounters* rtp_stats,
90 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000091
danilchap71fead22016-08-18 02:01:49 -070092 uint32_t TimestampOffset() const;
93 void SetTimestampOffset(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +000094
pbos@webrtc.org2f446732013-04-08 11:08:41 +000095 uint32_t GenerateNewSSRC();
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000096 void SetSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
danilchap5fb291a2016-08-09 07:43:25 -070098 uint16_t SequenceNumber() const;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000099 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000101 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
danilchap41befce2016-03-30 11:11:51 -0700103 void SetMaxPayloadLength(size_t max_payload_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700105 bool SendOutgoingData(FrameType frame_type,
106 int8_t payload_type,
107 uint32_t timestamp,
108 int64_t capture_time_ms,
109 const uint8_t* payload_data,
110 size_t payload_size,
111 const RTPFragmentationHeader* fragmentation,
112 const RTPVideoHeader* rtp_header,
113 uint32_t* transport_frame_id_out);
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000115 // RTP header extension
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000116 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset);
117 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000118 void SetVideoRotation(VideoRotation rotation);
sprang@webrtc.org30933902015-03-17 14:33:12 +0000119 int32_t SetTransportSequenceNumber(uint16_t sequence_number);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000121 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
danilchap5fb291a2016-08-09 07:43:25 -0700122 bool IsRtpHeaderExtensionRegistered(RTPExtensionType type);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000123 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000124
isheriff6b4b5f32016-06-08 00:24:21 -0700125 size_t RtpHeaderExtensionLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000126
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700127 uint16_t BuildRtpHeaderExtension(uint8_t* data_buffer, bool marker_bit) const
stefana23fc622016-07-28 07:56:38 -0700128 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000129
stefana23fc622016-07-28 07:56:38 -0700130 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t* data_buffer) const
131 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
132 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const
133 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
134 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const
135 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
136 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const
137 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700138 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer,
stefana23fc622016-07-28 07:56:38 -0700139 uint16_t sequence_number) const
140 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
isheriff6b4b5f32016-06-08 00:24:21 -0700141 uint8_t BuildPlayoutDelayExtension(uint8_t* data_buffer,
142 uint16_t min_playout_delay_ms,
stefana23fc622016-07-28 07:56:38 -0700143 uint16_t max_playout_delay_ms) const
144 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
sprang867fb522015-08-03 04:38:41 -0700145
146 // Verifies that the specified extension is registered, and that it is
147 // present in rtp packet. If extension is not registered kNotRegistered is
148 // returned. If extension cannot be found in the rtp header, or if it is
149 // malformed, kError is returned. Otherwise *extension_offset is set to the
150 // offset of the extension from the beginning of the rtp packet and kOk is
151 // returned.
152 enum class ExtensionStatus {
153 kNotRegistered,
154 kOk,
155 kError,
156 };
157 ExtensionStatus VerifyExtension(RTPExtensionType extension_type,
158 uint8_t* rtp_packet,
159 size_t rtp_packet_length,
160 const RTPHeader& rtp_header,
161 size_t extension_length_bytes,
162 size_t* extension_offset) const
tommiae695e92016-02-02 08:31:45 -0800163 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000164
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000165 bool UpdateAudioLevel(uint8_t* rtp_packet,
166 size_t rtp_packet_length,
167 const RTPHeader& rtp_header,
168 bool is_voiced,
169 uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000170
danilchap162abd32015-12-10 02:39:40 -0800171 bool UpdateVideoRotation(uint8_t* rtp_packet,
172 size_t rtp_packet_length,
173 const RTPHeader& rtp_header,
danilchap5fb291a2016-08-09 07:43:25 -0700174 VideoRotation rotation) const;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000175
philipela1ed0b32016-06-01 06:31:17 -0700176 bool TimeToSendPacket(uint16_t sequence_number,
177 int64_t capture_time_ms,
178 bool retransmission,
179 int probe_cluster_id);
180 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000181
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000182 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000183 int SelectiveRetransmissions() const;
184 int SetSelectiveRetransmissions(uint8_t settings);
Danil Chapovalov2800d742016-08-26 18:48:46 +0200185 void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000186 int64_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000187
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000188 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000190 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000192 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
isheriff6b4b5f32016-06-08 00:24:21 -0700194 // Feedback to decide when to stop sending playout delay.
195 void OnReceivedRtcpReportBlocks(const ReportBlockList& report_blocks);
196
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000197 // RTX.
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000198 void SetRtxStatus(int mode);
199 int RtxStatus() const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000200
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000201 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000202 void SetRtxSsrc(uint32_t ssrc);
203
Shao Changbine62202f2015-04-21 20:24:50 +0800204 void SetRtxPayloadType(int payload_type, int associated_payload_type);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000205
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000206 // Functions wrapping RTPSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000207 int32_t BuildRTPheader(uint8_t* data_buffer,
208 int8_t payload_type,
209 bool marker_bit,
210 uint32_t capture_timestamp,
211 int64_t capture_time_ms,
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700212 bool timestamp_provided = true,
danilchap5fb291a2016-08-09 07:43:25 -0700213 bool inc_sequence_number = true);
Sergey Ulanovec4f0682016-07-28 15:19:10 -0700214 int32_t BuildRtpHeader(uint8_t* data_buffer,
215 int8_t payload_type,
216 bool marker_bit,
217 uint32_t capture_timestamp,
danilchap5fb291a2016-08-09 07:43:25 -0700218 int64_t capture_time_ms);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000219
danilchap5fb291a2016-08-09 07:43:25 -0700220 size_t RtpHeaderLength() const;
221 uint16_t AllocateSequenceNumber(uint16_t packets_to_send);
222 size_t MaxPayloadLength() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
danilchap5fb291a2016-08-09 07:43:25 -0700224 uint32_t SSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200226 // Deprecated. Create RtpPacketToSend instead and use next function.
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700227 bool SendToNetwork(uint8_t* data_buffer,
228 size_t payload_length,
229 size_t rtp_header_length,
230 int64_t capture_time_ms,
231 StorageType storage,
danilchap5fb291a2016-08-09 07:43:25 -0700232 RtpPacketSender::Priority priority);
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200233 bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet,
234 StorageType storage,
235 RtpPacketSender::Priority priority);
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000236
237 // Audio.
238
239 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000240 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000241
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000242 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000243 // packet in silence (CNG).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000244 int32_t SetAudioPacketSize(uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000246 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000247 // header-extension-for-audio-level-indication.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000248 int32_t SetAudioLevel(uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000250 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000252 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000254 // FEC.
pbosba8c15b2015-07-14 09:36:34 -0700255 void SetGenericFECStatus(bool enable,
256 uint8_t payload_type_red,
257 uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
pbosba8c15b2015-07-14 09:36:34 -0700259 void GenericFECStatus(bool* enable,
260 uint8_t* payload_type_red,
261 uint8_t* payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000263 int32_t SetFecParameters(const FecProtectionParams *delta_params,
264 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
Stefan Holmer586b19b2015-09-18 11:14:31 +0200266 size_t SendPadData(size_t bytes,
267 bool timestamp_provided,
268 uint32_t timestamp,
philipel46948c12016-06-01 04:04:40 -0700269 int64_t capture_time_ms);
philipela1ed0b32016-06-01 06:31:17 -0700270 size_t SendPadData(size_t bytes,
271 bool timestamp_provided,
272 uint32_t timestamp,
273 int64_t capture_time_ms,
274 int probe_cluster_id);
275
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000276 // Called on update of RTP statistics.
277 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
278 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
279
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000280 uint32_t BitrateSent() const;
281
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000282 void SetRtpState(const RtpState& rtp_state);
283 RtpState GetRtpState() const;
284 void SetRtxRtpState(const RtpState& rtp_state);
285 RtpState GetRtxRtpState() const;
danilchap5fb291a2016-08-09 07:43:25 -0700286 bool ActivateCVORtpHeaderExtension();
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000287
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000288 protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000289 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000291 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000292 // Maps capture time in milliseconds to send-side delay in milliseconds.
293 // Send-side delay is the difference between transmission time and capture
294 // time.
295 typedef std::map<int64_t, int> SendDelayMap;
296
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000297 size_t CreateRtpHeader(uint8_t* header,
298 int8_t payload_type,
299 uint32_t ssrc,
300 bool marker_bit,
301 uint32_t timestamp,
302 uint16_t sequence_number,
stefana23fc622016-07-28 07:56:38 -0700303 const std::vector<uint32_t>& csrcs) const
304 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000305
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200306 bool PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000307 bool send_over_rtx,
philipela1ed0b32016-06-01 06:31:17 -0700308 bool is_retransmit,
309 int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000310
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000311 // Return the number of bytes sent. Note that both of these functions may
312 // return a larger value that their argument.
philipela1ed0b32016-06-01 06:31:17 -0700313 size_t TrySendRedundantPayloads(size_t bytes, int probe_cluster_id);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000314
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200315 std::unique_ptr<RtpPacketToSend> BuildRtxPacket(
316 const RtpPacketToSend& packet);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000317
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200318 bool SendPacketToNetwork(const RtpPacketToSend& packet,
stefan1d8a5062015-10-02 03:39:33 -0700319 const PacketOptions& options);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000320
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000321 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
asapersson35151f32016-05-02 23:44:01 -0700322 void UpdateOnSendPacket(int packet_id,
323 int64_t capture_time_ms,
324 uint32_t ssrc);
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000325
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000326 // Find the byte position of the RTP extension as indicated by |type| in
327 // |rtp_packet|. Return false if such extension doesn't exist.
328 bool FindHeaderExtensionPosition(RTPExtensionType type,
329 const uint8_t* rtp_packet,
330 size_t rtp_packet_length,
331 const RTPHeader& rtp_header,
stefana23fc622016-07-28 07:56:38 -0700332 size_t* position) const
333 EXCLUSIVE_LOCKS_REQUIRED(send_critsect_);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000334
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200335 bool UpdateTransportSequenceNumber(RtpPacketToSend* packet,
336 int* packet_id) const;
asapersson35151f32016-05-02 23:44:01 -0700337
isheriff6b4b5f32016-06-08 00:24:21 -0700338 void UpdatePlayoutDelayLimits(uint8_t* rtp_packet,
339 size_t rtp_packet_length,
340 const RTPHeader& rtp_header,
341 uint16_t min_playout_delay,
342 uint16_t max_playout_delay) const;
343
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200344 void UpdateRtpStats(const RtpPacketToSend& packet,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000345 bool is_rtx,
346 bool is_retransmit);
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200347 bool IsFecPacket(const RtpPacketToSend& packet) const;
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000348
tommiae695e92016-02-02 08:31:45 -0800349 Clock* const clock_;
350 const int64_t clock_delta_ms_;
danilchap47a740b2015-12-15 00:30:07 -0800351 Random random_ GUARDED_BY(send_critsect_);
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000352
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000353 const bool audio_configured_;
kwiberg84be5112016-04-27 01:19:58 -0700354 const std::unique_ptr<RTPSenderAudio> audio_;
355 const std::unique_ptr<RTPSenderVideo> video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000356
sprangebbf8a82015-09-21 15:11:14 -0700357 RtpPacketSender* const paced_sender_;
358 TransportSequenceNumberAllocator* const transport_sequence_number_allocator_;
sprang5e023eb2015-09-14 06:42:43 -0700359 TransportFeedbackObserver* const transport_feedback_observer_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000360 int64_t last_capture_time_ms_sent_;
tommiae695e92016-02-02 08:31:45 -0800361 rtc::CriticalSection send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000363 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000364 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000366 size_t max_payload_length_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000368 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000369 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370
stefana23fc622016-07-28 07:56:38 -0700371 RtpHeaderExtensionMap rtp_header_extension_map_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000372 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000373 uint32_t absolute_send_time_;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000374 VideoRotation rotation_;
isheriff6b4b5f32016-06-08 00:24:21 -0700375 bool video_rotation_active_;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000376 uint16_t transport_sequence_number_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
isheriff6b4b5f32016-06-08 00:24:21 -0700378 // Tracks the current request for playout delay limits from application
379 // and decides whether the current RTP frame should include the playout
380 // delay extension on header.
381 PlayoutDelayOracle playout_delay_oracle_;
382 bool playout_delay_active_ GUARDED_BY(send_critsect_);
383
Danil Chapovalov31e4e802016-08-03 18:27:40 +0200384 RtpPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000386 // Statistics
danilchap7c9426c2016-04-14 03:05:31 -0700387 rtc::CriticalSection statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000388 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000389 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000390 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
391 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
392 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
sprangcd349d92016-07-13 09:11:28 -0700393 RateStatistics total_bitrate_sent_ GUARDED_BY(statistics_crit_);
394 RateStatistics nack_bitrate_sent_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000395 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000396 SendSideDelayObserver* const send_side_delay_observer_;
terelius429c3452016-01-21 05:42:04 -0800397 RtcEventLog* const event_log_;
asapersson35151f32016-05-02 23:44:01 -0700398 SendPacketObserver* const send_packet_observer_;
sprangcd349d92016-07-13 09:11:28 -0700399 BitrateStatisticsObserver* const bitrate_callback_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000400
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000401 // RTP variables
danilchap71fead22016-08-18 02:01:49 -0700402 uint32_t timestamp_offset_ GUARDED_BY(send_critsect_);
tommiae695e92016-02-02 08:31:45 -0800403 SSRCDatabase* const ssrc_db_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000404 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
405 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
406 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
407 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
408 bool ssrc_forced_ GUARDED_BY(send_critsect_);
409 uint32_t ssrc_ GUARDED_BY(send_critsect_);
danilchape5b41412016-08-22 03:39:23 -0700410 uint32_t last_rtp_timestamp_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000411 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
412 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000413 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000414 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000415 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000416 int rtx_ GUARDED_BY(send_critsect_);
417 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
Shao Changbine62202f2015-04-21 20:24:50 +0800418 // Mapping rtx_payload_type_map_[associated] = rtx.
419 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000420
sprangcd349d92016-07-13 09:11:28 -0700421 RateLimiter* const retransmission_rate_limiter_;
terelius429c3452016-01-21 05:42:04 -0800422
423 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
niklase@google.com470e71d2011-07-07 08:21:25 +0000424};
niklase@google.com470e71d2011-07-07 08:21:25 +0000425
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000426} // namespace webrtc
427
428#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_