1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.at
//
// Implementation file
//
// Copyright (c) 1997-1999 Mark Danks.
// Copyright (c) Günther Geiger.
// Copyright (c) 2001-2011 IOhannes m zmölnig. forum::für::umläute. IEM. zmoelnig@iem.at
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_LIBVFW32
# ifndef HAVE_VFW_H
# define HAVE_VFW_H
# endif
#endif
#ifdef HAVE_VFW_H
#include "videoVFW.h"
#include "plugins/PluginFactory.h"
using namespace gem::plugins;
#include "Gem/RTE.h"
/* MinGW headers seem to be incomplete */
#ifndef AVSTREAMMASTER_NONE
#define AVSTREAMMASTER_NONE 1
#endif
REGISTER_VIDEOFACTORY("VFW", videoVFW);
/////////////////////////////////////////////////////////
//
// videoVFW
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
videoVFW :: videoVFW(void)
: videoBase("vfw", 0),
m_hWndC(NULL)
{
provide("dv");
provide("iidc");
provide("analog");
}
/////////////////////////////////////////////////////////
// Destructor
//
/////////////////////////////////////////////////////////
videoVFW :: ~videoVFW(void)
{
close();
}
/////////////////////////////////////////////////////////
// openDevice
//
/////////////////////////////////////////////////////////
bool videoVFW :: openDevice(gem::Properties&props)
{
char driverName[256];
char driverDesc[256];
if (capGetDriverDescription(0, driverName, 256, driverDesc, 256)) {
verbose(1, "[GEM:videoVFW] driver '%s'", driverName);
}
double d;
if (props.get("width", d)) {
m_width=d;
}
if (props.get("height", d)) {
m_height=d;
}
if(m_hWndC) {
closeDevice();
}
// Connect to the daemon
m_hWndC = capCreateCaptureWindow ((LPSTR)
"GEM video", // window name if pop-up
0, // window style (not visible)
0, 0, m_width, m_height,// window position and dimensions
GetDesktopWindow(), 0);
if (!m_hWndC) {
verbose(0, "[GEM:videoVFW] Unable to create capture window");
return false;
}
if (!capDriverConnect(m_hWndC, 0)) {
verbose(0, "[GEM:videoVFW] Unable to connect to video driver");
closeDevice();
return false;
}
CAPTUREPARMS params;
if (!capCaptureGetSetup(m_hWndC, ¶ms, sizeof(CAPTUREPARMS))) {
verbose(0, "[GEM:videoVFW] Unable to get capture parameters");
closeDevice();
return false;
}
params.fYield = TRUE;
params.fCaptureAudio = FALSE;
params.wPercentDropForError = 100;
params.fLimitEnabled = FALSE;
params.AVStreamMaster = AVSTREAMMASTER_NONE;
params.fStepCaptureAt2x = FALSE;
params.fAbortLeftMouse = FALSE;
params.fAbortRightMouse = FALSE;
if (!capCaptureSetSetup(m_hWndC, ¶ms, sizeof(CAPTUREPARMS))) {
verbose(0, "[GEM:videoVFW] Unable to set capture parameters");
closeDevice();
return false;
}
if (!capSetCallbackOnVideoStream(m_hWndC, videoVFW::videoFrameCallback)) {
verbose(0, "[GEM:videoVFW] Unable to set frame callback");
closeDevice();
return false;
}
if (!capSetUserData(m_hWndC, this)) {
verbose(0, "[GEM:videoVFW] Unable to set user data");
closeDevice();
return false;
}
DWORD formSize = capGetVideoFormat(m_hWndC, NULL, 0);
BITMAPINFO *videoFormat = (BITMAPINFO *)(new char[formSize]);
if (!capGetVideoFormat(m_hWndC, videoFormat, formSize)) {
verbose(0, "[GEM:videoVFW] Unable to get video format");
closeDevice();
return false;
}
videoFormat->bmiHeader.biWidth = m_width;
videoFormat->bmiHeader.biHeight = m_height;
videoFormat->bmiHeader.biBitCount = 24;
videoFormat->bmiHeader.biCompression = BI_RGB;
videoFormat->bmiHeader.biClrUsed = 0;
videoFormat->bmiHeader.biClrImportant = 0;
videoFormat->bmiHeader.biSizeImage = 0;
if (!capSetVideoFormat(m_hWndC, videoFormat, formSize)) {
verbose(0, "[GEM:videoVFW] Unable to set video format");
delete[]videoFormat;
closeDevice();
return false;
}
if (!capGetVideoFormat(m_hWndC, videoFormat, formSize)) {
error("[GEM:videoVFW] Unable to get video format");
}
m_width=static_cast<int>(videoFormat->bmiHeader.biWidth);
m_height=static_cast<int>(videoFormat->bmiHeader.biHeight);
verbose(1, "[GEM:videoVFW] Connected with %dx%d @ %d",
m_width, m_height,
static_cast<int>(videoFormat->bmiHeader.biBitCount));
delete[]videoFormat;
m_image.image.xsize = m_width;
m_image.image.ysize = m_height;
m_image.image.setCsizeByFormat(GEM_RGBA);
m_image.image.reallocate();
m_image.image.setBlack();
return true;
}
/////////////////////////////////////////////////////////
// closeDevice
//
/////////////////////////////////////////////////////////
void videoVFW :: closeDevice(void)
{
if (m_hWndC) {
capDriverDisconnect(m_hWndC);
DestroyWindow(m_hWndC);
}
m_hWndC=NULL;
}
/////////////////////////////////////////////////////////
// videoFrame callback
//
/////////////////////////////////////////////////////////
void videoVFW :: videoFrame(LPVIDEOHDR lpVHdr)
{
int count = lpVHdr->dwBytesUsed;
// notice that it is times 3 for the color!
// incoming data is BGR
const int dataSize = m_image.image.xsize * m_image.image.ysize * 3;
if (count < dataSize) {
return;
}
lock();
m_image.image.fromBGR(lpVHdr->lpData);
m_image.newimage = true;
unlock();
}
void videoVFW :: videoFrameCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
videoVFW*ptr = reinterpret_cast<videoVFW*>(capGetUserData(hWnd));
ptr->videoFrame(lpVHdr);
}
/////////////////////////////////////////////////////////
// render
//
/////////////////////////////////////////////////////////
bool videoVFW :: grabFrame(void)
{
return true;
}
/////////////////////////////////////////////////////////
// startTransfer
//
/////////////////////////////////////////////////////////
bool videoVFW :: startTransfer(void)
{
bool result= capCaptureSequenceNoFile(m_hWndC);
m_image.newfilm=result;
return result;
}
/////////////////////////////////////////////////////////
// stopTransfer
//
/////////////////////////////////////////////////////////
bool videoVFW :: stopTransfer(void)
{
capCaptureStop(m_hWndC);
return true;
}
/////////////////////////////////////////////////////////
// csMess
//
/////////////////////////////////////////////////////////
bool videoVFW :: setColor(int format)
{
if(format) {
m_image.image.setCsizeByFormat(format);
}
return true;
}
bool videoVFW :: enumProperties(gem::Properties&readable,
gem::Properties&writeable)
{
readable.clear();
writeable.clear();
gem::any type=0;
writeable.set("width", type);
writeable.set("height", type);
return true;
}
void videoVFW :: setProperties(gem::Properties&props)
{
double d;
bool dorestart=false;
if (props.get("width", d)) {
m_width=d;
dorestart=true;
}
if (props.get("height", d)) {
m_height=d;
dorestart=true;
}
if(dorestart && m_hWndC) {
reset();
}
}
void videoVFW :: getProperties(gem::Properties&props)
{
}
#endif /* HAVE_VFW */
|