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

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

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 | « remoting/host/audio_scheduler.h ('k') | remoting/host/chromoting_host.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 #include "remoting/host/audio_scheduler.h" 5 #include "remoting/host/audio_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "remoting/codec/audio_encoder.h" 12 #include "remoting/codec/audio_encoder.h"
13 #include "remoting/host/audio_capturer.h" 13 #include "remoting/host/audio_capturer.h"
14 #include "remoting/proto/audio.pb.h" 14 #include "remoting/proto/audio.pb.h"
15 #include "remoting/protocol/audio_stub.h" 15 #include "remoting/protocol/audio_stub.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 AudioScheduler::AudioScheduler( 19 AudioScheduler::AudioScheduler(
20 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 20 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
21 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 21 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
22 AudioCapturer* audio_capturer, 22 AudioCapturer* audio_capturer,
23 scoped_ptr<AudioEncoder> audio_encoder, 23 scoped_ptr<AudioEncoder> audio_encoder,
24 protocol::AudioStub* audio_stub) 24 protocol::AudioStub* audio_stub)
25 : capture_task_runner_(capture_task_runner), 25 : audio_task_runner_(audio_task_runner),
26 network_task_runner_(network_task_runner), 26 network_task_runner_(network_task_runner),
27 audio_capturer_(audio_capturer), 27 audio_capturer_(audio_capturer),
28 audio_encoder_(audio_encoder.Pass()), 28 audio_encoder_(audio_encoder.Pass()),
29 audio_stub_(audio_stub), 29 audio_stub_(audio_stub),
30 network_stopped_(false) { 30 network_stopped_(false) {
31 DCHECK(capture_task_runner_); 31 DCHECK(audio_task_runner_);
32 DCHECK(network_task_runner_); 32 DCHECK(network_task_runner_);
33 DCHECK(audio_capturer_); 33 DCHECK(audio_capturer_);
34 DCHECK(audio_stub_); 34 DCHECK(audio_stub_);
35 capture_task_runner_->PostTask( 35 audio_task_runner_->PostTask(
36 FROM_HERE, base::Bind(&AudioScheduler::DoStart, this)); 36 FROM_HERE, base::Bind(&AudioScheduler::DoStart, this));
37 } 37 }
38 38
39 void AudioScheduler::Stop(const base::Closure& done_task) { 39 void AudioScheduler::Stop(const base::Closure& done_task) {
40 DCHECK(!done_task.is_null()); 40 DCHECK(!done_task.is_null());
41 41
42 if (!capture_task_runner_->BelongsToCurrentThread()) { 42 if (!audio_task_runner_->BelongsToCurrentThread()) {
43 capture_task_runner_->PostTask(FROM_HERE, base::Bind( 43 audio_task_runner_->PostTask(FROM_HERE, base::Bind(
44 &AudioScheduler::Stop, this, done_task)); 44 &AudioScheduler::Stop, this, done_task));
45 return; 45 return;
46 } 46 }
47 47
48 audio_capturer_->Stop(); 48 audio_capturer_->Stop();
49 49
50 network_task_runner_->PostTask(FROM_HERE, base::Bind( 50 network_task_runner_->PostTask(FROM_HERE, base::Bind(
51 &AudioScheduler::DoStopOnNetworkThread, this, done_task)); 51 &AudioScheduler::DoStopOnNetworkThread, this, done_task));
52 } 52 }
53 53
(...skipping 14 matching lines...) Expand all
68 68
69 // The audio encoder returns a NULL audio packet if there's no audio to send. 69 // The audio encoder returns a NULL audio packet if there's no audio to send.
70 if (encoded_packet.get()) { 70 if (encoded_packet.get()) {
71 network_task_runner_->PostTask( 71 network_task_runner_->PostTask(
72 FROM_HERE, base::Bind(&AudioScheduler::DoSendAudioPacket, 72 FROM_HERE, base::Bind(&AudioScheduler::DoSendAudioPacket,
73 this, base::Passed(encoded_packet.Pass()))); 73 this, base::Passed(encoded_packet.Pass())));
74 } 74 }
75 } 75 }
76 76
77 void AudioScheduler::DoStart() { 77 void AudioScheduler::DoStart() {
78 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 78 DCHECK(audio_task_runner_->BelongsToCurrentThread());
79 79
80 // TODO(kxing): Do something with the return value. 80 // TODO(kxing): Do something with the return value.
81 audio_capturer_->Start( 81 audio_capturer_->Start(
82 base::Bind(&AudioScheduler::NotifyAudioPacketCaptured, this)); 82 base::Bind(&AudioScheduler::NotifyAudioPacketCaptured, this));
83 } 83 }
84 84
85 void AudioScheduler::DoSendAudioPacket(scoped_ptr<AudioPacket> packet) { 85 void AudioScheduler::DoSendAudioPacket(scoped_ptr<AudioPacket> packet) {
86 DCHECK(network_task_runner_->BelongsToCurrentThread()); 86 DCHECK(network_task_runner_->BelongsToCurrentThread());
87 DCHECK(packet.get()); 87 DCHECK(packet.get());
88 88
(...skipping 10 matching lines...) Expand all
99 99
100 void AudioScheduler::DoStopOnNetworkThread(const base::Closure& done_task) { 100 void AudioScheduler::DoStopOnNetworkThread(const base::Closure& done_task) {
101 DCHECK(network_task_runner_->BelongsToCurrentThread()); 101 DCHECK(network_task_runner_->BelongsToCurrentThread());
102 102
103 network_stopped_ = true; 103 network_stopped_ = true;
104 104
105 done_task.Run(); 105 done_task.Run();
106 } 106 }
107 107
108 } // namespace remoting 108 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/audio_scheduler.h ('k') | remoting/host/chromoting_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698