Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/host/desktop_environment.h" | |
| 14 #include "remoting/proto/audio.pb.h" | 15 #include "remoting/proto/audio.pb.h" |
| 15 #include "remoting/protocol/audio_stub.h" | 16 #include "remoting/protocol/audio_stub.h" |
| 16 | 17 |
| 17 namespace remoting { | 18 namespace remoting { |
| 18 | 19 |
| 19 AudioScheduler::AudioScheduler( | 20 AudioScheduler::AudioScheduler( |
| 20 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 21 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 21 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 22 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 22 AudioCapturer* audio_capturer, | 23 DesktopEnvironment* desktop_environment, |
| 23 scoped_ptr<AudioEncoder> audio_encoder, | 24 scoped_ptr<AudioEncoder> audio_encoder, |
| 24 protocol::AudioStub* audio_stub) | 25 protocol::AudioStub* audio_stub) |
| 25 : audio_task_runner_(audio_task_runner), | 26 : audio_task_runner_(audio_task_runner), |
| 26 network_task_runner_(network_task_runner), | 27 network_task_runner_(network_task_runner), |
| 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 enabled_(true) { | 31 enabled_(true) { |
| 32 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 32 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 33 DCHECK(audio_capturer_); | |
| 34 DCHECK(audio_stub_); | 33 DCHECK(audio_stub_); |
| 35 | 34 |
| 36 audio_task_runner_->PostTask( | 35 audio_task_runner_->PostTask( |
| 37 FROM_HERE, base::Bind(&AudioScheduler::StartOnAudioThread, this)); | 36 FROM_HERE, base::Bind(&AudioScheduler::StartOnAudioThread, this, |
| 37 desktop_environment)); | |
|
Wez
2012/10/27 03:43:15
base::Unretained()?
Wez
2012/10/27 03:43:15
Add a comment reminding that |desktop_environment|
Sergey Ulanov
2012/10/29 23:43:04
AudioScheduler is ref-counted
Sergey Ulanov
2012/10/29 23:43:04
Done.
| |
| 38 } | 38 } |
| 39 | 39 |
| 40 void AudioScheduler::Stop(const base::Closure& done_task) { | 40 void AudioScheduler::Stop(const base::Closure& done_task) { |
| 41 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 41 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 42 DCHECK(!done_task.is_null()); | 42 DCHECK(!done_task.is_null()); |
| 43 DCHECK(audio_stub_); | 43 DCHECK(audio_stub_); |
| 44 | 44 |
| 45 // Clear |audio_stub_| to prevent audio packets being delivered to the client. | 45 // Clear |audio_stub_| to prevent audio packets being delivered to the client. |
| 46 audio_stub_ = NULL; | 46 audio_stub_ = NULL; |
| 47 | 47 |
| 48 audio_task_runner_->PostTask( | 48 audio_task_runner_->PostTask( |
| 49 FROM_HERE, | 49 FROM_HERE, |
| 50 base::Bind(&AudioScheduler::StopOnAudioThread, this, done_task)); | 50 base::Bind(&AudioScheduler::StopOnAudioThread, this, done_task)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 AudioScheduler::~AudioScheduler() { | 53 AudioScheduler::~AudioScheduler() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 void AudioScheduler::StartOnAudioThread() { | 56 void AudioScheduler::StartOnAudioThread( |
| 57 DesktopEnvironment* desktop_environment) { | |
| 57 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 58 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 58 | 59 |
| 59 // TODO(kxing): Do something with the return value. | 60 audio_capturer_ = desktop_environment->CreateAudioCapturer(); |
| 60 audio_capturer_->Start( | 61 if (!audio_capturer_->Start( |
| 61 base::Bind(&AudioScheduler::EncodeAudioPacket, this)); | 62 base::Bind(&AudioScheduler::EncodeAudioPacket, this))) { |
|
Wez
2012/10/27 03:43:15
nit: Indentation.
Sergey Ulanov
2012/10/29 23:43:04
It is indented correctly - 4 spaces relative to st
| |
| 63 LOG(ERROR) << "Failed to create audio capturer"; | |
|
Wez
2012/10/27 03:43:15
nit: Failed to start audio capturer?
Sergey Ulanov
2012/10/29 23:43:04
Done.
| |
| 64 audio_capturer_.reset(); | |
| 65 } | |
| 62 } | 66 } |
| 63 | 67 |
| 64 void AudioScheduler::StopOnAudioThread(const base::Closure& done_task) { | 68 void AudioScheduler::StopOnAudioThread(const base::Closure& done_task) { |
| 65 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 69 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 66 audio_capturer_->Stop(); | 70 if (audio_capturer_) |
| 71 audio_capturer_->Stop(); | |
|
Wez
2012/10/27 03:43:15
Not for this CL, but I wonder if we even need Audi
Sergey Ulanov
2012/10/29 23:43:04
No. I'll remove it in a separate CL.
| |
| 67 | 72 |
| 68 network_task_runner_->PostTask(FROM_HERE, done_task); | 73 network_task_runner_->PostTask(FROM_HERE, done_task); |
| 69 } | 74 } |
| 70 | 75 |
| 71 void AudioScheduler::SetEnabled(bool enabled) { | 76 void AudioScheduler::SetEnabled(bool enabled) { |
| 72 if (!audio_task_runner_->BelongsToCurrentThread()) { | 77 if (!audio_task_runner_->BelongsToCurrentThread()) { |
| 73 audio_task_runner_->PostTask( | 78 audio_task_runner_->PostTask( |
| 74 FROM_HERE, base::Bind(&AudioScheduler::SetEnabled, this, enabled)); | 79 FROM_HERE, base::Bind(&AudioScheduler::SetEnabled, this, enabled)); |
| 75 return; | 80 return; |
| 76 } | 81 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 100 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 105 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 101 DCHECK(packet.get()); | 106 DCHECK(packet.get()); |
| 102 | 107 |
| 103 if (!audio_stub_) | 108 if (!audio_stub_) |
| 104 return; | 109 return; |
| 105 | 110 |
| 106 audio_stub_->ProcessAudioPacket(packet.Pass(), base::Closure()); | 111 audio_stub_->ProcessAudioPacket(packet.Pass(), base::Closure()); |
| 107 } | 112 } |
| 108 | 113 |
| 109 } // namespace remoting | 114 } // namespace remoting |
| OLD | NEW |