blob: 0558c191650988c6d230ee0486095a80f6fa9e94 [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
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000019#include "webrtc/base/thread_annotations.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000020#include "webrtc/common_types.h"
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000021#include "webrtc/modules/pacing/include/paced_sender.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000022#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
phoglund@webrtc.orgc38eef82013-01-07 10:18:30 +000023#include "webrtc/modules/rtp_rtcp/source/bitrate.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000024#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000025#include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000026#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
27#include "webrtc/modules/rtp_rtcp/source/ssrc_database.h"
28#include "webrtc/modules/rtp_rtcp/source/video_codec_information.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
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000034class BitrateAggregator;
niklase@google.com470e71d2011-07-07 08:21:25 +000035class CriticalSectionWrapper;
36class RTPSenderAudio;
37class RTPSenderVideo;
38
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000039class RTPSenderInterface {
40 public:
41 RTPSenderInterface() {}
42 virtual ~RTPSenderInterface() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000043
pbos@webrtc.org2f446732013-04-08 11:08:41 +000044 virtual uint32_t SSRC() const = 0;
45 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000047 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
48 const int8_t payload_type,
49 const bool marker_bit,
50 const uint32_t capture_timestamp,
51 int64_t capture_time_ms,
52 const bool timestamp_provided = true,
53 const bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000055 virtual size_t RTPHeaderLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000056 virtual uint16_t IncrementSequenceNumber() = 0;
57 virtual uint16_t SequenceNumber() const = 0;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000058 virtual size_t MaxPayloadLength() const = 0;
59 virtual size_t MaxDataPayloadLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000060 virtual uint16_t PacketOverHead() const = 0;
61 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.org2f446732013-04-08 11:08:41 +000063 virtual int32_t SendToNetwork(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000064 uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000065 int64_t capture_time_ms, StorageType storage,
66 PacedSender::Priority priority) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000067};
68
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000069class RTPSender : public RTPSenderInterface {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000070 public:
pbos@webrtc.org2f446732013-04-08 11:08:41 +000071 RTPSender(const int32_t id, const bool audio, Clock *clock,
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000072 Transport *transport, RtpAudioFeedback *audio_feedback,
andresp@webrtc.orgd11bec42014-07-08 14:32:58 +000073 PacedSender *paced_sender,
andresp@webrtc.org8f151212014-07-10 09:39:23 +000074 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000075 FrameCountObserver* frame_count_observer,
76 SendSideDelayObserver* send_side_delay_observer);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000077 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000078
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000079 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000080
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +000081 virtual uint16_t ActualSendBitrateKbit() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
pbos@webrtc.org2f446732013-04-08 11:08:41 +000083 uint32_t VideoBitrateSent() const;
84 uint32_t FecOverheadRate() const;
85 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +000086
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +000087 // Returns true if the statistics have been calculated, and false if no frame
88 // was sent within the statistics window.
89 bool GetSendSideDelay(int* avg_send_delay_ms, int* max_send_delay_ms) const;
90
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +000091 void SetTargetBitrate(uint32_t bitrate);
92 uint32_t GetTargetBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000093
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000094 // Includes size of RTP and FEC headers.
95 virtual size_t MaxDataPayloadLength() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
pbos@webrtc.org2f446732013-04-08 11:08:41 +000097 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +000098 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +000099 const int8_t payload_type, const uint32_t frequency,
100 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000102 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +0000104 void SetSendPayloadType(int8_t payload_type);
105
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000106 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000108 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000110 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000112 void SetSendingMediaStatus(const bool enabled);
113 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000115 void GetDataCounters(StreamDataCounters* rtp_stats,
116 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000118 void ResetDataCounters();
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000120 uint32_t StartTimestamp() const;
121 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000123 uint32_t GenerateNewSSRC();
124 void SetSSRC(const uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000126 virtual uint16_t SequenceNumber() const OVERRIDE;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000127 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000129 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000131 int32_t SetMaxPayloadLength(const size_t length,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000132 const uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000134 int32_t SendOutgoingData(const FrameType frame_type,
135 const int8_t payload_type,
136 const uint32_t timestamp,
137 int64_t capture_time_ms,
138 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000139 const size_t payload_size,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000140 const RTPFragmentationHeader* fragmentation,
141 VideoCodecInformation* codec_info = NULL,
142 const RTPVideoTypeHeader* rtp_type_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000144 // RTP header extension
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000145 int32_t SetTransmissionTimeOffset(
146 const int32_t transmission_time_offset);
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000147 int32_t SetAbsoluteSendTime(
148 const uint32_t absolute_send_time);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000150 int32_t RegisterRtpHeaderExtension(const RTPExtensionType type,
151 const uint8_t id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000152
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000153 int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000154
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000155 size_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000156
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000157 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000158
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000159 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const;
160 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const;
161 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000162
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000163 bool UpdateAudioLevel(uint8_t *rtp_packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000164 const size_t rtp_packet_length,
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000165 const RTPHeader &rtp_header,
166 const bool is_voiced,
167 const uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000168
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000169 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
170 bool retransmission);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000171 size_t TimeToSendPadding(size_t bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000172
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000173 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000174 int SelectiveRetransmissions() const;
175 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000176 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000177 const uint16_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000178
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000179 void SetStorePacketsStatus(const bool enable,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000180 const uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000182 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000183
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000184 int32_t ReSendPacket(uint16_t packet_id, uint32_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000186 bool ProcessNACKBitRate(const uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000188 // RTX.
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000189 void SetRTXStatus(int mode);
niklase@google.com470e71d2011-07-07 08:21:25 +0000190
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000191 void RTXStatus(int* mode, uint32_t* ssrc, int* payload_type) const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000192
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000193 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000194 void SetRtxSsrc(uint32_t ssrc);
195
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000196 void SetRtxPayloadType(int payloadType);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000197
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000198 // Functions wrapping RTPSenderInterface.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000199 virtual int32_t BuildRTPheader(
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000200 uint8_t* data_buffer,
201 const int8_t payload_type,
202 const bool marker_bit,
203 const uint32_t capture_timestamp,
stefan@webrtc.org8ccb9f92013-06-19 14:13:42 +0000204 int64_t capture_time_ms,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000205 const bool timestamp_provided = true,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000206 const bool inc_sequence_number = true) OVERRIDE;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000207
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000208 virtual size_t RTPHeaderLength() const OVERRIDE;
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000209 virtual uint16_t IncrementSequenceNumber() OVERRIDE;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000210 virtual size_t MaxPayloadLength() const OVERRIDE;
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000211 virtual uint16_t PacketOverHead() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000213 // Current timestamp.
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000214 virtual uint32_t Timestamp() const OVERRIDE;
215 virtual uint32_t SSRC() const OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000217 virtual int32_t SendToNetwork(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000218 uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000219 int64_t capture_time_ms, StorageType storage,
pbos@webrtc.orgf3e4cee2013-07-31 15:17:19 +0000220 PacedSender::Priority priority) OVERRIDE;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000221
222 // Audio.
223
224 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000225 int32_t SendTelephoneEvent(const uint8_t key,
226 const uint16_t time_ms,
227 const uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000228
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000229 bool SendTelephoneEventActive(int8_t *telephone_event) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000230
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000231 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000232 // packet in silence (CNG).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000233 int32_t SetAudioPacketSize(const uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000234
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000235 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000236 // header-extension-for-audio-level-indication.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000237 int32_t SetAudioLevel(const uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000238
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000239 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000240 int32_t SetRED(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000241
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000242 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000243 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000245 // Video.
246 VideoCodecInformation *CodecInformationVideo();
niklase@google.com470e71d2011-07-07 08:21:25 +0000247
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000248 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000250 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000252 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000254 // FEC.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000255 int32_t SetGenericFECStatus(const bool enable,
256 const uint8_t payload_type_red,
257 const uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000259 int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red,
260 uint8_t *payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000262 int32_t SetFecParameters(const FecProtectionParams *delta_params,
263 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000264
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000265 size_t SendPadData(uint32_t timestamp,
266 int64_t capture_time_ms,
267 size_t bytes);
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000268
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000269 // Called on update of RTP statistics.
270 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
271 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
272
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000273 uint32_t BitrateSent() const;
274
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000275 void SetRtpState(const RtpState& rtp_state);
276 RtpState GetRtpState() const;
277 void SetRtxRtpState(const RtpState& rtp_state);
278 RtpState GetRtxRtpState() const;
279
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000280 protected:
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000281 int32_t CheckPayloadType(const int8_t payload_type,
282 RtpVideoCodecTypes *video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000283
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000284 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000285 // Maps capture time in milliseconds to send-side delay in milliseconds.
286 // Send-side delay is the difference between transmission time and capture
287 // time.
288 typedef std::map<int64_t, int> SendDelayMap;
289
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000290 size_t CreateRtpHeader(uint8_t* header,
291 int8_t payload_type,
292 uint32_t ssrc,
293 bool marker_bit,
294 uint32_t timestamp,
295 uint16_t sequence_number,
296 const std::vector<uint32_t>& csrcs) const;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000297
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000298 void UpdateNACKBitRate(const size_t bytes, const uint32_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000299
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000300 bool PrepareAndSendPacket(uint8_t* buffer,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000301 size_t length,
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000302 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000303 bool send_over_rtx,
304 bool is_retransmit);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000305
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000306 // Return the number of bytes sent. Note that both of these functions may
307 // return a larger value that their argument.
308 size_t TrySendRedundantPayloads(size_t bytes);
309 size_t TrySendPadData(size_t bytes);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000310
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000311 size_t BuildPaddingPacket(uint8_t* packet, size_t header_length);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000312
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000313 void BuildRtxPacket(uint8_t* buffer, size_t* length,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000314 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000315
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000316 bool SendPacketToNetwork(const uint8_t *packet, size_t size);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000317
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000318 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
319
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000320 void UpdateTransmissionTimeOffset(uint8_t *rtp_packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000321 const size_t rtp_packet_length,
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000322 const RTPHeader &rtp_header,
323 const int64_t time_diff_ms) const;
324 void UpdateAbsoluteSendTime(uint8_t *rtp_packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000325 const size_t rtp_packet_length,
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000326 const RTPHeader &rtp_header,
327 const int64_t now_ms) const;
328
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000329 void UpdateRtpStats(const uint8_t* buffer,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000330 size_t size,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000331 const RTPHeader& header,
332 bool is_rtx,
333 bool is_retransmit);
334 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
335
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000336 Clock* clock_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000337 int64_t clock_delta_ms_;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000338
339 scoped_ptr<BitrateAggregator> bitrates_;
340 Bitrate total_bitrate_sent_;
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000341
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_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000348 int64_t last_capture_time_ms_sent_;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000349 CriticalSectionWrapper *send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000350
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000351 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000352 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000353
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000354 size_t max_payload_length_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000355 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000356
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000357 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000358 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000359
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000360 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000361 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000362 uint32_t absolute_send_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000364 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000365 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000366 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000367 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000368
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000369 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000370
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000371 // Statistics
pbos@webrtc.orge07049f2013-09-10 11:29:17 +0000372 scoped_ptr<CriticalSectionWrapper> statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000373 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
374 std::map<FrameType, uint32_t> frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000375 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
376 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
377 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000378 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000379 SendSideDelayObserver* const send_side_delay_observer_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000380
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000381 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000382 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
383 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
384 SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_);
385 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
386 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
387 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
388 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
389 bool ssrc_forced_ GUARDED_BY(send_critsect_);
390 uint32_t ssrc_ GUARDED_BY(send_critsect_);
391 uint32_t timestamp_ GUARDED_BY(send_critsect_);
392 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
393 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000394 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000395 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000396 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000397 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_