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