| 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 base::TimeTicks end_time; | 31 base::TimeTicks end_time; |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 // This class maintains a list of active audio directives. It fetches the audio | 34 // This class maintains a list of active audio directives. It fetches the audio |
| 36 // samples associated with a audio transmit directives and expires directives | 35 // samples associated with a audio transmit directives and expires directives |
| 37 // that have outlived their TTL. | 36 // that have outlived their TTL. |
| 38 // TODO(rkc): Once we implement more token technologies, move reusable code | 37 // TODO(rkc): Once we implement more token technologies, move reusable code |
| 39 // from here to a base class and inherit various XxxxDirectiveList | 38 // from here to a base class and inherit various XxxxDirectiveList |
| 40 // classes from it. | 39 // classes from it. |
| 41 class AudioDirectiveList { | 40 class AudioDirectiveList { |
| 42 public: | 41 public: |
| 43 AudioDirectiveList(); | 42 AudioDirectiveList(); |
| 44 ~AudioDirectiveList(); | 43 ~AudioDirectiveList(); |
| 45 | 44 |
| 46 void AddDirective(const std::string& op_id, base::TimeDelta ttl); | 45 void AddDirective(const std::string& op_id, base::TimeDelta ttl); |
| 47 void RemoveDirective(const std::string& op_id); | 46 void RemoveDirective(const std::string& op_id); |
| 48 | 47 |
| 49 scoped_ptr<AudioDirective> GetActiveDirective(); | 48 scoped_ptr<AudioDirective> GetActiveDirective(); |
| 50 | 49 |
| 50 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock); |
| 51 |
| 51 private: | 52 private: |
| 52 // Comparator for comparing end_times on audio tokens. | 53 // Comparator for comparing end_times on audio tokens. |
| 53 class LatestFirstComparator { | 54 class LatestFirstComparator { |
| 54 public: | 55 public: |
| 55 // This will sort our queue with the 'latest' time being the top. | 56 // This will sort our queue with the 'latest' time being the top. |
| 56 bool operator()(const AudioDirective& left, | 57 bool operator()(const AudioDirective& left, |
| 57 const AudioDirective& right) const { | 58 const AudioDirective& right) const { |
| 58 return left.end_time < right.end_time; | 59 return left.end_time < right.end_time; |
| 59 } | 60 } |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 std::vector<AudioDirective>::iterator FindDirectiveByOpId( | 63 std::vector<AudioDirective>::iterator FindDirectiveByOpId( |
| 63 const std::string& op_id); | 64 const std::string& op_id); |
| 64 | 65 |
| 65 // This vector will be organized as a heap with the latest time as the first | 66 // This vector will be organized as a heap with the latest time as the first |
| 66 // element. Only currently active directives will exist in this list. | 67 // element. Only currently active directives will exist in this list. |
| 67 std::vector<AudioDirective> active_directives_; | 68 std::vector<AudioDirective> active_directives_; |
| 68 | 69 |
| 69 scoped_ptr<base::TickClock> clock_; | 70 scoped_refptr<TickClockRefCounted> clock_; |
| 70 | 71 |
| 71 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); | 72 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 } // namespace copresence | 75 } // namespace copresence |
| 75 | 76 |
| 76 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ | 77 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ |
| OLD | NEW |