X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.cpp;h=9c4f68c8f6d875ea40a1e03b3d7b015b392efea0;hb=f1ce3c5618f769b1388b39c637877d242c8ddeed;hp=c05c2953deff7cc3837f1f203917eee8f734b843;hpb=b68d8a25951faf5b967b7a35fa0a363b4b68fbc0;p=nageru diff --git a/cef_capture.cpp b/cef_capture.cpp index c05c295..9c4f68c 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -39,6 +39,38 @@ CEFCapture::~CEFCapture() } } +void CEFCapture::post_to_cef_ui_thread(std::function &&func) +{ + lock_guard lock(browser_mutex); + if (browser != nullptr) { + CefPostTask(TID_UI, new CEFTaskAdapter(std::move(func))); + } else { + deferred_tasks.push_back(std::move(func)); + } +} + +void CEFCapture::set_url(const string &url) +{ + post_to_cef_ui_thread([this, url] { + browser->GetMainFrame()->LoadURL(url); + }); +} + +void CEFCapture::reload() +{ + post_to_cef_ui_thread([this] { + browser->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(); @@ -47,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; @@ -79,14 +111,22 @@ void CEFCapture::start_bm_capture() { cef_app->initialize_cef(); - 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; - - CefWindowInfo window_info; - window_info.SetAsWindowless(0); - CefBrowserHost::CreateBrowser(window_info, cef_client, start_url, browser_settings, nullptr); + CefPostTask(TID_UI, new CEFTaskAdapter([this]{ + lock_guard lock(browser_mutex); + + 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 = max_fps; + + CefWindowInfo window_info; + window_info.SetAsWindowless(0); + browser = CefBrowserHost::CreateBrowserSync(window_info, cef_client, start_url, browser_settings, nullptr); + for (function &task : deferred_tasks) { + task(); + } + deferred_tasks.clear(); + })); } void CEFCapture::stop_dequeue_thread() @@ -108,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;