Skip to content

Commit

Permalink
feat(websocket): Change library to websocketpp
Browse files Browse the repository at this point in the history
obs-studio release doesn't carrying with QWebSocket library. Before
we build our own one and distribute. But QT libraries cannot
compatible across version. So everytime obs-studio upgrade their QT
version, we need to recompile and distribute QWebSockets.

After changing to websocketpp, we won't carrying QWebSockets and
the version of our plugins can suit obs version more widely.

Signed-off-by: Yibai Zhang <xm1994@gmail.com>
  • Loading branch information
summershrimp committed Jan 6, 2024
1 parent cf07914 commit 3209c94
Show file tree
Hide file tree
Showing 22 changed files with 625 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .github/scripts/.build.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
if (( ! (${skips[(Ie)all]} + ${skips[(Ie)build]}) )) {
log_info "Configuring ${product_name}..."
conan install . -s "build_type=Release" -s "&:build_type=${BUILD_CONFIG:-RelWithDebInfo}" \
-of "build_${target##*-}" --deployer full_deploy
local _plugin_deps="${project_root:h}/obs-build-dependencies/plugin-deps-${OBS_DEPS_VERSION}-qt${QT_VERSION}-${target##*-}"
local -a cmake_args=(
-DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-RelWithDebInfo}
-DQT_VERSION=${QT_VERSION}
-DCMAKE_PREFIX_PATH="${_plugin_deps}"
-DCMAKE_TOOLCHAIN_FILE="build_${target##*-}/build/${BUILD_CONFIG:-RelWithDebInfo}/generators/conan_toolchain.cmake"
)
if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
Expand Down
3 changes: 3 additions & 0 deletions .github/scripts/Build-Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ function Build {
if ( ! ( ( $SkipAll ) -or ( $SkipBuild ) ) ) {
Ensure-Location $ProjectRoot

Invoke-External conan install . -s "build_type=Release" -s "&:build_type=${Configuration}" -of "build_${script:Target}" --deployer full_deploy

$DepsPath = "plugin-deps-${script:DepsVersion}-qt${script:QtVersion}-${script:Target}"
$CmakeArgs = @(
'-G', $CmakeGenerator
"-DCMAKE_SYSTEM_VERSION=${script:PlatformSDK}"
"-DCMAKE_GENERATOR_PLATFORM=$(if (${script:Target} -eq "x86") { "Win32" } else { "x64" })"
"-DCMAKE_BUILD_TYPE=${Configuration}"
"-DCMAKE_PREFIX_PATH:PATH=$(Resolve-Path -Path "${ProjectRoot}/../obs-build-dependencies/${DepsPath}")"
"-DCMAKE_TOOLCHAIN_FILE=$(Resolve-Path -Path "${ProjectRoot}/build_${script:Target}/build/generators/conan_toolchain.cmake")"
"-DQT_VERSION=${script:QtVersion}"
)

Expand Down
4 changes: 3 additions & 1 deletion .github/scripts/utils.zsh/setup_linux
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if (( ! (${skips[(Ie)all]} + ${skips[(Ie)deps]}) )) {
libx11-xcb-dev \
libgles2-mesa-dev \
libwayland-dev \
libpulse-dev
libpulse-dev \
libwebsocketpp-dev \
libasio-dev

local -a _qt_packages=()

Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ jobs:
fetch-depth: 0
submodules: recursive

- name: Install Conan
uses: turtlebrowser/get-conan@main
with:
version: 2.0.14

- name: Conan default profile
run: conan profile detect

- name: Setup Environment
id: setup
working-directory: ${{ github.workspace }}/plugin
Expand Down Expand Up @@ -201,6 +209,14 @@ jobs:
fetch-depth: 0
submodules: recursive

- name: Install Conan
uses: turtlebrowser/get-conan@main
with:
version: 2.0.14

- name: Conan default profile
run: conan profile detect

- name: Setup Environment
working-directory: ${{ github.workspace }}/plugin
id: setup
Expand Down Expand Up @@ -279,6 +295,14 @@ jobs:
fetch-depth: 0
submodules: recursive

- name: Install Conan
uses: turtlebrowser/get-conan@main
with:
version: 2.0.14

- name: Conan default profile
run: conan profile detect

- name: Setup Environment
working-directory: ${{ github.workspace }}/plugin
id: setup
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
# ignore generated files
*.generated.*
**/.Brewfile.lock.json

CMakeUserPresets.json
build/generated/
29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16...3.21)

# Change obs-plugintemplate to your plugin's name in a machine-readable format (e.g.:
# obs-myawesomeplugin) and set
project(obs-auto-subtitle VERSION 1.0.0)
project(obs-auto-subtitle VERSION 0.6.0)
add_library(${CMAKE_PROJECT_NAME} MODULE)

# Replace `Your Name Here` with the name (yours or your organization's) you want to see as the
Expand All @@ -21,6 +21,7 @@ set(LINUX_MAINTAINER_EMAIL "xm1994@gmail.com")
set(obs-auto-subtitle_SOURCES
src/obs-auto-subtitle.cpp
src/obs-autosub-filter.cpp
src/util/QWebsocketpp/QWebsocketpp.cpp
src/builder/ASR/AliNLSBuilder.cpp
src/builder/ASR/HwCloudRASRBuilder.cpp
src/builder/ASR/XFRtASRBuilder.cpp
Expand Down Expand Up @@ -61,7 +62,28 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api)
# Uncomment those lines if you want to use Qt in your plugin

find_qt(COMPONENTS Widgets Core Network WebSockets)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt::Core Qt::Widgets Qt::Network Qt::WebSockets)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")

# Find WebSocket++
find_package(Websocketpp REQUIRED)

# Find Asio
find_package(Asio REQUIRED)

# Find OpenSSL
#set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
Qt::Core
Qt::Widgets
Qt::Network
OpenSSL::Crypto
OpenSSL::SSL
CURL::libcurl)

set_target_properties(
${CMAKE_PROJECT_NAME}
PROPERTIES AUTOMOC ON
Expand All @@ -76,10 +98,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-macros.generated.h)

# --- Platform-independent build settings ---

target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/util/QWebsocketpp)

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs)

target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE ASIO_STANDALONE)
# --- End of section ---

# --- Windows-specific build settings and tasks ---
Expand Down
94 changes: 94 additions & 0 deletions cmake/Modules/FindAsio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#[=======================================================================[.rst
FindAsio
----------

FindModule for Asio and the associated library

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 2.0

This module defines the :prop_tgt:`IMPORTED` target ``Asio::Asio``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``Asio_FOUND``
True, if the library was found.
``Asio_VERSION``
Detected version of found Asio library.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``Asio_INCLUDE_DIR``
Directory containing ``asio.hpp``.

#]=======================================================================]

# cmake-format: off
# cmake-lint: disable=C0103
# cmake-lint: disable=C0301
# cmake-format: on

include(FindPackageHandleStandardArgs)

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(PC_Asio QUIET asio)
endif()

find_path(
Asio_INCLUDE_DIR
NAMES asio.hpp
HINTS ${PC_Asio_INCLUDE_DIRS}
PATHS /usr/include /usr/local/include
DOC "Asio include directory")

if(PC_Asio_VERSION VERSION_GREATER 0)
set(Asio_VERSION ${PC_Asio_VERSION})
elseif(EXISTS "${Asio_INCLUDE_DIR}/asio/version.hpp")
file(STRINGS "${Asio_INCLUDE_DIR}/asio/version.hpp" _version_string
REGEX "#define[ \t]+ASIO_VERSION[ \t]+[0-9]+[ \t]+\/\/[ \t][0-9]+\.[0-9]+\.[0-9]+")

string(REGEX REPLACE "#define[ \t]+ASIO_VERSION[ \t]+[0-9]+[ \t]+\/\/[ \t]([0-9]+\.[0-9]+\.[0-9]+)" "\\1"
Asio_VERSION "${_version_string}")
else()
if(NOT Asio_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find Asio version.")
endif()
set(Asio_VERSION 0.0.0)
endif()

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
set(Asio_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
set(Asio_ERROR_REASON "Ensure Asio library is available in local include paths.")
endif()

find_package_handle_standard_args(
Asio
REQUIRED_VARS Asio_INCLUDE_DIR
VERSION_VAR Asio_VERSION REASON_FAILURE_MESSAGE "${Asio_ERROR_REASON}")
mark_as_advanced(Asio_INCLUDE_DIR)
unset(Asio_ERROR_REASON)

if(Asio_FOUND)
if(NOT TARGET Asio::Asio)
add_library(Asio::Asio INTERFACE IMPORTED)
set_target_properties(Asio::Asio PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Asio_INCLUDE_DIR}")
endif()
endif()

include(FeatureSummary)
set_package_properties(
Asio PROPERTIES
URL "http://think-async.com/Asio"
DESCRIPTION
"Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach."
)
91 changes: 91 additions & 0 deletions cmake/Modules/FindWebsocketpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#[=======================================================================[.rst
FindWebsocketpp
----------

FindModule for WebSocket++ and the associated library

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 2.0

This module defines the :prop_tgt:`IMPORTED` target ``Websocketpp::Websocketpp``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``Websocketpp_FOUND``
True, if the library was found.
``Websocketpp_VERSION``
Detected version of found Websocketpp library.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``Websocketpp_INCLUDE_DIR``
Directory containing ``websocketpp/client.hpp``.

#]=======================================================================]

# cmake-format: off
# cmake-lint: disable=C0103
# cmake-lint: disable=C0301
# cmake-format: on

include(FindPackageHandleStandardArgs)

find_path(
Websocketpp_INCLUDE_DIR
NAMES websocketpp/client.hpp
PATHS /usr/include /usr/local/include
DOC "WebSocket++ include directory")

if(EXISTS "${Websocketpp_INCLUDE_DIR}/websocketpp/version.hpp")
file(STRINGS "${Websocketpp_INCLUDE_DIR}/websocketpp/version.hpp" _version_string
REGEX "^.*(major|minor|patch)_version[ \t]+=[ \t]+[0-9]+")

string(REGEX REPLACE ".*major_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
string(REGEX REPLACE ".*minor_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
string(REGEX REPLACE ".*patch_version[ \t]+=[ \t]+([0-9]+).*" "\\1" _version_patch "${_version_string}")

set(Websocketpp_VERSION "${_version_major}.${_version_minor}.${_version_patch}")
unset(_version_major)
unset(_version_minor)
unset(_version_patch)
else()
if(NOT Websocketpp_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find WebSocket++ version.")
endif()
set(Websocketpp_VERSION 0.0.0)
endif()

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
set(Websocketpp_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
set(Websocketpp_ERROR_REASON "Ensure WebSocket++ library is available in local include paths.")
endif()

find_package_handle_standard_args(
Websocketpp
REQUIRED_VARS Websocketpp_INCLUDE_DIR
VERSION_VAR Websocketpp_VERSION REASON_FAILURE_MESSAGE "${Websocketpp_ERROR_REASON}")
mark_as_advanced(Websocketpp_INCLUDE_DIR)
unset(Websocketpp_ERROR_REASON)

if(Websocketpp_FOUND)
if(NOT TARGET Websocketpp::Websocketpp)
add_library(Websocketpp::Websocketpp INTERFACE IMPORTED)
set_target_properties(Websocketpp::Websocketpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${Websocketpp_INCLUDE_DIR}")
endif()
endif()

include(FeatureSummary)
set_package_properties(
Websocketpp PROPERTIES
URL "https://www.zaphoyd.com/websocketpp/"
DESCRIPTION "WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket Protocol.")
1 change: 0 additions & 1 deletion cmake/ObsPluginHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ else()
${CMAKE_PROJECT_NAME}
PRIVATE
"LINKER:/OPT:REF"
"LINKER:/WX"
"$<$<NOT:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>>:LINKER\:/SAFESEH\:NO>"
"$<$<CONFIG:DEBUG>:LINKER\:/INCREMENTAL\:NO>"
"$<$<CONFIG:RELWITHDEBINFO>:LINKER\:/INCREMENTAL\:NO;/OPT\:ICF>")
Expand Down
8 changes: 8 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[requires]
libcurl/8.4.0
openssl/3.1.4
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
19 changes: 19 additions & 0 deletions src/util/QWebsocketpp/QWebsocketpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
QWebsocketpp
Copyright (C) 2019-2023 Yibai Zhang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; If not, see <https://www.gnu.org/licenses/>
*/

#include "QWebsocketpp.h"
Loading

0 comments on commit 3209c94

Please sign in to comment.