| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/base/logging.h" |
| 11 #include "webrtc/base/timeutils.h" | 12 #include "webrtc/base/timeutils.h" |
| 12 #include "webrtc/modules/audio_device/audio_device_config.h" | 13 #include "webrtc/modules/audio_device/audio_device_config.h" |
| 13 #include "webrtc/modules/audio_device/win/audio_device_wave_win.h" | 14 #include "webrtc/modules/audio_device/win/audio_device_wave_win.h" |
| 14 | 15 |
| 15 #include "webrtc/system_wrappers/include/event_wrapper.h" | 16 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 16 #include "webrtc/system_wrappers/include/trace.h" | 17 #include "webrtc/system_wrappers/include/trace.h" |
| 17 | 18 |
| 18 #include <windows.h> | 19 #include <windows.h> |
| 19 #include <objbase.h> // CoTaskMemAlloc, CoTaskMemFree | 20 #include <objbase.h> // CoTaskMemAlloc, CoTaskMemFree |
| 20 #include <strsafe.h> // StringCchCopy(), StringCchCat(), StringCchPrintf() | 21 #include <strsafe.h> // StringCchCopy(), StringCchCat(), StringCchPrintf() |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 int32_t AudioDeviceWindowsWave::ActiveAudioLayer(AudioDeviceModule::AudioLayer&
audioLayer) const | 190 int32_t AudioDeviceWindowsWave::ActiveAudioLayer(AudioDeviceModule::AudioLayer&
audioLayer) const |
| 190 { | 191 { |
| 191 audioLayer = AudioDeviceModule::kWindowsWaveAudio; | 192 audioLayer = AudioDeviceModule::kWindowsWaveAudio; |
| 192 return 0; | 193 return 0; |
| 193 } | 194 } |
| 194 | 195 |
| 195 // ---------------------------------------------------------------------------- | 196 // ---------------------------------------------------------------------------- |
| 196 // Init | 197 // Init |
| 197 // ---------------------------------------------------------------------------- | 198 // ---------------------------------------------------------------------------- |
| 198 | 199 |
| 199 int32_t AudioDeviceWindowsWave::Init() | 200 AudioDeviceGeneric::InitStatus AudioDeviceWindowsWave::Init() { |
| 200 { | 201 CriticalSectionScoped lock(&_critSect); |
| 201 | 202 |
| 202 CriticalSectionScoped lock(&_critSect); | 203 if (_initialized) { |
| 204 return InitStatus::OK; |
| 205 } |
| 203 | 206 |
| 204 if (_initialized) | 207 const uint32_t nowTime(rtc::TimeMillis()); |
| 205 { | |
| 206 return 0; | |
| 207 } | |
| 208 | 208 |
| 209 const uint32_t nowTime(rtc::TimeMillis()); | 209 _recordedBytes = 0; |
| 210 _prevRecByteCheckTime = nowTime; |
| 211 _prevRecTime = nowTime; |
| 212 _prevPlayTime = nowTime; |
| 213 _prevTimerCheckTime = nowTime; |
| 210 | 214 |
| 211 _recordedBytes = 0; | 215 _playWarning = 0; |
| 212 _prevRecByteCheckTime = nowTime; | 216 _playError = 0; |
| 213 _prevRecTime = nowTime; | 217 _recWarning = 0; |
| 214 _prevPlayTime = nowTime; | 218 _recError = 0; |
| 215 _prevTimerCheckTime = nowTime; | |
| 216 | 219 |
| 217 _playWarning = 0; | 220 _mixerManager.EnumerateAll(); |
| 218 _playError = 0; | |
| 219 _recWarning = 0; | |
| 220 _recError = 0; | |
| 221 | 221 |
| 222 _mixerManager.EnumerateAll(); | 222 if (_ptrThread) { |
| 223 // thread is already created and active |
| 224 return InitStatus::OK; |
| 225 } |
| 223 | 226 |
| 224 if (_ptrThread) | 227 const char* threadName = "webrtc_audio_module_thread"; |
| 225 { | 228 _ptrThread.reset(new rtc::PlatformThread(ThreadFunc, this, threadName)); |
| 226 // thread is already created and active | 229 _ptrThread->Start(); |
| 227 return 0; | 230 _ptrThread->SetPriority(rtc::kRealtimePriority); |
| 228 } | |
| 229 | 231 |
| 230 const char* threadName = "webrtc_audio_module_thread"; | 232 const bool periodic(true); |
| 231 _ptrThread.reset(new rtc::PlatformThread(ThreadFunc, this, threadName)); | 233 if (!_timeEvent.StartTimer(periodic, TIMER_PERIOD_MS)) { |
| 232 _ptrThread->Start(); | 234 LOG(LS_ERROR) << "failed to start the timer event"; |
| 233 _ptrThread->SetPriority(rtc::kRealtimePriority); | 235 _ptrThread->Stop(); |
| 236 _ptrThread.reset(); |
| 237 return InitStatus::OTHER_ERROR; |
| 238 } |
| 239 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 240 "periodic timer (dT=%d) is now active", TIMER_PERIOD_MS); |
| 234 | 241 |
| 235 const bool periodic(true); | 242 _hGetCaptureVolumeThread = |
| 236 if (!_timeEvent.StartTimer(periodic, TIMER_PERIOD_MS)) | 243 CreateThread(NULL, 0, GetCaptureVolumeThread, this, 0, NULL); |
| 237 { | 244 if (_hGetCaptureVolumeThread == NULL) { |
| 238 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, | 245 LOG(LS_ERROR) << " failed to create the volume getter thread"; |
| 239 "failed to start the timer event"); | 246 return InitStatus::OTHER_ERROR; |
| 240 _ptrThread->Stop(); | 247 } |
| 241 _ptrThread.reset(); | |
| 242 return -1; | |
| 243 } | |
| 244 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | |
| 245 "periodic timer (dT=%d) is now active", TIMER_PERIOD_MS); | |
| 246 | 248 |
| 247 _hGetCaptureVolumeThread = | 249 SetThreadPriority(_hGetCaptureVolumeThread, THREAD_PRIORITY_NORMAL); |
| 248 CreateThread(NULL, 0, GetCaptureVolumeThread, this, 0, NULL); | |
| 249 if (_hGetCaptureVolumeThread == NULL) | |
| 250 { | |
| 251 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | |
| 252 " failed to create the volume getter thread"); | |
| 253 return -1; | |
| 254 } | |
| 255 | 250 |
| 256 SetThreadPriority(_hGetCaptureVolumeThread, THREAD_PRIORITY_NORMAL); | 251 _hSetCaptureVolumeThread = |
| 252 CreateThread(NULL, 0, SetCaptureVolumeThread, this, 0, NULL); |
| 253 if (_hSetCaptureVolumeThread == NULL) { |
| 254 LOG(LS_ERROR) << " failed to create the volume setter thread"; |
| 255 return InitStatus::OTHER_ERROR; |
| 256 } |
| 257 | 257 |
| 258 _hSetCaptureVolumeThread = | 258 SetThreadPriority(_hSetCaptureVolumeThread, THREAD_PRIORITY_NORMAL); |
| 259 CreateThread(NULL, 0, SetCaptureVolumeThread, this, 0, NULL); | |
| 260 if (_hSetCaptureVolumeThread == NULL) | |
| 261 { | |
| 262 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | |
| 263 " failed to create the volume setter thread"); | |
| 264 return -1; | |
| 265 } | |
| 266 | 259 |
| 267 SetThreadPriority(_hSetCaptureVolumeThread, THREAD_PRIORITY_NORMAL); | 260 _initialized = true; |
| 268 | 261 |
| 269 _initialized = true; | 262 return InitStatus::OK; |
| 270 | |
| 271 return 0; | |
| 272 } | 263 } |
| 273 | 264 |
| 274 // ---------------------------------------------------------------------------- | 265 // ---------------------------------------------------------------------------- |
| 275 // Terminate | 266 // Terminate |
| 276 // ---------------------------------------------------------------------------- | 267 // ---------------------------------------------------------------------------- |
| 277 | 268 |
| 278 int32_t AudioDeviceWindowsWave::Terminate() | 269 int32_t AudioDeviceWindowsWave::Terminate() |
| 279 { | 270 { |
| 280 | 271 |
| 281 if (!_initialized) | 272 if (!_initialized) |
| (...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3723 bool AudioDeviceWindowsWave::KeyPressed() const{ | 3714 bool AudioDeviceWindowsWave::KeyPressed() const{ |
| 3724 | 3715 |
| 3725 int key_down = 0; | 3716 int key_down = 0; |
| 3726 for (int key = VK_SPACE; key < VK_NUMLOCK; key++) { | 3717 for (int key = VK_SPACE; key < VK_NUMLOCK; key++) { |
| 3727 short res = GetAsyncKeyState(key); | 3718 short res = GetAsyncKeyState(key); |
| 3728 key_down |= res & 0x1; // Get the LSB | 3719 key_down |= res & 0x1; // Get the LSB |
| 3729 } | 3720 } |
| 3730 return (key_down > 0); | 3721 return (key_down > 0); |
| 3731 } | 3722 } |
| 3732 } // namespace webrtc | 3723 } // namespace webrtc |
| OLD | NEW |