From f1ce3c5618f769b1388b39c637877d242c8ddeed Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 25 Feb 2018 15:33:50 +0100 Subject: [PATCH] Implement HTMLInput::set_max_fps(). --- cef_capture.cpp | 14 +++++++++++--- cef_capture.h | 2 ++ theme.cpp | 12 +++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cef_capture.cpp b/cef_capture.cpp index 548e529..9c4f68c 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -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 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; diff --git a/cef_capture.h b/cef_capture.h index 587af0a..be5402f 100644 --- a/cef_capture.h +++ b/cef_capture.h @@ -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 max_fps{60}; std::mutex browser_mutex; CefRefPtr browser; // Under . diff --git a/theme.cpp b/theme.cpp index 4ddea3a..71970c9 100644 --- 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 } }; -- 2.39.2