OLD | NEW |
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_HANDLER_H_ | 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ |
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ | 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/time/time.h" | |
15 #include "components/copresence/handlers/audio/audio_directive_list.h" | |
16 #include "components/copresence/mediums/audio/audio_manager.h" | 10 #include "components/copresence/mediums/audio/audio_manager.h" |
17 #include "components/copresence/proto/data.pb.h" | 11 #include "components/copresence/public/copresence_constants.h" |
18 | 12 |
19 namespace base { | 13 namespace base { |
20 class Timer; | 14 class TimeDelta; |
21 } | |
22 | |
23 namespace media { | |
24 class AudioBusRefCounted; | |
25 } | 15 } |
26 | 16 |
27 namespace copresence { | 17 namespace copresence { |
28 | 18 |
29 class TickClockRefCounted; | 19 class TokenInstruction; |
30 | 20 |
31 // The AudioDirectiveHandler handles audio transmit and receive instructions. | 21 // The AudioDirectiveHandler handles audio transmit and receive instructions. |
32 // TODO(rkc): Currently since WhispernetClient can only have one token encoded | 22 class AudioDirectiveHandler { |
33 // callback at a time, we need to have both the audible and inaudible in this | |
34 // class. Investigate a better way to do this; a few options are abstracting | |
35 // out token encoding to a separate class, or allowing whispernet to have | |
36 // multiple callbacks for encoded tokens being sent back and have two versions | |
37 // of this class. | |
38 class AudioDirectiveHandler final { | |
39 public: | 23 public: |
40 AudioDirectiveHandler(); | 24 virtual ~AudioDirectiveHandler() {} |
41 ~AudioDirectiveHandler(); | |
42 | 25 |
43 // Do not use this class before calling this. | 26 // Do not use this class before calling this. |
44 void Initialize(const AudioManager::DecodeSamplesCallback& decode_cb, | 27 virtual void Initialize( |
45 const AudioManager::EncodeTokenCallback& encode_cb); | 28 const AudioManager::DecodeSamplesCallback& decode_cb, |
| 29 const AudioManager::EncodeTokenCallback& encode_cb) = 0; |
46 | 30 |
47 // Adds an instruction to our handler. The instruction will execute and be | 31 // Adds an instruction to our handler. The instruction will execute and be |
48 // removed after the ttl expires. | 32 // removed after the ttl expires. |
49 void AddInstruction(const copresence::TokenInstruction& instruction, | 33 virtual void AddInstruction(const TokenInstruction& instruction, |
50 const std::string& op_id, | 34 const std::string& op_id, |
51 base::TimeDelta ttl_ms); | 35 base::TimeDelta ttl_ms) = 0; |
52 | 36 |
53 // Removes all instructions associated with this operation id. | 37 // Removes all instructions associated with this operation id. |
54 void RemoveInstructions(const std::string& op_id); | 38 virtual void RemoveInstructions(const std::string& op_id) = 0; |
55 | 39 |
56 // Returns the currently playing token. | 40 // Returns the currently playing token. |
57 const std::string PlayingToken(AudioType type) const; | 41 virtual const std::string PlayingToken(AudioType type) const = 0; |
58 | |
59 // The manager being passed in needs to be uninitialized. | |
60 void set_audio_manager_for_testing(scoped_ptr<AudioManager> manager) { | |
61 audio_manager_ = manager.Pass(); | |
62 } | |
63 | |
64 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock); | |
65 void set_timer_for_testing(scoped_ptr<base::Timer> timer); | |
66 | |
67 private: | |
68 // Processes the next active instruction, updating our audio manager state | |
69 // accordingly. | |
70 void ProcessNextInstruction(); | |
71 | |
72 // Returns the time that an instruction expires at. This will always return | |
73 // the earliest expiry time among all the active receive and transmit | |
74 // instructions. In case we don't have any active instructions, this method | |
75 // returns false. | |
76 bool GetNextInstructionExpiry(base::TimeTicks* next_event); | |
77 | |
78 scoped_ptr<AudioManager> audio_manager_; | |
79 | |
80 // Audible and inaudible lists. | |
81 // AUDIBLE = 0, INAUDIBLE = 1 (see copresence_constants.h). | |
82 AudioDirectiveList transmits_list_[2]; | |
83 AudioDirectiveList receives_list_[2]; | |
84 | |
85 scoped_ptr<base::Timer> audio_event_timer_; | |
86 | |
87 scoped_refptr<TickClockRefCounted> clock_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); | |
90 }; | 42 }; |
91 | 43 |
92 } // namespace copresence | 44 } // namespace copresence |
93 | 45 |
94 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ | 46 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ |
OLD | NEW |