wasapi2: Handle GetActivateResult failure

Even if GetActivateResult() succeeded, activation result can fail.
Checks output HRESULT code as well

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9468>
This commit is contained in:
Seungha Yang 2025-08-05 00:41:34 +09:00 committed by GStreamer Marge Bot
parent 7651662fc9
commit fedced4017
2 changed files with 26 additions and 4 deletions

View File

@ -89,16 +89,32 @@ Wasapi2ActivationHandler::ActivateCompleted (IActivateAudioInterfaceAsyncOperati
{
ComPtr<IUnknown> iface;
HRESULT hr = S_OK;
hr = op->GetActivateResult (&hr, &iface);
if (FAILED (hr)) {
HRESULT activate_hr = S_OK;
hr = op->GetActivateResult (&activate_hr, &iface);
if (!gst_wasapi2_result (hr))
GST_ERROR ("Couldn't get activate result, hr: 0x%x", (guint) hr);
if (!gst_wasapi2_result (activate_hr)) {
GST_ERROR ("GetActivateResult failed, hr: 0x%x", (guint) activate_hr);
hr = activate_hr;
}
if (SUCCEEDED (hr) && !iface) {
GST_ERROR ("Couldn't get inteface from asyncop");
hr = E_FAIL;
}
if (FAILED (hr)) {
activate_hr_ = hr;
SetEvent (event_);
return hr;
}
hr = iface.As (&client_);
activate_hr_ = hr;
{
std::lock_guard<std::mutex> lk (lock_);
hr = iface.As (&client_);
activate_hr_ = hr;
}
GST_LOG ("Activation result 0x%x", (guint) hr);
@ -133,6 +149,10 @@ Wasapi2ActivationHandler::GetClient (IAudioClient ** client, DWORD timeout)
if (!client)
return S_OK;
std::lock_guard<std::mutex> lk (lock_);
if (!client_)
return E_FAIL;
*client = client_.Get ();
(*client)->AddRef ();

View File

@ -24,6 +24,7 @@
#include <wrl.h>
#include <atomic>
#include <string>
#include <mutex>
/* Copy of audioclientactivationparams.h since those types are defined only for
* NTDDI_VERSION >= NTDDI_WIN10_FE */
@ -85,6 +86,7 @@ private:
private:
Microsoft::WRL::ComPtr<IAudioClient> client_;
std::atomic<HRESULT> activate_hr_ = { E_FAIL };
std::mutex lock_;
HANDLE event_;
PROPVARIANT prop_ = { };
AUDIOCLIENT_ACTIVATION_PARAMS params_ = { };