OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_ | |
6 #define CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/time/time.h" | |
lcwu1
2014/08/28 02:14:58
We should also include ref_counted.h. (IWYU)
gunsch
2014/08/28 02:39:54
also base/macros.h, here and in buffering_controll
damienv1
2014/08/29 15:09:06
Done.
damienv1
2014/08/29 15:09:06
Done.
| |
12 | |
13 namespace media { | |
14 namespace cma { | |
15 | |
16 class BufferingConfig : public base::RefCountedThreadSafe<BufferingConfig> { | |
17 public: | |
18 BufferingConfig(base::TimeDelta low_level_threshold, | |
19 base::TimeDelta high_level_threshold); | |
20 | |
21 base::TimeDelta low_level() const { return low_level_threshold_; } | |
22 base::TimeDelta high_level() const { return high_level_threshold_; } | |
23 | |
24 void set_low_level(base::TimeDelta low_level) { | |
25 low_level_threshold_ = low_level; | |
26 } | |
27 void set_high_level(base::TimeDelta high_level) { | |
28 high_level_threshold_ = high_level; | |
29 } | |
30 | |
31 private: | |
32 friend class base::RefCountedThreadSafe<BufferingConfig>; | |
33 virtual ~BufferingConfig(); | |
34 | |
35 base::TimeDelta low_level_threshold_; | |
36 base::TimeDelta high_level_threshold_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(BufferingConfig); | |
39 }; | |
40 | |
41 class BufferingState | |
42 : public base::RefCountedThreadSafe<BufferingState> { | |
43 public: | |
44 typedef base::Callback<void(base::TimeDelta)> HighLevelBufferCb; | |
45 | |
46 enum State { | |
47 kLowLevel, | |
48 kMediumLevel, | |
49 kHighLevel, | |
50 kEosReached, | |
51 }; | |
52 | |
53 // Create a new buffering state. The initial state is |kLowLevel|. | |
gunsch
2014/08/28 02:39:54
style nit (throughout the CL): "Function comments
damienv1
2014/08/29 15:09:06
Done.
| |
54 // |state_changed_cb| is used to notify about possible state changes. | |
55 // |high_level_buffer_cb| is used to adjust the high buffer threshold | |
56 // when the underlying buffer is not large enough to accomodate | |
57 // the current high buffer level. | |
58 BufferingState(const scoped_refptr<BufferingConfig>& config, | |
59 const base::Closure& state_changed_cb, | |
60 const HighLevelBufferCb& high_level_buffer_cb); | |
61 | |
62 // Return the buffering state. | |
63 State GetState() const { return state_; } | |
64 | |
65 // Notify the buffering state that the buffering configuration | |
66 // has been changed. | |
67 // Update the state but do not trigger |state_changed_cb_|. | |
68 void OnConfigChanged(); | |
69 | |
70 // Set the current rendering time for that stream. | |
gunsch
2014/08/28 02:39:54
"this" stream ? (here and below)
damienv1
2014/08/29 15:09:06
Done.
| |
71 void SetMediaTime(base::TimeDelta media_time); | |
72 | |
73 // Set/get the maximum rendering media time for that stream. | |
74 // The maximum rendering time is always lower than the buffered time. | |
75 void SetMaxRenderingTime(base::TimeDelta max_rendering_time); | |
76 base::TimeDelta GetMaxRenderingTime() const; | |
77 | |
78 // Set the buffered time. | |
79 void SetBufferedTime(base::TimeDelta buffered_time); | |
80 | |
81 // Notify the buffering state that all the frames for that stream have been | |
82 // buffer, i.e. the end of stream has been reached. | |
83 void NotifyEos(); | |
84 | |
85 // Notify the buffering has reached its maximum capacity. | |
gunsch
2014/08/28 02:39:54
Clarify: who is being notified?
damienv1
2014/08/29 15:09:06
Done.
| |
86 // The maximum frame timestamp in the buffer is given by |buffered_time|. | |
87 // Note: this timestamp can be different from the one provided through | |
88 // SetBufferedTime since SetBufferedTime takes the timestamp of a playable | |
89 // frame which is not necessarily the case here (e.g. missing key id). | |
90 void NotifyMaxCapacity(base::TimeDelta buffered_time); | |
91 | |
92 // Human readable output operator, for debugging. | |
93 std::string ToString() const; | |
94 | |
95 private: | |
96 friend class base::RefCountedThreadSafe<BufferingState>; | |
97 virtual ~BufferingState(); | |
98 | |
99 // Return the state solely based on the buffered time. | |
100 State GetBufferLevelState() const; | |
101 | |
102 // Update the state to |new_state|. | |
103 void UpdateState(State new_state); | |
104 | |
105 scoped_refptr<BufferingConfig> const config_; | |
106 | |
107 // Callback invoked each time there is a change of state. | |
108 base::Closure state_changed_cb_; | |
109 | |
110 // Callback invoked to adjust the high buffer level. | |
111 HighLevelBufferCb high_level_buffer_cb_; | |
112 | |
113 // State. | |
114 State state_; | |
115 | |
116 // Playback media time. | |
117 // Equal to kNoTimestamp() when not known. | |
118 base::TimeDelta media_time_; | |
119 | |
120 // Maximum rendering media time. | |
121 // This corresponds to the timestamp of the last frame sent to the hardware | |
122 // decoder/renderer. | |
123 base::TimeDelta max_rendering_time_; | |
124 | |
125 // Buffered media time. | |
126 // Equal to kNoTimestamp() when not known. | |
127 base::TimeDelta buffered_time_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(BufferingState); | |
130 }; | |
131 | |
132 } // namespace cma | |
133 } // namespace media | |
134 | |
135 #endif // CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_ | |
OLD | NEW |