blob: 17457ff2218a1cf50ba598ee053b8b6663d5fc0a [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.org2f446732013-04-08 11:08:41 +000046 virtual int32_t BuildRTPheader(
47 uint8_t *data_buffer, const int8_t payload_type,
48 const bool marker_bit, const uint32_t capture_time_stamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +000049 int64_t capture_time_ms,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000050 const bool time_stamp_provided = true,
51 const bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
pbos@webrtc.org2f446732013-04-08 11:08:41 +000053 virtual uint16_t RTPHeaderLength() const = 0;
54 virtual uint16_t IncrementSequenceNumber() = 0;
55 virtual uint16_t SequenceNumber() const = 0;
56 virtual uint16_t MaxPayloadLength() const = 0;
57 virtual uint16_t MaxDataPayloadLength() const = 0;
58 virtual uint16_t PacketOverHead() const = 0;
59 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
pbos@webrtc.org2f446732013-04-08 11:08:41 +000061 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000062 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000063 int64_t capture_time_ms, StorageType storage,
64 PacedSender::Priority priority) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000065};
66
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +000067class RTPSender : public RTPSenderInterface, public Bitrate::Observer {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000068 public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000069 RTPSender(const int32_t id, const bool audio, Clock *clock,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000070 Transport *transport, RtpAudioFeedback *audio_feedback,
71 PacedSender *paced_sender);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000072 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000073
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000074 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000075
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000076 virtual uint16_t ActualSendBitrateKbit() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
pbos@webrtc.org2f446732013-04-08 11:08:41 +000078 uint32_t VideoBitrateSent() const;
79 uint32_t FecOverheadRate() const;
80 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +000081
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +000082 // Returns true if the statistics have been calculated, and false if no frame
83 // was sent within the statistics window.
84 bool GetSendSideDelay(int* avg_send_delay_ms, int* max_send_delay_ms) const;
85
pbos@webrtc.org2f446732013-04-08 11:08:41 +000086 void SetTargetSendBitrate(const uint32_t bits);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000088 virtual uint16_t MaxDataPayloadLength() const
89 OVERRIDE; // with RTP and FEC headers.
niklase@google.com470e71d2011-07-07 08:21:25 +000090
pbos@webrtc.org2f446732013-04-08 11:08:41 +000091 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000092 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +000093 const int8_t payload_type, const uint32_t frequency,
94 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +000095
pbos@webrtc.org2f446732013-04-08 11:08:41 +000096 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000097
pbos@webrtc.org2f446732013-04-08 11:08:41 +000098 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000099
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000100 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000102 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000104 void SetSendingMediaStatus(const bool enabled);
105 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000107 // Number of sent RTP packets.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000108 uint32_t Packets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000110 // Number of sent RTP bytes.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000111 uint32_t Bytes() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000113 void ResetDataCounters();
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000115 uint32_t StartTimestamp() const;
116 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000118 uint32_t GenerateNewSSRC();
119 void SetSSRC(const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000121 virtual uint16_t SequenceNumber() const OVERRIDE;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000122 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000124 int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000126 void SetCSRCStatus(const bool include);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000128 void SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize],
129 const uint8_t arr_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000131 int32_t SetMaxPayloadLength(const uint16_t length,
132 const uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000134 int32_t SendOutgoingData(
135 const FrameType frame_type, const int8_t payload_type,
136 const uint32_t time_stamp, int64_t capture_time_ms,
137 const uint8_t *payload_data, const uint32_t payload_size,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000138 const RTPFragmentationHeader *fragmentation,
139 VideoCodecInformation *codec_info = NULL,
140 const RTPVideoTypeHeader * rtp_type_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000142 // RTP header extension
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000143 int32_t SetTransmissionTimeOffset(
144 const int32_t transmission_time_offset);
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000145 int32_t SetAbsoluteSendTime(
146 const uint32_t absolute_send_time);
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000148 int32_t RegisterRtpHeaderExtension(const RTPExtensionType type,
149 const uint8_t id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000150
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000151 int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000152
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000153 uint16_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000154
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000155 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000156
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000157 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const;
158 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const;
159 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000160
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000161 bool UpdateAudioLevel(uint8_t *rtp_packet,
162 const uint16_t rtp_packet_length,
163 const RTPHeader &rtp_header,
164 const bool is_voiced,
165 const uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000166
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000167 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
168 bool retransmission);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000169 int TimeToSendPadding(int bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000170
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000171 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000172 int SelectiveRetransmissions() const;
173 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000174 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000175 const uint16_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000176
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000177 void SetStorePacketsStatus(const bool enable,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000178 const uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000180 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000182 int32_t ReSendPacket(uint16_t packet_id, uint32_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000184 bool ProcessNACKBitRate(const uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000186 // RTX.
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000187 void SetRTXStatus(int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000189 void RTXStatus(int* mode, uint32_t* ssrc, int* payload_type) const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000190
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000191 void SetRtxSsrc(uint32_t ssrc);
192
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000193 void SetRtxPayloadType(int payloadType);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000194
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000195 // Functions wrapping RTPSenderInterface.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000196 virtual int32_t BuildRTPheader(
197 uint8_t *data_buffer, const int8_t payload_type,
198 const bool marker_bit, const uint32_t capture_time_stamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000199 int64_t capture_time_ms,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000200 const bool time_stamp_provided = true,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000201 const bool inc_sequence_number = true) OVERRIDE;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000202
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000203 virtual uint16_t RTPHeaderLength() const OVERRIDE;
204 virtual uint16_t IncrementSequenceNumber() OVERRIDE;
205 virtual uint16_t MaxPayloadLength() const OVERRIDE;
206 virtual uint16_t PacketOverHead() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000208 // Current timestamp.
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000209 virtual uint32_t Timestamp() const OVERRIDE;
210 virtual uint32_t SSRC() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000211
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000212 virtual int32_t SendToNetwork(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000213 uint8_t *data_buffer, int payload_length, int rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000214 int64_t capture_time_ms, StorageType storage,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000215 PacedSender::Priority priority) OVERRIDE;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000216
217 // Audio.
218
219 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000220 int32_t SendTelephoneEvent(const uint8_t key,
221 const uint16_t time_ms,
222 const uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000224 bool SendTelephoneEventActive(int8_t *telephone_event) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000226 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000227 // packet in silence (CNG).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000228 int32_t SetAudioPacketSize(const uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000230 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000231 // header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000232 int32_t SetAudioLevel(const uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000233
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000234 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000235 int32_t SetRED(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000237 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000238 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000240 // Video.
241 VideoCodecInformation *CodecInformationVideo();
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000243 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000245 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000246
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000247 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000249 // FEC.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000250 int32_t SetGenericFECStatus(const bool enable,
251 const uint8_t payload_type_red,
252 const uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000254 int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red,
255 uint8_t *payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000257 int32_t SetFecParameters(const FecProtectionParams *delta_params,
258 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000260 virtual void RegisterFrameCountObserver(FrameCountObserver* observer);
261 virtual FrameCountObserver* GetFrameCountObserver() const;
262
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000263 int SendPadData(int payload_type, uint32_t timestamp, int64_t capture_time_ms,
264 int32_t bytes, StorageType store,
265 bool force_full_size_packets, bool only_pad_after_markerbit);
266
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000267 // Called on update of RTP statistics.
268 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
269 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
270
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000271 // Called on new send bitrate estimate.
272 void RegisterBitrateObserver(BitrateStatisticsObserver* observer);
273 BitrateStatisticsObserver* GetBitrateObserver() const;
274
275 uint32_t BitrateSent() const;
276
277 virtual void BitrateUpdated(const BitrateStatistics& stats) OVERRIDE;
278
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000279 protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000280 int32_t CheckPayloadType(const int8_t payload_type,
281 RtpVideoCodecTypes *video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000283 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000284 // Maps capture time in milliseconds to send-side delay in milliseconds.
285 // Send-side delay is the difference between transmission time and capture
286 // time.
287 typedef std::map<int64_t, int> SendDelayMap;
288
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000289 int CreateRTPHeader(uint8_t* header, int8_t payload_type,
290 uint32_t ssrc, bool marker_bit,
291 uint32_t timestamp, uint16_t sequence_number,
292 const uint32_t* csrcs, uint8_t csrcs_length) const;
293
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000294 void UpdateNACKBitRate(const uint32_t bytes, const uint32_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000295
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000296 bool PrepareAndSendPacket(uint8_t* buffer,
297 uint16_t length,
298 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000299 bool send_over_rtx,
300 bool is_retransmit);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000301
302 int SendRedundantPayloads(int payload_type, int bytes);
303
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000304 bool SendPaddingAccordingToBitrate(int8_t payload_type,
305 uint32_t capture_timestamp,
306 int64_t capture_time_ms);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000307 int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000308
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000309 void BuildRtxPacket(uint8_t* buffer, uint16_t* length,
310 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000311
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000312 bool SendPacketToNetwork(const uint8_t *packet, uint32_t size);
313
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000314 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
315
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000316 void UpdateTransmissionTimeOffset(uint8_t *rtp_packet,
317 const uint16_t rtp_packet_length,
318 const RTPHeader &rtp_header,
319 const int64_t time_diff_ms) const;
320 void UpdateAbsoluteSendTime(uint8_t *rtp_packet,
321 const uint16_t rtp_packet_length,
322 const RTPHeader &rtp_header,
323 const int64_t now_ms) const;
324
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000325 void UpdateRtpStats(const uint8_t* buffer,
326 uint32_t size,
327 const RTPHeader& header,
328 bool is_rtx,
329 bool is_retransmit);
330 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
331
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000332 void SetTargetBitrateKbps(uint16_t bitrate_kbps);
333 uint16_t GetTargetBitrateKbps();
334
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000335 Clock* clock_;
336 Bitrate bitrate_sent_;
337
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000338 int32_t id_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000339 const bool audio_configured_;
340 RTPSenderAudio *audio_;
341 RTPSenderVideo *video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000342
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000343 PacedSender *paced_sender_;
344 CriticalSectionWrapper *send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000345
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000346 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000347 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000349 uint16_t max_payload_length_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000350 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000352 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000353 std::map<int8_t, ModuleRTPUtility::Payload *> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000354
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000355 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000356 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000357 uint32_t absolute_send_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000359 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000360 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
361 int32_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000362 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000363
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000364 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000366 // Statistics
pbos@webrtc.orge07049f2013-09-10 11:29:17 +0000367 scoped_ptr<CriticalSectionWrapper> statistics_crit_;
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000368 SendDelayMap send_delays_;
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000369 std::map<FrameType, uint32_t> frame_counts_;
370 FrameCountObserver* frame_count_observer_;
371 StreamDataCounters rtp_stats_;
372 StreamDataCounters rtx_rtp_stats_;
373 StreamDataCountersCallback* rtp_stats_callback_;
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000374 BitrateStatisticsObserver* bitrate_callback_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000375
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000376 // RTP variables
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000377 bool start_time_stamp_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000378 uint32_t start_time_stamp_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000379 SSRCDatabase &ssrc_db_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000380 uint32_t remote_ssrc_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000381 bool sequence_number_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000382 uint16_t sequence_number_;
383 uint16_t sequence_number_rtx_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000384 bool ssrc_forced_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000385 uint32_t ssrc_;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000386 uint32_t timestamp_;
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000387 int64_t capture_time_ms_;
henrik.lundin@webrtc.org6e95d7a2013-11-15 08:59:19 +0000388 int64_t last_timestamp_time_ms_;
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000389 bool last_packet_marker_bit_;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000390 uint8_t num_csrcs_;
391 uint32_t csrcs_[kRtpCsrcSize];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000392 bool include_csrcs_;
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000393 int rtx_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000394 uint32_t ssrc_rtx_;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000395 int payload_type_rtx_;
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000396
397 // Note: Don't access this variable directly, always go through
398 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
399 // that by the time the function returns there is no guarantee
400 // that the target bitrate is still valid.
401 scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
402 uint16_t target_bitrate_kbps_ GUARDED_BY(target_bitrate_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000403};
niklase@google.com470e71d2011-07-07 08:21:25 +0000404
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000405} // namespace webrtc
406
407#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_