mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-08 22:07:03 +00:00
[host] remove the invalid usage of SafeRelease
SafeRelease was really useless, derefencing the smart pointers through the use of & releases the value before SafeRelease get's to it. Instead either allow the destructor to handle it's release, or explicityly release it by assigning NULL
This commit is contained in:
parent
f692284f27
commit
a989914fef
@ -74,15 +74,13 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
output->GetDesc(&outputDesc);
|
||||
if (!outputDesc.AttachedToDesktop)
|
||||
{
|
||||
SafeRelease(&output);
|
||||
output = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
m_output = output;
|
||||
if (!m_output)
|
||||
{
|
||||
SafeRelease(&output);
|
||||
SafeRelease(&adapter);
|
||||
DEBUG_ERROR("Failed to get IDXGIOutput1");
|
||||
DeInitialize();
|
||||
return false;
|
||||
@ -91,7 +89,6 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
m_width = outputDesc.DesktopCoordinates.right - outputDesc.DesktopCoordinates.left;
|
||||
m_height = outputDesc.DesktopCoordinates.bottom - outputDesc.DesktopCoordinates.top;
|
||||
|
||||
SafeRelease(&output);
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
@ -99,7 +96,7 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
if (done)
|
||||
break;
|
||||
|
||||
SafeRelease(&adapter);
|
||||
adapter = NULL;
|
||||
}
|
||||
|
||||
if (!done)
|
||||
@ -119,7 +116,6 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
D3D_FEATURE_LEVEL_9_1
|
||||
};
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#define CREATE_FLAGS (D3D11_CREATE_DEVICE_DEBUG)
|
||||
#else
|
||||
@ -137,7 +133,6 @@ bool DXGI::Initialize(CaptureOptions * options)
|
||||
&m_featureLevel,
|
||||
&m_deviceContext
|
||||
);
|
||||
SafeRelease(&adapter);
|
||||
#undef CREATE_FLAGS
|
||||
|
||||
if (FAILED(status))
|
||||
@ -315,14 +310,14 @@ void DXGI::DeInitialize()
|
||||
m_pointerBufSize = 0;
|
||||
}
|
||||
|
||||
SafeRelease(&m_texture[0]);
|
||||
SafeRelease(&m_texture[1]);
|
||||
SafeRelease(&m_texture[2]);
|
||||
SafeRelease(&m_dup);
|
||||
SafeRelease(&m_output);
|
||||
SafeRelease(&m_deviceContext);
|
||||
SafeRelease(&m_device);
|
||||
SafeRelease(&m_dxgiFactory);
|
||||
for(int i = 0; i < _countof(m_texture); ++i)
|
||||
m_texture[i] = NULL;
|
||||
|
||||
m_dup = NULL;
|
||||
m_output = NULL;
|
||||
m_deviceContext = NULL;
|
||||
m_device = NULL;
|
||||
m_dxgiFactory = NULL;
|
||||
|
||||
m_initialized = false;
|
||||
}
|
||||
@ -435,7 +430,7 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs
|
||||
break;
|
||||
|
||||
// no frame data, clean up
|
||||
SafeRelease(&res);
|
||||
res = NULL;
|
||||
ReleaseFrame();
|
||||
|
||||
// if the cursor has been updated
|
||||
@ -469,8 +464,7 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
|
||||
res.QueryInterface(IID_PPV_ARGS(&texture));
|
||||
SafeRelease(&res);
|
||||
res.QueryInterface(IID_PPV_ARGS(&texture));
|
||||
|
||||
if (!texture)
|
||||
{
|
||||
@ -520,7 +514,6 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu
|
||||
return result;
|
||||
|
||||
m_deviceContext->CopyResource(m_texture[0], texture);
|
||||
SafeRelease(&texture);
|
||||
|
||||
result = ReleaseFrame();
|
||||
if (result != GRAB_STATUS_OK)
|
||||
@ -560,17 +553,12 @@ GrabStatus Capture::DXGI::GrabFrameYUV420(struct FrameInfo & frame, struct Curso
|
||||
|
||||
TextureList planes;
|
||||
if (!m_textureConverter->Convert(texture, planes))
|
||||
{
|
||||
SafeRelease(&texture);
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
SafeRelease(&texture);
|
||||
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
ID3D11Texture2DPtr t = planes.at(i);
|
||||
m_deviceContext->CopyResource(m_texture[i], planes.at(i));
|
||||
SafeRelease(&t);
|
||||
m_deviceContext->CopyResource(m_texture[i], t);
|
||||
}
|
||||
|
||||
result = ReleaseFrame();
|
||||
|
13
host/Com.h
13
host/Com.h
@ -39,6 +39,7 @@ _COM_SMARTPTR_TYPEDEF(IMFActivate , __uuidof(IMFActivate
|
||||
_COM_SMARTPTR_TYPEDEF(IMFAttributes , __uuidof(IMFAttributes ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFDXGIDeviceManager , __uuidof(IMFDXGIDeviceManager ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFTransform , __uuidof(IMFTransform ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFMediaEvent , __uuidof(IMFMediaEvent ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFMediaEventGenerator , __uuidof(IMFMediaEventGenerator ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFMediaType , __uuidof(IMFMediaType ));
|
||||
_COM_SMARTPTR_TYPEDEF(IMFSample , __uuidof(IMFSample ));
|
||||
@ -52,14 +53,4 @@ _COM_SMARTPTR_TYPEDEF(ID3D11InputLayout , __uuidof(ID3D11InputLayout
|
||||
_COM_SMARTPTR_TYPEDEF(ID3D11VertexShader , __uuidof(ID3D11VertexShader ));
|
||||
_COM_SMARTPTR_TYPEDEF(ID3D11PixelShader , __uuidof(ID3D11PixelShader ));
|
||||
_COM_SMARTPTR_TYPEDEF(ID3D11SamplerState , __uuidof(ID3D11SamplerState ));
|
||||
_COM_SMARTPTR_TYPEDEF(ID3D11Buffer , __uuidof(ID3D11Buffer ));
|
||||
|
||||
|
||||
template <class T> void SafeRelease(T **ppT)
|
||||
{
|
||||
if (*ppT)
|
||||
{
|
||||
(*ppT)->Release();
|
||||
*ppT = NULL;
|
||||
}
|
||||
}
|
||||
_COM_SMARTPTR_TYPEDEF(ID3D11Buffer , __uuidof(ID3D11Buffer ));
|
@ -74,7 +74,7 @@ bool MFT::H264::Initialize(ID3D11DevicePtr device, unsigned int width, unsigned
|
||||
|
||||
ID3D10MultithreadPtr mt(m_device);
|
||||
mt->SetMultithreadProtected(TRUE);
|
||||
SafeRelease(&mt);
|
||||
mt = NULL;
|
||||
|
||||
typeInfo.guidMajorType = MFMediaType_Video;
|
||||
typeInfo.guidSubtype = MFVideoFormat_H264;
|
||||
@ -131,7 +131,7 @@ bool MFT::H264::Initialize(ID3D11DevicePtr device, unsigned int width, unsigned
|
||||
attribs->GetUINT32(MF_SA_D3D11_AWARE, &d3d11Aware);
|
||||
if (async)
|
||||
attribs->SetUINT32(MF_TRANSFORM_ASYNC_UNLOCK, TRUE);
|
||||
SafeRelease(&attribs);
|
||||
attribs = NULL;
|
||||
|
||||
status = m_mfTransform.QueryInterface(IID_PPV_ARGS(&m_mediaEventGen));
|
||||
if (FAILED(status))
|
||||
@ -179,8 +179,8 @@ bool MFT::H264::Initialize(ID3D11DevicePtr device, unsigned int width, unsigned
|
||||
MFSetAttributeRatio(outType, MF_MT_FRAME_RATE , 60 , 1 );
|
||||
MFSetAttributeRatio(outType, MF_MT_PIXEL_ASPECT_RATIO, 1 , 1 );
|
||||
|
||||
status = m_mfTransform->SetOutputType(0, outType, 0);
|
||||
SafeRelease(&outType);
|
||||
status = m_mfTransform->SetOutputType(0, outType, 0);
|
||||
outType = NULL;
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to set the output media type on the H264 encoder MFT", status);
|
||||
@ -200,7 +200,7 @@ bool MFT::H264::Initialize(ID3D11DevicePtr device, unsigned int width, unsigned
|
||||
MFSetAttributeRatio(inType, MF_MT_PIXEL_ASPECT_RATIO, 1 , 1 );
|
||||
|
||||
status = m_mfTransform->SetInputType(0, inType, 0);
|
||||
SafeRelease(&inType);
|
||||
inType = NULL;
|
||||
if (FAILED(status))
|
||||
{
|
||||
DEBUG_WINERROR("Failed to set the input media type on the H264 encoder MFT", status);
|
||||
@ -224,9 +224,9 @@ void MFT::H264::DeInitialize()
|
||||
m_mfTransform->DeleteInputStream(0);
|
||||
}
|
||||
|
||||
SafeRelease(&m_mediaEventGen);
|
||||
SafeRelease(&m_mfTransform);
|
||||
SafeRelease(&m_mfDeviceManager);
|
||||
m_mediaEventGen = NULL;
|
||||
m_mfTransform = NULL;
|
||||
m_mfDeviceManager = NULL;
|
||||
|
||||
if (m_encodeEvent)
|
||||
{
|
||||
@ -240,7 +240,7 @@ void MFT::H264::DeInitialize()
|
||||
if (m_mfActivation)
|
||||
{
|
||||
m_mfActivation->ShutdownObject();
|
||||
SafeRelease(&m_mfActivation);
|
||||
m_mfActivation = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +307,6 @@ bool MFT::H264::ProvideFrame(ID3D11Texture2DPtr texture)
|
||||
DWORD length;
|
||||
imfBuffer->GetContiguousLength(&length);
|
||||
buffer->SetCurrentLength(length);
|
||||
SafeRelease(&imfBuffer);
|
||||
|
||||
IMFSamplePtr sample;
|
||||
MFCreateSample(&sample);
|
||||
@ -320,8 +319,6 @@ bool MFT::H264::ProvideFrame(ID3D11Texture2DPtr texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SafeRelease(&sample);
|
||||
SafeRelease(&buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -364,9 +361,11 @@ bool MFT::H264::GetFrame(void * buffer, const size_t bufferSize, unsigned int &
|
||||
memcpy(buffer, pixels, curLen);
|
||||
mb->Unlock();
|
||||
|
||||
SafeRelease(&mb);
|
||||
SafeRelease(&outDataBuffer.pSample);
|
||||
SafeRelease(&outDataBuffer.pEvents);
|
||||
if (outDataBuffer.pSample)
|
||||
outDataBuffer.pSample->Release();
|
||||
|
||||
if (outDataBuffer.pEvents)
|
||||
outDataBuffer.pEvents->Release();
|
||||
|
||||
dataLen = curLen;
|
||||
return true;
|
||||
@ -376,7 +375,7 @@ STDMETHODIMP MFT::H264::Invoke(IMFAsyncResult * pAsyncResult)
|
||||
{
|
||||
HRESULT status, evtStatus;
|
||||
MediaEventType meType = MEUnknown;
|
||||
IMFMediaEvent *pEvent = NULL;
|
||||
IMFMediaEventPtr pEvent = NULL;
|
||||
|
||||
status = m_mediaEventGen->EndGetEvent(pAsyncResult, &pEvent);
|
||||
if (FAILED(status))
|
||||
@ -388,14 +387,12 @@ STDMETHODIMP MFT::H264::Invoke(IMFAsyncResult * pAsyncResult)
|
||||
status = pEvent->GetStatus(&evtStatus);
|
||||
if (FAILED(status))
|
||||
{
|
||||
SafeRelease(&pEvent);
|
||||
DEBUG_WINERROR("GetStatus", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (FAILED(evtStatus))
|
||||
{
|
||||
SafeRelease(&pEvent);
|
||||
DEBUG_WINERROR("evtStatus", evtStatus);
|
||||
return evtStatus;
|
||||
}
|
||||
@ -403,11 +400,9 @@ STDMETHODIMP MFT::H264::Invoke(IMFAsyncResult * pAsyncResult)
|
||||
status = pEvent->GetType(&meType);
|
||||
if (FAILED(status))
|
||||
{
|
||||
SafeRelease(&pEvent);
|
||||
DEBUG_WINERROR("GetType", status);
|
||||
return status;
|
||||
}
|
||||
SafeRelease(&pEvent);
|
||||
|
||||
switch (meType)
|
||||
{
|
||||
|
@ -271,21 +271,21 @@ bool TextureConverter::IntializeBuffers()
|
||||
|
||||
void TextureConverter::DeInitialize()
|
||||
{
|
||||
SafeRelease(&m_samplerState );
|
||||
SafeRelease(&m_indexBuffer );
|
||||
SafeRelease(&m_vertexBuffer );
|
||||
m_samplerState = NULL;
|
||||
m_indexBuffer = NULL;
|
||||
m_indexBuffer = NULL;
|
||||
|
||||
for(int i = 0; i < _countof(m_targetTexture); ++i)
|
||||
{
|
||||
SafeRelease(&m_shaderView [i]);
|
||||
SafeRelease(&m_renderView [i]);
|
||||
SafeRelease(&m_targetTexture[i]);
|
||||
m_shaderView [i] = NULL;
|
||||
m_renderView [i] = NULL;
|
||||
m_targetTexture[i] = NULL;
|
||||
}
|
||||
|
||||
SafeRelease(&m_vertexShader);
|
||||
SafeRelease(&m_psConversion);
|
||||
SafeRelease(&m_layout );
|
||||
SafeRelease(&m_psCopy );
|
||||
m_vertexShader = NULL;
|
||||
m_psConversion = NULL;
|
||||
m_layout = NULL;
|
||||
m_psCopy = NULL;
|
||||
}
|
||||
|
||||
bool TextureConverter::Convert(ID3D11Texture2DPtr texture, TextureList & output)
|
||||
@ -351,7 +351,7 @@ bool TextureConverter::Convert(ID3D11Texture2DPtr texture, TextureList & output)
|
||||
m_deviceContext->PSSetShader (m_psConversion, NULL, 0);
|
||||
|
||||
m_deviceContext->DrawIndexed(m_indexCount, 0, 0);
|
||||
SafeRelease(&textureView);
|
||||
textureView = NULL;
|
||||
|
||||
D3D11_RENDER_TARGET_VIEW_DESC targetDesc;
|
||||
ZeroMemory(&targetDesc, sizeof(targetDesc));
|
||||
@ -395,7 +395,6 @@ bool TextureConverter::Convert(ID3D11Texture2DPtr texture, TextureList & output)
|
||||
result = m_device->CreateRenderTargetView(dest, &targetDesc, &view);
|
||||
if (FAILED(result))
|
||||
{
|
||||
SafeRelease(&dest);
|
||||
delete[] renderViews;
|
||||
DeInitialize();
|
||||
DEBUG_ERROR("Failed to create the target view");
|
||||
@ -411,7 +410,7 @@ bool TextureConverter::Convert(ID3D11Texture2DPtr texture, TextureList & output)
|
||||
m_deviceContext->DrawIndexed(m_indexCount, 0, 0);
|
||||
|
||||
output.push_back(dest);
|
||||
SafeRelease(&view);
|
||||
view = NULL;
|
||||
}
|
||||
|
||||
delete[] renderViews;
|
||||
|
Loading…
Reference in New Issue
Block a user