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_ |
| 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_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/time/time.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "components/copresence/handlers/audio/audio_directive_list.h" |
| 16 #include "components/copresence/mediums/audio/audio_recorder.h" |
| 17 #include "components/copresence/proto/data.pb.h" |
| 18 |
| 19 namespace media { |
| 20 class AudioBusRefCounted; |
| 21 } |
| 22 |
| 23 namespace copresence { |
| 24 |
| 25 class AudioPlayer; |
| 26 |
| 27 // The AudioDirectiveHandler handles audio transmit and receive instructions. |
| 28 class AudioDirectiveHandler { |
| 29 public: |
| 30 AudioDirectiveHandler( |
| 31 const AudioRecorder::DecodeSamplesCallback& decode_cb, |
| 32 const AudioDirectiveList::EncodeTokenCallback& encode_cb); |
| 33 virtual ~AudioDirectiveHandler(); |
| 34 |
| 35 // Do not use this class before calling this. |
| 36 void Initialize(); |
| 37 |
| 38 // Adds an instruction to our handler. The instruction will execute and be |
| 39 // removed after the ttl expires. |
| 40 void AddInstruction(const copresence::TokenInstruction& instruction, |
| 41 base::TimeDelta ttl_ms); |
| 42 |
| 43 protected: |
| 44 // Protected and virtual since we want to be able to mock these out. |
| 45 virtual void PlayAudio( |
| 46 const scoped_refptr<media::AudioBusRefCounted>& samples, |
| 47 base::TimeDelta duration); |
| 48 virtual void RecordAudio(base::TimeDelta duration); |
| 49 |
| 50 private: |
| 51 void StopPlayback(); |
| 52 void StopRecording(); |
| 53 |
| 54 // Execute the next active transmit instruction. |
| 55 void ExecuteNextTransmit(); |
| 56 // Execute the next active receive instruction. |
| 57 void ExecuteNextReceive(); |
| 58 |
| 59 AudioDirectiveList directive_list_; |
| 60 |
| 61 // The next two pointers are self-deleting. When we call Finalize on them, |
| 62 // they clean themselves up on the Audio thread. |
| 63 AudioPlayer* player_; |
| 64 AudioRecorder* recorder_; |
| 65 |
| 66 AudioRecorder::DecodeSamplesCallback decode_cb_; |
| 67 |
| 68 base::OneShotTimer<AudioDirectiveHandler> stop_playback_timer_; |
| 69 base::OneShotTimer<AudioDirectiveHandler> stop_recording_timer_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); |
| 72 }; |
| 73 |
| 74 } // namespace copresence |
| 75 |
| 76 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_ |
OLD | NEW |