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

Unified Diff: chromecast/media/cma/base/buffering_state.h

Issue 509213002: Add a buffering controller for Chromecast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ref-counting on the buffering controller. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chromecast/media/cma/base/buffering_state.h
diff --git a/chromecast/media/cma/base/buffering_state.h b/chromecast/media/cma/base/buffering_state.h
new file mode 100644
index 0000000000000000000000000000000000000000..1940b1aa772658d0152e98f75b7a8c74575292bc
--- /dev/null
+++ b/chromecast/media/cma/base/buffering_state.h
@@ -0,0 +1,135 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_
+#define CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_
+
+#include <string>
+
+#include "base/callback.h"
+#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.
+
+namespace media {
+namespace cma {
+
+class BufferingConfig : public base::RefCountedThreadSafe<BufferingConfig> {
+ public:
+ BufferingConfig(base::TimeDelta low_level_threshold,
+ base::TimeDelta high_level_threshold);
+
+ base::TimeDelta low_level() const { return low_level_threshold_; }
+ base::TimeDelta high_level() const { return high_level_threshold_; }
+
+ void set_low_level(base::TimeDelta low_level) {
+ low_level_threshold_ = low_level;
+ }
+ void set_high_level(base::TimeDelta high_level) {
+ high_level_threshold_ = high_level;
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<BufferingConfig>;
+ virtual ~BufferingConfig();
+
+ base::TimeDelta low_level_threshold_;
+ base::TimeDelta high_level_threshold_;
+
+ DISALLOW_COPY_AND_ASSIGN(BufferingConfig);
+};
+
+class BufferingState
+ : public base::RefCountedThreadSafe<BufferingState> {
+ public:
+ typedef base::Callback<void(base::TimeDelta)> HighLevelBufferCb;
+
+ enum State {
+ kLowLevel,
+ kMediumLevel,
+ kHighLevel,
+ kEosReached,
+ };
+
+ // 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.
+ // |state_changed_cb| is used to notify about possible state changes.
+ // |high_level_buffer_cb| is used to adjust the high buffer threshold
+ // when the underlying buffer is not large enough to accomodate
+ // the current high buffer level.
+ BufferingState(const scoped_refptr<BufferingConfig>& config,
+ const base::Closure& state_changed_cb,
+ const HighLevelBufferCb& high_level_buffer_cb);
+
+ // Return the buffering state.
+ State GetState() const { return state_; }
+
+ // Notify the buffering state that the buffering configuration
+ // has been changed.
+ // Update the state but do not trigger |state_changed_cb_|.
+ void OnConfigChanged();
+
+ // 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.
+ void SetMediaTime(base::TimeDelta media_time);
+
+ // Set/get the maximum rendering media time for that stream.
+ // The maximum rendering time is always lower than the buffered time.
+ void SetMaxRenderingTime(base::TimeDelta max_rendering_time);
+ base::TimeDelta GetMaxRenderingTime() const;
+
+ // Set the buffered time.
+ void SetBufferedTime(base::TimeDelta buffered_time);
+
+ // Notify the buffering state that all the frames for that stream have been
+ // buffer, i.e. the end of stream has been reached.
+ void NotifyEos();
+
+ // 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.
+ // The maximum frame timestamp in the buffer is given by |buffered_time|.
+ // Note: this timestamp can be different from the one provided through
+ // SetBufferedTime since SetBufferedTime takes the timestamp of a playable
+ // frame which is not necessarily the case here (e.g. missing key id).
+ void NotifyMaxCapacity(base::TimeDelta buffered_time);
+
+ // Human readable output operator, for debugging.
+ std::string ToString() const;
+
+ private:
+ friend class base::RefCountedThreadSafe<BufferingState>;
+ virtual ~BufferingState();
+
+ // Return the state solely based on the buffered time.
+ State GetBufferLevelState() const;
+
+ // Update the state to |new_state|.
+ void UpdateState(State new_state);
+
+ scoped_refptr<BufferingConfig> const config_;
+
+ // Callback invoked each time there is a change of state.
+ base::Closure state_changed_cb_;
+
+ // Callback invoked to adjust the high buffer level.
+ HighLevelBufferCb high_level_buffer_cb_;
+
+ // State.
+ State state_;
+
+ // Playback media time.
+ // Equal to kNoTimestamp() when not known.
+ base::TimeDelta media_time_;
+
+ // Maximum rendering media time.
+ // This corresponds to the timestamp of the last frame sent to the hardware
+ // decoder/renderer.
+ base::TimeDelta max_rendering_time_;
+
+ // Buffered media time.
+ // Equal to kNoTimestamp() when not known.
+ base::TimeDelta buffered_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(BufferingState);
+};
+
+} // namespace cma
+} // namespace media
+
+#endif // CHROMECAST_MEDIA_CMA_BASE_BUFFERING_STATE_H_

Powered by Google App Engine
This is Rietveld 408576698