2023-03-25 08:37:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
# include <stdio.h>
|
2023-03-25 08:37:51 +08:00
|
|
|
# include <Unknwn.h>
|
|
|
|
# include <wrl/client.h>
|
2023-04-02 01:51:36 +08:00
|
|
|
# include <exception>
|
2023-04-07 23:57:13 +08:00
|
|
|
# include <string_view>
|
2023-03-25 08:37:51 +08:00
|
|
|
|
|
|
|
namespace MFUtils
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename _Ty>
|
|
|
|
using TComPtr = Microsoft::WRL::ComPtr<_Ty>;
|
|
|
|
|
|
|
|
template <typename _Ty>
|
|
|
|
inline TComPtr<_Ty> MakeComPtr()
|
|
|
|
{
|
|
|
|
TComPtr<_Ty> obj;
|
|
|
|
_Ty** ppv = &obj;
|
|
|
|
*ppv = new _Ty();
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Ty, typename... _Types>
|
|
|
|
inline TComPtr<_Ty> MakeComPtr(_Types&&... args)
|
|
|
|
{
|
|
|
|
TComPtr<_Ty> obj;
|
|
|
|
_Ty** ppv = &obj;
|
|
|
|
*ppv = new _Ty(std::forward<_Types>(args)...);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename _Ty>
|
|
|
|
inline TComPtr<_Ty> ReferencedPtrToComPtr(_Ty* ptr)
|
|
|
|
{
|
|
|
|
TComPtr<_Ty> obj;
|
|
|
|
_Ty** ppv = &obj;
|
|
|
|
*ppv = ptr;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
template <typename T>
|
|
|
|
inline HRESULT CreateInstance(REFCLSID clsid, Microsoft::WRL::ComPtr<T>& ptr)
|
|
|
|
{
|
|
|
|
// ASSERT(!ptr);
|
|
|
|
return CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, __uuidof(T),
|
|
|
|
reinterpret_cast<void**>(ptr.GetAddressOf()));
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT InitializeMFOnce();
|
|
|
|
|
2023-04-07 23:57:13 +08:00
|
|
|
std::string_view GetVideoTypeName(const GUID& SubType);
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
} // namespace MFUtils
|
|
|
|
|
|
|
|
namespace DX
|
|
|
|
{
|
|
|
|
// Helper class for COM exceptions
|
|
|
|
class com_exception : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
com_exception(HRESULT hr) noexcept : result(hr) {}
|
|
|
|
|
|
|
|
const char* what() const override
|
|
|
|
{
|
|
|
|
static char s_str[64] = {};
|
|
|
|
sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast<unsigned int>(result));
|
|
|
|
return s_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
HRESULT result;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper utility converts D3D API failures into exceptions.
|
|
|
|
inline void ThrowIfFailed(HRESULT hr)
|
|
|
|
{
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
throw com_exception(hr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace DX
|
|
|
|
|
|
|
|
#endif
|