Wrapper for AVICap Window

Introduction

As well known, AVICap window class provides applications with a message-based interface to access video and waveform-audio acquisition hardware and to control the process of streaming video capture to disk. Unfortunately, it has a few serious limitations:

  • All of setup operations for format, source and videostandard are implemented within driver dialogs. Program control is
    complicated and without of any warranties of true results.
  • Capture conditions are strongly related with WM_VISIBLE flag of AVICap window.
  • There is no ability of window stretching.
  • Most of capture drivers has internal buffers queue (fifo), so they can't provide satisfactory time accuracy when user application needs to grab a single frame. They simply returns last frame from buffers queue.

In short, AVICap window is really good enough for control the process of streaming video capture to disk,
but in most cases useless for real-time video processing. For resolving this problem, i have wrote my own wrapper for AVICap windows which extended its functionality in order to work with real-time videoprocessing application.

Note: Win16 API provides interface for direct drivers access (all capture drivers, i know are 16 bits). This allows to build real-time program without huge and slow AVICap windows. Win32 API do not allow to interface with 16 bits drivers directly.

Class Implementation

Class AviCap was implemented by usual for MFC way("dynamically subclass"). Most of public methods are helpers for WM_CAP_XXXX messaging, but a few methods gives enhanced control for programmers.

Connection:

//Connect with specific driver. According to compile setting and 
//m_DoQuickConnection flag, connection can be quick or with a full 
//preliminary testing
BOOL ConnectWithDriver(LPCSTR Name=NULL);
BOOL ConnectWithDriver(INT indx);

Enhanced control:

//Reset internal driver buffers queue(if exist)
VOID ResetCache(); 
//Quick format setup
BOOL SetFormat(LPBITMAPINFO bmpinf); 
BOOL SetBitResolution(UINT reqBitsCount);
BOOL SetFrameSize(INT x, INT y);
BOOL SetFrameSize(CSize sz);

Enhanced formats information:

//Fill struct with a driver infoBOOL GetDriverInfo(CAPDRVINFO *cdi);
//Quick information about current format
CSize GetFrameSize(); 
DWORD GetRequiredBufferSize();
LPBITMAPINFO GetCurrentFormat();
BOOL IsSupportedBitsResolution(UINT uBitsCount);
DWORD GetCurrentBitsResolution();
//Enumerate all valid frame sizes
BOOL EnumValidFrameSize(CSize &sz, int indx);

Driver information:

//Get full list of installed capture drivers
INT GetDriversList(CStringArray *Names, CStringArray *Versions); 
//Get current driver name, version and index
LPCSTR GetDriverName();
LPCSTR GetDriverVer();
INT GetDriverIndex();

Setup specific callbacks functions for painting and progress notification:

//Setup callback for painting on the capture window
VOID SetDrawCallBack(DRAWCALLBACK cb);
/Setup callback for notification about progress during testing
VOID SetProgressCallback(LPVOID cb);

Other:

//Switch Stretch/No mode
VOID AdjustPlacement(BOOL fStretch=FALSE);

Notes:

  • Some drivers can splash Message box during testing.
  • The list of "public formats" from driver dialog can be appreciable different from list that you can get using EnumValidFrameSize method. This is a really strange fact, but it can be very useful.

Demo program:

Project was compiled and tested with MSV C++ 5.0. This small demo program connect with first capture driver installed on computer and performs full testing of driver. Some of "standard" and "enhanced" commands of this class are gathered in menu.

Downloads

Download source - 13 KB
Download demo project - 36 KB


Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds