1 Star 1 Fork 1

柏松/DShowCaptureToLocal

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SampleGrabberCB.cpp 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
柏松 提交于 2017-08-31 15:25 . 加入回调函数中控制帧率
#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()
{
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/poisson/DShowCaptureToLocal.git
git@gitee.com:poisson/DShowCaptureToLocal.git
poisson
DShowCaptureToLocal
DShowCaptureToLocal
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385