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 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.
| |
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 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.
| |
62 AudioRecorder* recorder_; | |
63 | |
64 AudioRecorder::DecodeSamplesCallback decode_cb_; | |
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_AUDIO_DIRECTIVE_HANDLER_ | |
OLD | NEW |