blob: 9ccc991e2590fd545506b59d2b07ba7730548f90 [file] [log] [blame]
[email protected]677bb0a2012-07-13 19:38:071// 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]677bb0a2012-07-13 19:38:0711
12namespace base {
13class SingleThreadTaskRunner;
14} // namespace base
15
16namespace remoting {
17
18namespace protocol {
19class AudioStub;
20} // namespace protocol
21
22class AudioCapturer;
[email protected]abad5052012-08-01 17:41:4323class AudioEncoder;
[email protected]677bb0a2012-07-13 19:38:0724class AudioPacket;
25
[email protected]efb972b2012-09-01 03:55:4726// 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]677bb0a2012-07-13 19:38:0730class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
31 public:
[email protected]efb972b2012-09-01 03:55:4732 // 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]677bb0a2012-07-13 19:38:0736 AudioScheduler(
[email protected]efb972b2012-09-01 03:55:4737 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
[email protected]677bb0a2012-07-13 19:38:0738 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
39 AudioCapturer* audio_capturer,
[email protected]abad5052012-08-01 17:41:4340 scoped_ptr<AudioEncoder> audio_encoder,
[email protected]677bb0a2012-07-13 19:38:0741 protocol::AudioStub* audio_stub);
42
43 // Stop the recording session.
44 void Stop(const base::Closure& done_task);
45
[email protected]2d26b312012-10-19 03:39:0546 // 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]677bb0a2012-07-13 19:38:0751 private:
52 friend class base::RefCountedThreadSafe<AudioScheduler>;
53 virtual ~AudioScheduler();
54
[email protected]0c850012012-10-23 01:06:3155 // Called on the audio thread to start capturing.
56 void StartOnAudioThread();
[email protected]677bb0a2012-07-13 19:38:0757
[email protected]0c850012012-10-23 01:06:3158 // Called on the audio thread to stop capturing.
59 void StopOnAudioThread(const base::Closure& done_task);
[email protected]677bb0a2012-07-13 19:38:0760
[email protected]0c850012012-10-23 01:06:3161 // Called on the audio thread when a new audio packet is available.
62 void EncodeAudioPacket(scoped_ptr<AudioPacket> packet);
[email protected]677bb0a2012-07-13 19:38:0763
[email protected]0c850012012-10-23 01:06:3164 // Called on the network thread to send a captured packet to the audio stub.
65 void SendAudioPacket(scoped_ptr<AudioPacket> packet);
[email protected]677bb0a2012-07-13 19:38:0766
[email protected]efb972b2012-09-01 03:55:4767 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
[email protected]677bb0a2012-07-13 19:38:0768 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
69
70 AudioCapturer* audio_capturer_;
71
[email protected]abad5052012-08-01 17:41:4372 scoped_ptr<AudioEncoder> audio_encoder_;
73
[email protected]677bb0a2012-07-13 19:38:0774 protocol::AudioStub* audio_stub_;
75
76 bool network_stopped_;
77
[email protected]2d26b312012-10-19 03:39:0578 bool enabled_;
79
[email protected]677bb0a2012-07-13 19:38:0780 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
81};
82
83} // namespace remoting
84
85#endif // REMOTING_HOST_AUDIO_SCHEDULER_H_