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

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

Issue 12049070: Avoids irregular OnMoreData callbacks on Windows using Core Audio (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleaned up Created 7 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 | 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/core_audio_util_win.h" 5 #include "media/audio/win/core_audio_util_win.h"
6 6
7 #include <Audioclient.h> 7 #include <Audioclient.h>
8 #include <Functiondiscoverykeys_devpkey.h> 8 #include <Functiondiscoverykeys_devpkey.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 542
543 // Get access to the IAudioRenderClient interface. This interface 543 // Get access to the IAudioRenderClient interface. This interface
544 // enables us to write output data to a rendering endpoint buffer. 544 // enables us to write output data to a rendering endpoint buffer.
545 ScopedComPtr<IAudioRenderClient> audio_render_client; 545 ScopedComPtr<IAudioRenderClient> audio_render_client;
546 HRESULT hr = client->GetService(__uuidof(IAudioRenderClient), 546 HRESULT hr = client->GetService(__uuidof(IAudioRenderClient),
547 audio_render_client.ReceiveVoid()); 547 audio_render_client.ReceiveVoid());
548 if (FAILED(hr)) { 548 if (FAILED(hr)) {
549 DVLOG(1) << "IAudioClient::GetService: " << std::hex << hr; 549 DVLOG(1) << "IAudioClient::GetService: " << std::hex << hr;
550 return ScopedComPtr<IAudioRenderClient>(); 550 return ScopedComPtr<IAudioRenderClient>();
551 } 551 }
552
553 // TODO(henrika): verify that this scheme is the same for shared mode and
554 // exclusive mode streams.
555
556 // Avoid start-up glitches by filling up the endpoint buffer with "silence"
557 // before starting the stream.
558 UINT32 endpoint_buffer_size = 0;
559 hr = client->GetBufferSize(&endpoint_buffer_size);
560 DVLOG_IF(1, FAILED(hr)) << "IAudioClient::GetBufferSize: " << std::hex << hr;
561
562 BYTE* data = NULL;
563 hr = audio_render_client->GetBuffer(endpoint_buffer_size, &data);
564 DVLOG_IF(1, FAILED(hr)) << "IAudioRenderClient::GetBuffer: "
565 << std::hex << hr;
566 if (SUCCEEDED(hr)) {
567 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to
568 // explicitly write silence data to the rendering buffer.
569 hr = audio_render_client->ReleaseBuffer(endpoint_buffer_size,
570 AUDCLNT_BUFFERFLAGS_SILENT);
571 DVLOG_IF(1, FAILED(hr)) << "IAudioRenderClient::ReleaseBuffer: "
572 << std::hex << hr;
573 }
574
575 // Sanity check: verify that the endpoint buffer is filled with silence.
576 UINT32 num_queued_frames = 0;
577 client->GetCurrentPadding(&num_queued_frames);
578 DCHECK(num_queued_frames == endpoint_buffer_size);
579
580 return audio_render_client; 552 return audio_render_client;
581 } 553 }
582 554
583 ScopedComPtr<IAudioCaptureClient> CoreAudioUtil::CreateCaptureClient( 555 ScopedComPtr<IAudioCaptureClient> CoreAudioUtil::CreateCaptureClient(
584 IAudioClient* client) { 556 IAudioClient* client) {
585 DCHECK(CoreAudioUtil::IsSupported()); 557 DCHECK(CoreAudioUtil::IsSupported());
586 558
587 // Get access to the IAudioCaptureClient interface. This interface 559 // Get access to the IAudioCaptureClient interface. This interface
588 // enables us to read input data from a capturing endpoint buffer. 560 // enables us to read input data from a capturing endpoint buffer.
589 ScopedComPtr<IAudioCaptureClient> audio_capture_client; 561 ScopedComPtr<IAudioCaptureClient> audio_capture_client;
590 HRESULT hr = client->GetService(__uuidof(IAudioCaptureClient), 562 HRESULT hr = client->GetService(__uuidof(IAudioCaptureClient),
591 audio_capture_client.ReceiveVoid()); 563 audio_capture_client.ReceiveVoid());
592 if (FAILED(hr)) { 564 if (FAILED(hr)) {
593 DVLOG(1) << "IAudioClient::GetService: " << std::hex << hr; 565 DVLOG(1) << "IAudioClient::GetService: " << std::hex << hr;
594 return ScopedComPtr<IAudioCaptureClient>(); 566 return ScopedComPtr<IAudioCaptureClient>();
595 } 567 }
596 return audio_capture_client; 568 return audio_capture_client;
597 } 569 }
598 570
599 } // namespace media 571 } // namespace media
OLDNEW
« media/audio/win/audio_unified_win.cc ('K') | « media/audio/win/audio_unified_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698