]> git.sesse.net Git - nageru/commitdiff
Implement HTMLInput::set_max_fps().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Feb 2018 14:33:50 +0000 (15:33 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 26 Feb 2018 17:06:16 +0000 (18:06 +0100)
cef_capture.cpp
cef_capture.h
theme.cpp

index 548e529ad3d2e5dc457e638288c787043d2016eb..9c4f68c8f6d875ea40a1e03b3d7b015b392efea0 100644 (file)
@@ -63,6 +63,14 @@ void CEFCapture::reload()
        });
 }
 
+void CEFCapture::set_max_fps(int max_fps)
+{
+       post_to_cef_ui_thread([this, max_fps] {
+               browser->GetHost()->SetWindowlessFrameRate(max_fps);
+               this->max_fps = max_fps;
+       });
+}
+
 void CEFCapture::OnPaint(const void *buffer, int width, int height)
 {
        steady_clock::time_point timestamp = steady_clock::now();
@@ -71,7 +79,7 @@ void CEFCapture::OnPaint(const void *buffer, int width, int height)
        video_format.width = width;
        video_format.height = height;
        video_format.stride = width * 4;
-       video_format.frame_rate_nom = 60;  // FIXME
+       video_format.frame_rate_nom = max_fps;
        video_format.frame_rate_den = 1;
        video_format.has_signal = true;
        video_format.is_connected = true;
@@ -109,7 +117,7 @@ void CEFCapture::start_bm_capture()
                CefBrowserSettings browser_settings;
                browser_settings.web_security = cef_state_t::STATE_DISABLED;
                browser_settings.webgl = cef_state_t::STATE_ENABLED;
-               browser_settings.windowless_frame_rate = 60;
+               browser_settings.windowless_frame_rate = max_fps;
 
                CefWindowInfo window_info;
                window_info.SetAsWindowless(0);
@@ -140,7 +148,7 @@ std::map<uint32_t, VideoMode> CEFCapture::get_available_video_modes() const
        mode.autodetect = false;
        mode.width = width;
        mode.height = height;
-       mode.frame_rate_num = 60;  // FIXME
+       mode.frame_rate_num = max_fps;
        mode.frame_rate_den = 1;
        mode.interlaced = false;
 
index 587af0a551dc0722af6b27acb821c28c83ccb58d..be5402fda9deb31c0a94cfe756b056250c999fe4 100644 (file)
@@ -71,6 +71,7 @@ public:
 
        void set_url(const std::string &url);
        void reload();
+       void set_max_fps(int max_fps);
 
        void OnPaint(const void *buffer, int width, int height);
 
@@ -163,6 +164,7 @@ private:
        bmusb::frame_callback_t frame_callback = nullptr;
 
        std::string description, start_url;
+       std::atomic<int> max_fps{60};
 
        std::mutex browser_mutex;
        CefRefPtr<CefBrowser> browser;  // Under <browser_mutex>.
index 4ddea3a25915713191719c0da8c412d49933ac02..71970c90f3ac4e849f3c0252172cb558f65544bc 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -439,6 +439,15 @@ int HTMLInput_reload(lua_State* L)
        return 0;
 }
 
+int HTMLInput_set_max_fps(lua_State* L)
+{
+       assert(lua_gettop(L) == 2);
+       CEFCapture **video_input = (CEFCapture **)luaL_checkudata(L, 1, "HTMLInput");
+       int max_fps = lrint(luaL_checknumber(L, 2));
+       (*video_input)->set_max_fps(max_fps);
+       return 0;
+}
+
 int HTMLInput_get_signal_num(lua_State* L)
 {
        assert(lua_gettop(L) == 1);
@@ -656,10 +665,11 @@ const luaL_Reg VideoInput_funcs[] = {
 };
 
 const luaL_Reg HTMLInput_funcs[] = {
-       // TODO: execute_javascript, perhaps set_max_fps?
+       // TODO: execute_javascript
        { "new", HTMLInput_new },
        { "set_url", HTMLInput_set_url },
        { "reload", HTMLInput_reload },
+       { "set_max_fps", HTMLInput_set_max_fps },
        { "get_signal_num", HTMLInput_get_signal_num },
        { NULL, NULL }
 };