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