From 12e34a9f4e7b8211dc4e9cabb061c370dd2bb7f4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 10 Jul 2016 22:23:01 -0700 Subject: [PATCH] Add the code back to request an IDR frame when switching back to Moonlight --- input.cpp | 5 +++++ moonlight.hpp | 3 +++ viddec.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/input.cpp b/input.cpp index 8d72455..2fc0b91 100644 --- a/input.cpp +++ b/input.cpp @@ -23,6 +23,11 @@ static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) { void MoonlightInstance::DidLockMouse(int32_t result) { m_MouseLocked = (result == PP_OK); + if (m_MouseLocked) { + // Request an IDR frame to dump the frame queue that may have + // built up from the GL pipeline being stalled. + g_Instance->m_RequestIdrFrame = true; + } } void MoonlightInstance::MouseLockLost() { diff --git a/moonlight.hpp b/moonlight.hpp index 1810764..fd55ada 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -53,6 +53,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { pp::MouseLock(this), m_HasNextPicture(false), m_IsPainting(false), + m_RequestIdrFrame(false), m_OpusDecoder(NULL), m_CallbackFactory(this), m_MouseLocked(false), @@ -122,6 +123,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { void PictureReady(int32_t result, PP_VideoPicture picture); void PaintPicture(void); void InitializeRenderingSurface(int width, int height); + void DidChangeFocus(bool got_focus); static void VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags); static void VidDecCleanup(void); @@ -159,6 +161,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { bool m_HasNextPicture; PP_VideoPicture m_CurrentPicture; bool m_IsPainting; + bool m_RequestIdrFrame; OpusMSDecoder* m_OpusDecoder; pp::Audio m_AudioPlayer; diff --git a/viddec.cpp b/viddec.cpp index 033fa4c..adebfb4 100644 --- a/viddec.cpp +++ b/viddec.cpp @@ -62,6 +62,14 @@ static const char k_FragmentShaderExternal[] = " gl_FragColor = texture2D(s_texture, v_texCoord); \n" "}"; +void MoonlightInstance::DidChangeFocus(bool got_focus) { + // Request an IDR frame to dump the frame queue that may have + // built up from the GL pipeline being stalled. + if (got_focus) { + g_Instance->m_RequestIdrFrame = true; + } +} + void MoonlightInstance::InitializeRenderingSurface(int width, int height) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { return; @@ -230,6 +238,12 @@ int MoonlightInstance::VidDecSubmitDecodeUnit(PDECODE_UNIT decodeUnit) { bool isSps = false; bool isPps = false; bool isIframe = false; + + // Request an IDR frame if needed + if (g_Instance->m_RequestIdrFrame) { + g_Instance->m_RequestIdrFrame = false; + return DR_NEED_IDR; + } // Look at the NALU type if (decodeUnit->bufferList->length > 5) {