OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ | 5 #ifndef MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ |
6 #define MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ | 6 #define MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 // Measures download speed based on the rate at which a media file is buffering. | 17 // Measures download speed based on the rate at which a media file is buffering. |
18 // Signals when it believes the media file can be played back without needing to | 18 // Signals when it believes the media file can be played back without needing to |
19 // pause to buffer. | 19 // pause to buffer. |
20 class MEDIA_EXPORT DownloadRateMonitor { | 20 class MEDIA_EXPORT DownloadRateMonitor { |
21 public: | 21 public: |
22 DownloadRateMonitor(); | 22 DownloadRateMonitor(); |
23 ~DownloadRateMonitor(); | 23 ~DownloadRateMonitor(); |
24 | 24 |
25 // Begin measuring download rate. The monitor will run |canplaythrough_cb| | 25 // Begin measuring download rate. The monitor will run |canplaythrough_cb| |
26 // when it believes the media can be played back without needing to pause to | 26 // when it believes the media can be played back without needing to pause to |
27 // buffer. |media_bitrate| is the bitrate of the video. | 27 // buffer. |media_bitrate| is the bitrate of the video. |
28 void Start(const base::Closure& canplaythrough_cb, int media_bitrate); | 28 void Start(const base::Closure& canplaythrough_cb, int media_bitrate, |
| 29 bool streaming, bool local_source); |
29 | 30 |
30 // Notifies the monitor of the current number of bytes buffered by the media | 31 // Notifies the monitor of the current number of bytes buffered by the media |
31 // file at what timestamp. The monitor expects subsequent calls to | 32 // file at what timestamp. The monitor expects subsequent calls to |
32 // SetBufferedBytes to have monotonically nondecreasing timestamps. | 33 // SetBufferedBytes to have monotonically nondecreasing timestamps. |
33 // Calls to the method are ignored if monitor has not been started or is | 34 // Calls to the method are ignored if monitor has not been started or is |
34 // stopped. | 35 // stopped. |
35 void SetBufferedBytes(int64 buffered_bytes, const base::Time& timestamp); | 36 void SetBufferedBytes(int64 buffered_bytes, const base::Time& timestamp); |
36 | 37 |
37 // Notifies the monitor when the media file has paused or continued | 38 // Notifies the monitor when the media file has paused or continued |
38 // downloading data. | 39 // downloading data. |
39 void SetNetworkActivity(bool is_downloading_data); | 40 void SetNetworkActivity(bool is_downloading_data); |
40 | 41 |
41 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } | 42 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } |
42 | 43 |
43 void set_loaded(bool loaded) { loaded_ = loaded; } | |
44 | |
45 // Stop monitoring download rate. This does not discard previously learned | 44 // Stop monitoring download rate. This does not discard previously learned |
46 // information, but it will no longer factor incoming information into its | 45 // information, but it will no longer factor incoming information into its |
47 // canplaythrough estimation. | 46 // canplaythrough estimation. |
48 void Stop(); | 47 void Stop(); |
49 | 48 |
50 // Resets monitor to uninitialized state. | 49 // Resets monitor to uninitialized state. |
51 void Reset(); | 50 void Reset(); |
52 | 51 |
53 private: | 52 private: |
54 // Represents a point in time in which the media was buffering data. | 53 // Represents a point in time in which the media was buffering data. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 129 |
131 // True if actively downloading bytes, false otherwise. | 130 // True if actively downloading bytes, false otherwise. |
132 bool is_downloading_data_; | 131 bool is_downloading_data_; |
133 | 132 |
134 // Total number of bytes in the media file, 0 if unknown or undefined. | 133 // Total number of bytes in the media file, 0 if unknown or undefined. |
135 int64 total_bytes_; | 134 int64 total_bytes_; |
136 | 135 |
137 // Amount of bytes buffered. | 136 // Amount of bytes buffered. |
138 int64 buffered_bytes_; | 137 int64 buffered_bytes_; |
139 | 138 |
140 // True if the media file is a fully loaded source, e.g. file:// protocol. | 139 // True if the media file is from a local source, e.g. file:// protocol or a |
141 bool loaded_; | 140 // webcam stream. |
| 141 bool local_source_; |
142 | 142 |
143 // Bitrate of the media file, 0 if unknown. | 143 // Bitrate of the media file, 0 if unknown. |
144 int bitrate_; | 144 int bitrate_; |
145 | 145 |
146 // True if the monitor has not yet started or has been stopped, false | 146 // True if the monitor has not yet started or has been stopped, false |
147 // otherwise. | 147 // otherwise. |
148 bool stopped_; | 148 bool stopped_; |
149 | 149 |
| 150 // True if the data source is a streaming source, false otherwise. |
| 151 bool streaming_; |
| 152 |
150 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitor); | 153 DISALLOW_COPY_AND_ASSIGN(DownloadRateMonitor); |
151 }; | 154 }; |
152 | 155 |
153 } // namespace media | 156 } // namespace media |
154 | 157 |
155 #endif // MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ | 158 #endif // MEDIA_BASE_DOWNLOAD_RATE_MONITOR_H_ |
OLD | NEW |