From 77477722d31bcabf70e2ccf27a1b077129153f5d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 11 Sep 2016 23:50:02 -0700 Subject: [PATCH] Display an error message if the video renderer fails to initialize --- main.cpp | 13 ++++++++----- moonlight.hpp | 2 +- viddec.cpp | 21 ++++++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 7c5d85b..95421f1 100644 --- a/main.cpp +++ b/main.cpp @@ -217,15 +217,18 @@ void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args) hexStringToBytes(rikey.c_str(), m_StreamConfig.remoteInputAesKey); int rikeyiv = htonl(stoi(rikeyid)); memcpy(m_StreamConfig.remoteInputAesIv, &rikeyiv, sizeof(rikeyiv)); - - // Initialize the rendering surface before starting the connection - InitializeRenderingSurface(m_StreamConfig.width, m_StreamConfig.height); // Store the host from the start message m_Host = host; - // Start the worker thread to establish the connection - pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this); + // Initialize the rendering surface before starting the connection + if (InitializeRenderingSurface(m_StreamConfig.width, m_StreamConfig.height)) { + // Start the worker thread to establish the connection + pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this); + } else { + // Failed to initialize renderer + OnConnectionStopped(0); + } pp::VarDictionary ret; ret.Set("callbackId", pp::Var(callbackId)); diff --git a/moonlight.hpp b/moonlight.hpp index fd55ada..49c3d0a 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -122,7 +122,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { void DispatchGetPicture(uint32_t unused); void PictureReady(int32_t result, PP_VideoPicture picture); void PaintPicture(void); - void InitializeRenderingSurface(int width, int height); + bool 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); diff --git a/viddec.cpp b/viddec.cpp index adebfb4..ecab06b 100644 --- a/viddec.cpp +++ b/viddec.cpp @@ -70,9 +70,9 @@ void MoonlightInstance::DidChangeFocus(bool got_focus) { } } -void MoonlightInstance::InitializeRenderingSurface(int width, int height) { +bool MoonlightInstance::InitializeRenderingSurface(int width, int height) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) { - return; + return false; } int32_t contextAttributes[] = { @@ -89,6 +89,10 @@ void MoonlightInstance::InitializeRenderingSurface(int width, int height) { PP_GRAPHICS3DATTRIB_NONE }; g_Instance->m_Graphics3D = pp::Graphics3D(this, contextAttributes); + if (g_Instance->m_Graphics3D.is_null()) { + ClDisplayMessage("Unable to create OpenGL context"); + return false; + } int32_t swapBehaviorAttribute[] = { PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, PP_GRAPHICS3DATTRIB_BUFFER_DESTROYED, @@ -97,10 +101,10 @@ void MoonlightInstance::InitializeRenderingSurface(int width, int height) { g_Instance->m_Graphics3D.SetAttribs(swapBehaviorAttribute); if (!BindGraphics(m_Graphics3D)) { - fprintf(stderr, "Unable to bind 3d context!\n"); + ClDisplayMessage("Unable to bind OpenGL context"); m_Graphics3D = pp::Graphics3D(); glSetCurrentContextPPAPI(0); - return; + return false; } glSetCurrentContextPPAPI(m_Graphics3D.pp_resource()); @@ -130,6 +134,7 @@ void MoonlightInstance::InitializeRenderingSurface(int width, int height) { assertNoGLError(); g_Instance->m_Graphics3D.SwapBuffers(pp::BlockUntilComplete()); + return true; } void MoonlightInstance::VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) { @@ -167,7 +172,13 @@ void MoonlightInstance::VidDecSetup(int videoFormat, int width, int height, int 0, pp::BlockUntilComplete()); - if (!(drFlags & DR_FLAG_FORCE_SW_DECODE)) { + if (err == PP_ERROR_NOTSUPPORTED) { + // No decoders available at all. We can't continue. + ClDisplayMessage("No hardware or software H.264 decoders available!"); + g_Instance->StopConnection(); + return; + } + else if (!(drFlags & DR_FLAG_FORCE_SW_DECODE)) { // Tell the user we had to fall back ClDisplayTransientMessage("Hardware decoding is unavailable. Falling back to CPU decoding"); }