Merge branch 'master' of steffen.gulpe.de:steffen/SimpleSkyCam

master
Steffen Pohle 2 years ago
commit f3afb9dd8a

1
.gitignore vendored

@ -8,4 +8,5 @@ simpleskycam
*~ *~
U2SM200C-AST_Cfg_A.bin U2SM200C-AST_Cfg_A.bin
U2SM200C-AST_Cfg_SAVE.bin U2SM200C-AST_Cfg_SAVE.bin
gmon.out

@ -7,7 +7,7 @@
VERSION = 0.0.1 VERSION = 0.0.1
APP = simpleskycam APP = simpleskycam
include Makefile.config -include Makefile.config
-include Makefile.rules -include Makefile.rules
OBJECTS := $(OBJECTS) gui.oo main.oo error.oo debug.oo \ OBJECTS := $(OBJECTS) gui.oo main.oo error.oo debug.oo \
@ -47,15 +47,24 @@ endif
ifeq ($(TARGET),) ifeq ($(TARGET),)
noconfig: configlinux help noconfig: defaultconfig help
endif endif
all: Makefile.rules $(TARGET) all: Makefile.rules $(TARGET)
defaultconfig:
ifeq ($(MAKEFILE_CONFIG),)
echo "MAKEFILE_CONFIG = 1" > Makefile.config
echo "" >> Makefile.config
echo "USE_SVBONY = 1" >> Makefile.config
echo "USE_DNG = 1" >> Makefile.config
echo "USE_SER = 1" >> Makefile.config
echo "" >> Makefile.config
echo "DEBUG_ANGLES = 0" >> Makefile.config
echo "DEBUG_POSCTL = 0" >> Makefile.config
endif
help: help:
echo "set up configuration" echo "set up configuration"
echo " make configlinux to generate the linix build" echo " make configlinux to generate the linix build"
@ -151,6 +160,9 @@ $(TARGET): $(OBJECTS)
.cc.oo : $(INCLUDES) .cc.oo : $(INCLUDES)
$(CPP) -o $@ -c $(CPPFLAGS) $< $(CPP) -o $@ -c $(CPPFLAGS) $<
cleanall: clean
rm -rf Makefile.config
clean: clean:
rm -f *.o *.oo *.c~ *.h~ *.cc~ *.ui~ $(APP) Makefile~ rm -f *.o *.oo *.c~ *.h~ *.cc~ *.ui~ $(APP) Makefile~
rm -rf config.h rm -rf config.h
@ -162,7 +174,7 @@ clean:
rm -rf U2SM200C-AST_Cfg_SAVE.bin rm -rf U2SM200C-AST_Cfg_SAVE.bin
rm -rf SimpleSkyCam-$(VERSION) rm -rf SimpleSkyCam-$(VERSION)
dist: clean dist: cleanall
rm -rf $(DISTNAME) rm -rf $(DISTNAME)
mkdir $(DISTNAME) mkdir $(DISTNAME)
cp Makefile* $(DISTNAME) cp Makefile* $(DISTNAME)

@ -1,12 +0,0 @@
#
# configurations should be made in here.
# set one of these variables to 0 to disable the function.
#
USE_SVBONY = 1
USE_DNG = 1
USE_SER = 1
DEBUG_ANGLES = 0
DEBUG_POSCTL = 0

@ -60,7 +60,7 @@ void axis_history_add(int axis, double diff, double out) {
} }
#define CALIB_MAXSPEED 1.0 #define CALIB_MAXSPEED 1.0
#define CALIB_DURATION_DELTA 10.0 #define CALIB_DURATION_DELTA 5.0
#define CALIB_DURATION_AXIS (CALIB_DURATION_DELTA / CALIB_MAXSPEED) #define CALIB_DURATION_AXIS (CALIB_DURATION_DELTA / CALIB_MAXSPEED)
void posctl_gui_update(); void posctl_gui_update();

@ -121,7 +121,11 @@ int VideoDev_Dumpfile::Open() {
} }
filesize = s.st_size; filesize = s.st_size;
#ifdef BUILD_WINDOWS
if ((fd = open(fname.c_str(), O_RDONLY | O_BINARY)) == -1) {
#else
if ((fd = open(fname.c_str(), O_RDONLY)) == -1) { if ((fd = open(fname.c_str(), O_RDONLY)) == -1) {
#endif
printf ("%s:%d could not open file '%s' error:%s\n", __FILE__, __LINE__, fname.c_str(), strerror(errno)); printf ("%s:%d could not open file '%s' error:%s\n", __FILE__, __LINE__, fname.c_str(), strerror(errno));
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
@ -267,9 +271,8 @@ int VideoDev_Dumpfile::ReadFrame() {
// //
// read frame // read frame
if (read (fd, inbuf, 4*2) != 4*2) { if (read (fd, inbuf, 4*2) != 4*2) {
printf ("%s:%d could not read frame header\n", __FILE__, __LINE__); printf ("%s:%d could not read frame header: %s\n", __FILE__, __LINE__, strerror(errno));
Close(); Close();
} }
filepos += (4*2); filepos += (4*2);
inframe_size = ntohl(inbuf[0]); inframe_size = ntohl(inbuf[0]);
@ -291,9 +294,8 @@ int VideoDev_Dumpfile::ReadFrame() {
printf ("%s:%d cloud not allocate enought memory\n", __FILE__, __LINE__); printf ("%s:%d cloud not allocate enought memory\n", __FILE__, __LINE__);
return VDEV_CBSTATUS_ERROR; return VDEV_CBSTATUS_ERROR;
} }
if (read (fd, inframe, inframe_size) != inframe_size) { if (read (fd, inframe, inframe_size) != inframe_size) {
printf ("%s:%d could not read frame\n", __FILE__, __LINE__); printf ("%s:%d could not read frame: %s\n", __FILE__, __LINE__, strerror(errno));
Close(); Close();
} }
filepos += inframe_size; filepos += inframe_size;

@ -1,5 +1,6 @@
/* /*
* module to read video data from vfw. * Module to grab video data from VfW interface. The interface is
* poorly documented for which some odd comments maybe found here.
*/ */
#include "config.h" #include "config.h"
@ -15,6 +16,11 @@
#include "convert.h" #include "convert.h"
#include "videodev-vfw.h" #include "videodev-vfw.h"
static char classNameVfW[] = "VFW-Class";
/*
* Constructor
*/
VideoDev_VFW::VideoDev_VFW() { VideoDev_VFW::VideoDev_VFW() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
hwnd = cap = NULL; hwnd = cap = NULL;
@ -25,16 +31,21 @@ VideoDev_VFW::VideoDev_VFW() {
inframe = NULL; inframe = NULL;
inframe_size = 0; inframe_size = 0;
vfw_size = 0; vfw_size = 0;
hclass = NULL;
hinst = NULL;
}; };
/*
* Destructor
*/
VideoDev_VFW::~VideoDev_VFW() { VideoDev_VFW::~VideoDev_VFW() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
if (running > 0) CaptureStop(); if (running > 0)
CaptureStop();
} }
/* /*
* check for connected devices and return the result in a list. * Check for connected devices and returns the result in a list.
*/ */
int VideoDev_VFW::GetDeviceList(std::list<std::string> *list) { int VideoDev_VFW::GetDeviceList(std::list<std::string> *list) {
@ -44,8 +55,10 @@ int VideoDev_VFW::GetDeviceList(std::list<std::string> *list) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
if (list == NULL) return VDEV_STATUS_ERROR; if (list == NULL) return VDEV_STATUS_ERROR;
// go through a list of 10 (maximum number defined by VfW)
for(int i=0; i < 10; i++) for(int i=0; i < 10; i++)
if(capGetDriverDescription(i, name, sizeof(name), desc, sizeof(desc))) { if(capGetDriverDescription(i, name, sizeof(name), desc, sizeof(desc))) {
// create a driver for the return list
std::string device; std::string device;
device = "VFW " + to_string(i) + " " + (string)name + " [" + (string)desc + "]"; device = "VFW " + to_string(i) + " " + (string)name + " [" + (string)desc + "]";
printf ("%s:%d %s Found device '%s'\n", __FILE__, __LINE__, __FUNCTION__, device.c_str()); printf ("%s:%d %s Found device '%s'\n", __FILE__, __LINE__, __FUNCTION__, device.c_str());
@ -56,73 +69,174 @@ int VideoDev_VFW::GetDeviceList(std::list<std::string> *list) {
} }
/* /*
* Open Device * Destroy and unregister window class.
* prepare the buffer
*/ */
int VideoDev_VFW::Open() { int VideoDev_VFW::DestroyClass() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
if (hclass) {
if(!UnregisterClass(classNameVfW, hinst)) {
printf ("%s:%d %s Could not unregister VFW class\n", __FILE__, __LINE__, __FUNCTION__);
return 0;
}
free (hclass);
hclass = NULL;
}
return 1;
}
/*
* Create and register window class.
*/
int VideoDev_VFW::CreateClass() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
if (hclass) return 1;
hclass = (WNDCLASSEX *)malloc(sizeof(WNDCLASSEX));
hclass->hInstance = hinst;
hclass->lpszClassName = classNameVfW;
hclass->lpfnWndProc = DefWindowProc;
hclass->style = CS_DBLCLKS;
hclass->cbSize = sizeof(WNDCLASSEX);
hclass->hIcon = LoadIcon(NULL,IDI_APPLICATION);
hclass->hIconSm = LoadIcon(NULL,IDI_APPLICATION);
hclass->hCursor = LoadCursor(NULL,IDC_ARROW);
hclass->lpszMenuName = NULL;
hclass->cbClsExtra = 0;
hclass->cbWndExtra = 0;
hclass->hbrBackground = (HBRUSH)COLOR_BACKGROUND;
if(!RegisterClassEx (hclass)) {
printf ("%s:%d %s Could not register VFW class\n", __FILE__, __LINE__, __FUNCTION__);
return 0;
}
return 1;
}
/*
* Print driver capabilities.
*/
void VideoDev_VFW::GetCapabilities() {
CAPDRIVERCAPS caps;
if(!capDriverGetCaps(cap, &caps, sizeof(caps))) {
printf ("%s:%d %s Unable to get driver capabilities\n", __FILE__, __LINE__, __FUNCTION__);
}
else {
printf ("%s:%d %s Id: %d\n", __FILE__, __LINE__, __FUNCTION__, caps.wDeviceIndex);
printf ("%s:%d %s Overlay: %d\n", __FILE__, __LINE__, __FUNCTION__, caps.fHasOverlay);
printf ("%s:%d %s VideoSource Dialog: %d\n", __FILE__, __LINE__, __FUNCTION__, caps.fHasDlgVideoSource);
printf ("%s:%d %s VideoFormat Dialog: %d\n", __FILE__, __LINE__, __FUNCTION__, caps.fHasDlgVideoFormat);
printf ("%s:%d %s VideoDisplay Dialog: %d\n", __FILE__, __LINE__, __FUNCTION__, caps.fHasDlgVideoDisplay);
}
}
/*
* The callback is run when an error in the capture driver occurred.
*/
LRESULT VFW_error_callback (HWND h, int nID, LPCSTR lpsz) {
printf("%s:%d %s id=%d (%s)\n", __FILE__, __LINE__, __FUNCTION__, nID, lpsz);
return TRUE;
}
/*
* The callback is run when a status update in the capture driver occurred.
*/
LRESULT VFW_status_callback (HWND h, int nID, LPCSTR lpsz) {
printf("%s:%d %s id=%d (%s)\n", __FILE__, __LINE__, __FUNCTION__, nID, lpsz);
return TRUE;
}
static int first = 1; #define USE_PREVIEW 0
/*
* Opens the device.
*/
int VideoDev_VFW::Open() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
// extract camera id from device name
camid = atoi (conf_device.c_str()); camid = atoi (conf_device.c_str());
printf ("%s:%d %s Opening VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); printf ("%s:%d %s Opening VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid);
// create parent window // find application instance handle for later use
//HWND main_hwnd = (HWND)GDK_WINDOW_HWND (gtk_widget_get_window (GTK_WIDGET(main_window))); hinst = GetModuleHandle(NULL);
HINSTANCE hinst = GetModuleHandle(NULL);
char classNameVfW[] = "VFW-Class"; // create and register window class
if (!CreateClass())
if (first) {
WNDCLASSEX hclass;
hclass.hInstance=hinst;
hclass.lpszClassName=classNameVfW;
hclass.lpfnWndProc=DefWindowProc;
hclass.style=CS_DBLCLKS;
hclass.cbSize=sizeof(WNDCLASSEX);
hclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
hclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
hclass.hCursor=LoadCursor(NULL,IDC_ARROW);
hclass.lpszMenuName=NULL;
hclass.cbClsExtra=0;
hclass.cbWndExtra=0;
hclass.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
if(!RegisterClassEx(&hclass)) {
printf ("%s:%d %s Could not register VFW class\n", __FILE__, __LINE__, __FUNCTION__);
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
}
first = 0; // now create the parent window for capture devicey
} // some notes:
// - the minimum possible size of 3x3
// - the WS_POPUPWINDOW removes window decorations
// - it does not need a parent window
// - the window MUST be visible, otherwise video grabbing does not work (no callbacks run)
#if USE_PREVIEW
hwnd = CreateWindowEx(0, classNameVfW, "CameraPreview", WS_POPUPWINDOW|WS_VISIBLE, 0, 0, 3, 3, NULL, NULL, hinst, NULL); hwnd = CreateWindowEx(0, classNameVfW, "CameraPreview", WS_POPUPWINDOW|WS_VISIBLE, 0, 0, 3, 3, NULL, NULL, hinst, NULL);
if (hwnd == NULL) { #else
hwnd = CreateWindowEx(0, classNameVfW, "CameraPreview", WS_POPUPWINDOW|WS_VISIBLE, 0, 0, 0, 0, NULL, NULL, hinst, NULL);
#endif
if (!hwnd) {
printf ("%s:%d %s Could not create window (%ld)\n", __FILE__, __LINE__, __FUNCTION__, GetLastError()); printf ("%s:%d %s Could not create window (%ld)\n", __FILE__, __LINE__, __FUNCTION__, GetLastError());
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
ShowWindow(hwnd, SW_SHOW); #if USE_PREVIEW
if(!ShowWindow(hwnd, SW_SHOW)) {
printf ("%s:%d %s Could not show window (%ld)\n", __FILE__, __LINE__, __FUNCTION__, GetLastError());
return VDEV_STATUS_ERROR;
}
#else
if(!ShowWindow(hwnd, SW_HIDE)) {
printf ("%s:%d %s Could not hide window (%ld)\n", __FILE__, __LINE__, __FUNCTION__, GetLastError());
return VDEV_STATUS_ERROR;
}
#endif
// connect to driver // create capture driver window handle, also here minim size is 1x1
#if USE_PREVIEW
cap = capCreateCaptureWindow("VFW", WS_CHILD|WS_VISIBLE, 0, 0, 1, 1, hwnd, camid); cap = capCreateCaptureWindow("VFW", WS_CHILD|WS_VISIBLE, 0, 0, 1, 1, hwnd, camid);
#else
cap = capCreateCaptureWindow("VFW", WS_CHILD, 0, 0, 0, 0, hwnd, camid);
#endif
if(!cap) { if(!cap) {
printf ("%s:%d %s Could not open VFW id %d window\n", __FILE__, __LINE__, __FUNCTION__, camid); printf ("%s:%d %s Could not open VFW id %d window\n", __FILE__, __LINE__, __FUNCTION__, camid);
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
if(!capSetCallbackOnStatus(cap, VFW_status_callback)) {
printf ("%s:%d %s Could not set status callback to VFW id %d (%ld)\n", __FILE__, __LINE__, __FUNCTION__, camid, GetLastError());
return VDEV_STATUS_ERROR;
}
if(!capSetCallbackOnError(cap, VFW_error_callback)) {
printf ("%s:%d %s Could not set error callback to VFW id %d (%ld)\n", __FILE__, __LINE__, __FUNCTION__, camid, GetLastError());
return VDEV_STATUS_ERROR;
}
// connect to driver
if(!capDriverConnect(cap, camid)) { if(!capDriverConnect(cap, camid)) {
printf ("%s:%d %s Could not connect to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); printf ("%s:%d %s Could not connect to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid);
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
// check capabilities
GetCapabilities();
// let the callbacks know this class pointer // let the callbacks know this class pointer
capSetUserData(cap, this); capSetUserData(cap, this);
// set video source, capture format and size
//capDlgVideoSource(cap);
//capDlgVideoFormat(cap);
CAPTUREPARMS cp; CAPTUREPARMS cp;
if(!capCaptureGetSetup(cap, &cp, sizeof(cp))) { if(!capCaptureGetSetup(cap, &cp, sizeof(cp))) {
printf ("%s:%d %s Could not get VFW setup\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s Could not get VFW capture setup\n", __FILE__, __LINE__, __FUNCTION__);
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
cp.dwRequestMicroSecPerFrame = 33333; cp.dwRequestMicroSecPerFrame = 10000; // rate in us
cp.fMakeUserHitOKToCapture = 0; cp.fMakeUserHitOKToCapture = 0;
cp.wPercentDropForError = 90; cp.wPercentDropForError = 10;
cp.fYield = TRUE; cp.fYield = TRUE;
cp.wNumVideoRequested = 1; cp.wNumVideoRequested = 1;
cp.fCaptureAudio = 0; cp.fCaptureAudio = 0;
@ -131,20 +245,10 @@ int VideoDev_VFW::Open() {
cp.fAbortRightMouse = 0; cp.fAbortRightMouse = 0;
cp.fLimitEnabled = 0; cp.fLimitEnabled = 0;
if(!capCaptureSetSetup(cap, &cp, sizeof(cp))) { if(!capCaptureSetSetup(cap, &cp, sizeof(cp))) {
printf ("%s:%d %s Could not set VFW setup\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s Could not set VFW capture setup\n", __FILE__, __LINE__, __FUNCTION__);
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
capOverlay(cap, 0);
capPreviewRate(cap, 10); // rate in ms
capPreviewScale(cap, 0);
capPreview(cap, TRUE);
//capCaptureSequenceNoFile(cap);
// set video source, capture format and size
capDlgVideoSource(cap);
capDlgVideoFormat(cap);
// get current valid width/height // get current valid width/height
BITMAPINFO bi; BITMAPINFO bi;
int i = 0; int i = 0;
@ -158,14 +262,15 @@ int VideoDev_VFW::Open() {
// try to set the configured width/height // try to set the configured width/height
if(conf_width != -1) { if(conf_width != -1) {
bi.bmiHeader.biWidth = conf_width; inframe_w = bi.bmiHeader.biWidth = conf_width;
bi.bmiHeader.biHeight = conf_height; inframe_h = bi.bmiHeader.biHeight = conf_height;
bi.bmiHeader.biCompression = inframe_pixfmt; bi.bmiHeader.biCompression = inframe_pixfmt;
if(!capSetVideoFormat(cap, &bi, sizeof(BITMAPINFO))) { if(!capSetVideoFormat(cap, &bi, sizeof(BITMAPINFO))) {
printf ("%s:%d %s Could not set capture size %dx%d (%s)\n", __FILE__, __LINE__, __FUNCTION__, conf_width, conf_height, conf_format.c_str()); printf ("%s:%d %s Could not set capture size %dx%d (%s)\n", __FILE__, __LINE__, __FUNCTION__, conf_width, conf_height, conf_format.c_str());
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
} }
// find out maximum resolution // find out maximum resolution
else { else {
int sizes[][2] = {{320, 240}, {640, 480}, {800, 600}, {1024, 768}, {1280, 720}, {1280, 1024}, {1920, 1080}, {-1, -1}}; int sizes[][2] = {{320, 240}, {640, 480}, {800, 600}, {1024, 768}, {1280, 720}, {1280, 1024}, {1920, 1080}, {-1, -1}};
@ -195,8 +300,7 @@ int VideoDev_VFW::Open() {
/* /*
* Close Device * Close the device.
* Free videobuffer
*/ */
int VideoDev_VFW::Close() { int VideoDev_VFW::Close() {
@ -207,6 +311,7 @@ int VideoDev_VFW::Close() {
DestroyWindow(hwnd); DestroyWindow(hwnd);
hwnd = cap = NULL; hwnd = cap = NULL;
} }
DestroyClass();
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
}; };
@ -216,22 +321,23 @@ int VideoDev_VFW::Close() {
* VideoGrabbing * VideoGrabbing
*/ */
/*
* The callback is run when a new frame is available. It copies the
* available data into the framebuffer of the class instance.
*/
LRESULT CALLBACK VFW_frame_callback (HWND h, LPVIDEOHDR v) { LRESULT CALLBACK VFW_frame_callback (HWND h, LPVIDEOHDR v) {
VideoDev_VFW * obj = (VideoDev_VFW *)capGetUserData(h); VideoDev_VFW * obj = (VideoDev_VFW *)capGetUserData(h);
obj->SetFrameBufferSize(v->dwBytesUsed); obj->SetFrameBufferSize(v->dwBytesUsed);
if (obj->GetFrameBuffer()) {
memcpy(obj->GetFrameBuffer(), v->lpData, obj->GetFrameBufferSize()); memcpy(obj->GetFrameBuffer(), v->lpData, obj->GetFrameBufferSize());
return TRUE;
} }
LRESULT VFW_error_callback(HWND h, int nID, LPCSTR lpsz) {
printf("%s:%d %s id=%d (%s)\n", __FILE__, __LINE__, __FUNCTION__, nID, lpsz);
return TRUE; return TRUE;
} }
/* /*
* prepare inframe for raw picture data, will hold a video frame with 16bit per channel or BGR32/BGR24 * Prepare inframe for raw picture data, will hold a video frame with
* inframe size = 4*W*H * maximum size of inframe size = 4*W*H. Setup capture
* send the start capture signal to the cam * callbacks. Then send the start capture signal to the camera.
*/ */
int VideoDev_VFW::CaptureStart() { int VideoDev_VFW::CaptureStart() {
@ -244,25 +350,33 @@ int VideoDev_VFW::CaptureStart() {
pixelformat = inframe_pixfmt; pixelformat = inframe_pixfmt;
if(!capSetCallbackOnError(cap, VFW_error_callback)) { #if USE_PREVIEW
printf ("%s:%d %s Could not set error callback to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); if(!capSetCallbackOnFrame(cap, VFW_frame_callback)) {
printf ("%s:%d %s Could not set frame callback to VFW id %d (%ld)\n", __FILE__, __LINE__, __FUNCTION__, camid, GetLastError());
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
#else
if(!capSetCallbackOnVideoStream(cap, VFW_frame_callback)) { if(!capSetCallbackOnVideoStream(cap, VFW_frame_callback)) {
printf ("%s:%d %s Could not set videostream callback to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); printf ("%s:%d %s Could not set videostream callback to VFW id %d (%ld)\n", __FILE__, __LINE__, __FUNCTION__, camid, GetLastError());
return VDEV_STATUS_ERROR; return VDEV_STATUS_ERROR;
} }
#endif
if(!capSetCallbackOnYield(cap, VFW_frame_callback)) { // disable overlay
printf ("%s:%d %s Cmould not set yield callback to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); capOverlay(cap, FALSE);
return VDEV_STATUS_ERROR;
}
if(!capSetCallbackOnFrame(cap, VFW_frame_callback)) { #if USE_PREVIEW
printf ("%s:%d %s Could not set frame callback to VFW id %d\n", __FILE__, __LINE__, __FUNCTION__, camid); // use preview window for grabbing
return VDEV_STATUS_ERROR; capPreviewRate (cap, 10); // rate in ms
capPreviewScale (cap, FALSE);
capPreview (cap, TRUE);
#else
// otherwise use other capture
capPreview (cap, FALSE);
if(!capCaptureSequenceNoFile (cap)) {
printf ("%s:%d %s Could not start capture (%ld)\n", __FILE__, __LINE__, __FUNCTION__, GetLastError());
} }
#endif
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
}; };
@ -270,16 +384,17 @@ int VideoDev_VFW::CaptureStart() {
/* /*
* free inbuffer * Stop capture and free framebuffer.
*/ */
int VideoDev_VFW::CaptureStop() { int VideoDev_VFW::CaptureStop() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
capCaptureAbort(cap); capCaptureAbort(cap);
capSetCallbackOnError(cap, NULL);
capSetCallbackOnFrame(cap, NULL); capSetCallbackOnFrame(cap, NULL);
capSetCallbackOnVideoStream(cap, NULL); capSetCallbackOnVideoStream(cap, NULL);
capSetCallbackOnYield(cap, NULL); capSetCallbackOnStatus(cap, NULL);
capSetCallbackOnError(cap, NULL);
// free inframe memory // free inframe memory
if (inframe) { if (inframe) {
@ -292,35 +407,50 @@ int VideoDev_VFW::CaptureStop() {
}; };
/* /*
* try to grab one frame and convert it into RGB32. * This function needed to continue running the capture window.
* If something goes wrong return an error code.
* Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read.
*/ */
// FIXME: SVBGetVideoData needs to be outside of Lock/UnLockMutex - using inside thread inbuffer void VideoDev_VFW::HandleMessages() {
int VideoDev_VFW::Grab(VideoFrameRaw *vf) {
MSG msg; MSG msg;
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
}
/*
* Try to grab one frame and copy it into raw video buffer. If
* something goes wrong return an error code. Return code
* VDEV_STATUS_AGAIN is not an error. There was no video image ready
* to read.
*/
int VideoDev_VFW::Grab(VideoFrameRaw *vf) {
// Do not know exactly why, but needed to translate/dispatch window message
HandleMessages();
if (inframe == NULL) return VDEV_STATUS_ERROR; if (inframe == NULL) return VDEV_STATUS_ERROR;
if (GetFrameBufferSize() > 0) { if (GetFrameBufferSize() > 0) {
LockMutex(); LockMutex();
vf->CopyFrom(inframe_pixfmt, inframe_w, inframe_h, GetFrameBufferSize(), inframe); vf->CopyFrom(inframe_pixfmt, inframe_w, inframe_h, GetFrameBufferSize(), inframe);
SetFrameBufferSize(0);
UnLockMutex(); UnLockMutex();
} }
else {
return VDEV_STATUS_AGAIN;
}
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
} }
/*
* For VfW this seems difficult / impossible to obtain the supported
* video formats, but they must be selected via capDlgVideoFormat().
*/
int VideoDev_VFW::GetDeviceFormats(string device, std::list<string> *formats) { int VideoDev_VFW::GetDeviceFormats(string device, std::list<string> *formats) {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
} }
@ -334,7 +464,6 @@ int VideoDev_VFW::GetDeviceFormats(string device, std::list<string> *formats) {
* set video control identified by id * set video control identified by id
*/ */
int VideoDev_VFW::SetDevCtrl(unsigned int id, int value) { int VideoDev_VFW::SetDevCtrl(unsigned int id, int value) {
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
}; };

@ -15,6 +15,8 @@ private:
ConvertData cdata; ConvertData cdata;
int camid; int camid;
HWND cap, hwnd; HWND cap, hwnd;
WNDCLASSEX * hclass;
HINSTANCE hinst;
int Grab(VideoFrameRaw *vf); int Grab(VideoFrameRaw *vf);
int Open(); int Open();
@ -23,6 +25,10 @@ private:
int CaptureStop(); int CaptureStop();
int SetDevCtrl(unsigned int id, int value); int SetDevCtrl(unsigned int id, int value);
int GetDevCtrl(unsigned int id, int *value); int GetDevCtrl(unsigned int id, int *value);
int CreateClass();
int DestroyClass();
void HandleMessages();
void GetCapabilities();
void print_error(int err); void print_error(int err);
public: public:

Loading…
Cancel
Save