-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebcamAccess.h
49 lines (40 loc) · 1.1 KB
/
WebcamAccess.h
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
44
45
46
47
48
#pragma once
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <mferror.h>
#include "ColorConverter.h"
template <class T> void SafeRelease(T **ppT)
{
if(*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
struct ChooseDeviceParam
{
IMFActivate **ppDevices; // Array of IMFActivate pointers.
UINT32 count; // Number of elements in the array.
UINT32 selection; // Selected device, by array index.
};
class CWebcamAccess
{
public:
CWebcamAccess();
~CWebcamAccess();
HRESULT Initialize();
bool SetDeviceIndex(unsigned int index);
HRESULT PrepareDevice();
void GetImageSizes(unsigned int &width, unsigned int&height);
HRESULT GetImageData(BYTE *buffer, LONG stride);
protected:
ChooseDeviceParam m_cam_devices;
IMFSourceReader *m_pReader;
CColorConverter m_color_converter;
bool m_ready;
void ShowErrorMessage(PCWSTR format, HRESULT hrErr);
HRESULT BuildListOfDevices();
void CloseDevice();
HRESULT TryMediaType(IMFMediaType *pType);
};