X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.h;h=c497179d72e127077e4abb193e34f720ed7ea141;hb=52c5033edb39aa71c2a979b4788b622dc44683af;hp=8dc053dddf9bfc1e37ecb0e62dd8954b1a3ac617;hpb=cd48c8ab6d7425d4b4d9fdb2493da69b44848c9e;p=nageru diff --git a/cef_capture.h b/cef_capture.h index 8dc053d..c497179 100644 --- a/cef_capture.h +++ b/cef_capture.h @@ -17,6 +17,7 @@ #include #include #include +#include #undef CHECK #include @@ -31,7 +32,7 @@ class CEFCapture; // A helper class for CEFCapture to proxy information to CEF, without becoming // CEF-refcounted itself. -class NageruCEFClient : public CefClient, public CefRenderHandler +class NageruCEFClient : public CefClient, public CefRenderHandler, public CefLoadHandler { public: NageruCEFClient(int width, int height, CEFCapture *parent) @@ -42,10 +43,21 @@ public: return this; } + CefRefPtr GetLoadHandler() override + { + return this; + } + + // CefRenderHandler. + void OnPaint(CefRefPtr browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height) override; bool GetViewRect(CefRefPtr browser, CefRect &rect); + // CefLoadHandler. + + void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, int httpStatusCode) override; + private: int width, height; CEFCapture *parent; @@ -70,9 +82,14 @@ public: } void set_url(const std::string &url); + void reload(); + void set_max_fps(int max_fps); + void execute_javascript_async(const std::string &js); void OnPaint(const void *buffer, int width, int height); + void OnLoadEnd(); + // CaptureInterface. void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override { @@ -162,6 +179,7 @@ private: bmusb::frame_callback_t frame_callback = nullptr; std::string description, start_url; + std::atomic max_fps{60}; std::mutex browser_mutex; CefRefPtr browser; // Under . @@ -169,6 +187,14 @@ private: // Tasks waiting for to get ready. Under . std::vector> deferred_tasks; + // Whether the last set_url() (includes the implicit one in the constructor) + // has loaded yet. Accessed from the CEF thread only. + bool loaded = false; + + // JavaScript waiting for the first page (well, any page) to have loaded. + // Accessed from the CEF thread only. + std::vector deferred_javascript; + int timecode = 0; };