]> git.sesse.net Git - nageru/blob - nageru/nageru_cef_app.cpp
Fix an issue where Matroska HTTP FFmpeg streams would not correctly restart on connec...
[nageru] / nageru / nageru_cef_app.cpp
1 #include <cef_app.h>
2 #include <cef_browser.h>
3 #include <cef_client.h>
4 #include <cef_version.h>
5 #include <QTimer>
6 #include <QWidget>
7
8 #include "nageru_cef_app.h"
9
10 using namespace std;
11
12 void NageruCefApp::OnBeforeCommandLineProcessing(
13         const CefString& process_type,
14         CefRefPtr<CefCommandLine> command_line)
15 {
16         command_line->AppendSwitch("disable-gpu");
17         command_line->AppendSwitch("disable-gpu-compositing");
18         command_line->AppendSwitch("enable-begin-frame-scheduling");
19 }
20
21 void NageruCefApp::initialize_cef()
22 {
23         unique_lock<mutex> lock(cef_mutex);
24         if (cef_thread_refcount++ == 0) {
25                 cef_thread = thread(&NageruCefApp::cef_thread_func, this);
26         }
27         cef_initialized_cond.wait(lock, [this]{ return cef_initialized; });
28 }
29
30 void NageruCefApp::close_browser(CefRefPtr<CefBrowser> browser)
31 {
32         lock_guard<mutex> lock(cef_mutex);
33         browser->GetHost()->CloseBrowser(/*force_close=*/true);
34 }
35
36 void NageruCefApp::unref_cef()
37 {
38         unique_lock<mutex> lock(cef_mutex);
39         if (--cef_thread_refcount == 0) {
40                 CefPostTask(TID_UI, new CEFTaskAdapter(&CefQuitMessageLoop));
41                 lock.unlock();
42                 cef_thread.join();
43         }
44 }
45
46 void NageruCefApp::cef_thread_func()
47 {
48         CefMainArgs main_args;
49         CefSettings settings;
50         //settings.log_severity = LOGSEVERITY_VERBOSE;
51         settings.windowless_rendering_enabled = true;
52         settings.no_sandbox = true;
53         settings.command_line_args_disabled = false;
54         CefInitialize(main_args, settings, this, nullptr);
55
56         {
57                 lock_guard<mutex> lock(cef_mutex);
58                 cef_initialized = true;
59         }
60         cef_initialized_cond.notify_all();
61
62         CefRunMessageLoop();
63
64         CefShutdown();
65 }
66