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_DIRECTIVE_HANDLER_ |
| 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_DIRECTIVE_HANDLER_ |
| 7 |
| 8 #include <vector> |
| 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 "base/timer/timer.h" |
| 16 #include "components/copresence/handlers/audio/audio_directive_list.h" |
| 17 #include "components/copresence/mediums/audio/audio_recorder.h" |
| 18 #include "components/copresence/proto/data.pb.h" |
| 19 |
| 20 namespace media { |
| 21 class AudioBusRefCounted; |
| 22 } |
| 23 |
| 24 namespace copresence { |
| 25 |
| 26 class AudioPlayer; |
| 27 class AudioRecorder; |
| 28 |
| 29 class AudioDirectiveHandler { |
| 30 public: |
| 31 AudioDirectiveHandler( |
| 32 const AudioRecorder::DecodeSamplesCallback& decode_cb, |
| 33 const AudioDirectiveList::EncodeTokenCallback& encode_cb); |
| 34 virtual ~AudioDirectiveHandler(); |
| 35 |
| 36 // Adds in instruction to our handler. The instruction will execute and be |
| 37 // removed after the ttl expires. |
| 38 void AddInstruction(const copresence::TokenInstruction& instruction, |
| 39 base::TimeDelta ttl_ms); |
| 40 |
| 41 protected: |
| 42 // Use this constructor ONLY for testing. |
| 43 explicit AudioDirectiveHandler( |
| 44 const AudioDirectiveList::EncodeTokenCallback& encode_cb); |
| 45 |
| 46 // Protected and virtual since we want to be able to mock these out. |
| 47 virtual void PlayAudio( |
| 48 const scoped_refptr<media::AudioBusRefCounted>& samples, |
| 49 base::TimeDelta duration); |
| 50 virtual void RecordAudio(base::TimeDelta duration); |
| 51 |
| 52 private: |
| 53 void StopPlayback(); |
| 54 void StopRecording(); |
| 55 |
| 56 // Execute the next active transmit instruction. |
| 57 void ExecuteNextTransmit(); |
| 58 // Execute the next active receive instruction. |
| 59 void ExecuteNextReceive(); |
| 60 |
| 61 AudioDirectiveList directive_list_; |
| 62 |
| 63 AudioPlayer* player_; |
| 64 AudioRecorder* recorder_; |
| 65 |
| 66 base::OneShotTimer<AudioDirectiveHandler> stop_playback_timer_; |
| 67 base::OneShotTimer<AudioDirectiveHandler> stop_recording_timer_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); |
| 70 }; |
| 71 |
| 72 } // namespace copresence |
| 73 |
| 74 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_DIRECTIVE_HANDLER_ |
OLD | NEW |