Chromium Code Reviews| 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_CONTROLLER_H | |
| 6 #define CHROMECAST_MEDIA_CMA_BASE_BUFFERING_CONTROLLER_H | |
| 7 | |
| 8 #include <list> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "base/time/time.h" | |
| 15 | |
| 16 namespace media { | |
| 17 namespace cma { | |
| 18 class BufferingConfig; | |
| 19 class BufferingState; | |
| 20 | |
| 21 class BufferingController { | |
| 22 public: | |
| 23 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.
| |
| 24 | |
| 25 // Create a buffering controller where the conditions to trigger re-buffering | |
| 26 // are given by |config|. The whole point of the buffering controller is to | |
| 27 // derive a single buffering state from the buffering state of various | |
| 28 // streams. | |
| 29 // |buffering_notification_cb| is a callback invoked to inform about possible | |
| 30 // changes of the buffering state. | |
| 31 BufferingController( | |
| 32 const scoped_refptr<BufferingConfig>& config, | |
| 33 const BufferingNotificationCb& buffering_notification_cb); | |
| 34 ~BufferingController(); | |
| 35 | |
| 36 // Create a buffering state for one stream. This state is added to the list | |
| 37 // of streams monitored by the buffering controller. | |
| 38 scoped_refptr<BufferingState> AddStream(); | |
| 39 | |
| 40 // Set the playback time. | |
| 41 void SetMediaTime(base::TimeDelta time); | |
| 42 | |
| 43 // Return the maximum media time available for rendering. | |
| 44 // Return kNoTimestamp() if unknown. | |
| 45 base::TimeDelta GetMaxRenderingTime() const; | |
| 46 | |
| 47 // Return whether there is an active buffering phase. | |
| 48 bool IsBuffering() const { return is_buffering_; } | |
| 49 | |
| 50 // Reset the buffering controller. This includes removing all the buffering | |
| 51 // states that were previously added. | |
| 52 void Reset(); | |
| 53 | |
| 54 private: | |
| 55 // Invoked each time the buffering state of one of the streams has changed. | |
| 56 // If |force_notification| is set, |buffering_notification_cb_| is invoked | |
| 57 // regardless whether the buffering state has changed or not. | |
| 58 // If |buffering_timeout| is set, then the condition to leave the buffering | |
| 59 // state is relaxed (we don't want to wait more). | |
| 60 void OnBufferingStateChanged(bool force_notification, | |
| 61 bool buffering_timeout); | |
| 62 | |
| 63 // Update the high buffer level threshold to |high_level_threshold| | |
| 64 // if needed. | |
| 65 // This condition is triggered when one of the stream reached its maximum | |
| 66 // capacity. In that case, to avoid possible race condition (the buffering | |
| 67 // controller waits for more data to come but the buffer is to small to | |
| 68 // accomodate additional data), the thresholds in |config_| are adjusted | |
| 69 // accordingly. | |
| 70 void UpdateHighLevelThreshold(base::TimeDelta high_level_threshold); | |
| 71 | |
| 72 // Determine the overall buffer level based on the buffer level of each | |
| 73 // stream. | |
| 74 bool IsHighBufferLevel(); | |
| 75 bool IsLowBufferLevel(); | |
| 76 | |
| 77 // Log the state of the buffering controller. | |
| 78 void DumpState() const; | |
| 79 | |
| 80 base::ThreadChecker thread_checker_; | |
| 81 | |
| 82 // Settings used to determine when to start/stop buffering. | |
| 83 scoped_refptr<BufferingConfig> config_; | |
| 84 | |
| 85 // Callback invoked to inform the stream about the buffering state. | |
| 86 BufferingNotificationCb buffering_notification_cb_; | |
| 87 | |
| 88 // State of the buffering controller. | |
| 89 bool is_buffering_; | |
| 90 | |
| 91 // Buffering state for metrics reporting. | |
| 92 base::Time begin_buffering_time_; | |
| 93 | |
| 94 // Buffering level for each individual stream. | |
| 95 typedef std::list<scoped_refptr<BufferingState> > StreamList; | |
| 96 StreamList stream_list_; | |
| 97 | |
| 98 base::WeakPtrFactory<BufferingController> weak_factory_; | |
| 99 base::WeakPtr<BufferingController> weak_this_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(BufferingController); | |
| 102 }; | |
| 103 | |
| 104 } // namespace cma | |
| 105 } // namespace media | |
| 106 | |
| 107 #endif // CHROMECAST_MEDIA_CMA_BASE_BUFFERING_CONTROLLER_H | |
| OLD | NEW |