| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 frame_count_observer_(frame_count_observer), | 106 frame_count_observer_(frame_count_observer), |
| 107 send_side_delay_observer_(send_side_delay_observer), | 107 send_side_delay_observer_(send_side_delay_observer), |
| 108 event_log_(event_log), | 108 event_log_(event_log), |
| 109 send_packet_observer_(send_packet_observer), | 109 send_packet_observer_(send_packet_observer), |
| 110 bitrate_callback_(bitrate_callback), | 110 bitrate_callback_(bitrate_callback), |
| 111 // RTP variables | 111 // RTP variables |
| 112 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), | 112 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), |
| 113 remote_ssrc_(0), | 113 remote_ssrc_(0), |
| 114 sequence_number_forced_(false), | 114 sequence_number_forced_(false), |
| 115 ssrc_forced_(false), | 115 ssrc_forced_(false), |
| 116 timestamp_(0), | 116 last_rtp_timestamp_(0), |
| 117 capture_time_ms_(0), | 117 capture_time_ms_(0), |
| 118 last_timestamp_time_ms_(0), | 118 last_timestamp_time_ms_(0), |
| 119 media_has_been_sent_(false), | 119 media_has_been_sent_(false), |
| 120 last_packet_marker_bit_(false), | 120 last_packet_marker_bit_(false), |
| 121 csrcs_(), | 121 csrcs_(), |
| 122 rtx_(kRtxOff), | 122 rtx_(kRtxOff), |
| 123 retransmission_rate_limiter_(retransmission_rate_limiter) { | 123 retransmission_rate_limiter_(retransmission_rate_limiter) { |
| 124 ssrc_ = ssrc_db_->CreateSSRC(); | 124 ssrc_ = ssrc_db_->CreateSSRC(); |
| 125 RTC_DCHECK(ssrc_ != 0); | 125 RTC_DCHECK(ssrc_ != 0); |
| 126 ssrc_rtx_ = ssrc_db_->CreateSSRC(); | 126 ssrc_rtx_ = ssrc_db_->CreateSSRC(); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 int8_t payload_type, | 429 int8_t payload_type, |
| 430 uint32_t capture_timestamp, | 430 uint32_t capture_timestamp, |
| 431 int64_t capture_time_ms, | 431 int64_t capture_time_ms, |
| 432 const uint8_t* payload_data, | 432 const uint8_t* payload_data, |
| 433 size_t payload_size, | 433 size_t payload_size, |
| 434 const RTPFragmentationHeader* fragmentation, | 434 const RTPFragmentationHeader* fragmentation, |
| 435 const RTPVideoHeader* rtp_header, | 435 const RTPVideoHeader* rtp_header, |
| 436 uint32_t* transport_frame_id_out) { | 436 uint32_t* transport_frame_id_out) { |
| 437 uint32_t ssrc; | 437 uint32_t ssrc; |
| 438 uint16_t sequence_number; | 438 uint16_t sequence_number; |
| 439 uint32_t rtp_timestamp; |
| 439 { | 440 { |
| 440 // Drop this packet if we're not sending media packets. | 441 // Drop this packet if we're not sending media packets. |
| 441 rtc::CritScope lock(&send_critsect_); | 442 rtc::CritScope lock(&send_critsect_); |
| 442 ssrc = ssrc_; | 443 ssrc = ssrc_; |
| 443 sequence_number = sequence_number_; | 444 sequence_number = sequence_number_; |
| 445 rtp_timestamp = timestamp_offset_ + capture_timestamp; |
| 446 if (transport_frame_id_out) |
| 447 *transport_frame_id_out = rtp_timestamp; |
| 444 if (!sending_media_) | 448 if (!sending_media_) |
| 445 return true; | 449 return true; |
| 446 } | 450 } |
| 447 RtpVideoCodecTypes video_type = kRtpVideoGeneric; | 451 RtpVideoCodecTypes video_type = kRtpVideoGeneric; |
| 448 if (CheckPayloadType(payload_type, &video_type) != 0) { | 452 if (CheckPayloadType(payload_type, &video_type) != 0) { |
| 449 LOG(LS_ERROR) << "Don't send data with unknown payload type: " | 453 LOG(LS_ERROR) << "Don't send data with unknown payload type: " |
| 450 << static_cast<int>(payload_type) << "."; | 454 << static_cast<int>(payload_type) << "."; |
| 451 return false; | 455 return false; |
| 452 } | 456 } |
| 453 | 457 |
| 454 bool result; | 458 bool result; |
| 455 if (audio_configured_) { | 459 if (audio_configured_) { |
| 456 TRACE_EVENT_ASYNC_STEP1("webrtc", "Audio", capture_timestamp, | 460 TRACE_EVENT_ASYNC_STEP1("webrtc", "Audio", rtp_timestamp, "Send", "type", |
| 457 "Send", "type", FrameTypeToString(frame_type)); | 461 FrameTypeToString(frame_type)); |
| 458 assert(frame_type == kAudioFrameSpeech || frame_type == kAudioFrameCN || | 462 assert(frame_type == kAudioFrameSpeech || frame_type == kAudioFrameCN || |
| 459 frame_type == kEmptyFrame); | 463 frame_type == kEmptyFrame); |
| 460 | 464 |
| 461 result = audio_->SendAudio(frame_type, payload_type, capture_timestamp, | 465 result = audio_->SendAudio(frame_type, payload_type, rtp_timestamp, |
| 462 payload_data, payload_size, fragmentation); | 466 payload_data, payload_size, fragmentation); |
| 463 } else { | 467 } else { |
| 464 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", capture_time_ms, | 468 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", capture_time_ms, |
| 465 "Send", "type", FrameTypeToString(frame_type)); | 469 "Send", "type", FrameTypeToString(frame_type)); |
| 466 assert(frame_type != kAudioFrameSpeech && frame_type != kAudioFrameCN); | 470 assert(frame_type != kAudioFrameSpeech && frame_type != kAudioFrameCN); |
| 467 | 471 |
| 468 if (frame_type == kEmptyFrame) | 472 if (frame_type == kEmptyFrame) |
| 469 return true; | 473 return true; |
| 470 | 474 |
| 471 if (rtp_header) { | 475 if (rtp_header) { |
| 472 playout_delay_oracle_.UpdateRequest(ssrc, rtp_header->playout_delay, | 476 playout_delay_oracle_.UpdateRequest(ssrc, rtp_header->playout_delay, |
| 473 sequence_number); | 477 sequence_number); |
| 474 } | 478 } |
| 475 | 479 |
| 476 // Update the active/inactive status of playout delay extension based | 480 // Update the active/inactive status of playout delay extension based |
| 477 // on what the oracle indicates. | 481 // on what the oracle indicates. |
| 478 { | 482 { |
| 479 rtc::CritScope lock(&send_critsect_); | 483 rtc::CritScope lock(&send_critsect_); |
| 480 if (playout_delay_active_ != playout_delay_oracle_.send_playout_delay()) { | 484 if (playout_delay_active_ != playout_delay_oracle_.send_playout_delay()) { |
| 481 playout_delay_active_ = playout_delay_oracle_.send_playout_delay(); | 485 playout_delay_active_ = playout_delay_oracle_.send_playout_delay(); |
| 482 rtp_header_extension_map_.SetActive(kRtpExtensionPlayoutDelay, | 486 rtp_header_extension_map_.SetActive(kRtpExtensionPlayoutDelay, |
| 483 playout_delay_active_); | 487 playout_delay_active_); |
| 484 } | 488 } |
| 485 } | 489 } |
| 486 | 490 |
| 487 result = video_->SendVideo(video_type, frame_type, payload_type, | 491 result = video_->SendVideo(video_type, frame_type, payload_type, |
| 488 capture_timestamp, capture_time_ms, payload_data, | 492 rtp_timestamp, capture_time_ms, payload_data, |
| 489 payload_size, fragmentation, rtp_header); | 493 payload_size, fragmentation, rtp_header); |
| 490 } | 494 } |
| 491 | 495 |
| 492 if (transport_frame_id_out) { | |
| 493 rtc::CritScope lock(&send_critsect_); | |
| 494 // TODO(sergeyu): Move RTP timestamp calculation from BuildRTPheader() to | |
| 495 // SendOutgoingData() and pass it to SendVideo()/SendAudio() calls. | |
| 496 *transport_frame_id_out = timestamp_; | |
| 497 } | |
| 498 | |
| 499 rtc::CritScope cs(&statistics_crit_); | 496 rtc::CritScope cs(&statistics_crit_); |
| 500 // Note: This is currently only counting for video. | 497 // Note: This is currently only counting for video. |
| 501 if (frame_type == kVideoFrameKey) { | 498 if (frame_type == kVideoFrameKey) { |
| 502 ++frame_counts_.key_frames; | 499 ++frame_counts_.key_frames; |
| 503 } else if (frame_type == kVideoFrameDelta) { | 500 } else if (frame_type == kVideoFrameDelta) { |
| 504 ++frame_counts_.delta_frames; | 501 ++frame_counts_.delta_frames; |
| 505 } | 502 } |
| 506 if (frame_count_observer_) { | 503 if (frame_count_observer_) { |
| 507 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); | 504 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); |
| 508 } | 505 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 560 |
| 564 uint32_t ssrc; | 561 uint32_t ssrc; |
| 565 uint16_t sequence_number; | 562 uint16_t sequence_number; |
| 566 int payload_type; | 563 int payload_type; |
| 567 bool over_rtx; | 564 bool over_rtx; |
| 568 { | 565 { |
| 569 rtc::CritScope lock(&send_critsect_); | 566 rtc::CritScope lock(&send_critsect_); |
| 570 if (!sending_media_) | 567 if (!sending_media_) |
| 571 return bytes_sent; | 568 return bytes_sent; |
| 572 if (!timestamp_provided) { | 569 if (!timestamp_provided) { |
| 573 timestamp = timestamp_; | 570 timestamp = last_rtp_timestamp_; |
| 574 capture_time_ms = capture_time_ms_; | 571 capture_time_ms = capture_time_ms_; |
| 575 } | 572 } |
| 576 if (rtx_ == kRtxOff) { | 573 if (rtx_ == kRtxOff) { |
| 577 // Without RTX we can't send padding in the middle of frames. | 574 // Without RTX we can't send padding in the middle of frames. |
| 578 if (!last_packet_marker_bit_) | 575 if (!last_packet_marker_bit_) |
| 579 return 0; | 576 return 0; |
| 580 ssrc = ssrc_; | 577 ssrc = ssrc_; |
| 581 sequence_number = sequence_number_; | 578 sequence_number = sequence_number_; |
| 582 ++sequence_number_; | 579 ++sequence_number_; |
| 583 payload_type = payload_type_; | 580 payload_type = payload_type_; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 int64_t capture_time_ms, | 1072 int64_t capture_time_ms, |
| 1076 bool timestamp_provided, | 1073 bool timestamp_provided, |
| 1077 bool inc_sequence_number) { | 1074 bool inc_sequence_number) { |
| 1078 return BuildRtpHeader(data_buffer, payload_type, marker_bit, | 1075 return BuildRtpHeader(data_buffer, payload_type, marker_bit, |
| 1079 capture_timestamp, capture_time_ms); | 1076 capture_timestamp, capture_time_ms); |
| 1080 } | 1077 } |
| 1081 | 1078 |
| 1082 int32_t RTPSender::BuildRtpHeader(uint8_t* data_buffer, | 1079 int32_t RTPSender::BuildRtpHeader(uint8_t* data_buffer, |
| 1083 int8_t payload_type, | 1080 int8_t payload_type, |
| 1084 bool marker_bit, | 1081 bool marker_bit, |
| 1085 uint32_t capture_timestamp, | 1082 uint32_t rtp_timestamp, |
| 1086 int64_t capture_time_ms) { | 1083 int64_t capture_time_ms) { |
| 1087 assert(payload_type >= 0); | 1084 assert(payload_type >= 0); |
| 1088 rtc::CritScope lock(&send_critsect_); | 1085 rtc::CritScope lock(&send_critsect_); |
| 1089 if (!sending_media_) | 1086 if (!sending_media_) |
| 1090 return -1; | 1087 return -1; |
| 1091 | 1088 |
| 1092 timestamp_ = timestamp_offset_ + capture_timestamp; | 1089 last_rtp_timestamp_ = rtp_timestamp; |
| 1093 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); | 1090 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); |
| 1094 uint32_t sequence_number = sequence_number_++; | 1091 uint32_t sequence_number = sequence_number_++; |
| 1095 capture_time_ms_ = capture_time_ms; | 1092 capture_time_ms_ = capture_time_ms; |
| 1096 last_packet_marker_bit_ = marker_bit; | 1093 last_packet_marker_bit_ = marker_bit; |
| 1097 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit, | 1094 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit, |
| 1098 timestamp_, sequence_number, csrcs_); | 1095 rtp_timestamp, sequence_number, csrcs_); |
| 1099 } | 1096 } |
| 1100 | 1097 |
| 1101 uint16_t RTPSender::BuildRtpHeaderExtension(uint8_t* data_buffer, | 1098 uint16_t RTPSender::BuildRtpHeaderExtension(uint8_t* data_buffer, |
| 1102 bool marker_bit) const { | 1099 bool marker_bit) const { |
| 1103 if (rtp_header_extension_map_.Size() <= 0) { | 1100 if (rtp_header_extension_map_.Size() <= 0) { |
| 1104 return 0; | 1101 return 0; |
| 1105 } | 1102 } |
| 1106 // RTP header extension, RFC 3550. | 1103 // RTP header extension, RFC 3550. |
| 1107 // 0 1 2 3 | 1104 // 0 1 2 3 |
| 1108 // 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 | 1105 // 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 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 void RTPSender::SetSendingMediaStatus(bool enabled) { | 1505 void RTPSender::SetSendingMediaStatus(bool enabled) { |
| 1509 rtc::CritScope lock(&send_critsect_); | 1506 rtc::CritScope lock(&send_critsect_); |
| 1510 sending_media_ = enabled; | 1507 sending_media_ = enabled; |
| 1511 } | 1508 } |
| 1512 | 1509 |
| 1513 bool RTPSender::SendingMedia() const { | 1510 bool RTPSender::SendingMedia() const { |
| 1514 rtc::CritScope lock(&send_critsect_); | 1511 rtc::CritScope lock(&send_critsect_); |
| 1515 return sending_media_; | 1512 return sending_media_; |
| 1516 } | 1513 } |
| 1517 | 1514 |
| 1518 uint32_t RTPSender::Timestamp() const { | |
| 1519 rtc::CritScope lock(&send_critsect_); | |
| 1520 return timestamp_; | |
| 1521 } | |
| 1522 | |
| 1523 void RTPSender::SetTimestampOffset(uint32_t timestamp) { | 1515 void RTPSender::SetTimestampOffset(uint32_t timestamp) { |
| 1524 rtc::CritScope lock(&send_critsect_); | 1516 rtc::CritScope lock(&send_critsect_); |
| 1525 timestamp_offset_ = timestamp; | 1517 timestamp_offset_ = timestamp; |
| 1526 } | 1518 } |
| 1527 | 1519 |
| 1528 uint32_t RTPSender::TimestampOffset() const { | 1520 uint32_t RTPSender::TimestampOffset() const { |
| 1529 rtc::CritScope lock(&send_critsect_); | 1521 rtc::CritScope lock(&send_critsect_); |
| 1530 return timestamp_offset_; | 1522 return timestamp_offset_; |
| 1531 } | 1523 } |
| 1532 | 1524 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 uint32_t RTPSender::BitrateSent() const { | 1678 uint32_t RTPSender::BitrateSent() const { |
| 1687 rtc::CritScope cs(&statistics_crit_); | 1679 rtc::CritScope cs(&statistics_crit_); |
| 1688 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 1680 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
| 1689 } | 1681 } |
| 1690 | 1682 |
| 1691 void RTPSender::SetRtpState(const RtpState& rtp_state) { | 1683 void RTPSender::SetRtpState(const RtpState& rtp_state) { |
| 1692 rtc::CritScope lock(&send_critsect_); | 1684 rtc::CritScope lock(&send_critsect_); |
| 1693 sequence_number_ = rtp_state.sequence_number; | 1685 sequence_number_ = rtp_state.sequence_number; |
| 1694 sequence_number_forced_ = true; | 1686 sequence_number_forced_ = true; |
| 1695 timestamp_offset_ = rtp_state.start_timestamp; | 1687 timestamp_offset_ = rtp_state.start_timestamp; |
| 1696 timestamp_ = rtp_state.timestamp; | 1688 last_rtp_timestamp_ = rtp_state.timestamp; |
| 1697 capture_time_ms_ = rtp_state.capture_time_ms; | 1689 capture_time_ms_ = rtp_state.capture_time_ms; |
| 1698 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; | 1690 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; |
| 1699 media_has_been_sent_ = rtp_state.media_has_been_sent; | 1691 media_has_been_sent_ = rtp_state.media_has_been_sent; |
| 1700 } | 1692 } |
| 1701 | 1693 |
| 1702 RtpState RTPSender::GetRtpState() const { | 1694 RtpState RTPSender::GetRtpState() const { |
| 1703 rtc::CritScope lock(&send_critsect_); | 1695 rtc::CritScope lock(&send_critsect_); |
| 1704 | 1696 |
| 1705 RtpState state; | 1697 RtpState state; |
| 1706 state.sequence_number = sequence_number_; | 1698 state.sequence_number = sequence_number_; |
| 1707 state.start_timestamp = timestamp_offset_; | 1699 state.start_timestamp = timestamp_offset_; |
| 1708 state.timestamp = timestamp_; | 1700 state.timestamp = last_rtp_timestamp_; |
| 1709 state.capture_time_ms = capture_time_ms_; | 1701 state.capture_time_ms = capture_time_ms_; |
| 1710 state.last_timestamp_time_ms = last_timestamp_time_ms_; | 1702 state.last_timestamp_time_ms = last_timestamp_time_ms_; |
| 1711 state.media_has_been_sent = media_has_been_sent_; | 1703 state.media_has_been_sent = media_has_been_sent_; |
| 1712 | 1704 |
| 1713 return state; | 1705 return state; |
| 1714 } | 1706 } |
| 1715 | 1707 |
| 1716 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { | 1708 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { |
| 1717 rtc::CritScope lock(&send_critsect_); | 1709 rtc::CritScope lock(&send_critsect_); |
| 1718 sequence_number_rtx_ = rtp_state.sequence_number; | 1710 sequence_number_rtx_ = rtp_state.sequence_number; |
| 1719 } | 1711 } |
| 1720 | 1712 |
| 1721 RtpState RTPSender::GetRtxRtpState() const { | 1713 RtpState RTPSender::GetRtxRtpState() const { |
| 1722 rtc::CritScope lock(&send_critsect_); | 1714 rtc::CritScope lock(&send_critsect_); |
| 1723 | 1715 |
| 1724 RtpState state; | 1716 RtpState state; |
| 1725 state.sequence_number = sequence_number_rtx_; | 1717 state.sequence_number = sequence_number_rtx_; |
| 1726 state.start_timestamp = timestamp_offset_; | 1718 state.start_timestamp = timestamp_offset_; |
| 1727 | 1719 |
| 1728 return state; | 1720 return state; |
| 1729 } | 1721 } |
| 1730 | 1722 |
| 1731 } // namespace webrtc | 1723 } // namespace webrtc |
| OLD | NEW |