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.
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
17 class AudioBusRefCounted;
20 namespace copresence {
22 struct AudioDirective {
23 // Default ctor, required by the priority queue.
25 AudioDirective(const std::string& op_id, base::Time end_time);
31 // This class maintains a list of active audio directives. It fetches the audio
32 // samples associated with a audio transmit directives and expires directives
33 // that have outlived their TTL.
34 // TODO(rkc): Once we implement more token technologies, move reusable code
35 // from here to a base class and inherit various XxxxDirectiveList
37 class AudioDirectiveList {
40 virtual ~AudioDirectiveList();
42 void AddDirective(const std::string& op_id, base::TimeDelta ttl);
43 void RemoveDirective(const std::string& op_id);
45 scoped_ptr<AudioDirective> GetActiveDirective();
48 // Comparator for comparing end_times on audio tokens.
49 class LatestFirstComparator {
51 // This will sort our queue with the 'latest' time being the top.
52 bool operator()(const AudioDirective& left,
53 const AudioDirective& right) const {
54 return left.end_time < right.end_time;
58 std::vector<AudioDirective>::iterator FindDirectiveByOpId(
59 const std::string& op_id);
61 // This vector will be organized as a heap with the latest time as the first
62 // element. Only currently active directives will exist in this list.
63 std::vector<AudioDirective> active_directives_;
65 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList);
68 } // namespace copresence
70 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_