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