CodeVis.com SourceForge.net Logo

VidCapDll.cpp File Reference


Detailed Description

C-style DLL wrapper for VidCapture library.

RCSfile
VidCapDll.cpp,v
Date
2004/03/01 18:31:06
Revision
1.4
Author
mikeellison

Definition in file VidCapDll.cpp.

#include <windows.h>
#include "VidCapDll.h"
#include "CVResDll.h"
#include "CVUtil.h"
#include "VidCapture.h"

Go to the source code of this file.

Compounds

Functions


Function Documentation

CVRES VIDCAPFUNC CVAcquireVidCap CVVIDCAPSYSTEM capSystem  ) 
 

CVAcquireVidCap() acquires a video capture object and initializes it. You must call CVReleaseVidCap() when done with the handle returned on a successful call.

Parameters:
capSystem - ref to handle. Contains new handle on success.
Returns:
CVRES - CVRES_SUCCESS on successful initialization.
See also:
CVReleaseVidCap()

Successful - save handle and return

Didn't initialize properly - uninitialize and return error.

Definition at line 96 of file VidCapDll.cpp.

References CVPlatform::AcquireVideoCapture(), CVRES, CVRES_DLL_VIDCAP_CREATE_ERROR, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVSUCCESS, CVVIDCAPSYSTEM, CVPlatform::GetPlatform(), CVVidCapture::Init(), CVPlatform::Release(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevConnect CVVIDCAPSYSTEM  capSystem,
int  devIndex
 

CVDevConnect() connects to the specified device. Only one device should be connected at a time.

Call CVDevDisconnect() then done with the capture device handle.

Parameters:
capSystem - handle from CVAcquireVidCap()
devIndex - index of device (from GetDeviceName/GetNumDevices)
Returns:
CVRES - CVRES_SUCCESS on success
See also:
CVDevDisconnect(), CVGetDeviceName(), CVAcquireVidCap()

Definition at line 283 of file VidCapDll.cpp.

References CVVidCapture::Connect(), CVAssert, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevDisconnect CVVIDCAPSYSTEM  capSystem  ) 
 

CVDevDisconnect() disconnects a previously connected device. CVDevDisconnect() should be called when done with a capture device connected via CVDevConnect().

Parameters:
capSystem - handle from CVAcquireVidCap()
Returns:
CVRES - CVRES_SUCCESS on success
See also:
CVDevCOnnect()

Definition at line 306 of file VidCapDll.cpp.

References CVAssert, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVVidCapture::Disconnect(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevGetFormatName CVVIDCAPSYSTEM  capSystem,
int  vidFormat,
char *  vidFormatNameBuf,
int *  vidFormatBufLen
 

CVDevGetFormatName() retrieves the name of the video format for a camera mode.

Parameters:
capSystem - handle from CVAcquireVidCap()
vidFormat - video format type (from CVDevGetModeInfo)
vidFormatNameBuf - ptr to buffer to receive format name
vidFormatBufLen - ptr to length of buffer. set to length of name on return.
Returns:
CVRES - CVRES_SUCCESS on success
See also:
CVDevGetModeInfo()

Definition at line 422 of file VidCapDll.cpp.

References CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVRES_VIDCAP_VIDEO_FORMAT_NOT_SUPPORTED, CVVidCapture::GetFormatModeName(), VIDCAP_FORMAT, VIDCAP_NUM_FORMATS, and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevGetModeInfo CVVIDCAPSYSTEM  capSystem,
int  modeIndex,
int *  xRes,
int *  yRes,
int *  frameRate,
int *  vidFormat
 

CVDevGetModeInfo() retrieve information about the specified mode.

Parameters:
capSystem - handle from CVAcquireVidCap()
modeIndex - index of mode to use for capture
xRes - ptr to receive x resolution of the camera mode
yRes - ptr to receive y resolution of the camera mode
frameRate - ptr to receive estimated framerate (may be null)
vidFormat - ptr to receive input video mode value (VIDCAP_FORMAT) may be null.
Returns:
CVRES - CVRES_SUCCESS on success
See also:
CVDevGetNumModes(), CVDevConnect(),

Definition at line 363 of file VidCapDll.cpp.

References CVAssert, CVFAILED, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::VIDCAP_MODE::EstFrameRate, CVVidCapture::GetModeInfo(), CVVidCapture::VIDCAP_MODE::InputFormat, VIDCAPFUNC, CVVidCapture::VIDCAP_MODE::XRes, and CVVidCapture::VIDCAP_MODE::YRes.

Referenced by main().

int VIDCAPFUNC CVDevGetNumModes CVVIDCAPSYSTEM  capSystem  ) 
 

CVDevGetNumModes() retrieves the number of available mode on a connected capture device.

You *must* connect to a device before you can retrieve the available modes for it. If you do not, you'll just get 0 for the number of modes.

Parameters:
capSystem - handle from CVAcquireVidCap()
Returns:
int - number of modes available for the connected device

An error occurred...

Definition at line 329 of file VidCapDll.cpp.

References CVAssert, CVSUCCESS, CVVidCapture::GetNumSupportedModes(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevGetProperty CVVIDCAPSYSTEM  capSystem,
CVCAMERAPROP  property,
long *  curValue,
long *  defValue,
long *  minValue,
long *  maxValue,
long *  step
 

CVDevGetProperty() retrieves the current, minimum, and maximum values for the specified property.

If the property is not supported by the camera, then it will return CVRES_DLL_VIDCAP_UNSUPPORTED_PROPERTY.

Parameters:
capSystem - handle to *connected* capture system.
property - property identifier
curValue - ptr to receive current value of property.
defValue - ptr to receive default value of property.
minValue - ptr to receive minimum value of property.
maxValue - ptr to receive maximum value of property.
step - ptr to receive the minimum step distance between values.
See also:
CVDevSetProperty()
This is a bit fugly, but I want to allow the class values to change while the DLL Values can't. Also, some properties probably shouldn't be messed with by the DLL (e.g. COLOR).

And, we've got the added bonus that bad values can be detected here...

Definition at line 882 of file VidCapDll.cpp.

References CVVidCapture::CAMERA_PROPERTY, CVVidCapture::CAMERAPROP_BRIGHT, CVVidCapture::CAMERAPROP_CONTRAST, CVVidCapture::CAMERAPROP_GAIN, CVVidCapture::CAMERAPROP_GAMMA, CVVidCapture::CAMERAPROP_HUE, CVVidCapture::CAMERAPROP_SAT, CVVidCapture::CAMERAPROP_SHARP, CVVidCapture::CAMERAPROP_WHITEBALANCE, CVAssert, CVCAM_BRIGHT, CVCAM_CONTRAST, CVCAM_GAIN, CVCAM_GAMMA, CVCAM_HUE, CVCAM_SAT, CVCAM_SHARP, CVCAM_WHITEBALANCE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVVidCapture::GetPropertyInfo(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevGrabImage CVVIDCAPSYSTEM  capSystem,
int  modeIndex,
CVIMAGETYPE  imageType,
CVIMAGESTRUCT **  imageStructPtrPtr
 

CVDevGrabImage() grabs a single image from a selected and connected camera.

You must free the returned pointer when done by calling CVReleaseImage() on it or you will leak massive amounts of memory.

Parameters:
capSystem - handle from CVAcquireVidCap()
modeIndex - index of mode to use for capture
imageType - requested type of image
imageStructPtrPtr - ptr to receive a ptr to created image struct. Call CVReleaseImage() on the returned image struct ptr when done.
Returns:
CVRES - CVRES_SUCCESS on success
See also:
CVDevGetModeInfo()

Select mode for grab

Perform the grab

Check validity of image struct**, then set it to null in case something fails.

Definition at line 471 of file VidCapDll.cpp.

References CVAssert, CVFAILED, CVImage::CVIMAGE_TYPE, CVImgStructFromImage(), CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::Grab(), CVImage::ReleaseImage(), CVVidCapture::SetMode(), and VIDCAPFUNC.

CVRES VIDCAPFUNC CVDevSetProperty CVVIDCAPSYSTEM  capSystem,
CVCAMERAPROP  property,
long  newValue
 

CVDevSetProperty() sets the specified property value for the camera.

If the property is not supported by the camera, then it will return CVRES_DLL_VIDCAP_UNSUPPORTED_PROPERTY.

Parameters:
capSystem - handle to *connected* capture system.
property - property identifier
newValue - new value for the property. Should be within range given by CVGetProperty()
See also:
CVDevGetProperty()
This is a bit fugly, but I want to allow the class values to change while the DLL Values can't. Also, some properties probably shouldn't be messed with by the DLL (e.g. COLOR).

And, we've got the added bonus that bad values can be detected here...

Definition at line 966 of file VidCapDll.cpp.

References CVVidCapture::CAMERA_PROPERTY, CVVidCapture::CAMERAPROP_BRIGHT, CVVidCapture::CAMERAPROP_CONTRAST, CVVidCapture::CAMERAPROP_GAIN, CVVidCapture::CAMERAPROP_GAMMA, CVVidCapture::CAMERAPROP_HUE, CVVidCapture::CAMERAPROP_SAT, CVVidCapture::CAMERAPROP_SHARP, CVVidCapture::CAMERAPROP_WHITEBALANCE, CVAssert, CVCAM_BRIGHT, CVCAM_CONTRAST, CVCAM_GAIN, CVCAM_GAMMA, CVCAM_HUE, CVCAM_SAT, CVCAM_SHARP, CVCAM_WHITEBALANCE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVVidCapture::SetProperty(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevStartCap CVVIDCAPSYSTEM  capSystem,
int  modeIndex,
CVIMAGETYPE  imageType,
CVVIDCAPDLLCB  callback,
void *  cbUserParam,
CVCAPHANDLE capHandlePtr
 

CVDevStartCap() starts a continuous capture, sending each image to the specified callback.

The CVIMAGESTRUCT* passed to the callback is *only* valid during the callback! You must copy the data out if you'll need it later. However, you should NOT call CVReleaseImage() on it - the DLL will do that for you when your callback function returns.

Parameters:
capSystem - handle from CVAcquireVidCap()
modeIndex - index of mode to use for capture
imageType - type of image to capture
callback - callback to receive images during capture
cbUserParam - user parameter to send to callback
capHandlePtr - ptr to receive capture handle.
Returns:
CVRES - CVRES_SUCCESS on success

Create a capture structure for our callback

If we didn't start successfully, clean up the capture struct

Definition at line 594 of file VidCapDll.cpp.

References CVAssert, CVCAPHANDLE, CVFAILED, CVImage::CVIMAGE_TYPE, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, DllCaptureCb(), DLLCAPTURESTRUCT::HostCallback, DLLCAPTURESTRUCT::HostUserParam, CVVidCapture::StartImageCap(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVDevStopCap CVVIDCAPSYSTEM  capSystem,
CVCAPHANDLE  capHandle
 

CVDevStopCap() halts an image capture session started by CVDevStartCap().

This must be called for cleanup even if the capture is stopped prematurely by an error or by returning false from within the callback function.

Parameters:
capSystem - vidcap handle from CVAcquireVidCap()
capHandle - cap handle received from CVDevStartCap()

Cleanup the capture structure

Definition at line 639 of file VidCapDll.cpp.

References CVAssert, CVRES, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::Stop(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVGetDeviceName CVVIDCAPSYSTEM  capSystem,
int  deviceNum,
char *  devNameBuffer,
int *  nameBufLen
 

CVGetDeviceName() retrieves the name of a capture device into the provided buffer.

Parameters:
capSystem - handle from CVAcquireVidCap()
deviceNum - index of device (0 -> CVGetNumDevices() - 1)
devNameBuffer - buffer to receive ASCIIZ device name. must be allocated by caller!
nameBufLen - ptr to Maximum length of devNameBuffer. set to length of device name on return.
Returns:
CVRES - CVRES_SUCCESS on success.
See also:
CVGetNumDevices(), CVDevConnect()

Definition at line 230 of file VidCapDll.cpp.

References CVAssert, CVFAILED, CVRES, CVRES_DLL_VIDCAP_DEV_NOT_FOUND, CVRES_DLL_VIDCAP_INVALID_HANDLE, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVVidCapture::VIDCAP_DEVICE::DeviceString, CVVidCapture::GetDeviceInfo(), and VIDCAPFUNC.

Referenced by main().

int VIDCAPFUNC CVGetNumDevices CVVIDCAPSYSTEM  capSystem  ) 
 

CVGetNumDevices() retrieves the number of capture devices available to the VidCap .DLL.

Parameters:
capSystem - handle from CVAcquireVidCap()
Returns:
int - number of available capture devices.

CVRES_DLL_VIDCAP_INVALID_HANDLE

Definition at line 159 of file VidCapDll.cpp.

References CVAssert, CVVidCapture::GetNumDevices(), and VIDCAPFUNC.

Referenced by main().

void VIDCAPFUNC CVGetVidCapString char *  buffer,
int *  bufLength
 

CVGetVidCapString() retrieves the library identifier/copyright string.

Parameters:
buffer - buffer to receive capture string
bufLength - ptr to size of buffer. Set to length of string on return.

Definition at line 794 of file VidCapDll.cpp.

References kVIDCAPTURE_STRING, and VIDCAPFUNC.

Referenced by main().

CVRES CVImgStructFromImage CVIMAGESTRUCT **  imageStructPtrPtr,
CVImage image
 

Internal function to create an image structure from an image class.

CVImgStructFromImage() is an internal function to convert from a CVImage* to a CVIMAGESTRUCT*.

You must call CVReleaseImage() on the created CVIMAGESTRUCT* when done.

Parameters:
imageStructPtrPtr - ptr to receive a ptr to created image struct. Call CVReleaseImage() on the returned image struct ptr when done.
image - image class object to convert
Returns:
CVRES - CVRES_SUCCESS on success

Bail if we couldn't allocate pixel data

Copy image

Definition at line 821 of file VidCapDll.cpp.

References CVIMAGESTRUCT::BytesPerPixel, CVIMAGETYPE, CVRES, CVRES_INVALID_PARAMETER, CVRES_OUT_OF_MEMORY, CVRES_SUCCESS, CVImage::GetBytesPerPixel(), CVImage::GetImageType(), CVImage::GetNumChannels(), CVImage::GetRawDataPtr(), CVImage::Height(), CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, kCVIMAGESTRUCTVER, CVIMAGESTRUCT::NumChannels, CVIMAGESTRUCT::PixelDataPtr, CVIMAGESTRUCT::Version, and CVImage::Width().

Referenced by CVDevGrabImage(), and CVLoadImage().

CVRES VIDCAPFUNC CVLoadImage const char *  filename,
CVIMAGESTRUCT **  imageStructPtrPtr
 

CVLoadImage() loads an image from the specified .ppm/.pgm file.

You must release it with CVReleaseImage() when done.

Parameters:
filename - pointer to ASCIIZ filename of .ppm/.pgm file.
imageStructPtrPtr - ptr to receive a ptr to created image struct. Call CVReleaseImage() on the returned image struct ptr when done.
See also:
CVReleaseImage(), CVSaveImage()

Load in the image

Convert image object to our struct type

Check validity of image struct**, then set it to null in case something fails.

Definition at line 679 of file VidCapDll.cpp.

References CVFAILED, CVImgStructFromImage(), CVRES, CVRES_INVALID_PARAMETER, CVRES_SUCCESS, CVImage::Load(), CVImage::ReleaseImage(), and VIDCAPFUNC.

void VIDCAPFUNC CVReleaseImage CVIMAGESTRUCT imageStructPtr  ) 
 

CVReleaseImage() releases an image retrieved from CVDevGrabImage() and CVLoadImage().

Parameters:
imageStructPtr - pointer to image struct to release

Definition at line 776 of file VidCapDll.cpp.

References CVIMAGESTRUCT::PixelDataPtr, and VIDCAPFUNC.

CVRES VIDCAPFUNC CVReleaseVidCap CVVIDCAPSYSTEM  capSystem  ) 
 

CVReleaseVidCap() releases a previously allocated video capture object.

Parameters:
capSystem - handle from CVACquireVidCap().
See also:
CVAcquireVidCap()

Definition at line 132 of file VidCapDll.cpp.

References CVRES, CVRES_SUCCESS, CVPlatform::GetPlatform(), CVPlatform::Release(), and VIDCAPFUNC.

Referenced by main().

CVRES VIDCAPFUNC CVSaveImage const char *  filename,
CVIMAGESTRUCT imageStructPtr,
BOOL  overwrite
 

CVSaveImage() saves an image from a CVIMAGESTRUCT* to disk.

Parameters:
filename - pointer to ASCIIZ filename of .ppm/.pgm file.
imageStructPtr - ptr to image struct
overwrite - TRUE to overwrite existing files, FALSE otherwise.
See also:
CVLoadImage()

Check image data size in struct

Invalid image size...

Create a CVImage to contain the passed in image for saving...

Double check bytes per pixel before performing copy

Copy data into CVImage

Save it, free up the CVImage, and exit

Definition at line 718 of file VidCapDll.cpp.

References CVIMAGESTRUCT::BytesPerPixel, CVImage::CreateImage(), CVFAILED, CVImage::CVIMAGE_TYPE, CVRES, CVRES_DLL_VIDCAP_INVALID_IMAGE_STRUCT, CVRES_INVALID_PARAMETER, CVImage::GetBytesPerPixel(), CVImage::GetRawDataPtr(), CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, CVIMAGESTRUCT::PixelDataPtr, CVImage::ReleaseImage(), CVImage::Save(), and VIDCAPFUNC.

bool DllCaptureCb CVRES  status,
CVImage capturedImage,
void *  userParam
 

DllCaptureCb() is a passthrough for the capture callback from CVVidCapture() to the host program.

It converts the CVImage* to a CVIMAGESTRUCT*, then calls the host.

If we have an image, convert it to an image struct

No image to pass - just call callback and return result.

Unlike the image grabs, we don't waste time copying the memory out. Just fill in the struct, then point to the CVImage's pixel data.

Definition at line 535 of file VidCapDll.cpp.

References CVIMAGESTRUCT::BytesPerPixel, CVIMAGETYPE, CVSUCCESS, CVImage::GetBytesPerPixel(), CVImage::GetImageType(), CVImage::GetNumChannels(), CVImage::GetRawDataPtr(), CVImage::Height(), DLLCAPTURESTRUCT::HostCallback, DLLCAPTURESTRUCT::HostUserParam, CVIMAGESTRUCT::ImageDataSize, CVIMAGESTRUCT::ImageHeight, CVIMAGESTRUCT::ImageType, CVIMAGESTRUCT::ImageWidth, kCVIMAGESTRUCTVER, CVIMAGESTRUCT::NumChannels, CVIMAGESTRUCT::PixelDataPtr, CVIMAGESTRUCT::Version, and CVImage::Width().

Referenced by CVDevStartCap().

BOOL WINAPI DllMain HINSTANCE  hInst,
DWORD  dwReason,
LPVOID  lpvReserved
 

DLLMain() - DLL entry point... Do we need to set aside thread storage? Hopefully not for now. To make things work between threads/apps we just create an entirely new CVVidCapture instance for each caller and then use that as a handle.

Process starting....

Process exiting...

Definition at line 64 of file VidCapDll.cpp.

References kVIDCAPTURE_STRING.

bool FindDeviceCB const char *  devname,
void *  userParam
 

FindDeviceCB is a callback for CVVidCapture::EnumDevices. It counts devices until it finds the requested one, then saves the device name.

This method isn't particularly efficient - later we should store a list but refresh it periodically or on the appropriate WM_DEVICECHANGE message.

Definition at line 199 of file VidCapDll.cpp.

References CVFINDDEVINFO::CurDev, CVFINDDEVINFO::DevName, and CVFINDDEVINFO::ReqDev.


Generated on Mon Mar 1 13:27:13 2004 for VidCapture Library by doxygen 1.3.3
CodeVis VidCapture 0.2 Copyright © 2003-2004 by Michael Ellison.