Implement fallback to software when hardware decoding is unavailable

This commit is contained in:
Cameron Gutman 2016-06-09 12:23:23 -05:00
parent f2d9bce746
commit 1f3f4bd0aa
5 changed files with 44 additions and 15 deletions

View File

@ -28,13 +28,13 @@ void MoonlightInstance::ClConnectionTerminated(long errorCode) {
g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode); g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode);
} }
void MoonlightInstance::ClDisplayMessage(char* message) { void MoonlightInstance::ClDisplayMessage(const char* message) {
pp::Var response(message); pp::Var response(std::string("DialogMsg: ") + std::string(message));
g_Instance->PostMessage(response); g_Instance->PostMessage(response);
} }
void MoonlightInstance::ClDisplayTransientMessage(char* message) { void MoonlightInstance::ClDisplayTransientMessage(const char* message) {
pp::Var response(message); pp::Var response(std::string("TransientMsg: ") + std::string(message));
g_Instance->PostMessage(response); g_Instance->PostMessage(response);
} }

@ -1 +1 @@
Subproject commit 69c8881187590bf131f18ee150cdce65f02bdd34 Subproject commit 86ade5204e7c8c8cc7be218940037b08bdde3b47

View File

@ -35,6 +35,9 @@
// which a profiling message is printed // which a profiling message is printed
#define PROFILING_MESSAGE_THRESHOLD 1 #define PROFILING_MESSAGE_THRESHOLD 1
#define DR_FLAG_FORCE_SW_DECODE 0x01
struct Shader { struct Shader {
Shader() : program(0), texcoord_scale_location(0) {} Shader() : program(0), texcoord_scale_location(0) {}
~Shader() {} ~Shader() {}
@ -108,8 +111,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
static void ClStageFailed(int stage, long errorCode); static void ClStageFailed(int stage, long errorCode);
static void ClConnectionStarted(void); static void ClConnectionStarted(void);
static void ClConnectionTerminated(long errorCode); static void ClConnectionTerminated(long errorCode);
static void ClDisplayMessage(char* message); static void ClDisplayMessage(const char* message);
static void ClDisplayTransientMessage(char* message); static void ClDisplayTransientMessage(const char* message);
static Shader CreateProgram(const char* vertexShader, const char* fragmentShader); static Shader CreateProgram(const char* vertexShader, const char* fragmentShader);
static void CreateShader(GLuint program, GLenum type, const char* source, int size); static void CreateShader(GLuint program, GLenum type, const char* source, int size);

View File

@ -30,6 +30,8 @@ function handleMessage(msg) {
$('#loadingSpinner').css('display', 'none'); $('#loadingSpinner').css('display', 'none');
} else if(msg.data.indexOf('ProgressMsg: ') === 0) { } else if(msg.data.indexOf('ProgressMsg: ') === 0) {
$('#loadingMessage').text(msg.data.replace('ProgressMsg: ', '')); $('#loadingMessage').text(msg.data.replace('ProgressMsg: ', ''));
} else if(msg.data.indexOf('TransientMsg: ') === 0) {
snackbarLog(msg.data.replace('TransientMsg: ', ''));
} }
} }
} }

View File

@ -133,11 +133,35 @@ void MoonlightInstance::VidDecSetup(int videoFormat, int width, int height, int
s_LastSpsLength = 0; s_LastSpsLength = 0;
s_LastPpsLength = 0; s_LastPpsLength = 0;
g_Instance->m_VideoDecoder->Initialize(g_Instance->m_Graphics3D, int32_t err;
if (!(drFlags & DR_FLAG_FORCE_SW_DECODE)) {
// Try to initialize hardware decoding only
err = g_Instance->m_VideoDecoder->Initialize(
g_Instance->m_Graphics3D,
PP_VIDEOPROFILE_H264HIGH, PP_VIDEOPROFILE_H264HIGH,
PP_HARDWAREACCELERATION_ONLY, PP_HARDWAREACCELERATION_ONLY,
0, 0,
pp::BlockUntilComplete()); pp::BlockUntilComplete());
}
else {
err = PP_ERROR_NOTSUPPORTED;
}
if (err == PP_ERROR_NOTSUPPORTED) {
// Fallback to software decoding
err = g_Instance->m_VideoDecoder->Initialize(
g_Instance->m_Graphics3D,
PP_VIDEOPROFILE_H264HIGH,
PP_HARDWAREACCELERATION_NONE,
0,
pp::BlockUntilComplete());
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");
}
}
pp::Module::Get()->core()->CallOnMainThread(0, pp::Module::Get()->core()->CallOnMainThread(0,
g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::DispatchGetPicture)); g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::DispatchGetPicture));