Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ComPtr for misc. things #19480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GPU/Common/Draw2D.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions UI/RemoteISOScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions Windows/BufferLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#pragma once

#include "CaptureDevice.h"
#include <wrl/client.h>


//-------------------------------------------------------------------
// VideoBufferLock class
Expand All @@ -27,17 +30,14 @@ class VideoBufferLock
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));
}

~VideoBufferLock()
{
UnlockBuffer();
SafeRelease(&m_pBuffer);
SafeRelease(&m_p2DBuffer);
}

//-------------------------------------------------------------------
Expand Down Expand Up @@ -116,8 +116,8 @@ class VideoBufferLock
}

private:
IMFMediaBuffer *m_pBuffer;
IMF2DBuffer *m_p2DBuffer;
Microsoft::WRL::ComPtr<IMFMediaBuffer> m_pBuffer;
Microsoft::WRL::ComPtr<IMF2DBuffer> m_p2DBuffer;

BOOL m_bLocked;
};
59 changes: 26 additions & 33 deletions Windows/CaptureDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,6 +26,8 @@
#include "Core/HLE/sceUsbCam.h"
#include "Core/Config.h"

using Microsoft::WRL::ComPtr;

namespace MFAPI {
HINSTANCE Mflib;
HINSTANCE Mfplatlib;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -278,7 +281,6 @@ HRESULT ReaderCallback::OnReadSample(
}
}

SafeRelease(&pBuffer);
return hr;
}

Expand Down Expand Up @@ -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);

Expand All @@ -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
);
}
Expand Down Expand Up @@ -609,7 +607,7 @@ bool WindowsCaptureDevice::start(void *startParam) {

if (FAILED(hr)) { break; }

hr = setDeviceParam(pType);
hr = setDeviceParam(pType.Get());

if (SUCCEEDED(hr))
break;
Expand Down Expand Up @@ -654,7 +652,7 @@ bool WindowsCaptureDevice::start(void *startParam) {

if (FAILED(hr)) { break; }

hr = setDeviceParam(pType);
hr = setDeviceParam(pType.Get());

if (SUCCEEDED(hr))
break;
Expand All @@ -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:
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -982,10 +976,9 @@ HRESULT WindowsCaptureDevice::enumDevices() {
}
}
if (SUCCEEDED(hr)) {
hr = EnumDeviceSources(pAttributes, &param.ppDevices, &param.count);
hr = EnumDeviceSources(pAttributes.Get(), &param.ppDevices, &param.count);
}

SafeRelease(&pAttributes);
return hr;
}

Expand Down
9 changes: 5 additions & 4 deletions Windows/CaptureDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>
#include <queue>
#include <thread>
#include <wrl/client.h>

#include "Core/HLE/sceUsbMic.h"

Expand Down Expand Up @@ -193,7 +194,7 @@ class WindowsCaptureDevice {
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; }
Expand Down Expand Up @@ -226,9 +227,9 @@ class WindowsCaptureDevice {
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;
Expand Down
11 changes: 5 additions & 6 deletions Windows/DSoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,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;
}
Expand Down Expand Up @@ -141,8 +140,8 @@ int DSoundAudioBackend::RunThread() {
}
dsBuffer_->Stop();

dsBuffer_->Release();
ds_->Release();
dsBuffer_ = nullptr;
ds_ = nullptr;

threadData_ = 2;
return 0;
Expand Down
9 changes: 4 additions & 5 deletions Windows/DSoundStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,8 +28,8 @@ class DSoundAudioBackend : public WindowsAudioBackend {

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;
Expand Down
Loading
Loading