Display an error message if the video renderer fails to initialize

This commit is contained in:
Cameron Gutman 2016-09-11 23:50:02 -07:00
parent f9dbf66dc2
commit 77477722d3
3 changed files with 25 additions and 11 deletions

View File

@ -218,14 +218,17 @@ void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args)
int rikeyiv = htonl(stoi(rikeyid)); int rikeyiv = htonl(stoi(rikeyid));
memcpy(m_StreamConfig.remoteInputAesIv, &rikeyiv, sizeof(rikeyiv)); 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 // Store the host from the start message
m_Host = host; m_Host = host;
// Start the worker thread to establish the connection // Initialize the rendering surface before starting the connection
pthread_create(&m_ConnectionThread, NULL, MoonlightInstance::ConnectionThreadFunc, this); 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; pp::VarDictionary ret;
ret.Set("callbackId", pp::Var(callbackId)); ret.Set("callbackId", pp::Var(callbackId));

View File

@ -122,7 +122,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
void DispatchGetPicture(uint32_t unused); void DispatchGetPicture(uint32_t unused);
void PictureReady(int32_t result, PP_VideoPicture picture); void PictureReady(int32_t result, PP_VideoPicture picture);
void PaintPicture(void); void PaintPicture(void);
void InitializeRenderingSurface(int width, int height); bool InitializeRenderingSurface(int width, int height);
void DidChangeFocus(bool got_focus); void DidChangeFocus(bool got_focus);
static void VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags); static void VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags);

View File

@ -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())) { if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) {
return; return false;
} }
int32_t contextAttributes[] = { int32_t contextAttributes[] = {
@ -89,6 +89,10 @@ void MoonlightInstance::InitializeRenderingSurface(int width, int height) {
PP_GRAPHICS3DATTRIB_NONE PP_GRAPHICS3DATTRIB_NONE
}; };
g_Instance->m_Graphics3D = pp::Graphics3D(this, contextAttributes); 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[] = { int32_t swapBehaviorAttribute[] = {
PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR, PP_GRAPHICS3DATTRIB_BUFFER_DESTROYED, 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); g_Instance->m_Graphics3D.SetAttribs(swapBehaviorAttribute);
if (!BindGraphics(m_Graphics3D)) { if (!BindGraphics(m_Graphics3D)) {
fprintf(stderr, "Unable to bind 3d context!\n"); ClDisplayMessage("Unable to bind OpenGL context");
m_Graphics3D = pp::Graphics3D(); m_Graphics3D = pp::Graphics3D();
glSetCurrentContextPPAPI(0); glSetCurrentContextPPAPI(0);
return; return false;
} }
glSetCurrentContextPPAPI(m_Graphics3D.pp_resource()); glSetCurrentContextPPAPI(m_Graphics3D.pp_resource());
@ -130,6 +134,7 @@ void MoonlightInstance::InitializeRenderingSurface(int width, int height) {
assertNoGLError(); assertNoGLError();
g_Instance->m_Graphics3D.SwapBuffers(pp::BlockUntilComplete()); g_Instance->m_Graphics3D.SwapBuffers(pp::BlockUntilComplete());
return true;
} }
void MoonlightInstance::VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags) { 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, 0,
pp::BlockUntilComplete()); 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 // Tell the user we had to fall back
ClDisplayTransientMessage("Hardware decoding is unavailable. Falling back to CPU decoding"); ClDisplayTransientMessage("Hardware decoding is unavailable. Falling back to CPU decoding");
} }