代码拉取完成,页面将自动刷新
#include "stdafx.h"
#include "SampleGrabberCB.h"
CSampleGrabberCB::CSampleGrabberCB(void)
//:m_mxMsgLog(FALSE, NULL, NULL)
{
//m_fp_dst = NULL;
//m_pParam = NULL;
//m_pPic_in = NULL;
//m_pPic_out = NULL;
//m_pHandle = NULL;
m_bBeginEncode = FALSE;
m_bEndEncode = FALSE;
m_bFirst = TRUE;
m_nFrameIndex = 0;
//m_sSavePath = _T("");
m_ulBitRate = 0;
//m_arrGrabDataArr.RemoveAll();
//m_hMainExitEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
}
CSampleGrabberCB::~CSampleGrabberCB(void)
{
}
ULONG STDMETHODCALLTYPE CSampleGrabberCB::AddRef()
{
return 2;
}
ULONG STDMETHODCALLTYPE CSampleGrabberCB::Release()
{
return 1;
}
HRESULT STDMETHODCALLTYPE CSampleGrabberCB::QueryInterface(REFIID riid, void ** ppv)
{
if( riid == IID_ISampleGrabberCB || riid == IID_IUnknown )
{
*ppv = (void *) static_cast<ISampleGrabberCB*> ( this );
return NOERROR;
}
return E_NOINTERFACE;
}
HRESULT STDMETHODCALLTYPE CSampleGrabberCB::SampleCB(double SampleTime, IMediaSample *pSample)
{
return 0;
}
HRESULT STDMETHODCALLTYPE CSampleGrabberCB::BufferCB(double SampleTime, BYTE *pBuffer, long BufferLen)
{
CString str;
str.Format(_T("\n BufferCB--lBufferSize:%ld,SampleTime%7.4f,pBuffer:%d\n"), BufferLen, SampleTime, pBuffer);
OutputDebugString(str);
if (m_bBeginEncode)
{
BYTE *pcmData = new BYTE[BufferLen];
memset(pcmData, 0, BufferLen);
GrabDataInfo data;
data.pData = pcmData;
data.nDataSize = BufferLen;
data.dSampleTime = SampleTime;
m_arrGrabDataArr.push_back(data);
}
return 0;
}
//RGB24תYUV420
BOOL CSampleGrabberCB::RGB2YUV(LPBYTE RgbBuf, UINT nWidth, UINT nHeight, LPBYTE yuvBuf, unsigned long *len)
{
if (RgbBuf == NULL)
{
return FALSE;
}
int i, j;
unsigned char*bufY, *bufU, *bufV, *bufRGB;
memset(yuvBuf,0,(unsigned int )*len);
bufY = yuvBuf;
bufV = yuvBuf + nWidth * nHeight;
bufU = bufV + (nWidth * nHeight* 1/4);
*len = 0;
unsigned char y, u, v, r, g, b;
unsigned int ylen = nWidth * nHeight;
unsigned int ulen = (nWidth * nHeight)/4;
unsigned int vlen = (nWidth * nHeight)/4;
for (j = 0; j<nHeight;j++)
{
bufRGB = RgbBuf + nWidth * (nHeight - 1 - j) * 3 ;
for (i = 0;i<nWidth;i++)
{
int pos = nWidth * i + j;
r = *(bufRGB++);
g = *(bufRGB++);
b = *(bufRGB++);
y = (unsigned char)( ( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16 ;
u = (unsigned char)( ( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128 ;
v = (unsigned char)( ( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128 ;
*(bufY++) = max( 0, min(y, 255 ));
if (j%2==0&&i%2 ==0)
{
if (u>255)
{
u=255;
}
if (u<0)
{
u = 0;
}
*(bufU++) =u;
//u
}
else
{
//v
if (i%2==0)
{
if (v>255)
{
v = 255;
}
if (v<0)
{
v = 0;
}
*(bufV++) =v;
}
}
}
}
*len = nWidth * nHeight+(nWidth * nHeight)/2;
return TRUE;
}
void CSampleGrabberCB::VideoDeal()
{
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。