| 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 14 matching lines...) Expand all Loading... |
| 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 return audio_manager_->get_token(type); | 58 return audio_manager_->get_token(type); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void set_audio_manager_for_testing(scoped_ptr<AudioManager> manager) { | 61 void set_audio_manager_for_testing(scoped_ptr<AudioManager> manager) { |
| 61 audio_manager_ = manager.Pass(); | 62 audio_manager_ = manager.Pass(); |
| 62 } | 63 } |
| 63 | 64 |
| 65 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock); |
| 66 void set_timer_for_testing(scoped_ptr<base::Timer> timer); |
| 67 |
| 64 private: | 68 private: |
| 65 // Processes the next active instruction, updating our audio manager state | 69 // Processes the next active instruction, updating our audio manager state |
| 66 // accordingly. | 70 // accordingly. |
| 67 void ProcessNextInstruction(); | 71 void ProcessNextInstruction(); |
| 68 | 72 |
| 69 bool GetNextInstructionExpiry(base::TimeTicks* next_event); | 73 bool GetNextInstructionExpiry(base::TimeTicks* next_event); |
| 70 | 74 |
| 71 scoped_ptr<AudioManager> audio_manager_; | 75 scoped_ptr<AudioManager> audio_manager_; |
| 72 | 76 |
| 73 // Audible and inaudible lists. | 77 // Audible and inaudible lists. |
| 74 // AUDIBLE = 0, INAUDIBLE = 1 (see copresence_constants.h). | 78 // AUDIBLE = 0, INAUDIBLE = 1 (see copresence_constants.h). |
| 75 AudioDirectiveList transmits_list_[2]; | 79 AudioDirectiveList transmits_list_[2]; |
| 76 AudioDirectiveList receives_list_[2]; | 80 AudioDirectiveList receives_list_[2]; |
| 77 | 81 |
| 78 scoped_ptr<base::Timer> audio_event_timer_; | 82 scoped_ptr<base::Timer> audio_event_timer_; |
| 79 | 83 |
| 80 scoped_ptr<base::TickClock> clock_; | 84 scoped_refptr<TickClockRefCounted> clock_; |
| 81 | 85 |
| 82 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); | 86 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); |
| 83 }; | 87 }; |
| 84 | 88 |
| 85 } // namespace copresence | 89 } // namespace copresence |
| 86 | 90 |
| 87 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ | 91 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ |
| OLD | NEW |