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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
12 | 12 |
13 #include <stdlib.h> // srand | 13 #include <stdlib.h> // srand |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/trace_event.h" | 19 #include "webrtc/base/trace_event.h" |
20 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
22 #include "webrtc/call/rtc_event_log.h" | 22 #include "webrtc/call/rtc_event_log.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
24 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 24 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
25 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" | |
25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" |
27 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 28 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
28 | 29 |
29 namespace webrtc { | 30 namespace webrtc { |
30 | 31 |
31 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. | 32 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. |
32 static const size_t kMaxPaddingLength = 224; | 33 static const size_t kMaxPaddingLength = 224; |
33 static const int kSendSideDelayWindowMs = 1000; | 34 static const int kSendSideDelayWindowMs = 1000; |
34 static const uint32_t kAbsSendTimeFraction = 18; | 35 static const uint32_t kAbsSendTimeFraction = 18; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 last_capture_time_ms_sent_(0), | 131 last_capture_time_ms_sent_(0), |
131 transport_(transport), | 132 transport_(transport), |
132 sending_media_(true), // Default to sending media. | 133 sending_media_(true), // Default to sending media. |
133 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. | 134 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. |
134 payload_type_(-1), | 135 payload_type_(-1), |
135 payload_type_map_(), | 136 payload_type_map_(), |
136 rtp_header_extension_map_(), | 137 rtp_header_extension_map_(), |
137 transmission_time_offset_(0), | 138 transmission_time_offset_(0), |
138 absolute_send_time_(0), | 139 absolute_send_time_(0), |
139 rotation_(kVideoRotation_0), | 140 rotation_(kVideoRotation_0), |
140 cvo_mode_(kCVONone), | 141 video_rotation_active_(false), |
141 transport_sequence_number_(0), | 142 transport_sequence_number_(0), |
142 // NACK. | 143 // NACK. |
143 nack_byte_count_times_(), | 144 nack_byte_count_times_(), |
144 nack_byte_count_(), | 145 nack_byte_count_(), |
145 nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()), | 146 nack_bitrate_(clock, bitrates_.retransmit_bitrate_observer()), |
147 playout_delay_active_(false), | |
146 packet_history_(clock), | 148 packet_history_(clock), |
147 // Statistics | 149 // Statistics |
148 rtp_stats_callback_(NULL), | 150 rtp_stats_callback_(NULL), |
149 frame_count_observer_(frame_count_observer), | 151 frame_count_observer_(frame_count_observer), |
150 send_side_delay_observer_(send_side_delay_observer), | 152 send_side_delay_observer_(send_side_delay_observer), |
151 event_log_(event_log), | 153 event_log_(event_log), |
152 send_packet_observer_(send_packet_observer), | 154 send_packet_observer_(send_packet_observer), |
153 // RTP variables | 155 // RTP variables |
154 start_timestamp_forced_(false), | 156 start_timestamp_forced_(false), |
155 start_timestamp_(0), | 157 start_timestamp_(0), |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 | 266 |
265 int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) { | 267 int32_t RTPSender::SetTransportSequenceNumber(uint16_t sequence_number) { |
266 rtc::CritScope lock(&send_critsect_); | 268 rtc::CritScope lock(&send_critsect_); |
267 transport_sequence_number_ = sequence_number; | 269 transport_sequence_number_ = sequence_number; |
268 return 0; | 270 return 0; |
269 } | 271 } |
270 | 272 |
271 int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type, | 273 int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type, |
272 uint8_t id) { | 274 uint8_t id) { |
273 rtc::CritScope lock(&send_critsect_); | 275 rtc::CritScope lock(&send_critsect_); |
274 if (type == kRtpExtensionVideoRotation) { | 276 switch (type) { |
275 cvo_mode_ = kCVOInactive; | 277 case kRtpExtensionVideoRotation: |
276 return rtp_header_extension_map_.RegisterInactive(type, id); | 278 video_rotation_active_ = false; |
279 return rtp_header_extension_map_.RegisterInactive(type, id); | |
280 case kRtpExtensionPlayoutDelay: | |
281 playout_delay_active_ = false; | |
282 return rtp_header_extension_map_.RegisterInactive(type, id); | |
283 default: | |
stefan-webrtc
2016/06/06 14:08:16
No default, instead just list all types here.
Irfan
2016/06/06 15:39:41
Done.
| |
284 return rtp_header_extension_map_.Register(type, id); | |
277 } | 285 } |
278 return rtp_header_extension_map_.Register(type, id); | |
279 } | 286 } |
280 | 287 |
281 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) { | 288 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) { |
282 rtc::CritScope lock(&send_critsect_); | 289 rtc::CritScope lock(&send_critsect_); |
283 return rtp_header_extension_map_.IsRegistered(type); | 290 return rtp_header_extension_map_.IsRegistered(type); |
284 } | 291 } |
285 | 292 |
286 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { | 293 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { |
287 rtc::CritScope lock(&send_critsect_); | 294 rtc::CritScope lock(&send_critsect_); |
288 return rtp_header_extension_map_.Deregister(type); | 295 return rtp_header_extension_map_.Deregister(type); |
289 } | 296 } |
290 | 297 |
291 size_t RTPSender::RtpHeaderExtensionTotalLength() const { | 298 size_t RTPSender::RtpHeaderExtensionLength() const { |
292 rtc::CritScope lock(&send_critsect_); | 299 rtc::CritScope lock(&send_critsect_); |
293 return rtp_header_extension_map_.GetTotalLengthInBytes(); | 300 return rtp_header_extension_map_.GetTotalLengthInBytes(); |
294 } | 301 } |
295 | 302 |
296 int32_t RTPSender::RegisterPayload( | 303 int32_t RTPSender::RegisterPayload( |
297 const char payload_name[RTP_PAYLOAD_NAME_SIZE], | 304 const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
298 int8_t payload_number, | 305 int8_t payload_number, |
299 uint32_t frequency, | 306 uint32_t frequency, |
300 size_t channels, | 307 size_t channels, |
301 uint32_t rate) { | 308 uint32_t rate) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 max_payload_length_ = max_payload_length; | 386 max_payload_length_ = max_payload_length; |
380 } | 387 } |
381 | 388 |
382 size_t RTPSender::MaxDataPayloadLength() const { | 389 size_t RTPSender::MaxDataPayloadLength() const { |
383 int rtx; | 390 int rtx; |
384 { | 391 { |
385 rtc::CritScope lock(&send_critsect_); | 392 rtc::CritScope lock(&send_critsect_); |
386 rtx = rtx_; | 393 rtx = rtx_; |
387 } | 394 } |
388 if (audio_configured_) { | 395 if (audio_configured_) { |
389 return max_payload_length_ - RTPHeaderLength(); | 396 return max_payload_length_ - RtpHeaderLength(); |
390 } else { | 397 } else { |
391 return max_payload_length_ - RTPHeaderLength() // RTP overhead. | 398 return max_payload_length_ - RtpHeaderLength() // RTP overhead. |
392 - video_->FECPacketOverhead() // FEC/ULP/RED overhead. | 399 - video_->FECPacketOverhead() // FEC/ULP/RED overhead. |
393 - ((rtx) ? 2 : 0); // RTX overhead. | 400 - ((rtx) ? 2 : 0); // RTX overhead. |
394 } | 401 } |
395 } | 402 } |
396 | 403 |
397 size_t RTPSender::MaxPayloadLength() const { | 404 size_t RTPSender::MaxPayloadLength() const { |
398 return max_payload_length_; | 405 return max_payload_length_; |
399 } | 406 } |
400 | 407 |
401 void RTPSender::SetRtxStatus(int mode) { | 408 void RTPSender::SetRtxStatus(int mode) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 SetSendPayloadType(payload_type); | 472 SetSendPayloadType(payload_type); |
466 RtpUtility::Payload* payload = it->second; | 473 RtpUtility::Payload* payload = it->second; |
467 assert(payload); | 474 assert(payload); |
468 if (!payload->audio && !audio_configured_) { | 475 if (!payload->audio && !audio_configured_) { |
469 video_->SetVideoCodecType(payload->typeSpecific.Video.videoCodecType); | 476 video_->SetVideoCodecType(payload->typeSpecific.Video.videoCodecType); |
470 *video_type = payload->typeSpecific.Video.videoCodecType; | 477 *video_type = payload->typeSpecific.Video.videoCodecType; |
471 } | 478 } |
472 return 0; | 479 return 0; |
473 } | 480 } |
474 | 481 |
475 RTPSenderInterface::CVOMode RTPSender::ActivateCVORtpHeaderExtension() { | 482 bool RTPSender::ActivateCVORtpHeaderExtension() { |
476 if (cvo_mode_ == kCVOInactive) { | 483 if (!video_rotation_active_) { |
477 rtc::CritScope lock(&send_critsect_); | 484 rtc::CritScope lock(&send_critsect_); |
478 if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) { | 485 if (rtp_header_extension_map_.SetActive(kRtpExtensionVideoRotation, true)) { |
479 cvo_mode_ = kCVOActivated; | 486 video_rotation_active_ = true; |
480 } | 487 } |
481 } | 488 } |
482 return cvo_mode_; | 489 return video_rotation_active_; |
483 } | 490 } |
484 | 491 |
485 int32_t RTPSender::SendOutgoingData(FrameType frame_type, | 492 int32_t RTPSender::SendOutgoingData(FrameType frame_type, |
486 int8_t payload_type, | 493 int8_t payload_type, |
487 uint32_t capture_timestamp, | 494 uint32_t capture_timestamp, |
488 int64_t capture_time_ms, | 495 int64_t capture_time_ms, |
489 const uint8_t* payload_data, | 496 const uint8_t* payload_data, |
490 size_t payload_size, | 497 size_t payload_size, |
491 const RTPFragmentationHeader* fragmentation, | 498 const RTPFragmentationHeader* fragmentation, |
492 const RTPVideoHeader* rtp_hdr) { | 499 const RTPVideoHeader* rtp_hdr) { |
493 uint32_t ssrc; | 500 uint32_t ssrc; |
501 uint16_t sequence_number; | |
494 { | 502 { |
495 // Drop this packet if we're not sending media packets. | 503 // Drop this packet if we're not sending media packets. |
496 rtc::CritScope lock(&send_critsect_); | 504 rtc::CritScope lock(&send_critsect_); |
497 ssrc = ssrc_; | 505 ssrc = ssrc_; |
506 sequence_number = sequence_number_; | |
498 if (!sending_media_) { | 507 if (!sending_media_) { |
499 return 0; | 508 return 0; |
500 } | 509 } |
501 } | 510 } |
502 RtpVideoCodecTypes video_type = kRtpVideoGeneric; | 511 RtpVideoCodecTypes video_type = kRtpVideoGeneric; |
503 if (CheckPayloadType(payload_type, &video_type) != 0) { | 512 if (CheckPayloadType(payload_type, &video_type) != 0) { |
504 LOG(LS_ERROR) << "Don't send data with unknown payload type: " | 513 LOG(LS_ERROR) << "Don't send data with unknown payload type: " |
505 << static_cast<int>(payload_type) << "."; | 514 << static_cast<int>(payload_type) << "."; |
506 return -1; | 515 return -1; |
507 } | 516 } |
508 | 517 |
509 int32_t ret_val; | 518 int32_t ret_val; |
510 if (audio_configured_) { | 519 if (audio_configured_) { |
511 TRACE_EVENT_ASYNC_STEP1("webrtc", "Audio", capture_timestamp, | 520 TRACE_EVENT_ASYNC_STEP1("webrtc", "Audio", capture_timestamp, |
512 "Send", "type", FrameTypeToString(frame_type)); | 521 "Send", "type", FrameTypeToString(frame_type)); |
513 assert(frame_type == kAudioFrameSpeech || frame_type == kAudioFrameCN || | 522 assert(frame_type == kAudioFrameSpeech || frame_type == kAudioFrameCN || |
514 frame_type == kEmptyFrame); | 523 frame_type == kEmptyFrame); |
515 | 524 |
516 ret_val = audio_->SendAudio(frame_type, payload_type, capture_timestamp, | 525 ret_val = audio_->SendAudio(frame_type, payload_type, capture_timestamp, |
517 payload_data, payload_size, fragmentation); | 526 payload_data, payload_size, fragmentation); |
518 } else { | 527 } else { |
519 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", capture_time_ms, | 528 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", capture_time_ms, |
520 "Send", "type", FrameTypeToString(frame_type)); | 529 "Send", "type", FrameTypeToString(frame_type)); |
521 assert(frame_type != kAudioFrameSpeech && frame_type != kAudioFrameCN); | 530 assert(frame_type != kAudioFrameSpeech && frame_type != kAudioFrameCN); |
522 | 531 |
523 if (frame_type == kEmptyFrame) | 532 if (frame_type == kEmptyFrame) |
524 return 0; | 533 return 0; |
525 | 534 |
526 ret_val = | 535 if (rtp_hdr) { |
527 video_->SendVideo(video_type, frame_type, payload_type, | 536 playout_delay_oracle_.UpdateRequest(ssrc, rtp_hdr->playout_delay, |
528 capture_timestamp, capture_time_ms, payload_data, | 537 sequence_number); |
529 payload_size, fragmentation, rtp_hdr); | 538 } |
539 | |
540 // Update the active/inactive status of playout delay extension based | |
541 // on what the oracle indicates. | |
542 { | |
543 rtc::CritScope lock(&send_critsect_); | |
544 if (playout_delay_active_ != playout_delay_oracle_.send_playout_delay()) { | |
545 playout_delay_active_ = playout_delay_oracle_.send_playout_delay(); | |
546 rtp_header_extension_map_.SetActive(kRtpExtensionPlayoutDelay, | |
547 playout_delay_active_); | |
548 } | |
549 } | |
550 | |
551 ret_val = video_->SendVideo( | |
552 video_type, frame_type, payload_type, capture_timestamp, | |
553 capture_time_ms, payload_data, payload_size, fragmentation, rtp_hdr); | |
530 } | 554 } |
531 | 555 |
532 rtc::CritScope cs(&statistics_crit_); | 556 rtc::CritScope cs(&statistics_crit_); |
533 // Note: This is currently only counting for video. | 557 // Note: This is currently only counting for video. |
534 if (frame_type == kVideoFrameKey) { | 558 if (frame_type == kVideoFrameKey) { |
535 ++frame_counts_.key_frames; | 559 ++frame_counts_.key_frames; |
536 } else if (frame_type == kVideoFrameDelta) { | 560 } else if (frame_type == kVideoFrameDelta) { |
537 ++frame_counts_.delta_frames; | 561 ++frame_counts_.delta_frames; |
538 } | 562 } |
539 if (frame_count_observer_) { | 563 if (frame_count_observer_) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 if (bytes_re_sent > target_bytes) { | 850 if (bytes_re_sent > target_bytes) { |
827 break; // Ignore the rest of the packets in the list. | 851 break; // Ignore the rest of the packets in the list. |
828 } | 852 } |
829 } | 853 } |
830 } | 854 } |
831 if (bytes_re_sent > 0) { | 855 if (bytes_re_sent > 0) { |
832 UpdateNACKBitRate(bytes_re_sent, now); | 856 UpdateNACKBitRate(bytes_re_sent, now); |
833 } | 857 } |
834 } | 858 } |
835 | 859 |
860 void RTPSender::OnReceivedRtcpReceiverReport( | |
861 const ReportBlockList& report_blocks) { | |
862 playout_delay_oracle_.OnReceivedRtcpReceiverReport(report_blocks); | |
863 } | |
864 | |
836 bool RTPSender::ProcessNACKBitRate(uint32_t now) { | 865 bool RTPSender::ProcessNACKBitRate(uint32_t now) { |
837 uint32_t num = 0; | 866 uint32_t num = 0; |
838 size_t byte_count = 0; | 867 size_t byte_count = 0; |
839 const uint32_t kAvgIntervalMs = 1000; | 868 const uint32_t kAvgIntervalMs = 1000; |
840 uint32_t target_bitrate = GetTargetBitrate(); | 869 uint32_t target_bitrate = GetTargetBitrate(); |
841 | 870 |
842 rtc::CritScope lock(&send_critsect_); | 871 rtc::CritScope lock(&send_critsect_); |
843 | 872 |
844 if (target_bitrate == 0) { | 873 if (target_bitrate == 0) { |
845 return true; | 874 return true; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 void RTPSender::ProcessBitrate() { | 1174 void RTPSender::ProcessBitrate() { |
1146 rtc::CritScope lock(&send_critsect_); | 1175 rtc::CritScope lock(&send_critsect_); |
1147 total_bitrate_sent_.Process(); | 1176 total_bitrate_sent_.Process(); |
1148 nack_bitrate_.Process(); | 1177 nack_bitrate_.Process(); |
1149 if (audio_configured_) { | 1178 if (audio_configured_) { |
1150 return; | 1179 return; |
1151 } | 1180 } |
1152 video_->ProcessBitrate(); | 1181 video_->ProcessBitrate(); |
1153 } | 1182 } |
1154 | 1183 |
1155 size_t RTPSender::RTPHeaderLength() const { | 1184 size_t RTPSender::RtpHeaderLength() const { |
1156 rtc::CritScope lock(&send_critsect_); | 1185 rtc::CritScope lock(&send_critsect_); |
1157 size_t rtp_header_length = kRtpHeaderLength; | 1186 size_t rtp_header_length = kRtpHeaderLength; |
1158 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); | 1187 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); |
1159 rtp_header_length += RtpHeaderExtensionTotalLength(); | 1188 rtp_header_length += RtpHeaderExtensionLength(); |
1160 return rtp_header_length; | 1189 return rtp_header_length; |
1161 } | 1190 } |
1162 | 1191 |
1163 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { | 1192 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { |
1164 rtc::CritScope lock(&send_critsect_); | 1193 rtc::CritScope lock(&send_critsect_); |
1165 uint16_t first_allocated_sequence_number = sequence_number_; | 1194 uint16_t first_allocated_sequence_number = sequence_number_; |
1166 sequence_number_ += packets_to_send; | 1195 sequence_number_ += packets_to_send; |
1167 return first_allocated_sequence_number; | 1196 return first_allocated_sequence_number; |
1168 } | 1197 } |
1169 | 1198 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1276 case kRtpExtensionAbsoluteSendTime: | 1305 case kRtpExtensionAbsoluteSendTime: |
1277 block_length = BuildAbsoluteSendTimeExtension(extension_data); | 1306 block_length = BuildAbsoluteSendTimeExtension(extension_data); |
1278 break; | 1307 break; |
1279 case kRtpExtensionVideoRotation: | 1308 case kRtpExtensionVideoRotation: |
1280 block_length = BuildVideoRotationExtension(extension_data); | 1309 block_length = BuildVideoRotationExtension(extension_data); |
1281 break; | 1310 break; |
1282 case kRtpExtensionTransportSequenceNumber: | 1311 case kRtpExtensionTransportSequenceNumber: |
1283 block_length = BuildTransportSequenceNumberExtension( | 1312 block_length = BuildTransportSequenceNumberExtension( |
1284 extension_data, transport_sequence_number_); | 1313 extension_data, transport_sequence_number_); |
1285 break; | 1314 break; |
1315 case kRtpExtensionPlayoutDelay: | |
1316 block_length = BuildPlayoutDelayExtension( | |
1317 extension_data, playout_delay_oracle_.min_playout_delay_ms(), | |
1318 playout_delay_oracle_.max_playout_delay_ms()); | |
1319 break; | |
1286 default: | 1320 default: |
1287 assert(false); | 1321 assert(false); |
1288 } | 1322 } |
1289 total_block_length += block_length; | 1323 total_block_length += block_length; |
1290 type = rtp_header_extension_map_.Next(type); | 1324 type = rtp_header_extension_map_.Next(type); |
1291 } | 1325 } |
1292 if (total_block_length == 0) { | 1326 if (total_block_length == 0) { |
1293 // No extension added. | 1327 // No extension added. |
1294 return 0; | 1328 return 0; |
1295 } | 1329 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1451 } | 1485 } |
1452 size_t pos = 0; | 1486 size_t pos = 0; |
1453 const uint8_t len = 1; | 1487 const uint8_t len = 1; |
1454 data_buffer[pos++] = (id << 4) + len; | 1488 data_buffer[pos++] = (id << 4) + len; |
1455 ByteWriter<uint16_t>::WriteBigEndian(data_buffer + pos, sequence_number); | 1489 ByteWriter<uint16_t>::WriteBigEndian(data_buffer + pos, sequence_number); |
1456 pos += 2; | 1490 pos += 2; |
1457 assert(pos == kTransportSequenceNumberLength); | 1491 assert(pos == kTransportSequenceNumberLength); |
1458 return kTransportSequenceNumberLength; | 1492 return kTransportSequenceNumberLength; |
1459 } | 1493 } |
1460 | 1494 |
1495 uint8_t RTPSender::BuildPlayoutDelayExtension( | |
1496 uint8_t* data_buffer, | |
1497 uint16_t min_playout_delay_ms, | |
1498 uint16_t max_playout_delay_ms) const { | |
1499 RTC_DCHECK_LE(min_playout_delay_ms, kPlayoutDelayMaxMs); | |
1500 RTC_DCHECK_LE(max_playout_delay_ms, kPlayoutDelayMaxMs); | |
1501 RTC_DCHECK_LE(min_playout_delay_ms, max_playout_delay_ms); | |
1502 // 0 1 2 3 | |
1503 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
1504 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
1505 // | ID | len=2 | MIN delay | MAX delay | | |
1506 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
1507 uint8_t id; | |
1508 if (rtp_header_extension_map_.GetId(kRtpExtensionPlayoutDelay, &id) != 0) { | |
1509 // Not registered. | |
1510 return 0; | |
1511 } | |
1512 size_t pos = 0; | |
1513 const uint8_t len = 2; | |
1514 // Convert MS to value to be sent on extension header. | |
1515 uint16_t min_playout = min_playout_delay_ms / kPlayoutDelayGranularityMs; | |
1516 uint16_t max_playout = max_playout_delay_ms / kPlayoutDelayGranularityMs; | |
1517 | |
1518 data_buffer[pos++] = (id << 4) + len; | |
1519 data_buffer[pos++] = min_playout >> 4; | |
1520 data_buffer[pos++] = ((min_playout & 0xf) << 4) | (max_playout >> 8); | |
1521 data_buffer[pos++] = max_playout & 0xff; | |
1522 assert(pos == kPlayoutDelayLength); | |
1523 return kPlayoutDelayLength; | |
1524 } | |
1525 | |
1461 bool RTPSender::FindHeaderExtensionPosition(RTPExtensionType type, | 1526 bool RTPSender::FindHeaderExtensionPosition(RTPExtensionType type, |
1462 const uint8_t* rtp_packet, | 1527 const uint8_t* rtp_packet, |
1463 size_t rtp_packet_length, | 1528 size_t rtp_packet_length, |
1464 const RTPHeader& rtp_header, | 1529 const RTPHeader& rtp_header, |
1465 size_t* position) const { | 1530 size_t* position) const { |
1466 // Get length until start of header extension block. | 1531 // Get length until start of header extension block. |
1467 int extension_block_pos = | 1532 int extension_block_pos = |
1468 rtp_header_extension_map_.GetLengthUntilBlockStartInBytes(type); | 1533 rtp_header_extension_map_.GetLengthUntilBlockStartInBytes(type); |
1469 if (extension_block_pos < 0) { | 1534 if (extension_block_pos < 0) { |
1470 LOG(LS_WARNING) << "Failed to find extension position for " << type | 1535 LOG(LS_WARNING) << "Failed to find extension position for " << type |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1924 rtc::CritScope lock(&send_critsect_); | 1989 rtc::CritScope lock(&send_critsect_); |
1925 | 1990 |
1926 RtpState state; | 1991 RtpState state; |
1927 state.sequence_number = sequence_number_rtx_; | 1992 state.sequence_number = sequence_number_rtx_; |
1928 state.start_timestamp = start_timestamp_; | 1993 state.start_timestamp = start_timestamp_; |
1929 | 1994 |
1930 return state; | 1995 return state; |
1931 } | 1996 } |
1932 | 1997 |
1933 } // namespace webrtc | 1998 } // namespace webrtc |
OLD | NEW |