blob: becd22ad13cf92de03036a0d705fd571fe1b9a6b [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"
niklase@google.com470e71d2011-07-07 08:21:25 +000028
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000029#define MAX_INIT_RTP_SEQ_NUMBER 32767 // 2^15 -1.
niklase@google.com470e71d2011-07-07 08:21:25 +000030
31namespace webrtc {
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000032
niklase@google.com470e71d2011-07-07 08:21:25 +000033class CriticalSectionWrapper;
34class RTPSenderAudio;
35class RTPSenderVideo;
36
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000037class RTPSenderInterface {
38 public:
39 RTPSenderInterface() {}
40 virtual ~RTPSenderInterface() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000041
pbos@webrtc.org2f446732013-04-08 11:08:41 +000042 virtual uint32_t SSRC() const = 0;
43 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
pbos@webrtc.org2f446732013-04-08 11:08:41 +000045 virtual int32_t BuildRTPheader(
46 uint8_t *data_buffer, const int8_t payload_type,
47 const bool marker_bit, const uint32_t capture_time_stamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +000048 int64_t capture_time_ms,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000049 const bool time_stamp_provided = true,
50 const bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
pbos@webrtc.org2f446732013-04-08 11:08:41 +000052 virtual uint16_t RTPHeaderLength() const = 0;
53 virtual uint16_t IncrementSequenceNumber() = 0;
54 virtual uint16_t SequenceNumber() const = 0;
55 virtual uint16_t MaxPayloadLength() const = 0;
56 virtual uint16_t MaxDataPayloadLength() const = 0;
57 virtual uint16_t PacketOverHead() const = 0;
58 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
pbos@webrtc.org2f446732013-04-08 11:08:41 +000060 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000061 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000062 int64_t capture_time_ms, StorageType storage,
63 PacedSender::Priority priority) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064};
65
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000066class RTPSender : public Bitrate, public RTPSenderInterface {
67 public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000068 RTPSender(const int32_t id, const bool audio, Clock *clock,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000069 Transport *transport, RtpAudioFeedback *audio_feedback,
70 PacedSender *paced_sender);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000071 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000072
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000073 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000074
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000075 virtual uint16_t ActualSendBitrateKbit() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000076
pbos@webrtc.org2f446732013-04-08 11:08:41 +000077 uint32_t VideoBitrateSent() const;
78 uint32_t FecOverheadRate() const;
79 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +000080
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +000081 // Returns true if the statistics have been calculated, and false if no frame
82 // was sent within the statistics window.
83 bool GetSendSideDelay(int* avg_send_delay_ms, int* max_send_delay_ms) const;
84
pbos@webrtc.org2f446732013-04-08 11:08:41 +000085 void SetTargetSendBitrate(const uint32_t bits);
niklase@google.com470e71d2011-07-07 08:21:25 +000086
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000087 virtual uint16_t MaxDataPayloadLength() const
88 OVERRIDE; // with RTP and FEC headers.
niklase@google.com470e71d2011-07-07 08:21:25 +000089
pbos@webrtc.org2f446732013-04-08 11:08:41 +000090 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000091 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +000092 const int8_t payload_type, const uint32_t frequency,
93 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +000094
pbos@webrtc.org2f446732013-04-08 11:08:41 +000095 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000096
pbos@webrtc.org2f446732013-04-08 11:08:41 +000097 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000099 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000101 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000103 void SetSendingMediaStatus(const bool enabled);
104 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000106 // Number of sent RTP packets.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000107 uint32_t Packets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000109 // Number of sent RTP bytes.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000110 uint32_t Bytes() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000112 void ResetDataCounters();
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000114 uint32_t StartTimestamp() const;
115 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000117 uint32_t GenerateNewSSRC();
118 void SetSSRC(const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000120 virtual uint16_t SequenceNumber() const OVERRIDE;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000121 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000123 int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000125 void SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000127 void SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize],
128 const uint8_t arr_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000130 int32_t SetMaxPayloadLength(const uint16_t length,
131 const uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000133 int32_t SendOutgoingData(
134 const FrameType frame_type, const int8_t payload_type,
135 const uint32_t time_stamp, int64_t capture_time_ms,
136 const uint8_t *payload_data, const uint32_t payload_size,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000137 const RTPFragmentationHeader *fragmentation,
138 VideoCodecInformation *codec_info = NULL,
139 const RTPVideoTypeHeader * rtp_type_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000141 // RTP header extension
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000142 int32_t SetTransmissionTimeOffset(
143 const int32_t transmission_time_offset);
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000144 int32_t SetAbsoluteSendTime(
145 const uint32_t absolute_send_time);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000147 int32_t RegisterRtpHeaderExtension(const RTPExtensionType type,
148 const uint8_t id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000149
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000150 int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000151
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000152 uint16_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000153
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000154 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000155
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000156 uint8_t BuildTransmissionTimeOffsetExtension(
157 uint8_t *data_buffer) const;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000158 uint8_t BuildAbsoluteSendTimeExtension(
159 uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000160
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000161 bool UpdateTransmissionTimeOffset(uint8_t *rtp_packet,
162 const uint16_t rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000163 const RTPHeader &rtp_header,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000164 const int64_t time_diff_ms) const;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000165 bool UpdateAbsoluteSendTime(uint8_t *rtp_packet,
166 const uint16_t rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000167 const RTPHeader &rtp_header,
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000168 const int64_t now_ms) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000169
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000170 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
171 bool retransmission);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000172 int TimeToSendPadding(int bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000173
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000174 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000175 int SelectiveRetransmissions() const;
176 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000177 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000178 const uint16_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000179
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000180 void SetStorePacketsStatus(const bool enable,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000181 const uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000183 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000184
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000185 int32_t ReSendPacket(uint16_t packet_id, uint32_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000187 bool ProcessNACKBitRate(const uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000189 // RTX.
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000190 void SetRTXStatus(int mode, bool set_ssrc, uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000192 void RTXStatus(int* mode, uint32_t* ssrc, int* payload_type) const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000193
194 void SetRtxPayloadType(int payloadType);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000195
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000196 // Functions wrapping RTPSenderInterface.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000197 virtual int32_t BuildRTPheader(
198 uint8_t *data_buffer, const int8_t payload_type,
199 const bool marker_bit, const uint32_t capture_time_stamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000200 int64_t capture_time_ms,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000201 const bool time_stamp_provided = true,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000202 const bool inc_sequence_number = true) OVERRIDE;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000203
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000204 virtual uint16_t RTPHeaderLength() const OVERRIDE;
205 virtual uint16_t IncrementSequenceNumber() OVERRIDE;
206 virtual uint16_t MaxPayloadLength() const OVERRIDE;
207 virtual uint16_t PacketOverHead() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000209 // Current timestamp.
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000210 virtual uint32_t Timestamp() const OVERRIDE;
211 virtual uint32_t SSRC() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000213 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000214 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000215 int64_t capture_time_ms, StorageType storage,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000216 PacedSender::Priority priority) OVERRIDE;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000217
218 // Audio.
219
220 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000221 int32_t SendTelephoneEvent(const uint8_t key,
222 const uint16_t time_ms,
223 const uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000224
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000225 bool SendTelephoneEventActive(int8_t *telephone_event) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000227 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000228 // packet in silence (CNG).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000229 int32_t SetAudioPacketSize(const uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000231 // Set status and ID for header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000232 int32_t SetAudioLevelIndicationStatus(const bool enable, const uint8_t ID);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000234 // Get status and ID for header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000235 int32_t AudioLevelIndicationStatus(bool *enable, uint8_t *id) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000237 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000238 // header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000239 int32_t SetAudioLevel(const uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000241 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000242 int32_t SetRED(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000243
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000244 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000245 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000247 // Video.
248 VideoCodecInformation *CodecInformationVideo();
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
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000254 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000256 // FEC.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000257 int32_t SetGenericFECStatus(const bool enable,
258 const uint8_t payload_type_red,
259 const uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000261 int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red,
262 uint8_t *payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000263
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000264 int32_t SetFecParameters(const FecProtectionParams *delta_params,
265 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000266
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000267 virtual void RegisterFrameCountObserver(FrameCountObserver* observer);
268 virtual FrameCountObserver* GetFrameCountObserver() const;
269
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000270 int SendPadData(int payload_type, uint32_t timestamp, int64_t capture_time_ms,
271 int32_t bytes, StorageType store,
272 bool force_full_size_packets, bool only_pad_after_markerbit);
273
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000274 protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000275 int32_t CheckPayloadType(const int8_t payload_type,
276 RtpVideoCodecTypes *video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000277
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000278 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000279 // Maps capture time in milliseconds to send-side delay in milliseconds.
280 // Send-side delay is the difference between transmission time and capture
281 // time.
282 typedef std::map<int64_t, int> SendDelayMap;
283
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000284 int CreateRTPHeader(uint8_t* header, int8_t payload_type,
285 uint32_t ssrc, bool marker_bit,
286 uint32_t timestamp, uint16_t sequence_number,
287 const uint32_t* csrcs, uint8_t csrcs_length) const;
288
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000289 void UpdateNACKBitRate(const uint32_t bytes, const uint32_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000290
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000291 bool PrepareAndSendPacket(uint8_t* buffer,
292 uint16_t length,
293 int64_t capture_time_ms,
294 bool send_over_rtx);
295
296 int SendRedundantPayloads(int payload_type, int bytes);
297
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000298 bool SendPaddingAccordingToBitrate(int8_t payload_type,
299 uint32_t capture_timestamp,
300 int64_t capture_time_ms);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000301 int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000302
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000303 void BuildRtxPacket(uint8_t* buffer, uint16_t* length,
304 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000305
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000306 bool SendPacketToNetwork(const uint8_t *packet, uint32_t size);
307
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000308 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
309
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000310 int32_t id_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000311 const bool audio_configured_;
312 RTPSenderAudio *audio_;
313 RTPSenderVideo *video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000314
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000315 PacedSender *paced_sender_;
316 CriticalSectionWrapper *send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000318 Transport *transport_;
319 bool sending_media_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000321 uint16_t max_payload_length_;
322 uint16_t target_send_bitrate_;
323 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000324
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000325 int8_t payload_type_;
326 std::map<int8_t, ModuleRTPUtility::Payload *> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000328 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000329 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000330 uint32_t absolute_send_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000332 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000333 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
334 int32_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000335 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000336
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000337 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000338
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000339 // Statistics
pbos@webrtc.orge07049f2013-09-10 11:29:17 +0000340 scoped_ptr<CriticalSectionWrapper> statistics_crit_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000341 uint32_t packets_sent_;
342 uint32_t payload_bytes_sent_;
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000343 SendDelayMap send_delays_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000344
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000345 // RTP variables
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000346 bool start_time_stamp_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000347 uint32_t start_time_stamp_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000348 SSRCDatabase &ssrc_db_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000349 uint32_t remote_ssrc_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000350 bool sequence_number_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000351 uint16_t sequence_number_;
352 uint16_t sequence_number_rtx_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000353 bool ssrc_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000354 uint32_t ssrc_;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000355 uint32_t timestamp_;
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000356 int64_t capture_time_ms_;
henrik.lundin@webrtc.org6e95d7a2013-11-15 08:59:19 +0000357 int64_t last_timestamp_time_ms_;
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000358 bool last_packet_marker_bit_;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000359 uint8_t num_csrcs_;
360 uint32_t csrcs_[kRtpCsrcSize];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000361 bool include_csrcs_;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000362 int rtx_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000363 uint32_t ssrc_rtx_;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000364 int payload_type_rtx_;
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000365 std::map<FrameType, uint32_t> frame_counts_;
366 FrameCountObserver* frame_count_observer_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367};
niklase@google.com470e71d2011-07-07 08:21:25 +0000368
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000369} // namespace webrtc
370
371#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_