| OLD | NEW |
| 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 COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ | 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ |
| 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ | 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 | 16 |
| 16 namespace base { | |
| 17 class TickClock; | |
| 18 } | |
| 19 | |
| 20 namespace media { | 17 namespace media { |
| 21 class AudioBusRefCounted; | 18 class AudioBusRefCounted; |
| 22 } | 19 } |
| 23 | 20 |
| 24 namespace copresence { | 21 namespace copresence { |
| 25 | 22 |
| 23 class TickClockRefCounted; |
| 24 |
| 26 struct AudioDirective final { | 25 struct AudioDirective final { |
| 27 // Default ctor, required by the priority queue. | 26 // Default ctor, required by the priority queue. |
| 28 AudioDirective(); | 27 AudioDirective(); |
| 29 AudioDirective(const std::string& op_id, base::TimeTicks end_time); | 28 AudioDirective(const std::string& op_id, base::TimeTicks end_time); |
| 30 | 29 |
| 31 std::string op_id; | 30 std::string op_id; |
| 32 // We're currently using TimeTicks to track time. This may not work for cases | 31 // We're currently using TimeTicks to track time. This may not work for cases |
| 33 // where your machine suspends. See crbug.com/426136 | 32 // where your machine suspends. See crbug.com/426136 |
| 34 base::TimeTicks end_time; | 33 base::TimeTicks end_time; |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 // This class maintains a list of active audio directives. It fetches the audio | 36 // This class maintains a list of active audio directives. It fetches the audio |
| 38 // samples associated with a audio transmit directives and expires directives | 37 // samples associated with a audio transmit directives and expires directives |
| 39 // that have outlived their TTL. | 38 // that have outlived their TTL. |
| 40 // TODO(rkc): Once we implement more token technologies, move reusable code | 39 // TODO(rkc): Once we implement more token technologies, move reusable code |
| 41 // from here to a base class and inherit various XxxxDirectiveList | 40 // from here to a base class and inherit various XxxxDirectiveList |
| 42 // classes from it. | 41 // classes from it. |
| 43 class AudioDirectiveList { | 42 class AudioDirectiveList { |
| 44 public: | 43 public: |
| 45 AudioDirectiveList(); | 44 AudioDirectiveList(); |
| 46 ~AudioDirectiveList(); | 45 ~AudioDirectiveList(); |
| 47 | 46 |
| 48 void AddDirective(const std::string& op_id, base::TimeDelta ttl); | 47 void AddDirective(const std::string& op_id, base::TimeDelta ttl); |
| 49 void RemoveDirective(const std::string& op_id); | 48 void RemoveDirective(const std::string& op_id); |
| 50 | 49 |
| 51 scoped_ptr<AudioDirective> GetActiveDirective(); | 50 scoped_ptr<AudioDirective> GetActiveDirective(); |
| 52 | 51 |
| 52 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock); |
| 53 |
| 53 private: | 54 private: |
| 54 // Comparator for comparing end_times on audio tokens. | 55 // Comparator for comparing end_times on audio tokens. |
| 55 class LatestFirstComparator { | 56 class LatestFirstComparator { |
| 56 public: | 57 public: |
| 57 // This will sort our queue with the 'latest' time being the top. | 58 // This will sort our queue with the 'latest' time being the top. |
| 58 bool operator()(const AudioDirective& left, | 59 bool operator()(const AudioDirective& left, |
| 59 const AudioDirective& right) const { | 60 const AudioDirective& right) const { |
| 60 return left.end_time < right.end_time; | 61 return left.end_time < right.end_time; |
| 61 } | 62 } |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 std::vector<AudioDirective>::iterator FindDirectiveByOpId( | 65 std::vector<AudioDirective>::iterator FindDirectiveByOpId( |
| 65 const std::string& op_id); | 66 const std::string& op_id); |
| 66 | 67 |
| 67 // This vector will be organized as a heap with the latest time as the first | 68 // This vector will be organized as a heap with the latest time as the first |
| 68 // element. Only currently active directives will exist in this list. | 69 // element. Only currently active directives will exist in this list. |
| 69 std::vector<AudioDirective> active_directives_; | 70 std::vector<AudioDirective> active_directives_; |
| 70 | 71 |
| 71 scoped_ptr<base::TickClock> clock_; | 72 scoped_refptr<TickClockRefCounted> clock_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); | 74 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace copresence | 77 } // namespace copresence |
| 77 | 78 |
| 78 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ | 79 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ |
| OLD | NEW |