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

Side by Side Diff: media/audio/win/audio_unified_win.cc

Issue 15979015: Reland 15721002: Hook up the device selection to the WebAudio live audio (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed the comments. Created 7 years, 6 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
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 "media/audio/win/audio_unified_win.h" 5 #include "media/audio/win/audio_unified_win.h"
6 6
7 #include <Functiondiscoverykeys_devpkey.h> 7 #include <Functiondiscoverykeys_devpkey.h>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #ifndef NDEBUG 10 #ifndef NDEBUG
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Convert frame count to milliseconds given the audio format in |format|. 102 // Convert frame count to milliseconds given the audio format in |format|.
103 static double FrameCountToMilliseconds(int num_frames, 103 static double FrameCountToMilliseconds(int num_frames,
104 const WAVEFORMATPCMEX& format) { 104 const WAVEFORMATPCMEX& format) {
105 return (base::Time::kMillisecondsPerSecond * num_frames) / 105 return (base::Time::kMillisecondsPerSecond * num_frames) /
106 static_cast<double>(format.Format.nSamplesPerSec); 106 static_cast<double>(format.Format.nSamplesPerSec);
107 } 107 }
108 108
109 namespace media { 109 namespace media {
110 110
111 WASAPIUnifiedStream::WASAPIUnifiedStream(AudioManagerWin* manager, 111 WASAPIUnifiedStream::WASAPIUnifiedStream(AudioManagerWin* manager,
112 const AudioParameters& params) 112 const AudioParameters& params,
113 const std::string& input_device_id)
113 : creating_thread_id_(base::PlatformThread::CurrentId()), 114 : creating_thread_id_(base::PlatformThread::CurrentId()),
114 manager_(manager), 115 manager_(manager),
115 params_(params), 116 params_(params),
116 input_channels_(params.input_channels()), 117 input_channels_(params.input_channels()),
117 output_channels_(params.channels()), 118 output_channels_(params.channels()),
119 input_device_id_(input_device_id),
118 share_mode_(CoreAudioUtil::GetShareMode()), 120 share_mode_(CoreAudioUtil::GetShareMode()),
119 audio_io_thread_(NULL), 121 audio_io_thread_(NULL),
120 opened_(false), 122 opened_(false),
121 volume_(1.0), 123 volume_(1.0),
122 output_buffer_size_frames_(0), 124 output_buffer_size_frames_(0),
123 input_buffer_size_frames_(0), 125 input_buffer_size_frames_(0),
124 endpoint_render_buffer_size_frames_(0), 126 endpoint_render_buffer_size_frames_(0),
125 endpoint_capture_buffer_size_frames_(0), 127 endpoint_capture_buffer_size_frames_(0),
126 num_written_frames_(0), 128 num_written_frames_(0),
127 total_delay_ms_(0.0), 129 total_delay_ms_(0.0),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 323 }
322 if (FAILED(hr)) 324 if (FAILED(hr))
323 return false; 325 return false;
324 326
325 ScopedComPtr<IAudioRenderClient> audio_render_client = 327 ScopedComPtr<IAudioRenderClient> audio_render_client =
326 CoreAudioUtil::CreateRenderClient(audio_output_client); 328 CoreAudioUtil::CreateRenderClient(audio_output_client);
327 if (!audio_render_client) 329 if (!audio_render_client)
328 return false; 330 return false;
329 331
330 // Capture side (always event driven but format depends on varispeed or not): 332 // Capture side (always event driven but format depends on varispeed or not):
331 333 // TODO(henrika): Open the correct input device with |input_device_id_|,
334 // http://crbug.com/147327.
332 ScopedComPtr<IAudioClient> audio_input_client = 335 ScopedComPtr<IAudioClient> audio_input_client =
333 CoreAudioUtil::CreateDefaultClient(eCapture, eConsole); 336 CoreAudioUtil::CreateDefaultClient(eCapture, eConsole);
334 if (!audio_input_client) 337 if (!audio_input_client)
335 return false; 338 return false;
336 339
337 if (!CoreAudioUtil::IsFormatSupported(audio_input_client, 340 if (!CoreAudioUtil::IsFormatSupported(audio_input_client,
338 share_mode_, 341 share_mode_,
339 &input_format_)) { 342 &input_format_)) {
340 return false; 343 return false;
341 } 344 }
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 void WASAPIUnifiedStream::StopAndJoinThread(HRESULT err) { 974 void WASAPIUnifiedStream::StopAndJoinThread(HRESULT err) {
972 CHECK(GetCurrentThreadId() == creating_thread_id_); 975 CHECK(GetCurrentThreadId() == creating_thread_id_);
973 DCHECK(audio_io_thread_.get()); 976 DCHECK(audio_io_thread_.get());
974 SetEvent(stop_streaming_event_.Get()); 977 SetEvent(stop_streaming_event_.Get());
975 audio_io_thread_->Join(); 978 audio_io_thread_->Join();
976 audio_io_thread_.reset(); 979 audio_io_thread_.reset();
977 HandleError(err); 980 HandleError(err);
978 } 981 }
979 982
980 } // namespace media 983 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698