├── notebooks ├── Big.Buck.Bunny.mp3 ├── Big.Buck.Bunny.mp4 ├── CameraStream.ipynb ├── AudioStream.ipynb ├── Chat.ipynb ├── VideoStream.ipynb ├── VideoRecorder.ipynb ├── AudioRecorder.ipynb ├── ImageRecorder.ipynb └── CameraStream_xtensor_fftw.ipynb ├── src ├── xpeer.cpp ├── xroom.cpp ├── xrecorder.cpp ├── xroom_mqtt.cpp ├── xroom_local.cpp ├── xaudio_stream.cpp ├── xcamera_stream.cpp ├── ximage_stream.cpp ├── xmedia_stream.cpp ├── xvideo_stream.cpp ├── xwidget_stream.cpp ├── xaudio_recorder.cpp ├── ximage_recorder.cpp └── xvideo_recorder.cpp ├── environment.yml ├── test ├── main.cpp ├── test_fake.cpp ├── copyGTest.cmake.in ├── downloadGTest.cmake.in └── CMakeLists.txt ├── .gitignore ├── include └── xwebrtc │ ├── xwebrtc_config_cling.hpp.in │ ├── xchat.hpp │ ├── xwebrtc_config.hpp │ ├── xroom_local.hpp │ ├── xmedia_stream.hpp │ ├── xroom_mqtt.hpp │ ├── xcamera_stream.hpp │ ├── ximage_stream.hpp │ ├── xaudio_stream.hpp │ ├── xvideo_stream.hpp │ ├── xwidget_stream.hpp │ ├── xvideo_recorder.hpp │ ├── xaudio_recorder.hpp │ ├── xpeer.hpp │ ├── xroom.hpp │ ├── ximage_recorder.hpp │ └── xrecorder.hpp ├── xwebrtcConfig.cmake.in ├── .travis.yml ├── LICENSE ├── .appveyor.yml ├── README.md ├── docs └── source │ └── binder-logo.svg └── CMakeLists.txt /notebooks/Big.Buck.Bunny.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantStack/xwebrtc/HEAD/notebooks/Big.Buck.Bunny.mp3 -------------------------------------------------------------------------------- /notebooks/Big.Buck.Bunny.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantStack/xwebrtc/HEAD/notebooks/Big.Buck.Bunny.mp4 -------------------------------------------------------------------------------- /src/xpeer.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xpeer.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xroom.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xroom.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xrecorder.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xrecorder.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xroom_mqtt.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xroom_mqtt.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xroom_local.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xroom_local.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xaudio_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xaudio_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xcamera_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xcamera_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/ximage_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/ximage_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xmedia_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xmedia_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xvideo_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xvideo_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xwidget_stream.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xwidget_stream.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xaudio_recorder.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xaudio_recorder.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/ximage_recorder.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/ximage_recorder.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /src/xvideo_recorder.cpp: -------------------------------------------------------------------------------- 1 | #include "xwebrtc/xvideo_recorder.hpp" 2 | 3 | template class XWEBRTC_API xw::xmaterialize; 4 | template class XWEBRTC_API xw::xtransport>; 5 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: xwebrtc 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | # Widgets 6 | - xwebrtc=0.6.0 7 | - xwidgets=0.23.0 8 | - widgetsnbextension >=3.0.0 9 | - ipywebrtc=0.4.1 10 | # Xtensor 11 | - xtensor-io=0.9.0 12 | - xtensor-fftw=0.2.6 13 | # C++ kernel 14 | - xeus-cling=0.10.0 15 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille and Sylvain Corlay * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include "gtest/gtest.h" 10 | 11 | int main(int argc, char* argv[]) 12 | { 13 | ::testing::InitGoogleTest(&argc, argv); 14 | return RUN_ALL_TESTS(); 15 | } 16 | -------------------------------------------------------------------------------- /test/test_fake.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille and Sylvain Corlay * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include "gtest/gtest.h" 10 | 11 | namespace xwebrtc 12 | { 13 | TEST(xmap, map) 14 | { 15 | int res = 64; 16 | EXPECT_EQ(64, res); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Vim tmp files 31 | *.swp 32 | 33 | # Build directory 34 | build/ 35 | 36 | # Test build artefacts 37 | test/test_xwidgets 38 | test/CMakeCache.txt 39 | test/Makefile 40 | test/CMakeFiles/ 41 | test/cmake_install.cmake 42 | 43 | # Documentation build artefacts 44 | docs/CMakeCache.txt 45 | docs/xml/ 46 | docs/build/ 47 | 48 | # Jupyter artefacts 49 | .ipynb_checkpoints/ 50 | 51 | # Generated files 52 | *.pc 53 | include/xwebrtc/xwebrtc_config_cling.hpp 54 | -------------------------------------------------------------------------------- /notebooks/CameraStream.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwebrtc/xcamera_stream.hpp\"" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "auto camera2 = xwebrtc::camera_facing_user(false).finalize();\n", 19 | "camera2" 20 | ] 21 | } 22 | ], 23 | "metadata": { 24 | "kernelspec": { 25 | "display_name": "C++14", 26 | "language": "C++14", 27 | "name": "xcpp14" 28 | }, 29 | "language_info": { 30 | "codemirror_mode": "text/x-c++src", 31 | "file_extension": ".cpp", 32 | "mimetype": "text/x-c++src", 33 | "name": "c++", 34 | "version": "14" 35 | } 36 | }, 37 | "nbformat": 4, 38 | "nbformat_minor": 2 39 | } 40 | -------------------------------------------------------------------------------- /include/xwebrtc/xwebrtc_config_cling.hpp.in: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_CONFIG_CLING_HPP 11 | #define XWEBRTC_CONFIG_CLING_HPP 12 | 13 | #pragma cling add_library_path(@XWEBRTC_INSTALL_LIBRARY_DIR@) 14 | #pragma cling load("libxwebrtc") 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /test/copyGTest.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 2.8.2) 10 | 11 | project(googletest-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(googletest 15 | URL "${GTEST_SRC_DIR}" 16 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 17 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 18 | CONFIGURE_COMMAND "" 19 | BUILD_COMMAND "" 20 | INSTALL_COMMAND "" 21 | TEST_COMMAND "" 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /notebooks/AudioStream.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwebrtc/xaudio_stream.hpp\"" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "auto audio = xwebrtc::audio_stream_from_file(\"Big.Buck.Bunny.mp3\").finalize();\n", 19 | "audio" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "audio" 29 | ] 30 | } 31 | ], 32 | "metadata": { 33 | "kernelspec": { 34 | "display_name": "C++14", 35 | "language": "C++14", 36 | "name": "xcpp14" 37 | }, 38 | "language_info": { 39 | "codemirror_mode": "text/x-c++src", 40 | "file_extension": ".cpp", 41 | "mimetype": "text/x-c++src", 42 | "name": "c++", 43 | "version": "14" 44 | } 45 | }, 46 | "nbformat": 4, 47 | "nbformat_minor": 2 48 | } 49 | -------------------------------------------------------------------------------- /notebooks/Chat.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwebrtc/xchat.hpp\"\n", 10 | "#include \"xwebrtc/xcamera_stream.hpp\"" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "auto camera = xwebrtc::camera_facing_user(false).finalize();" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "auto chat = xwebrtc::chat(\"quantstack\", camera);" 29 | ] 30 | } 31 | ], 32 | "metadata": { 33 | "kernelspec": { 34 | "display_name": "C++14", 35 | "language": "C++14", 36 | "name": "xcpp14" 37 | }, 38 | "language_info": { 39 | "codemirror_mode": "text/x-c++src", 40 | "file_extension": ".cpp", 41 | "mimetype": "text/x-c++src", 42 | "name": "c++", 43 | "version": "14" 44 | } 45 | }, 46 | "nbformat": 4, 47 | "nbformat_minor": 2 48 | } 49 | -------------------------------------------------------------------------------- /test/downloadGTest.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 2.8.2) 10 | 11 | project(googletest-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(googletest 15 | GIT_REPOSITORY https://github.com/google/googletest.git 16 | GIT_TAG release-1.10.0 17 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 18 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 19 | CONFIGURE_COMMAND "" 20 | BUILD_COMMAND "" 21 | INSTALL_COMMAND "" 22 | TEST_COMMAND "" 23 | ) 24 | 25 | -------------------------------------------------------------------------------- /xwebrtcConfig.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, Wolf Vollprecht and # 3 | # Martin Renou # 4 | # # 5 | # Distributed under the terms of the BSD 3-Clause License. # 6 | # # 7 | # The full license is in the file LICENSE, distributed with this software. # 8 | ############################################################################ 9 | 10 | # xwidgets cmake module 11 | # This module sets the following variables in your project:: 12 | # 13 | # xwebrtc_FOUND - true if xplot found on the system 14 | # xwebrtc_INCLUDE_DIRS - the directory containing xwebrtc headers 15 | # xwebrtc_LIBRARY - empty 16 | 17 | @PACKAGE_INIT@ 18 | 19 | set(PN xwebrtc) 20 | set_and_check(${PN}_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@") 21 | set(${PN}_LIBRARY "") 22 | check_required_components(${PN}) 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | env: 3 | global: 4 | - MINCONDA_VERSION="latest" 5 | - MINCONDA_LINUX="Linux-x86_64" 6 | - MINCONDA_OSX="MacOSX-x86_64" 7 | install: 8 | # Define the version of miniconda to download 9 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then 10 | MINCONDA_OS=$MINCONDA_LINUX; 11 | elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then 12 | MINCONDA_OS=$MINCONDA_OSX; 13 | fi 14 | - wget "http://repo.continuum.io/miniconda/Miniconda3-$MINCONDA_VERSION-$MINCONDA_OS.sh" -O miniconda.sh; 15 | - bash miniconda.sh -b -p $HOME/miniconda 16 | - export PATH="$HOME/miniconda/bin:$PATH" 17 | - hash -r 18 | - conda config --set always_yes yes --set changeps1 no 19 | - conda update -q conda 20 | # Install host dependencies 21 | - conda install cppzmq xproperty xwidgets=0.24.1 -c conda-forge 22 | # Install build dependencies 23 | - conda install gtest cmake -c conda-forge 24 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then 25 | conda install gxx_linux-64 -c conda-forge; 26 | fi 27 | # Activate root environment 28 | - source activate root 29 | # Testing 30 | - mkdir build 31 | - cd build 32 | - cmake -D CMAKE_INSTALL_PREFIX=$HOME/miniconda/ -D DOWNLOAD_GTEST=ON -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX .. 33 | - make -j2 install 34 | - make -j2 test_xwebrtc 35 | - cd test 36 | script: 37 | - ./test_xwebrtc 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Sylvain Corlay, Johan Mabille, Wolf Vollprecht and Martin Renou 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /.appveyor.yml: -------------------------------------------------------------------------------- 1 | build: false 2 | 3 | platform: 4 | - x64 5 | 6 | image: 7 | - Visual Studio 2017 8 | - Visual Studio 2015 9 | 10 | matrix: 11 | allow_failures: 12 | - image: Visual Studio 2017 13 | 14 | environment: 15 | matrix: 16 | - MINICONDA: C:\xwidgets-conda 17 | 18 | init: 19 | - "ECHO %MINICONDA%" 20 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" 21 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCARGUMENT=%PLATFORM% 22 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" if "%PLATFORM%" == "x64" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" 23 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" if "%PLATFORM%" == "x86" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat" 24 | - echo "%VCVARPATH% %VCARGUMENT%" 25 | - "%VCVARPATH% %VCARGUMENT%" 26 | - ps: if($env:Platform -eq "x64"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe' C:\Miniconda.exe; echo "Done"} 27 | - ps: if($env:Platform -eq "x86"){Start-FileDownload 'http://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe' C:\Miniconda.exe; echo "Done"} 28 | - cmd: C:\Miniconda.exe /S /D=C:\xwidgets-conda 29 | - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%" 30 | 31 | install: 32 | - conda config --set always_yes yes --set changeps1 no 33 | - conda update -q conda 34 | - conda info -a 35 | # Install host dependencies 36 | - conda install cppzmq xproperty xwidgets=0.24.1 -c conda-forge 37 | # Install build dependencies 38 | - conda install cmake -c conda-forge 39 | - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DDOWNLOAD_GTEST=ON . 40 | - nmake install 41 | - nmake test_xwebrtc 42 | - cd test 43 | 44 | build_script: 45 | - .\test_xwebrtc 46 | -------------------------------------------------------------------------------- /include/xwebrtc/xchat.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_CHAT_HPP 11 | #define XWEBRTC_CHAT_HPP 12 | 13 | #include 14 | 15 | #include "xcpp/xdisplay.hpp" 16 | 17 | #include "xwidgets/xbox.hpp" 18 | #include "xwidgets/xlink.hpp" 19 | 20 | #include "xwebrtc_config.hpp" 21 | #include "xroom_mqtt.hpp" 22 | #include "xmedia_stream.hpp" 23 | #include "xcamera_stream.hpp" 24 | 25 | namespace xwebrtc 26 | { 27 | namespace detail 28 | { 29 | template 30 | struct xchat_room 31 | { 32 | public: 33 | 34 | template 35 | inline xchat_room(const std::string& room_name, T&& input_stream) 36 | : room_name(room_name), stream(std::forward(input_stream)), 37 | room(room_mqtt::initialize().stream(std::forward(input_stream)).room(room_name).finalize()), 38 | box(xw::hbox()), 39 | link(xw::link(room, "streams", box, "children")) 40 | { 41 | } 42 | 43 | const std::string& room_name; 44 | CT stream; 45 | room_mqtt room; 46 | xw::hbox box; 47 | xw::link link; 48 | }; 49 | } 50 | 51 | template 52 | inline auto chat(const std::string& room_name, T&& stream) 53 | { 54 | auto room = detail::xchat_room(room_name, std::forward(stream)); 55 | xcpp::display(room.box); 56 | return room; 57 | } 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/xwebrtc/xwebrtc_config.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_CONFIG_HPP 11 | #define XWEBRTC_CONFIG_HPP 12 | 13 | // Visual C++ declspec macros 14 | #ifdef _WIN32 15 | #ifdef XWEBRTC_EXPORTS 16 | #define XWEBRTC_API __declspec(dllexport) 17 | #else 18 | #define XWEBRTC_API __declspec(dllimport) 19 | #endif 20 | #else 21 | #define XWEBRTC_API 22 | #endif 23 | 24 | // Project version 25 | #define XWEBRTC_VERSION_MAJOR 0 26 | #define XWEBRTC_VERSION_MINOR 6 27 | #define XWEBRTC_VERSION_PATCH 1 28 | 29 | // Binary version 30 | #define XWEBRTC_BINARY_CURRENT 1 31 | #define XWEBRTC_BINARY_REVISION 0 32 | #define XWEBRTC_BINARY_AGE 1 33 | 34 | // Semver requirement for jupyter-webrtc 35 | #define XJUPYTER_WEBRTC_VERSION_MAJOR 0 36 | #define XJUPYTER_WEBRTC_VERSION_MINOR 4 37 | #define XJUPYTER_WEBRTC_VERSION_PATCH 1 38 | 39 | // Composing the version strings from major, minor and patch 40 | #define XWEBRTC_CONCATENATE(A, B) XWEBRTC_CONCATENATE_IMPL(A, B) 41 | #define XWEBRTC_CONCATENATE_IMPL(A, B) A##B 42 | #define XWEBRTC_STRINGIFY(a) XWEBRTC_STRINGIFY_IMPL(a) 43 | #define XWEBRTC_STRINGIFY_IMPL(a) #a 44 | 45 | #define XJUPYTER_WEBRTC_VERSION XWEBRTC_STRINGIFY(XWEBRTC_CONCATENATE(XJUPYTER_WEBRTC_VERSION_MAJOR, \ 46 | XWEBRTC_CONCATENATE(.,XWEBRTC_CONCATENATE(XJUPYTER_WEBRTC_VERSION_MINOR, \ 47 | XWEBRTC_CONCATENATE(.,XJUPYTER_WEBRTC_VERSION_PATCH))))) 48 | 49 | inline std::string jupyter_webrtc_semver() 50 | { 51 | return std::string("^") + XJUPYTER_WEBRTC_VERSION; 52 | } 53 | 54 | #ifdef __CLING__ 55 | #include "xwebrtc_config_cling.hpp" 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /notebooks/VideoStream.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/xvideo.hpp\"\n", 10 | "#include \"xwebrtc/xvideo_stream.hpp\"" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "# Create a video_stream directly from a file" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "auto video_stream1 = xwebrtc::video_stream_from_file(\"Big.Buck.Bunny.mp4\")\n", 27 | " .finalize();" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "video_stream1" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "video_stream1" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "video_stream1.playing = false;" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "# Create a video_stream from a video widget" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "auto video = xw::video_from_file(\"Big.Buck.Bunny.mp4\").finalize();" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "auto video_stream2 = xwebrtc::video_stream(video);\n", 80 | "video_stream2" 81 | ] 82 | } 83 | ], 84 | "metadata": { 85 | "kernelspec": { 86 | "display_name": "C++14", 87 | "language": "C++14", 88 | "name": "xcpp14" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": "text/x-c++src", 92 | "file_extension": ".cpp", 93 | "mimetype": "text/x-c++src", 94 | "name": "c++", 95 | "version": "14" 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 2 100 | } 101 | -------------------------------------------------------------------------------- /notebooks/VideoRecorder.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/xvideo.hpp\"\n", 10 | "\n", 11 | "#include \"xwebrtc/xvideo_stream.hpp\"\n", 12 | "#include \"xwebrtc/xcamera_stream.hpp\"\n", 13 | "#include \"xwebrtc/xvideo_recorder.hpp\"" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "auto input = xwebrtc::video_stream_from_file(\"Big.Buck.Bunny.mp4\");" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "input" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "auto video_recorder = xwebrtc::video_recorder(input);\n", 41 | "video_recorder" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "video_recorder.video()" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "auto camera_input = xwebrtc::camera_facing_user(false);\n", 60 | "camera_input" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "auto camera_recorder = xwebrtc::video_recorder(camera_input);\n", 70 | "camera_recorder" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "camera_recorder.save();" 80 | ] 81 | } 82 | ], 83 | "metadata": { 84 | "kernelspec": { 85 | "display_name": "C++14", 86 | "language": "C++14", 87 | "name": "xcpp14" 88 | }, 89 | "language_info": { 90 | "codemirror_mode": "text/x-c++src", 91 | "file_extension": ".cpp", 92 | "mimetype": "text/x-c++src", 93 | "name": "c++", 94 | "version": "14" 95 | } 96 | }, 97 | "nbformat": 4, 98 | "nbformat_minor": 2 99 | } 100 | -------------------------------------------------------------------------------- /notebooks/AudioRecorder.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/xaudio.hpp\"\n", 10 | "\n", 11 | "#include \"xwebrtc/xvideo_stream.hpp\"\n", 12 | "#include \"xwebrtc/xcamera_stream.hpp\"\n", 13 | "#include \"xwebrtc/xaudio_recorder.hpp\"" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "auto input = xwebrtc::video_stream_from_file(\"Big.Buck.Bunny.mp4\")\n", 23 | " .finalize();" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "input" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "auto audio_recorder = xwebrtc::audio_recorder(input);\n", 42 | "audio_recorder" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "input.playing = false;" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "audio_recorder.audio()" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "auto camera = xwebrtc::camera_facing_user().finalize();\n", 70 | "camera" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "auto camera_audio_recorder = xwebrtc::audio_recorder(camera);\n", 80 | "camera_audio_recorder" 81 | ] 82 | } 83 | ], 84 | "metadata": { 85 | "kernelspec": { 86 | "display_name": "C++14", 87 | "language": "C++14", 88 | "name": "xcpp14" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": "text/x-c++src", 92 | "file_extension": ".cpp", 93 | "mimetype": "text/x-c++src", 94 | "name": "c++", 95 | "version": "14" 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 2 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xwebrtc 2 | 3 | [![Travis](https://travis-ci.org/QuantStack/xwebrtc.svg?branch=master)](https://travis-ci.org/QuantStack/xwebrtc) 4 | [![Appveyor](https://ci.appveyor.com/api/projects/status/5vjulggfcaknmxsh?svg=true)](https://ci.appveyor.com/project/QuantStack/xwebrtc/branch/master) 5 | [![Binder](https://img.shields.io/badge/launch-binder-brightgreen.svg)](https://mybinder.org/v2/gh/QuantStack/xwebrtc/stable?filepath=notebooks) 6 | 7 | C++ backend for WebRTC in the Jupyter notebook/lab 8 | 9 | **xwebrtc is an early developer preview, and is not suitable for general usage yet. Features and implementation are subject to change.** 10 | 11 | ## Trying it online 12 | 13 | To try out xwebrtc interactively in your web browser, just click on the binder link: 14 | 15 | [![Binder](docs/source/binder-logo.svg)](https://mybinder.org/v2/gh/QuantStack/xwebrtc/stable?filepath=notebooks) 16 | 17 | ## Installation 18 | 19 | We provide a package for the mamba (or conda) package manager. 20 | 21 | - Installing `xwebrtc` and the C++ kernel 22 | 23 | ```bash 24 | mamba install xeus-cling xwebrtc -c conda-forge 25 | ``` 26 | 27 | Then, the front-end extension must be installed for either the classic notebook or JupyterLab. 28 | 29 | - Installing the extensions for the classic notebook 30 | 31 | ``` 32 | mamba install widgetsnbextension -c conda-forge 33 | mamba install ipywebrtc -c conda-forge 34 | ``` 35 | 36 | ## Installation from sources 37 | 38 | Or you can directly install it from the sources if you have all the dependencies already installed: 39 | 40 | ```bash 41 | cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix 42 | make install 43 | ``` 44 | 45 | ## Dependencies 46 | 47 | All the dependencies of xleaflet are available for the mamba (or conda) package manager. 48 | 49 | | `xwebrtc` | `xwidgets` | `xeus` | 50 | |------------|---------------|-----------------| 51 | | master | >=0.23.0,<25 | >=0.24.1,<26 | 52 | | 0.6.1 | >=0.23.0,<25 | >=0.24.1,<26 | 53 | | 0.6.0 | ~0.23.0 | ~0.24.1 | 54 | | 0.5.0 | ~0.20.0 | ~0.23.3 | 55 | | 0.4.1 | ~0.16.1 | ~0.18.1 | 56 | | 0.4.0 | ~0.16.0 | ~0.18.1 | 57 | | 0.3.0 | ~0.15.0 | ~0.17.0 | 58 | | 0.2.0 | ~0.14.0 | ~0.15.0 | 59 | 60 | ## License 61 | 62 | We use a shared copyright model that enables all contributors to maintain the 63 | copyright on their contributions. 64 | 65 | This software is licensed under the BSD-3-Clause license. See the [LICENSE](LICENSE) file for details. 66 | -------------------------------------------------------------------------------- /include/xwebrtc/xroom_local.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_ROOM_LOCAL_HPP 11 | #define XWEBRTC_ROOM_LOCAL_HPP 12 | 13 | #include "nlohmann/json.hpp" 14 | 15 | #include "xtl/xoptional.hpp" 16 | 17 | #include "xwidgets/xmaterialize.hpp" 18 | #include "xwidgets/xholder.hpp" 19 | 20 | #include "xwebrtc_config.hpp" 21 | #include "xroom.hpp" 22 | 23 | namespace nl = nlohmann; 24 | 25 | namespace xwebrtc 26 | { 27 | /*************************** 28 | * xroom_local declaration * 29 | ***************************/ 30 | 31 | template 32 | class xroom_local : public xroom 33 | { 34 | public: 35 | 36 | using base_type = xroom; 37 | using derived_type = D; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | protected: 43 | 44 | xroom_local(); 45 | using base_type::base_type; 46 | 47 | private: 48 | 49 | void set_defaults(); 50 | }; 51 | 52 | using room_local = xw::xmaterialize; 53 | 54 | /****************************** 55 | * xroom_local implementation * 56 | ******************************/ 57 | 58 | template 59 | inline void xroom_local::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 60 | { 61 | base_type::serialize_state(state, buffers); 62 | } 63 | 64 | template 65 | inline void xroom_local::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 66 | { 67 | base_type::apply_patch(patch, buffers); 68 | } 69 | 70 | template 71 | inline xroom_local::xroom_local() 72 | : base_type() 73 | { 74 | set_defaults(); 75 | } 76 | 77 | template 78 | inline void xroom_local::set_defaults() 79 | { 80 | this->_model_name() = "WebRTCRoomLocalModel"; 81 | // this->_view_name() = "WebRTCRoomLocalView"; 82 | } 83 | } 84 | 85 | /********************* 86 | * precompiled types * 87 | *********************/ 88 | 89 | extern template class xw::xmaterialize; 90 | extern template class xw::xtransport>; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /docs/source/binder-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 14 | 16 | 19 | 23 | 26 | 27 | 28 | 29 | 30 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /notebooks/ImageRecorder.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/ximage.hpp\"\n", 10 | "\n", 11 | "#include \"xwebrtc/xvideo_stream.hpp\"\n", 12 | "#include \"xwebrtc/xcamera_stream.hpp\"\n", 13 | "#include \"xwebrtc/ximage_recorder.hpp\"" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "auto video = xwebrtc::video_stream_from_file(\"Big.Buck.Bunny.mp4\")\n", 23 | " .finalize();" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "video" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "auto image_recorder1 = xwebrtc::image_recorder(video);" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "image_recorder1" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "image_recorder1.image()" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "image_recorder1.autosave() = true;" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "auto image_saved = xw::image_from_file(\"record.png\").finalize();\n", 78 | "image_saved" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "auto camera = xwebrtc::camera_facing_user(false).finalize();\n", 88 | "camera" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "auto image_recorder2 = xwebrtc::image_recorder(camera);\n", 98 | "image_recorder2" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "auto image = image_recorder2.image();\n", 108 | "image" 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "C++14", 115 | "language": "C++14", 116 | "name": "xcpp14" 117 | }, 118 | "language_info": { 119 | "codemirror_mode": "text/x-c++src", 120 | "file_extension": ".cpp", 121 | "mimetype": "text/x-c++src", 122 | "name": "c++", 123 | "version": "14" 124 | } 125 | }, 126 | "nbformat": 4, 127 | "nbformat_minor": 2 128 | } 129 | -------------------------------------------------------------------------------- /include/xwebrtc/xmedia_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_MEDIA_STREAM_HPP 11 | #define XWEBRTC_MEDIA_STREAM_HPP 12 | 13 | #include "nlohmann/json.hpp" 14 | 15 | #include "xwidgets/xmaterialize.hpp" 16 | #include "xwidgets/xwidget.hpp" 17 | 18 | #include "xwebrtc_config.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xwebrtc 23 | { 24 | /***************************** 25 | * xmedia_stream declaration * 26 | *****************************/ 27 | 28 | template 29 | class xmedia_stream : public xw::xwidget 30 | { 31 | public: 32 | 33 | using base_type = xw::xwidget; 34 | using derived_type = D; 35 | 36 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 37 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 38 | 39 | protected: 40 | 41 | xmedia_stream(); 42 | using base_type::base_type; 43 | 44 | private: 45 | 46 | void set_defaults(); 47 | }; 48 | 49 | using media_stream = xw::xmaterialize; 50 | 51 | /******************************** 52 | * xmedia_stream implementation * 53 | ********************************/ 54 | 55 | template 56 | inline void xmedia_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 57 | { 58 | base_type::serialize_state(state, buffers); 59 | } 60 | 61 | template 62 | inline void xmedia_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 63 | { 64 | base_type::apply_patch(patch, buffers); 65 | } 66 | 67 | template 68 | inline xmedia_stream::xmedia_stream() 69 | : base_type() 70 | { 71 | set_defaults(); 72 | } 73 | 74 | template 75 | inline void xmedia_stream::set_defaults() 76 | { 77 | this->_model_module() = "jupyter-webrtc"; 78 | this->_view_module() = "jupyter-webrtc"; 79 | this->_model_name() = "MediaStreamModel"; 80 | this->_view_name() = "MediaStreamView"; 81 | this->_model_module_version() = jupyter_webrtc_semver(); 82 | this->_view_module_version() = jupyter_webrtc_semver(); 83 | } 84 | } 85 | 86 | /********************* 87 | * precompiled types * 88 | *********************/ 89 | 90 | extern template class xw::xmaterialize; 91 | extern template class xw::xtransport>; 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /include/xwebrtc/xroom_mqtt.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_ROOM_MQTT_HPP 11 | #define XWEBRTC_ROOM_MQTT_HPP 12 | 13 | #include 14 | 15 | #include "nlohmann/json.hpp" 16 | 17 | #include "xtl/xoptional.hpp" 18 | 19 | #include "xwidgets/xmaterialize.hpp" 20 | #include "xwidgets/xholder.hpp" 21 | 22 | #include "xwebrtc_config.hpp" 23 | #include "xroom.hpp" 24 | 25 | namespace nl = nlohmann; 26 | 27 | namespace xwebrtc 28 | { 29 | /************************** 30 | * xroom_mqtt declaration * 31 | **************************/ 32 | 33 | template 34 | class xroom_mqtt : public xroom 35 | { 36 | public: 37 | 38 | using base_type = xroom; 39 | using derived_type = D; 40 | 41 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 42 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 43 | 44 | XPROPERTY(std::string, derived_type, server, "wss://iot.eclipse.org:443/ws"); 45 | 46 | protected: 47 | 48 | xroom_mqtt(); 49 | using base_type::base_type; 50 | 51 | private: 52 | 53 | void set_defaults(); 54 | }; 55 | 56 | using room_mqtt = xw::xmaterialize; 57 | 58 | /***************************** 59 | * xroom_mqtt implementation * 60 | *****************************/ 61 | 62 | template 63 | inline void xroom_mqtt::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 64 | { 65 | using xw::xwidgets_serialize; 66 | base_type::serialize_state(state, buffers); 67 | 68 | xwidgets_serialize(server(), state["server"], buffers); 69 | } 70 | 71 | template 72 | inline void xroom_mqtt::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 73 | { 74 | using xw::set_property_from_patch; 75 | base_type::apply_patch(patch, buffers); 76 | 77 | set_property_from_patch(server, patch, buffers); 78 | } 79 | 80 | template 81 | inline xroom_mqtt::xroom_mqtt() 82 | : base_type() 83 | { 84 | set_defaults(); 85 | } 86 | 87 | template 88 | inline void xroom_mqtt::set_defaults() 89 | { 90 | this->_model_name() = "WebRTCRoomMqttModel"; 91 | // this->_view_name() = "WebRTCRoomMqttView"; 92 | } 93 | } 94 | 95 | /********************* 96 | * precompiled types * 97 | *********************/ 98 | 99 | extern template class xw::xmaterialize; 100 | extern template class xw::xtransport>; 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /include/xwebrtc/xcamera_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_CAMERA_STREAM_HPP 11 | #define XWEBRTC_CAMERA_STREAM_HPP 12 | 13 | #include "nlohmann/json.hpp" 14 | 15 | #include "xwidgets/xmaterialize.hpp" 16 | 17 | #include "xwebrtc_config.hpp" 18 | #include "xmedia_stream.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xwebrtc 23 | { 24 | /****************************** 25 | * xcamera_stream declaration * 26 | ******************************/ 27 | 28 | template 29 | class xcamera_stream : public xwebrtc::xmedia_stream 30 | { 31 | public: 32 | 33 | using base_type = xwebrtc::xmedia_stream; 34 | using derived_type = D; 35 | 36 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 37 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 38 | 39 | XPROPERTY(nl::json, derived_type, constraints); 40 | 41 | protected: 42 | 43 | xcamera_stream(); 44 | using base_type::base_type; 45 | 46 | private: 47 | 48 | void set_defaults(); 49 | }; 50 | 51 | using camera_stream = xw::xmaterialize; 52 | 53 | /********************************* 54 | * xcamera_stream implementation * 55 | *********************************/ 56 | 57 | template 58 | inline void xcamera_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 59 | { 60 | using xw::xwidgets_serialize; 61 | base_type::serialize_state(state, buffers); 62 | 63 | xwidgets_serialize(constraints(), state["constraints"], buffers); 64 | } 65 | 66 | template 67 | inline void xcamera_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 68 | { 69 | using xw::set_property_from_patch; 70 | base_type::apply_patch(patch, buffers); 71 | 72 | set_property_from_patch(constraints, patch, buffers); 73 | } 74 | 75 | template 76 | inline xcamera_stream::xcamera_stream() 77 | : base_type() 78 | { 79 | set_defaults(); 80 | 81 | this->constraints() = {{"audio", true}, {"video", true}}; 82 | } 83 | 84 | template 85 | inline void xcamera_stream::set_defaults() 86 | { 87 | this->_model_name() = "CameraStreamModel"; 88 | // this->_view_name() = "CameraStreamView"; 89 | } 90 | 91 | inline camera_stream camera_facing_user(bool audio = true) 92 | { 93 | return camera_stream::initialize().constraints({{"audio", audio}, {"video", {"facingMode", "user"}}}); 94 | } 95 | 96 | inline camera_stream camera_facing_environment(bool audio = true) 97 | { 98 | return camera_stream::initialize().constraints({{"audio", audio}, {"video", {"facingMode", "environment"}}}); 99 | } 100 | } 101 | 102 | /********************* 103 | * precompiled types * 104 | *********************/ 105 | 106 | extern template class xw::xmaterialize; 107 | extern template class xw::xtransport>; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, Wolf Vollprecht and # 3 | # Martin Renou # 4 | # # 5 | # Distributed under the terms of the BSD 3-Clause License. # 6 | # # 7 | # The full license is in the file LICENSE, distributed with this software. # 8 | ############################################################################ 9 | 10 | cmake_minimum_required(VERSION 3.8) 11 | 12 | message(STATUS "Forcing tests build type to Release") 13 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 14 | 15 | if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 16 | project(xwebrtc-test) 17 | 18 | find_package(xwebrtc REQUIRED CONFIG) 19 | set(XWEBRTC_INCLUDE_DIR ${xwebrtc_INCLUDE_DIRS}) 20 | endif () 21 | 22 | # Dependencies 23 | # ============ 24 | 25 | if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) 26 | if(DOWNLOAD_GTEST) 27 | # Download and unpack googletest at configure time 28 | configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt) 29 | else() 30 | # Copy local source of googletest at configure time 31 | configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt) 32 | endif() 33 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 34 | RESULT_VARIABLE result 35 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) 36 | if(result) 37 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") 38 | endif() 39 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 40 | RESULT_VARIABLE result 41 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) 42 | if(result) 43 | message(FATAL_ERROR "Build step for googletest failed: ${result}") 44 | endif() 45 | 46 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 47 | 48 | # Add googletest directly to our build. This defines 49 | # the gtest and gtest_main targets. 50 | add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src 51 | ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) 52 | 53 | set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include") 54 | set(GTEST_BOTH_LIBRARIES gtest_main gtest) 55 | else() 56 | find_package(GTest REQUIRED) 57 | endif() 58 | 59 | find_package(Threads) 60 | 61 | # Source files 62 | # ============ 63 | 64 | include_directories(${XWEBRTC_INCLUDE_DIR}) 65 | include_directories(${GTEST_INCLUDE_DIRS}) 66 | 67 | set(XWEBRTC_TESTS 68 | main.cpp 69 | test_fake.cpp 70 | ) 71 | 72 | # Output 73 | # ====== 74 | 75 | set(CMAKE_SKIP_BUILD_RPATH FALSE) 76 | set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 77 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") 78 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 79 | list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) 80 | if("${isSystemDir}" STREQUAL "-1") 81 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 82 | endif("${isSystemDir}" STREQUAL "-1") 83 | 84 | add_executable(test_xwebrtc ${XWEBRTC_TESTS} ${XWEBRTC_HEADERS}) 85 | if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) 86 | add_dependencies(test_xwebrtc gtest_main) 87 | endif() 88 | 89 | target_compile_features(test_xwebrtc PRIVATE cxx_std_14) 90 | 91 | target_link_libraries(test_xwebrtc 92 | PUBLIC xtl 93 | PUBLIC xeus 94 | PUBLIC xwidgets 95 | PUBLIC xwebrtc 96 | PRIVATE ${GTEST_BOTH_LIBRARIES} 97 | PRIVATE ${CMAKE_THREAD_LIBS_INIT}) 98 | -------------------------------------------------------------------------------- /include/xwebrtc/ximage_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_IMAGE_STREAM_HPP 11 | #define XWEBRTC_IMAGE_STREAM_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/ximage.hpp" 20 | 21 | #include "xwebrtc_config.hpp" 22 | #include "xmedia_stream.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xwebrtc 27 | { 28 | /***************************** 29 | * ximage_stream declaration * 30 | *****************************/ 31 | 32 | template 33 | class ximage_stream : public xmedia_stream 34 | { 35 | public: 36 | 37 | using base_type = xmedia_stream; 38 | using derived_type = D; 39 | 40 | using image_type = xw::xholder; 41 | 42 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 43 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 44 | 45 | XPROPERTY(image_type, derived_type, image); 46 | 47 | protected: 48 | 49 | ximage_stream(); 50 | ximage_stream(xw::xholder image); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | }; 57 | 58 | using image_stream = xw::xmaterialize; 59 | 60 | /******************************** 61 | * ximage_stream implementation * 62 | ********************************/ 63 | 64 | template 65 | inline void ximage_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 66 | { 67 | using xw::xwidgets_serialize; 68 | base_type::serialize_state(state, buffers); 69 | 70 | xwidgets_serialize(image(), state["image"], buffers); 71 | } 72 | 73 | template 74 | inline void ximage_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 75 | { 76 | using xw::set_property_from_patch; 77 | base_type::apply_patch(patch, buffers); 78 | 79 | set_property_from_patch(image, patch, buffers); 80 | } 81 | 82 | template 83 | inline ximage_stream::ximage_stream() 84 | : base_type() 85 | { 86 | set_defaults(); 87 | } 88 | 89 | template 90 | inline ximage_stream::ximage_stream(xw::xholder image) 91 | : base_type() 92 | { 93 | set_defaults(); 94 | 95 | this->image() = image; 96 | } 97 | 98 | template 99 | inline void ximage_stream::set_defaults() 100 | { 101 | this->_model_name() = "ImageStreamModel"; 102 | // this->_view_name() = "ImageStreamView"; 103 | } 104 | 105 | inline image_stream image_stream_from_file(const std::string& filename) 106 | { 107 | auto img = xw::image_from_file(filename).finalize(); 108 | return image_stream::initialize().image(std::move(img)); 109 | } 110 | 111 | inline image_stream image_stream_from_url(const std::string& url) 112 | { 113 | auto img = xw::image_from_url(url).finalize(); 114 | return image_stream::initialize().image(std::move(img)); 115 | } 116 | } 117 | 118 | /********************* 119 | * precompiled types * 120 | *********************/ 121 | 122 | extern template class xw::xmaterialize; 123 | extern template class xw::xtransport>; 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /include/xwebrtc/xaudio_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_AUDIO_STREAM_HPP 11 | #define XWEBRTC_AUDIO_STREAM_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/xaudio.hpp" 20 | 21 | #include "xwebrtc_config.hpp" 22 | #include "xmedia_stream.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xwebrtc 27 | { 28 | /***************************** 29 | * xaudio_stream declaration * 30 | *****************************/ 31 | 32 | template 33 | class xaudio_stream : public xmedia_stream 34 | { 35 | public: 36 | 37 | using base_type = xmedia_stream; 38 | using derived_type = D; 39 | 40 | using audio_type = xw::xholder; 41 | 42 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 43 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 44 | 45 | XPROPERTY(audio_type, derived_type, audio); 46 | XPROPERTY(bool, derived_type, playing, true); 47 | 48 | protected: 49 | 50 | xaudio_stream(); 51 | xaudio_stream(xw::xholder audio); 52 | using base_type::base_type; 53 | 54 | private: 55 | 56 | void set_defaults(); 57 | }; 58 | 59 | using audio_stream = xw::xmaterialize; 60 | 61 | /******************************** 62 | * xaudio_stream implementation * 63 | ********************************/ 64 | 65 | template 66 | inline void xaudio_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 67 | { 68 | using xw::xwidgets_serialize; 69 | base_type::serialize_state(state, buffers); 70 | 71 | xwidgets_serialize(audio(), state["audio"], buffers); 72 | xwidgets_serialize(playing(), state["playing"], buffers); 73 | } 74 | 75 | template 76 | inline void xaudio_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 77 | { 78 | using xw::set_property_from_patch; 79 | base_type::apply_patch(patch, buffers); 80 | 81 | set_property_from_patch(audio, patch, buffers); 82 | set_property_from_patch(playing, patch, buffers); 83 | } 84 | 85 | template 86 | inline xaudio_stream::xaudio_stream() 87 | : base_type() 88 | { 89 | set_defaults(); 90 | } 91 | 92 | template 93 | inline xaudio_stream::xaudio_stream(xw::xholder audio) 94 | : base_type() 95 | { 96 | set_defaults(); 97 | 98 | this->audio() = audio; 99 | } 100 | 101 | template 102 | inline void xaudio_stream::set_defaults() 103 | { 104 | this->_model_name() = "AudioStreamModel"; 105 | this->_view_name() = "AudioStreamView"; 106 | } 107 | 108 | inline audio_stream audio_stream_from_file(const std::string& filename) 109 | { 110 | auto vid = xw::audio_from_file(filename).autoplay(false).controls(false).finalize(); 111 | return audio_stream::initialize().audio(std::move(vid)); 112 | } 113 | 114 | inline audio_stream audio_stream_from_url(const std::string& url) 115 | { 116 | auto vid = xw::audio_from_url(url).autoplay(false).controls(false).finalize(); 117 | return audio_stream::initialize().audio(std::move(vid)); 118 | } 119 | } 120 | 121 | /********************* 122 | * precompiled types * 123 | *********************/ 124 | 125 | extern template class xw::xmaterialize; 126 | extern template class xw::xtransport>; 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/xwebrtc/xvideo_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_VIDEO_STREAM_HPP 11 | #define XWEBRTC_VIDEO_STREAM_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/xvideo.hpp" 20 | 21 | #include "xwebrtc_config.hpp" 22 | #include "xmedia_stream.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xwebrtc 27 | { 28 | /***************************** 29 | * xvideo_stream declaration * 30 | *****************************/ 31 | 32 | template 33 | class xvideo_stream : public xmedia_stream 34 | { 35 | public: 36 | 37 | using base_type = xmedia_stream; 38 | using derived_type = D; 39 | 40 | using video_type = xw::xholder; 41 | 42 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 43 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 44 | 45 | XPROPERTY(video_type, derived_type, video); 46 | XPROPERTY(bool, derived_type, playing, true); 47 | 48 | protected: 49 | 50 | xvideo_stream(); 51 | xvideo_stream(xw::xholder video); 52 | using base_type::base_type; 53 | 54 | private: 55 | 56 | void set_defaults(); 57 | }; 58 | 59 | using video_stream = xw::xmaterialize; 60 | 61 | /******************************** 62 | * xvideo_stream implementation * 63 | ********************************/ 64 | 65 | template 66 | inline void xvideo_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 67 | { 68 | using xw::xwidgets_serialize; 69 | base_type::serialize_state(state, buffers); 70 | 71 | xwidgets_serialize(video(), state["video"], buffers); 72 | xwidgets_serialize(playing(), state["playing"], buffers); 73 | } 74 | 75 | template 76 | inline void xvideo_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 77 | { 78 | using xw::set_property_from_patch; 79 | base_type::apply_patch(patch, buffers); 80 | 81 | set_property_from_patch(video, patch, buffers); 82 | set_property_from_patch(playing, patch, buffers); 83 | } 84 | 85 | template 86 | inline xvideo_stream::xvideo_stream() 87 | : base_type() 88 | { 89 | set_defaults(); 90 | } 91 | 92 | template 93 | inline xvideo_stream::xvideo_stream(xw::xholder video) 94 | : base_type() 95 | { 96 | set_defaults(); 97 | 98 | this->video() = video; 99 | } 100 | 101 | template 102 | inline void xvideo_stream::set_defaults() 103 | { 104 | this->_model_name() = "VideoStreamModel"; 105 | // this->_view_name() = "VideoStreamView"; 106 | } 107 | 108 | inline video_stream video_stream_from_file(const std::string& filename) 109 | { 110 | auto vid = xw::video_from_file(filename).autoplay(false).controls(false).finalize(); 111 | return video_stream::initialize().video(std::move(vid)); 112 | } 113 | 114 | inline video_stream video_stream_from_url(const std::string& url) 115 | { 116 | auto vid = xw::video_from_url(url).autoplay(false).controls(false).finalize(); 117 | return video_stream::initialize().video(std::move(vid)); 118 | } 119 | } 120 | 121 | /********************* 122 | * precompiled types * 123 | *********************/ 124 | 125 | extern template class xw::xmaterialize; 126 | extern template class xw::xtransport>; 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/xwebrtc/xwidget_stream.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_WIDGET_STREAM_HPP 11 | #define XWEBRTC_WIDGET_STREAM_HPP 12 | 13 | #include 14 | 15 | #include "nlohmann/json.hpp" 16 | 17 | #include "xwidgets/xmaterialize.hpp" 18 | 19 | #include "xwebrtc_config.hpp" 20 | #include "xmedia_stream.hpp" 21 | 22 | namespace nl = nlohmann; 23 | 24 | namespace xwebrtc 25 | { 26 | /****************************** 27 | * xwidget_stream declaration * 28 | ******************************/ 29 | 30 | template 31 | class xwidget_stream : public xmedia_stream 32 | { 33 | public: 34 | 35 | using base_type = xmedia_stream; 36 | using derived_type = D; 37 | 38 | using widget_type = xw::xholder; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(widget_type, derived_type, widget); 44 | XPROPERTY(xtl::xoptional, derived_type, max_fps); 45 | 46 | protected: 47 | 48 | xwidget_stream(); 49 | xwidget_stream(xw::xholder widget); 50 | using base_type::base_type; 51 | 52 | private: 53 | 54 | void set_defaults(); 55 | 56 | void setup_properties(); 57 | }; 58 | 59 | using widget_stream = xw::xmaterialize; 60 | 61 | /******************************** 62 | * xwidget_stream implementation * 63 | ********************************/ 64 | 65 | template 66 | inline void xwidget_stream::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 67 | { 68 | using xw::xwidgets_serialize; 69 | base_type::serialize_state(state, buffers); 70 | 71 | xwidgets_serialize(widget(), state["widget"], buffers); 72 | xwidgets_serialize(max_fps(), state["max_fps"], buffers); 73 | } 74 | 75 | template 76 | inline void xwidget_stream::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 77 | { 78 | using xw::set_property_from_patch; 79 | base_type::apply_patch(patch, buffers); 80 | 81 | set_property_from_patch(widget, patch, buffers); 82 | set_property_from_patch(max_fps, patch, buffers); 83 | } 84 | 85 | template 86 | inline xwidget_stream::xwidget_stream() 87 | : base_type() 88 | { 89 | set_defaults(); 90 | 91 | setup_properties(); 92 | } 93 | 94 | template 95 | inline xwidget_stream::xwidget_stream(xw::xholder widget) 96 | : base_type() 97 | { 98 | set_defaults(); 99 | 100 | setup_properties(); 101 | 102 | this->widget() = widget; 103 | } 104 | 105 | template 106 | inline void xwidget_stream::set_defaults() 107 | { 108 | this->_model_name() = "WidgetStreamModel"; 109 | this->_view_name() = "WidgetStreamView"; 110 | } 111 | 112 | template 113 | inline void xwidget_stream::setup_properties() 114 | { 115 | this->template validatemax_fps)::value_type>("max_fps", [](auto& /*owner*/, auto& proposal) { 116 | if (proposal.has_value() && proposal.value() < 0) 117 | { 118 | throw std::runtime_error("max_fps attribute must be a positive integer"); 119 | } 120 | }); 121 | } 122 | } 123 | 124 | /********************* 125 | * precompiled types * 126 | *********************/ 127 | 128 | extern template class xw::xmaterialize; 129 | extern template class xw::xtransport>; 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /include/xwebrtc/xvideo_recorder.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_VIDEO_RECORDER_HPP 11 | #define XWEBRTC_VIDEO_RECORDER_HPP 12 | 13 | #include 14 | 15 | #include "nlohmann/json.hpp" 16 | 17 | #include "xwidgets/xmaterialize.hpp" 18 | #include "xwidgets/xvideo.hpp" 19 | 20 | #include "xrecorder.hpp" 21 | #include "xwebrtc_config.hpp" 22 | 23 | namespace nl = nlohmann; 24 | 25 | namespace xwebrtc 26 | { 27 | /******************************* 28 | * xvideo_recorder declaration * 29 | *******************************/ 30 | 31 | template 32 | class xvideo_recorder : public xrecorder 33 | { 34 | public: 35 | 36 | using base_type = xrecorder; 37 | using derived_type = D; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | XPROPERTY(xw::video, derived_type, video); 43 | 44 | void save(const std::string& filename = "") const; 45 | 46 | protected: 47 | 48 | xvideo_recorder(); 49 | xvideo_recorder(xw::xholder video); 50 | using base_type::base_type; 51 | 52 | private: 53 | 54 | void set_defaults(); 55 | void setup_properties(); 56 | }; 57 | 58 | using video_recorder = xw::xmaterialize; 59 | 60 | /********************************** 61 | * xvideo_recorder implementation * 62 | **********************************/ 63 | 64 | template 65 | inline void xvideo_recorder::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 66 | { 67 | using xw::xwidgets_serialize; 68 | base_type::serialize_state(state, buffers); 69 | 70 | xwidgets_serialize(video(), state["video"], buffers); 71 | } 72 | 73 | template 74 | inline void xvideo_recorder::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 75 | { 76 | using xw::set_property_from_patch; 77 | base_type::apply_patch(patch, buffers); 78 | 79 | set_property_from_patch(video, patch, buffers); 80 | } 81 | 82 | template 83 | inline void xvideo_recorder::save(const std::string& filename) const 84 | { 85 | this->save_file(filename, this->video().value().cbegin(), this->video().value().cend()); 86 | } 87 | 88 | template 89 | inline xvideo_recorder::xvideo_recorder() 90 | : base_type() 91 | { 92 | set_defaults(); 93 | 94 | this->setup_properties(); 95 | } 96 | 97 | template 98 | inline xvideo_recorder::xvideo_recorder(xw::xholder video) 99 | : base_type() 100 | { 101 | this->stream() = video; 102 | 103 | set_defaults(); 104 | 105 | this->setup_properties(); 106 | } 107 | 108 | template 109 | inline void xvideo_recorder::set_defaults() 110 | { 111 | this->_model_name() = "VideoRecorderModel"; 112 | this->_view_name() = "VideoRecorderView"; 113 | 114 | this->video() = xw::video::initialize().format(this->format()).finalize(); 115 | } 116 | 117 | template 118 | inline void xvideo_recorder::setup_properties() 119 | { 120 | this->observe("format", [](auto& owner) { 121 | owner.video().format() = owner.format(); 122 | }); 123 | this->video().observe("value", [this](auto& owner) { 124 | if (this->autosave() && owner.value().size() != 0) 125 | { 126 | this->save_file("", owner.value().cbegin(), owner.value().cend()); 127 | } 128 | }); 129 | } 130 | } 131 | 132 | /********************* 133 | * precompiled types * 134 | *********************/ 135 | 136 | extern template class xw::xmaterialize; 137 | extern template class xw::xtransport>; 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /include/xwebrtc/xaudio_recorder.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_AUDIO_RECORDER_HPP 11 | #define XWEBRTC_AUDIO_RECORDER_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/xaudio.hpp" 20 | 21 | #include "xrecorder.hpp" 22 | #include "xwebrtc_config.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xwebrtc 27 | { 28 | /******************************* 29 | * xaudio_recorder declaration * 30 | *******************************/ 31 | 32 | template 33 | class xaudio_recorder : public xrecorder 34 | { 35 | public: 36 | 37 | using base_type = xrecorder; 38 | using derived_type = D; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(xw::audio, derived_type, audio); 44 | 45 | void save(const std::string& filename = "") const; 46 | 47 | protected: 48 | 49 | xaudio_recorder(); 50 | xaudio_recorder(xw::xholder audio); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | void setup_properties(); 57 | }; 58 | 59 | using audio_recorder = xw::xmaterialize; 60 | 61 | /********************************** 62 | * xaudio_recorder implementation * 63 | **********************************/ 64 | 65 | template 66 | inline void xaudio_recorder::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 67 | { 68 | using xw::xwidgets_serialize; 69 | base_type::serialize_state(state, buffers); 70 | 71 | xwidgets_serialize(audio(), state["audio"], buffers); 72 | } 73 | 74 | template 75 | inline void xaudio_recorder::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 76 | { 77 | using xw::set_property_from_patch; 78 | base_type::apply_patch(patch, buffers); 79 | 80 | set_property_from_patch(audio, patch, buffers); 81 | } 82 | 83 | template 84 | inline void xaudio_recorder::save(const std::string& filename) const 85 | { 86 | this->save_file(filename, this->audio().value().cbegin(), this->audio().value().cend()); 87 | } 88 | 89 | template 90 | inline xaudio_recorder::xaudio_recorder() 91 | : base_type() 92 | { 93 | set_defaults(); 94 | 95 | this->setup_properties(); 96 | } 97 | 98 | template 99 | inline xaudio_recorder::xaudio_recorder(xw::xholder audio) 100 | : base_type() 101 | { 102 | this->stream() = audio; 103 | 104 | set_defaults(); 105 | 106 | this->setup_properties(); 107 | } 108 | 109 | // template 110 | // template 111 | // inline xaudio_recorder::xaudio_recorder(xaudio_recorder&& rhs) noexcept 112 | // : base_type(rhs), audio(std::move(rhs.audio())), format(std::move(rhs.format())), 113 | // _width(std::move(rhs._width())), _height(std::move(rhs._height())) 114 | // { 115 | // this->setup_properties(); 116 | // } 117 | 118 | template 119 | inline void xaudio_recorder::set_defaults() 120 | { 121 | this->_model_name() = "AudioRecorderModel"; 122 | this->_view_name() = "AudioRecorderView"; 123 | 124 | this->audio() = xw::audio::initialize().format(this->format()).finalize(); 125 | } 126 | 127 | template 128 | inline void xaudio_recorder::setup_properties() 129 | { 130 | this->observe("format", [](auto& owner) { 131 | owner.audio().format() = owner.format(); 132 | }); 133 | this->audio().observe("value", [this](auto& owner) { 134 | if (this->autosave() && owner.value().size() != 0) 135 | { 136 | this->save_file("", owner.value().cbegin(), owner.value().cend()); 137 | } 138 | }); 139 | } 140 | } 141 | 142 | /********************* 143 | * precompiled types * 144 | *********************/ 145 | 146 | extern template class xw::xmaterialize; 147 | extern template class xw::xtransport>; 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /include/xwebrtc/xpeer.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_PEER_HPP 11 | #define XWEBRTC_PEER_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xtl/xoptional.hpp" 19 | 20 | #include "xwidgets/xfactory.hpp" 21 | #include "xwidgets/xholder.hpp" 22 | #include "xwidgets/xmaterialize.hpp" 23 | #include "xwidgets/xobject.hpp" 24 | #include "xwidgets/xmaker.hpp" 25 | 26 | #include "xwebrtc_config.hpp" 27 | #include "xmedia_stream.hpp" 28 | 29 | namespace nl = nlohmann; 30 | 31 | namespace xwebrtc 32 | { 33 | /********************* 34 | * xpeer declaration * 35 | *********************/ 36 | 37 | template 38 | class xpeer : public xw::xobject 39 | { 40 | public: 41 | 42 | using base_type = xw::xobject; 43 | using derived_type = D; 44 | 45 | using stream_type = xw::xholder; 46 | 47 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 48 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 49 | 50 | void connect() const; 51 | 52 | XPROPERTY(xtl::xoptional, derived_type, stream_local); 53 | XPROPERTY(xtl::xoptional, derived_type, stream_remote); 54 | XPROPERTY(std::string, derived_type, id_local); 55 | XPROPERTY(std::string, derived_type, id_remote); 56 | XPROPERTY(bool, derived_type, connected, false); 57 | XPROPERTY(bool, derived_type, failed, false); 58 | 59 | protected: 60 | 61 | xpeer(); 62 | using base_type::base_type; 63 | 64 | private: 65 | 66 | void set_defaults(); 67 | 68 | static int register_media_streams(); 69 | }; 70 | 71 | using peer = xw::xmaterialize; 72 | 73 | /************************ 74 | * xpeer implementation * 75 | ************************/ 76 | 77 | template 78 | inline void xpeer::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 79 | { 80 | using xw::xwidgets_serialize; 81 | base_type::serialize_state(state, buffers); 82 | 83 | xwidgets_serialize(stream_local(), state["stream_local"], buffers); 84 | xwidgets_serialize(stream_remote(), state["stream_remote"], buffers); 85 | xwidgets_serialize(id_local(), state["id_local"], buffers); 86 | xwidgets_serialize(id_remote(), state["id_remote"], buffers); 87 | } 88 | 89 | template 90 | inline void xpeer::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 91 | { 92 | using xw::set_property_from_patch; 93 | base_type::apply_patch(patch, buffers); 94 | 95 | set_property_from_patch(stream_local, patch, buffers); 96 | set_property_from_patch(stream_remote, patch, buffers); 97 | set_property_from_patch(id_local, patch, buffers); 98 | set_property_from_patch(id_remote, patch, buffers); 99 | set_property_from_patch(connected, patch, buffers); 100 | set_property_from_patch(failed, patch, buffers); 101 | } 102 | 103 | template 104 | inline void xpeer::connect() const 105 | { 106 | nl::json state; 107 | xeus::buffer_sequence buffers; 108 | state["msg"] = "connect"; 109 | this->send(std::move(state), std::move(buffers)); 110 | } 111 | 112 | template 113 | inline xpeer::xpeer() 114 | : base_type() 115 | { 116 | static int init = register_media_streams(); 117 | set_defaults(); 118 | } 119 | 120 | template 121 | inline void xpeer::set_defaults() 122 | { 123 | this->_model_module() = "jupyter-webrtc"; 124 | this->_view_module() = "jupyter-webrtc"; 125 | this->_model_name() = "WebRTCPeerModel"; 126 | this->_view_name() = "WebRTCPeerView"; 127 | this->_model_module_version() = jupyter_webrtc_semver(); 128 | this->_view_module_version() = jupyter_webrtc_semver(); 129 | } 130 | 131 | template 132 | inline int xpeer::register_media_streams() 133 | { 134 | xw::get_xfactory().register_maker( 135 | "jupyter-webrtc", 136 | "MediaStreamModel", 137 | "jupyter-webrtc", 138 | "MediaStreamView", 139 | xw::xmaker 140 | ); 141 | 142 | return 0; 143 | } 144 | } 145 | 146 | /********************* 147 | * precompiled types * 148 | *********************/ 149 | 150 | extern template class xw::xmaterialize; 151 | extern template class xw::xtransport>; 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /include/xwebrtc/xroom.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_ROOM_HPP 11 | #define XWEBRTC_ROOM_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xtl/xoptional.hpp" 19 | 20 | #include "xwidgets/xmaterialize.hpp" 21 | #include "xwidgets/xholder.hpp" 22 | #include "xwidgets/xobject.hpp" 23 | #include "xwidgets/xmaker.hpp" 24 | 25 | #include "xwebrtc_config.hpp" 26 | #include "xmedia_stream.hpp" 27 | #include "xpeer.hpp" 28 | 29 | namespace nl = nlohmann; 30 | 31 | namespace xwebrtc 32 | { 33 | /********************* 34 | * xroom declaration * 35 | *********************/ 36 | 37 | template 38 | class xroom : public xw::xobject 39 | { 40 | public: 41 | 42 | using base_type = xw::xobject; 43 | using derived_type = D; 44 | 45 | using stream_type = xw::xholder; 46 | using stream_list_type = std::vector; 47 | using peer_list_type = std::vector; 48 | 49 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 50 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 51 | 52 | XPROPERTY(std::string, derived_type, room, "room"); 53 | XPROPERTY(xtl::xoptional, derived_type, stream); 54 | XPROPERTY(std::string, derived_type, room_id); 55 | XPROPERTY(std::string, derived_type, nickname, "anonymous"); 56 | XPROPERTY(peer_list_type, derived_type, peers, {}); 57 | XPROPERTY(stream_list_type, derived_type, streams, {}); 58 | 59 | protected: 60 | 61 | xroom(); 62 | using base_type::base_type; 63 | 64 | private: 65 | 66 | void set_defaults(); 67 | 68 | static int register_peers(); 69 | }; 70 | 71 | using room = xw::xmaterialize; 72 | 73 | /************************ 74 | * xroom implementation * 75 | ************************/ 76 | 77 | template 78 | inline void xroom::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 79 | { 80 | using xw::xwidgets_serialize; 81 | base_type::serialize_state(state, buffers); 82 | 83 | xwidgets_serialize(room(), state["room"], buffers); 84 | xwidgets_serialize(stream(), state["stream"], buffers); 85 | xwidgets_serialize(nickname(), state["nickname"], buffers); 86 | xwidgets_serialize(peers(), state["peers"], buffers); 87 | xwidgets_serialize(streams(), state["streams"], buffers); 88 | } 89 | 90 | template 91 | inline void xroom::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 92 | { 93 | using xw::set_property_from_patch; 94 | base_type::apply_patch(patch, buffers); 95 | 96 | set_property_from_patch(room, patch, buffers); 97 | set_property_from_patch(stream, patch, buffers); 98 | set_property_from_patch(room_id, patch, buffers); 99 | set_property_from_patch(nickname, patch, buffers); 100 | set_property_from_patch(peers, patch, buffers); 101 | set_property_from_patch(streams, patch, buffers); 102 | } 103 | 104 | template 105 | inline xroom::xroom() 106 | : base_type() 107 | { 108 | static int init = register_peers(); 109 | set_defaults(); 110 | } 111 | 112 | template 113 | inline void xroom::set_defaults() 114 | { 115 | this->_model_module() = "jupyter-webrtc"; 116 | this->_view_module() = "jupyter-webrtc"; 117 | this->_model_name() = "WebRTCRoomModel"; 118 | // this->_view_name() = "WebRTCRoomView"; 119 | this->_model_module_version() = jupyter_webrtc_semver(); 120 | this->_view_module_version() = jupyter_webrtc_semver(); 121 | } 122 | 123 | template 124 | inline int xroom::register_peers() 125 | { 126 | xw::get_xfactory().register_maker( 127 | "jupyter-webrtc", 128 | "WebRTCPeerModel", 129 | "jupyter-webrtc", 130 | "WebRTCPeerView", 131 | xw::xmaker 132 | ); 133 | 134 | xw::get_xfactory().register_maker( 135 | "jupyter-webrtc", 136 | "MediaStreamModel", 137 | "jupyter-webrtc", 138 | "MediaStreamView", 139 | xw::xmaker 140 | ); 141 | 142 | return 0; 143 | } 144 | } 145 | 146 | /********************* 147 | * precompiled types * 148 | *********************/ 149 | 150 | extern template class xw::xmaterialize; 151 | extern template class xw::xtransport>; 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /include/xwebrtc/ximage_recorder.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_IMAGE_RECORDER_HPP 11 | #define XWEBRTC_IMAGE_RECORDER_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/ximage.hpp" 20 | 21 | #include "xrecorder.hpp" 22 | #include "xwebrtc_config.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xwebrtc 27 | { 28 | /******************************* 29 | * ximage_recorder declaration * 30 | *******************************/ 31 | 32 | template 33 | class ximage_recorder : public xrecorder 34 | { 35 | public: 36 | 37 | using base_type = xrecorder; 38 | using derived_type = D; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(xw::image, derived_type, image); 44 | XPROPERTY(std::string, derived_type, format, "png"); 45 | XPROPERTY(std::string, derived_type, _width, ""); 46 | XPROPERTY(std::string, derived_type, _height, ""); 47 | 48 | void save(const std::string& filename = "") const; 49 | 50 | protected: 51 | 52 | ximage_recorder(); 53 | ximage_recorder(xw::xholder video); 54 | using base_type::base_type; 55 | 56 | private: 57 | 58 | void set_defaults(); 59 | void setup_properties(); 60 | }; 61 | 62 | using image_recorder = xw::xmaterialize; 63 | 64 | /********************************** 65 | * ximage_recorder implementation * 66 | **********************************/ 67 | 68 | template 69 | inline void ximage_recorder::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 70 | { 71 | using xw::xwidgets_serialize; 72 | base_type::serialize_state(state, buffers); 73 | 74 | xwidgets_serialize(image(), state["image"], buffers); 75 | xwidgets_serialize(format(), state["format"], buffers); 76 | xwidgets_serialize(_width(), state["_width"], buffers); 77 | xwidgets_serialize(_height(), state["_height"], buffers); 78 | } 79 | 80 | template 81 | inline void ximage_recorder::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 82 | { 83 | using xw::set_property_from_patch; 84 | base_type::apply_patch(patch, buffers); 85 | 86 | set_property_from_patch(image, patch, buffers); 87 | set_property_from_patch(format, patch, buffers); 88 | set_property_from_patch(_width, patch, buffers); 89 | set_property_from_patch(_height, patch, buffers); 90 | } 91 | 92 | template 93 | inline void ximage_recorder::save(const std::string& filename) const 94 | { 95 | this->save_file(filename, this->image().value().cbegin(), this->image().value().cend()); 96 | } 97 | 98 | template 99 | inline ximage_recorder::ximage_recorder() 100 | : base_type() 101 | { 102 | set_defaults(); 103 | 104 | this->setup_properties(); 105 | } 106 | 107 | template 108 | inline ximage_recorder::ximage_recorder(xw::xholder video) 109 | : base_type() 110 | { 111 | this->stream() = video; 112 | 113 | set_defaults(); 114 | 115 | this->setup_properties(); 116 | } 117 | 118 | // template 119 | // template 120 | // inline ximage_recorder::ximage_recorder(ximage_recorder&& rhs) noexcept 121 | // : base_type(rhs), image(std::move(rhs.image())), format(std::move(rhs.format())), 122 | // _width(std::move(rhs._width())), _height(std::move(rhs._height())) 123 | // { 124 | // this->setup_properties(); 125 | // } 126 | 127 | template 128 | inline void ximage_recorder::set_defaults() 129 | { 130 | this->_model_name() = "ImageRecorderModel"; 131 | this->_view_name() = "ImageRecorderView"; 132 | 133 | this->image() = xw::image::initialize() 134 | .format(this->format()) 135 | .height(this->_height()) 136 | .width(this->_width()) 137 | .finalize(); 138 | } 139 | 140 | template 141 | inline void ximage_recorder::setup_properties() 142 | { 143 | this->observe("_width", [](auto& owner) { 144 | owner.image().width() = owner._width(); 145 | }); 146 | this->observe("_height", [](auto& owner) { 147 | owner.image().height() = owner._height(); 148 | }); 149 | this->observe("format", [](auto& owner) { 150 | owner.image().format() = owner.format(); 151 | }); 152 | this->image().observe("value", [this](auto& owner) { 153 | if (this->autosave() && owner.value().size() != 0) 154 | { 155 | this->save_file("", owner.value().cbegin(), owner.value().cend()); 156 | } 157 | }); 158 | } 159 | } 160 | 161 | /********************* 162 | * precompiled types * 163 | *********************/ 164 | 165 | extern template class xw::xmaterialize; 166 | extern template class xw::xtransport>; 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /notebooks/CameraStream_xtensor_fftw.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#pragma cling(optimize, 3)\n", 10 | "\n", 11 | "#include \n", 12 | "#include \n", 13 | "#include \n", 14 | "\n", 15 | "#include \"xtl/xbase64.hpp\"\n", 16 | "\n", 17 | "#include \"xtensor/xarray.hpp\"\n", 18 | "#include \"xtensor/xview.hpp\"\n", 19 | "#include \"xtensor/xbuilder.hpp\"\n", 20 | "\n", 21 | "#include \"xtensor-io/ximage.hpp\"\n", 22 | "\n", 23 | "#include \"xtensor-fftw/basic.hpp\"\n", 24 | "#include \"xtensor-fftw/helper.hpp\"\n", 25 | "\n", 26 | "#include \"xwidgets/ximage.hpp\"\n", 27 | "#include \"xwidgets/xbox.hpp\"\n", 28 | "\n", 29 | "#include \"xwebrtc/xcamera_stream.hpp\"\n", 30 | "#include \"xwebrtc/ximage_recorder.hpp\"" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "std::vector read_file(const char* filename)\n", 40 | "{\n", 41 | " std::basic_ifstream file(filename, std::ios::binary);\n", 42 | " return std::vector((std::istreambuf_iterator(file)), std::istreambuf_iterator());\n", 43 | "}" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "template \n", 53 | "std::vector to_png_buffer(const xt::xexpression& e)\n", 54 | "{\n", 55 | " const char* temp_filename = \"/tmp/xio_image.png\";\n", 56 | " xt::dump_image(temp_filename, e);\n", 57 | " return read_file(temp_filename);\n", 58 | "}" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "auto camera_stream = xwebrtc::camera_facing_user(false)\n", 68 | " .constraints({{\"audio\", false}, {\"video\", {{\"height\", 180}, {\"width\", 320}}}})\n", 69 | " .finalize();\n", 70 | "camera_stream" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": { 77 | "scrolled": false 78 | }, 79 | "outputs": [], 80 | "source": [ 81 | "auto recorder = xwebrtc::image_recorder(camera_stream);\n", 82 | "recorder.autosave() = false;\n", 83 | "auto& input = recorder.image();\n", 84 | "recorder" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "recorder.recording = true;" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "xt::xarray image_R;\n", 103 | "xt::xarray< std::complex > d_image_dx_fs_bw;\n", 104 | "xt::xarray< std::complex > d_image_dy_fs_bw;" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "auto output = xw::image();" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "auto callback = [&](auto&) {\n", 123 | " ::recorder.save();\n", 124 | " \n", 125 | " image_R = xt::view(xt::load_image(\"record.png\"), xt::all(), xt::all(), 0);\n", 126 | " \n", 127 | " auto image_fs_bw = xt::fftw::rfft2(image_R);\n", 128 | " \n", 129 | " std::complex i {0, 1};\n", 130 | " d_image_dx_fs_bw = i * xt::view(xt::fftw::fftscale(image_R.shape()[0]), xt::all(), xt::newaxis()) * image_fs_bw;\n", 131 | " d_image_dy_fs_bw = i * xt::fftw::rfftscale(image_R.shape()[1]) * image_fs_bw;\n", 132 | " \n", 133 | " auto d_image_dx_bw = xt::fftw::irfft2(d_image_dx_fs_bw);\n", 134 | " auto d_image_dy_bw = xt::fftw::irfft2(d_image_dy_fs_bw);\n", 135 | " \n", 136 | " auto d_image_grad_bw = xt::sqrt(d_image_dx_bw * d_image_dx_bw + d_image_dy_bw * d_image_dy_bw);\n", 137 | " \n", 138 | " double amax_d_image_grad_bw3 = xt::amax(d_image_grad_bw)[0];\n", 139 | " \n", 140 | " auto res = xt::cast(255 - (d_image_grad_bw / amax_d_image_grad_bw3 * 255));\n", 141 | " output.value = to_png_buffer(res);\n", 142 | " \n", 143 | " ::recorder.recording = true;\n", 144 | "};\n", 145 | "XOBSERVE(input, value, callback);" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "recorder.save();\n", 155 | "\n", 156 | "recorder.recording = true;" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "output.layout().width = \"100%\";\n", 166 | "output.layout().height = \"100%\";\n", 167 | "input.layout().width = \"100%\";\n", 168 | "input.layout().height = \"100%\";" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": null, 174 | "metadata": {}, 175 | "outputs": [], 176 | "source": [ 177 | "auto hbox = xw::hbox::initialize().children({input, output}).finalize();\n", 178 | "hbox" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "metadata": {}, 185 | "outputs": [], 186 | "source": [] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "C++14", 192 | "language": "C++14", 193 | "name": "xcpp14" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": "text/x-c++src", 197 | "file_extension": ".cpp", 198 | "mimetype": "text/x-c++src", 199 | "name": "c++", 200 | "version": "14" 201 | } 202 | }, 203 | "nbformat": 4, 204 | "nbformat_minor": 2 205 | } 206 | -------------------------------------------------------------------------------- /include/xwebrtc/xrecorder.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XWEBRTC_RECORDER_HPP 11 | #define XWEBRTC_RECORDER_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "nlohmann/json.hpp" 19 | 20 | #include "xproperty/xobserved.hpp" 21 | 22 | #include "xwidgets/xmaterialize.hpp" 23 | #include "xwidgets/xwidget.hpp" 24 | 25 | #include "xmedia_stream.hpp" 26 | #include "xwebrtc_config.hpp" 27 | 28 | namespace nl = nlohmann; 29 | 30 | namespace xwebrtc 31 | { 32 | /************************* 33 | * xrecorder declaration * 34 | *************************/ 35 | 36 | template 37 | class xrecorder : public xw::xwidget 38 | { 39 | public: 40 | 41 | using base_type = xw::xwidget; 42 | using derived_type = D; 43 | 44 | using media_stream_type = xw::xholder; 45 | using data_type = std::vector; 46 | using data_const_iterator = typename data_type::const_iterator; 47 | 48 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 49 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 50 | 51 | XPROPERTY(media_stream_type, derived_type, stream); 52 | XPROPERTY(std::string, derived_type, filename, "record"); 53 | XPROPERTY(std::string, derived_type, format, "webm"); 54 | XPROPERTY(bool, derived_type, recording, false); 55 | XPROPERTY(bool, derived_type, autosave, false); 56 | XPROPERTY(std::string, derived_type, _data_src); 57 | 58 | const std::vector& buffer_paths() const; 59 | void download() const; 60 | void save_file(const std::string& filename, data_const_iterator begin, data_const_iterator end) const; 61 | 62 | protected: 63 | 64 | xrecorder(); 65 | using base_type::base_type; 66 | 67 | private: 68 | 69 | void set_defaults(); 70 | }; 71 | 72 | using recorder = xw::xmaterialize; 73 | 74 | /**************************** 75 | * xrecorder implementation * 76 | ****************************/ 77 | 78 | template 79 | inline void xrecorder::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const 80 | { 81 | using xw::xwidgets_serialize; 82 | base_type::serialize_state(state, buffers); 83 | 84 | xwidgets_serialize(stream(), state["stream"], buffers); 85 | xwidgets_serialize(filename(), state["filename"], buffers); 86 | xwidgets_serialize(format(), state["format"], buffers); 87 | xwidgets_serialize(recording(), state["recording"], buffers); 88 | xwidgets_serialize(autosave(), state["autosave"], buffers); 89 | xwidgets_serialize(_data_src(), state["_data_src"], buffers); 90 | } 91 | 92 | template 93 | inline void xrecorder::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers) 94 | { 95 | using xw::set_property_from_patch; 96 | base_type::apply_patch(patch, buffers); 97 | 98 | set_property_from_patch(stream, patch, buffers); 99 | set_property_from_patch(filename, patch, buffers); 100 | set_property_from_patch(format, patch, buffers); 101 | set_property_from_patch(recording, patch, buffers); 102 | set_property_from_patch(autosave, patch, buffers); 103 | set_property_from_patch(_data_src, patch, buffers); 104 | } 105 | 106 | template 107 | inline const std::vector& xrecorder::buffer_paths() const 108 | { 109 | static const std::vector default_buffer_paths = {{"data"}}; 110 | return default_buffer_paths; 111 | } 112 | 113 | template 114 | inline void xrecorder::download() const 115 | { 116 | nl::json state; 117 | xeus::buffer_sequence buffers; 118 | state["msg"] = "download"; 119 | this->send(std::move(state), std::move(buffers)); 120 | } 121 | 122 | template 123 | inline xrecorder::xrecorder() 124 | : base_type() 125 | { 126 | set_defaults(); 127 | } 128 | 129 | template 130 | inline void xrecorder::save_file(const std::string& filename, data_const_iterator begin, data_const_iterator end) const 131 | { 132 | std::ofstream file; 133 | std::string name; 134 | if (filename.size() == 0) 135 | { 136 | name = this->filename(); 137 | } 138 | else 139 | { 140 | name = filename; 141 | } 142 | 143 | if (name.find('.') != std::string::npos) 144 | { 145 | file.open(name, std::ios::binary); 146 | } 147 | else 148 | { 149 | name.append(1, '.'); 150 | name.append(this->derived_cast().format()); 151 | file.open(name, std::ios::binary); 152 | } 153 | std::string data(begin, end); 154 | file << data; 155 | file.close(); 156 | } 157 | 158 | template 159 | inline void xrecorder::set_defaults() 160 | { 161 | this->_model_module() = "jupyter-webrtc"; 162 | this->_view_module() = "jupyter-webrtc"; 163 | this->_model_module_version() = jupyter_webrtc_semver(); 164 | this->_view_module_version() = jupyter_webrtc_semver(); 165 | } 166 | } 167 | 168 | /********************* 169 | * precompiled types * 170 | *********************/ 171 | 172 | extern template class xw::xmaterialize; 173 | extern template class xw::xtransport>; 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2017, Sylvain Corlay, Johan Mabille Wolf Vollprecht and # 3 | # Martin Renou # 4 | # # 5 | # Distributed under the terms of the BSD 3-Clause License. # 6 | # # 7 | # The full license is in the file LICENSE, distributed with this software. # 8 | ############################################################################ 9 | 10 | cmake_minimum_required(VERSION 3.8) 11 | project(xwebrtc) 12 | 13 | message(STATUS "Forcing tests build type to Release") 14 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 15 | 16 | set(XWEBRTC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) 17 | set(XWEBRTC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) 18 | 19 | # Configuration 20 | # ============= 21 | 22 | include(GNUInstallDirs) 23 | include(CMakePackageConfigHelpers) 24 | 25 | set(XWEBRTC_INSTALL_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"") 26 | 27 | configure_file ( 28 | "${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config_cling.hpp.in" 29 | "${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config_cling.hpp" 30 | ) 31 | 32 | # Versionning 33 | # =========== 34 | 35 | file(STRINGS "${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config.hpp" xwebrtc_version_defines 36 | REGEX "#define XWEBRTC_VERSION_(MAJOR|MINOR|PATCH)") 37 | foreach(ver ${xwebrtc_version_defines}) 38 | if(ver MATCHES "#define XWEBRTC_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") 39 | set(XWEBRTC_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") 40 | endif() 41 | endforeach() 42 | set(XWEBRTC_VERSION 43 | ${XWEBRTC_VERSION_MAJOR}.${XWEBRTC_VERSION_MINOR}.${XWEBRTC_VERSION_PATCH}) 44 | message(STATUS "xwebrtc version: v${XWEBRTC_VERSION}") 45 | 46 | # Binary version 47 | # See the following URL for explanations about the binary versionning 48 | # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info 49 | file(STRINGS "${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config.hpp" xwebrtc_version_defines 50 | REGEX "#define XWEBRTC_BINARY_(CURRENT|REVISION|AGE)") 51 | foreach(ver ${xwebrtc_version_defines}) 52 | if(ver MATCHES "#define XWEBRTC_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$") 53 | set(XWEBRTC_BINARY_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") 54 | endif() 55 | endforeach() 56 | set(XWEBRTC_BINARY_VERSION 57 | ${XWEBRTC_BINARY_CURRENT}.${XWEBRTC_BINARY_REVISION}.${XWEBRTC_BINARY_AGE}) 58 | message(STATUS "xwebrtc binary version: v${XWEBRTC_BINARY_VERSION}") 59 | 60 | # Dependencies 61 | # ============ 62 | 63 | find_package(cppzmq 4.3.0 REQUIRED) 64 | find_package(xtl 0.6.8 REQUIRED) 65 | find_package(xeus 0.24.1 REQUIRED) 66 | find_package(xwidgets 0.23.0 REQUIRED) 67 | 68 | # Source files 69 | # ============ 70 | 71 | set(XWEBRTC_HEADERS 72 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xaudio_recorder.hpp 73 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xaudio_stream.hpp 74 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xcamera_stream.hpp 75 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xchat.hpp 76 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/ximage_recorder.hpp 77 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/ximage_stream.hpp 78 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xmedia_stream.hpp 79 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xpeer.hpp 80 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xrecorder.hpp 81 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xroom_local.hpp 82 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xroom_mqtt.hpp 83 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xroom.hpp 84 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xvideo_recorder.hpp 85 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xvideo_stream.hpp 86 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config.hpp 87 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwebrtc_config_cling.hpp 88 | ${XWEBRTC_INCLUDE_DIR}/xwebrtc/xwidget_stream.hpp 89 | ) 90 | 91 | set(XWEBRTC_SOURCES 92 | ${XWEBRTC_SOURCE_DIR}/xaudio_recorder.cpp 93 | ${XWEBRTC_SOURCE_DIR}/xaudio_stream.cpp 94 | ${XWEBRTC_SOURCE_DIR}/xcamera_stream.cpp 95 | ${XWEBRTC_SOURCE_DIR}/ximage_recorder.cpp 96 | ${XWEBRTC_SOURCE_DIR}/ximage_stream.cpp 97 | ${XWEBRTC_SOURCE_DIR}/xmedia_stream.cpp 98 | ${XWEBRTC_SOURCE_DIR}/xpeer.cpp 99 | ${XWEBRTC_SOURCE_DIR}/xrecorder.cpp 100 | ${XWEBRTC_SOURCE_DIR}/xroom_local.cpp 101 | ${XWEBRTC_SOURCE_DIR}/xroom_mqtt.cpp 102 | ${XWEBRTC_SOURCE_DIR}/xroom.cpp 103 | ${XWEBRTC_SOURCE_DIR}/xvideo_recorder.cpp 104 | ${XWEBRTC_SOURCE_DIR}/xvideo_stream.cpp 105 | ${XWEBRTC_SOURCE_DIR}/xwidget_stream.cpp 106 | ) 107 | 108 | # Output 109 | # ====== 110 | 111 | add_library(xwebrtc SHARED ${XWEBRTC_SOURCES} ${XWEBRTC_HEADERS}) 112 | target_include_directories(xwebrtc PUBLIC $ 113 | $) 114 | 115 | target_link_libraries(xwebrtc 116 | PUBLIC xtl 117 | PUBLIC xeus 118 | PUBLIC xwidgets) 119 | 120 | set_target_properties(xwebrtc PROPERTIES 121 | PUBLIC_HEADER "${XWEBRTC_HEADERS}" 122 | COMPILE_DEFINITIONS "XWEBRTC_EXPORTS" 123 | PREFIX "" 124 | VERSION ${XWEBRTC_BINARY_VERSION} 125 | SOVERSION ${XWEBRTC_BINARY_CURRENT} 126 | OUTPUT_NAME "libxwebrtc") 127 | 128 | # Compilation flags 129 | # ================= 130 | 131 | include(CheckCXXCompilerFlag) 132 | string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) 133 | OPTION(DISABLE_ARCH_NATIVE "disable -march=native flag" OFF) 134 | 135 | set_target_properties(xwebrtc PROPERTIES 136 | CXX_EXTENSIONS OFF 137 | CXX_STANDARD_REQUIRED 14) 138 | 139 | target_compile_features(xwebrtc PRIVATE cxx_std_14) 140 | 141 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") 142 | target_compile_options(xwebrtc PUBLIC -Wunused-parameter -Wextra -Wreorder) 143 | if (NOT DISABLE_ARCH_NATIVE) 144 | target_compile_options(xwebrtc PUBLIC -march=native) 145 | endif() 146 | 147 | # Enable link time optimization and set the default symbol 148 | # visibility to hidden (very important to obtain small binaries) 149 | if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) 150 | # Check for Link Time Optimization support 151 | # (GCC/Clang) 152 | CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) 153 | if (HAS_LTO_FLAG) 154 | target_compile_options(xwebrtc PUBLIC -flto) 155 | endif() 156 | 157 | # Intel equivalent to LTO is called IPO 158 | if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") 159 | CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG) 160 | if (HAS_IPO_FLAG) 161 | target_compile_options(xwebrtc PUBLIC -ipo) 162 | endif() 163 | endif() 164 | endif() 165 | message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") 166 | endif() 167 | 168 | # if(MSVC) 169 | # target_compile_definitions(xwebrtc PUBLIC -DNOMINMAX) 170 | # target_compile_options(xwebrtc PUBLIC /DGUID_WINDOWS /MP /bigobj) 171 | # target_compile_options(xwebrtc PUBLIC /wd4251 /wd 4996) 172 | # # Allows to compile in debug without requiring each dependencies to 173 | # # be compiled in debug 174 | # if(${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) 175 | # set(CMAKE_CXX_FLAGS_DEBUG "/DNDEBUG /MD /Zi /Ob0 /Od /RTC1") 176 | # message(STATUS "Overriding CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") 177 | # endif() 178 | # endif() 179 | 180 | # Tests 181 | # ===== 182 | 183 | OPTION(BUILD_TESTS "xwebrtc test suite" OFF) 184 | OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF) 185 | 186 | if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) 187 | set(BUILD_TESTS ON) 188 | endif() 189 | 190 | if(BUILD_TESTS) 191 | add_subdirectory(test) 192 | endif() 193 | 194 | # Installation 195 | # ============ 196 | 197 | set(XWEBRTC_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xwebrtcConfig.cmake") 198 | 199 | install(TARGETS xwebrtc 200 | EXPORT ${PROJECT_NAME}-targets 201 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 202 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 203 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 204 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xwebrtc) 205 | 206 | # Makes the project importable from the build directory 207 | export(EXPORT ${PROJECT_NAME}-targets 208 | FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") 209 | 210 | configure_package_config_file(${PROJECT_NAME}Config.cmake.in 211 | "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" 212 | INSTALL_DESTINATION ${XWEBRTC_CMAKECONFIG_INSTALL_DIR}) 213 | write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake 214 | VERSION ${XWEBRTC_VERSION} 215 | COMPATIBILITY AnyNewerVersion) 216 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake 217 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake 218 | DESTINATION ${XWEBRTC_CMAKECONFIG_INSTALL_DIR}) 219 | install(EXPORT ${PROJECT_NAME}-targets 220 | FILE ${PROJECT_NAME}Targets.cmake 221 | DESTINATION ${XWEBRTC_CMAKECONFIG_INSTALL_DIR}) 222 | --------------------------------------------------------------------------------