2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_device/win/audio_device_utility_win.h"
13 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
14 #include "webrtc/system_wrappers/interface/trace.h"
20 #define STRING_MAX_SIZE 256
22 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
23 typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
28 // ============================================================================
29 // Construction & Destruction
30 // ============================================================================
32 // ----------------------------------------------------------------------------
33 // AudioDeviceUtilityWindows() - ctor
34 // ----------------------------------------------------------------------------
36 AudioDeviceUtilityWindows::AudioDeviceUtilityWindows(const int32_t id) :
37 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
39 _lastError(AudioDeviceModule::kAdmErrNone)
41 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
44 // ----------------------------------------------------------------------------
45 // AudioDeviceUtilityWindows() - dtor
46 // ----------------------------------------------------------------------------
48 AudioDeviceUtilityWindows::~AudioDeviceUtilityWindows()
50 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
52 CriticalSectionScoped lock(&_critSect);
60 // ============================================================================
62 // ============================================================================
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 int32_t AudioDeviceUtilityWindows::Init()
71 TCHAR szOS[STRING_MAX_SIZE];
73 if (GetOSDisplayString(szOS))
76 char os[STRING_MAX_SIZE];
77 if (WideCharToMultiByte(CP_UTF8, 0, szOS, -1, os, STRING_MAX_SIZE, NULL, NULL) == 0)
79 strncpy(os, "Could not get OS info", STRING_MAX_SIZE);
81 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, " OS info: %s", os);
83 WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, " OS info: %s", szOS);
90 // ============================================================================
92 // ============================================================================
94 BOOL AudioDeviceUtilityWindows::GetOSDisplayString(LPTSTR pszOS)
99 BOOL bOsVersionInfoEx;
101 ZeroMemory(&si, sizeof(SYSTEM_INFO));
102 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
104 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
106 // Retrieve information about the current operating system
108 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi);
109 if (!bOsVersionInfoEx)
112 // Parse our OS version string
114 if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4)
116 StringCchCopy(pszOS, STRING_MAX_SIZE, TEXT("Microsoft "));
118 // Test for the specific product
120 // Operating system Version number
121 // --------------------------------------
123 // Windows Server 2008 R2 6.1
124 // Windows Server 2008 6.0
126 // - - - - - - - - - - - - - - - - - - -
127 // Windows Server 2003 R2 5.2
128 // Windows Server 2003 5.2
132 // see http://msdn.microsoft.com/en-us/library/ms724832(VS.85).aspx for details
134 if (osvi.dwMajorVersion == 6)
136 if (osvi.dwMinorVersion == 0)
138 // Windows Vista or Server 2008
139 if (osvi.wProductType == VER_NT_WORKSTATION)
140 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Vista "));
142 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2008 " ));
145 if (osvi.dwMinorVersion == 1)
147 // Windows 7 or Server 2008 R2
148 if (osvi.wProductType == VER_NT_WORKSTATION)
149 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows 7 "));
151 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2008 R2 " ));
155 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
157 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2003"));
160 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
162 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows XP "));
163 if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
164 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Home Edition" ));
166 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Professional" ));
169 if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
171 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows 2000 "));
173 if (osvi.wProductType == VER_NT_WORKSTATION )
175 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Professional" ));
179 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
180 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Datacenter Server" ));
181 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
182 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Advanced Server" ));
183 else StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Server" ));
187 // Include service pack (if any)
189 if (_tcslen(osvi.szCSDVersion) > 0)
191 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT(" "));
192 StringCchCat(pszOS, STRING_MAX_SIZE, osvi.szCSDVersion);
197 // Include build number
199 StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
200 StringCchCat(pszOS, STRING_MAX_SIZE, buf);
202 // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise
204 pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
210 // Add 64-bit or 32-bit for OS versions "later than" Vista
212 if (osvi.dwMajorVersion >= 6)
214 if ((si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ||
215 (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64))
216 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( ", 64-bit" ));
217 else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL )
218 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT(", 32-bit"));
229 } // namespace webrtc