Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver: Stop encoder when stream stops #1456

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion alvr/server/cpp/alvr_server/OvrHMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ OvrHmd::~OvrHmd() {

if (m_encoder) {
Debug("OvrHmd::~OvrHmd(): Stopping encoder...\n");
m_encoder->Stop();
m_encoder.reset();
}

Expand Down Expand Up @@ -382,6 +381,15 @@ void OvrHmd::StartStreaming() {

void OvrHmd::StopStreaming() {
vr::VRDriverInput()->UpdateBooleanComponent(m_proximity, false, 0.0);
#ifdef _WIN32
if (m_directModeComponent) {
m_directModeComponent->ResetEncoder();
}
#endif
if (m_encoder) {
m_encoder.reset();
}
m_streamComponentsInitialized = false;
}

void OvrHmd::SetViewsConfig(FfiViewsConfig config) {
Expand Down
11 changes: 5 additions & 6 deletions alvr/server/cpp/platform/win32/CEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

CEncoder::~CEncoder()
{
Stop();
if (m_videoEncoder)
{
m_videoEncoder->Shutdown();
Expand All @@ -31,7 +32,7 @@
if (Settings::Instance().m_force_sw_encoding) {
try {
Debug("Try to use VideoEncoderSW.\n");
m_videoEncoder = std::make_shared<VideoEncoderSW>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder = std::make_unique<VideoEncoderSW>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder->Initialize();
return;
}
Expand All @@ -43,7 +44,7 @@

try {
Debug("Try to use VideoEncoderVCE.\n");
m_videoEncoder = std::make_shared<VideoEncoderVCE>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder = std::make_unique<VideoEncoderVCE>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder->Initialize();
return;
}
Expand All @@ -52,7 +53,7 @@
}
try {
Debug("Try to use VideoEncoderNVENC.\n");
m_videoEncoder = std::make_shared<VideoEncoderNVENC>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder = std::make_unique<VideoEncoderNVENC>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder->Initialize();
return;
}
Expand All @@ -62,7 +63,7 @@
#ifdef ALVR_GPL
try {
Debug("Try to use VideoEncoderSW.\n");
m_videoEncoder = std::make_shared<VideoEncoderSW>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder = std::make_unique<VideoEncoderSW>(d3dRender, encoderWidth, encoderHeight);
m_videoEncoder->Initialize();
return;
}
Expand All @@ -80,8 +81,6 @@
{
m_presentationTime = presentationTime;
m_targetTimestampNs = targetTimestampNs;
m_FrameRender->Startup();

m_FrameRender->RenderFrame(pTexture, bounds, layerCount, recentering, message, debugText);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/win32/CEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

private:
CThreadEvent m_newFrameReady, m_encodeFinished;
std::shared_ptr<VideoEncoder> m_videoEncoder;
std::unique_ptr<VideoEncoder> m_videoEncoder;
bool m_bExiting;
uint64_t m_presentationTime;
uint64_t m_targetTimestampNs;
Expand Down
4 changes: 4 additions & 0 deletions alvr/server/cpp/platform/win32/OvrDirectModeComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ void OvrDirectModeComponent::SetEncoder(std::shared_ptr<CEncoder> pEncoder) {
m_pEncoder = pEncoder;
}

void OvrDirectModeComponent::ResetEncoder() {
m_pEncoder.reset();
}

/** Specific to Oculus compositor support, textures supplied must be created using this method. */
void OvrDirectModeComponent::CreateSwapTextureSet(uint32_t unPid, const SwapTextureSetDesc_t *pSwapTextureSetDesc, SwapTextureSet_t *pOutSwapTextureSet)
{
Expand Down
1 change: 1 addition & 0 deletions alvr/server/cpp/platform/win32/OvrDirectModeComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OvrDirectModeComponent : public vr::IVRDriverDirectModeComponent
OvrDirectModeComponent(std::shared_ptr<CD3DRender> pD3DRender, std::shared_ptr<PoseHistory> poseHistory);

void SetEncoder(std::shared_ptr<CEncoder> pEncoder);
void ResetEncoder();

/** Specific to Oculus compositor support, textures supplied must be created using this method. */
virtual void CreateSwapTextureSet( uint32_t unPid, const SwapTextureSetDesc_t *pSwapTextureSetDesc, SwapTextureSet_t *pOutSwapTextureSet );
Expand Down
9 changes: 2 additions & 7 deletions alvr/server/cpp/platform/win32/VideoEncoderVCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ AMFPipe::AMFPipe(amf::AMFComponentPtr src, AMFDataReceiver receiver)
, m_receiver(receiver)
{}

AMFPipe::~AMFPipe()
{
Debug("AMFPipe::~AMFPipe() m_amfComponentSrc->Drain\n");
m_amfComponentSrc->Drain();
}
AMFPipe::~AMFPipe() {}

void AMFPipe::doPassthrough(bool hasQueryTimeout, uint32_t timerResolution)
{
Expand Down Expand Up @@ -366,8 +362,7 @@ void VideoEncoderVCE::Shutdown()
delete m_pipeline;

for (auto &component : m_amfComponents) {
component->Release();
delete component;
component->Terminate();
}

m_amfContext->Terminate();
Expand Down