Opening and Handling Devices: Save And Restore a Video Cacpture Device Properties

This short source code snippet illustrates how to save and restore video capture device properties with IC Imaging Control.
Language:Visual C++
Version:3.0.3
Released on:April 7, 2005
Author:IC Imaging Control Support Department
Requirements:IC Imaging Control >2.1
Camera, converter or grabber with WDM Stream Class drivers.

The sample application's window looks as follows:

The dialog window of the sample application.

First of all, an MFC - Dialog based application is created. Additionally, there are four buttons for opening the video capture device, show the IC Imaging Control's built-in property dialog and save and load the device from an .xml file.

An instance of the Grabber class must be created as member of the dialog class.

DShowLib::Grabber        m_cGrabber; // The instance of the Grabber class.

In the "Device" button event handler a video capture device is to be selected. First of all, it must be checked, whether the current Grabber object contains already a running video capture device, before IC Imaging Control's built-in "Device Selection" dialog can be called. The "Device Settings" dialog is shown with a call to Grabber::showDevicePage(). After the "Device Settings" dialog has been left, it is checked whehter a valid video capture device has been selected. If the video capture device in the Grabber object is valid, then the image data stream is started with a call to Grabber::startLive().

void CSaveRestorePropertiesDlg::OnBnClickedDevice()
{
    if(m_cGrabber.isDevValid() && m_cGrabber.isLive())
    {
        m_cGrabber.stopLive();
    }

    m_cGrabber.showDevicePage(this->m_hWnd);

    if(m_cGrabber.isDevValid())
    {
        m_cGrabber.startLive();
    }
}

The "Properties" button event handler shows the build-in dialog for device proiperties with a call to Grabber::showVCDPropertyPage():

void CSaveRestorePropertiesDlg::OnBnClickedProperties()
{
    if( m_cGrabber.isDevValid())
    {
        m_cGrabber.showVCDPropertyPage(this->m_hWnd);
    }
}

The method Grabber::saveDeviceStateToFile() saves the current settings and properties of a video capture deivce to an XML file:

void CSaveRestorePropertiesDlg::OnBnClickedSave()
{
    if( m_cGrabber.isDevValid())
    {
        m_cGrabber.saveDeviceStateToFile("device.xml");
    }
}

The method Grabber::loadDeviceStateFromFile restores a previously saved video capture device and its properties from an XML file. As for the device selection dialog, it is necessary to stop a probably running live video before a new video capture device can be opened. If a valid video capture device was loaded, the image data stream will be started using Grabber.startLive():

void CSaveRestorePropertiesDlg::OnBnClickedRestore()
{
    if(m_cGrabber.isDevValid() && m_cGrabber.isLive())
    {
        m_cGrabber.stopLive();
    }

    if( m_cGrabber.loadDeviceStateFromFile( "device.xml"))
    {
        if( m_cGrabber.isDevValid())
            m_cGrabber.startLive();
    }
}

Related Source Code Samples

Disclaimer
The source code that appears in the IC Imaging Control Source Code Library is indented for educational purposes only. The Imaging Source Europe GmbH, the manufacturer of IC Imaging Control, does not assume any kind of warranty expressed or implied, resulting from the use of the content of this page.

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, LiveDocx, phpLiveDocx and Forums.