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 // Use this constructor ONLY for testing. |
| 35 explicit AudioDirectiveHandler( |
| 36 const AudioDirectiveList::EncodeTokenCallback& encode_cb); |
| 37 virtual ~AudioDirectiveHandler(); |
| 38 |
| 39 void AddInstruction(const copresence::TokenInstruction& instruction, |
| 40 base::TimeDelta ttl_ms); |
| 41 |
| 42 protected: |
| 43 virtual void PlayAudio( |
| 44 const scoped_refptr<media::AudioBusRefCounted>& samples, |
| 45 base::TimeDelta duration); |
| 46 virtual void RecordAudio(base::TimeDelta duration); |
| 47 |
| 48 virtual void StopPlayback(); |
| 49 virtual void StopRecording(); |
| 50 |
| 51 // For testing, we want to override base::Time::Now(). |
| 52 base::Time Now(); |
| 53 |
| 54 private: |
| 55 void ExecuteNextTransmit(); |
| 56 void ExecuteNextReceive(); |
| 57 |
| 58 AudioDirectiveList directive_list_; |
| 59 |
| 60 AudioPlayer* player_; |
| 61 AudioRecorder* recorder_; |
| 62 |
| 63 base::OneShotTimer<AudioDirectiveHandler> stop_playback_timer_; |
| 64 base::OneShotTimer<AudioDirectiveHandler> stop_recording_timer_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); |
| 67 }; |
| 68 |
| 69 } // namespace copresence |
| 70 |
| 71 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_DIRECTIVE_HANDLER_ |
OLD | NEW |