From 46df94ee2cf818e2d980f1dc263bd62ff730d559 Mon Sep 17 00:00:00 2001 From: polygraphene Date: Sat, 29 Sep 2018 02:44:09 +0900 Subject: [PATCH] Try to use both VideoEncoder to determine what API is available. --- ALVR-common/exception.h | 9 ++++++++- alvr_server/alvr_server.cpp | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ALVR-common/exception.h b/ALVR-common/exception.h index 2e91258a..0174caec 100644 --- a/ALVR-common/exception.h +++ b/ALVR-common/exception.h @@ -7,12 +7,19 @@ class Exception : public std::exception { Exception(std::wstring what) : m_what(what) { } + Exception() { + } virtual const wchar_t *what() { return m_what.c_str(); } + + Exception& operator=(const Exception &src) { + m_what = src.m_what; + return *this; + } private: - const std::wstring m_what; + std::wstring m_what; }; Exception FormatExceptionV(const wchar_t *format, va_list args); diff --git a/alvr_server/alvr_server.cpp b/alvr_server/alvr_server.cpp index 0abe40d3..bb00bf6c 100644 --- a/alvr_server/alvr_server.cpp +++ b/alvr_server/alvr_server.cpp @@ -51,13 +51,10 @@ namespace class CEncoder : public CThread { public: - CEncoder(std::shared_ptr d3dRender, std::shared_ptr listener) + CEncoder() : m_bExiting( false ) , m_frameIndex(0) , m_frameIndex2(0) - , m_FrameRender(std::make_shared(d3dRender)) - , m_videoEncoder(std::make_shared(d3dRender, listener - , Settings::Instance().m_renderWidth, Settings::Instance().m_renderHeight)) { m_encodeFinished.Set(); } @@ -71,8 +68,32 @@ namespace } } - void Initialize() { - m_videoEncoder->Initialize(); + void Initialize(std::shared_ptr d3dRender, std::shared_ptr listener) { + m_FrameRender = std::make_shared(d3dRender); + + Exception vceException; + Exception nvencException; + try { + Log(L"Try to use VideoEncoderVCE."); + m_videoEncoder = std::make_shared(d3dRender, listener + , Settings::Instance().m_renderWidth, Settings::Instance().m_renderHeight); + m_videoEncoder->Initialize(); + return; + } + catch (Exception e) { + vceException = e; + } + try { + Log(L"Try to use VideoEncoderNVENC."); + m_videoEncoder = std::make_shared(d3dRender, listener + , ShouldUseNV12Texture()); + m_videoEncoder->Initialize(); + return; + } + catch (Exception e) { + nvencException = e; + } + throw MakeException(L"All VideoEncoder are not available. VCE: %s, NVENC: %s", vceException.what(), nvencException.what()); } bool CopyToStaging( ID3D11Texture2D *pTexture[][2], vr::VRTextureBounds_t bounds[][2], int layerCount, bool recentering @@ -823,9 +844,9 @@ class CRemoteHmd : public vr::ITrackedDeviceServerDriver Log(L"OSVer: %s", GetWindowsOSVersion().c_str()); // Spin up a separate thread to handle the overlapped encoding/transmit step. - m_encoder = std::make_shared(m_D3DRender, m_Listener); + m_encoder = std::make_shared(); try { - m_encoder->Initialize(); + m_encoder->Initialize(m_D3DRender, m_Listener); } catch (Exception e) { FatalLog(L"Failed to initialize CEncoder. %s", e.what());