waapi2: Remove unused WinRT deps and implementations

Removing unused WinRT API based implementations

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9307>
This commit is contained in:
Seungha Yang 2025-06-29 20:45:51 +09:00 committed by GStreamer Marge Bot
parent 0b3108cb3c
commit df45c088ad
5 changed files with 5 additions and 1672 deletions

View File

@ -1,168 +0,0 @@
// MIT License
//
// Copyright (c) 2016 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Source taken from https://github.com/microsoft/MixedRealityCompanionKit
#pragma once
#include <wrl.h>
#include <wrl\async.h>
#include <Windows.System.Threading.h>
#include <functional>
template <typename TDelegate, typename TOperation, typename TLambda>
HRESULT StartAsyncThen(_In_ TOperation* pOperation, _In_ TLambda&& tFunc)
{
if (nullptr == pOperation)
{
return E_INVALIDARG;
}
auto spCallback = Microsoft::WRL::Callback<TDelegate>(
[tFunc](_In_ TOperation* pOperation, _In_ AsyncStatus status) -> HRESULT
{
HRESULT hr = S_OK;
// wrap the operation
if (status != AsyncStatus::Completed)
{
Microsoft::WRL::ComPtr<TOperation> spOperation(pOperation);
Microsoft::WRL::ComPtr<IAsyncInfo> spAsyncInfo;
hr = spOperation.As(&spAsyncInfo);
if (SUCCEEDED(hr))
{
spAsyncInfo->get_ErrorCode(&hr);
}
}
return tFunc(hr, pOperation, status);
});
// start
return (nullptr != spCallback) ? pOperation->put_Completed(spCallback.Get()) : E_OUTOFMEMORY;
}
template <typename TLambda>
HRESULT StartAsyncThen(_In_ ABI::Windows::Foundation::IAsyncAction* pOperation, _In_ TLambda&& tFunc)
{
return StartAsyncThen<ABI::Windows::Foundation::IAsyncActionCompletedHandler, ABI::Windows::Foundation::IAsyncAction>(pOperation, static_cast<TLambda&&>(tFunc));
}
template <typename TProgress, typename TLambda>
HRESULT StartAsyncThen(_In_ ABI::Windows::Foundation::IAsyncActionWithProgress<TProgress>* pOperation, _In_ TLambda&& tFunc)
{
return StartAsyncThen<ABI::Windows::Foundation::IAsyncActionWithProgressCompletedHandler<TProgress>, Windows::Foundation::IAsyncActionWithProgress<TProgress>>(pOperation, static_cast<TLambda&&>(tFunc));
}
template <typename TResult, typename TLambda>
HRESULT StartAsyncThen(_In_ ABI::Windows::Foundation::IAsyncOperation<TResult>* pOperation, _In_ TLambda&& tFunc)
{
return StartAsyncThen<ABI::Windows::Foundation::IAsyncOperationCompletedHandler<TResult>, ABI::Windows::Foundation::IAsyncOperation<TResult>>(pOperation, static_cast<TLambda&&>(tFunc));
}
template <typename TResult, typename TProgress, typename TLambda>
HRESULT StartAsyncThen(_In_ ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress>* pOperation, _In_ TLambda&& tFunc)
{
return StartAsyncThen<ABI::Windows::Foundation::IAsyncOperationWithProgressCompletedHandler<TResult, TProgress>, ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress>>(pOperation, static_cast<TLambda&&>(tFunc));
}
// eg. TOperation = IAsyncOperationWithProgress<UINT32, UINT32>
// eg. THandler = IAsyncOperationWithProgressCompletedHandler<UINT, UINT>
template<typename TOperation, typename THandler>
class AsyncEventDelegate
: public Microsoft::WRL::RuntimeClass
< Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::Delegate>
, THandler
, Microsoft::WRL::FtmBase >
{
public:
AsyncEventDelegate()
: _completedEvent(CreateEventEx(nullptr, nullptr, 0, EVENT_ALL_ACCESS))
{
ComPtr<AsyncEventDelegate> spThis(this);
auto lambda = ([this, spThis](_In_ HRESULT hr, _In_ TOperation* pOperation)
{
SetEvent(_completedEvent.Get());
});
_func = std::move(lambda);
}
STDMETHOD(Invoke)(
_In_ TOperation* pOperation,
_In_ AsyncStatus status)
{
HRESULT hr = S_OK;
// if we completed successfully, then there is no need for getting hresult
if (status != AsyncStatus::Completed)
{
Microsoft::WRL::ComPtr<TOperation> spOperation(pOperation);
Microsoft::WRL::ComPtr<IAsyncInfo> spAsyncInfo;
if (SUCCEEDED(spOperation.As(&spAsyncInfo)))
{
spAsyncInfo->get_ErrorCode(&hr);
}
}
_func(hr, pOperation);
return S_OK;
}
STDMETHOD(SyncWait)(_In_ TOperation* pOperation, _In_ DWORD dwMilliseconds)
{
HRESULT hr = pOperation->put_Completed(this);
if (FAILED(hr))
{
return hr;
}
DWORD dwWait = WaitForSingleObjectEx(_completedEvent.Get(), dwMilliseconds, TRUE);
if (WAIT_IO_COMPLETION == dwWait || WAIT_OBJECT_0 == dwWait)
return S_OK;
return HRESULT_FROM_WIN32(GetLastError());
}
private:
std::function<void(HRESULT, TOperation*)> _func;
Microsoft::WRL::Wrappers::Event _completedEvent;
};
template <typename TOperation, typename THandler>
HRESULT SyncWait(_In_ TOperation* pOperation, _In_ DWORD dwMilliseconds)
{
auto spCallback = Microsoft::WRL::Make<AsyncEventDelegate<TOperation, THandler>>();
return spCallback->SyncWait(pOperation, dwMilliseconds);
}
template <typename TResult>
HRESULT SyncWait(_In_ ABI::Windows::Foundation::IAsyncAction* pOperation, _In_ DWORD dwMilliseconds = INFINITE)
{
return SyncWait<ABI::Windows::Foundation::IAsyncAction, ABI::Windows::Foundation::IAsyncActionCompletedHandler>(pOperation, dwMilliseconds);
}
template <typename TResult>
HRESULT SyncWait(_In_ ABI::Windows::Foundation::IAsyncOperation<TResult>* pOperation, _In_ DWORD dwMilliseconds = INFINITE)
{
return SyncWait<ABI::Windows::Foundation::IAsyncOperation<TResult>, ABI::Windows::Foundation::IAsyncOperationCompletedHandler<TResult>>(pOperation, dwMilliseconds);
}
template <typename TResult, typename TProgress>
HRESULT SyncWait(_In_ ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress>* pOperation, _In_ DWORD dwMilliseconds = INFINITE)
{
return SyncWait<ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress>, ABI::Windows::Foundation::IAsyncOperationWithProgressCompletedHandler<TResult, TProgress>>(pOperation, dwMilliseconds);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2020 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_WASAPI2_CLIENT_H__
#define __GST_WASAPI2_CLIENT_H__
#include <gst/gst.h>
#include <gst/audio/audio.h>
#include "gstwasapi2util.h"
G_BEGIN_DECLS
typedef enum
{
GST_WASAPI2_CLIENT_DEVICE_CLASS_CAPTURE = 0,
GST_WASAPI2_CLIENT_DEVICE_CLASS_RENDER,
GST_WASAPI2_CLIENT_DEVICE_CLASS_LOOPBACK_CAPTURE,
GST_WASAPI2_CLIENT_DEVICE_CLASS_INCLUDE_PROCESS_LOOPBACK_CAPTURE,
GST_WASAPI2_CLIENT_DEVICE_CLASS_EXCLUDE_PROCESS_LOOPBACK_CAPTURE,
} GstWasapi2ClientDeviceClass;
typedef enum
{
GST_WASAPI2_OK,
GST_WASAPI2_DEVICE_NOT_FOUND,
GST_WASAPI2_ACTIVATION_FAILED,
} GstWasapi2Result;
static inline gboolean
gst_wasapi2_device_class_is_loopback (GstWasapi2ClientDeviceClass device_class)
{
switch (device_class) {
case GST_WASAPI2_CLIENT_DEVICE_CLASS_LOOPBACK_CAPTURE:
return TRUE;
default:
break;
}
return FALSE;
}
static inline gboolean
gst_wasapi2_device_class_is_process_loopback (GstWasapi2ClientDeviceClass device_class)
{
switch (device_class) {
case GST_WASAPI2_CLIENT_DEVICE_CLASS_INCLUDE_PROCESS_LOOPBACK_CAPTURE:
case GST_WASAPI2_CLIENT_DEVICE_CLASS_EXCLUDE_PROCESS_LOOPBACK_CAPTURE:
return TRUE;
default:
break;
}
return FALSE;
}
#define GST_TYPE_WASAPI2_CLIENT_DEVICE_CLASS (gst_wasapi2_client_device_class_get_type())
GType gst_wasapi2_client_device_class_get_type (void);
#define GST_TYPE_WASAPI2_CLIENT (gst_wasapi2_client_get_type())
G_DECLARE_FINAL_TYPE (GstWasapi2Client,
gst_wasapi2_client, GST, WASAPI2_CLIENT, GstObject);
GstWasapi2Client * gst_wasapi2_client_new (GstWasapi2ClientDeviceClass device_class,
gint device_index,
const gchar * device_id,
guint target_pid,
gpointer dispatcher);
gboolean gst_wasapi2_client_ensure_activation (GstWasapi2Client * client);
IAudioClient * gst_wasapi2_client_get_handle (GstWasapi2Client * client);
gboolean gst_wasapi2_client_is_endpoint_muted (GstWasapi2Client * client);
GstCaps * gst_wasapi2_client_get_caps (GstWasapi2Client * client);
GstWasapi2Result gst_wasapi2_client_enumerate (GstWasapi2ClientDeviceClass device_class,
gint device_index,
GstWasapi2Client ** client);
G_END_DECLS
#endif /* __GST_WASAPI2_CLIENT_H__ */

View File

@ -450,10 +450,6 @@ gst_wasapi2_util_parse_waveformatex (WAVEFORMATEX * format,
gboolean
gst_wasapi2_can_automatic_stream_routing (void)
{
#ifdef GST_WASAPI2_WINAPI_ONLY_APP
/* Assume we are on very recent OS */
return TRUE;
#else
static gboolean ret = FALSE;
GST_WASAPI2_CALL_ONCE_BEGIN {
@ -488,17 +484,11 @@ gst_wasapi2_can_automatic_stream_routing (void)
GST_TRACE ("Automatic stream routing support: %d", ret);
return ret;
#endif
}
gboolean
gst_wasapi2_can_process_loopback (void)
{
#ifdef GST_WASAPI2_WINAPI_ONLY_APP
/* FIXME: Needs WinRT (Windows.System.Profile) API call
* for OS version check */
return FALSE;
#else
static gboolean ret = FALSE;
GST_WASAPI2_CALL_ONCE_BEGIN {
@ -540,7 +530,6 @@ gst_wasapi2_can_process_loopback (void)
GST_INFO ("Process loopback support: %d", ret);
return ret;
#endif
}
WAVEFORMATEX *

View File

@ -2,7 +2,6 @@ wasapi2_sources = [
'gstwasapi2src.c',
'gstwasapi2sink.c',
'gstwasapi2util.cpp',
'gstwasapi2client.cpp',
'gstwasapi2device.cpp',
'gstwasapi2ringbuffer.cpp',
'gstwasapi2activator.cpp',
@ -17,9 +16,7 @@ wasapi2_headers = [
'gstwasapi2util.h',
'gstwasapi2src.h',
'gstwasapi2sink.h',
'gstwasapi2client.h',
'gstwasapi2object.h',
'AsyncOperations.h',
]
mmdeviceapi_symbols = [
@ -48,11 +45,10 @@ endif
ole32_dep = cc.find_library('ole32', required : get_option('wasapi2'))
ksuser_dep = cc.find_library('ksuser', required : get_option('wasapi2'))
runtimeobject_dep = cc.find_library('runtimeobject', required : get_option('wasapi2'))
mmdeviceapi_dep = cc.find_library('mmdevapi', required : get_option('wasapi2'))
mfplat_dep = cc.find_library('mfplat', required : get_option('wasapi2'))
wasapi2_dep = [ole32_dep, ksuser_dep, runtimeobject_dep, mmdeviceapi_dep, mfplat_dep]
extra_args = ['-DGST_USE_UNSTABLE_API']
wasapi2_dep = [ole32_dep, ksuser_dep, mmdeviceapi_dep, mfplat_dep]
extra_args = []
foreach dep: wasapi2_dep
if not dep.found()
@ -82,40 +78,6 @@ foreach symbol: mmdeviceapi_symbols
endif
endforeach
winapi_app = cxx.compiles('''#include <winapifamily.h>
#include <windows.applicationmodel.core.h>
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#error "not winrt"
#endif
int main (int argc, char ** argv) {
IAudioClient3 *client = NULL;
return 0;
} ''',
dependencies: wasapi2_dep,
name: 'building for WINAPI_PARTITION_APP')
if not winapi_app
if wasapi2_option.enabled()
error('wasapi2 plugin was enabled explicitly, but build target is not include WINAPI_PARTITION_APP')
else
subdir_done()
endif
endif
winapi_desktop = cxx.compiles('''#include <winapifamily.h>
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#error "not win32"
#endif''',
name: 'building for WINAPI_PARTITION_DESKTOP')
if winapi_app and not winapi_desktop
extra_args += ['-DGST_WASAPI2_WINAPI_ONLY_APP']
endif
win10_sdk = cxx.compiles('''#include <windows.h>
#ifndef WDK_NTDDI_VERSION
#error "unknown Windows SDK version"
@ -149,24 +111,12 @@ if not building_for_win10
extra_args += ['-U_WIN32_WINNT', '-UWINVER', '-DWINVER=0x0A00', '-D_WIN32_WINNT=0x0A00', '-DNTDDI_VERSION=WDK_NTDDI_VERSION']
endif
if not gstwinrt_dep.found()
if wasapi2_option.enabled()
error('wasapi2 plugin was enabled explicitly, but GstWinRt library is unavailable')
else
subdir_done()
endif
endif
# Work around for Windows SDK header issue
# https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160#windows-header-issues
extra_cpp_args = cxx.get_supported_arguments(['/Zc:twoPhase-'])
gstwasapi2 = library('gstwasapi2',
wasapi2_sources,
c_args : gst_plugins_bad_args + ['-DCOBJMACROS'] + extra_args,
cpp_args : gst_plugins_bad_args + extra_args + extra_cpp_args,
c_args : gst_plugins_bad_args + extra_args,
cpp_args : gst_plugins_bad_args + extra_args,
include_directories : [configinc],
dependencies : [gstaudio_dep, gstwinrt_dep] + wasapi2_dep,
dependencies : [gstaudio_dep] + wasapi2_dep,
override_options : ['cpp_std=c++14'],
install : true,
install_dir : plugins_install_dir)