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