ARX
1.2.0
The next-generation open source augmented reality toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
Source
ARX
ARVideo
WindowsMediaCapture
CaptureFrameGrabber
MFIncludes.h
Go to the documentation of this file.
1
//
2
// MFIncludes.h
3
// Header for standard system include files.
4
//
5
6
#pragma once
7
8
#include <collection.h>
9
#include <ppltasks.h>
10
11
#include <wrl\implements.h>
12
#include <wrl\wrappers\corewrappers.h>
13
#include <Roerrorapi.h>
14
15
#include <queue>
16
#include <sstream>
17
18
#include <robuffer.h>
19
20
#include <mfapi.h>
21
#include <mfidl.h>
22
#include <Mferror.h>
23
24
#include <windows.media.h>
25
#include <windows.media.mediaproperties.h>
26
27
namespace
AWM = ::ABI::Windows::Media;
28
namespace
AWMMp = ::ABI::Windows::Media::MediaProperties;
29
namespace
AWFC = ::ABI::Windows::Foundation::Collections;
30
namespace
MW = ::Microsoft::WRL;
31
namespace
MWD = ::Microsoft::WRL::Details;
32
namespace
MWW = ::Microsoft::WRL::Wrappers;
33
namespace
WMC = ::Windows::Media::Capture;
34
namespace
WF = ::Windows::Foundation;
35
namespace
WMMp = ::Windows::Media::MediaProperties;
36
namespace
WSS = ::Windows::Storage::Streams;
37
38
// Exception-based error handling
39
#define CHK(statement) {HRESULT _hr = (statement); if (FAILED(_hr)) { throw ref new Platform::COMException(_hr); };}
40
#define CHKNULL(p) {if ((p) == nullptr) { throw ref new Platform::NullReferenceException(L#p); };}
41
42
// Exception-free error handling
43
#define CHK_RETURN(statement) {hr = (statement); if (FAILED(hr)) { return hr; };}
44
45
// Cast a C++/CX msartpointer to an ABI smartpointer
46
template
<
typename
T,
typename
U>
47
MW::ComPtr<T>
As
(U^ in)
48
{
49
MW::ComPtr<T> out;
50
CHK
(
reinterpret_cast<
IInspectable*
>
(in)->QueryInterface(IID_PPV_ARGS(&out)));
51
return
out;
52
}
53
54
// Cast an ABI smartpointer
55
template
<
typename
T,
typename
U>
56
Microsoft::WRL::ComPtr<T>
As
(
const
Microsoft::WRL::ComPtr<U>& in)
57
{
58
Microsoft::WRL::ComPtr<T> out;
59
CHK
(in.As(&out));
60
return
out;
61
}
62
63
// Cast an ABI smartpointer
64
template
<
typename
T,
typename
U>
65
Microsoft::WRL::ComPtr<T>
As
(U* in)
66
{
67
Microsoft::WRL::ComPtr<T> out;
68
CHK
(in->QueryInterface(IID_PPV_ARGS(&out)));
69
return
out;
70
}
71
72
// Get access to bytes in IBuffer
73
inline
unsigned
char
*
GetData
(_In_ WSS::IBuffer^ buffer)
74
{
75
unsigned
char
* bytes =
nullptr
;
76
CHK
(
As<WSS::IBufferByteAccess>
(buffer)->Buffer(&bytes));
77
return
bytes;
78
}
79
80
// Class to start and shutdown Media Foundation
81
class
AutoMF
82
{
83
public
:
84
AutoMF
()
85
: _bInitialized(false)
86
{
87
CHK
(MFStartup(MF_VERSION));
88
}
89
90
~AutoMF
()
91
{
92
if
(_bInitialized)
93
{
94
(void)MFShutdown();
95
}
96
}
97
98
private
:
99
bool
_bInitialized;
100
};
101
102
// Class to track error origin
103
template
<
size_t
N>
104
HRESULT
OriginateError
(__in HRESULT hr, __in
wchar_t
const
(&str)[N])
105
{
106
if
(FAILED(hr))
107
{
108
::RoOriginateErrorW(hr, N - 1, str);
109
}
110
return
hr;
111
}
112
113
// Class to track error origin
114
inline
HRESULT
OriginateError
(__in HRESULT hr)
115
{
116
if
(FAILED(hr))
117
{
118
::RoOriginateErrorW(hr, 0,
nullptr
);
119
}
120
return
hr;
121
}
122
123
// Converts exceptions into HRESULTs
124
template
<
typename
Lambda>
125
HRESULT
ExceptionBoundary
(Lambda&& lambda)
126
{
127
try
128
{
129
lambda();
130
return
S_OK;
131
}
132
catch
(Platform::Exception^ e)
133
{
134
return
e->HResult;
135
}
136
catch
(
const
std::bad_alloc&)
137
{
138
return
E_OUTOFMEMORY;
139
}
140
catch
(
const
std::exception&)
141
{
142
return
E_FAIL;
143
}
144
}
145
146
// Wraps an IMFSample in a C++/CX class to be able to define a callback delegate
147
148
namespace
Media
149
{
150
ref class
MediaSample
sealed
151
{
152
internal:
153
MW::ComPtr<IMFSample> Sample;
154
};
155
156
delegate
void
MediaSampleHandler
(MediaSample^ sample);
157
158
}
159
GetData
unsigned char * GetData(_In_ WSS::IBuffer^ buffer)
Definition
MFIncludes.h:73
OriginateError
HRESULT OriginateError(__in HRESULT hr, __in wchar_t const (&str)[N])
Definition
MFIncludes.h:104
ExceptionBoundary
HRESULT ExceptionBoundary(Lambda &&lambda)
Definition
MFIncludes.h:125
As
MW::ComPtr< T > As(U^ in)
Definition
MFIncludes.h:47
CHK
#define CHK(statement)
Definition
MFIncludes.h:39
AutoMF::AutoMF
AutoMF()
Definition
MFIncludes.h:84
AutoMF::~AutoMF
~AutoMF()
Definition
MFIncludes.h:90
Media
Definition
CaptureFrameGrabber.h:15
Media::MediaSampleHandler
delegate void MediaSampleHandler(MediaSample^ sample)
Generated on
for ARX by
1.18.0