Chromium Code Reviews| Index: components/copresence/handlers/audio/audio_directive_handler.h |
| diff --git a/components/copresence/handlers/audio/audio_directive_handler.h b/components/copresence/handlers/audio/audio_directive_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..359fa8d1b783791fdf267af34a40c249d90f38b3 |
| --- /dev/null |
| +++ b/components/copresence/handlers/audio/audio_directive_handler.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_ |
| +#define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_ |
| + |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "components/copresence/handlers/audio/audio_directive_list.h" |
| +#include "components/copresence/mediums/audio/audio_recorder.h" |
| +#include "components/copresence/proto/data.pb.h" |
| + |
| +namespace media { |
| +class AudioBusRefCounted; |
| +} |
| + |
| +namespace copresence { |
| + |
| +class AudioPlayer; |
| + |
| +// The AudioDirectiveHandler handles audio transmit and receive instructions. |
| +class AudioDirectiveHandler { |
| + public: |
| + AudioDirectiveHandler( |
| + const AudioRecorder::DecodeSamplesCallback& decode_cb, |
| + const AudioDirectiveList::EncodeTokenCallback& encode_cb); |
| + virtual ~AudioDirectiveHandler(); |
| + |
| + // Do not use this class before calling this. |
| + void Initialize(); |
| + |
| + // Adds in instruction to our handler. The instruction will execute and be |
|
Daniel Erat
2014/08/05 16:38:51
nit: s/in/an/
rkc
2014/08/05 18:00:35
Done.
|
| + // removed after the ttl expires. |
| + void AddInstruction(const copresence::TokenInstruction& instruction, |
| + base::TimeDelta ttl_ms); |
| + |
| + protected: |
| + // Protected and virtual since we want to be able to mock these out. |
| + virtual void PlayAudio( |
| + const scoped_refptr<media::AudioBusRefCounted>& samples, |
| + base::TimeDelta duration); |
| + virtual void RecordAudio(base::TimeDelta duration); |
| + |
| + private: |
| + void StopPlayback(); |
| + void StopRecording(); |
| + |
| + // Execute the next active transmit instruction. |
| + void ExecuteNextTransmit(); |
| + // Execute the next active receive instruction. |
| + void ExecuteNextReceive(); |
| + |
| + AudioDirectiveList directive_list_; |
| + |
| + AudioPlayer* player_; |
|
Daniel Erat
2014/08/05 16:38:51
nit: add a comment describing ownership of these b
rkc
2014/08/05 18:00:35
Done.
|
| + AudioRecorder* recorder_; |
| + |
| + AudioRecorder::DecodeSamplesCallback decode_cb_; |
| + |
| + base::OneShotTimer<AudioDirectiveHandler> stop_playback_timer_; |
| + base::OneShotTimer<AudioDirectiveHandler> stop_recording_timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); |
| +}; |
| + |
| +} // namespace copresence |
| + |
| +#endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_ |