Chromium Code Reviews| Index: media/audio/win/audio_low_latency_input_win.cc |
| diff --git a/media/audio/win/audio_low_latency_input_win.cc b/media/audio/win/audio_low_latency_input_win.cc |
| index 72d1d725f5bede99fcea3668212ba63d61c4e020..82ea254d3e09b2ab0f1480d03179f368f9a2e3fe 100644 |
| --- a/media/audio/win/audio_low_latency_input_win.cc |
| +++ b/media/audio/win/audio_low_latency_input_win.cc |
| @@ -51,6 +51,7 @@ WASAPIAudioInputStream::WASAPIAudioInputStream(AudioManagerWin* manager, |
| perf_count_to_100ns_units_(0.0), |
| ms_to_frame_count_(0.0), |
| sink_(NULL), |
| + com_stream_(NULL), |
|
tommi (sloooow) - chröme
2015/04/22 10:31:52
necessary?
DaleCurtis
2015/04/22 17:48:54
Done.
|
| audio_bus_(media::AudioBus::Create(params)) { |
| DCHECK(manager_); |
| @@ -158,6 +159,11 @@ void WASAPIAudioInputStream::Start(AudioInputCallback* callback) { |
| // using SetAutomaticGainControl(). |
| StartAgc(); |
| + if (!MarshalComPointers()) { |
| + HandleError(S_FALSE); |
| + return; |
| + } |
| + |
| // Create and start the thread that will drive the capturing by waiting for |
| // capture events. |
| capture_thread_ = |
| @@ -172,6 +178,8 @@ void WASAPIAudioInputStream::Start(AudioInputCallback* callback) { |
| hr = audio_render_client_for_loopback_->Start(); |
| started_ = SUCCEEDED(hr); |
| + if (!started_) |
| + HandleError(hr); |
| } |
| void WASAPIAudioInputStream::Stop() { |
| @@ -350,7 +358,7 @@ HRESULT WASAPIAudioInputStream::GetMixFormat(const std::string& device_id, |
| } |
| void WASAPIAudioInputStream::Run() { |
| - ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| + ScopedCOMInitializer com_init; |
| // Increase the thread priority. |
| capture_thread_->SetThreadPriority(base::ThreadPriority::REALTIME_AUDIO); |
| @@ -369,6 +377,11 @@ void WASAPIAudioInputStream::Run() { |
| LOG(WARNING) << "Failed to enable MMCSS (error code=" << err << ")."; |
| } |
| + // Retrieve COM pointers from the main thread. |
| + ScopedComPtr<IAudioCaptureClient> thread_audio_capture_client; |
| + |
| + bool error = !UnmarshalComPointers(&thread_audio_capture_client); |
| + |
| // Allocate a buffer with a size that enables us to take care of cases like: |
| // 1) The recorded buffer size is smaller, or does not match exactly with, |
| // the selected packet size used in each callback. |
| @@ -382,8 +395,7 @@ void WASAPIAudioInputStream::Run() { |
| LARGE_INTEGER now_count; |
| bool recording = true; |
| - bool error = false; |
| - double volume = GetVolume(); |
| + double volume = 0; |
| HANDLE wait_array[2] = |
| { stop_capture_event_.Get(), audio_samples_ready_event_.Get() }; |
| @@ -412,11 +424,9 @@ void WASAPIAudioInputStream::Run() { |
| // Retrieve the amount of data in the capture endpoint buffer, |
| // replace it with silence if required, create callbacks for each |
| // packet and store non-delivered data for the next event. |
| - hr = audio_capture_client_->GetBuffer(&data_ptr, |
| - &num_frames_to_read, |
| - &flags, |
| - &device_position, |
| - &first_audio_frame_timestamp); |
| + hr = thread_audio_capture_client->GetBuffer( |
| + &data_ptr, &num_frames_to_read, &flags, &device_position, |
| + &first_audio_frame_timestamp); |
| if (FAILED(hr)) { |
| DLOG(ERROR) << "Failed to get data from the capture buffer"; |
| continue; |
| @@ -438,7 +448,7 @@ void WASAPIAudioInputStream::Run() { |
| buffer_frame_index += num_frames_to_read; |
| } |
| - hr = audio_capture_client_->ReleaseBuffer(num_frames_to_read); |
| + hr = thread_audio_capture_client->ReleaseBuffer(num_frames_to_read); |
| DLOG_IF(ERROR, FAILED(hr)) << "Failed to release capture buffer"; |
| // Derive a delay estimate for the captured audio packet. |
| @@ -676,8 +686,11 @@ HRESULT WASAPIAudioInputStream::InitializeAudioEngine() { |
| &format_, |
| (effects_ & AudioParameters::DUCKING) ? &kCommunicationsSessionId : NULL); |
| - if (FAILED(hr)) |
| + if (FAILED(hr)) { |
| + PLOG(ERROR) << "Failed to initalize IAudioClient: " << std::hex << hr |
| + << " : "; |
|
tommi (sloooow) - chröme
2015/04/22 10:31:51
is this line left over from some previous code? (o
DaleCurtis
2015/04/22 17:48:54
It was the method that was silently failing during
|
| return hr; |
| + } |
| // Retrieve the length of the endpoint buffer shared between the client |
| // and the audio engine. The buffer length determines the maximum amount |
| @@ -768,4 +781,24 @@ HRESULT WASAPIAudioInputStream::InitializeAudioEngine() { |
| return hr; |
| } |
| +bool WASAPIAudioInputStream::MarshalComPointers() { |
| + HRESULT hr = CoMarshalInterThreadInterfaceInStream( |
| + __uuidof(IAudioCaptureClient), audio_capture_client_.get(), |
| + com_stream_.Receive()); |
| + if (FAILED(hr)) |
| + DLOG(ERROR) << "Marshal failed for IAudioCaptureClient: " << std::hex << hr; |
| + DCHECK(com_stream_); |
| + return SUCCEEDED(hr); |
| +} |
| + |
| +bool WASAPIAudioInputStream::UnmarshalComPointers( |
| + ScopedComPtr<IAudioCaptureClient>* audio_capture_client) { |
| + HRESULT hr = CoGetInterfaceAndReleaseStream( |
| + com_stream_.Detach(), __uuidof(IAudioCaptureClient), |
| + audio_capture_client->ReceiveVoid()); |
| + if (FAILED(hr)) |
|
tommi (sloooow) - chröme
2015/04/22 10:31:52
Should we have a DCHECK here that hr either succee
DaleCurtis
2015/04/22 17:48:54
IStream is always released according to the API do
|
| + DLOG(ERROR) << "Unmarshal failed IAudioCaptureClient: " << std::hex << hr; |
| + return SUCCEEDED(hr); |
| +} |
| + |
| } // namespace media |