blob: 89a5805e6e30f66c3d1432541fce85b7c29a16be [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"
11#include "base/time.h"
12
13namespace base {
14class SingleThreadTaskRunner;
15} // namespace base
16
17namespace remoting {
18
19namespace protocol {
20class AudioStub;
21} // namespace protocol
22
23class AudioCapturer;
[email protected]abad5052012-08-01 17:41:4324class AudioEncoder;
[email protected]677bb0a2012-07-13 19:38:0725class AudioPacket;
26
[email protected]efb972b2012-09-01 03:55:4727// 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]677bb0a2012-07-13 19:38:0731class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
32 public:
[email protected]efb972b2012-09-01 03:55:4733 // 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]677bb0a2012-07-13 19:38:0737 AudioScheduler(
[email protected]efb972b2012-09-01 03:55:4738 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
[email protected]677bb0a2012-07-13 19:38:0739 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
40 AudioCapturer* audio_capturer,
[email protected]abad5052012-08-01 17:41:4341 scoped_ptr<AudioEncoder> audio_encoder,
[email protected]677bb0a2012-07-13 19:38:0742 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]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
78 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
79};
80
81} // namespace remoting
82
83#endif // REMOTING_HOST_AUDIO_SCHEDULER_H_