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
|
/*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <qglobal.h>
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "../linux/VideoDeviceLinux.h"
#endif
#if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
#include "../win32/VideoDeviceWin32.h"
#endif
#include "VideoCollector.h"
CVideoCollector *CVideoCollector::s_pVideoCollector = 0;
#if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
QMap<HWND, CVideoDeviceWin32 *>CVideoCollector::s_HWND2Video;
#endif
CVideoCollector::CVideoCollector()
{
qDebug("CVideoCollector::VideoCollector()");
}
// private
void CVideoCollector::Scan()
{
#if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
int i;
CVideoDeviceWin32 *pDev;
char name[100], version[100];
for (i = 0; i < 10; i++) {
if (capGetDriverDescription(i, name ,sizeof(name), version, sizeof(version))) {
qDebug("found videodriver at pos %d: %s, %s", i, name, version);
pDev = new CVideoDeviceWin32(i);
if (pDev->IsValid())
m_Devices.append(pDev);
else
delete pDev;
}
else
break;
}
#endif
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
QString devname;
struct stat devstat;
int i;
CVideoDeviceLinux *v;
/* Argh. This is the second time Qt bites me in /dev: IT WON'T BLOODY
LIST DEVICE INODES!!! So back to plain old sprintf().
*/
for (i = 0; i < 64; i++) {
devname.sprintf("/dev/video%d", i);
if (stat(devname, &devstat) == 0) {
if (!S_ISLNK(devstat.st_mode)) {
v = new CVideoDeviceLinux(devname);
if (!v->IsValid()) { // The class detects if this is a valid device
delete v;
v = NULL;
}
if (v)
m_Devices.append(v);
} // .. if !S_ISLNK
} // ..if !stat
} // ..for i
#endif
}
// public
CVideoCollector *CVideoCollector::Instance()
{
if (s_pVideoCollector == 0) {
s_pVideoCollector = new CVideoCollector();
s_pVideoCollector->Scan();
}
return s_pVideoCollector;
}
uint CVideoCollector::NumberOfVideoDevices() const
{
return m_Devices.count();
}
CVideoDevice *CVideoCollector::GetVideoDevice(uint n)
{
if (n < 0 || n >= m_Devices.count())
return 0;
return m_Devices.at(n);
}
#if defined(_OS_WIN32_) || defined(Q_OS_WIN32)
/* These functions are necessary for Windows, since that uses a callback mechanism.
This is probably the best place to handle this, since CVideoCollector already
knows about the video-devices present; it dispatches the callbacks to the
apropriate device.
*/
void CVideoCollector::RegisterDevice(HWND h, CVideoDeviceWin32 *pVideo)
{
s_HWND2Video[h] = pVideo;
capSetCallbackOnCapControl (h, CVideoCollector::ControlCallback);
capSetCallbackOnError (h, CVideoCollector::ErrorCallback);
capSetCallbackOnStatus (h, CVideoCollector::StatusCallback);
capSetCallbackOnVideoStream(h, CVideoCollector::VideoCallback);
// capSetCallbackOnYield (h, CVideoCollector::YieldCallback);
}
void CVideoCollector::UnregisterDevice(HWND h)
{
if (!s_HWND2Video.contains(h))
return;
capSetCallbackOnCapControl (h, NULL);
capSetCallbackOnError (h, NULL);
capSetCallbackOnStatus (h, NULL);
capSetCallbackOnVideoStream(h, NULL);
// capSetCallbackOnYield (h, NULL);
s_HWND2Video.remove(h);
}
LRESULT CALLBACK CVideoCollector::ControlCallback(HWND h, int id)
{
CVideoDeviceWin32 *pVideo;
pVideo = s_HWND2Video[h];
if (pVideo == 0)
return FALSE;
return pVideo->CallbackControl(id);
}
LRESULT CALLBACK CVideoCollector::ErrorCallback(HWND h, int id, LPTSTR text)
{
CVideoDeviceWin32 *pVideo;
pVideo = s_HWND2Video[h];
if (pVideo == 0)
return FALSE;
return pVideo->CallbackError(id, text);
}
LRESULT CALLBACK CVideoCollector::StatusCallback(HWND h, int id, LPTSTR text)
{
CVideoDeviceWin32 *pVideo;
pVideo = s_HWND2Video[h];
if (pVideo == 0)
return FALSE;
return pVideo->CallbackStatus(id, text);
}
LRESULT CALLBACK CVideoCollector::VideoCallback(HWND h, LPVIDEOHDR video)
{
CVideoDeviceWin32 *pVideo;
pVideo = s_HWND2Video[h];
if (pVideo == 0)
return FALSE;
return pVideo->CallbackVideoStream(video);
}
LRESULT CALLBACK CVideoCollector::YieldCallback(HWND h)
{
CVideoDeviceWin32 *pVideo;
pVideo = s_HWND2Video[h];
if (pVideo == 0)
return FALSE;
return pVideo->CallbackYield();
}
#endif
|