| 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_IMPL_H_ | 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ |
| 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ | 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "components/copresence/handlers/audio/audio_directive_handler.h" | 14 #include "components/copresence/handlers/audio/audio_directive_handler.h" |
| 15 #include "components/copresence/public/copresence_constants.h" | |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 class TimeTicks; | 17 class TimeTicks; |
| 19 class Timer; | 18 class Timer; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace media { | 21 namespace media { |
| 23 class AudioBusRefCounted; | 22 class AudioBusRefCounted; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace copresence { | 25 namespace copresence { |
| 27 | 26 |
| 28 class AudioDirectiveList; | 27 class AudioDirectiveList; |
| 29 class TickClockRefCounted; | 28 class TickClockRefCounted; |
| 30 | 29 |
| 31 // The AudioDirectiveHandler handles audio transmit and receive instructions. | 30 // The AudioDirectiveHandler handles audio transmit and receive instructions. |
| 32 // TODO(rkc): Currently since WhispernetClient can only have one token encoded | 31 // TODO(rkc): Currently since WhispernetClient can only have one token encoded |
| 33 // callback at a time, we need to have both the audible and inaudible in this | 32 // 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 | 33 // 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 | 34 // 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 | 35 // multiple callbacks for encoded tokens being sent back and have two versions |
| 37 // of this class. | 36 // of this class. |
| 38 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler { | 37 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler { |
| 39 public: | 38 public: |
| 40 explicit AudioDirectiveHandlerImpl( | 39 AudioDirectiveHandlerImpl(); |
| 41 const DirectivesCallback& update_directives_callback); | 40 AudioDirectiveHandlerImpl(scoped_ptr<AudioManager> audio_manager, |
| 42 AudioDirectiveHandlerImpl( | 41 scoped_ptr<base::Timer> timer, |
| 43 const DirectivesCallback& update_directives_callback, | 42 const scoped_refptr<TickClockRefCounted>& clock); |
| 44 scoped_ptr<AudioManager> audio_manager, | |
| 45 scoped_ptr<base::Timer> timer, | |
| 46 const scoped_refptr<TickClockRefCounted>& clock); | |
| 47 | 43 |
| 48 ~AudioDirectiveHandlerImpl() override; | 44 ~AudioDirectiveHandlerImpl(); |
| 49 | 45 |
| 50 // AudioDirectiveHandler overrides: | 46 // AudioDirectiveHandler overrides: |
| 51 void Initialize(WhispernetClient* whispernet_client, | 47 void Initialize(WhispernetClient* whispernet_client, |
| 52 const TokensCallback& tokens_cb) override; | 48 const TokensCallback& tokens_cb) override; |
| 53 void AddInstruction(const Directive& directive, | 49 void AddInstruction(const copresence::TokenInstruction& instruction, |
| 54 const std::string& op_id) override; | 50 const std::string& op_id, |
| 51 base::TimeDelta ttl) override; |
| 55 void RemoveInstructions(const std::string& op_id) override; | 52 void RemoveInstructions(const std::string& op_id) override; |
| 56 const std::string PlayingToken(AudioType type) const override; | 53 const std::string PlayingToken(AudioType type) const override; |
| 57 bool IsPlayingTokenHeard(AudioType type) const override; | 54 bool IsPlayingTokenHeard(AudioType type) const override; |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 // Processes the next active instruction, | 57 // Processes the next active instruction, |
| 61 // updating our audio manager state accordingly. | 58 // updating our audio manager state accordingly. |
| 62 void ProcessNextInstruction(); | 59 void ProcessNextInstruction(); |
| 63 | 60 |
| 64 // Returns the time that an instruction expires at. This will always return | 61 // Returns the time that an instruction expires at. This will always return |
| 65 // the earliest expiry time among all the active receive and transmit | 62 // the earliest expiry time among all the active receive and transmit |
| 66 // instructions. If we don't have any active instructions, returns false. | 63 // instructions. If we don't have any active instructions, returns false. |
| 67 bool GetNextInstructionExpiry(base::TimeTicks* next_event); | 64 bool GetNextInstructionExpiry(base::TimeTicks* next_event); |
| 68 | 65 |
| 69 DirectivesCallback update_directives_callback_; | |
| 70 scoped_ptr<AudioManager> audio_manager_; | 66 scoped_ptr<AudioManager> audio_manager_; |
| 67 |
| 71 scoped_ptr<base::Timer> audio_event_timer_; | 68 scoped_ptr<base::Timer> audio_event_timer_; |
| 72 scoped_refptr<TickClockRefCounted> clock_; | 69 scoped_refptr<TickClockRefCounted> clock_; |
| 73 | 70 |
| 74 // Lists of transmits and receives, for both audible and inaudible tokens. | 71 // Lists of transmits and receives, for both audible and inaudible tokens. |
| 75 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h). | 72 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h). |
| 76 ScopedVector<AudioDirectiveList> transmits_lists_; | 73 ScopedVector<AudioDirectiveList> transmits_lists_; |
| 77 ScopedVector<AudioDirectiveList> receives_lists_; | 74 ScopedVector<AudioDirectiveList> receives_lists_; |
| 78 | 75 |
| 76 |
| 79 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl); | 77 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl); |
| 80 }; | 78 }; |
| 81 | 79 |
| 82 } // namespace copresence | 80 } // namespace copresence |
| 83 | 81 |
| 84 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ | 82 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_ |
| OLD | NEW |