当前位置: 代码迷 >> 多媒体/流媒体开发 >> DirectShow Ball filter 的FillBuffer函数有关问题
  详细解决方案

DirectShow Ball filter 的FillBuffer函数有关问题

热度:6595   发布时间:2013-02-26 00:00:00.0
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 
  相关解决方案