mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
use ComPtr for misc. things
This commit is contained in:
parent
60c98a6483
commit
5c1412f84d
12 changed files with 110 additions and 126 deletions
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "Data/Collections/Slice.h"
|
||||
#include "GPU/GPU.h"
|
||||
#include "Common/GPU/Shader.h"
|
||||
#include "GPU/thin3d.h"
|
||||
|
||||
// For framebuffer copies and similar things that just require passthrough.
|
||||
struct Draw2DVertex {
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
|
||||
#include <initguid.h>
|
||||
#include "Common/CommonWindows.h"
|
||||
#include <netfw.h>
|
||||
#include <wrl/client.h>
|
||||
#endif
|
||||
|
||||
// TODO: For text align flags, probably shouldn't be in gfx_es2/...
|
||||
|
@ -62,8 +63,8 @@ enum class ServerAllowStatus {
|
|||
|
||||
static ServerAllowStatus IsServerAllowed(int port) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
|
||||
INetFwMgr *fwMgr = nullptr;
|
||||
HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), nullptr, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void **)&fwMgr);
|
||||
Microsoft::WRL::ComPtr<INetFwMgr> fwMgr;
|
||||
HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fwMgr));
|
||||
if (FAILED(hr)) {
|
||||
return ServerAllowStatus::UNKNOWN;
|
||||
}
|
||||
|
@ -80,7 +81,6 @@ static ServerAllowStatus IsServerAllowed(int port) {
|
|||
VariantInit(&allowedV);
|
||||
VariantInit(&restrictedV);
|
||||
hr = fwMgr->IsPortAllowed(&app[0], NET_FW_IP_VERSION_ANY, port, nullptr, NET_FW_IP_PROTOCOL_TCP, &allowedV, &restrictedV);
|
||||
fwMgr->Release();
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return ServerAllowStatus::UNKNOWN;
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "CaptureDevice.h"
|
||||
#include <wrl/client.h>
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// VideoBufferLock class
|
||||
|
@ -27,8 +30,7 @@ public:
|
|||
VideoBufferLock(IMFMediaBuffer *pBuffer) : m_p2DBuffer(NULL), m_bLocked(FALSE)
|
||||
{
|
||||
m_pBuffer = pBuffer;
|
||||
m_pBuffer->AddRef();
|
||||
|
||||
|
||||
// Query for the 2-D buffer interface. OK if this fails.
|
||||
(void)m_pBuffer->QueryInterface(IID_PPV_ARGS(&m_p2DBuffer));
|
||||
}
|
||||
|
@ -36,8 +38,6 @@ public:
|
|||
~VideoBufferLock()
|
||||
{
|
||||
UnlockBuffer();
|
||||
SafeRelease(&m_pBuffer);
|
||||
SafeRelease(&m_p2DBuffer);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
@ -116,8 +116,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
IMFMediaBuffer *m_pBuffer;
|
||||
IMF2DBuffer *m_p2DBuffer;
|
||||
Microsoft::WRL::ComPtr<IMFMediaBuffer> m_pBuffer;
|
||||
Microsoft::WRL::ComPtr<IMF2DBuffer> m_p2DBuffer;
|
||||
|
||||
BOOL m_bLocked;
|
||||
};
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <shlwapi.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "Common/Thread/ThreadUtil.h"
|
||||
#include "CaptureDevice.h"
|
||||
|
@ -25,6 +26,8 @@
|
|||
#include "Core/HLE/sceUsbCam.h"
|
||||
#include "Core/Config.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace MFAPI {
|
||||
HINSTANCE Mflib;
|
||||
HINSTANCE Mfplatlib;
|
||||
|
@ -142,7 +145,7 @@ HRESULT ReaderCallback::OnReadSample(
|
|||
LONGLONG llTimestamp,
|
||||
IMFSample *pSample) {
|
||||
HRESULT hr = S_OK;
|
||||
IMFMediaBuffer *pBuffer = nullptr;
|
||||
ComPtr<IMFMediaBuffer> pBuffer;
|
||||
std::lock_guard<std::mutex> lock(device->sdMutex);
|
||||
if (device->isShutDown())
|
||||
return hr;
|
||||
|
@ -173,7 +176,7 @@ HRESULT ReaderCallback::OnReadSample(
|
|||
|
||||
// pSample can be null, in this case ReadSample still should be called to request next frame.
|
||||
if (pSample) {
|
||||
videoBuffer = new VideoBufferLock(pBuffer);
|
||||
videoBuffer = new VideoBufferLock(pBuffer.Get());
|
||||
hr = videoBuffer->LockBuffer(device->deviceParam.default_stride, device->deviceParam.height, &pbScanline0, &lStride);
|
||||
|
||||
if (lStride > 0)
|
||||
|
@ -278,7 +281,6 @@ HRESULT ReaderCallback::OnReadSample(
|
|||
}
|
||||
}
|
||||
|
||||
SafeRelease(&pBuffer);
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
@ -522,18 +524,15 @@ bool WindowsCaptureDevice::init() {
|
|||
|
||||
bool WindowsCaptureDevice::start(void *startParam) {
|
||||
HRESULT hr = S_OK;
|
||||
IMFAttributes *pAttributes = nullptr;
|
||||
IMFMediaType *pType = nullptr;
|
||||
ComPtr<IMFAttributes> pAttributes;
|
||||
ComPtr<IMFMediaType> pType;
|
||||
UINT32 selection = 0;
|
||||
UINT32 count = 0;
|
||||
|
||||
// Release old sources first(if any).
|
||||
SafeRelease(&m_pSource);
|
||||
SafeRelease(&m_pReader);
|
||||
if (m_pCallback) {
|
||||
delete m_pCallback;
|
||||
m_pCallback = nullptr;
|
||||
}
|
||||
m_pSource = nullptr;
|
||||
m_pReader = nullptr;
|
||||
m_pCallback = nullptr;
|
||||
// Need to re-enumerate the list,because old sources were released.
|
||||
std::vector<std::string> deviceList = getDeviceList(true);
|
||||
|
||||
|
@ -555,25 +554,24 @@ bool WindowsCaptureDevice::start(void *startParam) {
|
|||
}
|
||||
++count;
|
||||
}
|
||||
setSelction(selection);
|
||||
setSelection(selection);
|
||||
hr = param.ppDevices[param.selection]->ActivateObject(
|
||||
__uuidof(IMFMediaSource),
|
||||
(void**)&m_pSource);
|
||||
IID_PPV_ARGS(&m_pSource));
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
hr = MFCreateAttributes(&pAttributes, 2);
|
||||
|
||||
// Use async mode
|
||||
if (SUCCEEDED(hr))
|
||||
hr = pAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, m_pCallback);
|
||||
hr = pAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, m_pCallback.Get());
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
hr = pAttributes->SetUINT32(MF_READWRITE_DISABLE_CONVERTERS, TRUE);
|
||||
|
||||
if (SUCCEEDED(hr)) {
|
||||
hr = CreateSourceReaderFromMediaSource(
|
||||
m_pSource,
|
||||
pAttributes,
|
||||
m_pSource.Get(),
|
||||
pAttributes.Get(),
|
||||
&m_pReader
|
||||
);
|
||||
}
|
||||
|
@ -609,7 +607,7 @@ bool WindowsCaptureDevice::start(void *startParam) {
|
|||
|
||||
if (FAILED(hr)) { break; }
|
||||
|
||||
hr = setDeviceParam(pType);
|
||||
hr = setDeviceParam(pType.Get());
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
break;
|
||||
|
@ -654,7 +652,7 @@ bool WindowsCaptureDevice::start(void *startParam) {
|
|||
|
||||
if (FAILED(hr)) { break; }
|
||||
|
||||
hr = setDeviceParam(pType);
|
||||
hr = setDeviceParam(pType.Get());
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
break;
|
||||
|
@ -679,15 +677,11 @@ bool WindowsCaptureDevice::start(void *startParam) {
|
|||
setError(CAPTUREDEVIDE_ERROR_START_FAILED, "Cannot start");
|
||||
if(m_pSource)
|
||||
m_pSource->Shutdown();
|
||||
SafeRelease(&m_pSource);
|
||||
SafeRelease(&pAttributes);
|
||||
SafeRelease(&pType);
|
||||
SafeRelease(&m_pReader);
|
||||
m_pSource = nullptr;
|
||||
m_pReader = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
SafeRelease(&pAttributes);
|
||||
SafeRelease(&pType);
|
||||
updateState(CAPTUREDEVIDE_STATE::STARTED);
|
||||
break;
|
||||
case CAPTUREDEVIDE_STATE::LOST:
|
||||
|
@ -751,13 +745,13 @@ std::vector<std::string> WindowsCaptureDevice::getDeviceList(bool forceEnum, int
|
|||
|
||||
if (SUCCEEDED(hr)) {
|
||||
// Get the size needed first
|
||||
dwMinSize = WideCharToMultiByte(CP_UTF8, NULL, pwstrName, -1, nullptr, 0, nullptr, FALSE);
|
||||
dwMinSize = WideCharToMultiByte(CP_UTF8, 0, pwstrName, -1, nullptr, 0, nullptr, FALSE);
|
||||
if (dwMinSize == 0)
|
||||
hr = E_FAIL;
|
||||
}
|
||||
if (SUCCEEDED(hr)) {
|
||||
cstrName = new char[dwMinSize];
|
||||
WideCharToMultiByte(CP_UTF8, NULL, pwstrName, -1, cstrName, dwMinSize, NULL, FALSE);
|
||||
WideCharToMultiByte(CP_UTF8, 0, pwstrName, -1, cstrName, dwMinSize, NULL, FALSE);
|
||||
strName = cstrName;
|
||||
delete[] cstrName;
|
||||
|
||||
|
@ -937,9 +931,9 @@ void WindowsCaptureDevice::messageHandler() {
|
|||
stop();
|
||||
|
||||
std::lock_guard<std::mutex> lock(sdMutex);
|
||||
SafeRelease(&m_pSource);
|
||||
SafeRelease(&m_pReader);
|
||||
delete m_pCallback;
|
||||
m_pSource = nullptr;
|
||||
m_pReader = nullptr;
|
||||
m_pCallback = nullptr;
|
||||
unRegisterCMPTMFApis();
|
||||
|
||||
std::unique_lock<std::mutex> lock2(paramMutex);
|
||||
|
@ -957,7 +951,7 @@ void WindowsCaptureDevice::messageHandler() {
|
|||
|
||||
HRESULT WindowsCaptureDevice::enumDevices() {
|
||||
HRESULT hr = S_OK;
|
||||
IMFAttributes *pAttributes = nullptr;
|
||||
ComPtr<IMFAttributes> pAttributes;
|
||||
|
||||
hr = MFCreateAttributes(&pAttributes, 1);
|
||||
if (SUCCEEDED(hr)) {
|
||||
|
@ -982,10 +976,9 @@ HRESULT WindowsCaptureDevice::enumDevices() {
|
|||
}
|
||||
}
|
||||
if (SUCCEEDED(hr)) {
|
||||
hr = EnumDeviceSources(pAttributes, ¶m.ppDevices, ¶m.count);
|
||||
hr = EnumDeviceSources(pAttributes.Get(), ¶m.ppDevices, ¶m.count);
|
||||
}
|
||||
|
||||
SafeRelease(&pAttributes);
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <vector>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "Core/HLE/sceUsbMic.h"
|
||||
|
||||
|
@ -193,7 +194,7 @@ public:
|
|||
std::vector<std::string> getDeviceList(bool forceEnum = false, int *pActuallCount = nullptr);
|
||||
|
||||
void setError(const CAPTUREDEVIDE_ERROR &newError, const std::string &newErrorMessage) { error = newError; errorMessage = newErrorMessage; }
|
||||
void setSelction(const UINT32 &selection) { param.selection = selection; }
|
||||
void setSelection(const UINT32 &selection) { param.selection = selection; }
|
||||
HRESULT setDeviceParam(IMFMediaType *pType);
|
||||
|
||||
bool isShutDown() const { return state == CAPTUREDEVIDE_STATE::SHUTDOWN; }
|
||||
|
@ -226,9 +227,9 @@ protected:
|
|||
bool isDeviceChanged = false;
|
||||
|
||||
// MF interface.
|
||||
ReaderCallback *m_pCallback = nullptr;
|
||||
IMFSourceReader *m_pReader = nullptr;
|
||||
IMFMediaSource *m_pSource = nullptr;
|
||||
Microsoft::WRL::ComPtr<ReaderCallback> m_pCallback;
|
||||
Microsoft::WRL::ComPtr<IMFSourceReader> m_pReader;
|
||||
Microsoft::WRL::ComPtr<IMFMediaSource> m_pSource;
|
||||
|
||||
// Message loop.
|
||||
std::mutex mutex;
|
||||
|
|
|
@ -72,22 +72,21 @@ bool DSoundAudioBackend::CreateBuffer() {
|
|||
dsBuffer_->SetCurrentPosition(0);
|
||||
return true;
|
||||
} else {
|
||||
dsBuffer_ = NULL;
|
||||
dsBuffer_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int DSoundAudioBackend::RunThread() {
|
||||
if (FAILED(DirectSoundCreate8(0, &ds_, 0))) {
|
||||
ds_ = NULL;
|
||||
ds_ = nullptr;
|
||||
threadData_ = 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ds_->SetCooperativeLevel(window_, DSSCL_PRIORITY);
|
||||
if (!CreateBuffer()) {
|
||||
ds_->Release();
|
||||
ds_ = NULL;
|
||||
ds_ = nullptr;
|
||||
threadData_ = 2;
|
||||
return 1;
|
||||
}
|
||||
|
@ -135,8 +134,8 @@ int DSoundAudioBackend::RunThread() {
|
|||
}
|
||||
dsBuffer_->Stop();
|
||||
|
||||
dsBuffer_->Release();
|
||||
ds_->Release();
|
||||
dsBuffer_ = nullptr;
|
||||
ds_ = nullptr;
|
||||
|
||||
threadData_ = 2;
|
||||
return 0;
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
#include "WindowsAudio.h"
|
||||
#include <mmreg.h>
|
||||
|
||||
struct IDirectSound8;
|
||||
struct IDirectSoundBuffer;
|
||||
#include <dsound.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
class DSoundAudioBackend : public WindowsAudioBackend {
|
||||
public:
|
||||
|
@ -29,8 +28,8 @@ private:
|
|||
|
||||
StreamCallback callback_;
|
||||
|
||||
IDirectSound8 *ds_ = nullptr;
|
||||
IDirectSoundBuffer *dsBuffer_ = nullptr;
|
||||
Microsoft::WRL::ComPtr<IDirectSound8> ds_;
|
||||
Microsoft::WRL::ComPtr<IDirectSoundBuffer> dsBuffer_;
|
||||
|
||||
int bufferSize_ = 0; // bytes
|
||||
int totalRenderedBytes_ = 0;
|
||||
|
|
|
@ -16,25 +16,25 @@
|
|||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <initguid.h>
|
||||
#include <cstddef>
|
||||
#include <limits.h>
|
||||
#include <algorithm>
|
||||
#include <mmsystem.h>
|
||||
#include <XInput.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "Common/Input/InputState.h"
|
||||
#include "Common/Input/KeyCodes.h"
|
||||
#include "Common/LogReporting.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/System/NativeApp.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/HLE/sceCtrl.h"
|
||||
#include "Core/KeyMap.h"
|
||||
#include "Windows/DinputDevice.h"
|
||||
#pragma comment(lib,"dinput8.lib")
|
||||
|
||||
//initialize static members of DinputDevice
|
||||
unsigned int DinputDevice::pInstances = 0;
|
||||
LPDIRECTINPUT8 DinputDevice::pDI = NULL;
|
||||
Microsoft::WRL::ComPtr<IDirectInput8> DinputDevice::pDI;
|
||||
std::vector<DIDEVICEINSTANCE> DinputDevice::devices;
|
||||
bool DinputDevice::needsCheck_ = true;
|
||||
|
||||
|
@ -84,14 +84,14 @@ bool IsXInputDevice( const GUID* pGuidProductFromDirectInput ) {
|
|||
|
||||
LPDIRECTINPUT8 DinputDevice::getPDI()
|
||||
{
|
||||
if (pDI == NULL)
|
||||
if (pDI == nullptr)
|
||||
{
|
||||
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&pDI, NULL)))
|
||||
{
|
||||
pDI = NULL;
|
||||
pDI = nullptr;
|
||||
}
|
||||
}
|
||||
return pDI;
|
||||
return pDI.Get();
|
||||
}
|
||||
|
||||
BOOL CALLBACK DinputDevice::DevicesCallback(
|
||||
|
@ -125,7 +125,7 @@ void DinputDevice::getDevices(bool refresh)
|
|||
DinputDevice::DinputDevice(int devnum) {
|
||||
pInstances++;
|
||||
pDevNum = devnum;
|
||||
pJoystick = NULL;
|
||||
pJoystick = nullptr;
|
||||
memset(lastButtons_, 0, sizeof(lastButtons_));
|
||||
memset(lastPOV_, 0, sizeof(lastPOV_));
|
||||
last_lX_ = 0;
|
||||
|
@ -157,8 +157,7 @@ DinputDevice::DinputDevice(int devnum) {
|
|||
}
|
||||
|
||||
if (FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) {
|
||||
pJoystick->Release();
|
||||
pJoystick = NULL;
|
||||
pJoystick = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -187,8 +186,7 @@ DinputDevice::DinputDevice(int devnum) {
|
|||
|
||||
DinputDevice::~DinputDevice() {
|
||||
if (pJoystick) {
|
||||
pJoystick->Release();
|
||||
pJoystick = NULL;
|
||||
pJoystick = nullptr;
|
||||
}
|
||||
|
||||
pInstances--;
|
||||
|
@ -198,8 +196,7 @@ DinputDevice::~DinputDevice() {
|
|||
//happening at the same time and other values like pDI are
|
||||
//unsafe as well anyway
|
||||
if (pInstances == 0 && pDI) {
|
||||
pDI->Release();
|
||||
pDI = NULL;
|
||||
pDI = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <vector>
|
||||
#include <InitGuid.h>
|
||||
#include <wrl/client.h>
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#define DIRECTINPUT_RGBBUTTONS_MAX 128
|
||||
#include "InputDevice.h"
|
||||
|
@ -54,10 +55,10 @@ private:
|
|||
);
|
||||
static unsigned int pInstances;
|
||||
static std::vector<DIDEVICEINSTANCE> devices;
|
||||
static LPDIRECTINPUT8 pDI;
|
||||
static Microsoft::WRL::ComPtr<IDirectInput8> pDI;
|
||||
static bool needsCheck_;
|
||||
int pDevNum;
|
||||
LPDIRECTINPUTDEVICE8 pJoystick;
|
||||
Microsoft::WRL::ComPtr<IDirectInputDevice8> pJoystick;
|
||||
DIJOYSTATE2 pPrevState;
|
||||
bool analog;
|
||||
BYTE lastButtons_[128];
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <shlobj.h>
|
||||
#include <commdlg.h>
|
||||
#include <cderr.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
namespace W32Util {
|
||||
std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath) {
|
||||
|
@ -192,16 +193,16 @@ namespace W32Util {
|
|||
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
|
||||
static HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc, LPCWSTR lpszIcon, int iconIndex) {
|
||||
HRESULT hres;
|
||||
IShellLink *psl = nullptr;
|
||||
Microsoft::WRL::ComPtr<IShellLink> psl;
|
||||
hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
if (FAILED(hres))
|
||||
return hres;
|
||||
|
||||
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
|
||||
// has already been called.
|
||||
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
|
||||
hres = CoCreateInstance(__uuidof(ShellLink), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
|
||||
if (SUCCEEDED(hres) && psl) {
|
||||
IPersistFile *ppf = nullptr;
|
||||
Microsoft::WRL::ComPtr<IPersistFile> ppf;
|
||||
|
||||
// Set the path to the shortcut target and add the description.
|
||||
psl->SetPath(lpszPathObj);
|
||||
|
@ -213,14 +214,12 @@ static HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lp
|
|||
|
||||
// Query IShellLink for the IPersistFile interface, used for saving the
|
||||
// shortcut in persistent storage.
|
||||
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
|
||||
hres = psl.As(&ppf);
|
||||
|
||||
if (SUCCEEDED(hres) && ppf) {
|
||||
// Save the link by calling IPersistFile::Save.
|
||||
hres = ppf->Save(lpszPathLink, TRUE);
|
||||
ppf->Release();
|
||||
}
|
||||
psl->Release();
|
||||
}
|
||||
CoUninitialize();
|
||||
|
||||
|
|
|
@ -11,30 +11,25 @@
|
|||
|
||||
#include "Common/Thread/ThreadUtil.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <Objbase.h>
|
||||
#include <Mmreg.h>
|
||||
#include <MMDeviceAPI.h>
|
||||
#include <AudioClient.h>
|
||||
#include <AudioPolicy.h>
|
||||
#include <wrl/client.h>
|
||||
#include "Functiondiscoverykeys_devpkey.h"
|
||||
|
||||
// Includes some code from https://learn.microsoft.com/en-us/windows/win32/coreaudio/device-events
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "ole32.lib")
|
||||
|
||||
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
|
||||
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
|
||||
const IID IID_IAudioClient = __uuidof(IAudioClient);
|
||||
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
|
||||
#endif
|
||||
|
||||
// Adapted from a MSDN sample.
|
||||
|
||||
#define SAFE_RELEASE(punk) \
|
||||
if ((punk) != NULL) \
|
||||
{ (punk)->Release(); (punk) = NULL; }
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
class CMMNotificationClient final : public IMMNotificationClient {
|
||||
public:
|
||||
|
@ -44,7 +39,6 @@ public:
|
|||
virtual ~CMMNotificationClient() {
|
||||
CoTaskMemFree(currentDevice_);
|
||||
currentDevice_ = nullptr;
|
||||
SAFE_RELEASE(_pEnumerator)
|
||||
}
|
||||
|
||||
void SetCurrentDevice(IMMDevice *device) {
|
||||
|
@ -149,8 +143,8 @@ public:
|
|||
std::string GetDeviceName(LPCWSTR pwstrId)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
IMMDevice *pDevice = NULL;
|
||||
IPropertyStore *pProps = NULL;
|
||||
ComPtr<IMMDevice> pDevice;
|
||||
ComPtr<IPropertyStore> pProps;
|
||||
PROPVARIANT varString;
|
||||
PropVariantInit(&varString);
|
||||
|
||||
|
@ -159,8 +153,7 @@ public:
|
|||
// Get enumerator for audio endpoint devices.
|
||||
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
|
||||
NULL, CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IMMDeviceEnumerator),
|
||||
(void**)&_pEnumerator);
|
||||
IID_PPV_ARGS(&_pEnumerator));
|
||||
}
|
||||
if (hr == S_OK && _pEnumerator) {
|
||||
hr = _pEnumerator->GetDevice(pwstrId, &pDevice);
|
||||
|
@ -177,15 +170,13 @@ public:
|
|||
|
||||
PropVariantClear(&varString);
|
||||
|
||||
SAFE_RELEASE(pProps)
|
||||
SAFE_RELEASE(pDevice)
|
||||
return name;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex lock_;
|
||||
LONG _cRef = 1;
|
||||
IMMDeviceEnumerator *_pEnumerator = nullptr;
|
||||
ComPtr<IMMDeviceEnumerator> _pEnumerator;
|
||||
wchar_t *currentDevice_ = nullptr;
|
||||
bool deviceChanged_ = false;
|
||||
};
|
||||
|
@ -252,12 +243,12 @@ private:
|
|||
int &sampleRate_;
|
||||
StreamCallback &callback_;
|
||||
|
||||
IMMDeviceEnumerator *deviceEnumerator_ = nullptr;
|
||||
IMMDevice *device_ = nullptr;
|
||||
IAudioClient *audioInterface_ = nullptr;
|
||||
CMMNotificationClient *notificationClient_ = nullptr;
|
||||
ComPtr<IMMDeviceEnumerator> deviceEnumerator_;
|
||||
ComPtr<IMMDevice> device_;
|
||||
ComPtr<IAudioClient> audioInterface_;
|
||||
ComPtr<CMMNotificationClient> notificationClient_;
|
||||
WAVEFORMATEXTENSIBLE *deviceFormat_ = nullptr;
|
||||
IAudioRenderClient *renderClient_ = nullptr;
|
||||
ComPtr<IAudioRenderClient> renderClient_;
|
||||
int16_t *shortBuf_ = nullptr;
|
||||
|
||||
enum class Format {
|
||||
|
@ -276,10 +267,9 @@ WASAPIAudioThread::~WASAPIAudioThread() {
|
|||
shortBuf_ = nullptr;
|
||||
ShutdownAudioDevice();
|
||||
if (notificationClient_ && deviceEnumerator_)
|
||||
deviceEnumerator_->UnregisterEndpointNotificationCallback(notificationClient_);
|
||||
delete notificationClient_;
|
||||
deviceEnumerator_->UnregisterEndpointNotificationCallback(notificationClient_.Get());
|
||||
notificationClient_ = nullptr;
|
||||
SAFE_RELEASE(deviceEnumerator_);
|
||||
deviceEnumerator_ = nullptr;
|
||||
}
|
||||
|
||||
bool WASAPIAudioThread::ActivateDefaultDevice() {
|
||||
|
@ -289,7 +279,7 @@ bool WASAPIAudioThread::ActivateDefaultDevice() {
|
|||
return false;
|
||||
|
||||
_assert_(audioInterface_ == nullptr);
|
||||
hresult = device_->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&audioInterface_);
|
||||
hresult = device_->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, &audioInterface_);
|
||||
if (FAILED(hresult) || audioInterface_ == nullptr)
|
||||
return false;
|
||||
|
||||
|
@ -312,7 +302,7 @@ bool WASAPIAudioThread::InitAudioDevice() {
|
|||
if (FAILED(hresult))
|
||||
return false;
|
||||
_assert_(renderClient_ == nullptr);
|
||||
hresult = audioInterface_->GetService(IID_IAudioRenderClient, (void **)&renderClient_);
|
||||
hresult = audioInterface_->GetService(IID_PPV_ARGS(&renderClient_));
|
||||
if (FAILED(hresult) || !renderClient_)
|
||||
return false;
|
||||
|
||||
|
@ -327,11 +317,11 @@ bool WASAPIAudioThread::InitAudioDevice() {
|
|||
}
|
||||
|
||||
void WASAPIAudioThread::ShutdownAudioDevice() {
|
||||
SAFE_RELEASE(renderClient_);
|
||||
renderClient_ = nullptr;
|
||||
CoTaskMemFree(deviceFormat_);
|
||||
deviceFormat_ = nullptr;
|
||||
SAFE_RELEASE(audioInterface_);
|
||||
SAFE_RELEASE(device_);
|
||||
audioInterface_ = nullptr;
|
||||
device_ = nullptr;
|
||||
}
|
||||
|
||||
bool WASAPIAudioThread::DetectFormat() {
|
||||
|
@ -448,9 +438,9 @@ void WASAPIAudioThread::Run() {
|
|||
// Adapted from http://msdn.microsoft.com/en-us/library/windows/desktop/dd316756(v=vs.85).aspx
|
||||
|
||||
_assert_(deviceEnumerator_ == nullptr);
|
||||
HRESULT hresult = CoCreateInstance(CLSID_MMDeviceEnumerator,
|
||||
HRESULT hresult = CoCreateInstance(__uuidof(MMDeviceEnumerator),
|
||||
nullptr, /* Object is not created as the part of the aggregate */
|
||||
CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&deviceEnumerator_);
|
||||
CLSCTX_ALL, IID_PPV_ARGS(&deviceEnumerator_));
|
||||
|
||||
if (FAILED(hresult) || deviceEnumerator_ == nullptr)
|
||||
return;
|
||||
|
@ -461,11 +451,10 @@ void WASAPIAudioThread::Run() {
|
|||
}
|
||||
|
||||
notificationClient_ = new CMMNotificationClient();
|
||||
notificationClient_->SetCurrentDevice(device_);
|
||||
hresult = deviceEnumerator_->RegisterEndpointNotificationCallback(notificationClient_);
|
||||
notificationClient_->SetCurrentDevice(device_.Get());
|
||||
hresult = deviceEnumerator_->RegisterEndpointNotificationCallback(notificationClient_.Get());
|
||||
if (FAILED(hresult)) {
|
||||
// Let's just keep going, but release the client since it doesn't work.
|
||||
delete notificationClient_;
|
||||
notificationClient_ = nullptr;
|
||||
}
|
||||
|
||||
|
@ -549,7 +538,7 @@ void WASAPIAudioThread::Run() {
|
|||
// TODO: Return to the old device here?
|
||||
return;
|
||||
}
|
||||
notificationClient_->SetCurrentDevice(device_);
|
||||
notificationClient_->SetCurrentDevice(device_.Get());
|
||||
if (!InitAudioDevice()) {
|
||||
ERROR_LOG(Log::sceAudio, "WASAPI: Could not init audio device");
|
||||
return;
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#ifdef _WIN32
|
||||
#include <initguid.h>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
|
@ -30,6 +33,7 @@
|
|||
#include <shellapi.h>
|
||||
#include <Wbemidl.h>
|
||||
#include <ShlObj.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "Common/System/Display.h"
|
||||
#include "Common/System/NativeApp.h"
|
||||
|
@ -84,6 +88,11 @@
|
|||
#include "Windows/WindowsHost.h"
|
||||
#include "Windows/main.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "wbemuuid")
|
||||
#endif
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
// Nvidia OpenGL drivers >= v302 will check if the application exports a global
|
||||
// variable named NvOptimusEnablement to know if it should run the app in high
|
||||
|
@ -147,35 +156,33 @@ std::string GetVideoCardDriverVersion() {
|
|||
return retvalue;
|
||||
}
|
||||
|
||||
IWbemLocator *pIWbemLocator = NULL;
|
||||
hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWbemLocator), (LPVOID *)&pIWbemLocator);
|
||||
ComPtr<IWbemLocator> pIWbemLocator;
|
||||
hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pIWbemLocator));
|
||||
if (FAILED(hr)) {
|
||||
CoUninitialize();
|
||||
return retvalue;
|
||||
}
|
||||
|
||||
BSTR bstrServer = SysAllocString(L"\\\\.\\root\\cimv2");
|
||||
IWbemServices *pIWbemServices;
|
||||
ComPtr<IWbemServices> pIWbemServices;
|
||||
hr = pIWbemLocator->ConnectServer(bstrServer, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);
|
||||
if (FAILED(hr)) {
|
||||
pIWbemLocator->Release();
|
||||
SysFreeString(bstrServer);
|
||||
CoUninitialize();
|
||||
return retvalue;
|
||||
}
|
||||
|
||||
hr = CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
|
||||
hr = CoSetProxyBlanket(pIWbemServices.Get(), RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
|
||||
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL,EOAC_DEFAULT);
|
||||
|
||||
BSTR bstrWQL = SysAllocString(L"WQL");
|
||||
BSTR bstrPath = SysAllocString(L"select * from Win32_VideoController");
|
||||
IEnumWbemClassObject* pEnum;
|
||||
ComPtr<IEnumWbemClassObject> pEnum;
|
||||
hr = pIWbemServices->ExecQuery(bstrWQL, bstrPath, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
|
||||
|
||||
ULONG uReturned = 0;
|
||||
VARIANT var{};
|
||||
IWbemClassObject* pObj = NULL;
|
||||
ComPtr<IWbemClassObject> pObj;
|
||||
if (!FAILED(hr)) {
|
||||
hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &uReturned);
|
||||
}
|
||||
|
@ -189,11 +196,8 @@ std::string GetVideoCardDriverVersion() {
|
|||
}
|
||||
}
|
||||
|
||||
pEnum->Release();
|
||||
SysFreeString(bstrPath);
|
||||
SysFreeString(bstrWQL);
|
||||
pIWbemServices->Release();
|
||||
pIWbemLocator->Release();
|
||||
SysFreeString(bstrServer);
|
||||
CoUninitialize();
|
||||
return retvalue;
|
||||
|
|
Loading…
Add table
Reference in a new issue