Chromium Code Reviews| 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 #ifndef MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ | 5 #ifndef MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ |
| 6 #define MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ | 6 #define MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <deque> | |
| 9 | 10 |
| 11 #include "base/callback.h" | |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 12 #include "media/base/ranges.h" | 14 #include "media/base/ranges.h" |
| 13 #include "media/blink/interval_map.h" | 15 #include "media/blink/interval_map.h" |
| 14 #include "media/blink/media_blink_export.h" | 16 #include "media/blink/media_blink_export.h" |
| 15 | 17 |
| 16 namespace media { | 18 namespace media { |
| 17 | 19 |
| 18 // Interface for testing purposes. | 20 // Interface for testing purposes. |
| 19 class MEDIA_BLINK_EXPORT BufferedDataSourceHost { | 21 class MEDIA_BLINK_EXPORT BufferedDataSourceHost { |
| 20 public: | 22 public: |
| 21 // Notify the host of the total size of the media file. | 23 // Notify the host of the total size of the media file. |
| 22 virtual void SetTotalBytes(int64_t total_bytes) = 0; | 24 virtual void SetTotalBytes(int64_t total_bytes) = 0; |
| 23 | 25 |
| 24 // Notify the host that byte range [start,end] has been buffered. | 26 // Notify the host that byte range [start,end] has been buffered. |
| 25 // TODO(fischman): remove this method when demuxing is push-based instead of | 27 // TODO(fischman): remove this method when demuxing is push-based instead of |
| 26 // pull-based. http://crbug.com/131444 | 28 // pull-based. http://crbug.com/131444 |
| 27 virtual void AddBufferedByteRange(int64_t start, int64_t end) = 0; | 29 virtual void AddBufferedByteRange(int64_t start, int64_t end) = 0; |
| 28 | 30 |
| 29 protected: | 31 protected: |
| 30 virtual ~BufferedDataSourceHost() {} | 32 virtual ~BufferedDataSourceHost() {} |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 // Provides an implementation of BufferedDataSourceHost that translates the | 35 // Provides an implementation of BufferedDataSourceHost that translates the |
| 34 // buffered byte ranges into estimated time ranges. | 36 // buffered byte ranges into estimated time ranges. |
| 35 class MEDIA_BLINK_EXPORT BufferedDataSourceHostImpl | 37 class MEDIA_BLINK_EXPORT BufferedDataSourceHostImpl |
| 36 : public BufferedDataSourceHost { | 38 : public BufferedDataSourceHost { |
| 37 public: | 39 public: |
| 38 BufferedDataSourceHostImpl(); | 40 explicit BufferedDataSourceHostImpl(const base::Closure& progress_cb); |
| 39 ~BufferedDataSourceHostImpl() override; | 41 ~BufferedDataSourceHostImpl() override; |
| 40 | 42 |
| 41 // BufferedDataSourceHost implementation. | 43 // BufferedDataSourceHost implementation. |
| 42 void SetTotalBytes(int64_t total_bytes) override; | 44 void SetTotalBytes(int64_t total_bytes) override; |
| 43 void AddBufferedByteRange(int64_t start, int64_t end) override; | 45 void AddBufferedByteRange(int64_t start, int64_t end) override; |
| 44 | 46 |
| 45 // Translate the byte ranges to time ranges and append them to the list. | 47 // Translate the byte ranges to time ranges and append them to the list. |
| 46 // TODO(sandersd): This is a confusing name, find something better. | 48 // TODO(sandersd): This is a confusing name, find something better. |
| 47 void AddBufferedTimeRanges( | 49 void AddBufferedTimeRanges( |
| 48 Ranges<base::TimeDelta>* buffered_time_ranges, | 50 Ranges<base::TimeDelta>* buffered_time_ranges, |
| 49 base::TimeDelta media_duration) const; | 51 base::TimeDelta media_duration) const; |
| 50 | 52 |
| 51 bool DidLoadingProgress(); | 53 bool DidLoadingProgress(); |
| 52 | 54 |
| 55 // Returns true if we have enough buffered bytes to play from now | |
| 56 // until the end of media | |
| 57 bool CanPlayThrough(base::TimeDelta current_position, | |
| 58 base::TimeDelta media_duration, | |
| 59 double playback_rate) const; | |
| 60 | |
| 53 private: | 61 private: |
| 62 // Returns number of bytes not yet loaded in the given interval. | |
| 63 int64_t UnloadedBytesInInterval(const Interval<int64_t>& interval) const; | |
| 64 | |
| 65 // Returns an estimate of the download rate. | |
| 66 // Returns 0.0 if an estimate cannot be made. | |
| 67 double DownloadRate() const; | |
| 68 | |
| 54 // Total size of the data source. | 69 // Total size of the data source. |
| 55 int64_t total_bytes_; | 70 int64_t total_bytes_; |
| 56 | 71 |
| 57 // List of buffered byte ranges for estimating buffered time. | 72 // List of buffered byte ranges for estimating buffered time. |
| 58 // The InterValMap value is 1 for bytes that are buffered, 0 otherwise. | 73 // The InterValMap value is 1 for bytes that are buffered, 0 otherwise. |
| 59 IntervalMap<int64_t, int> buffered_byte_ranges_; | 74 IntervalMap<int64_t, int> buffered_byte_ranges_; |
| 60 | 75 |
| 61 // True when AddBufferedByteRange() has been called more recently than | 76 // True when AddBufferedByteRange() has been called more recently than |
| 62 // DidLoadingProgress(). | 77 // DidLoadingProgress(). |
| 63 bool did_loading_progress_; | 78 bool did_loading_progress_; |
| 64 | 79 |
| 80 // Contains how much we had downloaded at a given time. | |
| 81 // Pruned to contain roughly the last 10 seconds of data. | |
| 82 std::deque<std::pair<base::TimeTicks, uint64_t>> download_history_; | |
|
sandersd (OOO until July 31)
2017/04/25 22:00:57
I'm a bit worried about the size and complexity of
hubbe
2017/04/25 23:47:03
Given that each entry represents at least 1000 byt
DaleCurtis
2017/04/26 00:11:26
What does the size of this look like currently? I
hubbe
2017/04/26 00:24:27
There is a maximum of 1000 entries right now.
| |
| 83 base::Closure progress_cb_; | |
| 84 | |
| 65 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImpl); | 85 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImpl); |
| 66 }; | 86 }; |
| 67 | 87 |
| 68 } // namespace media | 88 } // namespace media |
| 69 | 89 |
| 70 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ | 90 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ |
| OLD | NEW |