Skip to content

Commit

Permalink
Driver: Stop encoder when stream stops
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Feb 13, 2023
1 parent 9d669f3 commit c309125
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
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
3 changes: 1 addition & 2 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 Down Expand Up @@ -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
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

0 comments on commit c309125

Please sign in to comment.