Download Source Code

CCapture Class Reference

Encapsulates the windows VFW capture API. More...

#include <Capture.h>

Collaboration diagram for CCapture:

Collaboration graph
[legend]
List of all members.

Public Member Functions

BOOL ShowDialogBox (DWORD db)
 Displays the specified dialog box.
BOOL LoadDriverInfo ()
 Loads information about drivers into m_cdi.
BOOL Connect (DWORD i)
 Connects to the specified device driver.
void Destroy ()
 Closes any open driver and releases all resources.
BOOL Create (LPCTSTR pTitle=NULL, HWND hwndParent=NULL, DWORD dwStyle=WS_VISIBLE|WS_OVERLAPPEDWINDOW, long x=10, long y=10, long width=320, long height=240, int nID=0)
 Creates a capture window.
 CCapture ()
 Constructor.
virtual ~CCapture ()
 Destructor.
HWND GetSafeHwnd ()
 Returns the capture window handle.
BOOL IsWnd ()
 Returns non-zero if there is a valid capture window.
BOOL IsConnected ()
 Returns non-zero if there is an open capture device.
BOOL GetCurrentDriverInfo (LPCAPTUREDRIVERINFO pcdi)
 Retrieves information about the current capture device.
BOOL GetDriverInfo (DWORD i, LPCAPTUREDRIVERINFO pcdi)
 Retrieves information about the specified capture device.
DWORD GetNumDrivers ()
 Retuns the number of installed capture devices.
BOOL GetStatus ()
 Returns non-zero if a capture device is connected.
BOOL ShowVideoSourceDlg ()
 Displays the video source dialog box.
BOOL ShowVideoFormatDlg ()
 Displays the video format dialog box.
BOOL ShowVideoDisplayDlg ()
 Displays the video display dialog box.
BOOL ShowVideoCompressionDlg ()
 Displays the video compression dialog box.
BOOL Preview (BOOL en)
 Enables / disables preview mode.
BOOL SetPreviewRate (DWORD rate=30)
 Sets the frame rate for preview mode.
BOOL PreviewStretching (BOOL en)
 Enables / disables stretching of the preview video.
BOOL EnableOverlay (BOOL en)
 Enables / disables video overlay mode.
BOOL SetCaptureFileName (LPCTSTR pName)
 Sets the capture filename.
LPCTSTR GetCaptureFileName ()
 Returns the currently set capture filename.
BOOL GetCaptureFileName (LPSTR buf)
 Copies the currently set capture filename to the specified buffer.
BOOL FileAlloc (DWORD size)
 Pre allocates disk space for video capture.
BOOL CaptureToFile ()
 Starts capture of data to file.
BOOL SaveAs (LPCTSTR pName)
 Copies the contents of the capture file to another.
BOOL IsAudioFormatData ()
 Returns non-zero if there is audio format data.
BOOL SetAudioFormat ()
 Sets the audio format of the capture device.
BOOL GetCaptureSetup ()
 Retrieves capture setup data to m_cp.
BOOL SetCaptureSetup ()
 Sets capture setup data in m_cp to the device.
void SetCaptureAudio (BOOL ca)
 Set audio capture flag in capture setup structure m_cp.
void SetYield (BOOL yield)
 Sets yield bit in capture setup structure m_cp.
BOOL CaptureSingleFrameOpen ()
 Opens the capture file for single frame capture.
BOOL CaptureSingleFrameClose ()
 Closes the capture file for single frame capture.
BOOL CaptureSingleFrame ()
 Appends a single frame of video to the capture file.
BOOL CaptureSequence ()
 Starts streaming video capture to a file.
BOOL CaptureSequenceNoFile ()
 Starts streaming video capture without writing to file.
BOOL CaptureStop ()
 Stops current video capture.
BOOL CaptureAbort ()
 Aborts the current capture.
BOOL CopyToClipboard ()
 Copies the current video frame and palette to the clipboard.
BOOL SaveAsDIB (LPCTSTR pFile)
 Saves the current frame of video as a DIB file.
BOOL SetMCIDeviceName (LPCTSTR pName)
 Specifies the name of the MCI video device to use for capture.
BOOL GetMCIDeviceName (LPSTR pName)
 Returns the name of the current MCI device being used for capture.
BOOL SetUserData (long data)
 Associates a four byte value with the current capture window.
long GetUserData ()
 Returns the associated four byte value with the current capture window.
BOOL GrabFrame ()
 Grabs a single frame of video from the current video device.
BOOL GrabFrameNoStop ()
 Grabs a single frame of video from the current video device without stopping the capture.
BOOL WaitGrab (DWORD timeout=3000)
 Waits for a grab operation to complete.
BOOL PaletteAuto (DWORD frames, DWORD colors)
 Requests the capture driver automatically create new palettes for video frames.
BOOL PaletteManual (BOOL grab, DWORD colors)
 Requests the capture driver manually sample video frames.
BOOL LoadPalette (LPCTSTR pFile)
 Loads a color palette from a file.
BOOL GetPaletteFromClipboard ()
 Loads a color palette from the clipboard.
BOOL SavePalette (LPCTSTR pFile)
 Saves the color palette to a file.
BOOL SetScrollPos (long x, long y)
 Sets the offset of the upper left corner of the video capture window.
DWORD GetNumStatusCallbacks ()
 Returns the nnumber of status callbacks since start of capture.
DWORD GetNumErrorCallbacks ()
 Returns the number of error callbacks since start of capture.
DWORD GetNumFrameCallbacks ()
 Returns the number of frame callbacks since the start of capture.
BOOL CallbacksEnabled ()
 Returns non-zero if callbacks are enabled.
BOOL SetPos (long x, long y)
 Sets the offset of the capture window with respect to it's parent window.
BOOL SetSize (long x, long y)
 Sets the size of the capture window.
BOOL SetWindow (LPRECT pRect)
 Sets the size of the capture window.
BOOL ShowWindow (UINT uCmdShow=SW_SHOWNORMAL)
 Sets the capture windows show state.
BOOL LockDC ()
 Locks the DC.
void UnlockDC ()
 Unlocks the DC.
BOOL IsInCallback ()
 Returns non-zero if the capture thread is currently in a callback.
BOOL Reconnect ()
 Attempts reconnect of current capture device.
DWORD GetDriverIndex ()
 Returns the index of the current capture device.
BOOL SetFrameMessageTarget (HDC hDC, LPRECT pRect, HWND hWnd, UINT uMsg)
 Sets the window handle and message id for video event callbacks.
BOOL SetCaptureWindowPos (HWND hwndAfter, int x, int y, int cx, int cy, UINT flags)
 Sets the Z-Order, position and size of the capture window.
BOOL HBitmapFromFrame (HBITMAP *phbmp, LPVIDEOHDR pvhdr)
 Converts the current frame to HBITMAP.
void ReleaseVideoFormatData ()
 Releases video format data.
void ReleaseAudioFormatData ()
 Releases audio format data.
BOOL GetAudioFormat (LPWAVEFORMATEX *ppwfx=NULL)
 Gets the audio format information.
void Disconnect ()
 Disconnects current capture device.
void DisableCallbacks ()
 Disables frame callbacks.
BOOL EnableCallbacks ()
 Enables frame callbacks.
BOOL AddInfoChunk (FOURCC type, LPBYTE buf, DWORD size)
 Adds information chunk to AVI file at current position.
BOOL GetVideoFormat (LPBITMAPINFO *ppbmp=NULL, LPDWORD psize=NULL)
 Returns information about the current video format.
BOOL SetVideoFormat (LPBITMAPINFO pbmp, DWORD size)
 Sets the current video format.

Public Attributes

CAPDRIVERCAPS m_cdc
 Current driver capabilities.
CAPSTATUS m_cs
 Current driver status ( call UpdateStatus() ).
CAPTUREPARMS m_cp
 Capture params.
TThreadSafe< BOOL > m_capturelock
 Video capture access lock.
TThreadSafe< BOOL > m_dclock
 Video decode DC access lock.

Protected Member Functions

virtual BOOL OnStatus (int nID, LPCTSTR pStatus)
 Resolved video status callback.
virtual BOOL OnError (int nID, LPCTSTR pStatus)
 Resolved video error callback.
virtual BOOL OnFrame (LPVIDEOHDR pVHdr)
 Resolved video frame callback.

Static Protected Member Functions

static LRESULT PASCAL StatusCallbackProc (HWND hWnd, int nID, LPSTR lpStatusText)
 Static function proxies video status callbacks.
static LRESULT PASCAL ErrorCallbackProc (HWND hWnd, int nErrID, LPSTR lpErrorText)
 Static function proxies video error callbacks.
static LRESULT PASCAL FrameCallbackProc (HWND hWnd, LPVIDEOHDR lpVHdr)
 Static function proxies video frame callbacks.

Detailed Description

Encapsulates the windows VFW capture API.

This class manages a single VFW capture device.


Member Function Documentation

BOOL CCapture::AddInfoChunk FOURCC  type,
LPBYTE  buf,
DWORD  size
 

Adds information chunk to AVI file at current position.

Parameters:
[in] type - Value specifying info chunk type.
[in] buf - Buffer containing info chunk data.
[in] size - size of the buffer in buf.
Use this function to add arbitrary data into the current AVI video stream.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureAbort  )  [inline]
 

Aborts the current capture.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureSequence  )  [inline]
 

Starts streaming video capture to a file.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureSequenceNoFile  )  [inline]
 

Starts streaming video capture without writing to file.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureSingleFrame  )  [inline]
 

Appends a single frame of video to the capture file.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureSingleFrameClose  )  [inline]
 

Closes the capture file for single frame capture.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureSingleFrameOpen  )  [inline]
 

Opens the capture file for single frame capture.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureStop  )  [inline]
 

Stops current video capture.

Returns:
Returns non-zero if success.

BOOL CCapture::CaptureToFile  )  [inline]
 

Starts capture of data to file.

Returns:
Returns non-zero if success.

BOOL CCapture::Connect DWORD  i  ) 
 

Connects to the specified device driver.

Parameters:
[in] i - The index of the driver to connect to.
Returns:
Returns non-zero if success.

BOOL CCapture::CopyToClipboard  )  [inline]
 

Copies the current video frame and palette to the clipboard.

Returns:
Returns non-zero if success.

BOOL CCapture::Create LPCTSTR  pTitle = NULL,
HWND  hwndParent = NULL,
DWORD  dwStyle = WS_VISIBLE|WS_OVERLAPPEDWINDOW,
long  x = 10,
long  y = 10,
long  width = 320,
long  height = 240,
int  nID = 0
 

Creates a capture window.

Parameters:
[in] pTitle - Title for the capture window.
[in] hwndParent - Handle of the parent window.
[in] dwStyle - Window styles for the capture window.
[in] x - Horizontal offset for the capture window.
[in] y - Vertical offset for the capture window.
[in] width - Width of the capture window.
[in] height - Height of the capture window.
[in] nID - Contorl id for the capture window.
Returns:
Returns non-zero if success.

BOOL CCapture::EnableCallbacks  ) 
 

Enables frame callbacks.

Returns:
Returns non-zero if success.

BOOL CCapture::EnableOverlay BOOL  en  )  [inline]
 

Enables / disables video overlay mode.

Parameters:
[in] en - Set to non-zero to enable overlay. Zero to disable.
Returns:
Returns non-zero if success.

BOOL CCapture::FileAlloc DWORD  size  )  [inline]
 

Pre allocates disk space for video capture.

Parameters:
[in] size - The amount of video space to allocate.
Returns:
Returns non-zero if success.

BOOL CCapture::GetAudioFormat LPWAVEFORMATEX *  ppwfx = NULL  ) 
 

Gets the audio format information.

Parameters:
[out] ppwfx - Receives the audio format data.
Returns:
Returns non-zero if success.

BOOL CCapture::GetCaptureFileName LPSTR  buf  )  [inline]
 

Copies the currently set capture filename to the specified buffer.

Parameters:
[in] buf - Character buffer that receives the filename.
Returns:
Returns non-zero if success.

BOOL CCapture::GetCaptureSetup  )  [inline]
 

Retrieves capture setup data to m_cp.

Returns:
Returns non-zero if success.

BOOL CCapture::GetCurrentDriverInfo LPCAPTUREDRIVERINFO  pcdi  )  [inline]
 

Retrieves information about the current capture device.

Parameters:
[out] pcdi - Structure that receives information about the currently open capture driver.
Returns:
Returns non-zero if success.

BOOL CCapture::GetDriverInfo DWORD  i,
LPCAPTUREDRIVERINFO  pcdi
[inline]
 

Retrieves information about the specified capture device.

Parameters:
[in] i - Index of the capture driver to query.
[out] pcdi - Structure that receives information about the currently open capture driver.
Returns:
Returns non-zero if success.

BOOL CCapture::GetMCIDeviceName LPSTR  pName  )  [inline]
 

Returns the name of the current MCI device being used for capture.

Parameters:
[in] pName - Address of a buffer that receives the MCI device name.
Returns:
Returns non-zero if success.

BOOL CCapture::GetPaletteFromClipboard  )  [inline]
 

Loads a color palette from the clipboard.

Returns:
Returns non-zero if success.

long CCapture::GetUserData  )  [inline]
 

Returns the associated four byte value with the current capture window.

Returns:
Returns four byte user value.

BOOL CCapture::GetVideoFormat LPBITMAPINFO *  ppbmp = NULL,
LPDWORD  psize = NULL
 

Returns information about the current video format.

Parameters:
[out] ppbmp - Structure to receive current video format information.
[out] psize - Receives the size of the data copied to ppbmp.
Returns:
Returns non-zero if success.

BOOL CCapture::GrabFrame  ) 
 

Grabs a single frame of video from the current video device.

Returns:
Returns non-zero if success.

BOOL CCapture::GrabFrameNoStop  )  [inline]
 

Grabs a single frame of video from the current video device without stopping the capture.

Returns:
Returns non-zero if success.

BOOL CCapture::HBitmapFromFrame HBITMAP *  phbmp,
LPVIDEOHDR  pvhdr
 

Converts the current frame to HBITMAP.

Parameters:
[out] phbmp - Receives the handle of the newly created HBITMAP.
[out] pvhdr - Video header for frame.
Returns:
Returns non-zero if success.

BOOL CCapture::LoadDriverInfo  ) 
 

Loads information about drivers into m_cdi.

Returns:
Returns non-zero if success.

BOOL CCapture::LoadPalette LPCTSTR  pFile  )  [inline]
 

Loads a color palette from a file.

Parameters:
[in] pFile - File name of the palette.
Returns:
Returns non-zero if success.

BOOL CCapture::LockDC  )  [inline]
 

Locks the DC.

Use this function to coordinate multi thread access to video frames. If this function returns zero, do not attempt to access the video buffers.

Returns:
Returns non-zero if buffer was locked.

BOOL CCapture::OnFrame LPVIDEOHDR  pVHdr  )  [protected, virtual]
 

Resolved video frame callback.

Parameters:
[in] pVHdr - Video header information.
Video header structure

        
        typedef struct 
        {
            LPSTR lpData;            // address of video buffer
            DWORD dwBufferLength;    // size, in bytes, of the 
                                     // data buffer
            DWORD dwBytesUsed;       // see below
            DWORD dwTimeCaptured;    // see below
            DWORD dwUser;            // user-specific data
            DWORD dwFlags;           // see below
            DWORD dwReserved[4];     // reserved; do not use
        } VIDEOHDR;

  • Members -

dwBytesUsed: Number of bytes used in the data buffer.

dwTimeCaptured: Time, in milliseconds, when the frame was captured relative to the first frame in the stream. Synchronization of audio and video in the resulting AVI file depends solely on this parameter, which should be derived directly from a counter (VSYNC_Count) incremented by a vertical sync interrupt. When using NTSC frame rates and frame-based interrupts, the returned value would be:

dwTimeCaptured = VSYNC_Count * 1/29.97.

The capture driver must maintain VSYNC_Count accurately by allowing recursive entry into the interrupt service routine (if only for the purpose of incrementing VSYNC_Count) and by not disabling interrupts for long periods of time.

dwFlags: Flags giving information about the data buffer. The following flags are defined for this field: VHDR_DONE Set by the device driver to indicate it is finished with the data buffer and it is returning the buffer to the application.

VHDR_PREPARED Set by the system to indicate the data buffer has been prepared with videoStreamPrepareHeader. VHDR_INQUEUE Set by the system to indicate the data buffer is queued for playback. VHDR_KEYFRAME Set by the device driver to indicate a key frame.

BOOL CCapture::PaletteAuto DWORD  frames,
DWORD  colors
[inline]
 

Requests the capture driver automatically create new palettes for video frames.

Parameters:
[in] frames - Number of frames to sample.
[in] colors - Number of colors in palette, cannot be more than 256.
Returns:
Returns non-zero if success.

BOOL CCapture::PaletteManual BOOL  grab,
DWORD  colors
[inline]
 

Requests the capture driver manually sample video frames.

Parameters:
[in] grab - Set to true for each frame included in palette.
[in] colors - Number of colors in palette, cannot be more than 256. This value is only used on the first frame of the sequence.
Call this function for each frame you want to include in the palette.

Returns:
Returns non-zero if success.

BOOL CCapture::Preview BOOL  en  )  [inline]
 

Enables / disables preview mode.

Parameters:
[in] en - Set to non-zero to enable preview mode. Zero to disable.
Returns:
Returns non-zero if success.

BOOL CCapture::PreviewStretching BOOL  en  )  [inline]
 

Enables / disables stretching of the preview video.

Parameters:
[in] en - Set to non-zero to enable stretching. Zero to disable.
Returns:
Returns non-zero if success.

BOOL CCapture::Reconnect  ) 
 

Attempts reconnect of current capture device.

Returns:
Returns non-zero if success.

BOOL CCapture::SaveAs LPCTSTR  pName  )  [inline]
 

Copies the contents of the capture file to another.

Parameters:
[in] pName - New filename.
If a larger amount of data was allocated with FileAlloc() than was actually used. This function copies only the used data.

Returns:
Returns non-zero if success.

BOOL CCapture::SaveAsDIB LPCTSTR  pFile  )  [inline]
 

Saves the current frame of video as a DIB file.

Parameters:
[in] pFile - File name for DIB.
Returns:
Returns non-zero if success.

BOOL CCapture::SavePalette LPCTSTR  pFile  )  [inline]
 

Saves the color palette to a file.

Parameters:
[in] pFile - File name of the palette.
Returns:
Returns non-zero if success.

BOOL CCapture::SetAudioFormat  )  [inline]
 

Sets the audio format of the capture device.

Returns:
Returns non-zero if success.

BOOL CCapture::SetCaptureFileName LPCTSTR  pName  )  [inline]
 

Sets the capture filename.

Parameters:
[in] pName - The filename for capture
Returns:
Returns non-zero if success.

BOOL CCapture::SetCaptureSetup  )  [inline]
 

Sets capture setup data in m_cp to the device.

Returns:
Returns non-zero if success.

BOOL CCapture::SetCaptureWindowPos HWND  hwndAfter,
int  x,
int  y,
int  cx,
int  cy,
UINT  flags
 

Sets the Z-Order, position and size of the capture window.

Parameters:
[in] hwndAfter - Puts the capture window after this window in the Z-Order.
[in] x - Horizontal offset of upper left corner of capture window.
[in] y - Veritical offset of upper left corner of capture window.
[in] cx - Horizontal size of capture window.
[in] cy - Vertical size of capture window.
[in] flags - Flags to pass to SetWindowPos()
Returns:
Returns non-zero if success.

BOOL CCapture::SetFrameMessageTarget HDC  hDC,
LPRECT  pRect,
HWND  hWnd,
UINT  uMsg
 

Sets the window handle and message id for video event callbacks.

Parameters:
[in] hDC - DC that will receive each video frame.
[in] pRect - Size of the DC in hDC.
[in] hWnd - Window that receives the callback.
[in] uMsg - Message ID for callbacks.
Returns:
Returns non-zero if success.

BOOL CCapture::SetMCIDeviceName LPCTSTR  pName  )  [inline]
 

Specifies the name of the MCI video device to use for capture.

Parameters:
[in] pName - Name of the MCI device.
Returns:
Returns non-zero if success.

BOOL CCapture::SetPos long  x,
long  y
[inline]
 

Sets the offset of the capture window with respect to it's parent window.

Parameters:
[in] x - Horizontal offset of video capture window.
[in] y - Vertical offset of video capture window.
Returns:
Returns non-zero if success.

BOOL CCapture::SetPreviewRate DWORD  rate = 30  )  [inline]
 

Sets the frame rate for preview mode.

Parameters:
[in] rate - Frame rate of video preview
Returns:
Returns non-zero if success.

BOOL CCapture::SetScrollPos long  x,
long  y
[inline]
 

Sets the offset of the upper left corner of the video capture window.

Parameters:
[in] x - Horizontal offset of video capture window.
[in] y - Vertical offset of video capture window.
Returns:
Returns non-zero if success.

BOOL CCapture::SetSize long  x,
long  y
[inline]
 

Sets the size of the capture window.

Parameters:
[in] x - Horizontal size of video capture window.
[in] y - Vertical size of video capture window.
Returns:
Returns non-zero if success.

BOOL CCapture::SetUserData long  data  )  [inline]
 

Associates a four byte value with the current capture window.

Parameters:
[in] data - Data to associate.
Returns:
Returns non-zero if success.

BOOL CCapture::SetVideoFormat LPBITMAPINFO  pbmp,
DWORD  size
[inline]
 

Sets the current video format.

Parameters:
[in] pbmp - Structure containing video format information.
[in] size - Receives the size of the data copied to pbmp.
Returns:
Returns non-zero if success.

BOOL CCapture::SetWindow LPRECT  pRect  )  [inline]
 

Sets the size of the capture window.

Parameters:
[in] pRect - Rectangle defining new capture window position with respect to the parent window.
Returns:
Returns non-zero if success.

BOOL CCapture::ShowDialogBox DWORD  db  ) 
 

Displays the specified dialog box.

Parameters:
[in] db - The dialog box to display.
  • CCAPTURE_DLG_VIDSOURCE - Video source
  • CCAPTURE_DLG_VIDFORMAT - Video Format
  • CCAPTURE_DLG_VIDDISPLAY - Video display
  • CCAPTURE_DLG_VIDCOMPRESSION - Video compression
Returns:
Returns non-zero if success.

BOOL CCapture::ShowVideoCompressionDlg  )  [inline]
 

Displays the video compression dialog box.

Returns:
Returns non-zero if success.

BOOL CCapture::ShowVideoDisplayDlg  )  [inline]
 

Displays the video display dialog box.

Returns:
Returns non-zero if success.

BOOL CCapture::ShowVideoFormatDlg  )  [inline]
 

Displays the video format dialog box.

Returns:
Returns non-zero if success.

BOOL CCapture::ShowVideoSourceDlg  )  [inline]
 

Displays the video source dialog box.

Returns:
Returns non-zero if success.

BOOL CCapture::ShowWindow UINT  uCmdShow = SW_SHOWNORMAL  )  [inline]
 

Sets the capture windows show state.

Parameters:
[in] uCmdShow - Flag specifying how the capture window is to be shown.
See the Windows API function ShowWindow()

Returns:
Returns non-zero if success.

void CCapture::UnlockDC  )  [inline]
 

Unlocks the DC.

Use this function to coordinate multi thread access to video frames

BOOL CCapture::WaitGrab DWORD  timeout = 3000  )  [inline]
 

Waits for a grab operation to complete.

Parameters:
[in] timeout - Maximum amount of time, in milli-seconds, to wait for a grab operation to complete.
Returns:
Returns non-zero if success.


The documentation for this class was generated from the following files:
  • inc/Capture.h
  • Capture.cpp
Copyright Robert Umbehant
This documentation is covered by the LGPL