OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/media/cma/base/buffering_controller.h" | 5 #include "chromecast/media/cma/base/buffering_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "chromecast/base/metrics/cast_metrics_helper.h" | |
10 #include "chromecast/media/cma/base/buffering_state.h" | 11 #include "chromecast/media/cma/base/buffering_state.h" |
11 #include "chromecast/media/cma/base/cma_logging.h" | 12 #include "chromecast/media/cma/base/cma_logging.h" |
12 #include "media/base/buffers.h" | 13 #include "media/base/buffers.h" |
13 | 14 |
14 namespace chromecast { | 15 namespace chromecast { |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 BufferingController::BufferingController( | 18 BufferingController::BufferingController( |
18 const scoped_refptr<BufferingConfig>& config, | 19 const scoped_refptr<BufferingConfig>& config, |
19 const BufferingNotificationCB& buffering_notification_cb) | 20 const BufferingNotificationCB& buffering_notification_cb) |
20 : config_(config), | 21 : config_(config), |
21 buffering_notification_cb_(buffering_notification_cb), | 22 buffering_notification_cb_(buffering_notification_cb), |
22 is_buffering_(false), | 23 is_buffering_(false), |
23 begin_buffering_time_(base::Time()), | 24 begin_buffering_time_(base::Time()), |
25 initial_buffering_(true), | |
24 weak_factory_(this) { | 26 weak_factory_(this) { |
25 weak_this_ = weak_factory_.GetWeakPtr(); | 27 weak_this_ = weak_factory_.GetWeakPtr(); |
26 thread_checker_.DetachFromThread(); | 28 thread_checker_.DetachFromThread(); |
27 } | 29 } |
28 | 30 |
29 BufferingController::~BufferingController() { | 31 BufferingController::~BufferingController() { |
30 // Some weak pointers might possibly be invalidated here. | 32 // Some weak pointers might possibly be invalidated here. |
31 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
32 } | 34 } |
33 | 35 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 max_rendering_time = max_stream_rendering_time; | 101 max_rendering_time = max_stream_rendering_time; |
100 } | 102 } |
101 } | 103 } |
102 return max_rendering_time; | 104 return max_rendering_time; |
103 } | 105 } |
104 | 106 |
105 void BufferingController::Reset() { | 107 void BufferingController::Reset() { |
106 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
107 | 109 |
108 is_buffering_ = false; | 110 is_buffering_ = false; |
109 stream_list_.clear(); | 111 stream_list_.clear(); |
damienv1
2014/10/16 00:00:13
Should initial_buffering_ be reset here as well ?
gunsch
2014/10/20 21:36:48
Done.
| |
110 } | 112 } |
111 | 113 |
112 void BufferingController::OnBufferingStateChanged( | 114 void BufferingController::OnBufferingStateChanged( |
113 bool force_notification, bool buffering_timeout) { | 115 bool force_notification, bool buffering_timeout) { |
114 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
115 | 117 |
116 // Log the state of each stream. | 118 // Log the state of each stream. |
117 DumpState(); | 119 DumpState(); |
118 | 120 |
119 bool is_low_buffering = IsLowBufferLevel(); | 121 bool is_low_buffering = IsLowBufferLevel(); |
(...skipping 20 matching lines...) Expand all Loading... | |
140 } | 142 } |
141 | 143 |
142 // End buffering. | 144 // End buffering. |
143 if (is_buffering_prv && !is_buffering_) { | 145 if (is_buffering_prv && !is_buffering_) { |
144 // TODO(damienv): |buffering_user_time| could be a UMA histogram. | 146 // TODO(damienv): |buffering_user_time| could be a UMA histogram. |
145 base::Time current_time = base::Time::Now(); | 147 base::Time current_time = base::Time::Now(); |
146 base::TimeDelta buffering_user_time = current_time - begin_buffering_time_; | 148 base::TimeDelta buffering_user_time = current_time - begin_buffering_time_; |
147 CMALOG(kLogControl) | 149 CMALOG(kLogControl) |
148 << "Buffering took: " | 150 << "Buffering took: " |
149 << buffering_user_time.InMilliseconds() << "ms"; | 151 << buffering_user_time.InMilliseconds() << "ms"; |
152 chromecast::metrics::CastMetricsHelper::BufferingType buffering_type = | |
153 initial_buffering_ ? | |
154 chromecast::metrics::CastMetricsHelper::kInitialBuffering : | |
155 chromecast::metrics::CastMetricsHelper::kBufferingAfterUnderrun; | |
156 chromecast::metrics::CastMetricsHelper::GetInstance()->LogTimeToBufferAv( | |
157 buffering_type, buffering_user_time); | |
158 | |
159 // Only the first buffering report is considered "initial buffering". | |
160 initial_buffering_ = false; | |
150 } | 161 } |
151 | 162 |
152 if (is_buffering_prv != is_buffering_ || force_notification) | 163 if (is_buffering_prv != is_buffering_ || force_notification) |
153 buffering_notification_cb_.Run(is_buffering_); | 164 buffering_notification_cb_.Run(is_buffering_); |
154 } | 165 } |
155 | 166 |
156 bool BufferingController::IsHighBufferLevel() { | 167 bool BufferingController::IsHighBufferLevel() { |
157 if (stream_list_.empty()) | 168 if (stream_list_.empty()) |
158 return true; | 169 return true; |
159 | 170 |
(...skipping 25 matching lines...) Expand all Loading... | |
185 void BufferingController::DumpState() const { | 196 void BufferingController::DumpState() const { |
186 CMALOG(kLogControl) << __FUNCTION__; | 197 CMALOG(kLogControl) << __FUNCTION__; |
187 for (StreamList::const_iterator it = stream_list_.begin(); | 198 for (StreamList::const_iterator it = stream_list_.begin(); |
188 it != stream_list_.end(); ++it) { | 199 it != stream_list_.end(); ++it) { |
189 CMALOG(kLogControl) << (*it)->ToString(); | 200 CMALOG(kLogControl) << (*it)->ToString(); |
190 } | 201 } |
191 } | 202 } |
192 | 203 |
193 } // namespace media | 204 } // namespace media |
194 } // namespace chromecast | 205 } // namespace chromecast |
OLD | NEW |