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

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

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 1 month 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
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/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 15
16 namespace base {
17 class TickClock;
18 }
19
16 namespace media { 20 namespace media {
17 class AudioBusRefCounted; 21 class AudioBusRefCounted;
18 } 22 }
19 23
20 namespace copresence { 24 namespace copresence {
21 25
22 struct AudioDirective { 26 struct AudioDirective final {
Daniel Erat 2014/10/22 16:34:35 nit: putting final on a struct seems unnecessary
rkc 2014/10/22 18:21:47 Done.
23 // Default ctor, required by the priority queue. 27 // Default ctor, required by the priority queue.
24 AudioDirective(); 28 AudioDirective();
25 AudioDirective(const std::string& op_id, base::Time end_time); 29 AudioDirective(const std::string& op_id, base::TimeTicks end_time);
26 30
27 std::string op_id; 31 std::string op_id;
28 base::Time end_time; 32 base::TimeTicks end_time;
Daniel Erat 2014/10/22 16:34:35 while i pretty much always support the use of Time
rkc 2014/10/22 18:21:47 I read that in the documentation but don't think i
Daniel Erat 2014/10/22 18:32:40 i'm not aware of anything that returns ticks since
rkc 2014/10/22 19:28:46 So the posix implementation of Time::Now() returns
29 }; 33 };
30 34
31 // This class maintains a list of active audio directives. It fetches the audio 35 // This class maintains a list of active audio directives. It fetches the audio
32 // samples associated with a audio transmit directives and expires directives 36 // samples associated with a audio transmit directives and expires directives
33 // that have outlived their TTL. 37 // that have outlived their TTL.
34 // TODO(rkc): Once we implement more token technologies, move reusable code 38 // TODO(rkc): Once we implement more token technologies, move reusable code
35 // from here to a base class and inherit various XxxxDirectiveList 39 // from here to a base class and inherit various XxxxDirectiveList
36 // classes from it. 40 // classes from it.
37 class AudioDirectiveList { 41 class AudioDirectiveList {
38 public: 42 public:
39 AudioDirectiveList(); 43 AudioDirectiveList();
40 virtual ~AudioDirectiveList(); 44 ~AudioDirectiveList();
41 45
42 void AddDirective(const std::string& op_id, base::TimeDelta ttl); 46 void AddDirective(const std::string& op_id, base::TimeDelta ttl);
43 void RemoveDirective(const std::string& op_id); 47 void RemoveDirective(const std::string& op_id);
44 48
45 scoped_ptr<AudioDirective> GetActiveDirective(); 49 scoped_ptr<AudioDirective> GetActiveDirective();
46 50
47 private: 51 private:
48 // Comparator for comparing end_times on audio tokens. 52 // Comparator for comparing end_times on audio tokens.
49 class LatestFirstComparator { 53 class LatestFirstComparator {
50 public: 54 public:
51 // This will sort our queue with the 'latest' time being the top. 55 // This will sort our queue with the 'latest' time being the top.
52 bool operator()(const AudioDirective& left, 56 bool operator()(const AudioDirective& left,
53 const AudioDirective& right) const { 57 const AudioDirective& right) const {
54 return left.end_time < right.end_time; 58 return left.end_time < right.end_time;
55 } 59 }
56 }; 60 };
57 61
58 std::vector<AudioDirective>::iterator FindDirectiveByOpId( 62 std::vector<AudioDirective>::iterator FindDirectiveByOpId(
59 const std::string& op_id); 63 const std::string& op_id);
60 64
61 // This vector will be organized as a heap with the latest time as the first 65 // 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. 66 // element. Only currently active directives will exist in this list.
63 std::vector<AudioDirective> active_directives_; 67 std::vector<AudioDirective> active_directives_;
64 68
69 scoped_ptr<base::TickClock> clock_;
70
65 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); 71 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList);
66 }; 72 };
67 73
68 } // namespace copresence 74 } // namespace copresence
69 75
70 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ 76 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698