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 | #include <cstdlib> // srand |
| 12 | |
| 13 | #include "rtp_sender.h" |
| 14 | |
| 15 | #include "critical_section_wrapper.h" |
| 16 | #include "trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 18 | #include "rtp_packet_history.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | #include "rtp_sender_audio.h" |
| 20 | #include "rtp_sender_video.h" |
| 21 | |
| 22 | namespace webrtc { |
pwestin@webrtc.org | 0644b1d | 2011-12-01 15:42:31 +0000 | [diff] [blame] | 23 | RTPSender::RTPSender(const WebRtc_Word32 id, |
| 24 | const bool audio, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 25 | RtpRtcpClock* clock, |
| 26 | Transport* transport, |
| 27 | RtpAudioFeedback* audio_feedback) |
| 28 | : Bitrate(clock), |
| 29 | _id(id), |
| 30 | _audioConfigured(audio), |
| 31 | _audio(NULL), |
| 32 | _video(NULL), |
| 33 | _sendCritsect(CriticalSectionWrapper::CreateCriticalSection()), |
| 34 | _transport(transport), |
| 35 | _sendingMedia(true), // Default to sending media |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 37 | _maxPayloadLength(IP_PACKET_SIZE-28), // default is IP-v4/UDP |
| 38 | _targetSendBitrate(0), |
| 39 | _packetOverHead(28), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 41 | _payloadType(-1), |
| 42 | _payloadTypeMap(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 44 | _rtpHeaderExtensionMap(), |
| 45 | _transmissionTimeOffset(0), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 47 | _nackByteCountTimes(), |
| 48 | _nackByteCount(), |
| 49 | _nackBitrate(clock), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 51 | _packetHistory(new RTPPacketHistory(clock)), |
| 52 | _sendBucket(clock), |
| 53 | _timeLastSendToNetworkUpdate(clock->GetTimeInMS()), |
| 54 | _transmissionSmoothing(false), |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 55 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 56 | _packetsSent(0), |
| 57 | _payloadBytesSent(0), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 59 | _startTimeStampForced(false), |
| 60 | _startTimeStamp(0), |
| 61 | _ssrcDB(*SSRCDatabase::GetSSRCDatabase()), |
| 62 | _remoteSSRC(0), |
| 63 | _sequenceNumberForced(false), |
| 64 | _sequenceNumber(0), |
| 65 | _sequenceNumberRTX(0), |
| 66 | _ssrcForced(false), |
| 67 | _ssrc(0), |
| 68 | _timeStamp(0), |
| 69 | _CSRCs(0), |
| 70 | _CSRC(), |
| 71 | _includeCSRCs(true), |
| 72 | _RTX(false), |
| 73 | _ssrcRTX(0) { |
| 74 | memset(_nackByteCountTimes, 0, sizeof(_nackByteCountTimes)); |
| 75 | memset(_nackByteCount, 0, sizeof(_nackByteCount)); |
| 76 | memset(_CSRC, 0, sizeof(_CSRC)); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 77 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 78 | // We need to seed the random generator. |
| 79 | srand( (WebRtc_UWord32)_clock.GetTimeInMS() ); |
| 80 | _ssrc = _ssrcDB.CreateSSRC(); // Can't be 0. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 82 | if (audio) { |
| 83 | _audio = new RTPSenderAudio(id, &_clock, this); |
| 84 | _audio->RegisterAudioCallback(audio_feedback); |
| 85 | } else { |
| 86 | _video = new RTPSenderVideo(id, &_clock, this); |
| 87 | } |
| 88 | WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 91 | RTPSender::~RTPSender() { |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 92 | if (_remoteSSRC != 0) { |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 93 | _ssrcDB.ReturnSSRC(_remoteSSRC); |
| 94 | } |
| 95 | _ssrcDB.ReturnSSRC(_ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 97 | SSRCDatabase::ReturnSSRCDatabase(); |
| 98 | delete _sendCritsect; |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 99 | while (!_payloadTypeMap.empty()) { |
| 100 | std::map<WebRtc_Word8, ModuleRTPUtility::Payload*>::iterator it = |
| 101 | _payloadTypeMap.begin(); |
| 102 | delete it->second; |
| 103 | _payloadTypeMap.erase(it); |
| 104 | } |
| 105 | delete _packetHistory; |
| 106 | delete _audio; |
| 107 | delete _video; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 108 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 109 | WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, _id, "%s deleted", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 112 | void RTPSender::SetTargetSendBitrate(const WebRtc_UWord32 bits) { |
| 113 | _targetSendBitrate = static_cast<uint16_t>(bits / 1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | } |
stefan@webrtc.org | d0bdab0 | 2011-10-14 14:24:54 +0000 | [diff] [blame] | 115 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 116 | WebRtc_UWord16 RTPSender::ActualSendBitrateKbit() const { |
| 117 | return (WebRtc_UWord16) (Bitrate::BitrateNow() / 1000); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | } |
| 119 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 120 | WebRtc_UWord32 RTPSender::VideoBitrateSent() const { |
| 121 | if (_video) { |
stefan@webrtc.org | fbea4e5 | 2011-10-27 16:08:29 +0000 | [diff] [blame] | 122 | return _video->VideoBitrateSent(); |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 123 | } |
| 124 | return 0; |
stefan@webrtc.org | fbea4e5 | 2011-10-27 16:08:29 +0000 | [diff] [blame] | 125 | } |
| 126 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 127 | WebRtc_UWord32 RTPSender::FecOverheadRate() const { |
| 128 | if (_video) { |
stefan@webrtc.org | fbea4e5 | 2011-10-27 16:08:29 +0000 | [diff] [blame] | 129 | return _video->FecOverheadRate(); |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 130 | } |
| 131 | return 0; |
stefan@webrtc.org | d0bdab0 | 2011-10-14 14:24:54 +0000 | [diff] [blame] | 132 | } |
| 133 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 134 | WebRtc_UWord32 RTPSender::NackOverheadRate() const { |
stefan@webrtc.org | d0bdab0 | 2011-10-14 14:24:54 +0000 | [diff] [blame] | 135 | return _nackBitrate.BitrateLast(); |
| 136 | } |
| 137 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 138 | WebRtc_Word32 RTPSender::SetTransmissionTimeOffset( |
| 139 | const WebRtc_Word32 transmissionTimeOffset) { |
| 140 | if (transmissionTimeOffset > (0x800000 - 1) || |
| 141 | transmissionTimeOffset < -(0x800000 - 1)) { // Word24 |
| 142 | return -1; |
| 143 | } |
| 144 | CriticalSectionScoped cs(_sendCritsect); |
| 145 | _transmissionTimeOffset = transmissionTimeOffset; |
| 146 | return 0; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 147 | } |
| 148 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 149 | WebRtc_Word32 RTPSender::RegisterRtpHeaderExtension(const RTPExtensionType type, |
| 150 | const WebRtc_UWord8 id) { |
| 151 | CriticalSectionScoped cs(_sendCritsect); |
| 152 | return _rtpHeaderExtensionMap.Register(type, id); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 153 | } |
| 154 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 155 | WebRtc_Word32 RTPSender::DeregisterRtpHeaderExtension( |
| 156 | const RTPExtensionType type) { |
| 157 | CriticalSectionScoped cs(_sendCritsect); |
| 158 | return _rtpHeaderExtensionMap.Deregister(type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 159 | } |
| 160 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 161 | WebRtc_UWord16 RTPSender::RtpHeaderExtensionTotalLength() const { |
| 162 | CriticalSectionScoped cs(_sendCritsect); |
| 163 | return _rtpHeaderExtensionMap.GetTotalLengthInBytes(); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 164 | } |
| 165 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 166 | WebRtc_Word32 RTPSender::RegisterPayload( |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 167 | const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 168 | const WebRtc_Word8 payloadNumber, |
| 169 | const WebRtc_UWord32 frequency, |
| 170 | const WebRtc_UWord8 channels, |
| 171 | const WebRtc_UWord32 rate) { |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 172 | assert(payloadName); |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 173 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 175 | std::map<WebRtc_Word8, ModuleRTPUtility::Payload*>::iterator it = |
| 176 | _payloadTypeMap.find(payloadNumber); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 178 | if (_payloadTypeMap.end() != it) { |
| 179 | // we already use this payload type |
| 180 | ModuleRTPUtility::Payload* payload = it->second; |
| 181 | assert(payload); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 183 | // check if it's the same as we already have |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 184 | if (ModuleRTPUtility::StringCompare(payload->name, payloadName, |
| 185 | RTP_PAYLOAD_NAME_SIZE - 1)) { |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 186 | if (_audioConfigured && payload->audio && |
| 187 | payload->typeSpecific.Audio.frequency == frequency && |
| 188 | (payload->typeSpecific.Audio.rate == rate || |
| 189 | payload->typeSpecific.Audio.rate == 0 || rate == 0)) { |
| 190 | payload->typeSpecific.Audio.rate = rate; |
| 191 | // Ensure that we update the rate if new or old is zero |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | return 0; |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 193 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 194 | if (!_audioConfigured && !payload->audio) { |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | } |
| 198 | return -1; |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 199 | } |
| 200 | WebRtc_Word32 retVal = -1; |
| 201 | ModuleRTPUtility::Payload* payload = NULL; |
| 202 | if (_audioConfigured) { |
| 203 | retVal = _audio->RegisterAudioPayload(payloadName, payloadNumber, frequency, |
| 204 | channels, rate, payload); |
| 205 | } else { |
| 206 | retVal = _video->RegisterVideoPayload(payloadName, payloadNumber, rate, |
| 207 | payload); |
| 208 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 209 | if (payload) { |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 210 | _payloadTypeMap[payloadNumber] = payload; |
| 211 | } |
| 212 | return retVal; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | } |
| 214 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 215 | WebRtc_Word32 RTPSender::DeRegisterSendPayload(const WebRtc_Word8 payloadType) { |
| 216 | CriticalSectionScoped lock(_sendCritsect); |
| 217 | |
| 218 | std::map<WebRtc_Word8, ModuleRTPUtility::Payload*>::iterator it = |
| 219 | _payloadTypeMap.find(payloadType); |
| 220 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 221 | if (_payloadTypeMap.end() == it) { |
| 222 | return -1; |
| 223 | } |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 224 | ModuleRTPUtility::Payload* payload = it->second; |
| 225 | delete payload; |
| 226 | _payloadTypeMap.erase(it); |
| 227 | return 0; |
| 228 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 230 | WebRtc_Word8 RTPSender::SendPayloadType() const { |
| 231 | return _payloadType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 234 | int RTPSender::SendPayloadFrequency() const { |
| 235 | return _audio->AudioFrequency(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | } |
| 237 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 238 | WebRtc_Word32 RTPSender::SetMaxPayloadLength( |
| 239 | const WebRtc_UWord16 maxPayloadLength, |
| 240 | const WebRtc_UWord16 packetOverHead) { |
| 241 | // sanity check |
| 242 | if (maxPayloadLength < 100 || maxPayloadLength > IP_PACKET_SIZE) { |
| 243 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 244 | "%s invalid argument", __FUNCTION__); |
| 245 | return -1; |
| 246 | } |
| 247 | CriticalSectionScoped cs(_sendCritsect); |
| 248 | _maxPayloadLength = maxPayloadLength; |
| 249 | _packetOverHead = packetOverHead; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 251 | WEBRTC_TRACE(kTraceInfo, kTraceRtpRtcp, _id, |
| 252 | "SetMaxPayloadLength to %d.", maxPayloadLength); |
| 253 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | } |
| 255 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 256 | WebRtc_UWord16 RTPSender::MaxDataPayloadLength() const { |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 257 | if (_audioConfigured) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 258 | return _maxPayloadLength - RTPHeaderLength(); |
| 259 | } else { |
| 260 | return _maxPayloadLength - RTPHeaderLength() - |
| 261 | _video->FECPacketOverhead() - ((_RTX) ? 2 : 0); |
| 262 | // Include the FEC/ULP/RED overhead. |
| 263 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | } |
| 265 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 266 | WebRtc_UWord16 RTPSender::MaxPayloadLength() const { |
| 267 | return _maxPayloadLength; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 268 | } |
| 269 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 270 | WebRtc_UWord16 RTPSender::PacketOverHead() const { |
| 271 | return _packetOverHead; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 272 | } |
| 273 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 274 | void RTPSender::SetTransmissionSmoothingStatus(const bool enable) { |
| 275 | CriticalSectionScoped cs(_sendCritsect); |
| 276 | _transmissionSmoothing = enable; |
| 277 | } |
| 278 | |
| 279 | bool RTPSender::TransmissionSmoothingStatus() const { |
| 280 | CriticalSectionScoped cs(_sendCritsect); |
| 281 | return _transmissionSmoothing; |
| 282 | } |
| 283 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 284 | void RTPSender::SetRTXStatus(const bool enable, |
| 285 | const bool setSSRC, |
| 286 | const WebRtc_UWord32 SSRC) { |
| 287 | CriticalSectionScoped cs(_sendCritsect); |
| 288 | _RTX = enable; |
| 289 | if (enable) { |
| 290 | if (setSSRC) { |
| 291 | _ssrcRTX = SSRC; |
| 292 | } else { |
| 293 | _ssrcRTX = _ssrcDB.CreateSSRC(); // can't be 0 |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 298 | void RTPSender::RTXStatus(bool* enable, WebRtc_UWord32* SSRC) const { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 299 | CriticalSectionScoped cs(_sendCritsect); |
| 300 | *enable = _RTX; |
| 301 | *SSRC = _ssrcRTX; |
| 302 | } |
| 303 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 304 | WebRtc_Word32 RTPSender::CheckPayloadType(const WebRtc_Word8 payloadType, |
| 305 | RtpVideoCodecTypes& videoType) { |
| 306 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 307 | |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 308 | if (payloadType < 0) { |
| 309 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 310 | "\tinvalid payloadType (%d)", payloadType); |
| 311 | return -1; |
| 312 | } |
| 313 | if (_audioConfigured) { |
| 314 | WebRtc_Word8 redPlType = -1; |
| 315 | if (_audio->RED(redPlType) == 0) { |
| 316 | // We have configured RED. |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 317 | if (redPlType == payloadType) { |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 318 | // And it's a match... |
| 319 | return 0; |
| 320 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | } |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 322 | } |
| 323 | if (_payloadType == payloadType) { |
| 324 | if (!_audioConfigured) { |
| 325 | videoType = _video->VideoCodecType(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 326 | } |
| 327 | return 0; |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 328 | } |
| 329 | std::map<WebRtc_Word8, ModuleRTPUtility::Payload*>::iterator it = |
| 330 | _payloadTypeMap.find(payloadType); |
| 331 | if (it == _payloadTypeMap.end()) { |
| 332 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 333 | "\tpayloadType:%d not registered", payloadType); |
| 334 | return -1; |
| 335 | } |
| 336 | _payloadType = payloadType; |
| 337 | ModuleRTPUtility::Payload* payload = it->second; |
| 338 | assert(payload); |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 339 | if (!payload->audio && !_audioConfigured) { |
| 340 | _video->SetVideoCodecType(payload->typeSpecific.Video.videoCodecType); |
| 341 | videoType = payload->typeSpecific.Video.videoCodecType; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 342 | _video->SetMaxConfiguredBitrateVideo(payload->typeSpecific.Video.maxRate); |
pwestin@webrtc.org | 0074187 | 2012-01-19 15:56:10 +0000 | [diff] [blame] | 343 | } |
| 344 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | } |
| 346 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 347 | WebRtc_Word32 RTPSender::SendOutgoingData( |
| 348 | const FrameType frame_type, |
| 349 | const WebRtc_Word8 payload_type, |
| 350 | const WebRtc_UWord32 capture_timestamp, |
| 351 | int64_t capture_time_ms, |
| 352 | const WebRtc_UWord8* payload_data, |
| 353 | const WebRtc_UWord32 payload_size, |
| 354 | const RTPFragmentationHeader* fragmentation, |
| 355 | VideoCodecInformation* codec_info, |
| 356 | const RTPVideoTypeHeader* rtp_type_hdr) { |
| 357 | { |
| 358 | // Drop this packet if we're not sending media packets. |
| 359 | CriticalSectionScoped cs(_sendCritsect); |
| 360 | if (!_sendingMedia) { |
| 361 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 362 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 363 | } |
| 364 | RtpVideoCodecTypes video_type = kRtpNoVideo; |
| 365 | if (CheckPayloadType(payload_type, video_type) != 0) { |
| 366 | WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, |
| 367 | "%s invalid argument failed to find payloadType:%d", |
| 368 | __FUNCTION__, payload_type); |
| 369 | return -1; |
| 370 | } |
| 371 | |
| 372 | if (_audioConfigured) { |
| 373 | assert(frame_type == kAudioFrameSpeech || |
| 374 | frame_type == kAudioFrameCN || |
| 375 | frame_type == kFrameEmpty); |
| 376 | |
| 377 | return _audio->SendAudio(frame_type, payload_type, capture_timestamp, |
| 378 | payload_data, payload_size,fragmentation); |
| 379 | } else { |
| 380 | assert(frame_type != kAudioFrameSpeech && |
| 381 | frame_type != kAudioFrameCN); |
| 382 | |
| 383 | if (frame_type == kFrameEmpty) { |
| 384 | return SendPaddingAccordingToBitrate(payload_type, capture_timestamp, |
| 385 | capture_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 386 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 387 | return _video->SendVideo(video_type, |
| 388 | frame_type, |
| 389 | payload_type, |
| 390 | capture_timestamp, |
| 391 | capture_time_ms, |
| 392 | payload_data, |
| 393 | payload_size, |
| 394 | fragmentation, |
| 395 | codec_info, |
| 396 | rtp_type_hdr); |
| 397 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 398 | } |
| 399 | |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 400 | WebRtc_Word32 RTPSender::SendPaddingAccordingToBitrate( |
| 401 | WebRtc_Word8 payload_type, |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 402 | WebRtc_UWord32 capture_timestamp, |
| 403 | int64_t capture_time_ms) { |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 404 | // Current bitrate since last estimate(1 second) averaged with the |
| 405 | // estimate since then, to get the most up to date bitrate. |
| 406 | uint32_t current_bitrate = BitrateNow(); |
| 407 | int bitrate_diff = _targetSendBitrate * 1000 - current_bitrate; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 408 | if (bitrate_diff <= 0) { |
| 409 | return 0; |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 410 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 411 | int bytes = 0; |
| 412 | if (current_bitrate == 0) { |
| 413 | // Start up phase. Send one 33.3 ms batch to start with. |
| 414 | bytes = (bitrate_diff / 8) / 30; |
| 415 | } else { |
| 416 | bytes = (bitrate_diff / 8); |
| 417 | // Cap at 200 ms of target send data. |
| 418 | int bytes_cap = _targetSendBitrate * 25; // 1000 / 8 / 5 |
| 419 | if (bytes > bytes_cap) { |
| 420 | bytes = bytes_cap; |
| 421 | } |
| 422 | } |
| 423 | return SendPadData(payload_type, capture_timestamp, capture_time_ms, bytes); |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 424 | } |
| 425 | |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 426 | WebRtc_Word32 RTPSender::SendPadData(WebRtc_Word8 payload_type, |
| 427 | WebRtc_UWord32 capture_timestamp, |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 428 | int64_t capture_time_ms, |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 429 | WebRtc_Word32 bytes) { |
| 430 | // Drop this packet if we're not sending media packets |
| 431 | if (!_sendingMedia) { |
| 432 | return 0; |
| 433 | } |
| 434 | // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. |
| 435 | int max_length = 224; |
| 436 | WebRtc_UWord8 data_buffer[IP_PACKET_SIZE]; |
| 437 | |
| 438 | for (; bytes > 0; bytes -= max_length) { |
asapersson@webrtc.org | 63a34f4 | 2012-04-20 13:20:27 +0000 | [diff] [blame] | 439 | int padding_bytes_in_packet = max_length; |
| 440 | if (bytes < max_length) { |
| 441 | padding_bytes_in_packet = (bytes + 16) & 0xffe0; // Keep our modulus 32. |
| 442 | } |
| 443 | if (padding_bytes_in_packet < 32) { |
| 444 | // Sanity don't send empty packets. |
| 445 | break; |
| 446 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 447 | // Correct seq num, timestamp and payload type. |
| 448 | int header_length = BuildRTPheader(data_buffer, |
| 449 | payload_type, |
| 450 | false, // No markerbit. |
| 451 | capture_timestamp, |
| 452 | true, // Timestamp provided. |
| 453 | true); // Increment sequence number. |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 454 | data_buffer[0] |= 0x20; // Set padding bit. |
| 455 | WebRtc_Word32* data = |
| 456 | reinterpret_cast<WebRtc_Word32*>(&(data_buffer[header_length])); |
| 457 | |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 458 | // Fill data buffer with random data. |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 459 | for (int j = 0; j < (padding_bytes_in_packet >> 2); j++) { |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 460 | data[j] = rand(); |
| 461 | } |
| 462 | // Set number of padding bytes in the last byte of the packet. |
| 463 | data_buffer[header_length + padding_bytes_in_packet - 1] = |
| 464 | padding_bytes_in_packet; |
| 465 | // Send the packet |
| 466 | if (0 > SendToNetwork(data_buffer, |
| 467 | padding_bytes_in_packet, |
| 468 | header_length, |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 469 | capture_time_ms, |
pwestin@webrtc.org | 12d97f6 | 2012-01-05 10:54:44 +0000 | [diff] [blame] | 470 | kDontRetransmit)) { |
| 471 | // Error sending the packet. |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | if (bytes > 31) { // 31 due to our modulus 32. |
| 476 | // We did not manage to send all bytes. |
| 477 | return -1; |
| 478 | } |
| 479 | return 0; |
| 480 | } |
| 481 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 482 | void RTPSender::SetStorePacketsStatus( |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 483 | const bool enable, |
| 484 | const WebRtc_UWord16 numberToStore) { |
| 485 | _packetHistory->SetStorePacketsStatus(enable, numberToStore); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 486 | } |
| 487 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 488 | bool RTPSender::StorePackets() const { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 489 | return _packetHistory->StorePackets(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 490 | } |
| 491 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 492 | WebRtc_Word32 RTPSender::ReSendPacket(WebRtc_UWord16 packet_id, |
| 493 | WebRtc_UWord32 min_resend_time) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 494 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 495 | WebRtc_UWord16 length = IP_PACKET_SIZE; |
| 496 | WebRtc_UWord8 data_buffer[IP_PACKET_SIZE]; |
| 497 | WebRtc_UWord8* buffer_to_send_ptr = data_buffer; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 498 | |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 499 | int64_t stored_time_in_ms; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 500 | StorageType type; |
| 501 | bool found = _packetHistory->GetRTPPacket(packet_id, |
| 502 | min_resend_time, data_buffer, &length, &stored_time_in_ms, &type); |
| 503 | if (!found) { |
| 504 | // Packet not found. |
asapersson@webrtc.org | 83ed0a4 | 2012-04-23 12:43:05 +0000 | [diff] [blame] | 505 | return 0; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 506 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 507 | if (length == 0 || type == kDontRetransmit) { |
| 508 | // No bytes copied (packet recently resent, skip resending) or |
| 509 | // packet should not be retransmitted. |
| 510 | return 0; |
| 511 | } |
pwestin@webrtc.org | b30f0ed | 2012-01-23 16:23:31 +0000 | [diff] [blame] | 512 | WebRtc_UWord8 data_buffer_rtx[IP_PACKET_SIZE]; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 513 | if (_RTX) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 514 | buffer_to_send_ptr = data_buffer_rtx; |
| 515 | |
| 516 | CriticalSectionScoped cs(_sendCritsect); |
| 517 | // Add RTX header. |
| 518 | ModuleRTPUtility::RTPHeaderParser rtpParser( |
| 519 | reinterpret_cast<const WebRtc_UWord8*>(data_buffer), |
| 520 | length); |
| 521 | |
| 522 | WebRtcRTPHeader rtp_header; |
| 523 | rtpParser.Parse(rtp_header); |
| 524 | |
| 525 | // Add original RTP header. |
| 526 | memcpy(data_buffer_rtx, data_buffer, rtp_header.header.headerLength); |
| 527 | |
| 528 | // Replace sequence number. |
| 529 | WebRtc_UWord8* ptr = data_buffer_rtx + 2; |
| 530 | ModuleRTPUtility::AssignUWord16ToBuffer(ptr, _sequenceNumberRTX++); |
| 531 | |
| 532 | // Replace SSRC. |
| 533 | ptr += 6; |
| 534 | ModuleRTPUtility::AssignUWord32ToBuffer(ptr, _ssrcRTX); |
| 535 | |
| 536 | // Add OSN (original sequence number). |
| 537 | ptr = data_buffer_rtx + rtp_header.header.headerLength; |
| 538 | ModuleRTPUtility::AssignUWord16ToBuffer( |
| 539 | ptr, rtp_header.header.sequenceNumber); |
| 540 | ptr += 2; |
| 541 | |
| 542 | // Add original payload data. |
| 543 | memcpy(ptr, |
| 544 | data_buffer + rtp_header.header.headerLength, |
| 545 | length - rtp_header.header.headerLength); |
| 546 | length += 2; |
| 547 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 548 | WebRtc_Word32 bytes_sent = ReSendToNetwork(buffer_to_send_ptr, length); |
| 549 | if (bytes_sent <= 0) { |
| 550 | WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, _id, |
| 551 | "Transport failed to resend packet_id %u", packet_id); |
| 552 | return -1; |
| 553 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 554 | // Store the time when the packet was last resent. |
| 555 | _packetHistory->UpdateResendTime(packet_id); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 556 | return bytes_sent; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | WebRtc_Word32 RTPSender::ReSendToNetwork(const WebRtc_UWord8* packet, |
| 560 | const WebRtc_UWord32 size) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 561 | WebRtc_Word32 bytes_sent = -1; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 562 | if (_transport) { |
| 563 | bytes_sent = _transport->SendPacket(_id, packet, size); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 564 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 565 | if (bytes_sent <= 0) { |
| 566 | return -1; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 567 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 568 | // Update send statistics |
| 569 | CriticalSectionScoped cs(_sendCritsect); |
| 570 | Bitrate::Update(bytes_sent); |
| 571 | _packetsSent++; |
| 572 | // We on purpose don't add to _payloadBytesSent since this is a |
| 573 | // re-transmit and not new payload data. |
| 574 | return bytes_sent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 575 | } |
| 576 | |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 +0000 | [diff] [blame] | 577 | int RTPSender::SelectiveRetransmissions() const { |
| 578 | if (!_video) return -1; |
| 579 | return _video->SelectiveRetransmissions(); |
| 580 | } |
| 581 | |
| 582 | int RTPSender::SetSelectiveRetransmissions(uint8_t settings) { |
| 583 | if (!_video) return -1; |
| 584 | return _video->SetSelectiveRetransmissions(settings); |
| 585 | } |
| 586 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 587 | void RTPSender::OnReceivedNACK(const WebRtc_UWord16 nackSequenceNumbersLength, |
| 588 | const WebRtc_UWord16* nackSequenceNumbers, |
| 589 | const WebRtc_UWord16 avgRTT) { |
| 590 | const WebRtc_Word64 now = _clock.GetTimeInMS(); |
| 591 | WebRtc_UWord32 bytesReSent = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 593 | // Enough bandwidth to send NACK? |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 594 | if (!ProcessNACKBitRate(now)) { |
| 595 | WEBRTC_TRACE(kTraceStream, |
| 596 | kTraceRtpRtcp, |
| 597 | _id, |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 598 | "NACK bitrate reached. Skip sending NACK response. Target %d", |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 599 | _targetSendBitrate); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 600 | return; |
| 601 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 602 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 603 | for (WebRtc_UWord16 i = 0; i < nackSequenceNumbersLength; ++i) { |
| 604 | const WebRtc_Word32 bytesSent = ReSendPacket(nackSequenceNumbers[i], |
| 605 | 5+avgRTT); |
| 606 | if (bytesSent > 0) { |
| 607 | bytesReSent += bytesSent; |
| 608 | } else if (bytesSent == 0) { |
| 609 | // The packet has previously been resent. |
| 610 | // Try resending next packet in the list. |
| 611 | continue; |
| 612 | } else if (bytesSent < 0) { |
| 613 | // Failed to send one Sequence number. Give up the rest in this nack. |
| 614 | WEBRTC_TRACE(kTraceWarning, |
| 615 | kTraceRtpRtcp, |
| 616 | _id, |
| 617 | "Failed resending RTP packet %d, Discard rest of packets", |
| 618 | nackSequenceNumbers[i]); |
| 619 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 620 | } |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 621 | // delay bandwidth estimate (RTT * BW) |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 622 | if (_targetSendBitrate != 0 && avgRTT) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 623 | // kbits/s * ms = bits => bits/8 = bytes |
| 624 | WebRtc_UWord32 targetBytes = |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 625 | (static_cast<WebRtc_UWord32>(_targetSendBitrate) * avgRTT) >> 3; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 626 | if (bytesReSent > targetBytes) { |
| 627 | break; // ignore the rest of the packets in the list |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | if (bytesReSent > 0) { |
| 632 | // TODO(pwestin) consolidate these two methods. |
| 633 | UpdateNACKBitRate(bytesReSent, now); |
| 634 | _nackBitrate.Update(bytesReSent); |
| 635 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 636 | } |
| 637 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 638 | bool RTPSender::ProcessNACKBitRate(const WebRtc_UWord32 now) { |
| 639 | WebRtc_UWord32 num = 0; |
| 640 | WebRtc_Word32 byteCount = 0; |
| 641 | const WebRtc_UWord32 avgInterval=1000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 642 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 643 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 644 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 645 | if (_targetSendBitrate == 0) { |
| 646 | return true; |
| 647 | } |
| 648 | for (num = 0; num < NACK_BYTECOUNT_SIZE; num++) { |
| 649 | if ((now - _nackByteCountTimes[num]) > avgInterval) { |
| 650 | // don't use data older than 1sec |
| 651 | break; |
| 652 | } else { |
| 653 | byteCount += _nackByteCount[num]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 654 | } |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 655 | } |
| 656 | WebRtc_Word32 timeInterval = avgInterval; |
| 657 | if (num == NACK_BYTECOUNT_SIZE) { |
| 658 | // More than NACK_BYTECOUNT_SIZE nack messages has been received |
| 659 | // during the last msgInterval |
| 660 | timeInterval = now - _nackByteCountTimes[num-1]; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 661 | if (timeInterval < 0) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 662 | timeInterval = avgInterval; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 663 | } |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 664 | } |
| 665 | return (byteCount*8) < (_targetSendBitrate * timeInterval); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 666 | } |
| 667 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 668 | void RTPSender::UpdateNACKBitRate(const WebRtc_UWord32 bytes, |
| 669 | const WebRtc_UWord32 now) { |
| 670 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 671 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 672 | // save bitrate statistics |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 673 | if (bytes > 0) { |
| 674 | if (now == 0) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 675 | // add padding length |
| 676 | _nackByteCount[0] += bytes; |
| 677 | } else { |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 678 | if (_nackByteCountTimes[0] == 0) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 679 | // first no shift |
| 680 | } else { |
| 681 | // shift |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 682 | for (int i = (NACK_BYTECOUNT_SIZE-2); i >= 0 ; i--) { |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 683 | _nackByteCount[i+1] = _nackByteCount[i]; |
| 684 | _nackByteCountTimes[i+1] = _nackByteCountTimes[i]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 685 | } |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 686 | } |
| 687 | _nackByteCount[0] = bytes; |
| 688 | _nackByteCountTimes[0] = now; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 689 | } |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 690 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 691 | } |
| 692 | |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 693 | void RTPSender::ProcessSendToNetwork() { |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 694 | WebRtc_Word64 delta_time_ms; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 695 | { |
| 696 | CriticalSectionScoped cs(_sendCritsect); |
| 697 | |
| 698 | if (!_transmissionSmoothing) { |
| 699 | return; |
| 700 | } |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 701 | WebRtc_Word64 now = _clock.GetTimeInMS(); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 702 | delta_time_ms = now - _timeLastSendToNetworkUpdate; |
| 703 | _timeLastSendToNetworkUpdate = now; |
| 704 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 705 | _sendBucket.UpdateBytesPerInterval(delta_time_ms, _targetSendBitrate); |
| 706 | |
| 707 | while (!_sendBucket.Empty()) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 708 | WebRtc_Word32 seq_num = _sendBucket.GetNextPacket(); |
| 709 | if (seq_num < 0) { |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | WebRtc_UWord8 data_buffer[IP_PACKET_SIZE]; |
| 714 | WebRtc_UWord16 length = IP_PACKET_SIZE; |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 715 | int64_t stored_time_ms; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 716 | StorageType type; |
asapersson@webrtc.org | 869ce2d | 2012-01-16 11:58:36 +0000 | [diff] [blame] | 717 | bool found = _packetHistory->GetRTPPacket(seq_num, 0, data_buffer, &length, |
| 718 | &stored_time_ms, &type); |
| 719 | if (!found) { |
| 720 | assert(false); |
| 721 | return; |
| 722 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 723 | assert(length > 0); |
| 724 | |
pwestin@webrtc.org | 1853005 | 2012-07-03 10:41:54 +0000 | [diff] [blame] | 725 | WebRtc_Word64 diff_ms = _clock.GetTimeInMS() - stored_time_ms; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 726 | |
| 727 | ModuleRTPUtility::RTPHeaderParser rtpParser(data_buffer, length); |
| 728 | WebRtcRTPHeader rtp_header; |
asapersson@webrtc.org | 869ce2d | 2012-01-16 11:58:36 +0000 | [diff] [blame] | 729 | rtpParser.Parse(rtp_header); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 730 | |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 731 | if (UpdateTransmissionTimeOffset(data_buffer, length, rtp_header, |
| 732 | diff_ms)) { |
| 733 | // Update stored packet in case of receiving a re-transmission request. |
| 734 | _packetHistory->ReplaceRTPHeader(data_buffer, |
| 735 | rtp_header.header.sequenceNumber, |
| 736 | rtp_header.header.headerLength); |
| 737 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 738 | |
| 739 | // Send packet |
| 740 | WebRtc_Word32 bytes_sent = -1; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 741 | if (_transport) { |
| 742 | bytes_sent = _transport->SendPacket(_id, data_buffer, length); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // Update send statistics |
| 746 | if (bytes_sent > 0) { |
| 747 | CriticalSectionScoped cs(_sendCritsect); |
| 748 | Bitrate::Update(bytes_sent); |
| 749 | _packetsSent++; |
| 750 | if (bytes_sent > rtp_header.header.headerLength) { |
| 751 | _payloadBytesSent += bytes_sent - rtp_header.header.headerLength; |
| 752 | } |
| 753 | } |
phoglund@webrtc.org | baaf243 | 2012-05-31 10:47:35 +0000 | [diff] [blame] | 754 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 755 | } |
| 756 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 757 | WebRtc_Word32 RTPSender::SendToNetwork(WebRtc_UWord8* buffer, |
| 758 | WebRtc_UWord16 payload_length, |
| 759 | WebRtc_UWord16 rtp_header_length, |
| 760 | int64_t capture_time_ms, |
| 761 | StorageType storage) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 762 | // Used for NACK or to spead out the transmission of packets. |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 763 | if (_packetHistory->PutRTPPacket(buffer, rtp_header_length + payload_length, |
| 764 | _maxPayloadLength, capture_time_ms, storage) != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 765 | return -1; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 766 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 767 | if (_transmissionSmoothing) { |
| 768 | const WebRtc_UWord16 sequenceNumber = (buffer[2] << 8) + buffer[3]; |
asapersson@webrtc.org | 23fd559 | 2012-09-24 12:07:13 +0000 | [diff] [blame] | 769 | const WebRtc_UWord32 timestamp = (buffer[4] << 24) + (buffer[5] << 16) + |
| 770 | (buffer[6] << 8) + buffer[7]; |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 771 | _sendBucket.Fill(sequenceNumber, timestamp, |
| 772 | rtp_header_length + payload_length); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 773 | // Packet will be sent at a later time. |
| 774 | return 0; |
| 775 | } |
stefan@webrtc.org | 715faaf | 2012-08-28 15:20:39 +0000 | [diff] [blame] | 776 | // |capture_time_ms| <= 0 is considered invalid. |
| 777 | // TODO(holmer): This should be changed all over Video Engine so that negative |
| 778 | // time is consider invalid, while 0 is considered a valid time. |
| 779 | if (capture_time_ms > 0) { |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 780 | ModuleRTPUtility::RTPHeaderParser rtpParser(buffer, |
| 781 | rtp_header_length + payload_length); |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 782 | WebRtcRTPHeader rtp_header; |
mflodman@webrtc.org | 90071dd | 2012-08-13 17:13:27 +0000 | [diff] [blame] | 783 | rtpParser.Parse(rtp_header); |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 784 | int64_t time_now = _clock.GetTimeInMS(); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 785 | if (UpdateTransmissionTimeOffset(buffer, rtp_header_length + payload_length, |
| 786 | rtp_header, time_now - capture_time_ms)) { |
| 787 | // Update stored packet in case of receiving a re-transmission request. |
| 788 | _packetHistory->ReplaceRTPHeader(buffer, rtp_header.header.sequenceNumber, |
| 789 | rtp_header.header.headerLength); |
| 790 | } |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 +0000 | [diff] [blame] | 791 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 792 | // Send packet |
| 793 | WebRtc_Word32 bytes_sent = -1; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 794 | if (_transport) { |
| 795 | bytes_sent = _transport->SendPacket(_id, buffer, |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 796 | payload_length + rtp_header_length); |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 +0000 | [diff] [blame] | 797 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 798 | if (bytes_sent <= 0) { |
| 799 | return -1; |
| 800 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 801 | // Update send statistics |
| 802 | CriticalSectionScoped cs(_sendCritsect); |
| 803 | Bitrate::Update(bytes_sent); |
| 804 | _packetsSent++; |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 805 | if (bytes_sent > rtp_header_length) { |
| 806 | _payloadBytesSent += bytes_sent - rtp_header_length; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 807 | } |
| 808 | return 0; |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 +0000 | [diff] [blame] | 809 | } |
| 810 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 811 | void RTPSender::ProcessBitrate() { |
| 812 | CriticalSectionScoped cs(_sendCritsect); |
| 813 | Bitrate::Process(); |
| 814 | _nackBitrate.Process(); |
| 815 | if (_audioConfigured) { |
| 816 | return; |
| 817 | } |
| 818 | _video->ProcessBitrate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 819 | } |
| 820 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 821 | WebRtc_UWord16 RTPSender::RTPHeaderLength() const { |
| 822 | WebRtc_UWord16 rtpHeaderLength = 12; |
| 823 | if (_includeCSRCs) { |
| 824 | rtpHeaderLength += sizeof(WebRtc_UWord32)*_CSRCs; |
| 825 | } |
| 826 | rtpHeaderLength += RtpHeaderExtensionTotalLength(); |
| 827 | return rtpHeaderLength; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 828 | } |
| 829 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 830 | WebRtc_UWord16 RTPSender::IncrementSequenceNumber() { |
| 831 | CriticalSectionScoped cs(_sendCritsect); |
| 832 | return _sequenceNumber++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 833 | } |
| 834 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 835 | void RTPSender::ResetDataCounters() { |
| 836 | _packetsSent = 0; |
| 837 | _payloadBytesSent = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 838 | } |
| 839 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 840 | WebRtc_UWord32 RTPSender::Packets() const { |
| 841 | // Don't use critsect to avoid potental deadlock |
| 842 | return _packetsSent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | // number of sent RTP bytes |
| 846 | // dont use critsect to avoid potental deadlock |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 847 | WebRtc_UWord32 RTPSender::Bytes() const { |
| 848 | return _payloadBytesSent; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 849 | } |
| 850 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 851 | WebRtc_Word32 RTPSender::BuildRTPheader(WebRtc_UWord8* dataBuffer, |
| 852 | const WebRtc_Word8 payloadType, |
| 853 | const bool markerBit, |
| 854 | const WebRtc_UWord32 captureTimeStamp, |
| 855 | const bool timeStampProvided, |
| 856 | const bool incSequenceNumber) { |
| 857 | assert(payloadType>=0); |
| 858 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 859 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 860 | dataBuffer[0] = static_cast<WebRtc_UWord8>(0x80); // version 2 |
| 861 | dataBuffer[1] = static_cast<WebRtc_UWord8>(payloadType); |
| 862 | if (markerBit) { |
| 863 | dataBuffer[1] |= kRtpMarkerBitMask; // MarkerBit is set |
| 864 | } |
| 865 | if (timeStampProvided) { |
| 866 | _timeStamp = _startTimeStamp + captureTimeStamp; |
| 867 | } else { |
| 868 | // make a unique time stamp |
| 869 | // we can't inc by the actual time, since then we increase the risk of back |
| 870 | // timing. |
| 871 | _timeStamp++; |
| 872 | } |
| 873 | ModuleRTPUtility::AssignUWord16ToBuffer(dataBuffer+2, _sequenceNumber); |
| 874 | ModuleRTPUtility::AssignUWord32ToBuffer(dataBuffer+4, _timeStamp); |
| 875 | ModuleRTPUtility::AssignUWord32ToBuffer(dataBuffer+8, _ssrc); |
| 876 | WebRtc_Word32 rtpHeaderLength = 12; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 877 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 878 | // Add the CSRCs if any |
| 879 | if (_includeCSRCs && _CSRCs > 0) { |
| 880 | if (_CSRCs > kRtpCsrcSize) { |
| 881 | // error |
| 882 | assert(false); |
| 883 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 884 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 885 | WebRtc_UWord8* ptr = &dataBuffer[rtpHeaderLength]; |
| 886 | for (WebRtc_UWord32 i = 0; i < _CSRCs; ++i) { |
| 887 | ModuleRTPUtility::AssignUWord32ToBuffer(ptr, _CSRC[i]); |
| 888 | ptr +=4; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 889 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 890 | dataBuffer[0] = (dataBuffer[0]&0xf0) | _CSRCs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 891 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 892 | // Update length of header |
| 893 | rtpHeaderLength += sizeof(WebRtc_UWord32)*_CSRCs; |
| 894 | } |
| 895 | _sequenceNumber++; // prepare for next packet |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 896 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 897 | WebRtc_UWord16 len = BuildRTPHeaderExtension(dataBuffer + rtpHeaderLength); |
| 898 | if (len) { |
| 899 | dataBuffer[0] |= 0x10; // set eXtension bit |
| 900 | rtpHeaderLength += len; |
| 901 | } |
| 902 | return rtpHeaderLength; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 903 | } |
| 904 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 905 | WebRtc_UWord16 RTPSender::BuildRTPHeaderExtension( |
| 906 | WebRtc_UWord8* dataBuffer) const { |
| 907 | if (_rtpHeaderExtensionMap.Size() <= 0) { |
| 908 | return 0; |
| 909 | } |
| 910 | /* RTP header extension, RFC 3550. |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 911 | 0 1 2 3 |
| 912 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 913 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 914 | | defined by profile | length | |
| 915 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 916 | | header extension | |
| 917 | | .... | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 918 | */ |
| 919 | const WebRtc_UWord32 kPosLength = 2; |
| 920 | const WebRtc_UWord32 kHeaderLength = RTP_ONE_BYTE_HEADER_LENGTH_IN_BYTES; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 921 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 922 | // Add extension ID (0xBEDE). |
| 923 | ModuleRTPUtility::AssignUWord16ToBuffer(dataBuffer, |
| 924 | RTP_ONE_BYTE_HEADER_EXTENSION); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 925 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 926 | // Add extensions. |
| 927 | WebRtc_UWord16 total_block_length = 0; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 928 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 929 | RTPExtensionType type = _rtpHeaderExtensionMap.First(); |
| 930 | while (type != kRtpExtensionNone) { |
| 931 | WebRtc_UWord8 block_length = 0; |
| 932 | if (type == kRtpExtensionTransmissionTimeOffset) { |
| 933 | block_length = BuildTransmissionTimeOffsetExtension( |
| 934 | dataBuffer + kHeaderLength + total_block_length); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 935 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 936 | total_block_length += block_length; |
| 937 | type = _rtpHeaderExtensionMap.Next(type); |
| 938 | } |
| 939 | if (total_block_length == 0) { |
| 940 | // No extension added. |
| 941 | return 0; |
| 942 | } |
| 943 | // Set header length (in number of Word32, header excluded). |
| 944 | assert(total_block_length % 4 == 0); |
| 945 | ModuleRTPUtility::AssignUWord16ToBuffer(dataBuffer + kPosLength, |
| 946 | total_block_length / 4); |
| 947 | // Total added length. |
| 948 | return kHeaderLength + total_block_length; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 949 | } |
| 950 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 951 | WebRtc_UWord8 RTPSender::BuildTransmissionTimeOffsetExtension( |
| 952 | WebRtc_UWord8* dataBuffer) const { |
| 953 | // From RFC 5450: Transmission Time Offsets in RTP Streams. |
| 954 | // |
| 955 | // The transmission time is signaled to the receiver in-band using the |
| 956 | // general mechanism for RTP header extensions [RFC5285]. The payload |
| 957 | // of this extension (the transmitted value) is a 24-bit signed integer. |
| 958 | // When added to the RTP timestamp of the packet, it represents the |
| 959 | // "effective" RTP transmission time of the packet, on the RTP |
| 960 | // timescale. |
| 961 | // |
| 962 | // The form of the transmission offset extension block: |
| 963 | // |
| 964 | // 0 1 2 3 |
| 965 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 966 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 967 | // | ID | len=2 | transmission offset | |
| 968 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 969 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 970 | // Get id defined by user. |
| 971 | WebRtc_UWord8 id; |
| 972 | if (_rtpHeaderExtensionMap.GetId(kRtpExtensionTransmissionTimeOffset, &id) |
| 973 | != 0) { |
| 974 | // Not registered. |
| 975 | return 0; |
| 976 | } |
| 977 | int pos = 0; |
| 978 | const WebRtc_UWord8 len = 2; |
| 979 | dataBuffer[pos++] = (id << 4) + len; |
| 980 | ModuleRTPUtility::AssignUWord24ToBuffer(dataBuffer + pos, |
| 981 | _transmissionTimeOffset); |
| 982 | pos += 3; |
| 983 | assert(pos == TRANSMISSION_TIME_OFFSET_LENGTH_IN_BYTES); |
| 984 | return TRANSMISSION_TIME_OFFSET_LENGTH_IN_BYTES; |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 985 | } |
| 986 | |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 987 | bool RTPSender::UpdateTransmissionTimeOffset( |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 988 | WebRtc_UWord8* rtp_packet, |
| 989 | const WebRtc_UWord16 rtp_packet_length, |
| 990 | const WebRtcRTPHeader& rtp_header, |
mflodman@webrtc.org | ba853c9 | 2012-08-10 14:30:53 +0000 | [diff] [blame] | 991 | const WebRtc_Word64 time_diff_ms) const { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 992 | CriticalSectionScoped cs(_sendCritsect); |
| 993 | |
| 994 | // Get length until start of transmission block. |
| 995 | int transmission_block_pos = |
| 996 | _rtpHeaderExtensionMap.GetLengthUntilBlockStartInBytes( |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 997 | kRtpExtensionTransmissionTimeOffset); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 998 | if (transmission_block_pos < 0) { |
| 999 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1000 | "Failed to update transmission time offset, not registered."); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1001 | return false; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | int block_pos = 12 + rtp_header.header.numCSRCs + transmission_block_pos; |
mflodman@webrtc.org | ba853c9 | 2012-08-10 14:30:53 +0000 | [diff] [blame] | 1005 | if (rtp_packet_length < block_pos + 4 || |
| 1006 | rtp_header.header.headerLength < block_pos + 4) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1007 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1008 | "Failed to update transmission time offset, invalid length."); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1009 | return false; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1010 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1011 | // Verify that header contains extension. |
| 1012 | if (!((rtp_packet[12 + rtp_header.header.numCSRCs] == 0xBE) && |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1013 | (rtp_packet[12 + rtp_header.header.numCSRCs + 1] == 0xDE))) { |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1014 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
| 1015 | "Failed to update transmission time offset, hdr extension not found."); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1016 | return false; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1017 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1018 | // Get id. |
| 1019 | WebRtc_UWord8 id = 0; |
| 1020 | if (_rtpHeaderExtensionMap.GetId(kRtpExtensionTransmissionTimeOffset, |
| 1021 | &id) != 0) { |
| 1022 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1023 | "Failed to update transmission time offset, no id."); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1024 | return false; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1025 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1026 | // Verify first byte in block. |
| 1027 | const WebRtc_UWord8 first_block_byte = (id << 4) + 2; |
| 1028 | if (rtp_packet[block_pos] != first_block_byte) { |
| 1029 | WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, _id, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1030 | "Failed to update transmission time offset."); |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1031 | return false; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1032 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1033 | // Update transmission offset field. |
| 1034 | ModuleRTPUtility::AssignUWord24ToBuffer(rtp_packet + block_pos + 1, |
mflodman@webrtc.org | ba853c9 | 2012-08-10 14:30:53 +0000 | [diff] [blame] | 1035 | time_diff_ms * 90); // RTP timestamp. |
asapersson@webrtc.org | e5b49a0 | 2012-11-06 13:09:39 +0000 | [diff] [blame] | 1036 | return true; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1039 | void RTPSender::SetSendingStatus(const bool enabled) { |
| 1040 | if (enabled) { |
| 1041 | WebRtc_UWord32 freq; |
| 1042 | if (_audioConfigured) { |
| 1043 | WebRtc_UWord32 frequency = _audio->AudioFrequency(); |
| 1044 | |
| 1045 | // sanity |
| 1046 | switch(frequency) { |
| 1047 | case 8000: |
| 1048 | case 12000: |
| 1049 | case 16000: |
| 1050 | case 24000: |
| 1051 | case 32000: |
| 1052 | break; |
| 1053 | default: |
| 1054 | assert(false); |
| 1055 | return; |
| 1056 | } |
| 1057 | freq = frequency; |
| 1058 | } else { |
| 1059 | freq = 90000; // 90 KHz for all video |
| 1060 | } |
| 1061 | WebRtc_UWord32 RTPtime = ModuleRTPUtility::GetCurrentRTP(&_clock, freq); |
| 1062 | |
| 1063 | // will be ignored if it's already configured via API |
| 1064 | SetStartTimestamp(RTPtime, false); |
| 1065 | } else { |
| 1066 | if (!_ssrcForced) { |
| 1067 | // generate a new SSRC |
| 1068 | _ssrcDB.ReturnSSRC(_ssrc); |
| 1069 | _ssrc = _ssrcDB.CreateSSRC(); // can't be 0 |
| 1070 | |
| 1071 | } |
| 1072 | // Don't initialize seq number if SSRC passed externally. |
| 1073 | if (!_sequenceNumberForced && !_ssrcForced) { |
| 1074 | // generate a new sequence number |
| 1075 | _sequenceNumber = rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | void RTPSender::SetSendingMediaStatus(const bool enabled) { |
| 1081 | CriticalSectionScoped cs(_sendCritsect); |
| 1082 | _sendingMedia = enabled; |
| 1083 | } |
| 1084 | |
| 1085 | bool RTPSender::SendingMedia() const { |
| 1086 | CriticalSectionScoped cs(_sendCritsect); |
| 1087 | return _sendingMedia; |
| 1088 | } |
| 1089 | |
| 1090 | WebRtc_UWord32 RTPSender::Timestamp() const { |
| 1091 | CriticalSectionScoped cs(_sendCritsect); |
| 1092 | return _timeStamp; |
| 1093 | } |
| 1094 | |
| 1095 | void RTPSender::SetStartTimestamp(WebRtc_UWord32 timestamp, bool force) { |
| 1096 | CriticalSectionScoped cs(_sendCritsect); |
| 1097 | if (force) { |
| 1098 | _startTimeStampForced = force; |
| 1099 | _startTimeStamp = timestamp; |
| 1100 | } else { |
| 1101 | if (!_startTimeStampForced) { |
| 1102 | _startTimeStamp = timestamp; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | WebRtc_UWord32 RTPSender::StartTimestamp() const { |
| 1108 | CriticalSectionScoped cs(_sendCritsect); |
| 1109 | return _startTimeStamp; |
| 1110 | } |
| 1111 | |
| 1112 | WebRtc_UWord32 RTPSender::GenerateNewSSRC() { |
| 1113 | // if configured via API, return 0 |
| 1114 | CriticalSectionScoped cs(_sendCritsect); |
| 1115 | |
| 1116 | if (_ssrcForced) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1117 | return 0; |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1118 | } |
| 1119 | _ssrc = _ssrcDB.CreateSSRC(); // can't be 0 |
| 1120 | return _ssrc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1123 | void RTPSender::SetSSRC(WebRtc_UWord32 ssrc) { |
| 1124 | // this is configured via the API |
| 1125 | CriticalSectionScoped cs(_sendCritsect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1126 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1127 | if (_ssrc == ssrc && _ssrcForced) { |
| 1128 | return; // since it's same ssrc, don't reset anything |
| 1129 | } |
| 1130 | _ssrcForced = true; |
| 1131 | _ssrcDB.ReturnSSRC(_ssrc); |
| 1132 | _ssrcDB.RegisterSSRC(ssrc); |
| 1133 | _ssrc = ssrc; |
| 1134 | if (!_sequenceNumberForced) { |
| 1135 | _sequenceNumber = rand() / (RAND_MAX / MAX_INIT_RTP_SEQ_NUMBER); |
| 1136 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1139 | WebRtc_UWord32 RTPSender::SSRC() const { |
| 1140 | CriticalSectionScoped cs(_sendCritsect); |
| 1141 | return _ssrc; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1144 | void RTPSender::SetCSRCStatus(const bool include) { |
| 1145 | _includeCSRCs = include; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1148 | void RTPSender::SetCSRCs(const WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize], |
| 1149 | const WebRtc_UWord8 arrLength) { |
| 1150 | assert(arrLength <= kRtpCsrcSize); |
| 1151 | CriticalSectionScoped cs(_sendCritsect); |
| 1152 | |
| 1153 | for (int i = 0; i < arrLength;i++) { |
| 1154 | _CSRC[i] = arrOfCSRC[i]; |
| 1155 | } |
| 1156 | _CSRCs = arrLength; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1159 | WebRtc_Word32 RTPSender::CSRCs(WebRtc_UWord32 arrOfCSRC[kRtpCsrcSize]) const { |
| 1160 | assert(arrOfCSRC); |
| 1161 | CriticalSectionScoped cs(_sendCritsect); |
| 1162 | for (int i = 0; i < _CSRCs && i < kRtpCsrcSize;i++) { |
| 1163 | arrOfCSRC[i] = _CSRC[i]; |
| 1164 | } |
| 1165 | return _CSRCs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1168 | void RTPSender::SetSequenceNumber(WebRtc_UWord16 seq) { |
| 1169 | CriticalSectionScoped cs(_sendCritsect); |
| 1170 | _sequenceNumberForced = true; |
| 1171 | _sequenceNumber = seq; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1174 | WebRtc_UWord16 RTPSender::SequenceNumber() const { |
| 1175 | CriticalSectionScoped cs(_sendCritsect); |
| 1176 | return _sequenceNumber; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1179 | /* |
| 1180 | * Audio |
| 1181 | */ |
| 1182 | WebRtc_Word32 RTPSender::SendTelephoneEvent(const WebRtc_UWord8 key, |
| 1183 | const WebRtc_UWord16 time_ms, |
| 1184 | const WebRtc_UWord8 level) { |
| 1185 | if (!_audioConfigured) { |
| 1186 | return -1; |
| 1187 | } |
| 1188 | return _audio->SendTelephoneEvent(key, time_ms, level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1191 | bool RTPSender::SendTelephoneEventActive(WebRtc_Word8& telephoneEvent) const { |
| 1192 | if (!_audioConfigured) { |
| 1193 | return false; |
| 1194 | } |
| 1195 | return _audio->SendTelephoneEventActive(telephoneEvent); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1198 | WebRtc_Word32 RTPSender::SetAudioPacketSize( |
| 1199 | const WebRtc_UWord16 packetSizeSamples) { |
| 1200 | if (!_audioConfigured) { |
| 1201 | return -1; |
| 1202 | } |
| 1203 | return _audio->SetAudioPacketSize(packetSizeSamples); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | WebRtc_Word32 |
| 1207 | RTPSender::SetAudioLevelIndicationStatus(const bool enable, |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1208 | const WebRtc_UWord8 ID) { |
| 1209 | if (!_audioConfigured) { |
| 1210 | return -1; |
| 1211 | } |
| 1212 | return _audio->SetAudioLevelIndicationStatus(enable, ID); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1215 | WebRtc_Word32 RTPSender::AudioLevelIndicationStatus(bool& enable, |
| 1216 | WebRtc_UWord8& ID) const { |
| 1217 | return _audio->AudioLevelIndicationStatus(enable, ID); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1220 | WebRtc_Word32 RTPSender::SetAudioLevel(const WebRtc_UWord8 level_dBov) { |
| 1221 | return _audio->SetAudioLevel(level_dBov); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1224 | WebRtc_Word32 RTPSender::SetRED(const WebRtc_Word8 payloadType) { |
| 1225 | if (!_audioConfigured) { |
| 1226 | return -1; |
| 1227 | } |
| 1228 | return _audio->SetRED(payloadType); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1231 | WebRtc_Word32 RTPSender::RED(WebRtc_Word8& payloadType) const { |
| 1232 | if (!_audioConfigured) { |
| 1233 | return -1; |
| 1234 | } |
| 1235 | return _audio->RED(payloadType); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1238 | /* |
| 1239 | * Video |
| 1240 | */ |
| 1241 | VideoCodecInformation* RTPSender::CodecInformationVideo() { |
| 1242 | if (_audioConfigured) { |
| 1243 | return NULL; |
| 1244 | } |
| 1245 | return _video->CodecInformationVideo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1248 | RtpVideoCodecTypes RTPSender::VideoCodecType() const { |
| 1249 | if (_audioConfigured) { |
| 1250 | return kRtpNoVideo; |
| 1251 | } |
| 1252 | return _video->VideoCodecType(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1255 | WebRtc_UWord32 RTPSender::MaxConfiguredBitrateVideo() const { |
| 1256 | if (_audioConfigured) { |
| 1257 | return 0; |
| 1258 | } |
| 1259 | return _video->MaxConfiguredBitrateVideo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1262 | WebRtc_Word32 RTPSender::SendRTPIntraRequest() { |
| 1263 | if (_audioConfigured) { |
| 1264 | return -1; |
| 1265 | } |
| 1266 | return _video->SendRTPIntraRequest(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1269 | WebRtc_Word32 RTPSender::SetGenericFECStatus( |
| 1270 | const bool enable, |
| 1271 | const WebRtc_UWord8 payloadTypeRED, |
| 1272 | const WebRtc_UWord8 payloadTypeFEC) { |
| 1273 | if (_audioConfigured) { |
| 1274 | return -1; |
| 1275 | } |
| 1276 | return _video->SetGenericFECStatus(enable, payloadTypeRED, payloadTypeFEC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1279 | WebRtc_Word32 RTPSender::GenericFECStatus(bool& enable, |
| 1280 | WebRtc_UWord8& payloadTypeRED, |
| 1281 | WebRtc_UWord8& payloadTypeFEC) const { |
| 1282 | if (_audioConfigured) { |
| 1283 | return -1; |
| 1284 | } |
| 1285 | return _video->GenericFECStatus(enable, payloadTypeRED, payloadTypeFEC); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
stefan@webrtc.org | e0d6fa4 | 2012-03-20 22:10:56 +0000 | [diff] [blame] | 1288 | WebRtc_Word32 RTPSender::SetFecParameters( |
| 1289 | const FecProtectionParams* delta_params, |
| 1290 | const FecProtectionParams* key_params) { |
| 1291 | if (_audioConfigured) { |
| 1292 | return -1; |
| 1293 | } |
| 1294 | return _video->SetFecParameters(delta_params, key_params); |
marpan@google.com | 80c5d7a | 2011-07-15 21:32:40 +0000 | [diff] [blame] | 1295 | } |
pwestin@webrtc.org | c66e8b3 | 2012-11-07 17:01:04 +0000 | [diff] [blame^] | 1296 | } // namespace webrtc |