• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10 
11 #include "webrtc/modules/audio_device/win/audio_device_utility_win.h"
12 
13 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
14 #include "webrtc/system_wrappers/interface/trace.h"
15 
16 #include <windows.h>
17 #include <tchar.h>
18 #include <strsafe.h>
19 
20 #define STRING_MAX_SIZE 256
21 
22 typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
23 typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
24 
25 namespace webrtc
26 {
27 
28 // ============================================================================
29 //                            Construction & Destruction
30 // ============================================================================
31 
32 // ----------------------------------------------------------------------------
33 //  AudioDeviceUtilityWindows() - ctor
34 // ----------------------------------------------------------------------------
35 
AudioDeviceUtilityWindows(const int32_t id)36 AudioDeviceUtilityWindows::AudioDeviceUtilityWindows(const int32_t id) :
37     _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
38     _id(id),
39     _lastError(AudioDeviceModule::kAdmErrNone)
40 {
41     WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
42 }
43 
44 // ----------------------------------------------------------------------------
45 //  AudioDeviceUtilityWindows() - dtor
46 // ----------------------------------------------------------------------------
47 
~AudioDeviceUtilityWindows()48 AudioDeviceUtilityWindows::~AudioDeviceUtilityWindows()
49 {
50     WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
51     {
52         CriticalSectionScoped lock(&_critSect);
53 
54         // free stuff here...
55     }
56 
57     delete &_critSect;
58 }
59 
60 // ============================================================================
61 //                                     API
62 // ============================================================================
63 
64 // ----------------------------------------------------------------------------
65 //  Init()
66 // ----------------------------------------------------------------------------
67 
Init()68 int32_t AudioDeviceUtilityWindows::Init()
69 {
70 
71     TCHAR szOS[STRING_MAX_SIZE];
72 
73     if (GetOSDisplayString(szOS))
74     {
75 #ifdef _UNICODE
76         char os[STRING_MAX_SIZE];
77         if (WideCharToMultiByte(CP_UTF8, 0, szOS, -1, os, STRING_MAX_SIZE, NULL, NULL) == 0)
78         {
79             strncpy(os, "Could not get OS info", STRING_MAX_SIZE);
80         }
81         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "  OS info: %s", os);
82 #else
83         WEBRTC_TRACE(kTraceStateInfo, kTraceAudioDevice, _id, "  OS info: %s", szOS);
84 #endif
85     }
86 
87     return 0;
88 }
89 
90 // ============================================================================
91 //                                 Private Methods
92 // ============================================================================
93 
GetOSDisplayString(LPTSTR pszOS)94 BOOL AudioDeviceUtilityWindows::GetOSDisplayString(LPTSTR pszOS)
95 {
96     OSVERSIONINFOEX osvi;
97     SYSTEM_INFO si;
98     PGNSI pGNSI;
99     BOOL bOsVersionInfoEx;
100 
101     ZeroMemory(&si, sizeof(SYSTEM_INFO));
102     ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
103 
104     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
105 
106     // Retrieve information about the current operating system
107     //
108     if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi)))
109         return FALSE;
110 
111     // Parse our OS version string
112     //
113     if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4)
114     {
115         StringCchCopy(pszOS, STRING_MAX_SIZE, TEXT("Microsoft "));
116 
117         // Test for the specific product
118         //
119         //  Operating system	    Version number
120         //  --------------------------------------
121         //  Windows 7	            6.1
122         //  Windows Server 2008 R2	6.1
123         //  Windows Server 2008	    6.0
124         //  Windows Vista	        6.0
125         //  - - - - - - - - - - - - - - - - - - -
126         //  Windows Server 2003 R2	5.2
127         //  Windows Server 2003	    5.2
128         //  Windows XP	            5.1
129         //  Windows 2000	        5.0
130         //
131         //  see http://msdn.microsoft.com/en-us/library/ms724832(VS.85).aspx for details
132         //
133         if (osvi.dwMajorVersion == 6)
134         {
135             if (osvi.dwMinorVersion == 0)
136             {
137                 // Windows Vista or Server 2008
138                 if (osvi.wProductType == VER_NT_WORKSTATION)
139                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Vista "));
140                 else
141                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2008 " ));
142             }
143 
144             if (osvi.dwMinorVersion == 1)
145             {
146                 // Windows 7 or Server 2008 R2
147                 if (osvi.wProductType == VER_NT_WORKSTATION)
148                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows 7 "));
149                 else
150                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2008 R2 " ));
151             }
152         }
153 
154         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
155         {
156             StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows Server 2003"));
157         }
158 
159         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
160         {
161             StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows XP "));
162             if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
163                 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Home Edition" ));
164             else
165                 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Professional" ));
166         }
167 
168         if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
169         {
170             StringCchCat(pszOS, STRING_MAX_SIZE, TEXT("Windows 2000 "));
171 
172             if (osvi.wProductType == VER_NT_WORKSTATION )
173             {
174                 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Professional" ));
175             }
176             else
177             {
178                 if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
179                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Datacenter Server" ));
180                 else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
181                     StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Advanced Server" ));
182                 else StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( "Server" ));
183             }
184         }
185 
186         // Include service pack (if any)
187         //
188         if (_tcslen(osvi.szCSDVersion) > 0)
189         {
190             StringCchCat(pszOS, STRING_MAX_SIZE, TEXT(" "));
191             StringCchCat(pszOS, STRING_MAX_SIZE, osvi.szCSDVersion);
192         }
193 
194         TCHAR buf[80];
195 
196         // Include build number
197         //
198         StringCchPrintf( buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
199         StringCchCat(pszOS, STRING_MAX_SIZE, buf);
200 
201         // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise
202         //
203         pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
204         if (NULL != pGNSI)
205             pGNSI(&si);
206         else
207             GetSystemInfo(&si);
208 
209         // Add 64-bit or 32-bit for OS versions "later than" Vista
210         //
211         if (osvi.dwMajorVersion >= 6)
212         {
213             if ((si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ||
214                 (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64))
215                 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT( ", 64-bit" ));
216             else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL )
217                 StringCchCat(pszOS, STRING_MAX_SIZE, TEXT(", 32-bit"));
218         }
219 
220         return TRUE;
221     }
222     else
223     {
224         return FALSE;
225    }
226 }
227 
228 }  // namespace webrtc
229