[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef REMOTING_HOST_AUDIO_SCHEDULER_H_ | ||||
6 | #define REMOTING_HOST_AUDIO_SCHEDULER_H_ | ||||
7 | |||||
8 | #include "base/callback_forward.h" | ||||
9 | #include "base/memory/ref_counted.h" | ||||
10 | #include "base/memory/scoped_ptr.h" | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 11 | |
12 | namespace base { | ||||
13 | class SingleThreadTaskRunner; | ||||
14 | } // namespace base | ||||
15 | |||||
16 | namespace remoting { | ||||
17 | |||||
18 | namespace protocol { | ||||
19 | class AudioStub; | ||||
20 | } // namespace protocol | ||||
21 | |||||
22 | class AudioCapturer; | ||||
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 23 | class AudioEncoder; |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 24 | class AudioPacket; |
25 | |||||
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame] | 26 | // AudioScheduler is responsible for fetching audio data from the AudioCapturer |
27 | // and encoding it before passing it to the AudioStub for delivery to the | ||||
28 | // client. Audio is captured and encoded on the audio thread and then passed to | ||||
29 | // AudioStub on the network thread. | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 30 | class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { |
31 | public: | ||||
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame] | 32 | // Audio capture and encoding tasks are dispatched via the |
33 | // |audio_task_runner|. |audio_stub| tasks are dispatched via the | ||||
34 | // |network_task_runner|. The caller must ensure that the |audio_capturer| and | ||||
35 | // |audio_stub| exist until the scheduler is stopped using Stop() method. | ||||
[email protected] | c18ad89 | 2012-12-08 03:39:24 | [diff] [blame^] | 36 | static scoped_refptr<AudioScheduler> Create( |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame] | 37 | scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 38 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
39 | AudioCapturer* audio_capturer, | ||||
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 40 | scoped_ptr<AudioEncoder> audio_encoder, |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 41 | protocol::AudioStub* audio_stub); |
42 | |||||
43 | // Stop the recording session. | ||||
44 | void Stop(const base::Closure& done_task); | ||||
45 | |||||
[email protected] | 2d26b31 | 2012-10-19 03:39:05 | [diff] [blame] | 46 | // Enable or disable audio on a running session. |
47 | // This leaves the audio capturer running, and only affects whether or not the | ||||
48 | // captured audio is encoded and sent on the wire. | ||||
49 | void SetEnabled(bool enabled); | ||||
50 | |||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 51 | private: |
52 | friend class base::RefCountedThreadSafe<AudioScheduler>; | ||||
[email protected] | c18ad89 | 2012-12-08 03:39:24 | [diff] [blame^] | 53 | |
54 | AudioScheduler( | ||||
55 | scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | ||||
56 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | ||||
57 | AudioCapturer* audio_capturer, | ||||
58 | scoped_ptr<AudioEncoder> audio_encoder, | ||||
59 | protocol::AudioStub* audio_stub); | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 60 | virtual ~AudioScheduler(); |
61 | |||||
[email protected] | 0c85001 | 2012-10-23 01:06:31 | [diff] [blame] | 62 | // Called on the audio thread to start capturing. |
63 | void StartOnAudioThread(); | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 64 | |
[email protected] | 0c85001 | 2012-10-23 01:06:31 | [diff] [blame] | 65 | // Called on the audio thread to stop capturing. |
66 | void StopOnAudioThread(const base::Closure& done_task); | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 67 | |
[email protected] | 0c85001 | 2012-10-23 01:06:31 | [diff] [blame] | 68 | // Called on the audio thread when a new audio packet is available. |
69 | void EncodeAudioPacket(scoped_ptr<AudioPacket> packet); | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 70 | |
[email protected] | 0c85001 | 2012-10-23 01:06:31 | [diff] [blame] | 71 | // Called on the network thread to send a captured packet to the audio stub. |
72 | void SendAudioPacket(scoped_ptr<AudioPacket> packet); | ||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 73 | |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame] | 74 | scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 75 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
76 | |||||
77 | AudioCapturer* audio_capturer_; | ||||
78 | |||||
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 79 | scoped_ptr<AudioEncoder> audio_encoder_; |
80 | |||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 81 | protocol::AudioStub* audio_stub_; |
82 | |||||
83 | bool network_stopped_; | ||||
84 | |||||
[email protected] | 2d26b31 | 2012-10-19 03:39:05 | [diff] [blame] | 85 | bool enabled_; |
86 | |||||
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(AudioScheduler); |
88 | }; | ||||
89 | |||||
90 | } // namespace remoting | ||||
91 | |||||
92 | #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ |