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