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

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

Issue 460743004: Improve audible token detection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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_ 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_ 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 46
47 // This class maintains a list of active audio directives. It fetches the audio 47 // This class maintains a list of active audio directives. It fetches the audio
48 // samples associated with a audio transmit directives and expires directives 48 // samples associated with a audio transmit directives and expires directives
49 // that have outlived their TTL. 49 // that have outlived their TTL.
50 // TODO(rkc): Once we implement more token technologies, move reusable code 50 // TODO(rkc): Once we implement more token technologies, move reusable code
51 // from here to a base class and inherit various XxxxDirectiveList 51 // from here to a base class and inherit various XxxxDirectiveList
52 // classes from it. 52 // classes from it.
53 class AudioDirectiveList { 53 class AudioDirectiveList {
54 public: 54 public:
55 typedef base::Callback< 55 typedef base::Callback<void(const std::string&,
56 void(const std::string&, const scoped_refptr<media::AudioBusRefCounted>&)> 56 bool,
57 const scoped_refptr<media::AudioBusRefCounted>&)>
57 SamplesCallback; 58 SamplesCallback;
58 typedef base::Callback<void(const std::string&, bool, const SamplesCallback&)> 59 typedef base::Callback<void(const std::string&, bool, const SamplesCallback&)>
59 EncodeTokenCallback; 60 EncodeTokenCallback;
60 61
61 AudioDirectiveList(const EncodeTokenCallback& encode_token_callback, 62 AudioDirectiveList(const EncodeTokenCallback& encode_token_callback,
62 const base::Closure& token_added_callback, 63 const base::Closure& token_added_callback,
63 bool use_audible_encoding); 64 bool use_audible_encoding);
64 virtual ~AudioDirectiveList(); 65 virtual ~AudioDirectiveList();
65 66
66 // Adds a token to the token queue, after getting its corresponding samples 67 // Adds a token to the token queue, after getting its corresponding samples
67 // from whispernet. 68 // from whispernet.
68 void AddTransmitDirective(const std::string& token, 69 void AddTransmitDirective(const std::string& token,
69 const std::string& op_id, 70 const std::string& op_id,
70 base::TimeDelta ttl); 71 base::TimeDelta ttl);
71 72
72 void AddReceiveDirective(const std::string& op_id, base::TimeDelta ttl); 73 void AddReceiveDirective(const std::string& op_id, base::TimeDelta ttl);
73 74
74 // Returns the next audio token to play. This also cleans up expired tokens. 75 // Returns the next audio token to play. This also cleans up expired tokens.
75 scoped_ptr<AudioDirective> GetNextTransmit(); 76 scoped_ptr<AudioDirective> GetNextTransmit();
76 scoped_ptr<AudioDirective> GetNextReceive(); 77 scoped_ptr<AudioDirective> GetNextReceive();
77 78
78 // This is the method that the whispernet client needs to call to return 79 // This is the method that the whispernet client needs to call to return
79 // samples to us. 80 // samples to us.
80 void OnTokenEncoded(const std::string& token, 81 void OnTokenEncoded(const std::string& token,
82 bool audible,
81 const scoped_refptr<media::AudioBusRefCounted>& samples); 83 const scoped_refptr<media::AudioBusRefCounted>& samples);
82 84
83 private: 85 private:
84 // Comparator for comparing end_times on audio tokens. 86 // Comparator for comparing end_times on audio tokens.
85 class LatestFirstComparator { 87 class LatestFirstComparator {
86 public: 88 public:
87 // This will sort our queue with the 'latest' time being the top. 89 // This will sort our queue with the 'latest' time being the top.
88 bool operator()(const AudioDirective& left, 90 bool operator()(const AudioDirective& left,
89 const AudioDirective& right) const { 91 const AudioDirective& right) const {
90 return left.end_time < right.end_time; 92 return left.end_time < right.end_time;
(...skipping 22 matching lines...) Expand all
113 // Cache that holds the encoded samples. After reaching its limit, the cache 115 // Cache that holds the encoded samples. After reaching its limit, the cache
114 // expires the oldest samples first. 116 // expires the oldest samples first.
115 SamplesMap samples_cache_; 117 SamplesMap samples_cache_;
116 118
117 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); 119 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList);
118 }; 120 };
119 121
120 } // namespace copresence 122 } // namespace copresence
121 123
122 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_ 124 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698