From b465034d6db052c6215f7db47439bc743958d45f Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Fri, 6 May 2016 11:11:46 -0400 Subject: [PATCH 01/10] changed default window size to include everything we need. This closes #55 --- static/js/background.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static/js/background.js b/static/js/background.js index 6ffa8b6..09e81e7 100644 --- a/static/js/background.js +++ b/static/js/background.js @@ -2,5 +2,8 @@ chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('index.html', { state: "normal", + bounds: { + width: 770, height: 440 + } }); }); \ No newline at end of file From 4e7560295f3a65db5b667a661c13fd58f9d43b98 Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Fri, 6 May 2016 12:39:36 -0400 Subject: [PATCH 02/10] NaCl module doesn't display until we start an app - this closes #49 --- static/css/style.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index 1602183..4e56cbd 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -71,8 +71,8 @@ main { } #listener { overflow: hidden; - margin-top: 20px; - border: 1px solid; + margin-top: 0px; + height: 0px; } .fullscreen { height: 100vh !important; From ea80c6e3efa90eccd73e5a7b6dbd5a681829a528 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 May 2016 13:18:42 -0400 Subject: [PATCH 03/10] Don't request filtering on input events. It needlessly increases CPU usage. --- main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index de1e3df..9e9e567 100644 --- a/main.cpp +++ b/main.cpp @@ -38,8 +38,7 @@ void MoonlightInstance::OnConnectionStarted(uint32_t unused) { PostMessage(response); // Start receiving input events - RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); - RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); + RequestInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD | PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); } void MoonlightInstance::OnConnectionStopped(uint32_t error) { From 97052591ba0f0e8fa208809d4013271c7d64ed0c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 May 2016 13:22:50 -0400 Subject: [PATCH 04/10] Modifiers are passed with every input event so we don't need to track them ourselves --- input.cpp | 63 ++++++++++++++++----------------------------------- moonlight.hpp | 3 --- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/input.cpp b/input.cpp index 747338d..8d72455 100644 --- a/input.cpp +++ b/input.cpp @@ -8,10 +8,6 @@ #define KEY_PREFIX 0x80 -#define KEY_CODE_ALT 18 -#define KEY_CODE_CTRL 17 -#define KEY_CODE_SHIFT 16 - static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) { switch (ppButton) { case PP_INPUTEVENT_MOUSEBUTTON_LEFT: @@ -31,38 +27,23 @@ void MoonlightInstance::DidLockMouse(int32_t result) { void MoonlightInstance::MouseLockLost() { m_MouseLocked = false; - m_KeyModifiers = 0; } -void MoonlightInstance::UpdateModifiers(PP_InputEvent_Type eventType, short keyCode) { - switch (keyCode) { - case KEY_CODE_ALT: - if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) { - m_KeyModifiers |= MODIFIER_ALT; - } - else { - m_KeyModifiers &= ~MODIFIER_ALT; - } - break; - - case KEY_CODE_CTRL: - if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) { - m_KeyModifiers |= MODIFIER_CTRL; - } - else { - m_KeyModifiers &= ~MODIFIER_CTRL; - } - break; - - case KEY_CODE_SHIFT: - if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) { - m_KeyModifiers |= MODIFIER_SHIFT; - } - else { - m_KeyModifiers &= ~MODIFIER_SHIFT; - } - break; +static char GetModifierFlags(const pp::InputEvent& event) { + uint32_t modifiers = event.GetModifiers(); + char flags = 0; + + if (modifiers & PP_INPUTEVENT_MODIFIER_SHIFTKEY) { + flags |= MODIFIER_SHIFT; } + if (modifiers & PP_INPUTEVENT_MODIFIER_CONTROLKEY) { + flags |= MODIFIER_CTRL; + } + if (modifiers & PP_INPUTEVENT_MODIFIER_ALTKEY) { + flags |= MODIFIER_ALT; + } + + return flags; } bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { @@ -135,11 +116,9 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { } pp::KeyboardInputEvent keyboardEvent(event); + char modifiers = GetModifierFlags(event); - // Update modifier state before sending the key event - UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode()); - - if (m_KeyModifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) { + if (modifiers == (MODIFIER_ALT | MODIFIER_CTRL | MODIFIER_SHIFT)) { if (keyboardEvent.GetKeyCode() == 0x51) { // Q key // Terminate the connection StopConnection(); @@ -152,7 +131,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { } LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(), - KEY_ACTION_DOWN, m_KeyModifiers); + KEY_ACTION_DOWN, modifiers); return true; } @@ -162,19 +141,17 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { } pp::KeyboardInputEvent keyboardEvent(event); - - // Update modifier state before sending the key event - UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode()); + char modifiers = GetModifierFlags(event); // Check if all modifiers are up now - if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) { + if (m_WaitingForAllModifiersUp && modifiers == 0) { UnlockMouse(); m_MouseLocked = false; m_WaitingForAllModifiersUp = false; } LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(), - KEY_ACTION_UP, m_KeyModifiers); + KEY_ACTION_UP, modifiers); return true; } diff --git a/moonlight.hpp b/moonlight.hpp index 10273b4..0e69c8d 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -46,7 +46,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { m_OpusDecoder(NULL), m_CallbackFactory(this), m_MouseLocked(false), - m_KeyModifiers(0), m_WaitingForAllModifiersUp(false), m_AccumulatedTicks(0), openHttpThread(this) { @@ -74,7 +73,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { void HandleOpenURL(int32_t callbackId, pp::VarArray args); void PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args); - void UpdateModifiers(PP_InputEvent_Type eventType, short keyCode); bool HandleInputEvent(const pp::InputEvent& event); void PollGamepads(); @@ -150,7 +148,6 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { const PPB_Gamepad* m_GamepadApi; pp::CompletionCallbackFactory m_CallbackFactory; bool m_MouseLocked; - char m_KeyModifiers; bool m_WaitingForAllModifiersUp; float m_AccumulatedTicks; From 7030576f80e08fd8680d67b1108491afa37c415e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 May 2016 13:36:10 -0400 Subject: [PATCH 05/10] Make the default window size a little bigger --- static/js/background.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/js/background.js b/static/js/background.js index 09e81e7..02c2dd6 100644 --- a/static/js/background.js +++ b/static/js/background.js @@ -1,9 +1,8 @@ -// just start the app in fullscreen chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('index.html', { state: "normal", bounds: { - width: 770, height: 440 + width: 850, height: 500 } }); }); \ No newline at end of file From 474c0c05e1bb53d93f2bc39c27a4407ab7b61ec7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 May 2016 14:47:37 -0400 Subject: [PATCH 06/10] Update common-c to fix 4K streaming --- moonlight-common-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonlight-common-c b/moonlight-common-c index f69ab5d..7e5e2ce 160000 --- a/moonlight-common-c +++ b/moonlight-common-c @@ -1 +1 @@ -Subproject commit f69ab5dd5eb8ca79bb59bcb9e87587a819c9bd4d +Subproject commit 7e5e2cebe210b0bb04ea0e0bff18d06135ade420 From f0b860414785d223596debd4e77640e973179d88 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 May 2016 14:51:43 -0400 Subject: [PATCH 07/10] Only filter keyboard events to ensure Esc still works when mouse lock is disabled --- main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9e9e567..bb3934c 100644 --- a/main.cpp +++ b/main.cpp @@ -38,7 +38,12 @@ void MoonlightInstance::OnConnectionStarted(uint32_t unused) { PostMessage(response); // Start receiving input events - RequestInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD | PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); + RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); + + // Filtering is suboptimal but it ensures that we can pass keyboard events + // to the browser when mouse lock is disabled. This is neccessary for Esc + // to kick the app out of full-screen. + RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); } void MoonlightInstance::OnConnectionStopped(uint32_t error) { From fcc4edb556c3015b94858f7fbb8565c479b2da43 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 8 May 2016 11:48:18 -0400 Subject: [PATCH 08/10] Use larger video packets to offset the higher packet reception overhead of NaCl --- main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index bb3934c..94b3051 100644 --- a/main.cpp +++ b/main.cpp @@ -181,10 +181,15 @@ void MoonlightInstance::HandleStartStream(int32_t callbackId, pp::VarArray args) m_StreamConfig.height = stoi(height); m_StreamConfig.fps = stoi(fps); m_StreamConfig.bitrate = stoi(bitrate); // kilobits per second - m_StreamConfig.packetSize = 1024; m_StreamConfig.streamingRemotely = 0; m_StreamConfig.audioConfiguration = AUDIO_CONFIGURATION_STEREO; + // The overhead of receiving a packet is much higher in NaCl because we must + // pass through various layers of abstraction on each recv() call. We're using a + // higher than normal default video packet size here to reduce CPU cycles wasted + // receiving packets. The possible cost is greater network losses. + m_StreamConfig.packetSize = 1392; + m_ServerMajorVersion = stoi(serverMajorVersion); // Initialize the rendering surface before starting the connection From 47dfce2c71cbcc44e2e3e879fc51580a2569d13f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 8 May 2016 12:10:49 -0400 Subject: [PATCH 09/10] Update common-c --- moonlight-common-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonlight-common-c b/moonlight-common-c index 7e5e2ce..dddcba2 160000 --- a/moonlight-common-c +++ b/moonlight-common-c @@ -1 +1 @@ -Subproject commit 7e5e2cebe210b0bb04ea0e0bff18d06135ade420 +Subproject commit dddcba217b315281364bca92e7e409b449fff000 From c31ae715669f1639b8bb6169e85d4504ed36196b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 8 May 2016 12:36:25 -0400 Subject: [PATCH 10/10] Bump version to 0.3 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 03575a6..5af865a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Moonlight", - "version": "0.02", + "version": "0.03", "description": "A Moonlight streaming plugin for Google Chrome", "icons": { "128": "icons/icon128.png",