OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_HOST_AUDIO_SCHEDULER_H_ | 5 #ifndef REMOTING_HOST_AUDIO_PUMP_H_ |
6 #define REMOTING_HOST_AUDIO_SCHEDULER_H_ | 6 #define REMOTING_HOST_AUDIO_PUMP_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/non_thread_safe.h" |
10 | 12 |
11 namespace base { | 13 namespace base { |
12 class SingleThreadTaskRunner; | 14 class SingleThreadTaskRunner; |
13 } // namespace base | 15 } // namespace base |
14 | 16 |
15 namespace remoting { | 17 namespace remoting { |
16 | 18 |
17 namespace protocol { | 19 namespace protocol { |
18 class AudioStub; | 20 class AudioStub; |
19 } // namespace protocol | 21 } // namespace protocol |
20 | 22 |
21 class AudioCapturer; | 23 class AudioCapturer; |
22 class AudioEncoder; | 24 class AudioEncoder; |
23 class AudioPacket; | 25 class AudioPacket; |
24 | 26 |
25 // AudioScheduler is responsible for fetching audio data from the AudioCapturer | 27 // AudioPump is responsible for fetching audio data from the AudioCapturer |
26 // and encoding it before passing it to the AudioStub for delivery to the | 28 // and encoding it before passing it to the AudioStub for delivery to the |
27 // client. Audio is captured and encoded on the audio thread and then passed to | 29 // client. Audio is captured and encoded on the audio thread and then passed to |
28 // AudioStub on the network thread. | 30 // AudioStub on the network thread. |
29 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { | 31 class AudioPump : public base::NonThreadSafe { |
30 public: | 32 public: |
31 // Audio capture and encoding tasks are dispatched via the | 33 // The caller must ensure that the |audio_stub| is not destroyed until the |
32 // |audio_task_runner|. |audio_stub| tasks are dispatched via the | 34 // pump is destroyed. |
33 // |network_task_runner|. The caller must ensure that the |audio_capturer| and | 35 AudioPump( |
34 // |audio_stub| exist until the scheduler is stopped using Stop() method. | |
35 AudioScheduler( | |
36 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 36 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
37 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 37 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
38 scoped_ptr<AudioCapturer> audio_capturer, | 38 scoped_ptr<AudioCapturer> audio_capturer, |
39 scoped_ptr<AudioEncoder> audio_encoder, | 39 scoped_ptr<AudioEncoder> audio_encoder, |
40 protocol::AudioStub* audio_stub); | 40 protocol::AudioStub* audio_stub); |
41 | 41 virtual ~AudioPump(); |
42 // Starts the recording session. | |
43 void Start(); | |
44 | |
45 // Stops the recording session. | |
46 void Stop(); | |
47 | 42 |
48 // Pauses or resumes audio on a running session. This leaves the audio | 43 // Pauses or resumes audio on a running session. This leaves the audio |
49 // capturer running, and only affects whether or not the captured audio is | 44 // capturer running, and only affects whether or not the captured audio is |
50 // encoded and sent on the wire. | 45 // encoded and sent on the wire. |
51 void Pause(bool pause); | 46 void Pause(bool pause); |
52 | 47 |
53 private: | 48 private: |
54 friend class base::RefCountedThreadSafe<AudioScheduler>; | 49 class Core; |
55 virtual ~AudioScheduler(); | |
56 | |
57 // Called on the audio thread to start capturing. | |
58 void StartOnAudioThread(); | |
59 | |
60 // Called on the audio thread to stop capturing. | |
61 void StopOnAudioThread(); | |
62 | |
63 // Called on the audio thread when a new audio packet is available. | |
64 void EncodeAudioPacket(scoped_ptr<AudioPacket> packet); | |
65 | 50 |
66 // Called on the network thread to send a captured packet to the audio stub. | 51 // Called on the network thread to send a captured packet to the audio stub. |
67 void SendAudioPacket(scoped_ptr<AudioPacket> packet); | 52 void SendAudioPacket(scoped_ptr<AudioPacket> packet); |
68 | 53 |
69 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; | 54 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
70 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | |
71 | |
72 scoped_ptr<AudioCapturer> audio_capturer_; | |
73 | |
74 scoped_ptr<AudioEncoder> audio_encoder_; | |
75 | |
76 protocol::AudioStub* audio_stub_; | 55 protocol::AudioStub* audio_stub_; |
77 | 56 |
78 bool enabled_; | 57 scoped_ptr<Core> core_; |
79 | 58 |
80 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); | 59 base::WeakPtrFactory<AudioPump> weak_factory_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(AudioPump); |
81 }; | 62 }; |
82 | 63 |
83 } // namespace remoting | 64 } // namespace remoting |
84 | 65 |
85 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ | 66 #endif // REMOTING_HOST_AUDIO_PUMP_H_ |
OLD | NEW |