OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SCHEDULER_H_ |
6 #define REMOTING_HOST_AUDIO_SCHEDULER_H_ | 6 #define REMOTING_HOST_AUDIO_SCHEDULER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class SingleThreadTaskRunner; | 14 class SingleThreadTaskRunner; |
15 } // namespace base | 15 } // namespace base |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 | 18 |
19 namespace protocol { | 19 namespace protocol { |
20 class AudioStub; | 20 class AudioStub; |
21 } // namespace protocol | 21 } // namespace protocol |
22 | 22 |
| 23 class AudioCaptureData; |
23 class AudioCapturer; | 24 class AudioCapturer; |
| 25 class AudioEncoder; |
24 class AudioPacket; | 26 class AudioPacket; |
25 | 27 |
26 // A class for controlling AudioCapturer and forwarding audio packets to the | 28 // A class for controlling AudioCapturer and forwarding audio packets to the |
27 // client. | 29 // client. |
28 // | 30 // |
29 // THREADING | 31 // THREADING |
30 // | 32 // |
31 // This class works on two threads: the capture and network threads. | 33 // This class works on two threads: the capture and network threads. |
32 // Any encoding that is done on the audio samples will be done on the capture | 34 // Any encoding that is done on the audio samples will be done on the capture |
33 // thread. | 35 // thread. |
34 // | 36 // |
35 // AudioScheduler is responsible for: | 37 // AudioScheduler is responsible for: |
36 // 1. managing the AudioCapturer. | 38 // 1. managing the AudioCapturer. |
37 // 2. sending packets of audio samples over the network to the client. | 39 // 2. sending packets of audio samples over the network to the client. |
38 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { | 40 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { |
39 public: | 41 public: |
40 // Construct an AudioScheduler. TaskRunners are used for message passing | 42 // Construct an AudioScheduler. TaskRunners are used for message passing |
41 // among the capturer and network threads. The caller is responsible for | 43 // among the capturer and network threads. The caller is responsible for |
42 // ensuring that the |audio_capturer| and |audio_stub| outlive the | 44 // ensuring that the |audio_capturer| and |audio_stub| outlive the |
43 // AudioScheduler. | 45 // AudioScheduler. |
44 AudioScheduler( | 46 AudioScheduler( |
45 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 47 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
46 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 48 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
47 AudioCapturer* audio_capturer, | 49 AudioCapturer* audio_capturer, |
| 50 scoped_ptr<AudioEncoder> audio_encoder, |
48 protocol::AudioStub* audio_stub); | 51 protocol::AudioStub* audio_stub); |
49 | 52 |
50 // Stop the recording session. | 53 // Stop the recording session. |
51 void Stop(const base::Closure& done_task); | 54 void Stop(const base::Closure& done_task); |
52 | 55 |
53 // Called when a client disconnects. | 56 // Called when a client disconnects. |
54 void OnClientDisconnected(); | 57 void OnClientDisconnected(); |
55 | 58 |
56 private: | 59 private: |
57 friend class base::RefCountedThreadSafe<AudioScheduler>; | 60 friend class base::RefCountedThreadSafe<AudioScheduler>; |
58 virtual ~AudioScheduler(); | 61 virtual ~AudioScheduler(); |
59 | 62 |
60 void NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet); | 63 void NotifyAudioSamplesCaptured(scoped_ptr<AudioCaptureData> capture_data); |
| 64 void NotifyAudioPacketEncoded(scoped_ptr<AudioPacket> packet); |
61 | 65 |
62 void DoStart(); | 66 void DoStart(); |
63 | 67 |
64 // Sends an audio packet to the client. | 68 // Sends an audio packet to the client. |
65 void DoSendAudioPacket(scoped_ptr<AudioPacket> packet); | 69 void DoSendAudioPacket(scoped_ptr<AudioPacket> packet); |
66 | 70 |
67 // Signal network thread to cease activities. | 71 // Signal network thread to cease activities. |
68 void DoStopOnNetworkThread(const base::Closure& done_task); | 72 void DoStopOnNetworkThread(const base::Closure& done_task); |
69 | 73 |
70 // Called when an AudioPacket has been delivered to the client. | 74 // Called when an AudioPacket has been delivered to the client. |
71 void OnCaptureCallbackNotified(); | 75 void OnCaptureCallbackNotified(); |
72 | 76 |
73 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | 77 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
74 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
75 | 79 |
76 AudioCapturer* audio_capturer_; | 80 AudioCapturer* audio_capturer_; |
77 | 81 |
| 82 scoped_ptr<AudioEncoder> audio_encoder_; |
| 83 |
78 protocol::AudioStub* audio_stub_; | 84 protocol::AudioStub* audio_stub_; |
79 | 85 |
80 bool network_stopped_; | 86 bool network_stopped_; |
81 | 87 |
82 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); | 88 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); |
83 }; | 89 }; |
84 | 90 |
85 } // namespace remoting | 91 } // namespace remoting |
86 | 92 |
87 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ | 93 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ |
OLD | NEW |