blob: d82de21a5d7064440f1818b1f308a8ec5cd7ab60 [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
27// A class for controlling AudioCapturer and forwarding audio packets to the
28// client.
29//
30// THREADING
31//
32// This class works on two threads: the capture and network threads.
33// Any encoding that is done on the audio samples will be done on the capture
34// thread.
35//
36// AudioScheduler is responsible for:
37// 1. managing the AudioCapturer.
38// 2. sending packets of audio samples over the network to the client.
39class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
40 public:
41 // Construct an AudioScheduler. TaskRunners are used for message passing
42 // among the capturer and network threads. The caller is responsible for
43 // ensuring that the |audio_capturer| and |audio_stub| outlive the
44 // AudioScheduler.
45 AudioScheduler(
46 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
47 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
48 AudioCapturer* audio_capturer,
[email protected]abad5052012-08-01 17:41:4349 scoped_ptr<AudioEncoder> audio_encoder,
[email protected]677bb0a2012-07-13 19:38:0750 protocol::AudioStub* audio_stub);
51
52 // Stop the recording session.
53 void Stop(const base::Closure& done_task);
54
55 // Called when a client disconnects.
56 void OnClientDisconnected();
57
58 private:
59 friend class base::RefCountedThreadSafe<AudioScheduler>;
60 virtual ~AudioScheduler();
61
62 void NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet);
63
64 void DoStart();
65
66 // Sends an audio packet to the client.
67 void DoSendAudioPacket(scoped_ptr<AudioPacket> packet);
68
69 // Signal network thread to cease activities.
70 void DoStopOnNetworkThread(const base::Closure& done_task);
71
72 // Called when an AudioPacket has been delivered to the client.
73 void OnCaptureCallbackNotified();
74
75 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
76 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
77
78 AudioCapturer* audio_capturer_;
79
[email protected]abad5052012-08-01 17:41:4380 scoped_ptr<AudioEncoder> audio_encoder_;
81
[email protected]677bb0a2012-07-13 19:38:0782 protocol::AudioStub* audio_stub_;
83
84 bool network_stopped_;
85
86 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
87};
88
89} // namespace remoting
90
91#endif // REMOTING_HOST_AUDIO_SCHEDULER_H_