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/video_engine/vie_remb.h" | 11 #include "webrtc/video_engine/vie_remb.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
18 #include "webrtc/modules/utility/include/process_thread.h" | 18 #include "webrtc/modules/utility/include/process_thread.h" |
19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
20 #include "webrtc/system_wrappers/include/tick_util.h" | 20 #include "webrtc/system_wrappers/include/tick_util.h" |
21 #include "webrtc/system_wrappers/include/trace.h" | 21 #include "webrtc/system_wrappers/include/trace.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 const int kRembSendIntervalMs = 200; | 25 const int kRembSendIntervalMs = 200; |
26 | 26 |
27 // % threshold for if we should send a new REMB asap. | 27 // % threshold for if we should send a new REMB asap. |
28 const unsigned int kSendThresholdPercent = 97; | 28 const unsigned int kSendThresholdPercent = 97; |
29 | 29 |
30 VieRemb::VieRemb() | 30 VieRemb::VieRemb(Clock* clock) |
31 : list_crit_(CriticalSectionWrapper::CreateCriticalSection()), | 31 : clock_(clock), |
32 last_remb_time_(TickTime::MillisecondTimestamp()), | 32 list_crit_(CriticalSectionWrapper::CreateCriticalSection()), |
| 33 last_remb_time_(clock_->TimeInMilliseconds()), |
33 last_send_bitrate_(0), | 34 last_send_bitrate_(0), |
34 bitrate_(0) {} | 35 bitrate_(0) {} |
35 | 36 |
36 VieRemb::~VieRemb() {} | 37 VieRemb::~VieRemb() {} |
37 | 38 |
38 void VieRemb::AddReceiveChannel(RtpRtcp* rtp_rtcp) { | 39 void VieRemb::AddReceiveChannel(RtpRtcp* rtp_rtcp) { |
39 assert(rtp_rtcp); | 40 assert(rtp_rtcp); |
40 | 41 |
41 CriticalSectionScoped cs(list_crit_.get()); | 42 CriticalSectionScoped cs(list_crit_.get()); |
42 if (std::find(receive_modules_.begin(), receive_modules_.end(), rtp_rtcp) != | 43 if (std::find(receive_modules_.begin(), receive_modules_.end(), rtp_rtcp) != |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 unsigned int bitrate) { | 99 unsigned int bitrate) { |
99 list_crit_->Enter(); | 100 list_crit_->Enter(); |
100 // If we already have an estimate, check if the new total estimate is below | 101 // If we already have an estimate, check if the new total estimate is below |
101 // kSendThresholdPercent of the previous estimate. | 102 // kSendThresholdPercent of the previous estimate. |
102 if (last_send_bitrate_ > 0) { | 103 if (last_send_bitrate_ > 0) { |
103 unsigned int new_remb_bitrate = last_send_bitrate_ - bitrate_ + bitrate; | 104 unsigned int new_remb_bitrate = last_send_bitrate_ - bitrate_ + bitrate; |
104 | 105 |
105 if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) { | 106 if (new_remb_bitrate < kSendThresholdPercent * last_send_bitrate_ / 100) { |
106 // The new bitrate estimate is less than kSendThresholdPercent % of the | 107 // The new bitrate estimate is less than kSendThresholdPercent % of the |
107 // last report. Send a REMB asap. | 108 // last report. Send a REMB asap. |
108 last_remb_time_ = TickTime::MillisecondTimestamp() - kRembSendIntervalMs; | 109 last_remb_time_ = clock_->TimeInMilliseconds() - kRembSendIntervalMs; |
109 } | 110 } |
110 } | 111 } |
111 bitrate_ = bitrate; | 112 bitrate_ = bitrate; |
112 | 113 |
113 // Calculate total receive bitrate estimate. | 114 // Calculate total receive bitrate estimate. |
114 int64_t now = TickTime::MillisecondTimestamp(); | 115 int64_t now = clock_->TimeInMilliseconds(); |
115 | 116 |
116 if (now - last_remb_time_ < kRembSendIntervalMs) { | 117 if (now - last_remb_time_ < kRembSendIntervalMs) { |
117 list_crit_->Leave(); | 118 list_crit_->Leave(); |
118 return; | 119 return; |
119 } | 120 } |
120 last_remb_time_ = now; | 121 last_remb_time_ = now; |
121 | 122 |
122 if (ssrcs.empty() || receive_modules_.empty()) { | 123 if (ssrcs.empty() || receive_modules_.empty()) { |
123 list_crit_->Leave(); | 124 list_crit_->Leave(); |
124 return; | 125 return; |
125 } | 126 } |
126 | 127 |
127 // Send a REMB packet. | 128 // Send a REMB packet. |
128 RtpRtcp* sender = NULL; | 129 RtpRtcp* sender = NULL; |
129 if (!rtcp_sender_.empty()) { | 130 if (!rtcp_sender_.empty()) { |
130 sender = rtcp_sender_.front(); | 131 sender = rtcp_sender_.front(); |
131 } else { | 132 } else { |
132 sender = receive_modules_.front(); | 133 sender = receive_modules_.front(); |
133 } | 134 } |
134 last_send_bitrate_ = bitrate_; | 135 last_send_bitrate_ = bitrate_; |
135 | 136 |
136 list_crit_->Leave(); | 137 list_crit_->Leave(); |
137 | 138 |
138 if (sender) { | 139 if (sender) { |
139 sender->SetREMBData(bitrate_, ssrcs); | 140 sender->SetREMBData(bitrate_, ssrcs); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 } // namespace webrtc | 144 } // namespace webrtc |
OLD | NEW |