]> git.sesse.net Git - nageru/blobdiff - cef_capture.cpp
Fix a bug when looping FFmpeg inputs that have no audio.
[nageru] / cef_capture.cpp
index 9dc454ba33d426a6abfcb86234c36e193f221c66..ff978f288640d8036cb33e1479b5e5c39c6a07d8 100644 (file)
@@ -41,7 +41,7 @@ CEFCapture::~CEFCapture()
 
 void CEFCapture::post_to_cef_ui_thread(std::function<void()> &&func)
 {
-       lock_guard<mutex> lock(browser_mutex);
+       lock_guard<recursive_mutex> lock(browser_mutex);
        if (browser != nullptr) {
                CefPostTask(TID_UI, new CEFTaskAdapter(std::move(func)));
        } else {
@@ -86,6 +86,13 @@ void CEFCapture::execute_javascript_async(const string &js)
        });
 }
 
+void CEFCapture::resize(unsigned width, unsigned height)
+{
+       lock_guard<mutex> lock(resolution_mutex);
+       this->width = width;
+       this->height = height;
+}
+
 void CEFCapture::OnPaint(const void *buffer, int width, int height)
 {
        steady_clock::time_point timestamp = steady_clock::now();
@@ -106,7 +113,10 @@ void CEFCapture::OnPaint(const void *buffer, int width, int height)
                // so we need to do this explicitly, or we could be stuck on an
                // old frame forever if the image doesn't change.)
                post_to_cef_ui_thread([this] {
-                       browser->GetHost()->Invalidate(PET_VIEW);
+                       lock_guard<recursive_mutex> lock(browser_mutex);
+                       if (browser != nullptr) {  // Could happen if we are shutting down.
+                               browser->GetHost()->Invalidate(PET_VIEW);
+                       }
                });
                ++timecode;
        } else {
@@ -149,7 +159,7 @@ void CEFCapture::start_bm_capture()
        cef_app->initialize_cef();
 
        CefPostTask(TID_UI, new CEFTaskAdapter([this]{
-               lock_guard<mutex> lock(browser_mutex);
+               lock_guard<recursive_mutex> lock(browser_mutex);
 
                CefBrowserSettings browser_settings;
                browser_settings.web_security = cef_state_t::STATE_DISABLED;
@@ -168,9 +178,11 @@ void CEFCapture::start_bm_capture()
 
 void CEFCapture::stop_dequeue_thread()
 {
-       lock_guard<mutex> lock(browser_mutex);
-       cef_app->close_browser(browser);
-       browser = nullptr;  // Or unref_cef() will be sad.
+       {
+               lock_guard<recursive_mutex> lock(browser_mutex);
+               cef_app->close_browser(browser);
+               browser = nullptr;  // Or unref_cef() will be sad.
+       }
        cef_app->unref_cef();
 }
 
@@ -224,6 +236,12 @@ void NageruCEFClient::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType ty
 
 bool NageruCEFClient::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
 {
+       return parent->GetViewRect(rect);
+}
+
+bool CEFCapture::GetViewRect(CefRect &rect)
+{
+       lock_guard<mutex> lock(resolution_mutex);
        rect = CefRect(0, 0, width, height);
        return true;
 }