Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/remote_bitrate_estimator/remote_estimator_proxy.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <utility> | |
| 14 | 15 |
| 15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
| 18 #include "webrtc/modules/pacing/packet_router.h" | 19 #include "webrtc/modules/pacing/packet_router.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
| 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 // TODO(sprang): Tune these! | 25 // TODO(sprang): Tune these! |
| 25 const int RemoteEstimatorProxy::kDefaultProcessIntervalMs = 50; | 26 const int RemoteEstimatorProxy::kHighBitrateProcessIntervalMs = 50; |
| 27 const int RemoteEstimatorProxy::kLowBitrateProcessIntervalMs = 200; | |
| 28 const int RemoteEstimatorProxy::kSwitchToLowBitrateProcessIntervalBps = 50000; | |
| 29 const int RemoteEstimatorProxy::kSwitchToHighBitrateProcessIntervalBps = 100000; | |
|
stefan-webrtc
2016/10/17 18:55:21
I'm starting to lean towards making the interval a
| |
| 30 const int RemoteEstimatorProxy::kMinPacketCountRecievedBitrate = 50; | |
| 26 const int RemoteEstimatorProxy::kBackWindowMs = 500; | 31 const int RemoteEstimatorProxy::kBackWindowMs = 500; |
| 27 | 32 |
| 28 // The maximum allowed value for a timestamp in milliseconds. This is lower | 33 // The maximum allowed value for a timestamp in milliseconds. This is lower |
| 29 // than the numerical limit since we often convert to microseconds. | 34 // than the numerical limit since we often convert to microseconds. |
| 30 static constexpr int64_t kMaxTimeMs = | 35 static constexpr int64_t kMaxTimeMs = |
| 31 std::numeric_limits<int64_t>::max() / 1000; | 36 std::numeric_limits<int64_t>::max() / 1000; |
| 32 | 37 |
| 33 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock, | 38 RemoteEstimatorProxy::RemoteEstimatorProxy( |
| 34 PacketRouter* packet_router) | 39 Clock* clock, |
| 40 PacketRouter* packet_router, | |
| 41 std::unique_ptr<rtc::RateTracker> recieved_bitrate_tracker) | |
| 35 : clock_(clock), | 42 : clock_(clock), |
| 36 packet_router_(packet_router), | 43 packet_router_(packet_router), |
| 37 last_process_time_ms_(-1), | 44 last_process_time_ms_(-1), |
| 38 media_ssrc_(0), | 45 media_ssrc_(0), |
| 39 feedback_sequence_(0), | 46 feedback_sequence_(0), |
| 40 window_start_seq_(-1) {} | 47 window_start_seq_(-1), |
| 48 process_interval_ms_(kHighBitrateProcessIntervalMs), | |
| 49 received_bitrate_tracker_bps_(std::move(recieved_bitrate_tracker)) {} | |
| 41 | 50 |
| 42 RemoteEstimatorProxy::~RemoteEstimatorProxy() {} | 51 RemoteEstimatorProxy::~RemoteEstimatorProxy() {} |
| 43 | 52 |
| 44 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( | 53 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( |
| 45 const std::vector<PacketInfo>& packet_feedback_vector) { | 54 const std::vector<PacketInfo>& packet_feedback_vector) { |
| 46 rtc::CritScope cs(&lock_); | 55 rtc::CritScope cs(&lock_); |
| 47 for (PacketInfo info : packet_feedback_vector) | 56 for (PacketInfo info : packet_feedback_vector) |
| 48 OnPacketArrival(info.sequence_number, info.arrival_time_ms); | 57 OnPacketArrival(info.sequence_number, info.arrival_time_ms); |
| 49 } | 58 } |
| 50 | 59 |
| 51 void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms, | 60 void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms, |
| 52 size_t payload_size, | 61 size_t payload_size, |
| 53 const RTPHeader& header) { | 62 const RTPHeader& header) { |
| 54 if (!header.extension.hasTransportSequenceNumber) { | 63 if (!header.extension.hasTransportSequenceNumber) { |
| 55 LOG(LS_WARNING) << "RemoteEstimatorProxy: Incoming packet " | 64 LOG(LS_WARNING) << "RemoteEstimatorProxy: Incoming packet " |
| 56 "is missing the transport sequence number extension!"; | 65 "is missing the transport sequence number extension!"; |
| 57 return; | 66 return; |
| 58 } | 67 } |
| 59 rtc::CritScope cs(&lock_); | 68 rtc::CritScope cs(&lock_); |
| 60 media_ssrc_ = header.ssrc; | 69 media_ssrc_ = header.ssrc; |
| 61 | 70 received_bitrate_tracker_bps_->AddSamples(payload_size * 8); |
| 62 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); | 71 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); |
| 63 } | 72 } |
| 64 | 73 |
| 65 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, | 74 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, |
| 66 unsigned int* bitrate_bps) const { | 75 unsigned int* bitrate_bps) const { |
| 67 return false; | 76 return false; |
| 68 } | 77 } |
| 69 | 78 |
| 70 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { | 79 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { |
| 71 int64_t now = clock_->TimeInMilliseconds(); | 80 int64_t now = clock_->TimeInMilliseconds(); |
| 72 int64_t time_until_next = 0; | 81 int64_t time_until_next = 0; |
| 82 { | |
| 83 rtc::CritScope cs(&lock_); | |
| 84 if (received_bitrate_tracker_bps_->TotalSampleCount() > | |
| 85 kMinPacketCountRecievedBitrate) { | |
| 86 double recieved_bitrate = received_bitrate_tracker_bps_->ComputeRate(); | |
| 87 if (recieved_bitrate <= kSwitchToLowBitrateProcessIntervalBps) | |
| 88 process_interval_ms_ = kLowBitrateProcessIntervalMs; | |
| 89 if (recieved_bitrate >= kSwitchToHighBitrateProcessIntervalBps) | |
| 90 process_interval_ms_ = kHighBitrateProcessIntervalMs; | |
| 91 } | |
| 92 } | |
| 73 if (last_process_time_ms_ != -1 && | 93 if (last_process_time_ms_ != -1 && |
| 74 now - last_process_time_ms_ < kDefaultProcessIntervalMs) { | 94 now - last_process_time_ms_ < process_interval_ms_) { |
| 75 time_until_next = (last_process_time_ms_ + kDefaultProcessIntervalMs - now); | 95 time_until_next = (last_process_time_ms_ + process_interval_ms_ - now); |
| 76 } | 96 } |
| 77 return time_until_next; | 97 return time_until_next; |
| 78 } | 98 } |
| 79 | 99 |
| 80 void RemoteEstimatorProxy::Process() { | 100 void RemoteEstimatorProxy::Process() { |
| 81 last_process_time_ms_ = clock_->TimeInMilliseconds(); | 101 last_process_time_ms_ = clock_->TimeInMilliseconds(); |
| 82 | 102 |
| 83 bool more_to_build = true; | 103 bool more_to_build = true; |
| 84 while (more_to_build) { | 104 while (more_to_build) { |
| 85 rtcp::TransportFeedback feedback_packet; | 105 rtcp::TransportFeedback feedback_packet; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 // Note: Don't erase items from packet_arrival_times_ after sending, in case | 194 // Note: Don't erase items from packet_arrival_times_ after sending, in case |
| 175 // they need to be re-sent after a reordering. Removal will be handled | 195 // they need to be re-sent after a reordering. Removal will be handled |
| 176 // by OnPacketArrival once packets are too old. | 196 // by OnPacketArrival once packets are too old. |
| 177 window_start_seq_ = it->first + 1; | 197 window_start_seq_ = it->first + 1; |
| 178 } | 198 } |
| 179 | 199 |
| 180 return true; | 200 return true; |
| 181 } | 201 } |
| 182 | 202 |
| 183 } // namespace webrtc | 203 } // namespace webrtc |
| OLD | NEW |