Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: media/blink/buffered_data_source_host_impl.h

Issue 2796193002: fix canplaythrough (Closed)
Patch Set: kSpecCompliantCanPlayThrough Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/media_switches.cc ('k') | media/blink/buffered_data_source_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "base/gtest_prod_util.h"
10 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/tick_clock.h"
11 #include "base/time/time.h" 15 #include "base/time/time.h"
12 #include "media/base/ranges.h" 16 #include "media/base/ranges.h"
13 #include "media/blink/interval_map.h" 17 #include "media/blink/interval_map.h"
14 #include "media/blink/media_blink_export.h" 18 #include "media/blink/media_blink_export.h"
15 19
16 namespace media { 20 namespace media {
17 21
18 // Interface for testing purposes. 22 // Interface for testing purposes.
19 class MEDIA_BLINK_EXPORT BufferedDataSourceHost { 23 class MEDIA_BLINK_EXPORT BufferedDataSourceHost {
20 public: 24 public:
21 // Notify the host of the total size of the media file. 25 // Notify the host of the total size of the media file.
22 virtual void SetTotalBytes(int64_t total_bytes) = 0; 26 virtual void SetTotalBytes(int64_t total_bytes) = 0;
23 27
24 // Notify the host that byte range [start,end] has been buffered. 28 // Notify the host that byte range [start,end] has been buffered.
25 // TODO(fischman): remove this method when demuxing is push-based instead of 29 // TODO(fischman): remove this method when demuxing is push-based instead of
26 // pull-based. http://crbug.com/131444 30 // pull-based. http://crbug.com/131444
27 virtual void AddBufferedByteRange(int64_t start, int64_t end) = 0; 31 virtual void AddBufferedByteRange(int64_t start, int64_t end) = 0;
28 32
29 protected: 33 protected:
30 virtual ~BufferedDataSourceHost() {} 34 virtual ~BufferedDataSourceHost() {}
31 }; 35 };
32 36
33 // Provides an implementation of BufferedDataSourceHost that translates the 37 // Provides an implementation of BufferedDataSourceHost that translates the
34 // buffered byte ranges into estimated time ranges. 38 // buffered byte ranges into estimated time ranges.
35 class MEDIA_BLINK_EXPORT BufferedDataSourceHostImpl 39 class MEDIA_BLINK_EXPORT BufferedDataSourceHostImpl
36 : public BufferedDataSourceHost { 40 : public BufferedDataSourceHost {
37 public: 41 public:
38 BufferedDataSourceHostImpl(); 42 BufferedDataSourceHostImpl(base::Closure progress_cb,
43 base::TickClock* tick_clock);
39 ~BufferedDataSourceHostImpl() override; 44 ~BufferedDataSourceHostImpl() override;
40 45
41 // BufferedDataSourceHost implementation. 46 // BufferedDataSourceHost implementation.
42 void SetTotalBytes(int64_t total_bytes) override; 47 void SetTotalBytes(int64_t total_bytes) override;
43 void AddBufferedByteRange(int64_t start, int64_t end) override; 48 void AddBufferedByteRange(int64_t start, int64_t end) override;
44 49
45 // Translate the byte ranges to time ranges and append them to the list. 50 // Translate the byte ranges to time ranges and append them to the list.
46 // TODO(sandersd): This is a confusing name, find something better. 51 // TODO(sandersd): This is a confusing name, find something better.
47 void AddBufferedTimeRanges( 52 void AddBufferedTimeRanges(
48 Ranges<base::TimeDelta>* buffered_time_ranges, 53 Ranges<base::TimeDelta>* buffered_time_ranges,
49 base::TimeDelta media_duration) const; 54 base::TimeDelta media_duration) const;
50 55
51 bool DidLoadingProgress(); 56 bool DidLoadingProgress();
52 57
58 // Returns true if we have enough buffered bytes to play from now
59 // until the end of media
60 bool CanPlayThrough(base::TimeDelta current_position,
61 base::TimeDelta media_duration,
62 double playback_rate) const;
63
64 // Caller must make sure |tick_clock| is valid for lifetime of this object.
65 void SetTickClockForTest(base::TickClock* tick_clock);
66
53 private: 67 private:
68 // Returns number of bytes not yet loaded in the given interval.
69 int64_t UnloadedBytesInInterval(const Interval<int64_t>& interval) const;
70
71 // Returns an estimate of the download rate.
72 // Returns 0.0 if an estimate cannot be made.
73 double DownloadRate() const;
74
54 // Total size of the data source. 75 // Total size of the data source.
55 int64_t total_bytes_; 76 int64_t total_bytes_;
56 77
57 // List of buffered byte ranges for estimating buffered time. 78 // List of buffered byte ranges for estimating buffered time.
58 // The InterValMap value is 1 for bytes that are buffered, 0 otherwise. 79 // The InterValMap value is 1 for bytes that are buffered, 0 otherwise.
59 IntervalMap<int64_t, int> buffered_byte_ranges_; 80 IntervalMap<int64_t, int> buffered_byte_ranges_;
60 81
61 // True when AddBufferedByteRange() has been called more recently than 82 // True when AddBufferedByteRange() has been called more recently than
62 // DidLoadingProgress(). 83 // DidLoadingProgress().
63 bool did_loading_progress_; 84 bool did_loading_progress_;
64 85
86 // Contains how much we had downloaded at a given time.
87 // Pruned to contain roughly the last 10 seconds of data.
88 std::deque<std::pair<base::TimeTicks, uint64_t>> download_history_;
89 base::Closure progress_cb_;
90
91 base::TickClock* tick_clock_;
92
93 FRIEND_TEST_ALL_PREFIXES(BufferedDataSourceHostImplTest, CanPlayThrough);
94 FRIEND_TEST_ALL_PREFIXES(BufferedDataSourceHostImplTest,
95 CanPlayThroughSmallAdvances);
65 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImpl); 96 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImpl);
66 }; 97 };
67 98
68 } // namespace media 99 } // namespace media
69 100
70 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_ 101 #endif // MEDIA_BLINK_BUFFERED_DATA_SOURCE_HOST_IMPL_H_
OLDNEW
« no previous file with comments | « media/base/media_switches.cc ('k') | media/blink/buffered_data_source_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698