blob: 61d835d06d90f7b9961464fd2aaac0999ed738f3 [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"
mflodman0828a0c2015-03-31 15:29:23 +020028#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
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070044 enum CVOMode {
45 kCVONone,
46 kCVOInactive, // CVO rtp header extension is registered but haven't
47 // received any frame with rotation pending.
48 kCVOActivated, // CVO rtp header extension will be present in the rtp
49 // packets.
50 };
51
pbos@webrtc.org2f446732013-04-08 11:08:41 +000052 virtual uint32_t SSRC() const = 0;
53 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000054
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000055 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000056 int8_t payload_type,
57 bool marker_bit,
58 uint32_t capture_timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000059 int64_t capture_time_ms,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000060 bool timestamp_provided = true,
61 bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000063 virtual size_t RTPHeaderLength() const = 0;
mflodman0828a0c2015-03-31 15:29:23 +020064 virtual uint16_t IncrementSequenceNumber() = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000065 virtual uint16_t SequenceNumber() const = 0;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000066 virtual size_t MaxPayloadLength() const = 0;
67 virtual size_t MaxDataPayloadLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000068 virtual uint16_t PacketOverHead() const = 0;
69 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
pbos@webrtc.org2f446732013-04-08 11:08:41 +000071 virtual int32_t SendToNetwork(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000072 uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000073 int64_t capture_time_ms, StorageType storage,
74 PacedSender::Priority priority) = 0;
guoweis@webrtc.org45362892015-03-04 22:55:15 +000075
76 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
77 size_t rtp_packet_length,
78 const RTPHeader& rtp_header,
79 VideoRotation rotation) const = 0;
80 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070081 virtual CVOMode ActivateCVORtpHeaderExtension() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000082};
83
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000084class RTPSender : public RTPSenderInterface {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000085 public:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000086 RTPSender(int32_t id,
87 bool audio,
88 Clock* clock,
89 Transport* transport,
90 RtpAudioFeedback* audio_feedback,
91 PacedSender* paced_sender,
andresp@webrtc.org8f151212014-07-10 09:39:23 +000092 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000093 FrameCountObserver* frame_count_observer,
94 SendSideDelayObserver* send_side_delay_observer);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000095 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000096
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000097 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +000098
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000099 uint16_t ActualSendBitrateKbit() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000101 uint32_t VideoBitrateSent() const;
102 uint32_t FecOverheadRate() const;
103 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000104
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000105 // Returns true if the statistics have been calculated, and false if no frame
106 // was sent within the statistics window.
107 bool GetSendSideDelay(int* avg_send_delay_ms, int* max_send_delay_ms) const;
108
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +0000109 void SetTargetBitrate(uint32_t bitrate);
110 uint32_t GetTargetBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000112 // Includes size of RTP and FEC headers.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000113 size_t MaxDataPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000115 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000116 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000117 const int8_t payload_type, const uint32_t frequency,
118 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000120 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +0000122 void SetSendPayloadType(int8_t payload_type);
123
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000124 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000126 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000128 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000130 void SetSendingMediaStatus(bool enabled);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000131 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000133 void GetDataCounters(StreamDataCounters* rtp_stats,
134 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000136 void ResetDataCounters();
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000138 uint32_t StartTimestamp() const;
139 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000141 uint32_t GenerateNewSSRC();
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000142 void SetSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000144 uint16_t SequenceNumber() const override;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000145 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000147 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000149 int32_t SetMaxPayloadLength(size_t length, uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000151 int32_t SendOutgoingData(FrameType frame_type,
152 int8_t payload_type,
153 uint32_t timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000154 int64_t capture_time_ms,
155 const uint8_t* payload_data,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000156 size_t payload_size,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000157 const RTPFragmentationHeader* fragmentation,
mflodman0828a0c2015-03-31 15:29:23 +0200158 VideoCodecInformation* codec_info = NULL,
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000159 const RTPVideoHeader* rtp_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000161 // RTP header extension
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000162 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset);
163 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000164 void SetVideoRotation(VideoRotation rotation);
sprang@webrtc.org30933902015-03-17 14:33:12 +0000165 int32_t SetTransportSequenceNumber(uint16_t sequence_number);
niklase@google.com470e71d2011-07-07 08:21:25 +0000166
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000167 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000168 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000169 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000170
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000171 size_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000172
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000173 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000174
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000175 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const;
176 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const;
177 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000178 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000179 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000180
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000181 bool UpdateAudioLevel(uint8_t* rtp_packet,
182 size_t rtp_packet_length,
183 const RTPHeader& rtp_header,
184 bool is_voiced,
185 uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000186
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000187 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
188 size_t rtp_packet_length,
189 const RTPHeader& rtp_header,
190 VideoRotation rotation) const override;
191
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000192 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
193 bool retransmission);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000194 size_t TimeToSendPadding(size_t bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000195
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000196 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000197 int SelectiveRetransmissions() const;
198 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000199 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000200 int64_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000201
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000202 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000203
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000204 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000206 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000207
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000208 bool ProcessNACKBitRate(uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000210 // RTX.
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000211 void SetRtxStatus(int mode);
212 int RtxStatus() const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000213
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000214 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000215 void SetRtxSsrc(uint32_t ssrc);
216
andrew@webrtc.org8f27fcc2015-01-09 20:22:46 +0000217 void SetRtxPayloadType(int payloadType);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000218
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000219 // Functions wrapping RTPSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000220 int32_t BuildRTPheader(uint8_t* data_buffer,
221 int8_t payload_type,
222 bool marker_bit,
223 uint32_t capture_timestamp,
224 int64_t capture_time_ms,
225 const bool timestamp_provided = true,
226 const bool inc_sequence_number = true) override;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000227
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000228 size_t RTPHeaderLength() const override;
mflodman0828a0c2015-03-31 15:29:23 +0200229 uint16_t IncrementSequenceNumber() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000230 size_t MaxPayloadLength() const override;
231 uint16_t PacketOverHead() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000233 // Current timestamp.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000234 uint32_t Timestamp() const override;
235 uint32_t SSRC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000237 int32_t SendToNetwork(uint8_t* data_buffer,
238 size_t payload_length,
239 size_t rtp_header_length,
240 int64_t capture_time_ms,
241 StorageType storage,
242 PacedSender::Priority priority) override;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000243
244 // Audio.
245
246 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000247 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000249 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000250 // packet in silence (CNG).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000251 int32_t SetAudioPacketSize(uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000252
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000253 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000254 // header-extension-for-audio-level-indication.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000255 int32_t SetAudioLevel(uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000256
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000257 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000258 int32_t SetRED(int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000260 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000261 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
mflodman0828a0c2015-03-31 15:29:23 +0200263 // Video.
264 VideoCodecInformation *CodecInformationVideo();
265
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000266 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000267
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000268 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000270 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000271
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000272 // FEC.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000273 int32_t SetGenericFECStatus(bool enable,
274 uint8_t payload_type_red,
275 uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000277 int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red,
278 uint8_t *payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000279
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000280 int32_t SetFecParameters(const FecProtectionParams *delta_params,
281 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000283 size_t SendPadData(uint32_t timestamp,
284 int64_t capture_time_ms,
285 size_t bytes);
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000286
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000287 // Called on update of RTP statistics.
288 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
289 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
290
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000291 uint32_t BitrateSent() const;
292
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000293 void SetRtpState(const RtpState& rtp_state);
294 RtpState GetRtpState() const;
295 void SetRtxRtpState(const RtpState& rtp_state);
296 RtpState GetRtxRtpState() const;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700297 CVOMode ActivateCVORtpHeaderExtension() override;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000298
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000299 protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000300 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000302 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000303 // Maps capture time in milliseconds to send-side delay in milliseconds.
304 // Send-side delay is the difference between transmission time and capture
305 // time.
306 typedef std::map<int64_t, int> SendDelayMap;
307
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000308 size_t CreateRtpHeader(uint8_t* header,
309 int8_t payload_type,
310 uint32_t ssrc,
311 bool marker_bit,
312 uint32_t timestamp,
313 uint16_t sequence_number,
314 const std::vector<uint32_t>& csrcs) const;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000315
stefan@webrtc.org11d81762014-12-19 09:52:24 +0000316 void UpdateNACKBitRate(uint32_t bytes, int64_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000317
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000318 bool PrepareAndSendPacket(uint8_t* buffer,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000319 size_t length,
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000320 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000321 bool send_over_rtx,
322 bool is_retransmit);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000323
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000324 // Return the number of bytes sent. Note that both of these functions may
325 // return a larger value that their argument.
326 size_t TrySendRedundantPayloads(size_t bytes);
327 size_t TrySendPadData(size_t bytes);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000328
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000329 size_t BuildPaddingPacket(uint8_t* packet, size_t header_length);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000330
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000331 void BuildRtxPacket(uint8_t* buffer, size_t* length,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000332 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000333
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000334 bool SendPacketToNetwork(const uint8_t *packet, size_t size);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000335
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000336 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
337
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000338 // Find the byte position of the RTP extension as indicated by |type| in
339 // |rtp_packet|. Return false if such extension doesn't exist.
340 bool FindHeaderExtensionPosition(RTPExtensionType type,
341 const uint8_t* rtp_packet,
342 size_t rtp_packet_length,
343 const RTPHeader& rtp_header,
344 size_t* position) const;
345
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000346 void UpdateTransmissionTimeOffset(uint8_t* rtp_packet,
347 size_t rtp_packet_length,
348 const RTPHeader& rtp_header,
349 int64_t time_diff_ms) const;
350 void UpdateAbsoluteSendTime(uint8_t* rtp_packet,
351 size_t rtp_packet_length,
352 const RTPHeader& rtp_header,
353 int64_t now_ms) const;
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000354
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000355 void UpdateRtpStats(const uint8_t* buffer,
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000356 size_t packet_length,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000357 const RTPHeader& header,
358 bool is_rtx,
359 bool is_retransmit);
360 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
361
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000362 Clock* clock_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000363 int64_t clock_delta_ms_;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000364
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000365 rtc::scoped_ptr<BitrateAggregator> bitrates_;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000366 Bitrate total_bitrate_sent_;
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000367
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000368 int32_t id_;
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +0000369
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000370 const bool audio_configured_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000371 rtc::scoped_ptr<RTPSenderAudio> audio_;
372 rtc::scoped_ptr<RTPSenderVideo> video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000373
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000374 PacedSender *paced_sender_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000375 int64_t last_capture_time_ms_sent_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000376 rtc::scoped_ptr<CriticalSectionWrapper> send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000378 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000379 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000381 size_t max_payload_length_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000382 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000384 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000385 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000387 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000388 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000389 uint32_t absolute_send_time_;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000390 VideoRotation rotation_;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700391 CVOMode cvo_mode_;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000392 uint16_t transport_sequence_number_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000393
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000394 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000395 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000396 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000397 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000398
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000399 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000400
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000401 // Statistics
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000402 rtc::scoped_ptr<CriticalSectionWrapper> statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000403 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000404 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000405 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
406 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
407 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000408 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000409 SendSideDelayObserver* const send_side_delay_observer_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000410
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000411 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000412 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
413 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
414 SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_);
415 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
416 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
417 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
418 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
419 bool ssrc_forced_ GUARDED_BY(send_critsect_);
420 uint32_t ssrc_ GUARDED_BY(send_critsect_);
421 uint32_t timestamp_ GUARDED_BY(send_critsect_);
422 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
423 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000424 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000425 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000426 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000427 int rtx_ GUARDED_BY(send_critsect_);
428 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
andrew@webrtc.org8f27fcc2015-01-09 20:22:46 +0000429 int payload_type_rtx_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000430
431 // Note: Don't access this variable directly, always go through
432 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
433 // that by the time the function returns there is no guarantee
434 // that the target bitrate is still valid.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000435 rtc::scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
stefan@webrtc.orgaa0e56e2014-06-26 11:44:49 +0000436 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000437};
niklase@google.com470e71d2011-07-07 08:21:25 +0000438
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000439} // namespace webrtc
440
441#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_