Image Capture using Media Foundation

I am writing a program which needs to get an image from a camera, then do some processing on the image and display it on screen. Since I'm developing this program for Windows 7 (64-bit), I decided to use the Media Foundation API, as opposed to DirectShow, to manage the video input device. I dug around on the MSDN website for a while, found some code which Microsoft told me should work pretty well. Problem is, it doesn't.

I'm willing to bet that this problem is caused by my inexperience with Media Foundation. I've just started working with it at the beginning of this week. I've dug around quite a bit on the MSDN website, and have at least a basic understanding of the Media Foundation classes, interfaces, and functions used in my program. I lack any sort of higher understanding of Media Foundation, however.

I've isolated the problem. After the call to MFEnumDeviceSources in the function CreateVideoCaptureDevice, the array which should refer to the list of connected input devices is empty. I'm really not sure why, as the computer I'm running this on, my laptop, has a webcam built in. The function CreateVideoCaptureDevice is reproduced below, and the full source file is linked to at the bottom.

I'm not sure if this is relevant, but CreateVideoCaptureDevice is the first MediaFoundation-related function I call in my program.

Does anyone know why the list of media devices is empty, or simply how I can make that list not empty?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
HRESULT CreateVideoCaptureDevice( IMFMediaSource **ppSource )
{
	// clear the pointer to whatever device we were dealing with before
    *ppSource = NULL;
	// the number of devices we can deal with
    UINT32 count = 0;
	// The attributes of the device we're dealing with
    IMFAttributes *pConfig = NULL;
	// An array of devices we can deal with
    IMFActivate **ppDevices = NULL;
    // Create an attribute store to hold the search criteria.
    HRESULT hr = MFCreateAttributes( &pConfig, 1 );
    // Request video capture devices.
    if( SUCCEEDED(hr) )
    {
		*debug<<"Created Media Foundation attributes\n";
        hr = pConfig->SetGUID(
            MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, 
            MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
            );
    }
    // Enumerate the devices,
    if( SUCCEEDED(hr) ) 
	{
		*debug<<"GUID of the config attributes was successfully set\n";
        hr = MFEnumDeviceSources( pConfig, &ppDevices, &count );
	}
    // Create a media source for the first device in the list.
    if( SUCCEEDED(hr) )
	{
		*debug<<"Device sources were successfully enumerated\n";
        if( count > 0 )
			// Activate the first device we found
            hr = ppDevices[0]->ActivateObject( IID_PPV_ARGS(ppSource) );
        else
            hr = MF_E_NOT_FOUND;
	}
	// free up unneeded memory
    for( DWORD i = 0; i < count; i++ )
        ppDevices[i]->Release();
    CoTaskMemFree( ppDevices );
    return hr;
}


Full source files: http://sdrv.ms/10gDnWM
bump
I am new to the Direct Show & Media Foundation. What are the best resources (books & links ) that would help me to understand and write a sample camera app.
Topic archived. No new replies allowed.