Skip to content

Commit

Permalink
Display an error message if the video renderer fails to initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Sep 12, 2016
1 parent f9dbf66 commit 7747772
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
13 changes: 8 additions & 5 deletions main.cpp
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion moonlight.hpp
Expand Up @@ -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);
Expand Down
21 changes: 16 additions & 5 deletions viddec.cpp
Expand Up @@ -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[] = {
Expand All @@ -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,
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 7747772

Please sign in to comment.