Changeset 89504 in vbox for trunk/src/VBox/Devices/Audio/DrvHostAudioWasApi.cpp
- Timestamp:
- Jun 4, 2021 11:30:46 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioWasApi.cpp
r89500 r89504 2375 2375 2376 2376 /** 2377 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable} 2378 */ 2379 static DECLCALLBACK(uint32_t) drvHostAudioWasHA_StreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream) 2377 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetState} 2378 */ 2379 static DECLCALLBACK(PDMHOSTAUDIOSTREAMSTATE) drvHostAudioWasHA_StreamGetState(PPDMIHOSTAUDIO pInterface, 2380 PPDMAUDIOBACKENDSTREAM pStream) 2380 2381 { 2381 2382 RT_NOREF(pInterface); 2382 2383 PDRVHOSTAUDIOWASSTREAM pStreamWas = (PDRVHOSTAUDIOWASSTREAM)pStream; 2383 AssertPtrReturn(pStreamWas, 0); 2384 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_IN); 2385 2386 uint32_t cbReadable = 0; 2387 RTCritSectEnter(&pStreamWas->CritSect); 2388 2389 if (pStreamWas->pDevCfg->pIAudioCaptureClient /* paranoia */) 2390 { 2391 UINT32 cFramesPending = 0; 2392 HRESULT hrc = pStreamWas->pDevCfg->pIAudioClient->GetCurrentPadding(&cFramesPending); 2393 if (SUCCEEDED(hrc)) 2394 { 2395 /* An unreleased buffer is included in the pending frame count, so subtract 2396 whatever we've got hanging around since the previous pfnStreamCapture call. */ 2397 AssertMsgStmt(cFramesPending >= pStreamWas->cFramesCaptureToRelease, 2398 ("%#x vs %#x\n", cFramesPending, pStreamWas->cFramesCaptureToRelease), 2399 cFramesPending = pStreamWas->cFramesCaptureToRelease); 2400 cFramesPending -= pStreamWas->cFramesCaptureToRelease; 2401 2402 /* Add what we've got left in said buffer. */ 2403 uint32_t cFramesCurPacket = PDMAudioPropsBytesToFrames(&pStreamWas->Cfg.Props, pStreamWas->cbCapture); 2404 cFramesPending += cFramesCurPacket; 2405 2406 /* Paranoia: Make sure we don't exceed the buffer size. */ 2407 AssertMsgStmt(cFramesPending <= pStreamWas->Cfg.Backend.cFramesBufferSize, 2408 ("cFramesPending=%#x cFramesCaptureToRelease=%#x cFramesCurPacket=%#x cFramesBufferSize=%#x\n", 2409 cFramesPending, pStreamWas->cFramesCaptureToRelease, cFramesCurPacket, 2410 pStreamWas->Cfg.Backend.cFramesBufferSize), 2411 cFramesPending = pStreamWas->Cfg.Backend.cFramesBufferSize); 2412 2413 cbReadable = PDMAudioPropsFramesToBytes(&pStreamWas->Cfg.Props, cFramesPending); 2414 } 2384 AssertPtrReturn(pStreamWas, PDMHOSTAUDIOSTREAMSTATE_INVALID); 2385 2386 PDMHOSTAUDIOSTREAMSTATE enmState; 2387 AssertPtr(pStreamWas->pDevCfg); 2388 if (pStreamWas->pDevCfg /*paranoia*/) 2389 { 2390 if (RT_SUCCESS(pStreamWas->pDevCfg->rcSetup)) 2391 { 2392 if (!pStreamWas->fDraining) 2393 enmState = PDMHOSTAUDIOSTREAMSTATE_OKAY; 2394 else 2395 { 2396 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT); 2397 enmState = PDMHOSTAUDIOSTREAMSTATE_DRAINING; 2398 } 2399 } 2400 else if ( pStreamWas->pDevCfg->rcSetup == VERR_AUDIO_STREAM_INIT_IN_PROGRESS 2401 || pStreamWas->fSwitchingDevice ) 2402 enmState = PDMHOSTAUDIOSTREAMSTATE_INITIALIZING; 2415 2403 else 2416 LogRelMax(64, ("WasAPI: GetCurrentPadding failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2417 } 2418 2419 RTCritSectLeave(&pStreamWas->CritSect); 2420 2421 LogFlowFunc(("returns %#x (%u) {%s}\n", cbReadable, cbReadable, drvHostWasStreamStatusString(pStreamWas))); 2422 return cbReadable; 2423 } 2424 2425 2426 /** 2427 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable} 2428 */ 2429 static DECLCALLBACK(uint32_t) drvHostAudioWasHA_StreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream) 2430 { 2431 RT_NOREF(pInterface); 2432 PDRVHOSTAUDIOWASSTREAM pStreamWas = (PDRVHOSTAUDIOWASSTREAM)pStream; 2433 AssertPtrReturn(pStreamWas, 0); 2434 LogFlowFunc(("Stream '%s' {%s}\n", pStreamWas->Cfg.szName, drvHostWasStreamStatusString(pStreamWas))); 2435 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT); 2436 2437 uint32_t cbWritable = 0; 2438 RTCritSectEnter(&pStreamWas->CritSect); 2439 2440 if ( pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT 2441 && pStreamWas->pDevCfg->pIAudioClient /* paranoia */) 2442 { 2443 UINT32 cFramesPending = 0; 2444 HRESULT hrc = pStreamWas->pDevCfg->pIAudioClient->GetCurrentPadding(&cFramesPending); 2445 if (SUCCEEDED(hrc)) 2446 { 2447 if (cFramesPending < pStreamWas->Cfg.Backend.cFramesBufferSize) 2448 cbWritable = PDMAudioPropsFramesToBytes(&pStreamWas->Cfg.Props, 2449 pStreamWas->Cfg.Backend.cFramesBufferSize - cFramesPending); 2450 else if (cFramesPending > pStreamWas->Cfg.Backend.cFramesBufferSize) 2451 { 2452 LogRelMax(64, ("WasAPI: Warning! GetCurrentPadding('%s') return too high: cFramesPending=%#x > cFramesBufferSize=%#x\n", 2453 pStreamWas->Cfg.szName, cFramesPending, pStreamWas->Cfg.Backend.cFramesBufferSize)); 2454 AssertMsgFailed(("cFramesPending=%#x > cFramesBufferSize=%#x\n", 2455 cFramesPending, pStreamWas->Cfg.Backend.cFramesBufferSize)); 2456 } 2457 } 2458 else 2459 LogRelMax(64, ("WasAPI: GetCurrentPadding failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2460 } 2461 2462 RTCritSectLeave(&pStreamWas->CritSect); 2463 2464 LogFlowFunc(("returns %#x (%u) {%s}\n", cbWritable, cbWritable, drvHostWasStreamStatusString(pStreamWas))); 2465 return cbWritable; 2404 enmState = PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING; 2405 } 2406 else if (pStreamWas->fSwitchingDevice) 2407 enmState = PDMHOSTAUDIOSTREAMSTATE_INITIALIZING; 2408 else 2409 enmState = PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING; 2410 2411 LogFlowFunc(("returns %d for '%s' {%s}\n", enmState, pStreamWas->Cfg.szName, drvHostWasStreamStatusString(pStreamWas))); 2412 return enmState; 2466 2413 } 2467 2414 … … 2508 2455 2509 2456 /** 2510 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetState} 2511 */ 2512 static DECLCALLBACK(PDMHOSTAUDIOSTREAMSTATE) drvHostAudioWasHA_StreamGetState(PPDMIHOSTAUDIO pInterface, 2513 PPDMAUDIOBACKENDSTREAM pStream) 2457 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable} 2458 */ 2459 static DECLCALLBACK(uint32_t) drvHostAudioWasHA_StreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream) 2514 2460 { 2515 2461 RT_NOREF(pInterface); 2516 2462 PDRVHOSTAUDIOWASSTREAM pStreamWas = (PDRVHOSTAUDIOWASSTREAM)pStream; 2517 AssertPtrReturn(pStreamWas, PDMHOSTAUDIOSTREAMSTATE_INVALID); 2518 2519 PDMHOSTAUDIOSTREAMSTATE enmState; 2520 AssertPtr(pStreamWas->pDevCfg); 2521 if (pStreamWas->pDevCfg /*paranoia*/) 2522 { 2523 if (RT_SUCCESS(pStreamWas->pDevCfg->rcSetup)) 2524 { 2525 if (!pStreamWas->fDraining) 2526 enmState = PDMHOSTAUDIOSTREAMSTATE_OKAY; 2527 else 2463 AssertPtrReturn(pStreamWas, 0); 2464 LogFlowFunc(("Stream '%s' {%s}\n", pStreamWas->Cfg.szName, drvHostWasStreamStatusString(pStreamWas))); 2465 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT); 2466 2467 uint32_t cbWritable = 0; 2468 RTCritSectEnter(&pStreamWas->CritSect); 2469 2470 if ( pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT 2471 && pStreamWas->pDevCfg->pIAudioClient /* paranoia */) 2472 { 2473 UINT32 cFramesPending = 0; 2474 HRESULT hrc = pStreamWas->pDevCfg->pIAudioClient->GetCurrentPadding(&cFramesPending); 2475 if (SUCCEEDED(hrc)) 2476 { 2477 if (cFramesPending < pStreamWas->Cfg.Backend.cFramesBufferSize) 2478 cbWritable = PDMAudioPropsFramesToBytes(&pStreamWas->Cfg.Props, 2479 pStreamWas->Cfg.Backend.cFramesBufferSize - cFramesPending); 2480 else if (cFramesPending > pStreamWas->Cfg.Backend.cFramesBufferSize) 2528 2481 { 2529 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_OUT); 2530 enmState = PDMHOSTAUDIOSTREAMSTATE_DRAINING; 2482 LogRelMax(64, ("WasAPI: Warning! GetCurrentPadding('%s') return too high: cFramesPending=%#x > cFramesBufferSize=%#x\n", 2483 pStreamWas->Cfg.szName, cFramesPending, pStreamWas->Cfg.Backend.cFramesBufferSize)); 2484 AssertMsgFailed(("cFramesPending=%#x > cFramesBufferSize=%#x\n", 2485 cFramesPending, pStreamWas->Cfg.Backend.cFramesBufferSize)); 2531 2486 } 2532 2487 } 2533 else if ( pStreamWas->pDevCfg->rcSetup == VERR_AUDIO_STREAM_INIT_IN_PROGRESS2534 || pStreamWas->fSwitchingDevice )2535 enmState = PDMHOSTAUDIOSTREAMSTATE_INITIALIZING;2536 2488 else 2537 enmState = PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING; 2538 } 2539 else if (pStreamWas->fSwitchingDevice) 2540 enmState = PDMHOSTAUDIOSTREAMSTATE_INITIALIZING; 2541 else 2542 enmState = PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING; 2543 2544 LogFlowFunc(("returns %d for '%s' {%s}\n", enmState, pStreamWas->Cfg.szName, drvHostWasStreamStatusString(pStreamWas))); 2545 return enmState; 2489 LogRelMax(64, ("WasAPI: GetCurrentPadding failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2490 } 2491 2492 RTCritSectLeave(&pStreamWas->CritSect); 2493 2494 LogFlowFunc(("returns %#x (%u) {%s}\n", cbWritable, cbWritable, drvHostWasStreamStatusString(pStreamWas))); 2495 return cbWritable; 2546 2496 } 2547 2497 … … 2702 2652 msPrev ? msNow - msPrev : 0, msPrev, pStreamWas->msLastTransfer, drvHostWasStreamStatusString(pStreamWas) )); 2703 2653 return rc; 2654 } 2655 2656 2657 /** 2658 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable} 2659 */ 2660 static DECLCALLBACK(uint32_t) drvHostAudioWasHA_StreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream) 2661 { 2662 RT_NOREF(pInterface); 2663 PDRVHOSTAUDIOWASSTREAM pStreamWas = (PDRVHOSTAUDIOWASSTREAM)pStream; 2664 AssertPtrReturn(pStreamWas, 0); 2665 Assert(pStreamWas->Cfg.enmDir == PDMAUDIODIR_IN); 2666 2667 uint32_t cbReadable = 0; 2668 RTCritSectEnter(&pStreamWas->CritSect); 2669 2670 if (pStreamWas->pDevCfg->pIAudioCaptureClient /* paranoia */) 2671 { 2672 UINT32 cFramesPending = 0; 2673 HRESULT hrc = pStreamWas->pDevCfg->pIAudioClient->GetCurrentPadding(&cFramesPending); 2674 if (SUCCEEDED(hrc)) 2675 { 2676 /* An unreleased buffer is included in the pending frame count, so subtract 2677 whatever we've got hanging around since the previous pfnStreamCapture call. */ 2678 AssertMsgStmt(cFramesPending >= pStreamWas->cFramesCaptureToRelease, 2679 ("%#x vs %#x\n", cFramesPending, pStreamWas->cFramesCaptureToRelease), 2680 cFramesPending = pStreamWas->cFramesCaptureToRelease); 2681 cFramesPending -= pStreamWas->cFramesCaptureToRelease; 2682 2683 /* Add what we've got left in said buffer. */ 2684 uint32_t cFramesCurPacket = PDMAudioPropsBytesToFrames(&pStreamWas->Cfg.Props, pStreamWas->cbCapture); 2685 cFramesPending += cFramesCurPacket; 2686 2687 /* Paranoia: Make sure we don't exceed the buffer size. */ 2688 AssertMsgStmt(cFramesPending <= pStreamWas->Cfg.Backend.cFramesBufferSize, 2689 ("cFramesPending=%#x cFramesCaptureToRelease=%#x cFramesCurPacket=%#x cFramesBufferSize=%#x\n", 2690 cFramesPending, pStreamWas->cFramesCaptureToRelease, cFramesCurPacket, 2691 pStreamWas->Cfg.Backend.cFramesBufferSize), 2692 cFramesPending = pStreamWas->Cfg.Backend.cFramesBufferSize); 2693 2694 cbReadable = PDMAudioPropsFramesToBytes(&pStreamWas->Cfg.Props, cFramesPending); 2695 } 2696 else 2697 LogRelMax(64, ("WasAPI: GetCurrentPadding failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2698 } 2699 2700 RTCritSectLeave(&pStreamWas->CritSect); 2701 2702 LogFlowFunc(("returns %#x (%u) {%s}\n", cbReadable, cbReadable, drvHostWasStreamStatusString(pStreamWas))); 2703 return cbReadable; 2704 2704 } 2705 2705 … … 3030 3030 pThis->IHostAudio.pfnStreamNotifyDeviceChanged = drvHostAudioWasHA_StreamNotifyDeviceChanged; 3031 3031 pThis->IHostAudio.pfnStreamControl = drvHostAudioWasHA_StreamControl; 3032 pThis->IHostAudio.pfnStreamGetState = drvHostAudioWasHA_StreamGetState; 3033 pThis->IHostAudio.pfnStreamGetPending = drvHostAudioWasHA_StreamGetPending; 3034 pThis->IHostAudio.pfnStreamGetWritable = drvHostAudioWasHA_StreamGetWritable; 3035 pThis->IHostAudio.pfnStreamPlay = drvHostAudioWasHA_StreamPlay; 3032 3036 pThis->IHostAudio.pfnStreamGetReadable = drvHostAudioWasHA_StreamGetReadable; 3033 pThis->IHostAudio.pfnStreamGetWritable = drvHostAudioWasHA_StreamGetWritable;3034 pThis->IHostAudio.pfnStreamGetPending = drvHostAudioWasHA_StreamGetPending;3035 pThis->IHostAudio.pfnStreamGetState = drvHostAudioWasHA_StreamGetState;3036 pThis->IHostAudio.pfnStreamPlay = drvHostAudioWasHA_StreamPlay;3037 3037 pThis->IHostAudio.pfnStreamCapture = drvHostAudioWasHA_StreamCapture; 3038 3038
Note:
See TracChangeset
for help on using the changeset viewer.