//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#include <iostream>
#include "videoInput.h"
#include <tchar.h>
//Include Directshow stuff here so we don't worry about needing all the h files.
#include <dshow.h>
//#include "streams.h"
#pragma include_alias( "dxtrans.h", "qedit.h" )
#define __IDxtCompositor_INTERFACE_DEFINED__
#define __IDxtAlphaSetter_INTERFACE_DEFINED__
#define __IDxtJpeg_INTERFACE_DEFINED__
#define __IDxtKey_INTERFACE_DEFINED__
#include <uuids.h>
#include <aviriff.h>
#include <windows.h>
//for threading
#include <process.h>
#ifndef HEADER
#define HEADER(pVideoInfo) (&(((VIDEOINFOHEADER *) (pVideoInfo))->bmiHeader))
#endif
// Due to a missing qedit.h in recent Platform SDKs, we've replicated the relevant contents here
// #include <qedit.h>
MIDL_INTERFACE("0579154A-2B53-4994-B0D0-E773148EFF85")
ISampleGrabberCB : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE SampleCB(
double SampleTime,
IMediaSample *pSample) = 0;
virtual HRESULT STDMETHODCALLTYPE BufferCB(
double SampleTime,
BYTE *pBuffer,
long BufferLen) = 0;
};
MIDL_INTERFACE("6B652FFF-11FE-4fce-92AD-0266B5D7C78F")
ISampleGrabber : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE SetOneShot(
BOOL OneShot) = 0;
virtual HRESULT STDMETHODCALLTYPE SetMediaType(
const AM_MEDIA_TYPE *pType) = 0;
virtual HRESULT STDMETHODCALLTYPE GetConnectedMediaType(
AM_MEDIA_TYPE *pType) = 0;
virtual HRESULT STDMETHODCALLTYPE SetBufferSamples(
BOOL BufferThem) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentBuffer(
/* [out][in] */ long *pBufferSize,
/* [out] */ long *pBuffer) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentSample(
/* [retval][out] */ IMediaSample **ppSample) = 0;
virtual HRESULT STDMETHODCALLTYPE SetCallback(
ISampleGrabberCB *pCallback,
long WhichMethodToCallback) = 0;
};
EXTERN_C const CLSID CLSID_SampleGrabber;
EXTERN_C const IID IID_ISampleGrabber;
EXTERN_C const CLSID CLSID_NullRenderer;
//use videoInput::setVerbose to change
static bool verbose = true;
//use videoInput::setComMultiThreaded to change
static bool VI_COM_MULTI_THREADED = false;
/////////////////////////// HANDY FUNCTIONS /////////////////////////////
void MyFreeMediaType(AM_MEDIA_TYPE& mt){
if (mt.cbFormat != 0)
{
CoTaskMemFree((PVOID)mt.pbFormat);
mt.cbFormat = 0;
mt.pbFormat = NULL;
}
if (mt.pUnk != NULL)
{
// Unecessary because pUnk should not be used, but safest.
mt.pUnk->Release();
mt.pUnk = NULL;
}
}
void MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
{
if (pmt != NULL)
{
MyFreeMediaType(*pmt);
CoTaskMemFree(pmt);
}
}
////////////////////////////// CALLBACK ////////////////////////////////
//Callback class
class SampleGrabberCallback : public ISampleGrabberCB{
public:
//------------------------------------------------
SampleGrabberCallback(){
InitializeCriticalSection(&critSection);
freezeCheck = 0;
bufferSetup = false;
newFrame = false;
latestBufferLength = 0;
hEvent = CreateEvent(NULL, true, false, NULL);
}
//------------------------------------------------
~SampleGrabberCallback(){
ptrBuffer = NULL;
DeleteCriticalSection(&critSection);
CloseHandle(hEvent);
if(bufferSetup){
delete [] pixels;
}
}
//------------------------------------------------
bool setupBuffer(int numBytesIn){
if(bufferSetup){
return false;
}else{
numBytes = numBytesIn;
pixels = new unsigned char[numBytes];
bufferSetup = true;
newFrame = false;
latestBufferLength = 0;
}
return true;
}
//------------------------------------------------
STDMETHODIMP_(ULONG) AddRef() { return 1; }
STDMETHODIMP_(ULONG) Release() { return 2; }
//------------------------------------------------
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject){
*ppvObject = static_cast<ISampleGrabberCB*>(this);
return S_OK;
}
//This method is meant to have less overhead
//------------------------------------------------
STDMETHODIMP SampleCB(double Time, IMediaSample *pSample){
if(WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0) return S_OK;
HRESULT hr = pSample->GetPointer(&ptrBuffer);
if(hr == S_OK){
latestBufferLength = pSample->GetActualDataLength();
if(latestBufferLength == numBytes){
EnterCriticalSection(&critSection);
memcpy(pixels, ptrBuffer, latestBufferLength);
newFrame = true;
freezeCheck = 1;
LeaveCriticalSection(&critSection);
SetEvent(hEvent);
}else{
printf("ERROR: SampleCB() - buffer sizes do not match\n");
}
}
return S_OK;
}
//This method is meant to have more overhead
STDMETHODIMP BufferCB(double Time, BYTE *pBuffer, long BufferLen){
return E_NOTIMPL;
}
int freezeCheck;
int latestBufferLength;
int numBytes;
bool newFrame;
bool bufferSetup;
unsigned char * pixels;
unsigned char * ptrBuffer;
CRITICAL_SECTION critSection;
HANDLE hEvent;
};
////////////////////////////// VIDEO DEVICE ////////////////////////////////
// ----------------------------------------------------------------------
// Should this class also be the callback?
//
// ----------------------------------------------------------------------
videoDevice::videoDevice(){
pCaptureGraph = NULL; // Capture graph builder object
pGraph = NULL; // Graph builder object
pControl = NULL; // Media control object
pVideoInputFilter = NULL; // Video Capture filter
pGrabber = NULL; // Grabs frame
pDestFilter = NULL; // Null Renderer Filter
pGrabberF = NULL; // Grabber Filter
pMediaEvent = NULL;
streamConf = NULL;
pAmMediaType = NULL;
//This is our callback class that processes the frame.
sgCallback = new SampleGrabberCallback();
sgCallback->newFrame = false;
//Default values for capture type
videoType = MEDIASUBTYPE_RGB24;
connection = PhysConn_Video_Composite;
storeConn = 0;
videoSize = 0;
width = 0;
height = 0;
tryWidth = 0;
tryHeight = 0;
nFramesForReconnect= 10000;
nFramesRunning = 0;
myID = -1;
tryDiffSize = false;
useCrossbar = false;
readyToCapture = false;
sizeSet = false;
setupStarted = false;
specificFormat = false;
autoReconnect = false;
requestedFrameTime = -1;
memset(wDeviceName, 0, sizeof(WCHAR) * 255);
memset(nDeviceName, 0, sizeof(char) * 255);
}
// ----------------------------------------------------------------------
// The only place we are doing new
//
// ----------------------------------------------------------------------
void videoDevice::setSize(int w, int h){
if(sizeSet){
if(verbose)printf("SETUP: Error device size should not be set more than once \n");
}
else
{
width = w;
height = h;
videoSize = w*h*3;
sizeSet = true;
pixels = new unsigned char[videoSize];
pBuffer = new char[videoSize];
memset(pixels, 0 , videoSize);
sgCallback->setupBuffer(videoSize);
}
}
// ----------------------------------------------------------------------
// Borrowed from the SDK, use it to take apart the graph from
// the capture device downstream to the null renderer
// --------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
VideoInput
共226个文件
h:186个
lib:23个
cpp:6个
需积分: 9 14 下载量 135 浏览量
2016-03-17
16:50:44
上传
评论
收藏 23.31MB ZIP 举报
温馨提示
VideoInput库源码 以及demo VS2010工程 欢迎下载
资源推荐
资源详情
资源评论
收起资源包目录
VideoInput (226个子文件)
videoInput.cpp 73KB
triangleApp.cpp 4KB
imageTexture.cpp 3KB
videoInputBasicDemo.cpp 2KB
simpleApp.cpp 1KB
stdafx.cpp 298B
videoInputBasicDemo.exe 90KB
strmif.h 795KB
Segment.h 552KB
Mstve.h 421KB
tuner.h 385KB
qedit.h 292KB
Mstvca.h 271KB
ddraw.h 234KB
ksmedia.h 221KB
dinput.h 218KB
strsafe.h 210KB
control.h 174KB
dxtrans.h 147KB
ks.h 140KB
bdaiface.h 123KB
dsound.h 105KB
dmusici.h 104KB
d3dx9mesh.h 101KB
d3d9.h 98KB
vmr9.h 92KB
d3d.h 86KB
dplay.h 83KB
d3dtypes.h 78KB
d3drmobj.h 78KB
Msvidctl.h 72KB
amstream.h 72KB
dmusicf.h 71KB
d3d9types.h 71KB
d3d8.h 71KB
dplay8.h 68KB
uuids.h 63KB
d3d8types.h 62KB
d3dx9tex.h 58KB
d3dx9math.h 57KB
amfilter.h 56KB
sbe.h 55KB
d3dx8tex.h 55KB
bdamedia.h 53KB
Bdatif.h 52KB
dxva.h 46KB
d3dxcore.h 44KB
mediaobj.h 44KB
d3dx9anim.h 42KB
d3dx9shader.h 41KB
tune.h 40KB
d3dx8math.h 38KB
d3dx9effect.h 38KB
xprtdefs.h 35KB
dmusicc.h 35KB
dvoice.h 33KB
d3dxmath.h 32KB
dinputd.h 31KB
dvp.h 31KB
vfwmsgs.h 30KB
mpeg2data.h 29KB
dplobby.h 28KB
d3dx8mesh.h 28KB
dmerror.h 26KB
edevdefs.h 26KB
d3dcaps.h 26KB
ctlutil.h 25KB
playlist.h 25KB
mmstream.h 24KB
d3drmdef.h 24KB
d3dx9core.h 23KB
d3d9caps.h 22KB
videoacc.h 21KB
ksproxy.h 21KB
dmoimpl.h 21KB
tvratings.h 20KB
austream.h 20KB
renbase.h 20KB
amvideo.h 19KB
wxlist.h 18KB
dplobby8.h 18KB
dvdmedia.h 18KB
glfw.h 17KB
glfw.h 17KB
evcode.h 17KB
rmxftmpl.h 17KB
qnetwork.h 17KB
d3dx8core.h 17KB
ddstream.h 16KB
vidcap.h 16KB
dmplugin.h 16KB
d3d8caps.h 16KB
winutil.h 16KB
dpaddr.h 16KB
medparam.h 15KB
dvdevcod.h 15KB
d3dxsprite.h 15KB
bdatypes.h 15KB
wxutil.h 15KB
d3drm.h 15KB
共 226 条
- 1
- 2
- 3
资源评论
_Tiny
- 粉丝: 37
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功