📄 videosurfacerenderer.cpp
字号:
// VideoSurfaceRenderer.cpp: implementation of the CVideoSurfaceRenderer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "VideoSurfaceRenderer.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// CVideoSurfaceRenderer constructor
//-----------------------------------------------------------------------------
CVideoSurfaceRenderer::CVideoSurfaceRenderer( LPUNKNOWN pUnk, HRESULT *phr )
: CBaseVideoRenderer(__uuidof(CLSID_VideoSurfaceRenderer),
NAME("SurfaceRenderer"), pUnk, phr)
{
// Store and AddRef the texture for our use.
*phr = S_OK;
apSurface[0] = NULL;
apSurface[1] = NULL;
m_front = 0;
}
//-----------------------------------------------------------------------------
// CVideoSurfaceRenderer destructor
//-----------------------------------------------------------------------------
CVideoSurfaceRenderer::~CVideoSurfaceRenderer()
{
// Do nothing
}
//-----------------------------------------------------------------------------
// CheckMediaType: This method forces the graph to give us an R8G8B8 video
// type, making our copy to texture memory trivial.
//-----------------------------------------------------------------------------
HRESULT CVideoSurfaceRenderer::CheckMediaType(const CMediaType *pmt)
{
HRESULT hr = E_FAIL;
VIDEOINFO *pvi;
// Reject the connection if this is not a video type
if( *pmt->FormatType() != FORMAT_VideoInfo ) {
return E_INVALIDARG;
}
// Only accept RGB24
pvi = (VIDEOINFO *)pmt->Format();
if(IsEqualGUID( *pmt->Type(), MEDIATYPE_Video) &&
IsEqualGUID( *pmt->Subtype(), MEDIASUBTYPE_RGB24))
{
hr = S_OK;
}
return hr;
}
//-----------------------------------------------------------------------------
// SetMediaType: Graph connection has been made.
//-----------------------------------------------------------------------------
HRESULT CVideoSurfaceRenderer::SetMediaType(const CMediaType *pmt)
{
// HRESULT hr;
// Retrive the size of this media type
VIDEOINFO *pviBmp; // Bitmap info header
pviBmp = (VIDEOINFO *)pmt->Format();
m_lVidWidth = pviBmp->bmiHeader.biWidth;
m_lVidHeight = abs(pviBmp->bmiHeader.biHeight);
m_lVidPitch = (m_lVidWidth * 3 + 3) & ~(3); // We are forcing RGB24
// Create the texture that maps to this media type
return S_OK;
}
//-----------------------------------------------------------------------------
// DoRenderSample: A sample has been delivered. Copy it to the texture.
//-----------------------------------------------------------------------------
HRESULT CVideoSurfaceRenderer::DoRenderSample( IMediaSample * pSample )
{
BYTE *pBmpBuffer;
// BYTE *pTxtBuffer; // Bitmap buffer, texture buffer
// LONG lTxtPitch; // Pitch of bitmap, texture
m_front++;
m_front %= 2;
CDxSurface* pSurface = apSurface[(m_front+1)%2];
if(NULL == pSurface)
return S_OK;
// Get the video bitmap buffer
pSample->GetPointer( &pBmpBuffer );
pSurface->LoadFromRGBData( pBmpBuffer, m_lVidWidth, m_lVidHeight, TRUE );
/*
// Lock the Texture
D3DLOCKED_RECT d3dlr;
if (FAILED(g_pTexture->LockRect(0, &d3dlr, 0, 0)))
return E_FAIL;
// Get the texture buffer & pitch
pTxtBuffer = static_cast<byte *>(d3dlr.pBits);
lTxtPitch = d3dlr.Pitch;
// Copy the bits
// OPTIMIZATION OPPORTUNITY: Use a video and texture
// format that allows a simpler copy than this one.
if (g_TextureFormat == D3DFMT_A8R8G8B8) {
for(int y = 0; y < m_lVidHeight; y++ ) {
BYTE *pBmpBufferOld = pBmpBuffer;
BYTE *pTxtBufferOld = pTxtBuffer;
for (int x = 0; x < m_lVidWidth; x++) {
pTxtBuffer[0] = pBmpBuffer[0];
pTxtBuffer[1] = pBmpBuffer[1];
pTxtBuffer[2] = pBmpBuffer[2];
pTxtBuffer[3] = 0xff;
pTxtBuffer += 4;
pBmpBuffer += 3;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}
if (g_TextureFormat == D3DFMT_A1R5G5B5) {
for(int y = 0; y < m_lVidHeight; y++ ) {
BYTE *pBmpBufferOld = pBmpBuffer;
BYTE *pTxtBufferOld = pTxtBuffer;
for (int x = 0; x < m_lVidWidth; x++) {
*(WORD *)pTxtBuffer =
0x8000 +
((pBmpBuffer[2] & 0xF8) << 7) +
((pBmpBuffer[1] & 0xF8) << 2) +
(pBmpBuffer[0] >> 3);
pTxtBuffer += 2;
pBmpBuffer += 3;
}
pBmpBuffer = pBmpBufferOld + m_lVidPitch;
pTxtBuffer = pTxtBufferOld + lTxtPitch;
}
}
// Unlock the Texture
if (FAILED(g_pTexture->UnlockRect(0)))
return E_FAIL;
*/
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -