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/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "remoting/codec/audio_encoder.h" | 11 #include "remoting/codec/audio_encoder.h" |
12 #include "remoting/host/audio_capturer.h" | 12 #include "remoting/host/audio_capturer.h" |
13 #include "remoting/proto/audio.pb.h" | 13 #include "remoting/proto/audio.pb.h" |
14 #include "remoting/protocol/audio_stub.h" | 14 #include "remoting/protocol/audio_stub.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 // static | 18 AudioScheduler::AudioScheduler( |
19 scoped_refptr<AudioScheduler> AudioScheduler::Create( | |
20 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 19 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
21 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
22 scoped_ptr<AudioCapturer> audio_capturer, | 21 scoped_ptr<AudioCapturer> audio_capturer, |
23 scoped_ptr<AudioEncoder> audio_encoder, | 22 scoped_ptr<AudioEncoder> audio_encoder, |
24 protocol::AudioStub* audio_stub) { | 23 protocol::AudioStub* audio_stub) |
25 DCHECK(network_task_runner->BelongsToCurrentThread()); | 24 : audio_task_runner_(audio_task_runner), |
26 DCHECK(audio_capturer); | 25 network_task_runner_(network_task_runner), |
27 DCHECK(audio_encoder); | 26 audio_capturer_(audio_capturer.Pass()), |
28 DCHECK(audio_stub); | 27 audio_encoder_(audio_encoder.Pass()), |
| 28 audio_stub_(audio_stub), |
| 29 network_stopped_(false), |
| 30 enabled_(true) { |
| 31 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 32 DCHECK(audio_capturer_); |
| 33 DCHECK(audio_encoder_); |
| 34 DCHECK(audio_stub_); |
| 35 } |
29 | 36 |
30 scoped_refptr<AudioScheduler> scheduler = new AudioScheduler( | 37 void AudioScheduler::Start() { |
31 audio_task_runner, network_task_runner, | 38 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
32 audio_capturer.Pass(), audio_encoder.Pass(), audio_stub); | |
33 audio_task_runner->PostTask( | |
34 FROM_HERE, base::Bind(&AudioScheduler::StartOnAudioThread, scheduler)); | |
35 | 39 |
36 return scheduler; | 40 audio_task_runner_->PostTask( |
| 41 FROM_HERE, base::Bind(&AudioScheduler::StartOnAudioThread, this)); |
37 } | 42 } |
38 | 43 |
39 void AudioScheduler::Stop() { | 44 void AudioScheduler::Stop() { |
40 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 45 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
41 DCHECK(audio_stub_); | 46 DCHECK(audio_stub_); |
42 | 47 |
43 // Clear |audio_stub_| to prevent audio packets being delivered to the client. | 48 // Clear |audio_stub_| to prevent audio packets being delivered to the client. |
44 audio_stub_ = NULL; | 49 audio_stub_ = NULL; |
45 | 50 |
46 audio_task_runner_->PostTask( | 51 audio_task_runner_->PostTask( |
47 FROM_HERE, | 52 FROM_HERE, |
48 base::Bind(&AudioScheduler::StopOnAudioThread, this)); | 53 base::Bind(&AudioScheduler::StopOnAudioThread, this)); |
49 } | 54 } |
50 | 55 |
51 AudioScheduler::AudioScheduler( | |
52 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | |
53 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
54 scoped_ptr<AudioCapturer> audio_capturer, | |
55 scoped_ptr<AudioEncoder> audio_encoder, | |
56 protocol::AudioStub* audio_stub) | |
57 : audio_task_runner_(audio_task_runner), | |
58 network_task_runner_(network_task_runner), | |
59 audio_capturer_(audio_capturer.Pass()), | |
60 audio_encoder_(audio_encoder.Pass()), | |
61 audio_stub_(audio_stub), | |
62 network_stopped_(false), | |
63 enabled_(true) { | |
64 } | |
65 | |
66 AudioScheduler::~AudioScheduler() { | 56 AudioScheduler::~AudioScheduler() { |
67 } | 57 } |
68 | 58 |
69 void AudioScheduler::StartOnAudioThread() { | 59 void AudioScheduler::StartOnAudioThread() { |
70 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 60 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
71 | 61 |
72 // TODO(kxing): Do something with the return value. | 62 // TODO(kxing): Do something with the return value. |
73 audio_capturer_->Start( | 63 audio_capturer_->Start( |
74 base::Bind(&AudioScheduler::EncodeAudioPacket, this)); | 64 base::Bind(&AudioScheduler::EncodeAudioPacket, this)); |
75 } | 65 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
112 DCHECK(packet.get()); | 102 DCHECK(packet.get()); |
113 | 103 |
114 if (!audio_stub_) | 104 if (!audio_stub_) |
115 return; | 105 return; |
116 | 106 |
117 audio_stub_->ProcessAudioPacket(packet.Pass(), base::Closure()); | 107 audio_stub_->ProcessAudioPacket(packet.Pass(), base::Closure()); |
118 } | 108 } |
119 | 109 |
120 } // namespace remoting | 110 } // namespace remoting |
OLD | NEW |