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), | |
114 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), | 112 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), |
115 remote_ssrc_(0), | 113 remote_ssrc_(0), |
116 sequence_number_forced_(false), | 114 sequence_number_forced_(false), |
117 ssrc_forced_(false), | 115 ssrc_forced_(false), |
118 timestamp_(0), | 116 timestamp_(0), |
119 capture_time_ms_(0), | 117 capture_time_ms_(0), |
120 last_timestamp_time_ms_(0), | 118 last_timestamp_time_ms_(0), |
121 media_has_been_sent_(false), | 119 media_has_been_sent_(false), |
122 last_packet_marker_bit_(false), | 120 last_packet_marker_bit_(false), |
123 csrcs_(), | 121 csrcs_(), |
124 rtx_(kRtxOff), | 122 rtx_(kRtxOff), |
125 retransmission_rate_limiter_(retransmission_rate_limiter) { | 123 retransmission_rate_limiter_(retransmission_rate_limiter) { |
126 ssrc_ = ssrc_db_->CreateSSRC(); | 124 ssrc_ = ssrc_db_->CreateSSRC(); |
127 RTC_DCHECK(ssrc_ != 0); | 125 RTC_DCHECK(ssrc_ != 0); |
128 ssrc_rtx_ = ssrc_db_->CreateSSRC(); | 126 ssrc_rtx_ = ssrc_db_->CreateSSRC(); |
129 RTC_DCHECK(ssrc_rtx_ != 0); | 127 RTC_DCHECK(ssrc_rtx_ != 0); |
130 | 128 |
| 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_ = start_timestamp_ + capture_timestamp; | 1102 timestamp_ = timestamp_offset_ + 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 { | |
1509 rtc::CritScope lock(&send_critsect_); | 1503 rtc::CritScope lock(&send_critsect_); |
1510 if (!ssrc_forced_) { | 1504 if (!ssrc_forced_) { |
1511 // Generate a new SSRC. | 1505 // Generate a new SSRC. |
1512 ssrc_db_->ReturnSSRC(ssrc_); | 1506 ssrc_db_->ReturnSSRC(ssrc_); |
1513 ssrc_ = ssrc_db_->CreateSSRC(); | 1507 ssrc_ = ssrc_db_->CreateSSRC(); |
1514 RTC_DCHECK(ssrc_ != 0); | 1508 RTC_DCHECK(ssrc_ != 0); |
1515 } | 1509 } |
1516 // Don't initialize seq number if SSRC passed externally. | 1510 // Don't initialize seq number if SSRC passed externally. |
1517 if (!sequence_number_forced_ && !ssrc_forced_) { | 1511 if (!sequence_number_forced_ && !ssrc_forced_) { |
1518 // Generate a new sequence number. | 1512 // Generate a new sequence number. |
(...skipping 10 matching lines...) Expand all Loading... |
1529 bool RTPSender::SendingMedia() const { | 1523 bool RTPSender::SendingMedia() const { |
1530 rtc::CritScope lock(&send_critsect_); | 1524 rtc::CritScope lock(&send_critsect_); |
1531 return sending_media_; | 1525 return sending_media_; |
1532 } | 1526 } |
1533 | 1527 |
1534 uint32_t RTPSender::Timestamp() const { | 1528 uint32_t RTPSender::Timestamp() const { |
1535 rtc::CritScope lock(&send_critsect_); | 1529 rtc::CritScope lock(&send_critsect_); |
1536 return timestamp_; | 1530 return timestamp_; |
1537 } | 1531 } |
1538 | 1532 |
1539 void RTPSender::SetStartTimestamp(uint32_t timestamp, bool force) { | 1533 void RTPSender::SetTimestampOffset(uint32_t timestamp) { |
1540 rtc::CritScope lock(&send_critsect_); | 1534 rtc::CritScope lock(&send_critsect_); |
1541 if (force) { | 1535 timestamp_offset_ = timestamp; |
1542 start_timestamp_forced_ = true; | |
1543 start_timestamp_ = timestamp; | |
1544 } else { | |
1545 if (!start_timestamp_forced_) { | |
1546 start_timestamp_ = timestamp; | |
1547 } | |
1548 } | |
1549 } | 1536 } |
1550 | 1537 |
1551 uint32_t RTPSender::StartTimestamp() const { | 1538 uint32_t RTPSender::TimestampOffset() const { |
1552 rtc::CritScope lock(&send_critsect_); | 1539 rtc::CritScope lock(&send_critsect_); |
1553 return start_timestamp_; | 1540 return timestamp_offset_; |
1554 } | 1541 } |
1555 | 1542 |
1556 uint32_t RTPSender::GenerateNewSSRC() { | 1543 uint32_t RTPSender::GenerateNewSSRC() { |
1557 // If configured via API, return 0. | 1544 // If configured via API, return 0. |
1558 rtc::CritScope lock(&send_critsect_); | 1545 rtc::CritScope lock(&send_critsect_); |
1559 | 1546 |
1560 if (ssrc_forced_) { | 1547 if (ssrc_forced_) { |
1561 return 0; | 1548 return 0; |
1562 } | 1549 } |
1563 ssrc_ = ssrc_db_->CreateSSRC(); | 1550 ssrc_ = ssrc_db_->CreateSSRC(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 | 1709 |
1723 uint32_t RTPSender::BitrateSent() const { | 1710 uint32_t RTPSender::BitrateSent() const { |
1724 rtc::CritScope cs(&statistics_crit_); | 1711 rtc::CritScope cs(&statistics_crit_); |
1725 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); | 1712 return total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0); |
1726 } | 1713 } |
1727 | 1714 |
1728 void RTPSender::SetRtpState(const RtpState& rtp_state) { | 1715 void RTPSender::SetRtpState(const RtpState& rtp_state) { |
1729 rtc::CritScope lock(&send_critsect_); | 1716 rtc::CritScope lock(&send_critsect_); |
1730 sequence_number_ = rtp_state.sequence_number; | 1717 sequence_number_ = rtp_state.sequence_number; |
1731 sequence_number_forced_ = true; | 1718 sequence_number_forced_ = true; |
| 1719 timestamp_offset_ = rtp_state.start_timestamp; |
1732 timestamp_ = rtp_state.timestamp; | 1720 timestamp_ = rtp_state.timestamp; |
1733 capture_time_ms_ = rtp_state.capture_time_ms; | 1721 capture_time_ms_ = rtp_state.capture_time_ms; |
1734 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; | 1722 last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms; |
1735 media_has_been_sent_ = rtp_state.media_has_been_sent; | 1723 media_has_been_sent_ = rtp_state.media_has_been_sent; |
1736 } | 1724 } |
1737 | 1725 |
1738 RtpState RTPSender::GetRtpState() const { | 1726 RtpState RTPSender::GetRtpState() const { |
1739 rtc::CritScope lock(&send_critsect_); | 1727 rtc::CritScope lock(&send_critsect_); |
1740 | 1728 |
1741 RtpState state; | 1729 RtpState state; |
1742 state.sequence_number = sequence_number_; | 1730 state.sequence_number = sequence_number_; |
1743 state.start_timestamp = start_timestamp_; | 1731 state.start_timestamp = timestamp_offset_; |
1744 state.timestamp = timestamp_; | 1732 state.timestamp = timestamp_; |
1745 state.capture_time_ms = capture_time_ms_; | 1733 state.capture_time_ms = capture_time_ms_; |
1746 state.last_timestamp_time_ms = last_timestamp_time_ms_; | 1734 state.last_timestamp_time_ms = last_timestamp_time_ms_; |
1747 state.media_has_been_sent = media_has_been_sent_; | 1735 state.media_has_been_sent = media_has_been_sent_; |
1748 | 1736 |
1749 return state; | 1737 return state; |
1750 } | 1738 } |
1751 | 1739 |
1752 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { | 1740 void RTPSender::SetRtxRtpState(const RtpState& rtp_state) { |
1753 rtc::CritScope lock(&send_critsect_); | 1741 rtc::CritScope lock(&send_critsect_); |
1754 sequence_number_rtx_ = rtp_state.sequence_number; | 1742 sequence_number_rtx_ = rtp_state.sequence_number; |
1755 } | 1743 } |
1756 | 1744 |
1757 RtpState RTPSender::GetRtxRtpState() const { | 1745 RtpState RTPSender::GetRtxRtpState() const { |
1758 rtc::CritScope lock(&send_critsect_); | 1746 rtc::CritScope lock(&send_critsect_); |
1759 | 1747 |
1760 RtpState state; | 1748 RtpState state; |
1761 state.sequence_number = sequence_number_rtx_; | 1749 state.sequence_number = sequence_number_rtx_; |
1762 state.start_timestamp = start_timestamp_; | 1750 state.start_timestamp = timestamp_offset_; |
1763 | 1751 |
1764 return state; | 1752 return state; |
1765 } | 1753 } |
1766 | 1754 |
1767 } // namespace webrtc | 1755 } // namespace webrtc |
OLD | NEW |