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

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

Issue 367923004: Turn audio ducking on by default on Windows again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 5 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 "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 <devicetopology.h> 8 #include <devicetopology.h>
9 #include <functiondiscoverykeys_devpkey.h> 9 #include <functiondiscoverykeys_devpkey.h>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/scoped_co_mem.h" 15 #include "base/win/scoped_co_mem.h"
16 #include "base/win/scoped_handle.h" 16 #include "base/win/scoped_handle.h"
17 #include "base/win/scoped_propvariant.h" 17 #include "base/win/scoped_propvariant.h"
18 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "media/base/media_switches.h" 19 #include "media/base/media_switches.h"
20 20
21 using base::win::ScopedCoMem; 21 using base::win::ScopedCoMem;
22 using base::win::ScopedHandle; 22 using base::win::ScopedHandle;
23 23
24 namespace media { 24 namespace media {
25 25
26 // See header file for documentation.
27 // {BE39AF4F-087C-423F-9303-234EC1E5B8EE}
28 const GUID kCommunicationsSessionId = {
DaleCurtis 2014/07/09 21:12:04 static const?
tommi (sloooow) - chröme 2014/07/10 02:57:52 I need the constant exported from the object file
29 0xbe39af4f, 0x87c, 0x423f, { 0x93, 0x3, 0x23, 0x4e, 0xc1, 0xe5, 0xb8, 0xee }
30 };
31
26 enum { KSAUDIO_SPEAKER_UNSUPPORTED = 0 }; 32 enum { KSAUDIO_SPEAKER_UNSUPPORTED = 0 };
27 33
28 // Converts Microsoft's channel configuration to ChannelLayout. 34 // Converts Microsoft's channel configuration to ChannelLayout.
29 // This mapping is not perfect but the best we can do given the current 35 // This mapping is not perfect but the best we can do given the current
30 // ChannelLayout enumerator and the Windows-specific speaker configurations 36 // ChannelLayout enumerator and the Windows-specific speaker configurations
31 // defined in ksmedia.h. Don't assume that the channel ordering in 37 // defined in ksmedia.h. Don't assume that the channel ordering in
32 // ChannelLayout is exactly the same as the Windows specific configuration. 38 // ChannelLayout is exactly the same as the Windows specific configuration.
33 // As an example: KSAUDIO_SPEAKER_7POINT1_SURROUND is mapped to 39 // As an example: KSAUDIO_SPEAKER_7POINT1_SURROUND is mapped to
34 // CHANNEL_LAYOUT_7_1 but the positions of Back L, Back R and Side L, Side R 40 // CHANNEL_LAYOUT_7_1 but the positions of Back L, Back R and Side L, Side R
35 // speakers are different in these two definitions. 41 // speakers are different in these two definitions.
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 ScopedComPtr<IAudioClient> client( 730 ScopedComPtr<IAudioClient> client(
725 CreateClient(device_id, data_flow, eConsole)); 731 CreateClient(device_id, data_flow, eConsole));
726 732
727 WAVEFORMATPCMEX format = {0}; 733 WAVEFORMATPCMEX format = {0};
728 if (!client || FAILED(GetSharedModeMixFormat(client, &format))) 734 if (!client || FAILED(GetSharedModeMixFormat(client, &format)))
729 return 0; 735 return 0;
730 736
731 return static_cast<ChannelConfig>(format.dwChannelMask); 737 return static_cast<ChannelConfig>(format.dwChannelMask);
732 } 738 }
733 739
734 HRESULT CoreAudioUtil::SharedModeInitialize(IAudioClient* client, 740 HRESULT CoreAudioUtil::SharedModeInitialize(
735 const WAVEFORMATPCMEX* format, 741 IAudioClient* client, const WAVEFORMATPCMEX* format, HANDLE event_handle,
736 HANDLE event_handle, 742 uint32* endpoint_buffer_size, const GUID* session_guid) {
737 uint32* endpoint_buffer_size) {
738 DCHECK(IsSupported()); 743 DCHECK(IsSupported());
739 744
740 // Use default flags (i.e, dont set AUDCLNT_STREAMFLAGS_NOPERSIST) to 745 // Use default flags (i.e, dont set AUDCLNT_STREAMFLAGS_NOPERSIST) to
741 // ensure that the volume level and muting state for a rendering session 746 // ensure that the volume level and muting state for a rendering session
742 // are persistent across system restarts. The volume level and muting 747 // are persistent across system restarts. The volume level and muting
743 // state for a capture session are never persistent. 748 // state for a capture session are never persistent.
744 DWORD stream_flags = 0; 749 DWORD stream_flags = 0;
745 750
746 // Enable event-driven streaming if a valid event handle is provided. 751 // Enable event-driven streaming if a valid event handle is provided.
747 // After the stream starts, the audio engine will signal the event handle 752 // After the stream starts, the audio engine will signal the event handle
748 // to notify the client each time a buffer becomes ready to process. 753 // to notify the client each time a buffer becomes ready to process.
749 // Event-driven buffering is supported for both rendering and capturing. 754 // Event-driven buffering is supported for both rendering and capturing.
750 // Both shared-mode and exclusive-mode streams can use event-driven buffering. 755 // Both shared-mode and exclusive-mode streams can use event-driven buffering.
751 bool use_event = (event_handle != NULL && 756 bool use_event = (event_handle != NULL &&
752 event_handle != INVALID_HANDLE_VALUE); 757 event_handle != INVALID_HANDLE_VALUE);
753 if (use_event) 758 if (use_event)
754 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK; 759 stream_flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
755 DVLOG(2) << "stream_flags: 0x" << std::hex << stream_flags; 760 DVLOG(2) << "stream_flags: 0x" << std::hex << stream_flags;
756 761
757 // Initialize the shared mode client for minimal delay. 762 // Initialize the shared mode client for minimal delay.
758 HRESULT hr = client->Initialize(AUDCLNT_SHAREMODE_SHARED, 763 HRESULT hr = client->Initialize(AUDCLNT_SHAREMODE_SHARED,
759 stream_flags, 764 stream_flags,
760 0, 765 0,
761 0, 766 0,
762 reinterpret_cast<const WAVEFORMATEX*>(format), 767 reinterpret_cast<const WAVEFORMATEX*>(format),
763 NULL); 768 session_guid);
764 if (FAILED(hr)) { 769 if (FAILED(hr)) {
765 DVLOG(1) << "IAudioClient::Initialize: " << std::hex << hr; 770 DVLOG(1) << "IAudioClient::Initialize: " << std::hex << hr;
766 return hr; 771 return hr;
767 } 772 }
768 773
769 if (use_event) { 774 if (use_event) {
770 hr = client->SetEventHandle(event_handle); 775 hr = client->SetEventHandle(event_handle);
771 if (FAILED(hr)) { 776 if (FAILED(hr)) {
772 DVLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr; 777 DVLOG(1) << "IAudioClient::SetEventHandle: " << std::hex << hr;
773 return hr; 778 return hr;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return false; 847 return false;
843 848
844 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to 849 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to
845 // explicitly write silence data to the rendering buffer. 850 // explicitly write silence data to the rendering buffer.
846 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; 851 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence";
847 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, 852 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill,
848 AUDCLNT_BUFFERFLAGS_SILENT)); 853 AUDCLNT_BUFFERFLAGS_SILENT));
849 } 854 }
850 855
851 } // namespace media 856 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698