Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Try to use both VideoEncoder to determine what API is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
polygraphene committed Sep 28, 2018
1 parent 645f7c3 commit 46df94e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion ALVR-common/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 29 additions & 8 deletions alvr_server/alvr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ namespace
class CEncoder : public CThread
{
public:
CEncoder(std::shared_ptr<CD3DRender> d3dRender, std::shared_ptr<Listener> listener)
CEncoder()
: m_bExiting( false )
, m_frameIndex(0)
, m_frameIndex2(0)
, m_FrameRender(std::make_shared<FrameRender>(d3dRender))
, m_videoEncoder(std::make_shared<VideoEncoderVCE>(d3dRender, listener
, Settings::Instance().m_renderWidth, Settings::Instance().m_renderHeight))
{
m_encodeFinished.Set();
}
Expand All @@ -71,8 +68,32 @@ namespace
}
}

void Initialize() {
m_videoEncoder->Initialize();
void Initialize(std::shared_ptr<CD3DRender> d3dRender, std::shared_ptr<Listener> listener) {
m_FrameRender = std::make_shared<FrameRender>(d3dRender);

Exception vceException;
Exception nvencException;
try {
Log(L"Try to use VideoEncoderVCE.");
m_videoEncoder = std::make_shared<VideoEncoderVCE>(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<VideoEncoderNVENC>(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
Expand Down Expand Up @@ -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<CEncoder>(m_D3DRender, m_Listener);
m_encoder = std::make_shared<CEncoder>();
try {
m_encoder->Initialize();
m_encoder->Initialize(m_D3DRender, m_Listener);
}
catch (Exception e) {
FatalLog(L"Failed to initialize CEncoder. %s", e.what());
Expand Down

0 comments on commit 46df94e

Please sign in to comment.