X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fcef_capture.cpp;h=952486158cdb67e19d604c6322af253d745b71ea;hb=d6e55865d7feccfc000c6187e285212fbfb8e9f7;hp=b6b8cca489ff782182541101a1db372ac1ab735a;hpb=9b7d691b4cc5db7dbfc18c82e86c1207fcac4722;p=nageru diff --git a/nageru/cef_capture.cpp b/nageru/cef_capture.cpp index b6b8cca..9524861 100644 --- a/nageru/cef_capture.cpp +++ b/nageru/cef_capture.cpp @@ -97,8 +97,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 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 +138,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)); @@ -246,16 +255,15 @@ void NageruCEFClient::OnPaint(CefRefPtr browser, PaintElementType ty parent->OnPaint(buffer, width, height); } -bool NageruCEFClient::GetViewRect(CefRefPtr browser, CefRect &rect) +void NageruCEFClient::GetViewRect(CefRefPtr browser, CefRect &rect) { - return parent->GetViewRect(rect); + parent->GetViewRect(rect); } -bool CEFCapture::GetViewRect(CefRect &rect) +void CEFCapture::GetViewRect(CefRect &rect) { lock_guard lock(resolution_mutex); rect = CefRect(0, 0, width, height); - return true; } void NageruCEFClient::OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode)