Skip to content

Commit 81a9bec

Browse files
authored
livekit-plugins-browser: initial dev renderer (#616)
1 parent 44a3423 commit 81a9bec

16 files changed

+655
-396
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Defines the Chromium style for automatic reformatting.
2+
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
3+
BasedOnStyle: Chromium
4+
---
5+
Language: ObjC
6+
BasedOnStyle: Google
7+
BinPackParameters: false
8+
BinPackArguments: false
9+
ColumnLimit: 100
10+
ObjCBlockIndentWidth: 2
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
AlignOperands: false
13+
AlwaysBreakBeforeMultilineStrings: false
14+
AllowShortFunctionsOnASingleLine: Inline
15+
BreakBeforeTernaryOperators: false
16+
IndentWrappedFunctionNames: true
17+
ContinuationIndentWidth: 4
18+
ObjCSpaceBeforeProtocolList: true
19+
---
20+
Language: Cpp
21+
IncludeBlocks: Regroup

livekit-plugins/livekit-plugins-browser/cef/src/CMakeLists.txt

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
set(LKCEF_SRCS app.cpp app.hpp utils.cpp utils.hpp handler.hpp handler.cpp)
1+
include(FetchContent)
2+
3+
set(FETCHCONTENT_QUIET off)
4+
5+
# I don't want to write a different code per platform for the dev mode.
6+
# so use glfw and imgui like I do for my other side projects...
7+
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
8+
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
9+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
10+
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
11+
FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.4)
12+
FetchContent_MakeAvailable(glfw)
13+
14+
FetchContent_Declare(imgui GIT_REPOSITORY https://github.com/ocornut/imgui GIT_TAG origin/docking)
15+
FetchContent_GetProperties(imgui)
16+
FetchContent_MakeAvailable(imgui)
17+
file(GLOB IMGUI_SOURCES ${imgui_SOURCE_DIR}/*.cpp)
18+
file(GLOB IMGUI_HEADERS ${imgui_SOURCE_DIR}/*.h)
19+
add_library(imgui STATIC ${IMGUI_SOURCES} ${IMGUI_SOURCES} ${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
20+
set_target_properties(imgui PROPERTIES CXX_STANDARD 17)
21+
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends ${GLFW_INCLUDE_DIR})
22+
target_link_libraries(imgui PRIVATE glfw)
23+
24+
25+
set(LKCEF_SRCS app.cpp app.hpp handler.hpp handler.cpp dev_renderer.hpp dev_renderer.cpp)
226
set(LKCEF_SRCS_LINUX main_linux.cpp)
3-
set(LKCEF_SRCS_MAC main_mac.mm handler_mac.mm app_mac.mm)
27+
set(LKCEF_SRCS_MAC app_mac.mm)
428
set(LKCEF_SRCS_WINDOWS main_win.cpp )
529
append_platform_sources(LKCEF_SRCS)
630
source_group(lkcef FILES ${LKCEF_SRCS})
731

8-
set(LKCEF_HELPER_SRCS utils.cpp utils.hpp)
32+
set(LKCEF_HELPER_SRCS )
933
set(LKCEF_HELPER_SRCS_LINUX helper_main_linux.cpp)
1034
set(LKCEF_HELPER_SRCS_MAC helper_main_mac.mm)
1135
set(LKCEF_HELPER_SRCS_WINDOWS helper_main_win.cpp)
@@ -69,9 +93,8 @@ if(OS_MAC)
6993
add_library(lkcef STATIC ${LKCEF_SRCS})
7094
set_library_target_properties(lkcef)
7195
add_dependencies(lkcef libcef_dll_wrapper)
72-
target_link_libraries(lkcef libcef_dll_wrapper ${CEF_STANDARD_LIBS})
73-
74-
96+
target_include_directories(lkcef PRIVATE ${GLFW_INCLUDE_DIR})
97+
target_link_libraries(lkcef libcef_dll_wrapper ${CEF_STANDARD_LIBS} glfw imgui)
7598

7699
add_custom_command(
77100
TARGET lkcef
@@ -101,7 +124,7 @@ if(OS_MAC)
101124
# Create Helper-specific variants of the helper-Info.plist file.
102125
set(_helper_info_plist
103126
"${CMAKE_CURRENT_BINARY_DIR}/lkcef-Info${_target_suffix}.plist")
104-
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/resources/lkcef-Info.plist"
127+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/resources/lkcefhelper-Info.plist"
105128
_plist_contents)
106129
string(REPLACE "\${EXECUTABLE_NAME}" "${_helper_output_name}"
107130
_plist_contents ${_plist_contents})
@@ -173,6 +196,4 @@ set_target_properties(lkcef_python PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
173196
target_include_directories(lkcef_python PRIVATE ${CEF_INCLUDE_PATH})
174197
target_link_libraries(lkcef_python PUBLIC lkcef)
175198
target_link_libraries(lkcef_python PUBLIC libcef_dll_wrapper ${CEF_STANDARD_LIBS})
176-
177-
178-
199+
add_dependencies(lkcef_python libcef_dll_wrapper)

livekit-plugins/livekit-plugins-browser/cef/src/agents_python.cpp

+36-11
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,50 @@
33
#include "app.hpp"
44
#include "include/internal/cef_mac.h"
55

6-
namespace py = pybind11;
6+
#include <pybind11/pybind11.h>
7+
#include <pybind11/functional.h>
78

8-
BrowserImpl::BrowserImpl() {
9+
namespace py = pybind11;
910

11+
BrowserApp::BrowserApp(const AppOptions& options) : options_(options) {
12+
app_ = new AgentApp(options_.dev_mode, options_.initialized_callback);
1013
}
1114

15+
std::shared_ptr<BrowserImpl> BrowserApp::CreateBrowser(
16+
const std::string& url,
17+
const BrowserOptions& options) {
1218

13-
void BrowserImpl::start() {
14-
py::print("BrowserImpl::start()");
15-
AgentApp::run();
19+
app_->CreateBrowser(url, options.framerate, options.created_callback);
20+
return nullptr;//std::make_shared<BrowserImpl>();
1621
}
1722

23+
int BrowserApp::Run() {
24+
return RunAgentApp(app_);
25+
}
26+
27+
BrowserImpl::BrowserImpl() {}
28+
29+
void BrowserImpl::SetSize(int width, int height) {}
1830

19-
PYBIND11_MODULE(lkcef_python, m)
20-
{
31+
PYBIND11_MODULE(lkcef_python, m) {
32+
// Isn't that fucking cool? llm using browsers
2133
m.doc() = "Chromium Embedded Framework (CEF) for LiveKit Agents";
22-
23-
34+
35+
py::class_<AppOptions>(m, "AppOptions")
36+
.def(py::init())
37+
.def_readwrite("dev_mode", &AppOptions::dev_mode)
38+
.def_readwrite("initialized_callback", &AppOptions::initialized_callback);
39+
40+
py::class_<BrowserOptions>(m, "BrowserOptions")
41+
.def(py::init())
42+
.def_readwrite("framerate", &BrowserOptions::framerate)
43+
.def_readwrite("created_callback", &BrowserOptions::created_callback);
44+
45+
py::class_<BrowserApp>(m, "BrowserApp")
46+
.def(py::init<const AppOptions&>())
47+
.def("create_browser", &BrowserApp::CreateBrowser)
48+
.def("run", &BrowserApp::Run);
49+
2450
py::class_<BrowserImpl>(m, "BrowserImpl")
25-
.def(py::init<>())
26-
.def("start", &BrowserImpl::start);
51+
.def("set_size", &BrowserImpl::SetSize);
2752
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
#ifndef LKCEF_AGENT_PYTHON_HPP
2-
#define LKCEF_AGENT_PYTHON_HPP
1+
#ifndef LKCEF_AGENTS_PYTHON_HPP
2+
#define LKCEF_AGENTS_PYTHON_HPP
33

4-
#include <pybind11/pybind11.h>
4+
#include <functional>
5+
#include <memory>
56

7+
#include "app.hpp"
68

7-
class BrowserImpl {
8-
public:
9-
BrowserImpl();
10-
void start();
9+
class BrowserImpl;
10+
11+
struct AppOptions {
12+
bool dev_mode = false;
13+
std::function<void()> initialized_callback = nullptr;
14+
};
15+
16+
struct BrowserOptions {
17+
int framerate = 30;
18+
std::function<void()> created_callback = nullptr;
19+
};
20+
21+
struct BrowserApp {
22+
BrowserApp(const AppOptions& options);
23+
24+
std::shared_ptr<BrowserImpl> CreateBrowser(const std::string& url,
25+
const BrowserOptions& options);
26+
int Run();
27+
28+
private:
29+
AppOptions options_;
30+
CefRefPtr<AgentApp> app_;
31+
};
32+
33+
struct BrowserImpl {
34+
BrowserImpl();
35+
36+
void SetSize(int width, int height);
1137
};
1238

13-
#endif // LKCEF_AGENT_PYTHON_HPP
39+
#endif // LKCEF_AGENTS_PYTHON_HPP

0 commit comments

Comments
 (0)