Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Capturing Video from Web-camera on Windows 7 and 8 by using Media Foundation

, 10 Apr 2013
Simple lib for capturing video from web-camera by using Media Foundation
SimpleCapture-exe.zip
Release
msvcp110.dll
msvcr110.dll
SimpleCapture.exe
SimpleCaptureVS2012.zip
SimpleCapture
Backup
SimpleCapture.aps
SimpleCapture.v11.suo
SimpleCapture.vcxproj.filters
SimpleCapture.vcxproj.user
TestResults
videoInput.lib
TestVideoInputVS2012x86-noexe.zip
TestVideoInput
Debug
TestVideoInput.ilk
ipch
testvideoinput-d1a6bc1c
testvideoinput-2a8f7f73.ipch
TestVideoInput.v11.suo
TestVideoInput
include
opencv
opencv2
calib3d
contrib
core
features2d
flann
gpu
device
detail
highgui
imgproc
legacy
ml
nonfree
objdetect
ocl
photo
stitching
detail
superres
ts
video
videostab
lib
opencv_core248d.lib
opencv_highgui248d.lib
TestVideoInput.vcxproj.filters
videoInput
videoInput.vcxproj.filters
videoInput.vcxproj.user
TestVideoInputVS2012x86.zip
opencv_core248d.dll
opencv_highgui248d.dll
TestVideoInput.exe
TestVideoInput.ilk
TestVideoInput.pdb
testvideoinput-2a8f7f73.ipch
TestResults
TestVideoInput.v11.suo
opencv_core248d.lib
opencv_highgui248d.lib
TestVideoInput.vcxproj.filters
videoInput.vcxproj.filters
videoInput.vcxproj.user
videoinput-staticlib-vs2012x86-noexe.zip
videoInput.lib
videoInput-staticlib-VS2012x86.zip
videoInput.lib
videoInputVS2012.zip
videoInput
videoInput.vcxproj.filters
videoInput.vcxproj.user
//////////////////////////////////////////////////////////////////////////
//
// preview.h : Preview helper class.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////

#pragma once

struct ChooseDeviceParam
{
    IMFActivate **ppDevices;
    UINT32      count;
    UINT32      selection;
	UINT32		selectedtype;
	UINT32		selectedtypecount;
};

class CPreview : public IMFPMediaPlayerCallback
{
public:
    static HRESULT CreateInstance(
        HWND hVideo,
        CPreview **ppPlayer
    );

    // IUnknown methods
    STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

    void STDMETHODCALLTYPE OnMediaPlayerEvent(MFP_EVENT_HEADER * pEventHeader);

    HRESULT       SetDevice(ChooseDeviceParam pParam);
    HRESULT       CloseDevice();
    HRESULT       UpdateVideo();
    HRESULT       CheckDeviceLost(DEV_BROADCAST_HDR *pHdr, BOOL *pbDeviceLost);
    BOOL          HasVideo() const { return m_bHasVideo; }

protected:

    // Constructor is private. Use static CreateInstance method to instantiate.
    CPreview(HWND hVideo);

    // Destructor is private. Caller should call Release.
    virtual ~CPreview();

    // Event handlers
    void OnMediaItemCreated(MFP_MEDIAITEM_CREATED_EVENT *pEvent);
    void OnMediaItemSet(MFP_MEDIAITEM_SET_EVENT *pEvent);

protected:

    long                    m_nRefCount;        // Reference count.
    IMFPMediaPlayer         *m_pPlayer;
    IMFMediaSource          *m_pSource;
    HWND                    m_hwnd;
    BOOL                    m_bHasVideo;

    WCHAR                   *m_pwszSymbolicLink;
    UINT32                  m_cchSymbolicLink;

};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Evgeny Pereguda
Software Developer
Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 10 Apr 2013
Article Copyright 2013 by Evgeny Pereguda
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid