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