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/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 11 namespace base { 12 class SingleThreadTaskRunner; 13 } // namespace base 14 15 namespace remoting { 16 17 namespace protocol { 18 class AudioStub; 19 } // namespace protocol 20 21 class AudioCapturer; 22 class AudioEncoder; 23 class AudioPacket; 24 25 // AudioScheduler is responsible for fetching audio data from the AudioCapturer 26 // 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 28 // AudioStub on the network thread. 29 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { 30 public: 31 // Audio capture and encoding tasks are dispatched via the 32 // |audio_task_runner|. |audio_stub| tasks are dispatched via the 33 // |network_task_runner|. The caller must ensure that the |audio_capturer| and 34 // |audio_stub| exist until the scheduler is stopped using Stop() method. 35 AudioScheduler( 36 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 37 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 38 scoped_ptr<AudioCapturer> audio_capturer, 39 scoped_ptr<AudioEncoder> audio_encoder, 40 protocol::AudioStub* audio_stub); 41 42 // Starts the recording session. 43 void Start(); 44 45 // Stops the recording session. 46 void Stop(); 47 48 // 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 50 // encoded and sent on the wire. 51 void Pause(bool pause); 52 53 private: 54 friend class base::RefCountedThreadSafe<AudioScheduler>; 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 66 // Called on the network thread to send a captured packet to the audio stub. 67 void SendAudioPacket(scoped_ptr<AudioPacket> packet); 68 69 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_; 77 78 bool network_stopped_; 79 80 bool enabled_; 81 82 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); 83 }; 84 85 } // namespace remoting 86 87 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ 88