[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" |
| 11 | #include "base/time.h" |
| 12 | |
| 13 | namespace base { |
| 14 | class SingleThreadTaskRunner; |
| 15 | } // namespace base |
| 16 | |
| 17 | namespace remoting { |
| 18 | |
| 19 | namespace protocol { |
| 20 | class AudioStub; |
| 21 | } // namespace protocol |
| 22 | |
| 23 | class AudioCapturer; |
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 24 | class AudioEncoder; |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 25 | class AudioPacket; |
| 26 | |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame^] | 27 | // AudioScheduler is responsible for fetching audio data from the AudioCapturer |
| 28 | // and encoding it before passing it to the AudioStub for delivery to the |
| 29 | // client. Audio is captured and encoded on the audio thread and then passed to |
| 30 | // AudioStub on the network thread. |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 31 | class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { |
| 32 | public: |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame^] | 33 | // Audio capture and encoding tasks are dispatched via the |
| 34 | // |audio_task_runner|. |audio_stub| tasks are dispatched via the |
| 35 | // |network_task_runner|. The caller must ensure that the |audio_capturer| and |
| 36 | // |audio_stub| exist until the scheduler is stopped using Stop() method. |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 37 | AudioScheduler( |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame^] | 38 | scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 39 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 40 | AudioCapturer* audio_capturer, |
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 41 | scoped_ptr<AudioEncoder> audio_encoder, |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 42 | protocol::AudioStub* audio_stub); |
| 43 | |
| 44 | // Stop the recording session. |
| 45 | void Stop(const base::Closure& done_task); |
| 46 | |
| 47 | // Called when a client disconnects. |
| 48 | void OnClientDisconnected(); |
| 49 | |
| 50 | private: |
| 51 | friend class base::RefCountedThreadSafe<AudioScheduler>; |
| 52 | virtual ~AudioScheduler(); |
| 53 | |
| 54 | void NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet); |
| 55 | |
| 56 | void DoStart(); |
| 57 | |
| 58 | // Sends an audio packet to the client. |
| 59 | void DoSendAudioPacket(scoped_ptr<AudioPacket> packet); |
| 60 | |
| 61 | // Signal network thread to cease activities. |
| 62 | void DoStopOnNetworkThread(const base::Closure& done_task); |
| 63 | |
| 64 | // Called when an AudioPacket has been delivered to the client. |
| 65 | void OnCaptureCallbackNotified(); |
| 66 | |
[email protected] | efb972b | 2012-09-01 03:55:47 | [diff] [blame^] | 67 | scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 68 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 69 | |
| 70 | AudioCapturer* audio_capturer_; |
| 71 | |
[email protected] | abad505 | 2012-08-01 17:41:43 | [diff] [blame] | 72 | scoped_ptr<AudioEncoder> audio_encoder_; |
| 73 | |
[email protected] | 677bb0a | 2012-07-13 19:38:07 | [diff] [blame] | 74 | protocol::AudioStub* audio_stub_; |
| 75 | |
| 76 | bool network_stopped_; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(AudioScheduler); |
| 79 | }; |
| 80 | |
| 81 | } // namespace remoting |
| 82 | |
| 83 | #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ |