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

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

Issue 11260053: Use correct thread for audio capturing and encoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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') | remoting/host/audio_scheduler.cc » ('J')
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 11
12 namespace base { 12 namespace base {
13 class SingleThreadTaskRunner; 13 class SingleThreadTaskRunner;
14 } // namespace base 14 } // namespace base
15 15
16 namespace remoting { 16 namespace remoting {
17 17
18 namespace protocol { 18 namespace protocol {
19 class AudioStub; 19 class AudioStub;
20 } // namespace protocol 20 } // namespace protocol
21 21
22 class AudioCapturer; 22 class AudioCapturer;
23 class AudioEncoder; 23 class AudioEncoder;
24 class AudioPacket; 24 class AudioPacket;
25 class DesktopEnvironment;
25 26
26 // AudioScheduler is responsible for fetching audio data from the AudioCapturer 27 // 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 // 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 // client. Audio is captured and encoded on the audio thread and then passed to
29 // AudioStub on the network thread. 30 // AudioStub on the network thread.
30 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> { 31 class AudioScheduler : public base::RefCountedThreadSafe<AudioScheduler> {
31 public: 32 public:
32 // Audio capture and encoding tasks are dispatched via the 33 // Audio capture and encoding tasks are dispatched via the
33 // |audio_task_runner|. |audio_stub| tasks are dispatched via the 34 // |audio_task_runner|. |audio_stub| tasks are dispatched via the
34 // |network_task_runner|. The caller must ensure that the |audio_capturer| and 35 // |network_task_runner|. The caller must ensure that the |audio_capturer| and
35 // |audio_stub| exist until the scheduler is stopped using Stop() method. 36 // |audio_stub| exist until the scheduler is stopped using Stop() method.
36 AudioScheduler( 37 AudioScheduler(
37 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 38 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
38 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 39 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
39 AudioCapturer* audio_capturer, 40 DesktopEnvironment* desktop_environment,
40 scoped_ptr<AudioEncoder> audio_encoder, 41 scoped_ptr<AudioEncoder> audio_encoder,
41 protocol::AudioStub* audio_stub); 42 protocol::AudioStub* audio_stub);
42 43
43 // Stop the recording session. 44 // Stop the recording session.
44 void Stop(const base::Closure& done_task); 45 void Stop(const base::Closure& done_task);
45 46
46 // Enable or disable audio on a running session. 47 // Enable or disable audio on a running session.
47 // This leaves the audio capturer running, and only affects whether or not the 48 // This leaves the audio capturer running, and only affects whether or not the
48 // captured audio is encoded and sent on the wire. 49 // captured audio is encoded and sent on the wire.
49 void SetEnabled(bool enabled); 50 void SetEnabled(bool enabled);
50 51
51 private: 52 private:
52 friend class base::RefCountedThreadSafe<AudioScheduler>; 53 friend class base::RefCountedThreadSafe<AudioScheduler>;
53 virtual ~AudioScheduler(); 54 virtual ~AudioScheduler();
54 55
55 // Called on the audio thread to start capturing. 56 // Called on the audio thread to start capturing.
56 void StartOnAudioThread(); 57 void StartOnAudioThread(DesktopEnvironment* desktop_environment);
57 58
58 // Called on the audio thread to stop capturing. 59 // Called on the audio thread to stop capturing.
59 void StopOnAudioThread(const base::Closure& done_task); 60 void StopOnAudioThread(const base::Closure& done_task);
60 61
61 // Called on the audio thread when a new audio packet is available. 62 // Called on the audio thread when a new audio packet is available.
62 void EncodeAudioPacket(scoped_ptr<AudioPacket> packet); 63 void EncodeAudioPacket(scoped_ptr<AudioPacket> packet);
63 64
64 // Called on the network thread to send a captured packet to the audio stub. 65 // Called on the network thread to send a captured packet to the audio stub.
65 void SendAudioPacket(scoped_ptr<AudioPacket> packet); 66 void SendAudioPacket(scoped_ptr<AudioPacket> packet);
66 67
67 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; 68 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
68 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 69 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
69 70
70 AudioCapturer* audio_capturer_; 71 scoped_ptr<AudioCapturer> audio_capturer_;
71 72
72 scoped_ptr<AudioEncoder> audio_encoder_; 73 scoped_ptr<AudioEncoder> audio_encoder_;
73 74
74 protocol::AudioStub* audio_stub_; 75 protocol::AudioStub* audio_stub_;
75 76
76 bool network_stopped_; 77 bool network_stopped_;
77 78
78 bool enabled_; 79 bool enabled_;
79 80
80 DISALLOW_COPY_AND_ASSIGN(AudioScheduler); 81 DISALLOW_COPY_AND_ASSIGN(AudioScheduler);
81 }; 82 };
82 83
83 } // namespace remoting 84 } // namespace remoting
84 85
85 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_ 86 #endif // REMOTING_HOST_AUDIO_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/audio_scheduler.cc » ('j') | remoting/host/audio_scheduler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698