| 6 |
| 7 | #include "AudioInputWASAPI.h" |
| 8 | #include "../../VoIPController.h" |
| 9 | #include "../../logging.h" |
| 10 | #include <cassert> |
| 11 |
| 12 | #define BUFFER_SIZE 960 |
| 13 | #define CHECK_RES(res, msg) \ |
| 14 | { \ |
| 15 | if (FAILED(res)) \ |
| 16 | { \ |
| 17 | LOGE("%s failed: HRESULT=0x%08X", msg, res); \ |
| 18 | failed = true; \ |
| 19 | return; \ |
| 20 | } \ |
| 21 | } |
| 22 | #define SCHECK_RES(res, msg) \ |
| 23 | { \ |
| 24 | if (FAILED(res)) \ |
| 25 | { \ |
| 26 | LOGE("%s failed: HRESULT=0x%08X", msg, res); \ |
| 27 | return; \ |
| 28 | } \ |
| 29 | } |
| 30 |
| 31 | template <class T> |
| 32 | void SafeRelease(T** ppT) |
| 33 | { |
| 34 | if (*ppT) |
| 35 | { |
| 36 | (*ppT)->Release(); |
| 37 | *ppT = nullptr; |
| 38 | } |
| 39 | } |
| 40 |
| 41 | using namespace tgvoip::audio; |
| 42 |
| 43 | AudioInputWASAPI::AudioInputWASAPI(std::string deviceID) |
| 44 | { |
| 45 | isRecording = false; |
| 46 | remainingDataLen = 0; |
| 47 | refCount = 1; |
| 48 | HRESULT res; |
| 49 | res = CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
| 50 | if (FAILED(res) && res != RPC_E_CHANGED_MODE) |
| 51 | { |
| 52 | CHECK_RES(res, "CoInitializeEx"); |
| 53 | } |
| 54 | #ifdef TGVOIP_WINXP_COMPAT |
| 55 | HANDLE(WINAPI * __CreateEventExA) |
| 56 | (LPSECURITY_ATTRIBUTES lpEventAttributes, LPCSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess); |
| 57 | __CreateEventExA = (HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES, LPCSTR, DWORD, DWORD))GetProcAddress(GetModuleHandleA("kernel32.dll"), "CreateEventExA"); |
| 58 | #undef CreateEventEx |
| 59 | #define CreateEventEx __CreateEventExA |
| 60 | #endif |
| 61 | shutdownEvent = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); |
| 62 | audioSamplesReadyEvent = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); |
| 63 | streamSwitchEvent = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); |
| 64 | ZeroMemory(&format, sizeof(format)); |
| 65 | format.wFormatTag = WAVE_FORMAT_PCM; |
| 66 | format.nChannels = 1; |
| 67 | format.nSamplesPerSec = 48000; |
| 68 | format.nBlockAlign = 2; |
| 69 | format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; |
| 70 | format.wBitsPerSample = 16; |
| 71 |
| 72 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 73 | res = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&enumerator)); |
| 74 | CHECK_RES(res, "CoCreateInstance(MMDeviceEnumerator)"); |
| 75 | res = enumerator->RegisterEndpointNotificationCallback(this); |
| 76 | CHECK_RES(res, "enumerator->RegisterEndpointNotificationCallback"); |
| 77 | audioSessionControl = nullptr; |
| 78 | device = nullptr; |
| 79 | #endif |
| 80 |
| 81 | audioClient = nullptr; |
| 82 | captureClient = nullptr; |
| 83 | thread = nullptr; |
| 84 | started = false; |
| 85 |
| 86 | SetCurrentDevice(deviceID); |
| 87 | } |
| 88 |
| 89 | AudioInputWASAPI::~AudioInputWASAPI() |
| 90 | { |
| 91 | if (audioClient && started) |
| 92 | { |
| 93 | audioClient->Stop(); |
| 94 | } |
| 95 |
| 96 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 97 | if (audioSessionControl) |
| 98 | { |
| 99 | audioSessionControl->UnregisterAudioSessionNotification(this); |
| 100 | } |
| 101 | #endif |
| 102 |
| 103 | SetEvent(shutdownEvent); |
| 104 | if (thread) |
| 105 | { |
| 106 | WaitForSingleObjectEx(thread, INFINITE, false); |
| 107 | CloseHandle(thread); |
| 108 | } |
| 109 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 110 | SafeRelease(&audioSessionControl); |
| 111 | #endif |
| 112 | SafeRelease(&captureClient); |
| 113 | SafeRelease(&audioClient); |
| 114 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 115 | SafeRelease(&device); |
| 116 | #endif |
| 117 | CloseHandle(shutdownEvent); |
| 118 | CloseHandle(audioSamplesReadyEvent); |
| 119 | CloseHandle(streamSwitchEvent); |
| 120 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 121 | if (enumerator) |
| 122 | enumerator->UnregisterEndpointNotificationCallback(this); |
| 123 | SafeRelease(&enumerator); |
| 124 | #endif |
| 125 | } |
| 126 | void AudioInputWASAPI::Start() |
| 127 | { |
| 128 | isRecording = true; |
| 129 | if (!thread) |
| 130 | { |
| 131 | thread = CreateThread(nullptr, 0, AudioInputWASAPI::StartThread, this, 0, nullptr); |
| 132 | } |
| 133 |
| 134 | if (audioClient && !started) |
| 135 | { |
| 136 | LOGI("audioClient->Start"); |
| 137 | audioClient->Start(); |
| 138 | started = true; |
| 139 | } |
| 140 | } |
| 141 |
| 142 | void AudioInputWASAPI::Stop() |
| 143 | { |
| 144 | isRecording = false; |
| 145 | } |
| 146 |
| 147 | bool AudioInputWASAPI::IsRecording() |
| 148 | { |
| 149 | return isRecording; |
| 150 | } |
| 151 |
| 152 | void AudioInputWASAPI::EnumerateDevices(std::vector<tgvoip::AudioInputDevice>& devs) |
| 153 | { |
| 154 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 155 | HRESULT res; |
| 156 | res = CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
| 157 | if (FAILED(res) && res != RPC_E_CHANGED_MODE) |
| 158 | { |
| 159 | SCHECK_RES(res, "CoInitializeEx"); |
| 160 | } |
| 161 |
| 162 | IMMDeviceEnumerator* deviceEnumerator = nullptr; |
| 163 | IMMDeviceCollection* deviceCollection = nullptr; |
| 164 |
| 165 | res = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&deviceEnumerator)); |
| 166 | SCHECK_RES(res, "CoCreateInstance(MMDeviceEnumerator)"); |
| 167 |
| 168 | res = deviceEnumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &deviceCollection); |
| 169 | SCHECK_RES(res, "EnumAudioEndpoints"); |
| 170 |
| 171 | UINT devCount; |
| 172 | res = deviceCollection->GetCount(&devCount); |
| 173 | SCHECK_RES(res, "GetCount"); |
| 174 |
| 175 | for (UINT i = 0; i < devCount; i++) |
| 176 | { |
| 177 | IMMDevice* device; |
| 178 | res = deviceCollection->Item(i, &device); |
| 179 | SCHECK_RES(res, "GetDeviceItem"); |
| 180 | wchar_t* devID; |
| 181 | res = device->GetId(&devID); |
| 182 | SCHECK_RES(res, "get device id"); |
| 183 |
| 184 | IPropertyStore* propStore; |
| 185 | res = device->OpenPropertyStore(STGM_READ, &propStore); |
| 186 | SafeRelease(&device); |
| 187 | SCHECK_RES(res, "OpenPropertyStore"); |
| 188 |
| 189 | PROPVARIANT friendlyName; |
| 190 | PropVariantInit(&friendlyName); |
| 191 | res = propStore->GetValue(PKEY_Device_FriendlyName, &friendlyName); |
| 192 | SafeRelease(&propStore); |
| 193 |
| 194 | AudioInputDevice dev; |
| 195 |
| 196 | wchar_t actualFriendlyName[128]; |
| 197 | if (friendlyName.vt == VT_LPWSTR) |
| 198 | { |
| 199 | wcsncpy(actualFriendlyName, friendlyName.pwszVal, sizeof(actualFriendlyName) / sizeof(wchar_t)); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | wcscpy(actualFriendlyName, L"Unknown"); |
| 204 | } |
| 205 | PropVariantClear(&friendlyName); |
| 206 |
| 207 | char buf[256]; |
| 208 | WideCharToMultiByte(CP_UTF8, 0, devID, -1, buf, sizeof(buf), nullptr, nullptr); |
| 209 | dev.id = buf; |
| 210 | WideCharToMultiByte(CP_UTF8, 0, actualFriendlyName, -1, buf, sizeof(buf), nullptr, nullptr); |
| 211 | dev.displayName = buf; |
| 212 | devs.emplace_back(dev); |
| 213 |
| 214 | CoTaskMemFree(devID); |
| 215 | } |
| 216 |
| 217 | SafeRelease(&deviceCollection); |
| 218 | SafeRelease(&deviceEnumerator); |
| 219 | #endif |
| 220 | } |
| 221 |
| 222 | void AudioInputWASAPI::SetCurrentDevice(std::string deviceID) |
| 223 | { |
| 224 | if (thread) |
| 225 | { |
| 226 | streamChangeToDevice = deviceID; |
| 227 | SetEvent(streamSwitchEvent); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | ActuallySetCurrentDevice(deviceID); |
| 232 | } |
| 233 | } |
| 234 |
| 235 | void AudioInputWASAPI::ActuallySetCurrentDevice(std::string deviceID) |
| 236 | { |
| 237 | m_currentDevice = deviceID; |
| 238 | HRESULT res; |
| 239 |
| 240 | if (audioClient) |
| 241 | { |
| 242 | res = audioClient->Stop(); |
| 243 | CHECK_RES(res, "audioClient->Stop"); |
| 244 | } |
| 245 |
| 246 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 247 | if (audioSessionControl) |
| 248 | { |
| 249 | res = audioSessionControl->UnregisterAudioSessionNotification(this); |
| 250 | CHECK_RES(res, "audioSessionControl->UnregisterAudioSessionNotification"); |
| 251 | } |
| 252 |
| 253 | SafeRelease(&audioSessionControl); |
| 254 | #endif |
| 255 | SafeRelease(&captureClient); |
| 256 | SafeRelease(&audioClient); |
| 257 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 258 | SafeRelease(&device); |
| 259 |
| 260 | IMMDeviceCollection* deviceCollection = nullptr; |
| 261 |
| 262 | if (deviceID == "default") |
| 263 | { |
| 264 | isDefaultDevice = true; |
| 265 | res = enumerator->GetDefaultAudioEndpoint(eCapture, eCommunications, &device); |
| 266 | CHECK_RES(res, "GetDefaultAudioEndpoint"); |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | isDefaultDevice = false; |
| 271 | res = enumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &deviceCollection); |
| 272 | CHECK_RES(res, "EnumAudioEndpoints"); |
| 273 |
| 274 | UINT devCount; |
| 275 | res = deviceCollection->GetCount(&devCount); |
| 276 | CHECK_RES(res, "GetCount"); |
| 277 |
| 278 | for (UINT i = 0; i < devCount; i++) |
| 279 | { |
| 280 | IMMDevice* device; |
| 281 | res = deviceCollection->Item(i, &device); |
| 282 | CHECK_RES(res, "GetDeviceItem"); |
| 283 | wchar_t* _devID; |
| 284 | res = device->GetId(&_devID); |
| 285 | CHECK_RES(res, "get device id"); |
| 286 |
| 287 | char devID[128]; |
| 288 | WideCharToMultiByte(CP_UTF8, 0, _devID, -1, devID, 128, nullptr, nullptr); |
| 289 |
| 290 | CoTaskMemFree(_devID); |
| 291 | if (deviceID == devID) |
| 292 | { |
| 293 | this->device = device; |
| 294 | //device->AddRef(); |
| 295 | break; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 |
| 300 | if (deviceCollection) |
| 301 | SafeRelease(&deviceCollection); |
| 302 |
| 303 | if (!device) |
| 304 | { |
| 305 | LOGE("Didn't find capture device; failing"); |
| 306 | m_failed = true; |
| 307 | return; |
| 308 | } |
| 309 |
| 310 | res = device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, nullptr, (void**)&audioClient); |
| 311 | CHECK_RES(res, "device->Activate"); |
| 312 | #else |
| 313 | std::wstring devID; |
| 314 |
| 315 | if (deviceID == "default") |
| 316 | { |
| 317 | Platform::String ^ defaultDevID = Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Communications); |
| 318 | if (defaultDevID == nullptr) |
| 319 | { |
| 320 | LOGE("Didn't find capture device; failing"); |
| 321 | failed = true; |
| 322 | return; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | isDefaultDevice = true; |
| 327 | devID = defaultDevID->Data(); |
| 328 | } |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | int wchars_num = MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, nullptr, 0); |
| 333 | wchar_t* wstr = new wchar_t[wchars_num]; |
| 334 | MultiByteToWideChar(CP_UTF8, 0, deviceID.c_str(), -1, wstr, wchars_num); |
| 335 | devID = wstr; |
| 336 | } |
| 337 |
| 338 | HRESULT res1, res2; |
| 339 | IAudioClient2* audioClient2 = WindowsSandboxUtils::ActivateAudioDevice(devID.c_str(), &res1, &res2); |
| 340 | CHECK_RES(res1, "activate1"); |
| 341 | CHECK_RES(res2, "activate2"); |
| 342 |
| 343 | AudioClientProperties properties = {}; |
| 344 | properties.cbSize = sizeof AudioClientProperties; |
| 345 | properties.eCategory = AudioCategory_Communications; |
| 346 | res = audioClient2->SetClientProperties(&properties); |
| 347 | CHECK_RES(res, "audioClient2->SetClientProperties"); |
| 348 |
| 349 | audioClient = audioClient2; |
| 350 | #endif |
| 351 |
| 352 | // {2C693079-3F59-49FD-964F-61C005EAA5D3} |
| 353 | const GUID guid = {0x2c693079, 0x3f59, 0x49fd, {0x96, 0x4f, 0x61, 0xc0, 0x5, 0xea, 0xa5, 0xd3}}; |
| 354 | // Use 1000ms buffer to avoid resampling glitches on Windows 8.1 and older. This should not increase latency. |
| 355 | res = audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_NOPERSIST | AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY, 1000 * 10000, 0, &format, &guid); |
| 356 | CHECK_RES(res, "audioClient->Initialize"); |
| 357 |
| 358 | std::uint32_t bufSize; |
| 359 | res = audioClient->GetBufferSize(&bufSize); |
| 360 | CHECK_RES(res, "audioClient->GetBufferSize"); |
| 361 |
| 362 | LOGV("buffer size: %u", bufSize); |
| 363 | m_estimatedDelay = 0; |
| 364 | REFERENCE_TIME latency, devicePeriod; |
| 365 | if (SUCCEEDED(audioClient->GetStreamLatency(&latency))) |
| 366 | { |
| 367 | if (SUCCEEDED(audioClient->GetDevicePeriod(&devicePeriod, nullptr))) |
| 368 | { |
| 369 | m_estimatedDelay = (std::int32_t)(latency / 10000 + devicePeriod / 10000); |
| 370 | } |
| 371 | } |
| 372 |
| 373 | res = audioClient->SetEventHandle(audioSamplesReadyEvent); |
| 374 | CHECK_RES(res, "audioClient->SetEventHandle"); |
| 375 |
| 376 | res = audioClient->GetService(IID_PPV_ARGS(&captureClient)); |
| 377 | CHECK_RES(res, "audioClient->GetService"); |
| 378 |
| 379 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 380 | res = audioClient->GetService(IID_PPV_ARGS(&audioSessionControl)); |
| 381 | CHECK_RES(res, "audioClient->GetService(IAudioSessionControl)"); |
| 382 |
| 383 | res = audioSessionControl->RegisterAudioSessionNotification(this); |
| 384 | CHECK_RES(res, "audioSessionControl->RegisterAudioSessionNotification"); |
| 385 | #endif |
| 386 |
| 387 | if (isRecording) |
| 388 | audioClient->Start(); |
| 389 |
| 390 | LOGV("set current input device done"); |
| 391 | } |
| 392 |
| 393 | DWORD WINAPI AudioInputWASAPI::StartThread(void* arg) |
| 394 | { |
| 395 | LOGV("WASAPI capture thread starting"); |
| 396 | ((AudioInputWASAPI*)arg)->RunThread(); |
| 397 | return 0; |
| 398 | } |
| 399 |
| 400 | void AudioInputWASAPI::RunThread() |
| 401 | { |
| 402 | if (m_failed) |
| 403 | return; |
| 404 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); |
| 405 |
| 406 | HANDLE waitArray[] = {shutdownEvent, streamSwitchEvent, audioSamplesReadyEvent}; |
| 407 | HRESULT res = CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
| 408 | CHECK_RES(res, "CoInitializeEx in capture thread"); |
| 409 |
| 410 | std::uint32_t bufferSize = 0; |
| 411 | std::uint64_t framesWritten = 0; |
| 412 |
| 413 | bool running = true; |
| 414 | //double prevCallback=VoIPController::GetCurrentTime(); |
| 415 |
| 416 | while (running) |
| 417 | { |
| 418 | DWORD waitResult = WaitForMultipleObjectsEx(3, waitArray, false, INFINITE, false); |
| 419 | if (waitResult == WAIT_OBJECT_0) |
| 420 | { // shutdownEvent |
| 421 | LOGV("capture thread shutting down"); |
| 422 | running = false; |
| 423 | } |
| 424 | else if (waitResult == WAIT_OBJECT_0 + 1) |
| 425 | { // streamSwitchEvent |
| 426 | LOGV("stream switch"); |
| 427 | ActuallySetCurrentDevice(streamChangeToDevice); |
| 428 | ResetEvent(streamSwitchEvent); |
| 429 | bufferSize = 0; |
| 430 | LOGV("stream switch done"); |
| 431 | } |
| 432 | else if (waitResult == WAIT_OBJECT_0 + 2) |
| 433 | { // audioSamplesReadyEvent |
| 434 | if (!audioClient) |
| 435 | continue; |
| 436 | res = captureClient->GetNextPacketSize(&bufferSize); |
| 437 | CHECK_RES(res, "captureClient->GetNextPacketSize"); |
| 438 | BYTE* data; |
| 439 | std::uint32_t framesAvailable = 0; |
| 440 | DWORD flags; |
| 441 |
| 442 | res = captureClient->GetBuffer(&data, &framesAvailable, &flags, nullptr, nullptr); |
| 443 | CHECK_RES(res, "captureClient->GetBuffer"); |
| 444 | std::size_t dataLen = framesAvailable * 2; |
| 445 | assert(remainingDataLen + dataLen < sizeof(remainingData)); |
| 446 |
| 447 | if (flags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) |
| 448 | { |
| 449 | LOGW("Audio capture data discontinuity"); |
| 450 | } |
| 451 |
| 452 | //double t=VoIPController::GetCurrentTime(); |
| 453 | //LOGV("audio capture: %u, time %f, flags %u", framesAvailable, t-prevCallback, flags); |
| 454 | //prevCallback=t; |
| 455 |
| 456 | std::memcpy(remainingData + remainingDataLen, data, dataLen); |
| 457 | remainingDataLen += dataLen; |
| 458 | while (remainingDataLen > 960 * 2) |
| 459 | { |
| 460 | if (isRecording) |
| 461 | InvokeCallback(remainingData, 960 * 2); |
| 462 |
| 463 | //LOGV("remaining data len %u", remainingDataLen); |
| 464 | memmove(remainingData, remainingData + (960 * 2), remainingDataLen - 960 * 2); |
| 465 | remainingDataLen -= 960 * 2; |
| 466 | } |
| 467 |
| 468 | res = captureClient->ReleaseBuffer(framesAvailable); |
| 469 | CHECK_RES(res, "captureClient->ReleaseBuffer"); |
| 470 | //estimatedDelay=(std::int32_t)((devicePosition-framesWritten)/48); |
| 471 |
| 472 | framesWritten += framesAvailable; |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 |
| 477 | #ifdef TGVOIP_WINDOWS_DESKTOP |
| 478 | HRESULT AudioInputWASAPI::OnSessionDisconnected(AudioSessionDisconnectReason reason) |
| 479 | { |
| 480 | if (!isDefaultDevice) |
| 481 | { |
| 482 | streamChangeToDevice = "default"; |
| 483 | SetEvent(streamSwitchEvent); |
| 484 | } |
| 485 | return S_OK; |
| 486 | } |
| 487 |
| 488 | HRESULT AudioInputWASAPI::OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR newDevID) |
| 489 | { |
| 490 | if (flow == eCapture && role == eCommunications && isDefaultDevice) |
| 491 | { |
| 492 | streamChangeToDevice = "default"; |
| 493 | SetEvent(streamSwitchEvent); |
| 494 | } |
| 495 | return S_OK; |
| 496 | } |
| 497 |
| 498 | ULONG AudioInputWASAPI::AddRef() |
| 499 | { |
| 500 | return InterlockedIncrement(&refCount); |
| 501 | } |
| 502 |
| 503 | ULONG AudioInputWASAPI::Release() |
| 504 | { |
| 505 | return InterlockedDecrement(&refCount); |
| 506 | } |
| 507 |
| 508 | HRESULT AudioInputWASAPI::QueryInterface(REFIID iid, void** obj) |
| 509 | { |
| 510 | if (!obj) |
| 511 | { |
| 512 | return E_POINTER; |
| 513 | } |
| 514 | *obj = nullptr; |
| 515 |
| 516 | if (iid == IID_IUnknown) |
| 517 | { |
| 518 | *obj = static_cast<IUnknown*>(static_cast<IAudioSessionEvents*>(this)); |
| 519 | AddRef(); |
| 520 | } |
| 521 | else if (iid == __uuidof(IMMNotificationClient)) |
| 522 | { |
| 523 | *obj = static_cast<IMMNotificationClient*>(this); |
| 524 | AddRef(); |
| 525 | } |
| 526 | else if (iid == __uuidof(IAudioSessionEvents)) |
| 527 | { |
| 528 | *obj = static_cast<IAudioSessionEvents*>(this); |
| 529 | AddRef(); |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | return E_NOINTERFACE; |
| 534 | } |
| 535 |
| 536 | return S_OK; |
| 537 | } |
| 538 | #endif |
| 539 |