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