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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 rtp_stats_callback_(nullptr), | 102 rtp_stats_callback_(nullptr), |
103 total_bitrate_sent_(kBitrateStatisticsWindowMs, | 103 total_bitrate_sent_(kBitrateStatisticsWindowMs, |
104 RateStatistics::kBpsScale), | 104 RateStatistics::kBpsScale), |
105 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), | 105 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), |
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 start_timestamp_forced_(false), |
| 113 start_timestamp_(0), |
112 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), | 114 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), |
113 remote_ssrc_(0), | 115 remote_ssrc_(0), |
114 sequence_number_forced_(false), | 116 sequence_number_forced_(false), |
115 ssrc_forced_(false), | 117 ssrc_forced_(false), |
116 timestamp_(0), | 118 timestamp_(0), |
117 capture_time_ms_(0), | 119 capture_time_ms_(0), |
118 last_timestamp_time_ms_(0), | 120 last_timestamp_time_ms_(0), |
119 media_has_been_sent_(false), | 121 media_has_been_sent_(false), |
120 last_packet_marker_bit_(false), | 122 last_packet_marker_bit_(false), |
121 csrcs_(), | 123 csrcs_(), |
122 rtx_(kRtxOff), | 124 rtx_(kRtxOff), |
123 retransmission_rate_limiter_(retransmission_rate_limiter) { | 125 retransmission_rate_limiter_(retransmission_rate_limiter) { |
124 ssrc_ = ssrc_db_->CreateSSRC(); | 126 ssrc_ = ssrc_db_->CreateSSRC(); |
125 RTC_DCHECK(ssrc_ != 0); | 127 RTC_DCHECK(ssrc_ != 0); |
126 ssrc_rtx_ = ssrc_db_->CreateSSRC(); | 128 ssrc_rtx_ = ssrc_db_->CreateSSRC(); |
127 RTC_DCHECK(ssrc_rtx_ != 0); | 129 RTC_DCHECK(ssrc_rtx_ != 0); |
128 | 130 |
129 // This random initialization is not intended to be cryptographic strong. | |
130 timestamp_offset_ = random_.Rand<uint32_t>(); | |
131 // Random start, 16 bits. Can't be 0. | 131 // Random start, 16 bits. Can't be 0. |
132 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 132 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
133 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 133 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
134 } | 134 } |
135 | 135 |
136 RTPSender::~RTPSender() { | 136 RTPSender::~RTPSender() { |
137 // TODO(tommi): Use a thread checker to ensure the object is created and | 137 // TODO(tommi): Use a thread checker to ensure the object is created and |
138 // deleted on the same thread. At the moment this isn't possible due to | 138 // deleted on the same thread. At the moment this isn't possible due to |
139 // voe::ChannelOwner in voice engine. To reproduce, run: | 139 // voe::ChannelOwner in voice engine. To reproduce, run: |
140 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus | 140 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 int32_t RTPSender::BuildRtpHeader(uint8_t* data_buffer, | 1092 int32_t RTPSender::BuildRtpHeader(uint8_t* data_buffer, |
1093 int8_t payload_type, | 1093 int8_t payload_type, |
1094 bool marker_bit, | 1094 bool marker_bit, |
1095 uint32_t capture_timestamp, | 1095 uint32_t capture_timestamp, |
1096 int64_t capture_time_ms) { | 1096 int64_t capture_time_ms) { |
1097 assert(payload_type >= 0); | 1097 assert(payload_type >= 0); |
1098 rtc::CritScope lock(&send_critsect_); | 1098 rtc::CritScope lock(&send_critsect_); |
1099 if (!sending_media_) | 1099 if (!sending_media_) |
1100 return -1; | 1100 return -1; |
1101 | 1101 |
1102 timestamp_ = timestamp_offset_ + capture_timestamp; | 1102 timestamp_ = start_timestamp_ + capture_timestamp; |
1103 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); | 1103 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); |
1104 uint32_t sequence_number = sequence_number_++; | 1104 uint32_t sequence_number = sequence_number_++; |
1105 capture_time_ms_ = capture_time_ms; | 1105 capture_time_ms_ = capture_time_ms; |
1106 last_packet_marker_bit_ = marker_bit; | 1106 last_packet_marker_bit_ = marker_bit; |
1107 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit, | 1107 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit, |
1108 timestamp_, sequence_number, csrcs_); | 1108 timestamp_, sequence_number, csrcs_); |
1109 } | 1109 } |
1110 | 1110 |
1111 uint16_t RTPSender::BuildRtpHeaderExtension(uint8_t* data_buffer, | 1111 uint16_t RTPSender::BuildRtpHeaderExtension(uint8_t* data_buffer, |
1112 bool marker_bit) const { | 1112 bool marker_bit) const { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 | 1492 |
1493 *packet_id = transport_sequence_number_allocator_->AllocateSequenceNumber(); | 1493 *packet_id = transport_sequence_number_allocator_->AllocateSequenceNumber(); |
1494 | 1494 |
1495 if (!packet->SetExtension<TransportSequenceNumber>(*packet_id)) | 1495 if (!packet->SetExtension<TransportSequenceNumber>(*packet_id)) |
1496 return false; | 1496 return false; |
1497 | 1497 |
1498 return true; | 1498 return true; |
1499 } | 1499 } |
1500 | 1500 |
1501 void RTPSender::SetSendingStatus(bool enabled) { | 1501 void RTPSender::SetSendingStatus(bool enabled) { |
1502 if (!enabled) { | 1502 if (enabled) { |
| 1503 uint32_t frequency_hz = SendPayloadFrequency(); |
| 1504 uint32_t RTPtime = CurrentRtp(*clock_, frequency_hz); |
| 1505 |
| 1506 // Will be ignored if it's already configured via API. |
| 1507 SetStartTimestamp(RTPtime, false); |
| 1508 } else { |
1503 rtc::CritScope lock(&send_critsect_); | 1509 rtc::CritScope lock(&send_critsect_); |
1504 if (!ssrc_forced_) { | 1510 if (!ssrc_forced_) { |
1505 // Generate a new SSRC. | 1511 // Generate a new SSRC. |
1506 ssrc_db_->ReturnSSRC(ssrc_); | 1512 ssrc_db_->ReturnSSRC(ssrc_); |
1507 ssrc_ = ssrc_db_->CreateSSRC(); | 1513 ssrc_ = ssrc_db_->CreateSSRC(); |
1508 RTC_DCHECK(ssrc_ != 0); | 1514 RTC_DCHECK(ssrc_ != 0); |
1509 } | 1515 } |
1510 // Don't initialize seq number if SSRC passed externally. | 1516 // Don't initialize seq number if SSRC passed externally. |
1511 if (!sequence_number_forced_ && !ssrc_forced_) { | 1517 if (!sequence_number_forced_ && !ssrc_forced_) { |
1512 // Generate a new sequence number. | 1518 // Generate a new sequence number. |
(...skipping 10 matching lines...) Expand all Loading... |
1523 bool RTPSender::SendingMedia() const { | 1529 bool RTPSender::SendingMedia() const { |
1524 rtc::CritScope lock(&send_critsect_); | 1530 rtc::CritScope lock(&send_critsect_); |
1525 return sending_media_; | 1531 return sending_media_; |
1526 } | 1532 } |
1527 | 1533 |
1528 uint32_t RTPSender::Timestamp() const { | 1534 uint32_t RTPSender::Timestamp() const { |
1529 rtc::CritScope lock(&send_critsect_); | 1535 rtc::CritScope lock(&send_critsect_); |
1530 return timestamp_; | 1536 return timestamp_; |
1531 } | 1537 } |
1532 | 1538 |
1533 void RTPSender::SetTimestampOffset(uint32_t timestamp) { | 1539 void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) { |
1534 rtc::CritScope lock(&send_critsect_); | 1540 rtc::CritScope lock(&send_critsect_); |
1535 timestamp_offset_ = timestamp; | 1541 if (force) { |
| 1542 start_timestamp_forced_ = true; |
| 1543 start_timestamp_ = timestamp; |
| 1544 } else { |
| 1545 if (!start_timestamp_forced_) { |
| 1546 start_timestamp_ = timestamp; |
| 1547 } |
| 1548 } |
1536 } | 1549 } |
1537 | 1550 |
1538 uint32_t RTPSender::TimestampOffset() const { | 1551 uint32_t RTPSender::StartTimestamp() const { |
1539 rtc::CritScope lock(&send_critsect_); | 1552 rtc::CritScope lock(&send_critsect_); |
1540 return timestamp_offset_; | 1553 return start_timestamp_; |
1541 } | 1554 } |
1542 | 1555 |
1543 uint32_t RTPSender::GenerateNewSSRC() { | 1556 uint32_t RTPSender::GenerateNewSSRC() { |
1544 // If configured via API, return 0. | 1557 // If configured via API, return 0. |
1545 rtc::CritScope lock(&send_critsect_); | 1558 rtc::CritScope lock(&send_critsect_); |
1546 | 1559 |
1547 if (ssrc_forced_) { | 1560 if (ssrc_forced_) { |
1548 return 0; | 1561 return 0; |
1549 } | 1562 } |
1550 ssrc_ = ssrc_db_->CreateSSRC(); | 1563 ssrc_ = ssrc_db_->CreateSSRC(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 | 1722 |
1710 uint32_t RTPSender::BitrateSent() const { | 1723 uint32_t RTPSender::BitrateSent() const { |
1711 rtc::CritScope cs(&statistics_crit_); | 1724 rtc::CritScope cs(&statistics_crit_); |
1712 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 1725 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
1713 } | 1726 } |
1714 | 1727 |
1715 void RTPSender::SetRtpState(const RtpState& rtp_state) { | 1728 void RTPSender::SetRtpState(const RtpState& rtp_state) { |
1716 rtc::CritScope lock(&send_critsect_); | 1729 rtc::CritScope lock(&send_critsect_); |
1717 sequence_number_ = rtp_state.sequence_number; | 1730 sequence_number_ = rtp_state.sequence_number; |
1718 sequence_number_forced_ = true; | 1731 sequence_number_forced_ = true; |
1719 timestamp_offset_ = rtp_state.start_timestamp; | |
1720 timestamp_ = rtp_state.timestamp; | 1732 timestamp_ = rtp_state.timestamp; |
1721 capture_time_ms_ = rtp_state.capture_time_ms; | 1733 capture_time_ms_ = rtp_state.capture_time_ms; |
1722 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; | 1734 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; |
1723 media_has_been_sent_ = rtp_state.media_has_been_sent; | 1735 media_has_been_sent_ = rtp_state.media_has_been_sent; |
1724 } | 1736 } |
1725 | 1737 |
1726 RtpState RTPSender::GetRtpState() const { | 1738 RtpState RTPSender::GetRtpState() const { |
1727 rtc::CritScope lock(&send_critsect_); | 1739 rtc::CritScope lock(&send_critsect_); |
1728 | 1740 |
1729 RtpState state; | 1741 RtpState state; |
1730 state.sequence_number = sequence_number_; | 1742 state.sequence_number = sequence_number_; |
1731 state.start_timestamp = timestamp_offset_; | 1743 state.start_timestamp = start_timestamp_; |
1732 state.timestamp = timestamp_; | 1744 state.timestamp = timestamp_; |
1733 state.capture_time_ms = capture_time_ms_; | 1745 state.capture_time_ms = capture_time_ms_; |
1734 state.last_timestamp_time_ms = last_timestamp_time_ms_; | 1746 state.last_timestamp_time_ms = last_timestamp_time_ms_; |
1735 state.media_has_been_sent = media_has_been_sent_; | 1747 state.media_has_been_sent = media_has_been_sent_; |
1736 | 1748 |
1737 return state; | 1749 return state; |
1738 } | 1750 } |
1739 | 1751 |
1740 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { | 1752 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { |
1741 rtc::CritScope lock(&send_critsect_); | 1753 rtc::CritScope lock(&send_critsect_); |
1742 sequence_number_rtx_ = rtp_state.sequence_number; | 1754 sequence_number_rtx_ = rtp_state.sequence_number; |
1743 } | 1755 } |
1744 | 1756 |
1745 RtpState RTPSender::GetRtxRtpState() const { | 1757 RtpState RTPSender::GetRtxRtpState() const { |
1746 rtc::CritScope lock(&send_critsect_); | 1758 rtc::CritScope lock(&send_critsect_); |
1747 | 1759 |
1748 RtpState state; | 1760 RtpState state; |
1749 state.sequence_number = sequence_number_rtx_; | 1761 state.sequence_number = sequence_number_rtx_; |
1750 state.start_timestamp = timestamp_offset_; | 1762 state.start_timestamp = start_timestamp_; |
1751 | 1763 |
1752 return state; | 1764 return state; |
1753 } | 1765 } |
1754 | 1766 |
1755 } // namespace webrtc | 1767 } // namespace webrtc |
OLD | NEW |