niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 14 | #include <assert.h> |
| 15 | #include <math.h> |
| 16 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 17 | #include <map> |
| 18 | |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 19 | #include "webrtc/base/thread_annotations.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 20 | #include "webrtc/common_types.h" |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 21 | #include "webrtc/modules/pacing/include/paced_sender.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 22 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
phoglund@webrtc.org | c38eef8 | 2013-01-07 10:18:30 +0000 | [diff] [blame] | 23 | #include "webrtc/modules/rtp_rtcp/source/bitrate.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 24 | #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 25 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 26 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 30 | #define MAX_INIT_RTP_SEQ_NUMBER 32767 // 2^15 -1. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 33 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 34 | class BitrateAggregator; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | class CriticalSectionWrapper; |
| 36 | class RTPSenderAudio; |
| 37 | class RTPSenderVideo; |
| 38 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 39 | class RTPSenderInterface { |
| 40 | public: |
| 41 | RTPSenderInterface() {} |
| 42 | virtual ~RTPSenderInterface() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 44 | virtual uint32_t SSRC() const = 0; |
| 45 | virtual uint32_t Timestamp() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 47 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 55 | virtual uint16_t RTPHeaderLength() const = 0; |
| 56 | virtual uint16_t IncrementSequenceNumber() = 0; |
| 57 | virtual uint16_t SequenceNumber() const = 0; |
| 58 | virtual uint16_t MaxPayloadLength() const = 0; |
| 59 | virtual uint16_t MaxDataPayloadLength() const = 0; |
| 60 | virtual uint16_t PacketOverHead() const = 0; |
| 61 | virtual uint16_t ActualSendBitrateKbit() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 63 | virtual int32_t SendToNetwork( |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 64 | uint8_t *data_buffer, int payload_length, int rtp_header_length, |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 65 | int64_t capture_time_ms, StorageType storage, |
| 66 | PacedSender::Priority priority) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 69 | class RTPSender : public RTPSenderInterface { |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 70 | public: |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 71 | RTPSender(const int32_t id, const bool audio, Clock *clock, |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 72 | Transport *transport, RtpAudioFeedback *audio_feedback, |
andresp@webrtc.org | d11bec4 | 2014-07-08 14:32:58 +0000 | [diff] [blame] | 73 | PacedSender *paced_sender, |
andresp@webrtc.org | 8f15121 | 2014-07-10 09:39:23 +0000 | [diff] [blame] | 74 | BitrateStatisticsObserver* bitrate_callback, |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 75 | FrameCountObserver* frame_count_observer, |
| 76 | SendSideDelayObserver* send_side_delay_observer); |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 77 | virtual ~RTPSender(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 79 | void ProcessBitrate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 81 | virtual uint16_t ActualSendBitrateKbit() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 83 | uint32_t VideoBitrateSent() const; |
| 84 | uint32_t FecOverheadRate() const; |
| 85 | uint32_t NackOverheadRate() const; |
stefan@webrtc.org | d0bdab0 | 2011-10-14 14:24:54 +0000 | [diff] [blame] | 86 | |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 87 | // 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.org | a15fbfd | 2014-06-17 17:32:05 +0000 | [diff] [blame] | 91 | void SetTargetBitrate(uint32_t bitrate); |
| 92 | uint32_t GetTargetBitrate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 94 | virtual uint16_t MaxDataPayloadLength() const |
| 95 | OVERRIDE; // with RTP and FEC headers. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 97 | int32_t RegisterPayload( |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 98 | const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 99 | const int8_t payload_type, const uint32_t frequency, |
| 100 | const uint8_t channels, const uint32_t rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 102 | int32_t DeRegisterSendPayload(const int8_t payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
andresp@webrtc.org | c3c2911 | 2014-08-27 09:39:43 +0000 | [diff] [blame] | 104 | void SetSendPayloadType(int8_t payload_type); |
| 105 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 106 | int8_t SendPayloadType() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 108 | int SendPayloadFrequency() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
pbos@webrtc.org | 59f20bb | 2013-09-09 16:02:19 +0000 | [diff] [blame] | 110 | void SetSendingStatus(bool enabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 112 | void SetSendingMediaStatus(const bool enabled); |
| 113 | bool SendingMedia() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 115 | void GetDataCounters(StreamDataCounters* rtp_stats, |
| 116 | StreamDataCounters* rtx_stats) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 118 | void ResetDataCounters(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 120 | uint32_t StartTimestamp() const; |
| 121 | void SetStartTimestamp(uint32_t timestamp, bool force); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 123 | uint32_t GenerateNewSSRC(); |
| 124 | void SetSSRC(const uint32_t ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 126 | virtual uint16_t SequenceNumber() const OVERRIDE; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 127 | void SetSequenceNumber(uint16_t seq); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 129 | int32_t CSRCs(uint32_t arr_of_csrc[kRtpCsrcSize]) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 131 | void SetCSRCStatus(const bool include); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 132 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 133 | void SetCSRCs(const uint32_t arr_of_csrc[kRtpCsrcSize], |
| 134 | const uint8_t arr_length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 136 | int32_t SetMaxPayloadLength(const uint16_t length, |
| 137 | const uint16_t packet_over_head); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 139 | int32_t SendOutgoingData(const FrameType frame_type, |
| 140 | const int8_t payload_type, |
| 141 | const uint32_t timestamp, |
| 142 | int64_t capture_time_ms, |
| 143 | const uint8_t* payload_data, |
| 144 | const uint32_t payload_size, |
| 145 | const RTPFragmentationHeader* fragmentation, |
| 146 | VideoCodecInformation* codec_info = NULL, |
| 147 | const RTPVideoTypeHeader* rtp_type_hdr = NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 149 | // RTP header extension |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 150 | int32_t SetTransmissionTimeOffset( |
| 151 | const int32_t transmission_time_offset); |
solenberg@webrtc.org | 7ebbea1 | 2013-05-16 11:10:31 +0000 | [diff] [blame] | 152 | int32_t SetAbsoluteSendTime( |
| 153 | const uint32_t absolute_send_time); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 155 | int32_t RegisterRtpHeaderExtension(const RTPExtensionType type, |
| 156 | const uint8_t id); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 157 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 158 | int32_t DeregisterRtpHeaderExtension(const RTPExtensionType type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 159 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 160 | uint16_t RtpHeaderExtensionTotalLength() const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 161 | |
stefan@webrtc.org | a817962 | 2013-06-04 13:47:36 +0000 | [diff] [blame] | 162 | uint16_t BuildRTPHeaderExtension(uint8_t* data_buffer) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 163 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 164 | uint8_t BuildTransmissionTimeOffsetExtension(uint8_t *data_buffer) const; |
| 165 | uint8_t BuildAudioLevelExtension(uint8_t* data_buffer) const; |
| 166 | uint8_t BuildAbsoluteSendTimeExtension(uint8_t* data_buffer) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 167 | |
wu@webrtc.org | ebdb0e3 | 2014-03-06 23:49:08 +0000 | [diff] [blame] | 168 | bool UpdateAudioLevel(uint8_t *rtp_packet, |
| 169 | const uint16_t rtp_packet_length, |
| 170 | const RTPHeader &rtp_header, |
| 171 | const bool is_voiced, |
| 172 | const uint8_t dBov) const; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 173 | |
stefan@webrtc.org | 9b82f5a | 2013-11-13 15:29:21 +0000 | [diff] [blame] | 174 | bool TimeToSendPacket(uint16_t sequence_number, int64_t capture_time_ms, |
| 175 | bool retransmission); |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 176 | int TimeToSendPadding(int bytes); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 177 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 178 | // NACK. |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 179 | int SelectiveRetransmissions() const; |
| 180 | int SetSelectiveRetransmissions(uint8_t settings); |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 181 | void OnReceivedNACK(const std::list<uint16_t>& nack_sequence_numbers, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 182 | const uint16_t avg_rtt); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 183 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 184 | void SetStorePacketsStatus(const bool enable, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 185 | const uint16_t number_to_store); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 187 | bool StorePackets() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 189 | int32_t ReSendPacket(uint16_t packet_id, uint32_t min_resend_time = 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 191 | bool ProcessNACKBitRate(const uint32_t now); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 193 | // RTX. |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 194 | void SetRTXStatus(int mode); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 195 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 196 | void RTXStatus(int* mode, uint32_t* ssrc, int* payload_type) const; |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 +0000 | [diff] [blame] | 197 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 198 | uint32_t RtxSsrc() const; |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 199 | void SetRtxSsrc(uint32_t ssrc); |
| 200 | |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 +0000 | [diff] [blame] | 201 | void SetRtxPayloadType(int payloadType); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 202 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 203 | // Functions wrapping RTPSenderInterface. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 204 | virtual int32_t BuildRTPheader( |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 205 | uint8_t* data_buffer, |
| 206 | const int8_t payload_type, |
| 207 | const bool marker_bit, |
| 208 | const uint32_t capture_timestamp, |
stefan@webrtc.org | 8ccb9f9 | 2013-06-19 14:13:42 +0000 | [diff] [blame] | 209 | int64_t capture_time_ms, |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 210 | const bool timestamp_provided = true, |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 211 | const bool inc_sequence_number = true) OVERRIDE; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 212 | |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 213 | virtual uint16_t RTPHeaderLength() const OVERRIDE; |
| 214 | virtual uint16_t IncrementSequenceNumber() OVERRIDE; |
| 215 | virtual uint16_t MaxPayloadLength() const OVERRIDE; |
| 216 | virtual uint16_t PacketOverHead() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 218 | // Current timestamp. |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 219 | virtual uint32_t Timestamp() const OVERRIDE; |
| 220 | virtual uint32_t SSRC() const OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 222 | virtual int32_t SendToNetwork( |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 223 | uint8_t *data_buffer, int payload_length, int rtp_header_length, |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 224 | int64_t capture_time_ms, StorageType storage, |
pbos@webrtc.org | f3e4cee | 2013-07-31 15:17:19 +0000 | [diff] [blame] | 225 | PacedSender::Priority priority) OVERRIDE; |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 226 | |
| 227 | // Audio. |
| 228 | |
| 229 | // Send a DTMF tone using RFC 2833 (4733). |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 230 | int32_t SendTelephoneEvent(const uint8_t key, |
| 231 | const uint16_t time_ms, |
| 232 | const uint8_t level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 233 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 234 | bool SendTelephoneEventActive(int8_t *telephone_event) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 236 | // Set audio packet size, used to determine when it's time to send a DTMF |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 237 | // packet in silence (CNG). |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 238 | int32_t SetAudioPacketSize(const uint16_t packet_size_samples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 240 | // Store the audio level in d_bov for |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 241 | // header-extension-for-audio-level-indication. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 242 | int32_t SetAudioLevel(const uint8_t level_d_bov); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 243 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 244 | // Set payload type for Redundant Audio Data RFC 2198. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 245 | int32_t SetRED(const int8_t payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 246 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 247 | // Get payload type for Redundant Audio Data RFC 2198. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 248 | int32_t RED(int8_t *payload_type) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 249 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 250 | // Video. |
| 251 | VideoCodecInformation *CodecInformationVideo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 253 | RtpVideoCodecTypes VideoCodecType() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 255 | uint32_t MaxConfiguredBitrateVideo() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 256 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 257 | int32_t SendRTPIntraRequest(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 259 | // FEC. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 260 | int32_t SetGenericFECStatus(const bool enable, |
| 261 | const uint8_t payload_type_red, |
| 262 | const uint8_t payload_type_fec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 263 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 264 | int32_t GenericFECStatus(bool *enable, uint8_t *payload_type_red, |
| 265 | uint8_t *payload_type_fec) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 266 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 267 | int32_t SetFecParameters(const FecProtectionParams *delta_params, |
| 268 | const FecProtectionParams *key_params); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 269 | |
andresp@webrtc.org | 817a034 | 2014-08-14 08:24:47 +0000 | [diff] [blame] | 270 | int SendPadData(uint32_t timestamp, |
pbos@webrtc.org | 72491b9 | 2014-07-10 16:24:54 +0000 | [diff] [blame] | 271 | int64_t capture_time_ms, |
pbos@webrtc.org | 63c60ed | 2014-07-16 09:37:29 +0000 | [diff] [blame] | 272 | int32_t bytes); |
stefan@webrtc.org | c4726d0 | 2013-12-05 09:16:33 +0000 | [diff] [blame] | 273 | |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 274 | // Called on update of RTP statistics. |
| 275 | void RegisterRtpStatisticsCallback(StreamDataCountersCallback* callback); |
| 276 | StreamDataCountersCallback* GetRtpStatisticsCallback() const; |
| 277 | |
sprang@webrtc.org | 6811b6e | 2013-12-13 09:46:59 +0000 | [diff] [blame] | 278 | uint32_t BitrateSent() const; |
| 279 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 280 | void SetRtpState(const RtpState& rtp_state); |
| 281 | RtpState GetRtpState() const; |
| 282 | void SetRtxRtpState(const RtpState& rtp_state); |
| 283 | RtpState GetRtxRtpState() const; |
| 284 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 285 | protected: |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 286 | int32_t CheckPayloadType(const int8_t payload_type, |
| 287 | RtpVideoCodecTypes *video_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 288 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame] | 289 | private: |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 290 | // Maps capture time in milliseconds to send-side delay in milliseconds. |
| 291 | // Send-side delay is the difference between transmission time and capture |
| 292 | // time. |
| 293 | typedef std::map<int64_t, int> SendDelayMap; |
| 294 | |
stefan@webrtc.org | a817962 | 2013-06-04 13:47:36 +0000 | [diff] [blame] | 295 | int CreateRTPHeader(uint8_t* header, int8_t payload_type, |
| 296 | uint32_t ssrc, bool marker_bit, |
| 297 | uint32_t timestamp, uint16_t sequence_number, |
| 298 | const uint32_t* csrcs, uint8_t csrcs_length) const; |
| 299 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 300 | void UpdateNACKBitRate(const uint32_t bytes, const uint32_t now); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 301 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 302 | bool PrepareAndSendPacket(uint8_t* buffer, |
| 303 | uint16_t length, |
| 304 | int64_t capture_time_ms, |
stefan@webrtc.org | 7c6ff2d | 2014-03-19 18:14:52 +0000 | [diff] [blame] | 305 | bool send_over_rtx, |
| 306 | bool is_retransmit); |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 307 | |
andresp@webrtc.org | 817a034 | 2014-08-14 08:24:47 +0000 | [diff] [blame] | 308 | // Return the number of bytes sent. |
| 309 | int TrySendRedundantPayloads(int bytes); |
| 310 | int TrySendPadData(int bytes); |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 311 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 312 | int BuildPaddingPacket(uint8_t* packet, int header_length, int32_t bytes); |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 313 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 314 | void BuildRtxPacket(uint8_t* buffer, uint16_t* length, |
| 315 | uint8_t* buffer_rtx); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 316 | |
pwestin@webrtc.org | b0061f9 | 2013-04-27 00:41:08 +0000 | [diff] [blame] | 317 | bool SendPacketToNetwork(const uint8_t *packet, uint32_t size); |
| 318 | |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 319 | void UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms); |
| 320 | |
stefan@webrtc.org | 420b256 | 2014-05-30 12:17:15 +0000 | [diff] [blame] | 321 | void UpdateTransmissionTimeOffset(uint8_t *rtp_packet, |
| 322 | const uint16_t rtp_packet_length, |
| 323 | const RTPHeader &rtp_header, |
| 324 | const int64_t time_diff_ms) const; |
| 325 | void UpdateAbsoluteSendTime(uint8_t *rtp_packet, |
| 326 | const uint16_t rtp_packet_length, |
| 327 | const RTPHeader &rtp_header, |
| 328 | const int64_t now_ms) const; |
| 329 | |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 330 | void UpdateRtpStats(const uint8_t* buffer, |
| 331 | uint32_t size, |
| 332 | const RTPHeader& header, |
| 333 | bool is_rtx, |
| 334 | bool is_retransmit); |
| 335 | bool IsFecPacket(const uint8_t* buffer, const RTPHeader& header) const; |
| 336 | |
sprang@webrtc.org | 6811b6e | 2013-12-13 09:46:59 +0000 | [diff] [blame] | 337 | Clock* clock_; |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 338 | int64_t clock_delta_ms_; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame^] | 339 | |
| 340 | scoped_ptr<BitrateAggregator> bitrates_; |
| 341 | Bitrate total_bitrate_sent_; |
sprang@webrtc.org | 6811b6e | 2013-12-13 09:46:59 +0000 | [diff] [blame] | 342 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 343 | int32_t id_; |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 344 | const bool audio_configured_; |
| 345 | RTPSenderAudio *audio_; |
| 346 | RTPSenderVideo *video_; |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 347 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 348 | PacedSender *paced_sender_; |
sprang@webrtc.org | dcebf2d | 2014-11-04 16:27:16 +0000 | [diff] [blame] | 349 | int64_t last_capture_time_ms_sent_; |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 350 | CriticalSectionWrapper *send_critsect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 351 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 352 | Transport *transport_; |
sprang@webrtc.org | 5a320fb | 2014-03-13 15:12:37 +0000 | [diff] [blame] | 353 | bool sending_media_ GUARDED_BY(send_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 355 | uint16_t max_payload_length_; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 356 | uint16_t packet_over_head_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 357 | |
sprang@webrtc.org | efcad39 | 2014-03-25 16:51:35 +0000 | [diff] [blame] | 358 | int8_t payload_type_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 359 | std::map<int8_t, RtpUtility::Payload*> payload_type_map_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 360 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 361 | RtpHeaderExtensionMap rtp_header_extension_map_; |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 362 | int32_t transmission_time_offset_; |
solenberg@webrtc.org | 7ebbea1 | 2013-05-16 11:10:31 +0000 | [diff] [blame] | 363 | uint32_t absolute_send_time_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 364 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 365 | // NACK |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 366 | uint32_t nack_byte_count_times_[NACK_BYTECOUNT_SIZE]; |
| 367 | int32_t nack_byte_count_[NACK_BYTECOUNT_SIZE]; |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 368 | Bitrate nack_bitrate_; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 369 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 370 | RTPPacketHistory packet_history_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 372 | // Statistics |
pbos@webrtc.org | e07049f | 2013-09-10 11:29:17 +0000 | [diff] [blame] | 373 | scoped_ptr<CriticalSectionWrapper> statistics_crit_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 374 | SendDelayMap send_delays_ GUARDED_BY(statistics_crit_); |
| 375 | std::map<FrameType, uint32_t> frame_counts_ GUARDED_BY(statistics_crit_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 376 | StreamDataCounters rtp_stats_ GUARDED_BY(statistics_crit_); |
| 377 | StreamDataCounters rtx_rtp_stats_ GUARDED_BY(statistics_crit_); |
| 378 | StreamDataCountersCallback* rtp_stats_callback_ GUARDED_BY(statistics_crit_); |
andresp@webrtc.org | 8f15121 | 2014-07-10 09:39:23 +0000 | [diff] [blame] | 379 | FrameCountObserver* const frame_count_observer_; |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 380 | SendSideDelayObserver* const send_side_delay_observer_; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 381 | |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 382 | // RTP variables |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 383 | bool start_timestamp_forced_ GUARDED_BY(send_critsect_); |
| 384 | uint32_t start_timestamp_ GUARDED_BY(send_critsect_); |
| 385 | SSRCDatabase& ssrc_db_ GUARDED_BY(send_critsect_); |
| 386 | uint32_t remote_ssrc_ GUARDED_BY(send_critsect_); |
| 387 | bool sequence_number_forced_ GUARDED_BY(send_critsect_); |
| 388 | uint16_t sequence_number_ GUARDED_BY(send_critsect_); |
| 389 | uint16_t sequence_number_rtx_ GUARDED_BY(send_critsect_); |
| 390 | bool ssrc_forced_ GUARDED_BY(send_critsect_); |
| 391 | uint32_t ssrc_ GUARDED_BY(send_critsect_); |
| 392 | uint32_t timestamp_ GUARDED_BY(send_critsect_); |
| 393 | int64_t capture_time_ms_ GUARDED_BY(send_critsect_); |
| 394 | int64_t last_timestamp_time_ms_ GUARDED_BY(send_critsect_); |
stefan@webrtc.org | 8b94e3d | 2014-07-17 16:10:14 +0000 | [diff] [blame] | 395 | bool media_has_been_sent_ GUARDED_BY(send_critsect_); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 396 | bool last_packet_marker_bit_ GUARDED_BY(send_critsect_); |
| 397 | uint8_t num_csrcs_ GUARDED_BY(send_critsect_); |
| 398 | uint32_t csrcs_[kRtpCsrcSize] GUARDED_BY(send_critsect_); |
| 399 | bool include_csrcs_ GUARDED_BY(send_critsect_); |
| 400 | int rtx_ GUARDED_BY(send_critsect_); |
| 401 | uint32_t ssrc_rtx_ GUARDED_BY(send_critsect_); |
| 402 | int payload_type_rtx_ GUARDED_BY(send_critsect_); |
andresp@webrtc.org | d09d074 | 2014-03-26 14:27:34 +0000 | [diff] [blame] | 403 | |
| 404 | // Note: Don't access this variable directly, always go through |
| 405 | // SetTargetBitrateKbps or GetTargetBitrateKbps. Also remember |
| 406 | // that by the time the function returns there is no guarantee |
| 407 | // that the target bitrate is still valid. |
| 408 | scoped_ptr<CriticalSectionWrapper> target_bitrate_critsect_; |
stefan@webrtc.org | aa0e56e | 2014-06-26 11:44:49 +0000 | [diff] [blame] | 409 | uint32_t target_bitrate_ GUARDED_BY(target_bitrate_critsect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 410 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 411 | |
phoglund@webrtc.org | 43da54a | 2013-01-25 10:53:38 +0000 | [diff] [blame] | 412 | } // namespace webrtc |
| 413 | |
| 414 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |