blob: 43fb3976a8af9c750f32361b41dbf17125c320a1 [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]c18ad892012-12-08 03:39:2436 static scoped_refptr<AudioScheduler> Create(
[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>;
[email protected]c18ad892012-12-08 03:39:2453
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]677bb0a2012-07-13 19:38:0760 virtual ~AudioScheduler();
61
[email protected]0c850012012-10-23 01:06:3162 // Called on the audio thread to start capturing.
63 void StartOnAudioThread();
[email protected]677bb0a2012-07-13 19:38:0764
[email protected]0c850012012-10-23 01:06:3165 // Called on the audio thread to stop capturing.
66 void StopOnAudioThread(const base::Closure& done_task);
[email protected]677bb0a2012-07-13 19:38:0767
[email protected]0c850012012-10-23 01:06:3168 // Called on the audio thread when a new audio packet is available.
69 void EncodeAudioPacket(scoped_ptr<AudioPacket> packet);
[email protected]677bb0a2012-07-13 19:38:0770
[email protected]0c850012012-10-23 01:06:3171 // Called on the network thread to send a captured packet to the audio stub.
72 void SendAudioPacket(scoped_ptr<AudioPacket> packet);
[email protected]677bb0a2012-07-13 19:38:0773
[email protected]efb972b2012-09-01 03:55:4774 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
[email protected]677bb0a2012-07-13 19:38:0775 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
76
77 AudioCapturer* audio_capturer_;
78
[email protected]abad5052012-08-01 17:41:4379 scoped_ptr<AudioEncoder> audio_encoder_;
80
[email protected]677bb0a2012-07-13 19:38:0781 protocol::AudioStub* audio_stub_;
82
83 bool network_stopped_;
84
[email protected]2d26b312012-10-19 03:39:0585 bool enabled_;
86
[email protected]677bb0a2012-07-13 19:38:0787 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
88};
89
90} // namespace remoting
91
92#endif // REMOTING_HOST_AUDIO_SCHEDULER_H_