X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cef_capture.h;h=30cc4879593eaece48df9e315f755d51c38de3bf;hb=e284d1c7a2e18ee7e4aea082c4a57a3504a0f5e8;hp=dc74b30d527c4c28d6d54cb2ec1431ed77039fde;hpb=b68d8a25951faf5b967b7a35fa0a363b4b68fbc0;p=nageru diff --git a/cef_capture.h b/cef_capture.h index dc74b30..30cc487 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; @@ -69,7 +81,17 @@ public: return card_index; } + 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 resize(unsigned width, unsigned height); + void request_new_frame(); + + // Callbacks from NageruCEFClient. void OnPaint(const void *buffer, int width, int height); + bool GetViewRect(CefRect &rect); + void OnLoadEnd(); // CaptureInterface. void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override @@ -145,8 +167,16 @@ public: uint32_t get_current_audio_input() const override { return 0; } private: + void post_to_cef_ui_thread(std::function &&func, int64_t delay_ms = 0); + CefRefPtr cef_client; - unsigned width, height; + + // Needs to be different from browser_mutex below, since GetViewRect + // can be called unpredictably from when we are already holding + // . + std::mutex resolution_mutex; + unsigned width, height; // Under . + int card_index = -1; bool has_dequeue_callbacks = false; @@ -158,6 +188,23 @@ private: bmusb::frame_callback_t frame_callback = nullptr; std::string description, start_url; + std::atomic max_fps{60}; + + // Needs to be recursive because the lambda in OnPaint could cause + // OnPaint itself to be called. + std::recursive_mutex browser_mutex; + CefRefPtr browser; // Under . + + // 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; };