本文整理汇总了C++中LPDIRECT3DSURFACE9::GetDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DSURFACE9::GetDevice方法的具体用法?C++ LPDIRECT3DSURFACE9::GetDevice怎么用?C++ LPDIRECT3DSURFACE9::GetDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DSURFACE9
的用法示例。
在下文中一共展示了LPDIRECT3DSURFACE9::GetDevice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessFrame
STDMETHODIMP CLAVSubtitleConsumer::ProcessFrame(LAVFrame *pFrame)
{
CheckPointer(m_pProvider, E_FAIL);
HRESULT hr = S_OK;
LPDIRECT3DSURFACE9 pSurface = nullptr;
// Wait for the requested frame
m_evFrame.Wait();
if (m_SubtitleFrame != nullptr) {
int count = 0;
if (FAILED(m_SubtitleFrame->GetBitmapCount(&count))) {
count = 0;
}
if (count == 0) {
SafeRelease(&m_SubtitleFrame);
return S_FALSE;
}
BYTE *data[4] = {0};
ptrdiff_t stride[4] = {0};
LAVPixelFormat format = pFrame->format;
int bpp = pFrame->bpp;
if (pFrame->format == LAVPixFmt_DXVA2) {
// Copy the surface, if required
if (!(pFrame->flags & LAV_FRAME_FLAG_BUFFER_MODIFY)) {
IMediaSample *pOrigSample = (IMediaSample *)pFrame->data[0];
LPDIRECT3DSURFACE9 pOrigSurface = (LPDIRECT3DSURFACE9)pFrame->data[3];
hr = m_pLAVVideo->GetD3DBuffer(pFrame);
if (FAILED(hr)) {
DbgLog((LOG_TRACE, 10, L"CLAVSubtitleConsumer::ProcessFrame: getting a new D3D buffer failed"));
} else {
IMediaSample *pNewSample = (IMediaSample *)pFrame->data[0];
pSurface = (LPDIRECT3DSURFACE9)pFrame->data[3];
IDirect3DDevice9 *pDevice = nullptr;
if (SUCCEEDED(hr = pSurface->GetDevice(&pDevice))) {
hr = pDevice->StretchRect(pOrigSurface, nullptr, pSurface, nullptr, D3DTEXF_NONE);
if (SUCCEEDED(hr)) {
pFrame->flags |= LAV_FRAME_FLAG_BUFFER_MODIFY|LAV_FRAME_FLAG_DXVA_NOADDREF;
pOrigSurface = nullptr;
// Release the surface, we only want to hold a ref on the media buffer
pSurface->Release();
}
SafeRelease(&pDevice);
}
if (FAILED(hr)) {
DbgLog((LOG_TRACE, 10, L"CLAVSubtitleConsumer::ProcessFrame: processing d3d buffer failed, restoring previous buffer"));
pNewSample->Release();
pSurface->Release();
pFrame->data[0] = (BYTE *)pOrigSample;
pFrame->data[3] = (BYTE *)pOrigSurface;
}
}
}
pSurface = (LPDIRECT3DSURFACE9)pFrame->data[3];
D3DSURFACE_DESC surfaceDesc;
pSurface->GetDesc(&surfaceDesc);
D3DLOCKED_RECT LockedRect;
hr = pSurface->LockRect(&LockedRect, nullptr, 0);
if (FAILED(hr)) {
DbgLog((LOG_TRACE, 10, L"pSurface->LockRect failed (hr: %X)", hr));
SafeRelease(&m_SubtitleFrame);
return E_FAIL;
}
data[0] = (BYTE *)LockedRect.pBits;
data[1] = data[0] + (surfaceDesc.Height * LockedRect.Pitch);
stride[0] = LockedRect.Pitch;
stride[1] = LockedRect.Pitch;
format = LAVPixFmt_NV12;
bpp = 8;
} else {
if (!(pFrame->flags & LAV_FRAME_FLAG_BUFFER_MODIFY)) {
CopyLAVFrameInPlace(pFrame);
}
memcpy(&data, &pFrame->data, sizeof(pFrame->data));
memcpy(&stride, &pFrame->stride, sizeof(pFrame->stride));
}
RECT videoRect;
::SetRect(&videoRect, 0, 0, pFrame->width, pFrame->height);
RECT subRect;
m_SubtitleFrame->GetOutputRect(&subRect);
ULONGLONG id;
POINT position;
SIZE size;
const uint8_t *rgbData;
int pitch;
for (int i = 0; i < count; i++) {
if (FAILED(m_SubtitleFrame->GetBitmap(i, &id, &position, &size, (LPCVOID *)&rgbData, &pitch))) {
DbgLog((LOG_TRACE, 10, L"GetBitmap() failed on index %d", i));
//.........这里部分代码省略.........