blob: a4703989d6e4a33323a68325b13efe392839499d [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_
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <assert.h>
14#include <math.h>
15
pwestin@webrtc.org00741872012-01-19 15:56:10 +000016#include <map>
17
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000018#include "webrtc/base/thread_annotations.h"
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"
mflodmanfcf54bd2015-04-14 21:28:08 +020026#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +000027#include "webrtc/modules/rtp_rtcp/source/ssrc_database.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
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000033class BitrateAggregator;
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
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070043 enum CVOMode {
44 kCVONone,
45 kCVOInactive, // CVO rtp header extension is registered but haven't
46 // received any frame with rotation pending.
47 kCVOActivated, // CVO rtp header extension will be present in the rtp
48 // packets.
49 };
50
pbos@webrtc.org2f446732013-04-08 11:08:41 +000051 virtual uint32_t SSRC() const = 0;
52 virtual uint32_t Timestamp() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000054 virtual int32_t BuildRTPheader(uint8_t* data_buffer,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000055 int8_t payload_type,
56 bool marker_bit,
57 uint32_t capture_timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000058 int64_t capture_time_ms,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000059 bool timestamp_provided = true,
60 bool inc_sequence_number = true) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000062 virtual size_t RTPHeaderLength() const = 0;
mflodmanfcf54bd2015-04-14 21:28:08 +020063 // Returns the next sequence number to use for a packet and allocates
64 // 'packets_to_send' number of sequence numbers. It's important all allocated
65 // sequence numbers are used in sequence to avoid perceived packet loss.
66 virtual uint16_t AllocateSequenceNumber(uint16_t packets_to_send) = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000067 virtual uint16_t SequenceNumber() const = 0;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000068 virtual size_t MaxPayloadLength() const = 0;
69 virtual size_t MaxDataPayloadLength() const = 0;
pbos@webrtc.org2f446732013-04-08 11:08:41 +000070 virtual uint16_t PacketOverHead() const = 0;
71 virtual uint16_t ActualSendBitrateKbit() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000072
pbos@webrtc.org2f446732013-04-08 11:08:41 +000073 virtual int32_t SendToNetwork(
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000074 uint8_t *data_buffer, size_t payload_length, size_t rtp_header_length,
stefan@webrtc.org508a84b2013-06-17 12:53:37 +000075 int64_t capture_time_ms, StorageType storage,
76 PacedSender::Priority priority) = 0;
guoweis@webrtc.org45362892015-03-04 22:55:15 +000077
78 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
79 size_t rtp_packet_length,
80 const RTPHeader& rtp_header,
81 VideoRotation rotation) const = 0;
82 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) = 0;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -070083 virtual CVOMode ActivateCVORtpHeaderExtension() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000084};
85
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000086class RTPSender : public RTPSenderInterface {
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000087 public:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +000088 RTPSender(int32_t id,
89 bool audio,
90 Clock* clock,
91 Transport* transport,
92 RtpAudioFeedback* audio_feedback,
93 PacedSender* paced_sender,
andresp@webrtc.org8f151212014-07-10 09:39:23 +000094 BitrateStatisticsObserver* bitrate_callback,
stefan@webrtc.org168f23f2014-07-11 13:44:02 +000095 FrameCountObserver* frame_count_observer,
96 SendSideDelayObserver* send_side_delay_observer);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000097 virtual ~RTPSender();
niklase@google.com470e71d2011-07-07 08:21:25 +000098
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +000099 void ProcessBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000101 uint16_t ActualSendBitrateKbit() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000103 uint32_t VideoBitrateSent() const;
104 uint32_t FecOverheadRate() const;
105 uint32_t NackOverheadRate() const;
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000106
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +0000107 void SetTargetBitrate(uint32_t bitrate);
108 uint32_t GetTargetBitrate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000110 // Includes size of RTP and FEC headers.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000111 size_t MaxDataPayloadLength() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000113 int32_t RegisterPayload(
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000114 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000115 const int8_t payload_type, const uint32_t frequency,
116 const uint8_t channels, const uint32_t rate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000118 int32_t DeRegisterSendPayload(const int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
andresp@webrtc.orgc3c29112014-08-27 09:39:43 +0000120 void SetSendPayloadType(int8_t payload_type);
121
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000122 int8_t SendPayloadType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000124 int SendPayloadFrequency() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000126 void SetSendingStatus(bool enabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000128 void SetSendingMediaStatus(bool enabled);
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000129 bool SendingMedia() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000131 void GetDataCounters(StreamDataCounters* rtp_stats,
132 StreamDataCounters* rtx_stats) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000134 uint32_t StartTimestamp() const;
135 void SetStartTimestamp(uint32_t timestamp, bool force);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000137 uint32_t GenerateNewSSRC();
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000138 void SetSSRC(uint32_t ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000140 uint16_t SequenceNumber() const override;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000141 void SetSequenceNumber(uint16_t seq);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000143 void SetCsrcs(const std::vector<uint32_t>& csrcs);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000145 int32_t SetMaxPayloadLength(size_t length, uint16_t packet_over_head);
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000147 int32_t SendOutgoingData(FrameType frame_type,
148 int8_t payload_type,
149 uint32_t timestamp,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000150 int64_t capture_time_ms,
151 const uint8_t* payload_data,
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000152 size_t payload_size,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000153 const RTPFragmentationHeader* fragmentation,
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000154 const RTPVideoHeader* rtp_hdr = NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000155
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000156 // RTP header extension
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000157 int32_t SetTransmissionTimeOffset(int32_t transmission_time_offset);
158 int32_t SetAbsoluteSendTime(uint32_t absolute_send_time);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000159 void SetVideoRotation(VideoRotation rotation);
sprang@webrtc.org30933902015-03-17 14:33:12 +0000160 int32_t SetTransportSequenceNumber(uint16_t sequence_number);
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000162 int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000163 virtual bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) override;
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000164 int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000165
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000166 size_t RtpHeaderExtensionTotalLength() const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000167
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000168 uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer, bool marker_bit) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000169
wu@webrtc.orgebdb0e32014-03-06 23:49:08 +0000170 uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const;
171 uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const;
172 uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000173 uint8_t BuildVideoRotationExtension(uint8_t* data_buffer) const;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000174 uint8_t BuildTransportSequenceNumberExtension(uint8_t* data_buffer) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000175
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000176 bool UpdateAudioLevel(uint8_t* rtp_packet,
177 size_t rtp_packet_length,
178 const RTPHeader& rtp_header,
179 bool is_voiced,
180 uint8_t dBov) const;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000181
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000182 virtual bool UpdateVideoRotation(uint8_t* rtp_packet,
183 size_t rtp_packet_length,
184 const RTPHeader& rtp_header,
185 VideoRotation rotation) const override;
186
stefan@webrtc.org9b82f5a2013-11-13 15:29:21 +0000187 bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms,
188 bool retransmission);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000189 size_t TimeToSendPadding(size_t bytes);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000190
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000191 // NACK.
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000192 int SelectiveRetransmissions() const;
193 int SetSelectiveRetransmissions(uint8_t settings);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000194 void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000195 int64_t avg_rtt);
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000196
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000197 void SetStorePacketsStatus(bool enable, uint16_t number_to_store);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000199 bool StorePackets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000201 int32_t ReSendPacket(uint16_t packet_id, int64_t min_resend_time = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000203 bool ProcessNACKBitRate(uint32_t now);
niklase@google.com470e71d2011-07-07 08:21:25 +0000204
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000205 // RTX.
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000206 void SetRtxStatus(int mode);
207 int RtxStatus() const;
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000208
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000209 uint32_t RtxSsrc() const;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000210 void SetRtxSsrc(uint32_t ssrc);
211
Shao Changbine62202f2015-04-21 20:24:50 +0800212 void SetRtxPayloadType(int payload_type, int associated_payload_type);
213 std::pair<int, int> RtxPayloadType() const;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000214
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000215 // Functions wrapping RTPSenderInterface.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000216 int32_t BuildRTPheader(uint8_t* data_buffer,
217 int8_t payload_type,
218 bool marker_bit,
219 uint32_t capture_timestamp,
220 int64_t capture_time_ms,
221 const bool timestamp_provided = true,
222 const bool inc_sequence_number = true) override;
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000223
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000224 size_t RTPHeaderLength() const override;
mflodmanfcf54bd2015-04-14 21:28:08 +0200225 uint16_t AllocateSequenceNumber(uint16_t packets_to_send) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000226 size_t MaxPayloadLength() const override;
227 uint16_t PacketOverHead() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000229 // Current timestamp.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000230 uint32_t Timestamp() const override;
231 uint32_t SSRC() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000233 int32_t SendToNetwork(uint8_t* data_buffer,
234 size_t payload_length,
235 size_t rtp_header_length,
236 int64_t capture_time_ms,
237 StorageType storage,
238 PacedSender::Priority priority) override;
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000239
240 // Audio.
241
242 // Send a DTMF tone using RFC 2833 (4733).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000243 int32_t SendTelephoneEvent(uint8_t key, uint16_t time_ms, uint8_t level);
niklase@google.com470e71d2011-07-07 08:21:25 +0000244
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000245 // Set audio packet size, used to determine when it's time to send a DTMF
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000246 // packet in silence (CNG).
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000247 int32_t SetAudioPacketSize(uint16_t packet_size_samples);
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000249 // Store the audio level in d_bov for
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000250 // header-extension-for-audio-level-indication.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000251 int32_t SetAudioLevel(uint8_t level_d_bov);
niklase@google.com470e71d2011-07-07 08:21:25 +0000252
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000253 // Set payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000254 int32_t SetRED(int8_t payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000256 // Get payload type for Redundant Audio Data RFC 2198.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000257 int32_t RED(int8_t *payload_type) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000258
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000259 RtpVideoCodecTypes VideoCodecType() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000260
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000261 uint32_t MaxConfiguredBitrateVideo() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000262
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000263 int32_t SendRTPIntraRequest();
niklase@google.com470e71d2011-07-07 08:21:25 +0000264
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000265 // FEC.
pbosba8c15b2015-07-14 09:36:34 -0700266 void SetGenericFECStatus(bool enable,
267 uint8_t payload_type_red,
268 uint8_t payload_type_fec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
pbosba8c15b2015-07-14 09:36:34 -0700270 void GenericFECStatus(bool* enable,
271 uint8_t* payload_type_red,
272 uint8_t* payload_type_fec) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000274 int32_t SetFecParameters(const FecProtectionParams *delta_params,
275 const FecProtectionParams *key_params);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000277 size_t SendPadData(uint32_t timestamp,
278 int64_t capture_time_ms,
279 size_t bytes);
stefan@webrtc.orgc4726d02013-12-05 09:16:33 +0000280
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000281 // Called on update of RTP statistics.
282 void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback);
283 StreamDataCountersCallback* GetRtpStatisticsCallback() const;
284
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000285 uint32_t BitrateSent() const;
286
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000287 void SetRtpState(const RtpState& rtp_state);
288 RtpState GetRtpState() const;
289 void SetRtxRtpState(const RtpState& rtp_state);
290 RtpState GetRtxRtpState() const;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700291 CVOMode ActivateCVORtpHeaderExtension() override;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000292
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000293 protected:
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000294 int32_t CheckPayloadType(int8_t payload_type, RtpVideoCodecTypes* video_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
pwestin@webrtc.orgc66e8b32012-11-07 17:01:04 +0000296 private:
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000297 // Maps capture time in milliseconds to send-side delay in milliseconds.
298 // Send-side delay is the difference between transmission time and capture
299 // time.
300 typedef std::map<int64_t, int> SendDelayMap;
301
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000302 size_t CreateRtpHeader(uint8_t* header,
303 int8_t payload_type,
304 uint32_t ssrc,
305 bool marker_bit,
306 uint32_t timestamp,
307 uint16_t sequence_number,
308 const std::vector<uint32_t>& csrcs) const;
stefan@webrtc.orga8179622013-06-04 13:47:36 +0000309
stefan@webrtc.org11d81762014-12-19 09:52:24 +0000310 void UpdateNACKBitRate(uint32_t bytes, int64_t now);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000311
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000312 bool PrepareAndSendPacket(uint8_t* buffer,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000313 size_t length,
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000314 int64_t capture_time_ms,
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000315 bool send_over_rtx,
316 bool is_retransmit);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000317
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000318 // Return the number of bytes sent. Note that both of these functions may
319 // return a larger value that their argument.
320 size_t TrySendRedundantPayloads(size_t bytes);
321 size_t TrySendPadData(size_t bytes);
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000322
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000323 size_t BuildPaddingPacket(uint8_t* packet, size_t header_length);
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000324
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000325 void BuildRtxPacket(uint8_t* buffer, size_t* length,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000326 uint8_t* buffer_rtx);
mikhal@webrtc.orgbda7f302013-03-15 23:21:52 +0000327
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000328 bool SendPacketToNetwork(const uint8_t *packet, size_t size);
pwestin@webrtc.orgb0061f92013-04-27 00:41:08 +0000329
stefan@webrtc.org0a3c1472013-12-05 14:05:07 +0000330 void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms);
331
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000332 // Find the byte position of the RTP extension as indicated by |type| in
333 // |rtp_packet|. Return false if such extension doesn't exist.
334 bool FindHeaderExtensionPosition(RTPExtensionType type,
335 const uint8_t* rtp_packet,
336 size_t rtp_packet_length,
337 const RTPHeader& rtp_header,
338 size_t* position) const;
339
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000340 void UpdateTransmissionTimeOffset(uint8_t* rtp_packet,
341 size_t rtp_packet_length,
342 const RTPHeader& rtp_header,
343 int64_t time_diff_ms) const;
344 void UpdateAbsoluteSendTime(uint8_t* rtp_packet,
345 size_t rtp_packet_length,
346 const RTPHeader& rtp_header,
347 int64_t now_ms) const;
stefan@webrtc.org420b2562014-05-30 12:17:15 +0000348
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000349 void UpdateRtpStats(const uint8_t* buffer,
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000350 size_t packet_length,
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000351 const RTPHeader& header,
352 bool is_rtx,
353 bool is_retransmit);
354 bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const;
355
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000356 Clock* clock_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000357 int64_t clock_delta_ms_;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000358
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000359 rtc::scoped_ptr<BitrateAggregator> bitrates_;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000360 Bitrate total_bitrate_sent_;
sprang@webrtc.org6811b6e2013-12-13 09:46:59 +0000361
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000362 int32_t id_;
pbos@webrtc.org7c4d20f2015-02-12 12:20:08 +0000363
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000364 const bool audio_configured_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000365 rtc::scoped_ptr<RTPSenderAudio> audio_;
366 rtc::scoped_ptr<RTPSenderVideo> video_;
phoglund@webrtc.orgbaaf2432012-05-31 10:47:35 +0000367
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000368 PacedSender *paced_sender_;
sprang@webrtc.orgdcebf2d2014-11-04 16:27:16 +0000369 int64_t last_capture_time_ms_sent_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000370 rtc::scoped_ptr<CriticalSectionWrapper> send_critsect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000371
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000372 Transport *transport_;
sprang@webrtc.org5a320fb2014-03-13 15:12:37 +0000373 bool sending_media_ GUARDED_BY(send_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000374
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000375 size_t max_payload_length_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000376 uint16_t packet_over_head_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
sprang@webrtc.orgefcad392014-03-25 16:51:35 +0000378 int8_t payload_type_ GUARDED_BY(send_critsect_);
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000379 std::map<int8_t, RtpUtility::Payload*> payload_type_map_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000381 RtpHeaderExtensionMap rtp_header_extension_map_;
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000382 int32_t transmission_time_offset_;
solenberg@webrtc.org7ebbea12013-05-16 11:10:31 +0000383 uint32_t absolute_send_time_;
guoweis@webrtc.org45362892015-03-04 22:55:15 +0000384 VideoRotation rotation_;
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700385 CVOMode cvo_mode_;
sprang@webrtc.org30933902015-03-17 14:33:12 +0000386 uint16_t transport_sequence_number_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000388 // NACK
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000389 uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE];
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000390 size_t nack_byte_count_[NACK_BYTECOUNT_SIZE];
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000391 Bitrate nack_bitrate_;
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000392
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000393 RTPPacketHistory packet_history_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000395 // Statistics
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000396 rtc::scoped_ptr<CriticalSectionWrapper> statistics_crit_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000397 SendDelayMap send_delays_ GUARDED_BY(statistics_crit_);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000398 FrameCounts frame_counts_ GUARDED_BY(statistics_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000399 StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_);
400 StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_);
401 StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_);
andresp@webrtc.org8f151212014-07-10 09:39:23 +0000402 FrameCountObserver* const frame_count_observer_;
stefan@webrtc.org168f23f2014-07-11 13:44:02 +0000403 SendSideDelayObserver* const send_side_delay_observer_;
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000404
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000405 // RTP variables
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000406 bool start_timestamp_forced_ GUARDED_BY(send_critsect_);
407 uint32_t start_timestamp_ GUARDED_BY(send_critsect_);
408 SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_);
409 uint32_t remote_ssrc_ GUARDED_BY(send_critsect_);
410 bool sequence_number_forced_ GUARDED_BY(send_critsect_);
411 uint16_t sequence_number_ GUARDED_BY(send_critsect_);
412 uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_);
413 bool ssrc_forced_ GUARDED_BY(send_critsect_);
414 uint32_t ssrc_ GUARDED_BY(send_critsect_);
415 uint32_t timestamp_ GUARDED_BY(send_critsect_);
416 int64_t capture_time_ms_ GUARDED_BY(send_critsect_);
417 int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_);
stefan@webrtc.org8b94e3d2014-07-17 16:10:14 +0000418 bool media_has_been_sent_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000419 bool last_packet_marker_bit_ GUARDED_BY(send_critsect_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000420 std::vector<uint32_t> csrcs_ GUARDED_BY(send_critsect_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000421 int rtx_ GUARDED_BY(send_critsect_);
422 uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_);
Shao Changbine62202f2015-04-21 20:24:50 +0800423 // TODO(changbin): Remove rtx_payload_type_ once interop with old clients that
424 // only understand one RTX PT is no longer needed.
425 int rtx_payload_type_ GUARDED_BY(send_critsect_);
426 // Mapping rtx_payload_type_map_[associated] = rtx.
427 std::map<int8_t, int8_t> rtx_payload_type_map_ GUARDED_BY(send_critsect_);
andresp@webrtc.orgd09d0742014-03-26 14:27:34 +0000428
429 // Note: Don't access this variable directly, always go through
430 // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember
431 // that by the time the function returns there is no guarantee
432 // that the target bitrate is still valid.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000433 rtc::scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_;
stefan@webrtc.orgaa0e56e2014-06-26 11:44:49 +0000434 uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000435};
niklase@google.com470e71d2011-07-07 08:21:25 +0000436
phoglund@webrtc.org43da54a2013-01-25 10:53:38 +0000437} // namespace webrtc
438
439#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_