OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <limits> | |
12 | |
13 #include "webrtc/base/checks.h" | |
14 #include "webrtc/base/logging.h" | |
15 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | |
16 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" | |
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | |
18 #include "webrtc/modules/utility/interface/process_thread.h" | |
19 | |
20 namespace webrtc { | |
21 | |
22 const int64_t kSendTimeHistoryWindowMs = 2000; | |
23 const int64_t kNoTimestamp = std::numeric_limits<int64_t>::min(); | |
stefan-webrtc
2015/09/10 11:10:01
Doesn't -1 work?
sprang_webrtc
2015/09/11 12:33:47
Yes. Initially I allowed slightly negative timesta
| |
24 const int64_t kBaseTimestampScaleFactor = | |
25 rtcp::TransportFeedback::kDeltaScaleFactor * (1 << 8); | |
26 const int64_t kBaseTimestampRangeSizeUs = kBaseTimestampScaleFactor * (1 << 24); | |
27 | |
28 TransportFeedbackAdapter::TransportFeedbackAdapter( | |
29 RtcpBandwidthObserver* bandwidth_observer, | |
30 Clock* clock, | |
31 ProcessThread* process_thread) | |
32 : send_time_history_(kSendTimeHistoryWindowMs), | |
33 rtcp_bandwidth_observer_(bandwidth_observer), | |
34 process_thread_(process_thread), | |
35 clock_(clock), | |
36 current_offset_ms_(kNoTimestamp), | |
37 last_timestamp_us_(kNoTimestamp) {} | |
38 | |
39 TransportFeedbackAdapter::~TransportFeedbackAdapter() { | |
40 if (bitrate_estimator_.get()) | |
41 process_thread_->DeRegisterModule(bitrate_estimator_.get()); | |
42 } | |
43 | |
44 void TransportFeedbackAdapter::SetBitrateEstimator( | |
45 RemoteBitrateEstimator* rbe) { | |
46 if (bitrate_estimator_.get() != rbe) { | |
47 bitrate_estimator_.reset(rbe); | |
48 process_thread_->RegisterModule(rbe); | |
49 } | |
50 } | |
51 | |
52 void TransportFeedbackAdapter::OnPacketSent(uint16_t sequence_number, | |
53 int64_t send_time, | |
54 size_t size, | |
55 bool was_paced) { | |
56 rtc::CritScope cs(&lock_); | |
57 send_time_history_.AddAndRemoveOld( | |
58 PacketInfo(0, send_time, sequence_number, size, was_paced)); | |
59 } | |
60 | |
61 void TransportFeedbackAdapter::OnTransportFeedback( | |
62 const rtcp::TransportFeedback& feedback) { | |
63 int64_t timestamp_us = feedback.GetBaseTimeUs(); | |
64 if (last_timestamp_us_ == kNoTimestamp) { | |
65 current_offset_ms_ = clock_->TimeInMilliseconds(); | |
66 } else { | |
67 int64_t delta = timestamp_us - last_timestamp_us_; | |
68 | |
69 if (labs(delta - kBaseTimestampRangeSizeUs) < labs(delta)) { | |
stefan-webrtc
2015/09/10 11:10:01
std::abs<int64_t> or something like that instead?
stefan-webrtc
2015/09/10 11:10:01
Comment on what lines 69-73 are doing.
sprang_webrtc
2015/09/11 12:33:47
Done.
sprang_webrtc
2015/09/11 12:33:47
Done.
| |
70 delta -= kBaseTimestampRangeSizeUs; | |
71 } else if (labs(delta + kBaseTimestampRangeSizeUs) < labs(delta)) { | |
72 delta += kBaseTimestampRangeSizeUs; | |
73 } | |
74 | |
75 current_offset_ms_ += delta / 1000; | |
76 } | |
77 last_timestamp_us_ = timestamp_us; | |
78 | |
79 uint16_t sequence_number = feedback.GetBaseSequence(); | |
80 std::vector<int64_t> delta_vec = feedback.GetReceiveDeltasUs(); | |
81 auto delta_it = delta_vec.begin(); | |
82 std::vector<PacketInfo> packet_feedback_vector; | |
83 packet_feedback_vector.reserve(delta_vec.size()); | |
84 | |
85 { | |
86 rtc::CritScope cs(&lock_); | |
87 size_t failed_lookups = 0; | |
88 int64_t offset_us = 0; | |
89 for (auto symbol : feedback.GetStatusVector()) { | |
90 if (symbol != rtcp::TransportFeedback::StatusSymbol::kNotReceived) { | |
91 DCHECK(delta_it != delta_vec.end()); | |
92 offset_us += *(delta_it++); | |
93 int64_t ms_timestamp = current_offset_ms_ + (offset_us / 1000); | |
stefan-webrtc
2015/09/10 11:10:01
timestamp_ms
sprang_webrtc
2015/09/11 12:33:47
Done.
| |
94 PacketInfo info = {ms_timestamp, 0, sequence_number, 0, false}; | |
95 if (send_time_history_.GetInfo(&info, true)) { | |
96 packet_feedback_vector.push_back(info); | |
97 } else { | |
98 ++failed_lookups; | |
99 } | |
100 } | |
101 ++sequence_number; | |
102 } | |
103 DCHECK(delta_it == delta_vec.end()); | |
104 if (failed_lookups > 0) { | |
105 LOG(LS_WARNING) << "Failed to lookup send time for " << failed_lookups | |
106 << " packet" << (failed_lookups > 1 ? "s" : "") | |
107 << ". Send time history too small?"; | |
108 } | |
109 } | |
110 DCHECK(bitrate_estimator_.get() != nullptr); | |
111 bitrate_estimator_->IncomingPacketFeedbackVector(packet_feedback_vector); | |
112 } | |
113 | |
114 void TransportFeedbackAdapter::OnReceiveBitrateChanged( | |
115 const std::vector<unsigned int>& ssrcs, | |
116 unsigned int bitrate) { | |
117 rtcp_bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate); | |
118 } | |
119 | |
120 void TransportFeedbackAdapter::OnRttUpdate(int64_t avg_rtt_ms, | |
121 int64_t max_rtt_ms) { | |
122 DCHECK(bitrate_estimator_.get() != nullptr); | |
123 bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
124 } | |
125 | |
126 } // namespace webrtc | |
OLD | NEW |