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