]> git.sesse.net Git - nageru/blobdiff - nageru/cef_capture.cpp
IWYU-fix nageru/*.cpp.
[nageru] / nageru / cef_capture.cpp
index b6b8cca489ff782182541101a1db372ac1ab735a..68a719a20f753a29eb9cd12adbd23e8a875959bc 100644 (file)
@@ -1,17 +1,24 @@
 #include <assert.h>
+#include <functional>
+#include <map>
+#include <mutex>
 #include <stdio.h>
+#include <stdint.h>
 #include <string.h>
 #include <chrono>
 #include <memory>
 #include <string>
+#include <utility>
 
 #include "cef_capture.h"
+#include "base/cef_logging.h"
 #include "nageru_cef_app.h"
+#include "nageru/defs.h"
 
 #undef CHECK
-#include <cef_app.h>
 #include <cef_browser.h>
-#include <cef_client.h>
+#include <cef_frame.h>
+#include <cef_task.h>
 
 #include "bmusb/bmusb.h"
 
@@ -97,8 +104,17 @@ void CEFCapture::resize(unsigned width, unsigned height)
        this->height = height;
 }
 
-void CEFCapture::request_new_frame()
+void CEFCapture::request_new_frame(bool ignore_if_locked)
 {
+       unique_lock<recursive_mutex> outer_lock(browser_mutex, defer_lock);
+       if (ignore_if_locked && !outer_lock.try_lock()) {
+               // If the caller is holding card_mutex, we need to abort here
+               // if we can't get browser_mutex, since otherwise, the UI thread
+               // might hold browser_mutex (blocking post_to_cef_ui_thread())
+               // and be waiting for card_mutex.
+               return;
+       }
+
        // By adding a delay, we make sure we don't get a new frame
        // delivered immediately (we probably already are on the UI thread),
        // where we couldn't really deal with it.
@@ -129,7 +145,7 @@ void CEFCapture::OnPaint(const void *buffer, int width, int height)
                // (CEF only sends OnPaint when there are actual changes,
                // so we need to do this explicitly, or we could be stuck on an
                // old frame forever if the image doesn't change.)
-               request_new_frame();
+               request_new_frame(/*ignore_if_locked=*/false);
                ++timecode;
        } else {
                assert(video_frame.size >= unsigned(width * height * 4));
@@ -156,8 +172,6 @@ void CEFCapture::OnLoadEnd()
        });
 }
 
-#define FRAME_SIZE (8 << 20)  // 8 MB.
-
 void CEFCapture::configure_card()
 {
        if (video_frame_allocator == nullptr) {
@@ -174,13 +188,12 @@ void CEFCapture::start_bm_capture()
                lock_guard<recursive_mutex> 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);
+               browser = CefBrowserHost::CreateBrowserSync(window_info, cef_client, start_url, browser_settings, nullptr, nullptr);
                for (function<void()> &task : deferred_tasks) {
                        task();
                }
@@ -246,16 +259,15 @@ void NageruCEFClient::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType ty
        parent->OnPaint(buffer, width, height);
 }
 
-bool NageruCEFClient::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
+void NageruCEFClient::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
 {
-       return parent->GetViewRect(rect);
+       parent->GetViewRect(rect);
 }
 
-bool CEFCapture::GetViewRect(CefRect &rect)
+void CEFCapture::GetViewRect(CefRect &rect)
 {
        lock_guard<mutex> lock(resolution_mutex);
        rect = CefRect(0, 0, width, height);
-       return true;
 }
 
 void NageruCEFClient::OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode)