读书人

DirectShow Ball filter 的FillBuffer

发布时间: 2012-03-05 11:54:02 作者: rapoo

DirectShow Ball filter 的FillBuffer函数问题
DirectShow Ball filter 的FillBuffer函数问题

DirectShow Ball filter 的范例 (D:\DXSDK\Samples\C++\DirectShow\Filters\Ball)

FillBuffer函数 是对 Sample数据的填充。例1 中可见到小球在跳动.
例2的想法是对Sample填充一种颜色. [RGB(128, 128, 128)或RGB(0x80, 0x80, 0x80) , 不是黑色],
但例2的效果是黑屏,不知什么原因?是填充FillBuffer函数写得不对?

例1:
HRESULT CBallStream::FillBuffer(IMediaSample *pms)
{
BYTE *pData;
long lDataLen;

pms->GetPointer(&pData);
lDataLen = pms->GetSize();

// If true then we clear the output buffer and don't attempt to
// erase a previous drawing of the ball - this will be the case
// when we start running as the buffer will be full of rubbish
if( m_bZeroMemory ) {
ZeroMemory( pData, lDataLen );
}

{
CAutoLock cAutoLockShared(&m_cSharedState);

// If we haven't just cleared the buffer delete the old
// ball and move the ball on

if( !m_bZeroMemory ){
BYTE aZeroes[ 4 ] = { 0, 0, 0, 0 };
m_Ball->PlotBall(pData, lDataLen, aZeroes, m_iPixelSize);
m_Ball->MoveBall(m_rtSampleTime - (LONG) m_iRepeatTime);
}

m_Ball->PlotBall(pData, lDataLen, m_BallPixel, m_iPixelSize);

// The current time is the sample's start
CRefTime rtStart = m_rtSampleTime;

// Increment to find the finish time
m_rtSampleTime += (LONG)m_iRepeatTime;

pms->SetTime((REFERENCE_TIME *) &rtStart,(REFERENCE_TIME *) &m_rtSampleTime);
}

m_bZeroMemory = FALSE;
pms->SetSyncPoint(TRUE);

return NOERROR;

} // FillBuffer




例2:
HRESULT CBallStream::FillBuffer(IMediaSample *pms)
{
BYTE *pData;
long lDataLen;

pms->GetPointer(&pData);
lDataLen = pms->GetSize();

// If true then we clear the output buffer and don't attempt to
// erase a previous drawing of the ball - this will be the case
// when we start running as the buffer will be full of rubbish
if( m_bZeroMemory ) {
ZeroMemory( pData, lDataLen );
}


#if 1
BYTE *pTmpData;
pTmpData = new BYTE[230400]; //320*240*3 = 230400
memset(pTmpData, 0x80, 230400); //128
//FillMemory(buf, sizeof(buf), 0);
pData = pTmpData;
lDataLen = 230400;

// The current time is the sample's start
CRefTime rtStart = m_rtSampleTime;
// Increment to find the finish time
m_rtSampleTime += (LONG)m_iRepeatTime;
pms->SetTime((REFERENCE_TIME *) &rtStart,(REFERENCE_TIME *) &m_rtSampleTime);

#endif



m_bZeroMemory = FALSE;
pms->SetSyncPoint(TRUE);


#if 1
delete [] pTmpData;
pTmpData = NULL;
#endif

return NOERROR;

} // FillBuffer


[解决办法]
应该是你填充数据有问题

[解决办法]
例2:
HRESULT CBallStream::FillBuffer(IMediaSample *pms)
{
BYTE *pData;
long lDataLen;

pms->GetPointer(&pData);
lDataLen = pms->GetSize();

// 只要这一行就行了
memset(pData, 0x80, lDataLen); //128



// The current time is the sample's start
CRefTime rtStart = m_rtSampleTime;
// Increment to find the finish time
m_rtSampleTime += (LONG)m_iRepeatTime;
pms->SetTime((REFERENCE_TIME *) &rtStart,(REFERENCE_TIME *) &m_rtSampleTime);


m_bZeroMemory = FALSE;
pms->SetSyncPoint(TRUE);

//最好加上这个
pms->SetActualDataLength(...);

return NOERROR;

} // FillBuffer

读书人网 >多媒体

热点推荐