1
// Header for standard system include files.
3
// Copyright (c) Microsoft. All rights reserved.
5
// The MIT License (MIT)
7
// Permission is hereby granted, free of charge, to any person obtaining a copy
8
// of this software and associated documentation files(the "Software"), to deal
9
// in the Software without restriction, including without limitation the rights
10
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
// copies of the Software, and to permit persons to whom the Software is
12
// furnished to do so, subject to the following conditions :
14
// The above copyright notice and this permission notice shall be included in
15
// all copies or substantial portions of the Software.
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
20
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
#include <collection.h>
30
#include <wrl\implements.h>
31
#include <wrl\wrappers\corewrappers.h>
32
#include <Roerrorapi.h>
43
#include <windows.media.h>
44
#include <windows.media.mediaproperties.h>
46
namespace AWM = ::ABI::Windows::Media;
47
namespace AWMMp = ::ABI::Windows::Media::MediaProperties;
48
namespace AWFC = ::ABI::Windows::Foundation::Collections;
49
namespace MW = ::Microsoft::WRL;
50
namespace MWD = ::Microsoft::WRL::Details;
51
namespace MWW = ::Microsoft::WRL::Wrappers;
52
namespace WMC = ::Windows::Media::Capture;
53
namespace WF = ::Windows::Foundation;
54
namespace WMMp = ::Windows::Media::MediaProperties;
55
namespace WSS = ::Windows::Storage::Streams;
57
// Exception-based error handling
58
#define CHK(statement) {HRESULT _hr = (statement); if (FAILED(_hr)) { throw ref new Platform::COMException(_hr); };}
59
#define CHKNULL(p) {if ((p) == nullptr) { throw ref new Platform::NullReferenceException(L#p); };}
61
// Exception-free error handling
62
#define CHK_RETURN(statement) {hr = (statement); if (FAILED(hr)) { return hr; };}
64
// Cast a C++/CX msartpointer to an ABI smartpointer
65
template<typename T, typename U>
66
MW::ComPtr<T> As(U^ in)
69
CHK(reinterpret_cast<IInspectable*>(in)->QueryInterface(IID_PPV_ARGS(&out)));
73
// Cast an ABI smartpointer
74
template<typename T, typename U>
75
Microsoft::WRL::ComPtr<T> As(const Microsoft::WRL::ComPtr<U>& in)
77
Microsoft::WRL::ComPtr<T> out;
82
// Cast an ABI smartpointer
83
template<typename T, typename U>
84
Microsoft::WRL::ComPtr<T> As(U* in)
86
Microsoft::WRL::ComPtr<T> out;
87
CHK(in->QueryInterface(IID_PPV_ARGS(&out)));
91
// Get access to bytes in IBuffer
92
inline unsigned char* GetData(_In_ WSS::IBuffer^ buffer)
94
unsigned char* bytes = nullptr;
95
CHK(As<WSS::IBufferByteAccess>(buffer)->Buffer(&bytes));
99
// Class to start and shutdown Media Foundation
104
: _bInitialized(false)
106
CHK(MFStartup(MF_VERSION));
121
// Class to track error origin
123
HRESULT OriginateError(__in HRESULT hr, __in wchar_t const (&str)[N])
127
::RoOriginateErrorW(hr, N - 1, str);
132
// Class to track error origin
133
inline HRESULT OriginateError(__in HRESULT hr)
137
::RoOriginateErrorW(hr, 0, nullptr);
142
// Converts exceptions into HRESULTs
143
template <typename Lambda>
144
HRESULT ExceptionBoundary(Lambda&& lambda)
151
catch (Platform::Exception^ e)
155
catch (const std::bad_alloc&)
157
return E_OUTOFMEMORY;
159
catch (const std::exception&)
165
// Wraps an IMFSample in a C++/CX class to be able to define a callback delegate
166
ref class MediaSample sealed
169
MW::ComPtr<IMFSample> Sample;
172
delegate void MediaSampleHandler(MediaSample^ sample);
b'\\ No newline at end of file'