Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: components/copresence/handlers/audio/audio_directive_list.h

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

Powered by Google App Engine
This is Rietveld 408576698