Index: media/audio/win/audio_low_latency_output_win.cc |
diff --git a/media/audio/win/audio_low_latency_output_win.cc b/media/audio/win/audio_low_latency_output_win.cc |
index a9d637c3edc7e7c705011c4e88f95885866b4255..f7b31a3c00a09d75376a190fa9df926f9b32b6db 100644 |
--- a/media/audio/win/audio_low_latency_output_win.cc |
+++ b/media/audio/win/audio_low_latency_output_win.cc |
@@ -249,11 +249,6 @@ |
} |
num_written_frames_ = endpoint_buffer_size_frames_; |
- if (!MarshalComPointers()) { |
- callback->OnError(this); |
- return; |
- } |
- |
// Create and start the thread that will drive the rendering by waiting for |
// render events. |
render_thread_.reset( |
@@ -338,7 +333,7 @@ |
} |
void WASAPIAudioOutputStream::Run() { |
- ScopedCOMInitializer com_init; |
+ ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
// Increase the thread priority. |
render_thread_->SetThreadPriority(base::ThreadPriority::REALTIME_AUDIO); |
@@ -357,12 +352,6 @@ |
LOG(WARNING) << "Failed to enable MMCSS (error code=" << err << ")."; |
} |
- // Retrieve COM pointers from the main thread. |
- ScopedComPtr<IAudioClient> audio_client; |
- ScopedComPtr<IAudioRenderClient> audio_render_client; |
- ScopedComPtr<IAudioClock> audio_clock; |
- UnmarshalComPointers(&audio_client, &audio_render_client, &audio_clock); |
- |
HRESULT hr = S_FALSE; |
bool playing = true; |
@@ -373,7 +362,7 @@ |
// The device frequency is the frequency generated by the hardware clock in |
// the audio device. The GetFrequency() method reports a constant frequency. |
- hr = audio_clock->GetFrequency(&device_frequency); |
+ hr = audio_clock_->GetFrequency(&device_frequency); |
error = FAILED(hr); |
PLOG_IF(ERROR, error) << "Failed to acquire IAudioClock interface: " |
<< std::hex << hr; |
@@ -394,9 +383,7 @@ |
break; |
case WAIT_OBJECT_0 + 1: |
// |audio_samples_render_event_| has been set. |
- error = !RenderAudioFromSource(device_frequency, audio_client.get(), |
- audio_render_client.get(), |
- audio_clock.get()); |
+ error = !RenderAudioFromSource(device_frequency); |
break; |
default: |
error = true; |
@@ -404,11 +391,11 @@ |
} |
} |
- if (playing && error && audio_client) { |
+ if (playing && error) { |
// Stop audio rendering since something has gone wrong in our main thread |
// loop. Note that, we are still in a "started" state, hence a Stop() call |
// is required to join the thread properly. |
- audio_client->Stop(); |
+ audio_client_->Stop(); |
PLOG(ERROR) << "WASAPI rendering failed."; |
} |
@@ -418,11 +405,7 @@ |
} |
} |
-bool WASAPIAudioOutputStream::RenderAudioFromSource( |
- UINT64 device_frequency, |
- IAudioClient* audio_client, |
- IAudioRenderClient* audio_render_client, |
- IAudioClock* audio_clock) { |
+bool WASAPIAudioOutputStream::RenderAudioFromSource(UINT64 device_frequency) { |
TRACE_EVENT0("audio", "RenderAudioFromSource"); |
HRESULT hr = S_FALSE; |
@@ -437,7 +420,7 @@ |
if (share_mode_ == AUDCLNT_SHAREMODE_SHARED) { |
// Get the padding value which represents the amount of rendering |
// data that is queued up to play in the endpoint buffer. |
- hr = audio_client->GetCurrentPadding(&num_queued_frames); |
+ hr = audio_client_->GetCurrentPadding(&num_queued_frames); |
num_available_frames = |
endpoint_buffer_size_frames_ - num_queued_frames; |
if (FAILED(hr)) { |
@@ -479,7 +462,8 @@ |
for (size_t n = 0; n < num_packets; ++n) { |
// Grab all available space in the rendering endpoint buffer |
// into which the client can write a data packet. |
- hr = audio_render_client->GetBuffer(packet_size_frames_, &audio_data); |
+ hr = audio_render_client_->GetBuffer(packet_size_frames_, |
+ &audio_data); |
if (FAILED(hr)) { |
DLOG(ERROR) << "Failed to use rendering audio buffer: " |
<< std::hex << hr; |
@@ -493,7 +477,7 @@ |
// unit at the render side. |
UINT64 position = 0; |
uint32 audio_delay_bytes = 0; |
- hr = audio_clock->GetPosition(&position, NULL); |
+ hr = audio_clock_->GetPosition(&position, NULL); |
if (SUCCEEDED(hr)) { |
// Stream position of the sample that is currently playing |
// through the speaker. |
@@ -533,7 +517,7 @@ |
// Render silence if we were not able to fill up the buffer totally. |
DWORD flags = (num_filled_bytes < packet_size_bytes_) ? |
AUDCLNT_BUFFERFLAGS_SILENT : 0; |
- audio_render_client->ReleaseBuffer(packet_size_frames_, flags); |
+ audio_render_client_->ReleaseBuffer(packet_size_frames_, flags); |
num_written_frames_ += packet_size_frames_; |
} |
@@ -638,73 +622,4 @@ |
source_ = NULL; |
} |
-bool WASAPIAudioOutputStream::MarshalComPointers() { |
- DCHECK_EQ(creating_thread_id_, base::PlatformThread::CurrentId()); |
- DCHECK(!com_stream_); |
- |
- ScopedComPtr<IStream> com_stream; |
- HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, com_stream.Receive()); |
- if (FAILED(hr)) { |
- DLOG(ERROR) << "Failed to create stream for marshaling COM pointers."; |
- return false; |
- } |
- |
- hr = CoMarshalInterface(com_stream.get(), __uuidof(IAudioClient), |
- audio_client_.get(), MSHCTX_INPROC, NULL, |
- MSHLFLAGS_NORMAL); |
- if (FAILED(hr)) { |
- DLOG(ERROR) << "Marshal failed for IAudioClient: " << std::hex << hr; |
- return false; |
- } |
- |
- hr = CoMarshalInterface(com_stream.get(), __uuidof(IAudioRenderClient), |
- audio_render_client_.get(), MSHCTX_INPROC, NULL, |
- MSHLFLAGS_NORMAL); |
- if (FAILED(hr)) { |
- DLOG(ERROR) << "Marshal failed for IAudioRenderClient: " << std::hex << hr; |
- return false; |
- } |
- |
- hr = CoMarshalInterface(com_stream.get(), __uuidof(IAudioClock), |
- audio_clock_.get(), MSHCTX_INPROC, NULL, |
- MSHLFLAGS_NORMAL); |
- if (FAILED(hr)) { |
- DLOG(ERROR) << "Marshal failed for IAudioClock: " << std::hex << hr; |
- return false; |
- } |
- |
- LARGE_INTEGER pos = {0}; |
- hr = com_stream->Seek(pos, STREAM_SEEK_SET, NULL); |
- if (FAILED(hr)) { |
- DLOG(ERROR) << "Failed to seek IStream for marshaling: " << std::hex << hr; |
- return false; |
- } |
- |
- com_stream_ = com_stream.Pass(); |
- return true; |
-} |
- |
-void WASAPIAudioOutputStream::UnmarshalComPointers( |
- ScopedComPtr<IAudioClient>* audio_client, |
- ScopedComPtr<IAudioRenderClient>* audio_render_client, |
- ScopedComPtr<IAudioClock>* audio_clock) { |
- DCHECK_EQ(render_thread_->tid(), base::PlatformThread::CurrentId()); |
- |
- DCHECK(com_stream_); |
- ScopedComPtr<IStream> com_stream; |
- com_stream = com_stream_.Pass(); |
- |
- HRESULT hr = CoUnmarshalInterface(com_stream.get(), __uuidof(IAudioClient), |
- audio_client->ReceiveVoid()); |
- CHECK(SUCCEEDED(hr)); |
- |
- hr = CoUnmarshalInterface(com_stream.get(), __uuidof(IAudioRenderClient), |
- audio_render_client->ReceiveVoid()); |
- CHECK(SUCCEEDED(hr)); |
- |
- hr = CoUnmarshalInterface(com_stream.get(), __uuidof(IAudioClock), |
- audio_clock->ReceiveVoid()); |
- CHECK(SUCCEEDED(hr)); |
-} |
- |
} // namespace media |