blob: 265e69c3547fe876dceb7d80ffb7a3ed8ea4f4c3 [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_
13
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000014#include <assert.h>
15#include <math.h>
16
pwestin@webrtc.org00741872012-01-19 15:56:10 +000017#include <map>
18
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000019#include "webrtc/common_types.h"
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000020#include "webrtc/modules/pacing/include/paced_sender.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000021#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
phoglund@webrtc.orgc38eef82013-01-07 10:18:30 +000022#include "webrtc/modules/rtp_rtcp/source/bitrate.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000023#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000024#include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000025#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
26#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
27#include "webrtc/modules/rtp_rtcp/source/video_codec_information.h"
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +000028#include "webrtc/system_wrappers/interface/thread_annotations.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000029
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000030#define MAX_INIT_RTP_SEQ_NUMBER 32767 // 2^15 -1.
niklase@google.com470e71d2011-07-07 08:21:25 +000031
32namespace webrtc {
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000033
niklase@google.com470e71d2011-07-07 08:21:25 +000034class CriticalSectionWrapper;
35class RTPSenderAudio;
36class RTPSenderVideo;
37
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000038class RTPSenderInterface {
39 public:
40 RTPSenderInterface() {}
41 virtual ~RTPSenderInterface() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000042
pbos@webrtc.org2f446732013-04-08 11:08:41 +000043 virtual uint32_t SSRC() const = 0;
44 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000046 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
47 const int8_t payload_type,
48 const bool marker_bit,
49 const uint32_t capture_timestamp,
50 int64_t capture_time_ms,
51 const bool timestamp_provided = true,
52 const bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
pbos@webrtc.org2f446732013-04-08 11:08:41 +000054 virtual uint16_t RTPHeaderLength() const = 0;
55 virtual uint16_t IncrementSequenceNumber() = 0;
56 virtual uint16_t SequenceNumber() const = 0;
57 virtual uint16_t MaxPayloadLength() const = 0;
58 virtual uint16_t MaxDataPayloadLength() const = 0;
59 virtual uint16_t PacketOverHead() const = 0;
60 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
pbos@webrtc.org2f446732013-04-08 11:08:41 +000062 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000063 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000064 int64_t capture_time_ms, StorageType storage,
65 PacedSender::Priority priority) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000066};
67
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +000068class RTPSender : public RTPSenderInterface, public Bitrate::Observer {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000069 public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000070 RTPSender(const int32_t id, const bool audio, Clock *clock,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000071 Transport *transport, RtpAudioFeedback *audio_feedback,
andresp@webrtc.orgd11bec42014-07-08 14:32:58 +000072 PacedSender *paced_sender,
andresp@webrtc.org8f151212014-07-10 09:39:23 +000073 BitrateStatisticsObserver* bitrate_callback,
74 FrameCountObserver* frame_count_observer);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000075 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000076
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000077 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000078
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000079 virtual uint16_t ActualSendBitrateKbit() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
pbos@webrtc.org2f446732013-04-08 11:08:41 +000081 uint32_t VideoBitrateSent() const;
82 uint32_t FecOverheadRate() const;
83 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +000084
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +000085 // Returns true if the statistics have been calculated, and false if no frame
86 // was sent within the statistics window.
87 bool GetSendSideDelay(int* avg_send_delay_ms, int* max_send_delay_ms) const;
88
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +000089 void SetTargetBitrate(uint32_t bitrate);
90 uint32_t GetTargetBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000091
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000092 virtual uint16_t MaxDataPayloadLength() const
93 OVERRIDE; // with RTP and FEC headers.
niklase@google.com470e71d2011-07-07 08:21:25 +000094
pbos@webrtc.org2f446732013-04-08 11:08:41 +000095 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000096 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +000097 const int8_t payload_type, const uint32_t frequency,
98 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +000099
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000100 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000102 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000104 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000106 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000108 void SetSendingMediaStatus(const bool enabled);
109 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000111 // Number of sent RTP packets.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000112 uint32_t Packets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000114 // Number of sent RTP bytes.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000115 uint32_t Bytes() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000117 void ResetDataCounters();
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000119 uint32_t StartTimestamp() const;
120 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000122 uint32_t GenerateNewSSRC();
123 void SetSSRC(const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000125 virtual uint16_t SequenceNumber() const OVERRIDE;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000126 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000128 int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000130 void SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000132 void SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize],
133 const uint8_t arr_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000135 int32_t SetMaxPayloadLength(const uint16_t length,
136 const uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000138 int32_t SendOutgoingData(const FrameType frame_type,
139 const int8_t payload_type,
140 const uint32_t timestamp,
141 int64_t capture_time_ms,
142 const uint8_t* payload_data,
143 const uint32_t payload_size,
144 const RTPFragmentationHeader* fragmentation,
145 VideoCodecInformation* codec_info = NULL,
146 const RTPVideoTypeHeader* rtp_type_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000148 // RTP header extension
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000149 int32_t SetTransmissionTimeOffset(
150 const int32_t transmission_time_offset);
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000151 int32_t SetAbsoluteSendTime(
152 const uint32_t absolute_send_time);
niklase@google.com470e71d2011-07-07 08:21:25 +0000153
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000154 int32_t RegisterRtpHeaderExtension(const RTPExtensionType type,
155 const uint8_t id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000156
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000157 int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000158
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000159 uint16_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000160
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000161 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000162
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000163 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const;
164 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const;
165 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000166
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000167 bool UpdateAudioLevel(uint8_t *rtp_packet,
168 const uint16_t rtp_packet_length,
169 const RTPHeader &rtp_header,
170 const bool is_voiced,
171 const uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000172
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000173 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
174 bool retransmission);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000175 int TimeToSendPadding(int bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000176
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000177 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000178 int SelectiveRetransmissions() const;
179 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000180 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000181 const uint16_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000182
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000183 void SetStorePacketsStatus(const bool enable,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000184 const uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000186 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000188 int32_t ReSendPacket(uint16_t packet_id, uint32_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000190 bool ProcessNACKBitRate(const uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000192 // RTX.
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000193 void SetRTXStatus(int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000195 void RTXStatus(int* mode, uint32_t* ssrc, int* payload_type) const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000196
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000197 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000198 void SetRtxSsrc(uint32_t ssrc);
199
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000200 void SetRtxPayloadType(int payloadType);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000201
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000202 // Functions wrapping RTPSenderInterface.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000203 virtual int32_t BuildRTPheader(
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000204 uint8_t* data_buffer,
205 const int8_t payload_type,
206 const bool marker_bit,
207 const uint32_t capture_timestamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000208 int64_t capture_time_ms,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000209 const bool timestamp_provided = true,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000210 const bool inc_sequence_number = true) OVERRIDE;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000211
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000212 virtual uint16_t RTPHeaderLength() const OVERRIDE;
213 virtual uint16_t IncrementSequenceNumber() OVERRIDE;
214 virtual uint16_t MaxPayloadLength() const OVERRIDE;
215 virtual uint16_t PacketOverHead() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000217 // Current timestamp.
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000218 virtual uint32_t Timestamp() const OVERRIDE;
219 virtual uint32_t SSRC() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000221 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000222 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000223 int64_t capture_time_ms, StorageType storage,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000224 PacedSender::Priority priority) OVERRIDE;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000225
226 // Audio.
227
228 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000229 int32_t SendTelephoneEvent(const uint8_t key,
230 const uint16_t time_ms,
231 const uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000233 bool SendTelephoneEventActive(int8_t *telephone_event) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000235 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000236 // packet in silence (CNG).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000237 int32_t SetAudioPacketSize(const uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000238
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000239 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000240 // header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000241 int32_t SetAudioLevel(const uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000243 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000244 int32_t SetRED(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000246 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000247 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000249 // Video.
250 VideoCodecInformation *CodecInformationVideo();
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000252 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000254 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000256 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000257
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000258 // FEC.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000259 int32_t SetGenericFECStatus(const bool enable,
260 const uint8_t payload_type_red,
261 const uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000263 int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red,
264 uint8_t *payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000265
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000266 int32_t SetFecParameters(const FecProtectionParams *delta_params,
267 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000268
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000269 int SendPadData(int payload_type, uint32_t timestamp, int64_t capture_time_ms,
270 int32_t bytes, StorageType store,
271 bool force_full_size_packets, bool only_pad_after_markerbit);
272
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000273 // Called on update of RTP statistics.
274 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
275 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
276
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000277 uint32_t BitrateSent() const;
278
279 virtual void BitrateUpdated(const BitrateStatistics& stats) OVERRIDE;
280
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000281 void SetRtpState(const RtpState& rtp_state);
282 RtpState GetRtpState() const;
283 void SetRtxRtpState(const RtpState& rtp_state);
284 RtpState GetRtxRtpState() const;
285
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000286 protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000287 int32_t CheckPayloadType(const int8_t payload_type,
288 RtpVideoCodecTypes *video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000289
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000290 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000291 // Maps capture time in milliseconds to send-side delay in milliseconds.
292 // Send-side delay is the difference between transmission time and capture
293 // time.
294 typedef std::map<int64_t, int> SendDelayMap;
295
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000296 int CreateRTPHeader(uint8_t* header, int8_t payload_type,
297 uint32_t ssrc, bool marker_bit,
298 uint32_t timestamp, uint16_t sequence_number,
299 const uint32_t* csrcs, uint8_t csrcs_length) const;
300
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000301 void UpdateNACKBitRate(const uint32_t bytes, const uint32_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000302
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000303 bool PrepareAndSendPacket(uint8_t* buffer,
304 uint16_t length,
305 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000306 bool send_over_rtx,
307 bool is_retransmit);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000308
309 int SendRedundantPayloads(int payload_type, int bytes);
310
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000311 bool SendPaddingAccordingToBitrate(int8_t payload_type,
312 uint32_t capture_timestamp,
313 int64_t capture_time_ms);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000314 int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000315
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000316 void BuildRtxPacket(uint8_t* buffer, uint16_t* length,
317 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000318
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000319 bool SendPacketToNetwork(const uint8_t *packet, uint32_t size);
320
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000321 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
322
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000323 void UpdateTransmissionTimeOffset(uint8_t *rtp_packet,
324 const uint16_t rtp_packet_length,
325 const RTPHeader &rtp_header,
326 const int64_t time_diff_ms) const;
327 void UpdateAbsoluteSendTime(uint8_t *rtp_packet,
328 const uint16_t rtp_packet_length,
329 const RTPHeader &rtp_header,
330 const int64_t now_ms) const;
331
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000332 void UpdateRtpStats(const uint8_t* buffer,
333 uint32_t size,
334 const RTPHeader& header,
335 bool is_rtx,
336 bool is_retransmit);
337 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
338
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000339 Clock* clock_;
340 Bitrate bitrate_sent_;
341
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000342 int32_t id_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000343 const bool audio_configured_;
344 RTPSenderAudio *audio_;
345 RTPSenderVideo *video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000346
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000347 PacedSender *paced_sender_;
348 CriticalSectionWrapper *send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000349
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000350 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000351 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000353 uint16_t max_payload_length_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000354 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000356 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000357 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000359 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000360 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000361 uint32_t absolute_send_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000363 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000364 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
365 int32_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000366 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000367
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000368 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000370 // Statistics
pbos@webrtc.orge07049f2013-09-10 11:29:17 +0000371 scoped_ptr<CriticalSectionWrapper> statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000372 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
373 std::map<FrameType, uint32_t> frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000374 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
375 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
376 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
andresp@webrtc.orgd11bec42014-07-08 14:32:58 +0000377 BitrateStatisticsObserver* const bitrate_callback_;
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000378 FrameCountObserver* const frame_count_observer_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000379
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000380 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000381 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
382 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
383 SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_);
384 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
385 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
386 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
387 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
388 bool ssrc_forced_ GUARDED_BY(send_critsect_);
389 uint32_t ssrc_ GUARDED_BY(send_critsect_);
390 uint32_t timestamp_ GUARDED_BY(send_critsect_);
391 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
392 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
393 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
394 uint8_t num_csrcs_ GUARDED_BY(send_critsect_);
395 uint32_t csrcs_[kRtpCsrcSize] GUARDED_BY(send_critsect_);
396 bool include_csrcs_ GUARDED_BY(send_critsect_);
397 int rtx_ GUARDED_BY(send_critsect_);
398 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
399 int payload_type_rtx_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000400
401 // Note: Don't access this variable directly, always go through
402 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
403 // that by the time the function returns there is no guarantee
404 // that the target bitrate is still valid.
405 scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
stefan@webrtc.orgaa0e56e2014-06-26 11:44:49 +0000406 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000407};
niklase@google.com470e71d2011-07-07 08:21:25 +0000408
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000409} // namespace webrtc
410
411#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_