### Load configuration from a JSON file
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
This example shows how to start the webrtc-streamer using a configuration file specified by the -C option.
```bash
./webrtc-streamer -C config.json
```
--------------------------------
### Download WebRTC Source and Install Sysroot
Source: https://github.com/mpromonet/webrtc-streamer/wiki/Cross-compile-WebRTC-for-Raspberry-Pi
Fetches the WebRTC source code using depot_tools and installs the necessary sysroot for ARM architecture.
```bash
fetch --no-history webrtc
src/build/linux/sysroot_scripts/install-sysroot.py --arch=arm
```
--------------------------------
### Install depot_tools
Source: https://github.com/mpromonet/webrtc-streamer/wiki/Cross-compile-WebRTC-for-Raspberry-Pi
Clones the depot_tools repository and adds it to the system's PATH for managing WebRTC dependencies.
```bash
sudo git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git /opt/depot_tools
echo "export PATH=/opt/depot_tools:$PATH" | sudo tee /etc/profile.d/depot_tools.sh
source /etc/profile
```
--------------------------------
### Install Chromium Depot Tools
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Clone the depot_tools repository and add it to the PATH. This is the first step in building WebRTC Streamer.
```sh
pushd ..
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:`realpath depot_tools`
popd
```
--------------------------------
### Display a grid of WebRTC streams
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
This example demonstrates how to arrange multiple WebRTC streams in a grid layout, specified by the 'layout' parameter.
```html
?layout=2x4
```
--------------------------------
### Start Embedded STUN/TURN Server
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Start the webrtc-streamer with an embedded STUN and TURN server. The public IP is dynamically fetched using curl.
```sh
./webrtc-streamer --stun-server=0.0.0.0:3478 --stun=$(curl -s ifconfig.me):3478
```
```sh
./webrtc-streamer --stun=- --turn-server=0.0.0.0:3478 -tturn:turn@$(curl -s ifconfig.me):3478
```
```sh
./webrtc-streamer --stun-server=0.0.0.0:3478 --stun=$(curl -s ifconfig.me):3478 --turn-server=0.0.0.0:3479 --turn=turn:turn@$(curl -s ifconfig.me):3479
```
--------------------------------
### Run Basic Docker Image
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Start the webrtc-streamer application using its Docker image. This command exposes the application on port 8000.
```sh
docker run -p 8000:8000 -it mpromonet/webrtc-streamer
```
--------------------------------
### CPack Packaging Configuration
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Configures installation rules and CPack generator settings for creating distributable packages.
```cmake
install (TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin)
install (DIRECTORY html DESTINATION share/${CMAKE_PROJECT_NAME})
install (FILES config.json DESTINATION share/${CMAKE_PROJECT_NAME})
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_BUILD_TYPE})
SET(CPACK_PACKAGE_CONTACT "michel.promonet@free.fr")
if(PROJECTVERSION)
SET(CPACK_PACKAGE_VERSION "${PROJECTVERSION}")
endif()
INCLUDE(CPack)
```
--------------------------------
### Install Raspberry Pi GCC Cross-Compiler
Source: https://github.com/mpromonet/webrtc-streamer/wiki/Cross-compile-WebRTC-for-Raspberry-Pi
Downloads and extracts a specific GCC cross-compiler toolchain for Raspberry Pi 2/3 (Buster) and adds its bin directory to the PATH.
```bash
wget -qO- https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Buster/GCC%209.3.0/Raspberry%20Pi%202%2C%203/cross-gcc-9.3.0-pi_2-3.tar.gz | sudo tar xz -C /opt
echo "export PATH=$(ls -d /opt/cross-pi-gcc-*/bin):$PATH" | sudo tee /etc/profile.d/arm_tools.sh
source /etc/profile
```
--------------------------------
### Minimal WHEP Player Example
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
A minimal HTML page using the @eyevinn/whep-video-component to display a WebRTC stream via the WHEP protocol. It configures the video source to stream from the webrtc-streamer API.
```html
```
--------------------------------
### Configure NAT Rules with upnpc
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Use upnpc to configure NAT rules for port forwarding. This example forwards ports for HTTP, STUN, and TURN.
```sh
upnpc -r 8000 tcp 3478 tcp 3478 udp
```
--------------------------------
### WebRTC Build Arguments Configuration
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Sets various build arguments for the WebRTC library, such as disabling tests, examples, and enabling/disabling specific features like H.264/H.265 support based on build type and branding.
```cmake
set (WEBRTCARGS rtc_include_tests=false
rtc_enable_protobuf=false
rtc_build_examples=false
treat_warnings_as_errors=false
enable_js_protobuf=false
use_glib=false
)
set (WEBRTCARGS libyuv_use_sme=false
${WEBRTCARGS})
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT WIN32)
set (WEBRTCARGS use_custom_libcxx=true
${WEBRTCARGS})
else()
set (WEBRTCARGS use_custom_libcxx=false
${WEBRTCARGS})
endif()
# debug/release
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set (WEBRTCARGS is_debug=false
${WEBRTCARGS})
else()
set (WEBRTCARGS is_debug=true
${WEBRTCARGS})
endif()
# enable H264 support
if (WEBRTCCHROMEBRANDED STREQUAL "ON")
set (WEBRTCARGS is_chrome_branded=true
${WEBRTCARGS})
else()
set (WEBRTCARGS rtc_use_h264=true
rtc_use_h265=true
${WEBRTCARGS})
endif()
```
--------------------------------
### Get Ice Candidates
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/docs/api.md
Retrieves the list of ICE candidates for the communication.
```APIDOC
## GET /api/getIceCandidate
### Description
Retrieves the list of ICE candidates for the communication.
### Method
GET
### Endpoint
/api/getIceCandidate
```
--------------------------------
### Get Ice Configuration
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/docs/api.md
Retrieves the IceServers configuration used by the streamer side.
```APIDOC
## GET /api/getIceServers
### Description
Retrieves the IceServers configuration used by the streamer side.
### Method
GET
### Endpoint
/api/getIceServers
```
--------------------------------
### HTML Page with WebComponent
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
An example HTML page using the webrtc-streamer Web Component. This provides a declarative way to embed WebRTC streams directly in HTML.
```html
```
--------------------------------
### Determine Project Version using Git
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
This snippet dynamically determines the project version by executing Git commands to get tags, commit hashes, and dirty status. It also appends version information for submodules like civetweb, webrtc, and live555helper. Use this to embed version information directly into the build.
```cmake
if(GIT_FOUND)
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} submodule update --init)
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty OUTPUT_VARIABLE PROJECTVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set (VERSION "${PROJECTVERSION}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} -C civetweb describe --tags --always --dirty OUTPUT_VARIABLE CIVETVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set (VERSION "${VERSION} civetweb@${CIVETVERSION}")
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} -C ${WEBRTCROOT}/src describe --tags --always --dirty OUTPUT_VARIABLE WEBRTCVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set (VERSION "${VERSION} webrtc@${WEBRTCVERSION}")
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} -C live555helper describe --tags --always --dirty OUTPUT_VARIABLE LIVEVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set (VERSION "${VERSION} live555helper@${LIVEVERSION}")
endif()
add_definitions(-DVERSION=\"${VERSION}\")
MESSAGE("VERSION = ${VERSION}")
add_definitions(-DWEBRTCSTREAMERRESSOURCE=\"${WEBRTCSTREAMERRESSOURCE}\")
MESSAGE("WEBRTCSTREAMERRESSOURCE = ${WEBRTCSTREAMERRESSOURCE}")
```
--------------------------------
### Download WebRTC Source
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Create a directory for WebRTC source code and fetch the repository using depot_tools.
```sh
mkdir ../webrtc
pushd ../webrtc
fetch webrtc
popd
```
--------------------------------
### View Docker Image Help
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Run the webrtc-streamer Docker image with the --help flag to view all available commands and options.
```sh
docker run -p 8000:8000 -it mpromonet/webrtc-streamer --help
```
--------------------------------
### Initialize JanusVideoRoom
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Instantiate the JanusVideoRoom class with Janus and WebRTC streamer URLs.
```js
var janus = new JanusVideoRoom(, )
```
--------------------------------
### Initialize XMPPVideoRoom for Jitsi
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Instantiate the XMPPVideoRoom class with the XMPP server URL and WebRTC streamer URL.
```js
var xmpp = new XMPPVideoRoom(, )
```
--------------------------------
### Configure WebRTC Build with GN
Source: https://github.com/mpromonet/webrtc-streamer/wiki/Cross-compile-WebRTC-for-Raspberry-Pi
Generates build files using GN for an ARM release build, enabling H.264, disabling tests, and configuring other build options.
```bash
pushd src
gn gen arm/out/Release --args='is_debug=false rtc_use_h264=true ffmpeg_branding="Chrome" is_clang=false target_cpu="arm" treat_warnings_as_errors=false rtc_include_tests=false rtc_enable_protobuf=false use_custom_libcxx=false use_ozone=true rtc_include_pulse_audio=false rtc_build_examples=false'
popd
```
--------------------------------
### Display webrtc-streamer help message
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Use this command to display all available options and their descriptions for the webrtc-streamer tool.
```bash
./webrtc-streamer [OPTION...] [urls...]
```
--------------------------------
### Linux Desktop Capture and X11 Libraries
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Conditionally enables desktop capture if the ninja build files exist and links necessary X11 libraries.
```cmake
if (EXISTS ${WEBRTCROOT}/src/out/${CMAKE_BUILD_TYPE}/obj/modules/desktop_capture/desktop_capture.ninja)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_X11)
find_package(X11)
target_link_libraries(${CMAKE_PROJECT_NAME} ${X11_LIBRARIES} ${X11_Xdamage_LIB} ${X11_Xfixes_LIB} ${X11_Xcomposite_LIB} ${X11_Xrandr_LIB} ${X11_Xtst_LIB})
endif()
```
--------------------------------
### Build WebRTC Streamer
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Configure the build using CMake, specifying the clang compiler, and then compile the project. Ensure the LLVM bin directory is in the PATH.
```sh
export PATH=$PATH:`realpath ../webrtc/src/third_party/llvm-build/Release+Asserts/bin`
cmake -DCMAKE_C_COMPILER=clang .
make
```
--------------------------------
### Civetweb Library Configuration
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds Civetweb as a static library, sets its compile definitions for OpenSSL and WebSockets, links it to the main project, and sets its include directories.
```cmake
add_library (civetweb STATIC civetweb/src/civetweb.c civetweb/src/CivetServer.cpp)
target_compile_definitions(civetweb PUBLIC OPENSSL_API_3_0 USE_WEBSOCKET)
target_link_libraries (${CMAKE_PROJECT_NAME} civetweb)
target_include_directories(civetweb PUBLIC civetweb/include)
```
--------------------------------
### Configure live555helper
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds the live555helper subdirectory and links it along with boringssl. Defines HAVE_LIVE555.
```cmake
add_subdirectory(live555helper EXCLUDE_FROM_ALL)
target_include_directories(liblive555helper PRIVATE ${WEBRTCROOT}/src/third_party/boringssl/src/include)
target_link_libraries (${CMAKE_PROJECT_NAME} liblive555helper ${WEBRTCOBJS}/third_party/boringssl/${CMAKE_STATIC_LIBRARY_PREFIX}boringssl${CMAKE_STATIC_LIBRARY_SUFFIX})
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_LIVE555)
```
--------------------------------
### Build WebRTC with Ninja
Source: https://github.com/mpromonet/webrtc-streamer/wiki/Cross-compile-WebRTC-for-Raspberry-Pi
Compiles the WebRTC project using Ninja for the previously configured ARM release build.
```bash
pushd src
ninja -C arm/out/Release
popd
```
--------------------------------
### Add Prometheus-cpp Core
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Includes the Prometheus-cpp core library and links it to the project. Sets up include directories.
```cmake
include(GenerateExportHeader)
include(GNUInstallDirs)
set(PROJECT_NAME prometheus-cpp)
add_subdirectory(prometheus-cpp/core EXCLUDE_FROM_ALL)
target_link_libraries (${CMAKE_PROJECT_NAME} core)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE prometheus-cpp/core/include)
```
--------------------------------
### WebRTC Include Directories
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Sets the include directories for WebRTC and its dependencies. Ensure WEBRTCROOT is correctly defined.
```cmake
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${WEBRTCROOT}/src ${WEBRTCROOT}/src/third_party/abseil-cpp ${WEBRTCROOT}/src/third_party/jsoncpp/source/include ${WEBRTCROOT}/src/third_party/jsoncpp/generated ${WEBRTCROOT}/src/third_party/libyuv/include)
```
--------------------------------
### Configure sound support based on OS
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Sets WEBRTCARGS based on the operating system to include or exclude specific audio device support.
```cmake
if (APPLE)
set (WEBRTCARGS rtc_include_internal_audio_device=true
${WEBRTCARGS})
set (WEBRTCARGS rtc_include_pulse_audio=true
${WEBRTCARGS})
elseif (WIN32)
set (WEBRTCARGS rtc_include_internal_audio_device=true
${WEBRTCARGS})
elseif (NOT DEFINED CMAKE_SYSROOT)
if (NOT PulseAudio_FOUND)
set (WEBRTCARGS rtc_include_pulse_audio=false
${WEBRTCARGS})
endif()
if (NOT ALSA_FOUND)
set (WEBRTCARGS rtc_include_internal_audio_device=false
${WEBRTCARGS})
endif()
endif()
```
--------------------------------
### Linux Civetweb and ALSA Libraries
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Links the dl library for Civetweb and conditionally defines HAVE_SOUND if ALSA is found.
```cmake
target_link_libraries(${CMAKE_PROJECT_NAME} dl)
if (ALSA_FOUND)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_SOUND)
endif()
```
--------------------------------
### Define Project Executable and Link Libraries
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
This snippet defines the main executable for the project using `add_executable` and `GLOB_RECURSE` to find source files. It then links necessary libraries, including custom libc++ and libc++abi if found, and the Threads library. Ensure that the paths to WEBRTCOBJS and source files are correctly configured.
```cmake
FILE(GLOB_RECURSE WEBRTJSONCPPCOBJS ${WEBRTCOBJS}/third_party/jsoncpp/jsoncpp/*${CMAKE_C_OUTPUT_EXTENSION} ${WEBRTCOBJS}/rtc_base/rtc_json/*${CMAKE_C_OUTPUT_EXTENSION})
FILE(GLOB_RECURSE WEBRTP2POBJ ${WEBRTCOBJS}/p2p/p2p_server_utils/*${CMAKE_C_OUTPUT_EXTENSION})
SET (WEBRTCEXTRAOBJS ${WEBRTJSONCPPCOBJS} ${WEBRTP2POBJ} ${WEBRTCCOMOBJ})
FILE(GLOB SOURCE src/*.cpp)
add_executable (${CMAKE_PROJECT_NAME} ${SOURCE} ${WEBRTCEXTRAOBJS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE inc)
if (EXISTS ${WEBRTCOBJS}/buildtools/third_party/libc++/${CMAKE_STATIC_LIBRARY_PREFIX}c++${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "Found libc++ library at ${WEBRTCOBJS}/buildtools/third_party/libc++/${CMAKE_STATIC_LIBRARY_PREFIX}c++${CMAKE_STATIC_LIBRARY_SUFFIX}")
target_link_libraries(${CMAKE_PROJECT_NAME} "${WEBRTCOBJS}/buildtools/third_party/libc++/${CMAKE_STATIC_LIBRARY_PREFIX}c++${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
if (EXISTS ${WEBRTCOBJS}/buildtools/third_party/libc++abi/${CMAKE_STATIC_LIBRARY_PREFIX}c++abi${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "Found libc++abi library at ${WEBRTCOBJS}/buildtools/third_party/libc++abi/${CMAKE_STATIC_LIBRARY_PREFIX}c++abi${CMAKE_STATIC_LIBRARY_SUFFIX}")
target_link_libraries(${CMAKE_PROJECT_NAME} "${WEBRTCOBJS}/buildtools/third_party/libc++abi/${CMAKE_STATIC_LIBRARY_PREFIX}c++abi${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
# cxxopts
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE cxxopts/include)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE CXXOPTS_NO_RTTI)
# thread
if (NOT WIN32)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
endif()
find_package(Threads REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} Threads::Threads)
```
--------------------------------
### Run Docker Image with Config File
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Mount a custom config.json file into the webrtc-streamer Docker container. This allows for custom configuration of the streamer.
```sh
docker run --name webrtc -d -p 8000:8000 -v $PWD/config.json:/usr/local/share/webrtc-streamer/config.json mpromonet/webrtc-streamer
```
--------------------------------
### Configure screen capture support
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Disables X11 and PipeWire for screen capture if GTK3 is not found or WEBRTCDESKTOPCAPTURE is OFF.
```cmake
find_package(PkgConfig QUIET)
pkg_check_modules(GTK3 QUIET gtk+-3.0)
MESSAGE("GTK3_FOUND = ${GTK3_FOUND}")
if(NOT GTK3_FOUND OR (WEBRTCDESKTOPCAPTURE STREQUAL "OFF"))
set (WEBRTCARGS rtc_use_x11=false
rtc_use_pipewire=false
${WEBRTCARGS})
endif()
```
--------------------------------
### Publish WebRTC Streams to Jitsi Video Room
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Join a Jitsi Video Room with the specified room name, stream URL, and display name using the XMPPVideoRoom interface. Requires several Strophe and Jingle libraries.
```html
```
--------------------------------
### Write build arguments to file
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Writes the accumulated WEBRTCARGS to the args.gn file in the build output directory.
```cmake
FILE(WRITE ${WEBRTCROOT}/src/out/${CMAKE_BUILD_TYPE}/args.gn ${WEBRTCARGS})
```
--------------------------------
### Configure compilation mode for ARM processors
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Sets WEBRTCARGS for different ARM processor architectures, including target CPU, version, float ABI, and libaom enablement.
```cmake
if(CMAKE_SYSTEM_PROCESSOR MATCHES "armv6.*")
set (WEBRTCARGS target_cpu="arm"
arm_version=6
arm_float_abi="hard"
enable_libaom=false
${WEBRTCARGS})
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv.*")
set (WEBRTCARGS target_cpu="arm"
${WEBRTCARGS})
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
set (WEBRTCARGS target_cpu="arm64"
${WEBRTCARGS})
endif()
```
--------------------------------
### Initiate Communication Asking to be Called
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/docs/api.md
Creates an offer to initiate communication, allowing the other party to call back.
```APIDOC
## POST /api/createOffer
### Description
Creates an offer to initiate communication, allowing the other party to call back.
### Method
POST
### Endpoint
/api/createOffer
```
--------------------------------
### Publish WebRTC Streams to Janus Video Room (NodeJS)
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Join a Janus Video Room using the JanusVideoRoom module in NodeJS. Requires 'then-request' and the local 'janusvideoroom.js' module.
```js
global.request = require("then-request");
var JanusVideoRoom = require("./html/janusvideoroom.js");
var janus = new JanusVideoRoom(
"http://192.168.0.15:8088/janus",
"http://192.168.0.15:8000",
);
janus.join(1234, "videocap://0", "video");
```
--------------------------------
### Linux libv4l2cpp Library
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds the libv4l2cpp library as a static library, sets its include directories, and links it to the main project. Also defines HAVE_V4L2.
```cmake
aux_source_directory(libv4l2cpp/src LIBSRC_FILES)
add_library(libv4l2cpp STATIC ${LIBSRC_FILES})
target_include_directories(libv4l2cpp PUBLIC libv4l2cpp/inc)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_V4L2)
target_link_libraries (${CMAKE_PROJECT_NAME} libv4l2cpp)
```
--------------------------------
### Generate build files with gn
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Executes the 'gn gen' command to generate build files for the specified build type. Sets the shell command based on the operating system.
```cmake
if (WIN32)
SET (SHELLCOMMAND cmd /c )
endif()
EXECUTE_PROCESS(WORKING_DIRECTORY ${WEBRTCROOT}/src/out/${CMAKE_BUILD_TYPE} COMMAND ${SHELLCOMMAND} gn gen . RESULT_VARIABLE NINJA_RESULT)
```
--------------------------------
### Build webrtc with ninja
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Compiles the webrtc project using ninja with a specified list of targets. Checks for build failures and reports an error if the build fails.
```cmake
SET(NINJA_TARGET webrtc rtc_json builtin_video_decoder_factory builtin_video_encoder_factory p2p_server_utils task_queue default_task_queue_factory field_trials rtc_tools)
EXECUTE_PROCESS(WORKING_DIRECTORY ${WEBRTCROOT}/src/out/${CMAKE_BUILD_TYPE} COMMAND ${SHELLCOMMAND} ninja ${NINJA_TARGET} RESULT_VARIABLE NINJA_RESULT)
if(NOT NINJA_RESULT EQUAL 0)
message(FATAL_ERROR "webrtc build failed with exit code ${NINJA_RESULT}")
endif()
```
--------------------------------
### Initiate Communication as Caller
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/docs/api.md
Sends an offer and receives an answer to initiate communication as the caller.
```APIDOC
## POST /api/call
### Description
Sends an offer and receives an answer to initiate communication as the caller.
### Method
POST
### Endpoint
/api/call
```
--------------------------------
### Copying FFmpeg Configuration Files
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Copies generated FFmpeg configuration header files to specific locations within the WebRTC build directory. This is part of the FFmpeg integration process for ARMv6 builds.
```cmake
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/config.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/config_components.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavutil/avconfig.h DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavutil/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavfilter/filter_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavfilter/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/codec_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/parser_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavcodec/bsf_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavcodec/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavformat/demuxer_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavformat/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavformat/muxer_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavformat/)
file(COPY ${WEBRTCROOT}/src/third_party/ffmpeg/libavformat/protocol_list.c DESTINATION ${WEBRTCROOT}/src/third_party/ffmpeg/chromium/config/Chrome/linux/arm/libavformat/)
```
--------------------------------
### HTML Page with WebRTC Stream
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
A sample HTML page demonstrating how to use the WebRtcStreamer JavaScript class to display a video stream. It connects to a local webrtc-streamer instance and plays an RTSP stream.
```html
```
--------------------------------
### WebRTC Compile Definitions
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds compile definitions for WebRTC, including HAVE_JPEG.
```cmake
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_JPEG)
```
--------------------------------
### Publish WebRTC Streams to Janus Video Room (Browser)
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Join a Janus Video Room with specified room ID, stream URL, and display name using the JanusVideoRoom interface in a browser.
```html
```
--------------------------------
### Configure RTMP Support
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Finds and configures RTMP library support. Links the RTMP library if found.
```cmake
find_package(PkgConfig QUIET)
pkg_check_modules(RTMP QUIET librtmp)
MESSAGE("RTMP_FOUND = ${RTMP_FOUND} RTMP_INCLUDE_DIRS=${RTMP_INCLUDE_DIRS} RTMP_LIBRARY_DIRS=${RTMP_LIBRARY_DIRS} RTMP_LIBRARIES=${RTMP_LIBRARIES}")
find_library(RTMP_LIB NAMES rtmp)
MESSAGE("RTMP_LIB=${RTMP_LIB}")
if (RTMP_FOUND AND RTMP_LIB_FOUND)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_RTMP)
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${RTMP_INCLUDE_DIRS})
target_link_directories(${CMAKE_PROJECT_NAME} PUBLIC ${RTMP_LIBRARY_DIRS})
target_link_libraries (${CMAKE_PROJECT_NAME} ${RTMP_LIB})
endif()
```
--------------------------------
### Windows WebRTC Definitions and Libraries
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Configures WebRTC specific compile definitions and links necessary Windows libraries for multimedia and networking.
```cmake
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE WEBRTC_WIN EHsc NOMINMAX __PRETTY_FUNCTION__=__FUNCTION__)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_X11 HAVE_SOUND)
target_link_libraries (${CMAKE_PROJECT_NAME} secur32 dmoguids wmcodecdspuuid strmiids msdmo winmm dxgi d3d11 iphlpapi dwmapi shcore)
```
--------------------------------
### macOS WebRTC Definitions and Libraries
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Configures WebRTC specific compile definitions and finds/links macOS frameworks for audio, video, and application services.
```cmake
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE WEBRTC_MAC WEBRTC_POSIX)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HAVE_SOUND)
add_definitions(-fno-rtti)
find_library(CORE_FOUNDATION Foundation)
find_library(APPLICATION_SERVICES ApplicationServices)
find_library(CORE_SERVICES CoreServices)
find_library(CORE_AUDIO CoreAudio)
find_library(AUDIO_TOOLBOX AudioToolBox)
find_library(IO_SURFACE IOSurface)
find_library(APP_KIT AppKit)
target_link_libraries (${CMAKE_PROJECT_NAME} ${CORE_FOUNDATION} ${APPLICATION_SERVICES} ${CORE_SERVICES}
${CORE_AUDIO} ${AUDIO_TOOLBOX} ${IO_SURFACE} ${APP_KIT})
```
--------------------------------
### Windows Live555 Definitions
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds definitions for Live555 on Windows to disable iterator debug checking and enable Winsock.
```cmake
add_definitions(-D_HAS_ITERATOR_DEBUGGING=0 -D_WINSOCKAPI_)
```
--------------------------------
### macOS Live555 Definitions
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Adds definitions for Live555 on macOS to enable locale support.
```cmake
add_definitions(-DNEED_XLOCALE_H=1)
```
--------------------------------
### Run Docker Image with Extra Host
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Run the webrtc-streamer Docker container and add an extra host entry for host.docker.internal. This is useful for accessing host services from within the container.
```sh
docker run --name webrtc -d -p 8000:8000 --add-host host.docker.internal:host-gateway mpromonet/webrtc-streamer -e host.docker.internal
```
--------------------------------
### Run Docker Image with Host Network
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Run the webrtc-streamer Docker container using the host's network stack. This bypasses Docker's network isolation.
```sh
docker run --name webrtc -d --net host mpromonet/webrtc-streamer
```
--------------------------------
### Run Docker Image with V4L2 Device
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Expose V4L2 devices from the host machine to the webrtc-streamer Docker container. This allows the container to access host video devices.
```sh
docker run --device=/dev/video0 -p 8000:8000 -it mpromonet/webrtc-streamer
```
--------------------------------
### FFmpeg Configuration for ARMv6
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Configures FFmpeg with specific options for ARMv6 architecture, including enabling certain codecs and demuxers, and setting cross-compilation flags. This snippet is executed only if the system processor matches 'armv6'.
```cmake
if (CMAKE_SYSTEM_PROCESSOR MATCHES "armv6.*" )
set (CONFIGURE_ARGS --disable-everything --disable-all --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-static --enable-avcodec --enable-avformat --enable-avutil --enable-static --enable-libopus --disable-debug --disable-bzlib --disable-iconv --disable-network --disable-schannel --disable-sdl2 --disable-symver --disable-xlib --disable-zlib --disable-securetransport --disable-faan --disable-alsa --disable-autodetect --disable-error-resilience --enable-decoder=vorbis,libopus,flac,pcm_u8,pcm_s16le,pcm_s24le,pcm_s32le,pcm_f32le,mp3,pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw --enable-demuxer=ogg,matroska,wav,flac,mp3,mov --enable-parser=opus,vorbis,flac,mpegaudio,vp9 --extra-cflags=-I${WEBRTCROOT}/src/third_party/opus/src/include --disable-linux-perf --x86asmexe=nasm --optflags="-O2" --arch=arm --enable-armv6 --disable-armv6t2 --enable-vfp --disable-thumb --extra-cflags=-march=armv6 --enable-cross-compile --target-os=linux --extra-cflags=--target=arm-linux-gnueabihf --extra-ldflags=--target=arm-linux-gnueabihf --sysroot=${WEBRTCROOT}/src/build/linux/debian_bullseye_armhf-sysroot --extra-cflags=-mtune=cortex-a8 --extra-cflags=-mfloat-abi=hard --extra-cflags=-O2 --disable-neon --extra-cflags=-mfpu=vfpv3-d16 --enable-pic --cc=clang --cxx=clang++ --ld=clang --extra-ldflags=-fuse-ld=lld --enable-decoder=aac,h264 --enable-demuxer=aac --enable-parser=aac,h264)
MESSAGE("CONFIGURE_ARGS = ${CONFIGURE_ARGS}")
EXECUTE_PROCESS(WORKING_DIRECTORY ${WEBRTCROOT}/src/third_party/ffmpeg COMMAND ./configure ${CONFIGURE_ARGS})
```
--------------------------------
### Initiate Communication using WHEP
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/docs/api.md
Initiates communication using the WHEP protocol, similar to the /api/call endpoint.
```APIDOC
## POST /api/whep
### Description
Initiates communication using the WHEP protocol, similar to the /api/call endpoint.
### Method
POST
### Endpoint
/api/whep
```
--------------------------------
### Linux WebRTC Definitions and RTTI
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/CMakeLists.txt
Configures WebRTC specific compile definitions for POSIX systems and disables RTTI. Includes ARM-specific flags for armv6 processors.
```cmake
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE WEBRTC_POSIX)
add_definitions(-fno-rtti -fpermissive)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "armv6.*")
add_definitions(-marm -march=armv6 -mfpu=vfp -mfloat-abi=hard)
endif()
```
--------------------------------
### Initialize WebRtcStreamer in JavaScript
Source: https://github.com/mpromonet/webrtc-streamer/blob/master/README.md
Instantiate the WebRtcStreamer class in JavaScript to embed a WebRTC stream in an HTML page. Requires the video tag ID and the webrtc-streamer URL.
```javascript
var webRtcServer = new WebRtcStreamer(