Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update cef to 103 #1506

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ _Note: if you ran docker with sudo, CasparCG server will not be able to run with
2. `git clone --single-branch --branch master https://github.com/CasparCG/server casparcg-server-master`
3. `cd casparcg-server-master`
4. Install dependencies, this can be done with `sudo ./tools/linux/install-dependencies`
5. Extract Boost, FFmpeg and CEF from the docker images via `sudo ./tools/linux/extract-deps-from-docker`. Alternatively these can be prepared manually by following the steps laid out in each Dockerfile
5. Extract Boost and FFmpeg from the docker images via `sudo ./tools/linux/extract-deps-from-docker`. Alternatively these can be prepared manually by following the steps laid out in each Dockerfile
6. `mkdir build && cd build`
7. `cmake ../src`
8. `make -j8`
Expand Down
31 changes: 25 additions & 6 deletions src/CMakeModules/Bootstrap_Linux.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 3.16)

include(ExternalProject)

# Determine build (target) platform
INCLUDE (PlatformIntrospection)
_DETERMINE_PLATFORM (CONFIG_PLATFORM)
Expand Down Expand Up @@ -39,8 +41,29 @@ FIND_PACKAGE (SFML 2 COMPONENTS graphics window system REQUIRED)
FIND_PACKAGE (X11 REQUIRED)

if (ENABLE_HTML)
SET(CEF_ROOT_DIR "/opt/cef" CACHE STRING "Path to CEF")
FIND_PACKAGE (CEF REQUIRED)
casparcg_add_external_project(cef)
ExternalProject_Add(cef
URL https://cef-builds.spotifycdn.com/cef_binary_103.0.12%2Bg8eb56c7%2Bchromium-103.0.5060.134_linux64_minimal.tar.bz2
URL_HASH SHA1=2f6500b81ea780feaabae41570192aef71d60963
DOWNLOAD_DIR ${CASPARCG_DOWNLOAD_CACHE}
CMAKE_ARGS -DUSE_SANDBOX=Off
INSTALL_COMMAND ""
BUILD_BYPRODUCTS
"<SOURCE_DIR>/Release/libcef.so"
"<BINARY_DIR>/libcef_dll_wrapper/libcef_dll_wrapper.a"
)
ExternalProject_Get_Property(cef SOURCE_DIR)
ExternalProject_Get_Property(cef BINARY_DIR)

# Note: All of these must be referenced in the BUILD_BYPRODUCTS above, to satisfy ninja
set(CEF_LIB
"${SOURCE_DIR}/Release/libcef.so"
"${BINARY_DIR}/libcef_dll_wrapper/libcef_dll_wrapper.a"
)

set(CEF_INCLUDE_PATH "${SOURCE_DIR}")
set(CEF_BIN_PATH "${SOURCE_DIR}/Release")
set(CEF_RESOURCE_PATH "${SOURCE_DIR}/Resources")
endif ()

SET (BOOST_INCLUDE_PATH "${Boost_INCLUDE_DIRS}")
Expand All @@ -50,10 +73,6 @@ SET (SFML_INCLUDE_PATH "${SFML_INCLUDE_DIR}")
SET (FFMPEG_INCLUDE_PATH "${FFMPEG_INCLUDE_DIRS}")
SET (FREEIMAGE_INCLUDE_PATH "${FreeImage_INCLUDE_DIRS}")

set(CEF_INCLUDE_PATH "${CEF_ROOT_DIR}")
set(CEF_BIN_PATH "${CEF_ROOT_DIR}/Release")
set(CEF_RESOURCE_PATH "${CEF_ROOT_DIR}/Resources")

SET_PROPERTY (GLOBAL PROPERTY USE_FOLDERS ON)

ADD_DEFINITIONS (-DSFML_STATIC)
Expand Down
5 changes: 2 additions & 3 deletions src/CMakeModules/Bootstrap_Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ casparcg_add_runtime_dependency("${LIBERATION_FONTS_BIN_PATH}/LiberationMono-Reg
if (ENABLE_HTML)
casparcg_add_external_project(cef)
ExternalProject_Add(cef
URL ${CASPARCG_DOWNLOAD_MIRROR}/cef/cef_binary_4638_windows_x64.zip
URL_HASH MD5=14ad547122903eba3f145322fb02bc6d
URL https://builds.julusian.dev/casparcg/dependencies/cef_binary_103.0.0-5060-shared-textures.2596%2Bgaa7dcf4%2Bchromium-103.0.5060.134_windows64_minimal.zip
URL_HASH MD5=240f5cebcc019410643c7e787a31ff75
DOWNLOAD_DIR ${CASPARCG_DOWNLOAD_CACHE}
CMAKE_ARGS -DUSE_SANDBOX=Off -DCEF_RUNTIME_LIBRARY_FLAG=/MD
INSTALL_COMMAND ""
Expand All @@ -227,7 +227,6 @@ if (ENABLE_HTML)
casparcg_add_runtime_dependency("${CEF_RESOURCE_PATH}/resources.pak")
casparcg_add_runtime_dependency("${CEF_RESOURCE_PATH}/icudtl.dat")

casparcg_add_runtime_dependency_dir("${CEF_BIN_PATH}/swiftshader")
casparcg_add_runtime_dependency("${CEF_BIN_PATH}/snapshot_blob.bin")
casparcg_add_runtime_dependency("${CEF_BIN_PATH}/v8_context_snapshot.bin")
casparcg_add_runtime_dependency("${CEF_BIN_PATH}/libcef.dll")
Expand Down
69 changes: 0 additions & 69 deletions src/CMakeModules/FindCEF.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions src/accelerator/d3d/d3d_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
namespace caspar { namespace accelerator { namespace d3d {
struct d3d_device::impl : public std::enable_shared_from_this<impl>
{
using texture_queue_t = tbb::concurrent_bounded_queue<std::shared_ptr<d3d_texture2d>>;

mutable std::mutex device_pools_mutex_;
tbb::concurrent_unordered_map<size_t, texture_queue_t> device_pools_;

std::wstring adaptor_name_ = L"N/A";
std::shared_ptr<ID3D11Device> device_;
std::shared_ptr<d3d_device_context> ctx_;
Expand Down
62 changes: 61 additions & 1 deletion src/accelerator/d3d/d3d_texture2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ d3d_texture2d::~d3d_texture2d()
ogl->dispatch_sync([&] {
const std::shared_ptr<void> interop = ogl->d3d_interop();
if (texture_handle_ != nullptr && interop != nullptr) {
wglDXUnlockObjectsNV(interop.get(), 1, &texture_handle_);
if (is_locked_) {
wglDXUnlockObjectsNV(interop.get(), 1, &texture_handle_);
is_locked_ = false;
}

wglDXUnregisterObjectNV(interop.get(), texture_handle_);
texture_handle_ = nullptr;
}
Expand Down Expand Up @@ -100,7 +104,63 @@ void d3d_texture2d::gen_gl_texture(std::shared_ptr<ogl::device> ogl)
gl_texture_id_ = 0;
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to lock shared d3d texture."));
}

is_locked_ = true;
});
}

void d3d_texture2d::lock_gl()
{
if (is_locked_)
return;

if (!texture_handle_ || gl_texture_id_ == 0) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("texture is not ready to be locked."));
}

const std::shared_ptr<ogl::device> ogl = ogl_.lock();
if (ogl == nullptr) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("failed to lock opengl device."));
}

const std::shared_ptr<void> interop = ogl->d3d_interop();
if (!interop) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("d3d interop not setup to lock shared d3d texture."));
}

bool res = ogl->dispatch_sync([&] { return wglDXLockObjectsNV(interop.get(), 1, &texture_handle_); });
if (!res) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to lock shared d3d texture."));
}

is_locked_ = true;
}

void d3d_texture2d::unlock_gl()
{
if (!is_locked_)
return;

if (!texture_handle_ || gl_texture_id_ == 0) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("texture is not ready to be locked."));
}

const std::shared_ptr<ogl::device> ogl = ogl_.lock();
if (ogl == nullptr) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("failed to lock opengl device."));
}

const std::shared_ptr<void> interop = ogl->d3d_interop();
if (!interop) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("d3d interop not setup to unlock shared d3d texture."));
}

bool res = ogl->dispatch_sync([&] { return wglDXUnlockObjectsNV(interop.get(), 1, &texture_handle_); });
if (!res) {
CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to unlock shared d3d texture."));
}

is_locked_ = false;
}

}}} // namespace caspar::accelerator::d3d
5 changes: 5 additions & 0 deletions src/accelerator/d3d/d3d_texture2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class d3d_texture2d

void gen_gl_texture(std::shared_ptr<ogl::device>);

void lock_gl();

void unlock_gl();

private:
HANDLE share_handle_;

Expand All @@ -44,5 +48,6 @@ class d3d_texture2d
std::weak_ptr<ogl::device> ogl_;
HANDLE texture_handle_ = nullptr;
uint32_t gl_texture_id_ = 0;
bool is_locked_ = false;
};
}}} // namespace caspar::accelerator::d3d
8 changes: 7 additions & 1 deletion src/accelerator/ogl/image/image_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,21 @@ struct image_mixer::impl
// map directx texture with wgl texture
if (d3d_texture->gl_texture_id() == 0)
d3d_texture->gen_gl_texture(ogl_);
else
// signal d3d to flush/sync the texture
d3d_texture->lock_gl();

// copy directx texture to gl texture
// copy d3d texture to gl texture
auto gl_texture = ogl_->dispatch_sync([=] {
return ogl_->copy_async(d3d_texture->gl_texture_id(), d3d_texture->width(), d3d_texture->height(), 4);
});

// make gl texture to draw
std::vector<future_texture> textures{make_ready_future(gl_texture.get())};

// signal d3d is free to take ownership
d3d_texture->unlock_gl();

std::weak_ptr<image_mixer::impl> weak_self = shared_from_this();
core::pixel_format_desc desc(core::pixel_format::bgra);
desc.planes.push_back(core::pixel_format_desc::plane(d3d_texture->width(), d3d_texture->height(), 4));
Expand Down
3 changes: 1 addition & 2 deletions src/modules/html/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ if(MSVC)
)
else()
target_link_libraries(html
${CEF_BIN_PATH}/libcef.so
${CEF_BIN_PATH}/libcef_dll_wrapper.a
${CEF_LIB}
)
endif()

1 change: 0 additions & 1 deletion src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ else ()
ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CEF_RESOURCE_PATH}/icudtl.dat ${CMAKE_BINARY_DIR}/staging/lib/icudtl.dat)
ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CEF_RESOURCE_PATH}/resources.pak ${CMAKE_BINARY_DIR}/staging/lib/resources.pak)

ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CEF_BIN_PATH}/swiftshader ${CMAKE_BINARY_DIR}/staging/lib/swiftshader)
ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CEF_BIN_PATH}/chrome-sandbox ${CMAKE_BINARY_DIR}/staging/lib/chrome-sandbox)
ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CEF_BIN_PATH}/libcef.so ${CMAKE_BINARY_DIR}/staging/lib/libcef.so)
ADD_CUSTOM_COMMAND (TARGET casparcg POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CEF_BIN_PATH}/libEGL.so ${CMAKE_BINARY_DIR}/staging/lib/libEGL.so)
Expand Down
3 changes: 0 additions & 3 deletions tools/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
ARG IMAGE_BASE
ARG IMAGE_BOOST
ARG IMAGE_FFMPEG
ARG IMAGE_CEF

FROM ${IMAGE_BOOST} as boost
FROM ${IMAGE_FFMPEG} as ffmpeg
FROM ${IMAGE_CEF} as cef

FROM ${IMAGE_BASE} as build-casparcg
COPY --from=boost /opt/boost /opt/boost
COPY --from=ffmpeg /opt/ffmpeg /opt/ffmpeg
COPY --from=cef /opt/cef /opt/cef

RUN mkdir /source && mkdir /build && mkdir /install

Expand Down
2 changes: 1 addition & 1 deletion tools/linux/build-base-images
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source $(dirname "$0")/image-versions

docker rmi $IMAGE_BASE $IMAGE_CEF $IMAGE_BOOST $IMAGE_FFMPEG
docker rmi $IMAGE_BASE $IMAGE_BOOST $IMAGE_FFMPEG

$(dirname "$0")/ensure-base-images
1 change: 0 additions & 1 deletion tools/linux/build-in-docker
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ docker build -t casparcg/server \
--build-arg PROC_COUNT \
--build-arg GIT_HASH \
--build-arg IMAGE_BASE \
--build-arg IMAGE_CEF \
--build-arg IMAGE_BOOST \
--build-arg IMAGE_FFMPEG \
-f $PWD/tools/linux/Dockerfile $PWD
Expand Down
17 changes: 0 additions & 17 deletions tools/linux/cef/Dockerfile

This file was deleted.

2 changes: 0 additions & 2 deletions tools/linux/ensure-base-images
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
source $(dirname "$0")/image-versions

docker pull $IMAGE_BASE || docker build --pull -f tools/linux/base/Dockerfile -t $IMAGE_BASE tools/linux
docker pull $IMAGE_CEF || docker build -t $IMAGE_CEF --build-arg PROC_COUNT --build-arg IMAGE_BASE tools/linux/cef
docker pull $IMAGE_BOOST || docker build -t $IMAGE_BOOST --build-arg PROC_COUNT --build-arg IMAGE_BASE tools/linux/boost
docker pull $IMAGE_FFMPEG || docker build -t $IMAGE_FFMPEG --build-arg PROC_COUNT --build-arg IMAGE_BASE tools/linux/ffmpeg

if [ "$CASPARCG_PUSH_IMAGES" = true ]; then
docker push $IMAGE_BASE
docker push $IMAGE_CEF
docker push $IMAGE_BOOST
docker push $IMAGE_FFMPEG
fi
7 changes: 0 additions & 7 deletions tools/linux/extract-deps-from-docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

source $(dirname "$0")/image-versions

# CEF
echo "Extracting CEF"
rm -Rf /opt/cef
tempContainer=$(docker create $IMAGE_CEF sh)
docker cp $tempContainer:/opt/cef /opt/cef
docker rm -v $tempContainer

# FFmpeg
echo "Extracting FFmpeg"
rm -Rf /opt/ffmpeg
Expand Down
1 change: 0 additions & 1 deletion tools/linux/image-versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
export IMAGE_PREFIX=ghcr.io/casparcg/server/

export IMAGE_BASE=${IMAGE_PREFIX}base:jammy-0
export IMAGE_CEF=${IMAGE_PREFIX}cef:95.0.4638.69-obs-2
export IMAGE_BOOST=${IMAGE_PREFIX}boost:1.67-2
export IMAGE_FFMPEG=${IMAGE_PREFIX}ffmpeg:5.1.3-1