X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.cpp;fp=cef_capture.cpp;h=f692c857f0201b1800a7cd913fdb40af3b701fbb;hb=3196324d54748a391c7c333191769f2624e3e022;hp=853c6b4916a6b1ddcfb4aa4b715f574f51e7cb40;hpb=06608bb52fa8788a7a6498198143fc38fa83df44;p=nageru diff --git a/cef_capture.cpp b/cef_capture.cpp index 853c6b4..f692c85 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -97,6 +97,19 @@ void CEFCapture::resize(unsigned width, unsigned height) this->height = height; } +void CEFCapture::request_new_frame() +{ + // 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. + post_to_cef_ui_thread([this] { + lock_guard lock(browser_mutex); + if (browser != nullptr) { // Could happen if we are shutting down. + browser->GetHost()->Invalidate(PET_VIEW); + } + }, 16); +} + void CEFCapture::OnPaint(const void *buffer, int width, int height) { steady_clock::time_point timestamp = steady_clock::now(); @@ -116,16 +129,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.) - // - // 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. - post_to_cef_ui_thread([this] { - lock_guard lock(browser_mutex); - if (browser != nullptr) { // Could happen if we are shutting down. - browser->GetHost()->Invalidate(PET_VIEW); - } - }, 16); + request_new_frame(); ++timecode; } else { assert(video_frame.size >= unsigned(width * height * 4));