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

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

Issue 866863004: Replace AudioScheduler with AudioPump. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mouse_cursor_pipe
Patch Set: Created 5 years, 10 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
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_capturer_win.h" 5 #include "remoting/host/audio_capturer_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <avrt.h> 8 #include <avrt.h>
9 #include <mmreg.h> 9 #include <mmreg.h>
10 #include <mmsystem.h> 10 #include <mmsystem.h>
(...skipping 26 matching lines...) Expand all
37 37
38 namespace remoting { 38 namespace remoting {
39 39
40 AudioCapturerWin::AudioCapturerWin() 40 AudioCapturerWin::AudioCapturerWin()
41 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID), 41 : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID),
42 silence_detector_(kSilenceThreshold), 42 silence_detector_(kSilenceThreshold),
43 last_capture_error_(S_OK) { 43 last_capture_error_(S_OK) {
44 thread_checker_.DetachFromThread(); 44 thread_checker_.DetachFromThread();
45 } 45 }
46 46
47 AudioCapturerWin::~AudioCapturerWin() { 47 AudioCapturerWin::~AudioCapturerWin() {
Wez 2015/02/11 01:41:12 Add thread-check here, since you no longer have ca
Sergey Ulanov 2015/02/11 21:18:12 Done.
48 } 48 }
49 49
50 bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) { 50 bool AudioCapturerWin::Start(const PacketCapturedCallback& callback) {
51 DCHECK(!audio_capture_client_.get()); 51 DCHECK(!audio_capture_client_.get());
52 DCHECK(!audio_client_.get()); 52 DCHECK(!audio_client_.get());
53 DCHECK(!mm_device_.get()); 53 DCHECK(!mm_device_.get());
54 DCHECK(static_cast<PWAVEFORMATEX>(wave_format_ex_) == nullptr); 54 DCHECK(static_cast<PWAVEFORMATEX>(wave_format_ex_) == nullptr);
55 DCHECK(thread_checker_.CalledOnValidThread()); 55 DCHECK(thread_checker_.CalledOnValidThread());
56 56
57 callback_ = callback; 57 callback_ = callback;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 silence_detector_.Reset(sampling_rate_, kChannels); 193 silence_detector_.Reset(sampling_rate_, kChannels);
194 194
195 // Start capturing. 195 // Start capturing.
196 capture_timer_->Start(FROM_HERE, 196 capture_timer_->Start(FROM_HERE,
197 audio_device_period_, 197 audio_device_period_,
198 this, 198 this,
199 &AudioCapturerWin::DoCapture); 199 &AudioCapturerWin::DoCapture);
200 return true; 200 return true;
201 } 201 }
202 202
203 void AudioCapturerWin::Stop() {
204 DCHECK(thread_checker_.CalledOnValidThread());
205 DCHECK(IsStarted());
206
207 capture_timer_.reset();
208 mm_device_.Release();
209 audio_client_.Release();
210 audio_capture_client_.Release();
211 wave_format_ex_.Reset(nullptr);
212
213 thread_checker_.DetachFromThread();
214 }
215
216 bool AudioCapturerWin::IsStarted() {
217 DCHECK(thread_checker_.CalledOnValidThread());
218 return capture_timer_.get() != nullptr;
219 }
220
221 void AudioCapturerWin::DoCapture() { 203 void AudioCapturerWin::DoCapture() {
222 DCHECK(AudioCapturer::IsValidSampleRate(sampling_rate_)); 204 DCHECK(AudioCapturer::IsValidSampleRate(sampling_rate_));
223 DCHECK(thread_checker_.CalledOnValidThread()); 205 DCHECK(thread_checker_.CalledOnValidThread());
224 DCHECK(IsStarted());
225 206
226 // Fetch all packets from the audio capture endpoint buffer. 207 // Fetch all packets from the audio capture endpoint buffer.
227 HRESULT hr = S_OK; 208 HRESULT hr = S_OK;
228 while (true) { 209 while (true) {
229 UINT32 next_packet_size; 210 UINT32 next_packet_size;
230 HRESULT hr = audio_capture_client_->GetNextPacketSize(&next_packet_size); 211 HRESULT hr = audio_capture_client_->GetNextPacketSize(&next_packet_size);
231 if (FAILED(hr)) 212 if (FAILED(hr))
232 break; 213 break;
233 214
234 if (next_packet_size <= 0) { 215 if (next_packet_size <= 0) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 257
277 bool AudioCapturer::IsSupported() { 258 bool AudioCapturer::IsSupported() {
278 return true; 259 return true;
279 } 260 }
280 261
281 scoped_ptr<AudioCapturer> AudioCapturer::Create() { 262 scoped_ptr<AudioCapturer> AudioCapturer::Create() {
282 return make_scoped_ptr(new AudioCapturerWin()); 263 return make_scoped_ptr(new AudioCapturerWin());
283 } 264 }
284 265
285 } // namespace remoting 266 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698