 Chromium Code Reviews
 Chromium Code Reviews Issue 1623543002:
  Refactor RtpSender and SSRCDatabase a bit.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1623543002:
  Refactor RtpSender and SSRCDatabase a bit.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 uint32_t ConvertMsTo24Bits(int64_t time_ms) { | 56 uint32_t ConvertMsTo24Bits(int64_t time_ms) { | 
| 57 uint32_t time_24_bits = | 57 uint32_t time_24_bits = | 
| 58 static_cast<uint32_t>( | 58 static_cast<uint32_t>( | 
| 59 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / | 59 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / | 
| 60 1000) & | 60 1000) & | 
| 61 0x00FFFFFF; | 61 0x00FFFFFF; | 
| 62 return time_24_bits; | 62 return time_24_bits; | 
| 63 } | 63 } | 
| 64 } // namespace | 64 } // namespace | 
| 65 | 65 | 
| 66 class BitrateAggregator { | 66 RTPSender::BitrateAggregator::BitrateAggregator( | 
| 67 public: | 67 BitrateStatisticsObserver* bitrate_callback) | 
| 68 explicit BitrateAggregator(BitrateStatisticsObserver* bitrate_callback) | 68 : callback_(bitrate_callback), | 
| 69 : callback_(bitrate_callback), | 69 total_bitrate_observer_(*this), | 
| 70 total_bitrate_observer_(*this), | 70 retransmit_bitrate_observer_(*this), | 
| 71 retransmit_bitrate_observer_(*this), | 71 ssrc_(0) {} | 
| 72 ssrc_(0) {} | |
| 73 | 72 | 
| 74 void OnStatsUpdated() const { | 73 void RTPSender::BitrateAggregator::OnStatsUpdated() const { | 
| 75 if (callback_) | 74 if (callback_) { | 
| 76 callback_->Notify(total_bitrate_observer_.statistics(), | 75 callback_->Notify(total_bitrate_observer_.statistics(), | 
| 77 retransmit_bitrate_observer_.statistics(), | 76 retransmit_bitrate_observer_.statistics(), ssrc_); | 
| 78 ssrc_); | |
| 79 } | 77 } | 
| 78 } | |
| 80 | 79 | 
| 81 Bitrate::Observer* total_bitrate_observer() { | 80 Bitrate::Observer* RTPSender::BitrateAggregator::total_bitrate_observer() { | 
| 82 return &total_bitrate_observer_; | 81 return &total_bitrate_observer_; | 
| 83 } | 82 } | 
| 84 Bitrate::Observer* retransmit_bitrate_observer() { | 83 Bitrate::Observer* RTPSender::BitrateAggregator::retransmit_bitrate_observer() { | 
| 85 return &retransmit_bitrate_observer_; | 84 return &retransmit_bitrate_observer_; | 
| 86 } | 85 } | 
| 87 | 86 | 
| 88 void set_ssrc(uint32_t ssrc) { ssrc_ = ssrc; } | 87 void RTPSender::BitrateAggregator::set_ssrc(uint32_t ssrc) { | 
| 88 ssrc_ = ssrc; | |
| 89 } | |
| 89 | 90 | 
| 90 private: | 91 RTPSender::BitrateAggregator::BitrateObserver::BitrateObserver( | 
| 91 // We assume that these observers are called on the same thread, which is | 92 const BitrateAggregator& aggregator) | 
| 92 // true for RtpSender as they are called on the Process thread. | 93 : aggregator_(aggregator) {} | 
| 93 class BitrateObserver : public Bitrate::Observer { | |
| 94 public: | |
| 95 explicit BitrateObserver(const BitrateAggregator& aggregator) | |
| 96 : aggregator_(aggregator) {} | |
| 97 | 94 | 
| 98 // Implements Bitrate::Observer. | 95 // Implements Bitrate::Observer. | 
| 99 void BitrateUpdated(const BitrateStatistics& stats) override { | 96 void RTPSender::BitrateAggregator::BitrateObserver::BitrateUpdated( | 
| 100 statistics_ = stats; | 97 const BitrateStatistics& stats) { | 
| 101 aggregator_.OnStatsUpdated(); | 98 statistics_ = stats; | 
| 102 } | 99 aggregator_.OnStatsUpdated(); | 
| 100 } | |
| 103 | 101 | 
| 104 BitrateStatistics statistics() const { return statistics_; } | 102 const BitrateStatistics& | 
| 105 | 103 RTPSender::BitrateAggregator::BitrateObserver::statistics() const { | 
| 106 private: | 104 return statistics_; | 
| 107 BitrateStatistics statistics_; | 105 } | 
| 108 const BitrateAggregator& aggregator_; | |
| 109 }; | |
| 110 | |
| 111 BitrateStatisticsObserver* const callback_; | |
| 112 BitrateObserver total_bitrate_observer_; | |
| 113 BitrateObserver retransmit_bitrate_observer_; | |
| 114 uint32_t ssrc_; | |
| 115 }; | |
| 116 | 106 | 
| 117 RTPSender::RTPSender( | 107 RTPSender::RTPSender( | 
| 118 bool audio, | 108 bool audio, | 
| 119 Clock* clock, | 109 Clock* clock, | 
| 120 Transport* transport, | 110 Transport* transport, | 
| 121 RtpAudioFeedback* audio_feedback, | 111 RtpAudioFeedback* audio_feedback, | 
| 122 RtpPacketSender* paced_sender, | 112 RtpPacketSender* paced_sender, | 
| 123 TransportSequenceNumberAllocator* sequence_number_allocator, | 113 TransportSequenceNumberAllocator* sequence_number_allocator, | 
| 124 TransportFeedbackObserver* transport_feedback_observer, | 114 TransportFeedbackObserver* transport_feedback_observer, | 
| 125 BitrateStatisticsObserver* bitrate_callback, | 115 BitrateStatisticsObserver* bitrate_callback, | 
| 126 FrameCountObserver* frame_count_observer, | 116 FrameCountObserver* frame_count_observer, | 
| 127 SendSideDelayObserver* send_side_delay_observer, | 117 SendSideDelayObserver* send_side_delay_observer, | 
| 128 RtcEventLog* event_log) | 118 RtcEventLog* event_log) | 
| 129 : clock_(clock), | 119 : clock_(clock), | 
| 130 // TODO(holmer): Remove this conversion when we remove the use of | 120 // TODO(holmer): Remove this conversion when we remove the use of | 
| 131 // TickTime. | 121 // TickTime. | 
| 132 clock_delta_ms_(clock_->TimeInMilliseconds() - | 122 clock_delta_ms_(clock_->TimeInMilliseconds() - | 
| 133 TickTime::MillisecondTimestamp()), | 123 TickTime::MillisecondTimestamp()), | 
| 134 random_(clock_->TimeInMicroseconds()), | 124 random_(clock_->TimeInMicroseconds()), | 
| 135 bitrates_(new BitrateAggregator(bitrate_callback)), | 125 bitrates_(bitrate_callback), | 
| 136 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), | 126 total_bitrate_sent_(clock, bitrates_.total_bitrate_observer()), | 
| 137 audio_configured_(audio), | 127 audio_configured_(audio), | 
| 138 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), | 128 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), | 
| 139 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), | 129 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), | 
| 140 paced_sender_(paced_sender), | 130 paced_sender_(paced_sender), | 
| 141 transport_sequence_number_allocator_(sequence_number_allocator), | 131 transport_sequence_number_allocator_(sequence_number_allocator), | 
| 142 transport_feedback_observer_(transport_feedback_observer), | 132 transport_feedback_observer_(transport_feedback_observer), | 
| 143 last_capture_time_ms_sent_(0), | 133 last_capture_time_ms_sent_(0), | 
| 144 send_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 145 transport_(transport), | 134 transport_(transport), | 
| 146 sending_media_(true), // Default to sending media. | 135 sending_media_(true), // Default to sending media. | 
| 147 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. | 136 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. | 
| 148 packet_over_head_(28), | 137 packet_over_head_(28), | 
| 149 payload_type_(-1), | 138 payload_type_(-1), | 
| 150 payload_type_map_(), | 139 payload_type_map_(), | 
| 151 rtp_header_extension_map_(), | 140 rtp_header_extension_map_(), | 
| 152 transmission_time_offset_(0), | 141 transmission_time_offset_(0), | 
| 153 absolute_send_time_(0), | 142 absolute_send_time_(0), | 
| 154 rotation_(kVideoRotation_0), | 143 rotation_(kVideoRotation_0), | 
| 155 cvo_mode_(kCVONone), | 144 cvo_mode_(kCVONone), | 
| 156 transport_sequence_number_(0), | 145 transport_sequence_number_(0), | 
| 157 // NACK. | 146 // NACK. | 
| 158 nack_byte_count_times_(), | 147 nack_byte_count_times_(), | 
| 159 nack_byte_count_(), | 148 nack_byte_count_(), | 
| 160 nack_bitrate_(clock, bitrates_->retransmit_bitrate_observer()), | 149 nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()), | 
| 161 packet_history_(clock), | 150 packet_history_(clock), | 
| 162 // Statistics | 151 // Statistics | 
| 163 statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()), | 152 statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()), | 
| 164 rtp_stats_callback_(NULL), | 153 rtp_stats_callback_(NULL), | 
| 165 frame_count_observer_(frame_count_observer), | 154 frame_count_observer_(frame_count_observer), | 
| 166 send_side_delay_observer_(send_side_delay_observer), | 155 send_side_delay_observer_(send_side_delay_observer), | 
| 167 event_log_(event_log), | 156 event_log_(event_log), | 
| 168 // RTP variables | 157 // RTP variables | 
| 169 start_timestamp_forced_(false), | 158 start_timestamp_forced_(false), | 
| 170 start_timestamp_(0), | 159 start_timestamp_(0), | 
| 171 ssrc_db_(*SSRCDatabase::GetSSRCDatabase()), | 160 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), | 
| 172 remote_ssrc_(0), | 161 remote_ssrc_(0), | 
| 173 sequence_number_forced_(false), | 162 sequence_number_forced_(false), | 
| 174 ssrc_forced_(false), | 163 ssrc_forced_(false), | 
| 175 timestamp_(0), | 164 timestamp_(0), | 
| 176 capture_time_ms_(0), | 165 capture_time_ms_(0), | 
| 177 last_timestamp_time_ms_(0), | 166 last_timestamp_time_ms_(0), | 
| 178 media_has_been_sent_(false), | 167 media_has_been_sent_(false), | 
| 179 last_packet_marker_bit_(false), | 168 last_packet_marker_bit_(false), | 
| 180 csrcs_(), | 169 csrcs_(), | 
| 181 rtx_(kRtxOff), | 170 rtx_(kRtxOff), | 
| 182 rtx_payload_type_(-1), | 171 rtx_payload_type_(-1), | 
| 183 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 172 target_bitrate_critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 
| 184 target_bitrate_(0) { | 173 target_bitrate_(0) { | 
| 185 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); | 174 memset(nack_byte_count_times_, 0, sizeof(nack_byte_count_times_)); | 
| 186 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); | 175 memset(nack_byte_count_, 0, sizeof(nack_byte_count_)); | 
| 187 // We need to seed the random generator. | 176 // We need to seed the random generator for BuildPaddingPacket() below. | 
| 177 // TODO(holmer,tommi): Note that TimeInMilliseconds might return 0 on Mac | |
| 178 // early on in the process. | |
| 188 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); | 179 srand(static_cast<uint32_t>(clock_->TimeInMilliseconds())); | 
| 189 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 180 ssrc_ = ssrc_db_->CreateSSRC(); | 
| 190 ssrc_rtx_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 181 RTC_DCHECK(ssrc_); | 
| 191 bitrates_->set_ssrc(ssrc_); | 182 ssrc_rtx_ = ssrc_db_->CreateSSRC(); | 
| 183 RTC_DCHECK(ssrc_rtx_); | |
| 184 | |
| 185 bitrates_.set_ssrc(ssrc_); | |
| 192 // Random start, 16 bits. Can't be 0. | 186 // Random start, 16 bits. Can't be 0. | 
| 193 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 187 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 
| 194 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 188 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 
| 195 } | 189 } | 
| 196 | 190 | 
| 197 RTPSender::~RTPSender() { | 191 RTPSender::~RTPSender() { | 
| 192 // TODO(tommi): Use a thread checker to ensure the object is created and | |
| 193 // deleted on the same thread. At the moment this isn't possible due to | |
| 194 // voe::ChannelOwner in voice engine. To reproduce, run: | |
| 195 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus | |
| 196 | |
| 197 // TODO(tommi,holmer): We don't grab locks in the dtor before accessing member | |
| 198 // variables but we grab them in all other methods. (what's the design?) | |
| 199 // Start documenting what thread we're on in what method so that it's easier | |
| 200 // to understand performance attributes and possibly remove locks. | |
| 198 if (remote_ssrc_ != 0) { | 201 if (remote_ssrc_ != 0) { | 
| 199 ssrc_db_.ReturnSSRC(remote_ssrc_); | 202 ssrc_db_->ReturnSSRC(remote_ssrc_); | 
| 200 } | 203 } | 
| 201 ssrc_db_.ReturnSSRC(ssrc_); | 204 ssrc_db_->ReturnSSRC(ssrc_); | 
| 202 | 205 | 
| 203 SSRCDatabase::ReturnSSRCDatabase(); | 206 SSRCDatabase::ReturnSSRCDatabase(); | 
| 204 while (!payload_type_map_.empty()) { | 207 while (!payload_type_map_.empty()) { | 
| 205 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 208 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 
| 206 payload_type_map_.begin(); | 209 payload_type_map_.begin(); | 
| 207 delete it->second; | 210 delete it->second; | 
| 208 payload_type_map_.erase(it); | 211 payload_type_map_.erase(it); | 
| 209 } | 212 } | 
| 210 } | 213 } | 
| 211 | 214 | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 239 | 242 | 
| 240 uint32_t RTPSender::NackOverheadRate() const { | 243 uint32_t RTPSender::NackOverheadRate() const { | 
| 241 return nack_bitrate_.BitrateLast(); | 244 return nack_bitrate_.BitrateLast(); | 
| 242 } | 245 } | 
| 243 | 246 | 
| 244 int32_t RTPSender::SetTransmissionTimeOffset(int32_t transmission_time_offset) { | 247 int32_t RTPSender::SetTransmissionTimeOffset(int32_t transmission_time_offset) { | 
| 245 if (transmission_time_offset > (0x800000 - 1) || | 248 if (transmission_time_offset > (0x800000 - 1) || | 
| 246 transmission_time_offset < -(0x800000 - 1)) { // Word24. | 249 transmission_time_offset < -(0x800000 - 1)) { // Word24. | 
| 247 return -1; | 250 return -1; | 
| 248 } | 251 } | 
| 249 CriticalSectionScoped cs(send_critsect_.get()); | 252 rtc::CritScope lock(&send_critsect_); | 
| 250 transmission_time_offset_ = transmission_time_offset; | 253 transmission_time_offset_ = transmission_time_offset; | 
| 251 return 0; | 254 return 0; | 
| 252 } | 255 } | 
| 253 | 256 | 
| 254 int32_t RTPSender::SetAbsoluteSendTime(uint32_t absolute_send_time) { | 257 int32_t RTPSender::SetAbsoluteSendTime(uint32_t absolute_send_time) { | 
| 255 if (absolute_send_time > 0xffffff) { // UWord24. | 258 if (absolute_send_time > 0xffffff) { // UWord24. | 
| 256 return -1; | 259 return -1; | 
| 257 } | 260 } | 
| 258 CriticalSectionScoped cs(send_critsect_.get()); | 261 rtc::CritScope lock(&send_critsect_); | 
| 259 absolute_send_time_ = absolute_send_time; | 262 absolute_send_time_ = absolute_send_time; | 
| 260 return 0; | 263 return 0; | 
| 261 } | 264 } | 
| 262 | 265 | 
| 263 void RTPSender::SetVideoRotation(VideoRotation rotation) { | 266 void RTPSender::SetVideoRotation(VideoRotation rotation) { | 
| 264 CriticalSectionScoped cs(send_critsect_.get()); | 267 rtc::CritScope lock(&send_critsect_); | 
| 265 rotation_ = rotation; | 268 rotation_ = rotation; | 
| 266 } | 269 } | 
| 267 | 270 | 
| 268 int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) { | 271 int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) { | 
| 269 CriticalSectionScoped cs(send_critsect_.get()); | 272 rtc::CritScope lock(&send_critsect_); | 
| 270 transport_sequence_number_ = sequence_number; | 273 transport_sequence_number_ = sequence_number; | 
| 271 return 0; | 274 return 0; | 
| 272 } | 275 } | 
| 273 | 276 | 
| 274 int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type, | 277 int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type, | 
| 275 uint8_t id) { | 278 uint8_t id) { | 
| 276 CriticalSectionScoped cs(send_critsect_.get()); | 279 rtc::CritScope lock(&send_critsect_); | 
| 277 if (type == kRtpExtensionVideoRotation) { | 280 if (type == kRtpExtensionVideoRotation) { | 
| 278 cvo_mode_ = kCVOInactive; | 281 cvo_mode_ = kCVOInactive; | 
| 279 return rtp_header_extension_map_.RegisterInactive(type, id); | 282 return rtp_header_extension_map_.RegisterInactive(type, id); | 
| 280 } | 283 } | 
| 281 return rtp_header_extension_map_.Register(type, id); | 284 return rtp_header_extension_map_.Register(type, id); | 
| 282 } | 285 } | 
| 283 | 286 | 
| 284 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) { | 287 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) { | 
| 285 CriticalSectionScoped cs(send_critsect_.get()); | 288 rtc::CritScope lock(&send_critsect_); | 
| 286 return rtp_header_extension_map_.IsRegistered(type); | 289 return rtp_header_extension_map_.IsRegistered(type); | 
| 287 } | 290 } | 
| 288 | 291 | 
| 289 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { | 292 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { | 
| 290 CriticalSectionScoped cs(send_critsect_.get()); | 293 rtc::CritScope lock(&send_critsect_); | 
| 291 return rtp_header_extension_map_.Deregister(type); | 294 return rtp_header_extension_map_.Deregister(type); | 
| 292 } | 295 } | 
| 293 | 296 | 
| 294 size_t RTPSender::RtpHeaderExtensionTotalLength() const { | 297 size_t RTPSender::RtpHeaderExtensionTotalLength() const { | 
| 295 CriticalSectionScoped cs(send_critsect_.get()); | 298 rtc::CritScope lock(&send_critsect_); | 
| 296 return rtp_header_extension_map_.GetTotalLengthInBytes(); | 299 return rtp_header_extension_map_.GetTotalLengthInBytes(); | 
| 297 } | 300 } | 
| 298 | 301 | 
| 299 int32_t RTPSender::RegisterPayload( | 302 int32_t RTPSender::RegisterPayload( | 
| 300 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 303 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 
| 301 int8_t payload_number, | 304 int8_t payload_number, | 
| 302 uint32_t frequency, | 305 uint32_t frequency, | 
| 303 size_t channels, | 306 size_t channels, | 
| 304 uint32_t rate) { | 307 uint32_t rate) { | 
| 305 assert(payload_name); | 308 assert(payload_name); | 
| 306 CriticalSectionScoped cs(send_critsect_.get()); | 309 rtc::CritScope lock(&send_critsect_); | 
| 307 | 310 | 
| 308 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 311 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 
| 309 payload_type_map_.find(payload_number); | 312 payload_type_map_.find(payload_number); | 
| 310 | 313 | 
| 311 if (payload_type_map_.end() != it) { | 314 if (payload_type_map_.end() != it) { | 
| 312 // We already use this payload type. | 315 // We already use this payload type. | 
| 313 RtpUtility::Payload* payload = it->second; | 316 RtpUtility::Payload* payload = it->second; | 
| 314 assert(payload); | 317 assert(payload); | 
| 315 | 318 | 
| 316 // Check if it's the same as we already have. | 319 // Check if it's the same as we already have. | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 339 } else { | 342 } else { | 
| 340 payload = video_->CreateVideoPayload(payload_name, payload_number, rate); | 343 payload = video_->CreateVideoPayload(payload_name, payload_number, rate); | 
| 341 } | 344 } | 
| 342 if (payload) { | 345 if (payload) { | 
| 343 payload_type_map_[payload_number] = payload; | 346 payload_type_map_[payload_number] = payload; | 
| 344 } | 347 } | 
| 345 return ret_val; | 348 return ret_val; | 
| 346 } | 349 } | 
| 347 | 350 | 
| 348 int32_t RTPSender::DeRegisterSendPayload(int8_t payload_type) { | 351 int32_t RTPSender::DeRegisterSendPayload(int8_t payload_type) { | 
| 349 CriticalSectionScoped lock(send_critsect_.get()); | 352 rtc::CritScope lock(&send_critsect_); | 
| 350 | 353 | 
| 351 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 354 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 
| 352 payload_type_map_.find(payload_type); | 355 payload_type_map_.find(payload_type); | 
| 353 | 356 | 
| 354 if (payload_type_map_.end() == it) { | 357 if (payload_type_map_.end() == it) { | 
| 355 return -1; | 358 return -1; | 
| 356 } | 359 } | 
| 357 RtpUtility::Payload* payload = it->second; | 360 RtpUtility::Payload* payload = it->second; | 
| 358 delete payload; | 361 delete payload; | 
| 359 payload_type_map_.erase(it); | 362 payload_type_map_.erase(it); | 
| 360 return 0; | 363 return 0; | 
| 361 } | 364 } | 
| 362 | 365 | 
| 363 void RTPSender::SetSendPayloadType(int8_t payload_type) { | 366 void RTPSender::SetSendPayloadType(int8_t payload_type) { | 
| 364 CriticalSectionScoped cs(send_critsect_.get()); | 367 rtc::CritScope lock(&send_critsect_); | 
| 365 payload_type_ = payload_type; | 368 payload_type_ = payload_type; | 
| 366 } | 369 } | 
| 367 | 370 | 
| 368 int8_t RTPSender::SendPayloadType() const { | 371 int8_t RTPSender::SendPayloadType() const { | 
| 369 CriticalSectionScoped cs(send_critsect_.get()); | 372 rtc::CritScope lock(&send_critsect_); | 
| 370 return payload_type_; | 373 return payload_type_; | 
| 371 } | 374 } | 
| 372 | 375 | 
| 373 int RTPSender::SendPayloadFrequency() const { | 376 int RTPSender::SendPayloadFrequency() const { | 
| 374 return audio_ != NULL ? audio_->AudioFrequency() : kVideoPayloadTypeFrequency; | 377 return audio_ != NULL ? audio_->AudioFrequency() : kVideoPayloadTypeFrequency; | 
| 375 } | 378 } | 
| 376 | 379 | 
| 377 int32_t RTPSender::SetMaxPayloadLength(size_t max_payload_length, | 380 int32_t RTPSender::SetMaxPayloadLength(size_t max_payload_length, | 
| 378 uint16_t packet_over_head) { | 381 uint16_t packet_over_head) { | 
| 379 // Sanity check. | 382 // Sanity check. | 
| 380 RTC_DCHECK(max_payload_length >= 100 && max_payload_length <= IP_PACKET_SIZE) | 383 RTC_DCHECK(max_payload_length >= 100 && max_payload_length <= IP_PACKET_SIZE) | 
| 381 << "Invalid max payload length: " << max_payload_length; | 384 << "Invalid max payload length: " << max_payload_length; | 
| 382 CriticalSectionScoped cs(send_critsect_.get()); | 385 rtc::CritScope lock(&send_critsect_); | 
| 383 max_payload_length_ = max_payload_length; | 386 max_payload_length_ = max_payload_length; | 
| 384 packet_over_head_ = packet_over_head; | 387 packet_over_head_ = packet_over_head; | 
| 385 return 0; | 388 return 0; | 
| 386 } | 389 } | 
| 387 | 390 | 
| 388 size_t RTPSender::MaxDataPayloadLength() const { | 391 size_t RTPSender::MaxDataPayloadLength() const { | 
| 389 int rtx; | 392 int rtx; | 
| 390 { | 393 { | 
| 391 CriticalSectionScoped rtx_lock(send_critsect_.get()); | 394 rtc::CritScope lock(&send_critsect_); | 
| 392 rtx = rtx_; | 395 rtx = rtx_; | 
| 393 } | 396 } | 
| 394 if (audio_configured_) { | 397 if (audio_configured_) { | 
| 395 return max_payload_length_ - RTPHeaderLength(); | 398 return max_payload_length_ - RTPHeaderLength(); | 
| 396 } else { | 399 } else { | 
| 397 return max_payload_length_ - RTPHeaderLength() // RTP overhead. | 400 return max_payload_length_ - RTPHeaderLength() // RTP overhead. | 
| 398 - video_->FECPacketOverhead() // FEC/ULP/RED overhead. | 401 - video_->FECPacketOverhead() // FEC/ULP/RED overhead. | 
| 399 - ((rtx) ? 2 : 0); // RTX overhead. | 402 - ((rtx) ? 2 : 0); // RTX overhead. | 
| 400 } | 403 } | 
| 401 } | 404 } | 
| 402 | 405 | 
| 403 size_t RTPSender::MaxPayloadLength() const { | 406 size_t RTPSender::MaxPayloadLength() const { | 
| 404 return max_payload_length_; | 407 return max_payload_length_; | 
| 405 } | 408 } | 
| 406 | 409 | 
| 407 uint16_t RTPSender::PacketOverHead() const { return packet_over_head_; } | 410 uint16_t RTPSender::PacketOverHead() const { return packet_over_head_; } | 
| 408 | 411 | 
| 409 void RTPSender::SetRtxStatus(int mode) { | 412 void RTPSender::SetRtxStatus(int mode) { | 
| 410 CriticalSectionScoped cs(send_critsect_.get()); | 413 rtc::CritScope lock(&send_critsect_); | 
| 411 rtx_ = mode; | 414 rtx_ = mode; | 
| 412 } | 415 } | 
| 413 | 416 | 
| 414 int RTPSender::RtxStatus() const { | 417 int RTPSender::RtxStatus() const { | 
| 415 CriticalSectionScoped cs(send_critsect_.get()); | 418 rtc::CritScope lock(&send_critsect_); | 
| 416 return rtx_; | 419 return rtx_; | 
| 417 } | 420 } | 
| 418 | 421 | 
| 419 void RTPSender::SetRtxSsrc(uint32_t ssrc) { | 422 void RTPSender::SetRtxSsrc(uint32_t ssrc) { | 
| 420 CriticalSectionScoped cs(send_critsect_.get()); | 423 rtc::CritScope lock(&send_critsect_); | 
| 421 ssrc_rtx_ = ssrc; | 424 ssrc_rtx_ = ssrc; | 
| 422 } | 425 } | 
| 423 | 426 | 
| 424 uint32_t RTPSender::RtxSsrc() const { | 427 uint32_t RTPSender::RtxSsrc() const { | 
| 425 CriticalSectionScoped cs(send_critsect_.get()); | 428 rtc::CritScope lock(&send_critsect_); | 
| 426 return ssrc_rtx_; | 429 return ssrc_rtx_; | 
| 427 } | 430 } | 
| 428 | 431 | 
| 429 void RTPSender::SetRtxPayloadType(int payload_type, | 432 void RTPSender::SetRtxPayloadType(int payload_type, | 
| 430 int associated_payload_type) { | 433 int associated_payload_type) { | 
| 431 CriticalSectionScoped cs(send_critsect_.get()); | 434 rtc::CritScope lock(&send_critsect_); | 
| 432 RTC_DCHECK_LE(payload_type, 127); | 435 RTC_DCHECK_LE(payload_type, 127); | 
| 433 RTC_DCHECK_LE(associated_payload_type, 127); | 436 RTC_DCHECK_LE(associated_payload_type, 127); | 
| 434 if (payload_type < 0) { | 437 if (payload_type < 0) { | 
| 435 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; | 438 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; | 
| 436 return; | 439 return; | 
| 437 } | 440 } | 
| 438 | 441 | 
| 439 rtx_payload_type_map_[associated_payload_type] = payload_type; | 442 rtx_payload_type_map_[associated_payload_type] = payload_type; | 
| 440 rtx_payload_type_ = payload_type; | 443 rtx_payload_type_ = payload_type; | 
| 441 } | 444 } | 
| 442 | 445 | 
| 443 std::pair<int, int> RTPSender::RtxPayloadType() const { | 446 std::pair<int, int> RTPSender::RtxPayloadType() const { | 
| 444 CriticalSectionScoped cs(send_critsect_.get()); | 447 rtc::CritScope lock(&send_critsect_); | 
| 445 for (const auto& kv : rtx_payload_type_map_) { | 448 for (const auto& kv : rtx_payload_type_map_) { | 
| 446 if (kv.second == rtx_payload_type_) { | 449 if (kv.second == rtx_payload_type_) { | 
| 447 return std::make_pair(rtx_payload_type_, kv.first); | 450 return std::make_pair(rtx_payload_type_, kv.first); | 
| 448 } | 451 } | 
| 449 } | 452 } | 
| 450 return std::make_pair(-1, -1); | 453 return std::make_pair(-1, -1); | 
| 451 } | 454 } | 
| 452 | 455 | 
| 453 int32_t RTPSender::CheckPayloadType(int8_t payload_type, | 456 int32_t RTPSender::CheckPayloadType(int8_t payload_type, | 
| 454 RtpVideoCodecTypes* video_type) { | 457 RtpVideoCodecTypes* video_type) { | 
| 455 CriticalSectionScoped cs(send_critsect_.get()); | 458 rtc::CritScope lock(&send_critsect_); | 
| 456 | 459 | 
| 457 if (payload_type < 0) { | 460 if (payload_type < 0) { | 
| 458 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; | 461 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; | 
| 459 return -1; | 462 return -1; | 
| 460 } | 463 } | 
| 461 if (audio_configured_) { | 464 if (audio_configured_) { | 
| 462 int8_t red_pl_type = -1; | 465 int8_t red_pl_type = -1; | 
| 463 if (audio_->RED(&red_pl_type) == 0) { | 466 if (audio_->RED(&red_pl_type) == 0) { | 
| 464 // We have configured RED. | 467 // We have configured RED. | 
| 465 if (red_pl_type == payload_type) { | 468 if (red_pl_type == payload_type) { | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 487 if (!payload->audio && !audio_configured_) { | 490 if (!payload->audio && !audio_configured_) { | 
| 488 video_->SetVideoCodecType(payload->typeSpecific.Video.videoCodecType); | 491 video_->SetVideoCodecType(payload->typeSpecific.Video.videoCodecType); | 
| 489 *video_type = payload->typeSpecific.Video.videoCodecType; | 492 *video_type = payload->typeSpecific.Video.videoCodecType; | 
| 490 video_->SetMaxConfiguredBitrateVideo(payload->typeSpecific.Video.maxRate); | 493 video_->SetMaxConfiguredBitrateVideo(payload->typeSpecific.Video.maxRate); | 
| 491 } | 494 } | 
| 492 return 0; | 495 return 0; | 
| 493 } | 496 } | 
| 494 | 497 | 
| 495 RTPSenderInterface::CVOMode RTPSender::ActivateCVORtpHeaderExtension() { | 498 RTPSenderInterface::CVOMode RTPSender::ActivateCVORtpHeaderExtension() { | 
| 496 if (cvo_mode_ == kCVOInactive) { | 499 if (cvo_mode_ == kCVOInactive) { | 
| 497 CriticalSectionScoped cs(send_critsect_.get()); | 500 rtc::CritScope lock(&send_critsect_); | 
| 498 if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) { | 501 if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) { | 
| 499 cvo_mode_ = kCVOActivated; | 502 cvo_mode_ = kCVOActivated; | 
| 500 } | 503 } | 
| 501 } | 504 } | 
| 502 return cvo_mode_; | 505 return cvo_mode_; | 
| 503 } | 506 } | 
| 504 | 507 | 
| 505 int32_t RTPSender::SendOutgoingData(FrameType frame_type, | 508 int32_t RTPSender::SendOutgoingData(FrameType frame_type, | 
| 506 int8_t payload_type, | 509 int8_t payload_type, | 
| 507 uint32_t capture_timestamp, | 510 uint32_t capture_timestamp, | 
| 508 int64_t capture_time_ms, | 511 int64_t capture_time_ms, | 
| 509 const uint8_t* payload_data, | 512 const uint8_t* payload_data, | 
| 510 size_t payload_size, | 513 size_t payload_size, | 
| 511 const RTPFragmentationHeader* fragmentation, | 514 const RTPFragmentationHeader* fragmentation, | 
| 512 const RTPVideoHeader* rtp_hdr) { | 515 const RTPVideoHeader* rtp_hdr) { | 
| 513 uint32_t ssrc; | 516 uint32_t ssrc; | 
| 514 { | 517 { | 
| 515 // Drop this packet if we're not sending media packets. | 518 // Drop this packet if we're not sending media packets. | 
| 516 CriticalSectionScoped cs(send_critsect_.get()); | 519 rtc::CritScope lock(&send_critsect_); | 
| 517 ssrc = ssrc_; | 520 ssrc = ssrc_; | 
| 518 if (!sending_media_) { | 521 if (!sending_media_) { | 
| 519 return 0; | 522 return 0; | 
| 520 } | 523 } | 
| 521 } | 524 } | 
| 522 RtpVideoCodecTypes video_type = kRtpVideoGeneric; | 525 RtpVideoCodecTypes video_type = kRtpVideoGeneric; | 
| 523 if (CheckPayloadType(payload_type, &video_type) != 0) { | 526 if (CheckPayloadType(payload_type, &video_type) != 0) { | 
| 524 LOG(LS_ERROR) << "Don't send data with unknown payload type: " | 527 LOG(LS_ERROR) << "Don't send data with unknown payload type: " | 
| 525 << static_cast<int>(payload_type) << "."; | 528 << static_cast<int>(payload_type) << "."; | 
| 526 return -1; | 529 return -1; | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 } | 561 } | 
| 559 if (frame_count_observer_) { | 562 if (frame_count_observer_) { | 
| 560 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); | 563 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); | 
| 561 } | 564 } | 
| 562 | 565 | 
| 563 return ret_val; | 566 return ret_val; | 
| 564 } | 567 } | 
| 565 | 568 | 
| 566 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) { | 569 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) { | 
| 567 { | 570 { | 
| 568 CriticalSectionScoped cs(send_critsect_.get()); | 571 rtc::CritScope lock(&send_critsect_); | 
| 569 if ((rtx_ & kRtxRedundantPayloads) == 0) | 572 if ((rtx_ & kRtxRedundantPayloads) == 0) | 
| 570 return 0; | 573 return 0; | 
| 571 } | 574 } | 
| 572 | 575 | 
| 573 uint8_t buffer[IP_PACKET_SIZE]; | 576 uint8_t buffer[IP_PACKET_SIZE]; | 
| 574 int bytes_left = static_cast<int>(bytes_to_send); | 577 int bytes_left = static_cast<int>(bytes_to_send); | 
| 575 while (bytes_left > 0) { | 578 while (bytes_left > 0) { | 
| 576 size_t length = bytes_left; | 579 size_t length = bytes_left; | 
| 577 int64_t capture_time_ms; | 580 int64_t capture_time_ms; | 
| 578 if (!packet_history_.GetBestFittingPacket(buffer, &length, | 581 if (!packet_history_.GetBestFittingPacket(buffer, &length, | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 transport_sequence_number_allocator_; | 623 transport_sequence_number_allocator_; | 
| 621 for (; bytes > 0; bytes -= padding_bytes_in_packet) { | 624 for (; bytes > 0; bytes -= padding_bytes_in_packet) { | 
| 622 if (bytes < padding_bytes_in_packet) | 625 if (bytes < padding_bytes_in_packet) | 
| 623 bytes = padding_bytes_in_packet; | 626 bytes = padding_bytes_in_packet; | 
| 624 | 627 | 
| 625 uint32_t ssrc; | 628 uint32_t ssrc; | 
| 626 uint16_t sequence_number; | 629 uint16_t sequence_number; | 
| 627 int payload_type; | 630 int payload_type; | 
| 628 bool over_rtx; | 631 bool over_rtx; | 
| 629 { | 632 { | 
| 630 CriticalSectionScoped cs(send_critsect_.get()); | 633 rtc::CritScope lock(&send_critsect_); | 
| 631 if (!timestamp_provided) { | 634 if (!timestamp_provided) { | 
| 632 timestamp = timestamp_; | 635 timestamp = timestamp_; | 
| 633 capture_time_ms = capture_time_ms_; | 636 capture_time_ms = capture_time_ms_; | 
| 634 } | 637 } | 
| 635 if (rtx_ == kRtxOff) { | 638 if (rtx_ == kRtxOff) { | 
| 636 // Without RTX we can't send padding in the middle of frames. | 639 // Without RTX we can't send padding in the middle of frames. | 
| 637 if (!last_packet_marker_bit_) | 640 if (!last_packet_marker_bit_) | 
| 638 return 0; | 641 return 0; | 
| 639 ssrc = ssrc_; | 642 ssrc = ssrc_; | 
| 640 sequence_number = sequence_number_; | 643 sequence_number = sequence_number_; | 
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 // TickTime. | 737 // TickTime. | 
| 735 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_; | 738 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_; | 
| 736 paced_sender_->InsertPacket( | 739 paced_sender_->InsertPacket( | 
| 737 RtpPacketSender::kNormalPriority, header.ssrc, header.sequenceNumber, | 740 RtpPacketSender::kNormalPriority, header.ssrc, header.sequenceNumber, | 
| 738 corrected_capture_tims_ms, length - header.headerLength, true); | 741 corrected_capture_tims_ms, length - header.headerLength, true); | 
| 739 | 742 | 
| 740 return length; | 743 return length; | 
| 741 } | 744 } | 
| 742 int rtx = kRtxOff; | 745 int rtx = kRtxOff; | 
| 743 { | 746 { | 
| 744 CriticalSectionScoped lock(send_critsect_.get()); | 747 rtc::CritScope lock(&send_critsect_); | 
| 745 rtx = rtx_; | 748 rtx = rtx_; | 
| 746 } | 749 } | 
| 747 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, | 750 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, | 
| 748 (rtx & kRtxRetransmitted) > 0, true)) { | 751 (rtx & kRtxRetransmitted) > 0, true)) { | 
| 749 return -1; | 752 return -1; | 
| 750 } | 753 } | 
| 751 return static_cast<int32_t>(length); | 754 return static_cast<int32_t>(length); | 
| 752 } | 755 } | 
| 753 | 756 | 
| 754 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, | 757 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 UpdateNACKBitRate(bytes_re_sent, now); | 835 UpdateNACKBitRate(bytes_re_sent, now); | 
| 833 } | 836 } | 
| 834 } | 837 } | 
| 835 | 838 | 
| 836 bool RTPSender::ProcessNACKBitRate(uint32_t now) { | 839 bool RTPSender::ProcessNACKBitRate(uint32_t now) { | 
| 837 uint32_t num = 0; | 840 uint32_t num = 0; | 
| 838 size_t byte_count = 0; | 841 size_t byte_count = 0; | 
| 839 const uint32_t kAvgIntervalMs = 1000; | 842 const uint32_t kAvgIntervalMs = 1000; | 
| 840 uint32_t target_bitrate = GetTargetBitrate(); | 843 uint32_t target_bitrate = GetTargetBitrate(); | 
| 841 | 844 | 
| 842 CriticalSectionScoped cs(send_critsect_.get()); | 845 rtc::CritScope lock(&send_critsect_); | 
| 843 | 846 | 
| 844 if (target_bitrate == 0) { | 847 if (target_bitrate == 0) { | 
| 845 return true; | 848 return true; | 
| 846 } | 849 } | 
| 847 for (num = 0; num < NACK_BYTECOUNT_SIZE; ++num) { | 850 for (num = 0; num < NACK_BYTECOUNT_SIZE; ++num) { | 
| 848 if ((now - nack_byte_count_times_[num]) > kAvgIntervalMs) { | 851 if ((now - nack_byte_count_times_[num]) > kAvgIntervalMs) { | 
| 849 // Don't use data older than 1sec. | 852 // Don't use data older than 1sec. | 
| 850 break; | 853 break; | 
| 851 } else { | 854 } else { | 
| 852 byte_count += nack_byte_count_[num]; | 855 byte_count += nack_byte_count_[num]; | 
| 853 } | 856 } | 
| 854 } | 857 } | 
| 855 uint32_t time_interval = kAvgIntervalMs; | 858 uint32_t time_interval = kAvgIntervalMs; | 
| 856 if (num == NACK_BYTECOUNT_SIZE) { | 859 if (num == NACK_BYTECOUNT_SIZE) { | 
| 857 // More than NACK_BYTECOUNT_SIZE nack messages has been received | 860 // More than NACK_BYTECOUNT_SIZE nack messages has been received | 
| 858 // during the last msg_interval. | 861 // during the last msg_interval. | 
| 859 if (nack_byte_count_times_[num - 1] <= now) { | 862 if (nack_byte_count_times_[num - 1] <= now) { | 
| 860 time_interval = now - nack_byte_count_times_[num - 1]; | 863 time_interval = now - nack_byte_count_times_[num - 1]; | 
| 861 } | 864 } | 
| 862 } | 865 } | 
| 863 return (byte_count * 8) < (target_bitrate / 1000 * time_interval); | 866 return (byte_count * 8) < (target_bitrate / 1000 * time_interval); | 
| 864 } | 867 } | 
| 865 | 868 | 
| 866 void RTPSender::UpdateNACKBitRate(uint32_t bytes, int64_t now) { | 869 void RTPSender::UpdateNACKBitRate(uint32_t bytes, int64_t now) { | 
| 867 CriticalSectionScoped cs(send_critsect_.get()); | 870 rtc::CritScope lock(&send_critsect_); | 
| 868 if (bytes == 0) | 871 if (bytes == 0) | 
| 869 return; | 872 return; | 
| 870 nack_bitrate_.Update(bytes); | 873 nack_bitrate_.Update(bytes); | 
| 871 // Save bitrate statistics. | 874 // Save bitrate statistics. | 
| 872 // Shift all but first time. | 875 // Shift all but first time. | 
| 873 for (int i = NACK_BYTECOUNT_SIZE - 2; i >= 0; i--) { | 876 for (int i = NACK_BYTECOUNT_SIZE - 2; i >= 0; i--) { | 
| 874 nack_byte_count_[i + 1] = nack_byte_count_[i]; | 877 nack_byte_count_[i + 1] = nack_byte_count_[i]; | 
| 875 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; | 878 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; | 
| 876 } | 879 } | 
| 877 nack_byte_count_[0] = bytes; | 880 nack_byte_count_[0] = bytes; | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 893 &length, | 896 &length, | 
| 894 &stored_time_ms)) { | 897 &stored_time_ms)) { | 
| 895 // Packet cannot be found. Allow sending to continue. | 898 // Packet cannot be found. Allow sending to continue. | 
| 896 return true; | 899 return true; | 
| 897 } | 900 } | 
| 898 if (!retransmission && capture_time_ms > 0) { | 901 if (!retransmission && capture_time_ms > 0) { | 
| 899 UpdateDelayStatistics(capture_time_ms, clock_->TimeInMilliseconds()); | 902 UpdateDelayStatistics(capture_time_ms, clock_->TimeInMilliseconds()); | 
| 900 } | 903 } | 
| 901 int rtx; | 904 int rtx; | 
| 902 { | 905 { | 
| 903 CriticalSectionScoped lock(send_critsect_.get()); | 906 rtc::CritScope lock(&send_critsect_); | 
| 904 rtx = rtx_; | 907 rtx = rtx_; | 
| 905 } | 908 } | 
| 906 return PrepareAndSendPacket(data_buffer, | 909 return PrepareAndSendPacket(data_buffer, | 
| 907 length, | 910 length, | 
| 908 capture_time_ms, | 911 capture_time_ms, | 
| 909 retransmission && (rtx & kRtxRetransmitted) > 0, | 912 retransmission && (rtx & kRtxRetransmitted) > 0, | 
| 910 retransmission); | 913 retransmission); | 
| 911 } | 914 } | 
| 912 | 915 | 
| 913 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, | 916 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 options.packet_id = | 954 options.packet_id = | 
| 952 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header); | 955 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header); | 
| 953 } | 956 } | 
| 954 | 957 | 
| 955 if (using_transport_seq && transport_feedback_observer_) { | 958 if (using_transport_seq && transport_feedback_observer_) { | 
| 956 transport_feedback_observer_->AddPacket(options.packet_id, length, true); | 959 transport_feedback_observer_->AddPacket(options.packet_id, length, true); | 
| 957 } | 960 } | 
| 958 | 961 | 
| 959 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); | 962 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); | 
| 960 if (ret) { | 963 if (ret) { | 
| 961 CriticalSectionScoped lock(send_critsect_.get()); | 964 rtc::CritScope lock(&send_critsect_); | 
| 962 media_has_been_sent_ = true; | 965 media_has_been_sent_ = true; | 
| 963 } | 966 } | 
| 964 UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx, | 967 UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx, | 
| 965 is_retransmit); | 968 is_retransmit); | 
| 966 return ret; | 969 return ret; | 
| 967 } | 970 } | 
| 968 | 971 | 
| 969 void RTPSender::UpdateRtpStats(const uint8_t* buffer, | 972 void RTPSender::UpdateRtpStats(const uint8_t* buffer, | 
| 970 size_t packet_length, | 973 size_t packet_length, | 
| 971 const RTPHeader& header, | 974 const RTPHeader& header, | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); | 1014 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); | 
| 1012 return fec_enabled && | 1015 return fec_enabled && | 
| 1013 header.payloadType == pt_red && | 1016 header.payloadType == pt_red && | 
| 1014 buffer[header.headerLength] == pt_fec; | 1017 buffer[header.headerLength] == pt_fec; | 
| 1015 } | 1018 } | 
| 1016 | 1019 | 
| 1017 size_t RTPSender::TimeToSendPadding(size_t bytes) { | 1020 size_t RTPSender::TimeToSendPadding(size_t bytes) { | 
| 1018 if (audio_configured_ || bytes == 0) | 1021 if (audio_configured_ || bytes == 0) | 
| 1019 return 0; | 1022 return 0; | 
| 1020 { | 1023 { | 
| 1021 CriticalSectionScoped cs(send_critsect_.get()); | 1024 rtc::CritScope lock(&send_critsect_); | 
| 1022 if (!sending_media_) | 1025 if (!sending_media_) | 
| 1023 return 0; | 1026 return 0; | 
| 1024 } | 1027 } | 
| 1025 size_t bytes_sent = TrySendRedundantPayloads(bytes); | 1028 size_t bytes_sent = TrySendRedundantPayloads(bytes); | 
| 1026 if (bytes_sent < bytes) | 1029 if (bytes_sent < bytes) | 
| 1027 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); | 1030 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); | 
| 1028 return bytes_sent; | 1031 return bytes_sent; | 
| 1029 } | 1032 } | 
| 1030 | 1033 | 
| 1031 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 1034 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 | 1086 | 
| 1084 // Mark the packet as sent in the history even if send failed. Dropping a | 1087 // Mark the packet as sent in the history even if send failed. Dropping a | 
| 1085 // packet here should be treated as any other packet drop so we should be | 1088 // packet here should be treated as any other packet drop so we should be | 
| 1086 // ready for a retransmission. | 1089 // ready for a retransmission. | 
| 1087 packet_history_.SetSent(rtp_header.sequenceNumber); | 1090 packet_history_.SetSent(rtp_header.sequenceNumber); | 
| 1088 | 1091 | 
| 1089 if (!sent) | 1092 if (!sent) | 
| 1090 return -1; | 1093 return -1; | 
| 1091 | 1094 | 
| 1092 { | 1095 { | 
| 1093 CriticalSectionScoped lock(send_critsect_.get()); | 1096 rtc::CritScope lock(&send_critsect_); | 
| 1094 media_has_been_sent_ = true; | 1097 media_has_been_sent_ = true; | 
| 1095 } | 1098 } | 
| 1096 UpdateRtpStats(buffer, length, rtp_header, false, false); | 1099 UpdateRtpStats(buffer, length, rtp_header, false, false); | 
| 1097 return 0; | 1100 return 0; | 
| 1098 } | 1101 } | 
| 1099 | 1102 | 
| 1100 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 1103 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 
| 1101 if (!send_side_delay_observer_) | 1104 if (!send_side_delay_observer_) | 
| 1102 return; | 1105 return; | 
| 1103 | 1106 | 
| 1104 uint32_t ssrc; | 1107 uint32_t ssrc; | 
| 1105 int avg_delay_ms = 0; | 1108 int avg_delay_ms = 0; | 
| 1106 int max_delay_ms = 0; | 1109 int max_delay_ms = 0; | 
| 1107 { | 1110 { | 
| 1108 CriticalSectionScoped lock(send_critsect_.get()); | 1111 rtc::CritScope lock(&send_critsect_); | 
| 1109 ssrc = ssrc_; | 1112 ssrc = ssrc_; | 
| 1110 } | 1113 } | 
| 1111 { | 1114 { | 
| 1112 CriticalSectionScoped cs(statistics_crit_.get()); | 1115 CriticalSectionScoped cs(statistics_crit_.get()); | 
| 1113 // TODO(holmer): Compute this iteratively instead. | 1116 // TODO(holmer): Compute this iteratively instead. | 
| 1114 send_delays_[now_ms] = now_ms - capture_time_ms; | 1117 send_delays_[now_ms] = now_ms - capture_time_ms; | 
| 1115 send_delays_.erase(send_delays_.begin(), | 1118 send_delays_.erase(send_delays_.begin(), | 
| 1116 send_delays_.lower_bound(now_ms - | 1119 send_delays_.lower_bound(now_ms - | 
| 1117 kSendSideDelayWindowMs)); | 1120 kSendSideDelayWindowMs)); | 
| 1118 int num_delays = 0; | 1121 int num_delays = 0; | 
| 1119 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs); | 1122 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs); | 
| 1120 it != send_delays_.end(); ++it) { | 1123 it != send_delays_.end(); ++it) { | 
| 1121 max_delay_ms = std::max(max_delay_ms, it->second); | 1124 max_delay_ms = std::max(max_delay_ms, it->second); | 
| 1122 avg_delay_ms += it->second; | 1125 avg_delay_ms += it->second; | 
| 1123 ++num_delays; | 1126 ++num_delays; | 
| 1124 } | 1127 } | 
| 1125 if (num_delays == 0) | 1128 if (num_delays == 0) | 
| 1126 return; | 1129 return; | 
| 1127 avg_delay_ms = (avg_delay_ms + num_delays / 2) / num_delays; | 1130 avg_delay_ms = (avg_delay_ms + num_delays / 2) / num_delays; | 
| 1128 } | 1131 } | 
| 1129 send_side_delay_observer_->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, | 1132 send_side_delay_observer_->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, | 
| 1130 ssrc); | 1133 ssrc); | 
| 1131 } | 1134 } | 
| 1132 | 1135 | 
| 1133 void RTPSender::ProcessBitrate() { | 1136 void RTPSender::ProcessBitrate() { | 
| 1134 CriticalSectionScoped cs(send_critsect_.get()); | 1137 rtc::CritScope lock(&send_critsect_); | 
| 1135 total_bitrate_sent_.Process(); | 1138 total_bitrate_sent_.Process(); | 
| 1136 nack_bitrate_.Process(); | 1139 nack_bitrate_.Process(); | 
| 1137 if (audio_configured_) { | 1140 if (audio_configured_) { | 
| 1138 return; | 1141 return; | 
| 1139 } | 1142 } | 
| 1140 video_->ProcessBitrate(); | 1143 video_->ProcessBitrate(); | 
| 1141 } | 1144 } | 
| 1142 | 1145 | 
| 1143 size_t RTPSender::RTPHeaderLength() const { | 1146 size_t RTPSender::RTPHeaderLength() const { | 
| 1144 CriticalSectionScoped lock(send_critsect_.get()); | 1147 rtc::CritScope lock(&send_critsect_); | 
| 1145 size_t rtp_header_length = kRtpHeaderLength; | 1148 size_t rtp_header_length = kRtpHeaderLength; | 
| 1146 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); | 1149 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); | 
| 1147 rtp_header_length += RtpHeaderExtensionTotalLength(); | 1150 rtp_header_length += RtpHeaderExtensionTotalLength(); | 
| 1148 return rtp_header_length; | 1151 return rtp_header_length; | 
| 1149 } | 1152 } | 
| 1150 | 1153 | 
| 1151 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { | 1154 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { | 
| 1152 CriticalSectionScoped cs(send_critsect_.get()); | 1155 rtc::CritScope lock(&send_critsect_); | 
| 1153 uint16_t first_allocated_sequence_number = sequence_number_; | 1156 uint16_t first_allocated_sequence_number = sequence_number_; | 
| 1154 sequence_number_ += packets_to_send; | 1157 sequence_number_ += packets_to_send; | 
| 1155 return first_allocated_sequence_number; | 1158 return first_allocated_sequence_number; | 
| 1156 } | 1159 } | 
| 1157 | 1160 | 
| 1158 void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats, | 1161 void RTPSender::GetDataCounters(StreamDataCounters* rtp_stats, | 
| 1159 StreamDataCounters* rtx_stats) const { | 1162 StreamDataCounters* rtx_stats) const { | 
| 1160 CriticalSectionScoped lock(statistics_crit_.get()); | 1163 CriticalSectionScoped lock(statistics_crit_.get()); | 
| 1161 *rtp_stats = rtp_stats_; | 1164 *rtp_stats = rtp_stats_; | 
| 1162 *rtx_stats = rtx_rtp_stats_; | 1165 *rtx_stats = rtx_rtp_stats_; | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 } | 1204 } | 
| 1202 | 1205 | 
| 1203 int32_t RTPSender::BuildRTPheader(uint8_t* data_buffer, | 1206 int32_t RTPSender::BuildRTPheader(uint8_t* data_buffer, | 
| 1204 int8_t payload_type, | 1207 int8_t payload_type, | 
| 1205 bool marker_bit, | 1208 bool marker_bit, | 
| 1206 uint32_t capture_timestamp, | 1209 uint32_t capture_timestamp, | 
| 1207 int64_t capture_time_ms, | 1210 int64_t capture_time_ms, | 
| 1208 bool timestamp_provided, | 1211 bool timestamp_provided, | 
| 1209 bool inc_sequence_number) { | 1212 bool inc_sequence_number) { | 
| 1210 assert(payload_type >= 0); | 1213 assert(payload_type >= 0); | 
| 1211 CriticalSectionScoped cs(send_critsect_.get()); | 1214 rtc::CritScope lock(&send_critsect_); | 
| 1212 | 1215 | 
| 1213 if (timestamp_provided) { | 1216 if (timestamp_provided) { | 
| 1214 timestamp_ = start_timestamp_ + capture_timestamp; | 1217 timestamp_ = start_timestamp_ + capture_timestamp; | 
| 1215 } else { | 1218 } else { | 
| 1216 // Make a unique time stamp. | 1219 // Make a unique time stamp. | 
| 1217 // We can't inc by the actual time, since then we increase the risk of back | 1220 // We can't inc by the actual time, since then we increase the risk of back | 
| 1218 // timing. | 1221 // timing. | 
| 1219 timestamp_++; | 1222 timestamp_++; | 
| 1220 } | 1223 } | 
| 1221 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); | 1224 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); | 
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1508 | 1511 | 
| 1509 *extension_offset = block_pos; | 1512 *extension_offset = block_pos; | 
| 1510 return ExtensionStatus::kOk; | 1513 return ExtensionStatus::kOk; | 
| 1511 } | 1514 } | 
| 1512 | 1515 | 
| 1513 void RTPSender::UpdateTransmissionTimeOffset(uint8_t* rtp_packet, | 1516 void RTPSender::UpdateTransmissionTimeOffset(uint8_t* rtp_packet, | 
| 1514 size_t rtp_packet_length, | 1517 size_t rtp_packet_length, | 
| 1515 const RTPHeader& rtp_header, | 1518 const RTPHeader& rtp_header, | 
| 1516 int64_t time_diff_ms) const { | 1519 int64_t time_diff_ms) const { | 
| 1517 size_t offset; | 1520 size_t offset; | 
| 1518 CriticalSectionScoped cs(send_critsect_.get()); | 1521 rtc::CritScope lock(&send_critsect_); | 
| 1519 switch (VerifyExtension(kRtpExtensionTransmissionTimeOffset, rtp_packet, | 1522 switch (VerifyExtension(kRtpExtensionTransmissionTimeOffset, rtp_packet, | 
| 1520 rtp_packet_length, rtp_header, | 1523 rtp_packet_length, rtp_header, | 
| 1521 kTransmissionTimeOffsetLength, &offset)) { | 1524 kTransmissionTimeOffsetLength, &offset)) { | 
| 1522 case ExtensionStatus::kNotRegistered: | 1525 case ExtensionStatus::kNotRegistered: | 
| 1523 return; | 1526 return; | 
| 1524 case ExtensionStatus::kError: | 1527 case ExtensionStatus::kError: | 
| 1525 LOG(LS_WARNING) << "Failed to update transmission time offset."; | 1528 LOG(LS_WARNING) << "Failed to update transmission time offset."; | 
| 1526 return; | 1529 return; | 
| 1527 case ExtensionStatus::kOk: | 1530 case ExtensionStatus::kOk: | 
| 1528 break; | 1531 break; | 
| 1529 default: | 1532 default: | 
| 1530 RTC_NOTREACHED(); | 1533 RTC_NOTREACHED(); | 
| 1531 } | 1534 } | 
| 1532 | 1535 | 
| 1533 // Update transmission offset field (converting to a 90 kHz timestamp). | 1536 // Update transmission offset field (converting to a 90 kHz timestamp). | 
| 1534 ByteWriter<int32_t, 3>::WriteBigEndian(rtp_packet + offset + 1, | 1537 ByteWriter<int32_t, 3>::WriteBigEndian(rtp_packet + offset + 1, | 
| 1535 time_diff_ms * 90); // RTP timestamp. | 1538 time_diff_ms * 90); // RTP timestamp. | 
| 1536 } | 1539 } | 
| 1537 | 1540 | 
| 1538 bool RTPSender::UpdateAudioLevel(uint8_t* rtp_packet, | 1541 bool RTPSender::UpdateAudioLevel(uint8_t* rtp_packet, | 
| 1539 size_t rtp_packet_length, | 1542 size_t rtp_packet_length, | 
| 1540 const RTPHeader& rtp_header, | 1543 const RTPHeader& rtp_header, | 
| 1541 bool is_voiced, | 1544 bool is_voiced, | 
| 1542 uint8_t dBov) const { | 1545 uint8_t dBov) const { | 
| 1543 size_t offset; | 1546 size_t offset; | 
| 1544 CriticalSectionScoped cs(send_critsect_.get()); | 1547 rtc::CritScope lock(&send_critsect_); | 
| 1545 | 1548 | 
| 1546 switch (VerifyExtension(kRtpExtensionAudioLevel, rtp_packet, | 1549 switch (VerifyExtension(kRtpExtensionAudioLevel, rtp_packet, | 
| 1547 rtp_packet_length, rtp_header, kAudioLevelLength, | 1550 rtp_packet_length, rtp_header, kAudioLevelLength, | 
| 1548 &offset)) { | 1551 &offset)) { | 
| 1549 case ExtensionStatus::kNotRegistered: | 1552 case ExtensionStatus::kNotRegistered: | 
| 1550 return false; | 1553 return false; | 
| 1551 case ExtensionStatus::kError: | 1554 case ExtensionStatus::kError: | 
| 1552 LOG(LS_WARNING) << "Failed to update audio level."; | 1555 LOG(LS_WARNING) << "Failed to update audio level."; | 
| 1553 return false; | 1556 return false; | 
| 1554 case ExtensionStatus::kOk: | 1557 case ExtensionStatus::kOk: | 
| 1555 break; | 1558 break; | 
| 1556 default: | 1559 default: | 
| 1557 RTC_NOTREACHED(); | 1560 RTC_NOTREACHED(); | 
| 1558 } | 1561 } | 
| 1559 | 1562 | 
| 1560 rtp_packet[offset + 1] = (is_voiced ? 0x80 : 0x00) + (dBov & 0x7f); | 1563 rtp_packet[offset + 1] = (is_voiced ? 0x80 : 0x00) + (dBov & 0x7f); | 
| 1561 return true; | 1564 return true; | 
| 1562 } | 1565 } | 
| 1563 | 1566 | 
| 1564 bool RTPSender::UpdateVideoRotation(uint8_t* rtp_packet, | 1567 bool RTPSender::UpdateVideoRotation(uint8_t* rtp_packet, | 
| 1565 size_t rtp_packet_length, | 1568 size_t rtp_packet_length, | 
| 1566 const RTPHeader& rtp_header, | 1569 const RTPHeader& rtp_header, | 
| 1567 VideoRotation rotation) const { | 1570 VideoRotation rotation) const { | 
| 1568 size_t offset; | 1571 size_t offset; | 
| 1569 CriticalSectionScoped cs(send_critsect_.get()); | 1572 rtc::CritScope lock(&send_critsect_); | 
| 1570 | 1573 | 
| 1571 switch (VerifyExtension(kRtpExtensionVideoRotation, rtp_packet, | 1574 switch (VerifyExtension(kRtpExtensionVideoRotation, rtp_packet, | 
| 1572 rtp_packet_length, rtp_header, kVideoRotationLength, | 1575 rtp_packet_length, rtp_header, kVideoRotationLength, | 
| 1573 &offset)) { | 1576 &offset)) { | 
| 1574 case ExtensionStatus::kNotRegistered: | 1577 case ExtensionStatus::kNotRegistered: | 
| 1575 return false; | 1578 return false; | 
| 1576 case ExtensionStatus::kError: | 1579 case ExtensionStatus::kError: | 
| 1577 LOG(LS_WARNING) << "Failed to update CVO."; | 1580 LOG(LS_WARNING) << "Failed to update CVO."; | 
| 1578 return false; | 1581 return false; | 
| 1579 case ExtensionStatus::kOk: | 1582 case ExtensionStatus::kOk: | 
| 1580 break; | 1583 break; | 
| 1581 default: | 1584 default: | 
| 1582 RTC_NOTREACHED(); | 1585 RTC_NOTREACHED(); | 
| 1583 } | 1586 } | 
| 1584 | 1587 | 
| 1585 rtp_packet[offset + 1] = ConvertVideoRotationToCVOByte(rotation); | 1588 rtp_packet[offset + 1] = ConvertVideoRotationToCVOByte(rotation); | 
| 1586 return true; | 1589 return true; | 
| 1587 } | 1590 } | 
| 1588 | 1591 | 
| 1589 void RTPSender::UpdateAbsoluteSendTime(uint8_t* rtp_packet, | 1592 void RTPSender::UpdateAbsoluteSendTime(uint8_t* rtp_packet, | 
| 1590 size_t rtp_packet_length, | 1593 size_t rtp_packet_length, | 
| 1591 const RTPHeader& rtp_header, | 1594 const RTPHeader& rtp_header, | 
| 1592 int64_t now_ms) const { | 1595 int64_t now_ms) const { | 
| 1593 size_t offset; | 1596 size_t offset; | 
| 1594 CriticalSectionScoped cs(send_critsect_.get()); | 1597 rtc::CritScope lock(&send_critsect_); | 
| 1595 | 1598 | 
| 1596 switch (VerifyExtension(kRtpExtensionAbsoluteSendTime, rtp_packet, | 1599 switch (VerifyExtension(kRtpExtensionAbsoluteSendTime, rtp_packet, | 
| 1597 rtp_packet_length, rtp_header, | 1600 rtp_packet_length, rtp_header, | 
| 1598 kAbsoluteSendTimeLength, &offset)) { | 1601 kAbsoluteSendTimeLength, &offset)) { | 
| 1599 case ExtensionStatus::kNotRegistered: | 1602 case ExtensionStatus::kNotRegistered: | 
| 1600 return; | 1603 return; | 
| 1601 case ExtensionStatus::kError: | 1604 case ExtensionStatus::kError: | 
| 1602 LOG(LS_WARNING) << "Failed to update absolute send time"; | 1605 LOG(LS_WARNING) << "Failed to update absolute send time"; | 
| 1603 return; | 1606 return; | 
| 1604 case ExtensionStatus::kOk: | 1607 case ExtensionStatus::kOk: | 
| 1605 break; | 1608 break; | 
| 1606 default: | 1609 default: | 
| 1607 RTC_NOTREACHED(); | 1610 RTC_NOTREACHED(); | 
| 1608 } | 1611 } | 
| 1609 | 1612 | 
| 1610 // Update absolute send time field (convert ms to 24-bit unsigned with 18 bit | 1613 // Update absolute send time field (convert ms to 24-bit unsigned with 18 bit | 
| 1611 // fractional part). | 1614 // fractional part). | 
| 1612 ByteWriter<uint32_t, 3>::WriteBigEndian(rtp_packet + offset + 1, | 1615 ByteWriter<uint32_t, 3>::WriteBigEndian(rtp_packet + offset + 1, | 
| 1613 ConvertMsTo24Bits(now_ms)); | 1616 ConvertMsTo24Bits(now_ms)); | 
| 1614 } | 1617 } | 
| 1615 | 1618 | 
| 1616 uint16_t RTPSender::UpdateTransportSequenceNumber( | 1619 uint16_t RTPSender::UpdateTransportSequenceNumber( | 
| 1617 uint8_t* rtp_packet, | 1620 uint8_t* rtp_packet, | 
| 1618 size_t rtp_packet_length, | 1621 size_t rtp_packet_length, | 
| 1619 const RTPHeader& rtp_header) const { | 1622 const RTPHeader& rtp_header) const { | 
| 1620 size_t offset; | 1623 size_t offset; | 
| 1621 CriticalSectionScoped cs(send_critsect_.get()); | 1624 rtc::CritScope lock(&send_critsect_); | 
| 1622 | 1625 | 
| 1623 switch (VerifyExtension(kRtpExtensionTransportSequenceNumber, rtp_packet, | 1626 switch (VerifyExtension(kRtpExtensionTransportSequenceNumber, rtp_packet, | 
| 1624 rtp_packet_length, rtp_header, | 1627 rtp_packet_length, rtp_header, | 
| 1625 kTransportSequenceNumberLength, &offset)) { | 1628 kTransportSequenceNumberLength, &offset)) { | 
| 1626 case ExtensionStatus::kNotRegistered: | 1629 case ExtensionStatus::kNotRegistered: | 
| 1627 return 0; | 1630 return 0; | 
| 1628 case ExtensionStatus::kError: | 1631 case ExtensionStatus::kError: | 
| 1629 LOG(LS_WARNING) << "Failed to update transport sequence number"; | 1632 LOG(LS_WARNING) << "Failed to update transport sequence number"; | 
| 1630 return 0; | 1633 return 0; | 
| 1631 case ExtensionStatus::kOk: | 1634 case ExtensionStatus::kOk: | 
| 1632 break; | 1635 break; | 
| 1633 default: | 1636 default: | 
| 1634 RTC_NOTREACHED(); | 1637 RTC_NOTREACHED(); | 
| 1635 } | 1638 } | 
| 1636 | 1639 | 
| 1637 uint16_t seq = transport_sequence_number_allocator_->AllocateSequenceNumber(); | 1640 uint16_t seq = transport_sequence_number_allocator_->AllocateSequenceNumber(); | 
| 1638 BuildTransportSequenceNumberExtension(rtp_packet + offset, seq); | 1641 BuildTransportSequenceNumberExtension(rtp_packet + offset, seq); | 
| 1639 return seq; | 1642 return seq; | 
| 1640 } | 1643 } | 
| 1641 | 1644 | 
| 1642 void RTPSender::SetSendingStatus(bool enabled) { | 1645 void RTPSender::SetSendingStatus(bool enabled) { | 
| 1643 if (enabled) { | 1646 if (enabled) { | 
| 1644 uint32_t frequency_hz = SendPayloadFrequency(); | 1647 uint32_t frequency_hz = SendPayloadFrequency(); | 
| 1645 uint32_t RTPtime = CurrentRtp(*clock_, frequency_hz); | 1648 uint32_t RTPtime = CurrentRtp(*clock_, frequency_hz); | 
| 1646 | 1649 | 
| 1647 // Will be ignored if it's already configured via API. | 1650 // Will be ignored if it's already configured via API. | 
| 1648 SetStartTimestamp(RTPtime, false); | 1651 SetStartTimestamp(RTPtime, false); | 
| 1649 } else { | 1652 } else { | 
| 1650 CriticalSectionScoped lock(send_critsect_.get()); | 1653 rtc::CritScope lock(&send_critsect_); | 
| 1651 if (!ssrc_forced_) { | 1654 if (!ssrc_forced_) { | 
| 1652 // Generate a new SSRC. | 1655 // Generate a new SSRC. | 
| 1653 ssrc_db_.ReturnSSRC(ssrc_); | 1656 ssrc_db_->ReturnSSRC(ssrc_); | 
| 1654 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 1657 ssrc_ = ssrc_db_->CreateSSRC(); | 
| 1655 bitrates_->set_ssrc(ssrc_); | 1658 RTC_DCHECK(ssrc_); | 
| 
stefan-webrtc
2016/01/26 13:19:52
I prefer > 0 or != 0.
 
tommi
2016/01/30 10:53:41
Done.
 | |
| 1659 bitrates_.set_ssrc(ssrc_); | |
| 1656 } | 1660 } | 
| 1657 // Don't initialize seq number if SSRC passed externally. | 1661 // Don't initialize seq number if SSRC passed externally. | 
| 1658 if (!sequence_number_forced_ && !ssrc_forced_) { | 1662 if (!sequence_number_forced_ && !ssrc_forced_) { | 
| 1659 // Generate a new sequence number. | 1663 // Generate a new sequence number. | 
| 1660 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 1664 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 
| 1661 } | 1665 } | 
| 1662 } | 1666 } | 
| 1663 } | 1667 } | 
| 1664 | 1668 | 
| 1665 void RTPSender::SetSendingMediaStatus(bool enabled) { | 1669 void RTPSender::SetSendingMediaStatus(bool enabled) { | 
| 1666 CriticalSectionScoped cs(send_critsect_.get()); | 1670 rtc::CritScope lock(&send_critsect_); | 
| 1667 sending_media_ = enabled; | 1671 sending_media_ = enabled; | 
| 1668 } | 1672 } | 
| 1669 | 1673 | 
| 1670 bool RTPSender::SendingMedia() const { | 1674 bool RTPSender::SendingMedia() const { | 
| 1671 CriticalSectionScoped cs(send_critsect_.get()); | 1675 rtc::CritScope lock(&send_critsect_); | 
| 1672 return sending_media_; | 1676 return sending_media_; | 
| 1673 } | 1677 } | 
| 1674 | 1678 | 
| 1675 uint32_t RTPSender::Timestamp() const { | 1679 uint32_t RTPSender::Timestamp() const { | 
| 1676 CriticalSectionScoped cs(send_critsect_.get()); | 1680 rtc::CritScope lock(&send_critsect_); | 
| 1677 return timestamp_; | 1681 return timestamp_; | 
| 1678 } | 1682 } | 
| 1679 | 1683 | 
| 1680 void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) { | 1684 void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) { | 
| 1681 CriticalSectionScoped cs(send_critsect_.get()); | 1685 rtc::CritScope lock(&send_critsect_); | 
| 1682 if (force) { | 1686 if (force) { | 
| 1683 start_timestamp_forced_ = true; | 1687 start_timestamp_forced_ = true; | 
| 1684 start_timestamp_ = timestamp; | 1688 start_timestamp_ = timestamp; | 
| 1685 } else { | 1689 } else { | 
| 1686 if (!start_timestamp_forced_) { | 1690 if (!start_timestamp_forced_) { | 
| 1687 start_timestamp_ = timestamp; | 1691 start_timestamp_ = timestamp; | 
| 1688 } | 1692 } | 
| 1689 } | 1693 } | 
| 1690 } | 1694 } | 
| 1691 | 1695 | 
| 1692 uint32_t RTPSender::StartTimestamp() const { | 1696 uint32_t RTPSender::StartTimestamp() const { | 
| 1693 CriticalSectionScoped cs(send_critsect_.get()); | 1697 rtc::CritScope lock(&send_critsect_); | 
| 1694 return start_timestamp_; | 1698 return start_timestamp_; | 
| 1695 } | 1699 } | 
| 1696 | 1700 | 
| 1697 uint32_t RTPSender::GenerateNewSSRC() { | 1701 uint32_t RTPSender::GenerateNewSSRC() { | 
| 1698 // If configured via API, return 0. | 1702 // If configured via API, return 0. | 
| 1699 CriticalSectionScoped cs(send_critsect_.get()); | 1703 rtc::CritScope lock(&send_critsect_); | 
| 1700 | 1704 | 
| 1701 if (ssrc_forced_) { | 1705 if (ssrc_forced_) { | 
| 1702 return 0; | 1706 return 0; | 
| 1703 } | 1707 } | 
| 1704 ssrc_ = ssrc_db_.CreateSSRC(); // Can't be 0. | 1708 ssrc_ = ssrc_db_->CreateSSRC(); | 
| 1705 bitrates_->set_ssrc(ssrc_); | 1709 RTC_DCHECK(ssrc_); | 
| 
stefan-webrtc
2016/01/26 13:19:52
same here
 
tommi
2016/01/30 10:53:41
Done.
 | |
| 1710 bitrates_.set_ssrc(ssrc_); | |
| 1706 return ssrc_; | 1711 return ssrc_; | 
| 1707 } | 1712 } | 
| 1708 | 1713 | 
| 1709 void RTPSender::SetSSRC(uint32_t ssrc) { | 1714 void RTPSender::SetSSRC(uint32_t ssrc) { | 
| 1710 // This is configured via the API. | 1715 // This is configured via the API. | 
| 1711 CriticalSectionScoped cs(send_critsect_.get()); | 1716 rtc::CritScope lock(&send_critsect_); | 
| 1712 | 1717 | 
| 1713 if (ssrc_ == ssrc && ssrc_forced_) { | 1718 if (ssrc_ == ssrc && ssrc_forced_) { | 
| 1714 return; // Since it's same ssrc, don't reset anything. | 1719 return; // Since it's same ssrc, don't reset anything. | 
| 1715 } | 1720 } | 
| 1716 ssrc_forced_ = true; | 1721 ssrc_forced_ = true; | 
| 1717 ssrc_db_.ReturnSSRC(ssrc_); | 1722 ssrc_db_->ReturnSSRC(ssrc_); | 
| 1718 ssrc_db_.RegisterSSRC(ssrc); | 1723 ssrc_db_->RegisterSSRC(ssrc); | 
| 1719 ssrc_ = ssrc; | 1724 ssrc_ = ssrc; | 
| 1720 bitrates_->set_ssrc(ssrc_); | 1725 bitrates_.set_ssrc(ssrc_); | 
| 1721 if (!sequence_number_forced_) { | 1726 if (!sequence_number_forced_) { | 
| 1722 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 1727 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 
| 1723 } | 1728 } | 
| 1724 } | 1729 } | 
| 1725 | 1730 | 
| 1726 uint32_t RTPSender::SSRC() const { | 1731 uint32_t RTPSender::SSRC() const { | 
| 1727 CriticalSectionScoped cs(send_critsect_.get()); | 1732 rtc::CritScope lock(&send_critsect_); | 
| 1728 return ssrc_; | 1733 return ssrc_; | 
| 1729 } | 1734 } | 
| 1730 | 1735 | 
| 1731 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 1736 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 
| 1732 assert(csrcs.size() <= kRtpCsrcSize); | 1737 assert(csrcs.size() <= kRtpCsrcSize); | 
| 1733 CriticalSectionScoped cs(send_critsect_.get()); | 1738 rtc::CritScope lock(&send_critsect_); | 
| 1734 csrcs_ = csrcs; | 1739 csrcs_ = csrcs; | 
| 1735 } | 1740 } | 
| 1736 | 1741 | 
| 1737 void RTPSender::SetSequenceNumber(uint16_t seq) { | 1742 void RTPSender::SetSequenceNumber(uint16_t seq) { | 
| 1738 CriticalSectionScoped cs(send_critsect_.get()); | 1743 rtc::CritScope lock(&send_critsect_); | 
| 1739 sequence_number_forced_ = true; | 1744 sequence_number_forced_ = true; | 
| 1740 sequence_number_ = seq; | 1745 sequence_number_ = seq; | 
| 1741 } | 1746 } | 
| 1742 | 1747 | 
| 1743 uint16_t RTPSender::SequenceNumber() const { | 1748 uint16_t RTPSender::SequenceNumber() const { | 
| 1744 CriticalSectionScoped cs(send_critsect_.get()); | 1749 rtc::CritScope lock(&send_critsect_); | 
| 1745 return sequence_number_; | 1750 return sequence_number_; | 
| 1746 } | 1751 } | 
| 1747 | 1752 | 
| 1748 // Audio. | 1753 // Audio. | 
| 1749 int32_t RTPSender::SendTelephoneEvent(uint8_t key, | 1754 int32_t RTPSender::SendTelephoneEvent(uint8_t key, | 
| 1750 uint16_t time_ms, | 1755 uint16_t time_ms, | 
| 1751 uint8_t level) { | 1756 uint8_t level) { | 
| 1752 if (!audio_configured_) { | 1757 if (!audio_configured_) { | 
| 1753 return -1; | 1758 return -1; | 
| 1754 } | 1759 } | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1811 const FecProtectionParams *key_params) { | 1816 const FecProtectionParams *key_params) { | 
| 1812 if (audio_configured_) { | 1817 if (audio_configured_) { | 
| 1813 return -1; | 1818 return -1; | 
| 1814 } | 1819 } | 
| 1815 video_->SetFecParameters(delta_params, key_params); | 1820 video_->SetFecParameters(delta_params, key_params); | 
| 1816 return 0; | 1821 return 0; | 
| 1817 } | 1822 } | 
| 1818 | 1823 | 
| 1819 void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length, | 1824 void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length, | 
| 1820 uint8_t* buffer_rtx) { | 1825 uint8_t* buffer_rtx) { | 
| 1821 CriticalSectionScoped cs(send_critsect_.get()); | 1826 rtc::CritScope lock(&send_critsect_); | 
| 1822 uint8_t* data_buffer_rtx = buffer_rtx; | 1827 uint8_t* data_buffer_rtx = buffer_rtx; | 
| 1823 // Add RTX header. | 1828 // Add RTX header. | 
| 1824 RtpUtility::RtpHeaderParser rtp_parser( | 1829 RtpUtility::RtpHeaderParser rtp_parser( | 
| 1825 reinterpret_cast<const uint8_t*>(buffer), *length); | 1830 reinterpret_cast<const uint8_t*>(buffer), *length); | 
| 1826 | 1831 | 
| 1827 RTPHeader rtp_header; | 1832 RTPHeader rtp_header; | 
| 1828 rtp_parser.Parse(&rtp_header); | 1833 rtp_parser.Parse(&rtp_header); | 
| 1829 | 1834 | 
| 1830 // Add original RTP header. | 1835 // Add original RTP header. | 
| 1831 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); | 1836 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1866 CriticalSectionScoped cs(statistics_crit_.get()); | 1871 CriticalSectionScoped cs(statistics_crit_.get()); | 
| 1867 return rtp_stats_callback_; | 1872 return rtp_stats_callback_; | 
| 1868 } | 1873 } | 
| 1869 | 1874 | 
| 1870 uint32_t RTPSender::BitrateSent() const { | 1875 uint32_t RTPSender::BitrateSent() const { | 
| 1871 return total_bitrate_sent_.BitrateLast(); | 1876 return total_bitrate_sent_.BitrateLast(); | 
| 1872 } | 1877 } | 
| 1873 | 1878 | 
| 1874 void RTPSender::SetRtpState(const RtpState& rtp_state) { | 1879 void RTPSender::SetRtpState(const RtpState& rtp_state) { | 
| 1875 SetStartTimestamp(rtp_state.start_timestamp, true); | 1880 SetStartTimestamp(rtp_state.start_timestamp, true); | 
| 1876 CriticalSectionScoped lock(send_critsect_.get()); | 1881 rtc::CritScope lock(&send_critsect_); | 
| 1877 sequence_number_ = rtp_state.sequence_number; | 1882 sequence_number_ = rtp_state.sequence_number; | 
| 1878 sequence_number_forced_ = true; | 1883 sequence_number_forced_ = true; | 
| 1879 timestamp_ = rtp_state.timestamp; | 1884 timestamp_ = rtp_state.timestamp; | 
| 1880 capture_time_ms_ = rtp_state.capture_time_ms; | 1885 capture_time_ms_ = rtp_state.capture_time_ms; | 
| 1881 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; | 1886 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; | 
| 1882 media_has_been_sent_ = rtp_state.media_has_been_sent; | 1887 media_has_been_sent_ = rtp_state.media_has_been_sent; | 
| 1883 } | 1888 } | 
| 1884 | 1889 | 
| 1885 RtpState RTPSender::GetRtpState() const { | 1890 RtpState RTPSender::GetRtpState() const { | 
| 1886 CriticalSectionScoped lock(send_critsect_.get()); | 1891 rtc::CritScope lock(&send_critsect_); | 
| 1887 | 1892 | 
| 1888 RtpState state; | 1893 RtpState state; | 
| 1889 state.sequence_number = sequence_number_; | 1894 state.sequence_number = sequence_number_; | 
| 1890 state.start_timestamp = start_timestamp_; | 1895 state.start_timestamp = start_timestamp_; | 
| 1891 state.timestamp = timestamp_; | 1896 state.timestamp = timestamp_; | 
| 1892 state.capture_time_ms = capture_time_ms_; | 1897 state.capture_time_ms = capture_time_ms_; | 
| 1893 state.last_timestamp_time_ms = last_timestamp_time_ms_; | 1898 state.last_timestamp_time_ms = last_timestamp_time_ms_; | 
| 1894 state.media_has_been_sent = media_has_been_sent_; | 1899 state.media_has_been_sent = media_has_been_sent_; | 
| 1895 | 1900 | 
| 1896 return state; | 1901 return state; | 
| 1897 } | 1902 } | 
| 1898 | 1903 | 
| 1899 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { | 1904 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { | 
| 1900 CriticalSectionScoped lock(send_critsect_.get()); | 1905 rtc::CritScope lock(&send_critsect_); | 
| 1901 sequence_number_rtx_ = rtp_state.sequence_number; | 1906 sequence_number_rtx_ = rtp_state.sequence_number; | 
| 1902 } | 1907 } | 
| 1903 | 1908 | 
| 1904 RtpState RTPSender::GetRtxRtpState() const { | 1909 RtpState RTPSender::GetRtxRtpState() const { | 
| 1905 CriticalSectionScoped lock(send_critsect_.get()); | 1910 rtc::CritScope lock(&send_critsect_); | 
| 1906 | 1911 | 
| 1907 RtpState state; | 1912 RtpState state; | 
| 1908 state.sequence_number = sequence_number_rtx_; | 1913 state.sequence_number = sequence_number_rtx_; | 
| 1909 state.start_timestamp = start_timestamp_; | 1914 state.start_timestamp = start_timestamp_; | 
| 1910 | 1915 | 
| 1911 return state; | 1916 return state; | 
| 1912 } | 1917 } | 
| 1913 | 1918 | 
| 1914 } // namespace webrtc | 1919 } // namespace webrtc | 
| OLD | NEW |