2,543
社区成员
发帖
与我相关
我的任务
分享
HRESULT CBallStream::FillBuffer(IMediaSample *pms)
{
CheckPointer(pms,E_POINTER);
ASSERT(m_Ball);
BYTE *pData;
long lDataLen;
pms->GetPointer(&pData); //得到Sample的数据指针,即获取输出数据指针
lDataLen = pms->GetSize(); //得到数据长度
ZeroMemory(pData, lDataLen);
{
CAutoLock cAutoLockShared(&m_cSharedState);
if (ffmpeg_ReadOneFrame())
{
//反转图像 ,否则生成的图像是上下调到的
/* pFrame->data[0] += pFrame->linesize[0] * (pCodecCtx->height - 1);
pFrame->linesize[0] *= -1;
pFrame->data[1] += pFrame->linesize[1] * (pCodecCtx->height / 2 - 1);
pFrame->linesize[1] *= -1;
pFrame->data[2] += pFrame->linesize[2] * (pCodecCtx->height / 2 - 1);
pFrame->linesize[2] *= -1;*/
//转换图像格式,将解压出来的YUV420P的图像转换为BRG24的图像
sws_scale(pSwsCtx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
//SaveAsBMP(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i++, 24);
CopyMemory(pData, pFrameRGB->data[0], pCodecCtx->width*pCodecCtx->height*3);
}
// If we haven't just cleared the buffer delete the old
// ball and move the ball on
/* m_Ball->MoveBall(m_rtSampleTime - (LONG) m_iRepeatTime);
m_Ball->PlotBall(pData, 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);
}
pms->SetSyncPoint(TRUE);
return NOERROR;
} // FillBuffer