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

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

Issue 12823002: Merge 186166 "Improved CoreAudioUtil::IsSupported()." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1410/src/
Patch Set: Created 7 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 bool LoadAudiosesDll() { 70 bool LoadAudiosesDll() {
71 static const wchar_t* const kAudiosesDLL = 71 static const wchar_t* const kAudiosesDLL =
72 L"%WINDIR%\\system32\\audioses.dll"; 72 L"%WINDIR%\\system32\\audioses.dll";
73 73
74 wchar_t path[MAX_PATH] = {0}; 74 wchar_t path[MAX_PATH] = {0};
75 ExpandEnvironmentStringsW(kAudiosesDLL, path, arraysize(path)); 75 ExpandEnvironmentStringsW(kAudiosesDLL, path, arraysize(path));
76 return (LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) != NULL); 76 return (LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) != NULL);
77 } 77 }
78 78
79 bool CanCreateDeviceEnumerator() {
80 ScopedComPtr<IMMDeviceEnumerator> device_enumerator;
81 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
82 NULL,
83 CLSCTX_INPROC_SERVER,
84 __uuidof(IMMDeviceEnumerator),
85 device_enumerator.ReceiveVoid());
86
87 // If we hit CO_E_NOTINITIALIZED, CoInitialize has not been called and it
88 // must be called at least once for each thread that uses the COM library.
89 CHECK_NE(hr, CO_E_NOTINITIALIZED);
90
91 return SUCCEEDED(hr);
92 }
93
79 bool CoreAudioUtil::IsSupported() { 94 bool CoreAudioUtil::IsSupported() {
80 // Microsoft does not plan to make the Core Audio APIs available for use 95 // Microsoft does not plan to make the Core Audio APIs available for use
81 // with earlier versions of Windows, including Microsoft Windows Server 2003, 96 // with earlier versions of Windows, including Microsoft Windows Server 2003,
82 // Windows XP, Windows Millennium Edition, Windows 2000, and Windows 98. 97 // Windows XP, Windows Millennium Edition, Windows 2000, and Windows 98.
83 if (base::win::GetVersion() < base::win::VERSION_VISTA) 98 if (base::win::GetVersion() < base::win::VERSION_VISTA)
84 return false; 99 return false;
85 100
86 // The audio core APIs are implemented in the Mmdevapi.dll and Audioses.dll 101 // The audio core APIs are implemented in the Mmdevapi.dll and Audioses.dll
87 // system components. 102 // system components.
88 // Dependency Walker shows that it is enough to verify possibility to load 103 // Dependency Walker shows that it is enough to verify possibility to load
89 // the Audioses DLL since it depends on Mmdevapi.dll. 104 // the Audioses DLL since it depends on Mmdevapi.dll.
90 // See http://crbug.com/166397 why this extra step is required to guarantee 105 // See http://crbug.com/166397 why this extra step is required to guarantee
91 // Core Audio support. 106 // Core Audio support.
92 static bool g_audioses_dll_available = LoadAudiosesDll(); 107 static bool g_audioses_dll_available = LoadAudiosesDll();
93 return g_audioses_dll_available; 108 if (!g_audioses_dll_available)
109 return false;
110
111 // Being able to load the Audioses.dll does not seem to be sufficient for
112 // all devices to guarantee Core Audio support. To be 100%, we also verify
113 // that it is possible to a create the IMMDeviceEnumerator interface. If this
114 // works as well we should be home free.
115 static bool g_can_create_device_enumerator = CanCreateDeviceEnumerator();
116 LOG_IF(ERROR, !g_can_create_device_enumerator)
117 << "Failed to create Core Audio device enumerator on thread with ID "
118 << GetCurrentThreadId();
119 return g_can_create_device_enumerator;
94 } 120 }
95 121
96 base::TimeDelta CoreAudioUtil::RefererenceTimeToTimeDelta(REFERENCE_TIME time) { 122 base::TimeDelta CoreAudioUtil::RefererenceTimeToTimeDelta(REFERENCE_TIME time) {
97 // Each unit of reference time is 100 nanoseconds <=> 0.1 microsecond. 123 // Each unit of reference time is 100 nanoseconds <=> 0.1 microsecond.
98 return base::TimeDelta::FromMicroseconds(0.1 * time + 0.5); 124 return base::TimeDelta::FromMicroseconds(0.1 * time + 0.5);
99 } 125 }
100 126
101 AUDCLNT_SHAREMODE CoreAudioUtil::GetShareMode() { 127 AUDCLNT_SHAREMODE CoreAudioUtil::GetShareMode() {
102 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 128 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
103 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) 129 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio))
(...skipping 30 matching lines...) Expand all
134 } 160 }
135 161
136 ScopedComPtr<IMMDeviceEnumerator> CoreAudioUtil::CreateDeviceEnumerator() { 162 ScopedComPtr<IMMDeviceEnumerator> CoreAudioUtil::CreateDeviceEnumerator() {
137 DCHECK(IsSupported()); 163 DCHECK(IsSupported());
138 ScopedComPtr<IMMDeviceEnumerator> device_enumerator; 164 ScopedComPtr<IMMDeviceEnumerator> device_enumerator;
139 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), 165 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
140 NULL, 166 NULL,
141 CLSCTX_INPROC_SERVER, 167 CLSCTX_INPROC_SERVER,
142 __uuidof(IMMDeviceEnumerator), 168 __uuidof(IMMDeviceEnumerator),
143 device_enumerator.ReceiveVoid()); 169 device_enumerator.ReceiveVoid());
144 // CO_E_NOTINITIALIZED is the most likely reason for failure and if that 170 LOG_IF(ERROR, FAILED(hr)) << "IMMDeviceEnumerator::CreateDeviceEnumerator: "
145 // happens we might as well die here. 171 << std::hex << hr;
146 CHECK(SUCCEEDED(hr));
147 return device_enumerator; 172 return device_enumerator;
148 } 173 }
149 174
150 ScopedComPtr<IMMDevice> CoreAudioUtil::CreateDefaultDevice(EDataFlow data_flow, 175 ScopedComPtr<IMMDevice> CoreAudioUtil::CreateDefaultDevice(EDataFlow data_flow,
151 ERole role) { 176 ERole role) {
152 DCHECK(IsSupported()); 177 DCHECK(IsSupported());
153 ScopedComPtr<IMMDevice> endpoint_device; 178 ScopedComPtr<IMMDevice> endpoint_device;
154 179
155 // Create the IMMDeviceEnumerator interface. 180 // Create the IMMDeviceEnumerator interface.
156 ScopedComPtr<IMMDeviceEnumerator> device_enumerator = 181 ScopedComPtr<IMMDeviceEnumerator> device_enumerator =
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return false; 599 return false;
575 600
576 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to 601 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to
577 // explicitly write silence data to the rendering buffer. 602 // explicitly write silence data to the rendering buffer.
578 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; 603 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence";
579 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, 604 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill,
580 AUDCLNT_BUFFERFLAGS_SILENT)); 605 AUDCLNT_BUFFERFLAGS_SILENT));
581 } 606 }
582 607
583 } // namespace media 608 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698