211 lines
5.8 KiB
C++
211 lines
5.8 KiB
C++
#ifndef _VIDCAP_VIDCAP_HPP_
|
|
#define _VIDCAP_VIDCAP_HPP_
|
|
#ifndef _COMMON_AVICAP_HPP_
|
|
#include <common/avicap.hpp>
|
|
#endif
|
|
#ifndef _COMMON_INSTANCEDATA_HPP_
|
|
#include <common/instance.hpp>
|
|
#endif
|
|
#ifndef _COMMON_GLOBALDATA_HPP_
|
|
#include <common/gdata.hpp>
|
|
#endif
|
|
#ifndef _COMMON_BITMAPINFO_HPP_
|
|
#include <common/bminfo.hpp>
|
|
#endif
|
|
#ifndef _VIDCAP_DRVINFO_HPP_
|
|
#include <vidcap/drvinfo.hpp>
|
|
#endif
|
|
#ifndef _VIDCAP_CAPTUREPARAMS_HPP_
|
|
#include <vidcap/capparms.hpp>
|
|
#endif
|
|
#ifndef _VIDCAP_CAPSTATUS_HPP_
|
|
#include <vidcap/capstat.hpp>
|
|
#endif
|
|
#ifndef _VIDCAP_DRVCAPS_HPP_
|
|
#include <vidcap/drvcaps.hpp>
|
|
#endif
|
|
|
|
class VidCap
|
|
{
|
|
public:
|
|
VidCap();
|
|
virtual ~VidCap();
|
|
bool create(HWND hParentWnd,DWORD width=DefaultWidth,DWORD height=DefaultHeight);
|
|
bool connect(const String &driverName);
|
|
bool connect(WORD driverIndex);
|
|
bool connect(void);
|
|
bool sequenceNoFile(void);
|
|
bool sequence(void);
|
|
bool capStop(void)const;
|
|
bool capAbort(void)const;
|
|
bool grabFrame(void)const;
|
|
bool grabFrameNoStop(void)const;
|
|
bool getDriverCaps(DriverCaps &someDriverCaps);
|
|
bool getCaptureParams(CaptureParams &someCaptureParams);
|
|
bool setCaptureParams(CaptureParams &someCaptureParams);
|
|
bool getCaptureStatus(CaptureStatus &someCaptureStatus);
|
|
bool getVideoFormat(BitmapInfo &bitmapInfo);
|
|
bool setVideoFormat(BitmapInfo &someBitmapInfo);
|
|
bool setMCIDeviceName(const String &mciDeviceName);
|
|
bool getMCIDeviceName(String &mciDeviceName);
|
|
bool setPreviewRate(DWORD milliseconds);
|
|
bool dialogVideoSource(void);
|
|
bool dialogVideoFormat(void);
|
|
bool dialogVideoDisplay(void);
|
|
bool preview(bool preview);
|
|
bool isConnected(void)const;
|
|
bool isOkay(void)const;
|
|
void disconnect(void);
|
|
static void getDrivers(Block<DriverInfo> &capDrivers);
|
|
protected:
|
|
virtual void errorHandler(int errorID,const String &errorString);
|
|
virtual void statusHandler(int nID,const String &statusString);
|
|
virtual void videoHandler(VIDEOHDR &videoHeader);
|
|
virtual void frameHandler(VIDEOHDR &videoHeader);
|
|
private:
|
|
enum{ControlID=101,DefaultWidth=160,DefaultHeight=120};
|
|
void isConnected(bool isConnected);
|
|
void installHandlers(void);
|
|
void removeHandlers(void);
|
|
void destroy(void);
|
|
static void WINAPI errorCallback(HWND hWnd,int nErrorID,LPSTR lpszErrorText);
|
|
static void WINAPI statusCallback(HWND hWnd,int nID,LPSTR lpszStatusText);
|
|
static void WINAPI videoCallback(HWND hWnd,LPVIDEOHDR lpVideoHeader);
|
|
static void WINAPI frameCallback(HWND hWnd,LPVIDEOHDR lpVideoHeader);
|
|
HWND mhCaptureWnd;
|
|
HWND mhParentWnd;
|
|
bool mIsConnected;
|
|
InstanceData mInstanceData;
|
|
CaptureParams mCaptureParams;
|
|
CaptureStatus mCaptureStatus;
|
|
};
|
|
|
|
inline
|
|
bool VidCap::isConnected(void)const
|
|
{
|
|
return mIsConnected;
|
|
}
|
|
|
|
inline
|
|
void VidCap::isConnected(bool isConnected)
|
|
{
|
|
mIsConnected=isConnected;
|
|
}
|
|
|
|
inline
|
|
bool VidCap::isOkay(void)const
|
|
{
|
|
return (mhCaptureWnd?TRUE:FALSE);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::capStop(void)const
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_STOP,(WPARAM)0,(LPARAM)0);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::capAbort(void)const
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_ABORT,(WPARAM)0,(LPARAM)0);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::grabFrame(void)const
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_GRAB_FRAME,(WPARAM)0,(LPARAM)0);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::grabFrameNoStop(void)const
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_GRAB_FRAME_NOSTOP,(WPARAM)0,(LPARAM)0);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::sequenceNoFile(void)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SEQUENCE_NOFILE,0,0L);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::sequence(void)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SEQUENCE,0,0L);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::setPreviewRate(DWORD milliseconds)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SET_PREVIEWRATE,milliseconds,0L);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::preview(bool preview)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SET_PREVIEW,preview,0L);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::getCaptureStatus(CaptureStatus &someCaptureStatus)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_GET_STATUS,(WPARAM)sizeof(CAPSTATUS),(LPARAM)(LPVOID)&((CAPSTATUS&)someCaptureStatus));
|
|
}
|
|
|
|
inline
|
|
bool VidCap::getCaptureParams(CaptureParams &someCaptureParams)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_GET_SEQUENCE_SETUP,(WPARAM)sizeof(CAPTUREPARMS),(LPARAM)(LPVOID)&((CAPTUREPARMS&)someCaptureParams));
|
|
}
|
|
|
|
inline
|
|
bool VidCap::setCaptureParams(CaptureParams &someCaptureParams)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SET_SEQUENCE_SETUP,(WPARAM)sizeof(CAPTUREPARMS),(LPARAM)(LPVOID)&((CAPTUREPARMS&)someCaptureParams));
|
|
}
|
|
|
|
inline
|
|
bool VidCap::getDriverCaps(DriverCaps &someDriverCaps)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_DRIVER_GET_CAPS,(WPARAM)sizeof(CAPDRIVERCAPS),(LPARAM)(LPVOID)&someDriverCaps);
|
|
}
|
|
|
|
inline
|
|
bool VidCap::setVideoFormat(BitmapInfo &someBitmapInfo)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
if(!someBitmapInfo.width()||!someBitmapInfo.height())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SET_VIDEOFORMAT,(WPARAM)sizeof(BITMAPINFOHEADER),(LPARAM)&((BITMAPINFOHEADER&)someBitmapInfo));
|
|
}
|
|
|
|
inline
|
|
bool VidCap::setMCIDeviceName(const String &mciDeviceName)
|
|
{
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_SET_MCI_DEVICE,0,(LPARAM)mciDeviceName.str());
|
|
}
|
|
|
|
inline
|
|
bool VidCap::getMCIDeviceName(String &mciDeviceName)
|
|
{
|
|
bool returnCode=false;
|
|
|
|
mciDeviceName.reserve(512);
|
|
if(!isOkay()||!isConnected())return false;
|
|
return ::SendMessage(mhCaptureWnd,WM_CAP_GET_MCI_DEVICE,512,(LPARAM)mciDeviceName.str());
|
|
}
|
|
#endif
|
|
|