Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: remoting/host/audio_scheduler.h

Issue 10914029: Use a separate thread for audio capturing and encoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/host/audio_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_HOST_AUDIO_SCHEDULER_H_ 5 #ifndef REMOTING_HOST_AUDIO_SCHEDULER_H_
6 #define REMOTING_HOST_AUDIO_SCHEDULER_H_ 6 #define REMOTING_HOST_AUDIO_SCHEDULER_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 12
13 namespace base { 13 namespace base {
14 class SingleThreadTaskRunner; 14 class SingleThreadTaskRunner;
15 } // namespace base 15 } // namespace base
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 namespace protocol { 19 namespace protocol {
20 class AudioStub; 20 class AudioStub;
21 } // namespace protocol 21 } // namespace protocol
22 22
23 class AudioCapturer; 23 class AudioCapturer;
24 class AudioEncoder; 24 class AudioEncoder;
25 class AudioPacket; 25 class AudioPacket;
26 26
27 // A class for controlling AudioCapturer and forwarding audio packets to the 27 // AudioScheduler is responsible for fetching audio data from the AudioCapturer
28 // client. 28 // and encoding it before passing it to the AudioStub for delivery to the
29 // 29 // client. Audio is captured and encoded on the audio thread and then passed to
30 // THREADING 30 // AudioStub on the network thread.
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.
39 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { 31 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
40 public: 32 public:
41 // Construct an AudioScheduler. TaskRunners are used for message passing 33 // Audio capture and encoding tasks are dispatched via the
42 // among the capturer and network threads. The caller is responsible for 34 // |audio_task_runner|. |audio_stub| tasks are dispatched via the
43 // ensuring that the |audio_capturer| and |audio_stub| outlive the 35 // |network_task_runner|. The caller must ensure that the |audio_capturer| and
44 // AudioScheduler. 36 // |audio_stub| exist until the scheduler is stopped using Stop() method.
45 AudioScheduler( 37 AudioScheduler(
46 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 38 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
47 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 39 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
48 AudioCapturer* audio_capturer, 40 AudioCapturer* audio_capturer,
49 scoped_ptr<AudioEncoder> audio_encoder, 41 scoped_ptr<AudioEncoder> audio_encoder,
50 protocol::AudioStub* audio_stub); 42 protocol::AudioStub* audio_stub);
51 43
52 // Stop the recording session. 44 // Stop the recording session.
53 void Stop(const base::Closure& done_task); 45 void Stop(const base::Closure& done_task);
54 46
55 // Called when a client disconnects. 47 // Called when a client disconnects.
56 void OnClientDisconnected(); 48 void OnClientDisconnected();
57 49
58 private: 50 private:
59 friend class base::RefCountedThreadSafe<AudioScheduler>; 51 friend class base::RefCountedThreadSafe<AudioScheduler>;
60 virtual ~AudioScheduler(); 52 virtual ~AudioScheduler();
61 53
62 void NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet); 54 void NotifyAudioPacketCaptured(scoped_ptr<AudioPacket> packet);
63 55
64 void DoStart(); 56 void DoStart();
65 57
66 // Sends an audio packet to the client. 58 // Sends an audio packet to the client.
67 void DoSendAudioPacket(scoped_ptr<AudioPacket> packet); 59 void DoSendAudioPacket(scoped_ptr<AudioPacket> packet);
68 60
69 // Signal network thread to cease activities. 61 // Signal network thread to cease activities.
70 void DoStopOnNetworkThread(const base::Closure& done_task); 62 void DoStopOnNetworkThread(const base::Closure& done_task);
71 63
72 // Called when an AudioPacket has been delivered to the client. 64 // Called when an AudioPacket has been delivered to the client.
73 void OnCaptureCallbackNotified(); 65 void OnCaptureCallbackNotified();
74 66
75 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 67 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
76 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 68 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
77 69
78 AudioCapturer* audio_capturer_; 70 AudioCapturer* audio_capturer_;
79 71
80 scoped_ptr<AudioEncoder> audio_encoder_; 72 scoped_ptr<AudioEncoder> audio_encoder_;
81 73
82 protocol::AudioStub* audio_stub_; 74 protocol::AudioStub* audio_stub_;
83 75
84 bool network_stopped_; 76 bool network_stopped_;
85 77
86 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); 78 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
87 }; 79 };
88 80
89 } // namespace remoting 81 } // namespace remoting
90 82
91 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ 83 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/audio_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698