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