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

Unified Diff: chromecast/media/cma/base/buffering_controller.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_controller.h
diff --git a/chromecast/media/cma/base/buffering_controller.h b/chromecast/media/cma/base/buffering_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..b85ffd2c73ed1ec9f1c71438bafdca63e60bbb45
--- /dev/null
+++ b/chromecast/media/cma/base/buffering_controller.h
@@ -0,0 +1,107 @@
+// 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_CONTROLLER_H
+#define CHROMECAST_MEDIA_CMA_BASE_BUFFERING_CONTROLLER_H
+
+#include <list>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+
+namespace media {
+namespace cma {
+class BufferingConfig;
+class BufferingState;
+
+class BufferingController {
+ public:
+ typedef base::Callback<void(bool)> BufferingNotificationCb;
xhwang 2014/08/28 20:44:43 nit: in media code, we use FooCB for callback type
damienv1 2014/08/29 15:09:06 Done.
+
+ // Create a buffering controller where the conditions to trigger re-buffering
+ // are given by |config|. The whole point of the buffering controller is to
+ // derive a single buffering state from the buffering state of various
+ // streams.
+ // |buffering_notification_cb| is a callback invoked to inform about possible
+ // changes of the buffering state.
+ BufferingController(
+ const scoped_refptr<BufferingConfig>& config,
+ const BufferingNotificationCb& buffering_notification_cb);
+ ~BufferingController();
+
+ // Create a buffering state for one stream. This state is added to the list
+ // of streams monitored by the buffering controller.
+ scoped_refptr<BufferingState> AddStream();
+
+ // Set the playback time.
+ void SetMediaTime(base::TimeDelta time);
+
+ // Return the maximum media time available for rendering.
+ // Return kNoTimestamp() if unknown.
+ base::TimeDelta GetMaxRenderingTime() const;
+
+ // Return whether there is an active buffering phase.
+ bool IsBuffering() const { return is_buffering_; }
+
+ // Reset the buffering controller. This includes removing all the buffering
+ // states that were previously added.
+ void Reset();
+
+ private:
+ // Invoked each time the buffering state of one of the streams has changed.
+ // If |force_notification| is set, |buffering_notification_cb_| is invoked
+ // regardless whether the buffering state has changed or not.
+ // If |buffering_timeout| is set, then the condition to leave the buffering
+ // state is relaxed (we don't want to wait more).
+ void OnBufferingStateChanged(bool force_notification,
+ bool buffering_timeout);
+
+ // Update the high buffer level threshold to |high_level_threshold|
+ // if needed.
+ // This condition is triggered when one of the stream reached its maximum
+ // capacity. In that case, to avoid possible race condition (the buffering
+ // controller waits for more data to come but the buffer is to small to
+ // accomodate additional data), the thresholds in |config_| are adjusted
+ // accordingly.
+ void UpdateHighLevelThreshold(base::TimeDelta high_level_threshold);
+
+ // Determine the overall buffer level based on the buffer level of each
+ // stream.
+ bool IsHighBufferLevel();
+ bool IsLowBufferLevel();
+
+ // Log the state of the buffering controller.
+ void DumpState() const;
+
+ base::ThreadChecker thread_checker_;
+
+ // Settings used to determine when to start/stop buffering.
+ scoped_refptr<BufferingConfig> config_;
+
+ // Callback invoked to inform the stream about the buffering state.
+ BufferingNotificationCb buffering_notification_cb_;
+
+ // State of the buffering controller.
+ bool is_buffering_;
+
+ // Buffering state for metrics reporting.
+ base::Time begin_buffering_time_;
+
+ // Buffering level for each individual stream.
+ typedef std::list<scoped_refptr<BufferingState> > StreamList;
+ StreamList stream_list_;
+
+ base::WeakPtrFactory<BufferingController> weak_factory_;
+ base::WeakPtr<BufferingController> weak_this_;
+
+ DISALLOW_COPY_AND_ASSIGN(BufferingController);
+};
+
+} // namespace cma
+} // namespace media
+
+#endif // CHROMECAST_MEDIA_CMA_BASE_BUFFERING_CONTROLLER_H

Powered by Google App Engine
This is Rietveld 408576698