### ARM Cross-Compilation Setup Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Example package installation commands for setting up an environment for ARM cross-compilation. This includes installing essential build tools, development libraries, and ARM-specific compilers. ```shell sudo apt-get install ssh dkms build-essential linux-headers-generic sudo apt-get install kdevelop cmake git subversion sudo apt-get install graphviz doxygen doxygen-gui sudo apt-get install manpages manpages-dev manpages-posix manpages-posix-dev sudo apt-get install libboost-all-dev libboost-dev libssl-dev sudo apt-get install rpm terminator fish sudo apt-get install g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf ``` -------------------------------- ### Build Library with CMake (Release Install) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md CMake commands for a release build and installation. Specifies the installation prefix and build type. Includes commands to build and install the library. ```shell mkdir out cd out cmake -DCMAKE_INSTALL_PREFIX="/usr/lib" -DCMAKE_BUILD_TYPE="Release" .. cmake --build . --config Release sudo cmake --build . --target install --config Release ``` -------------------------------- ### Clone libyuv repository with Git Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This command fetches only the source code of the libyuv repository without any build configurations. It's a straightforward way to get the latest version of the code directly from the Git repository. ```bash git clone https://chromium.googlesource.com/libyuv/libyuv ``` -------------------------------- ### Run Unit Tests with Intel SDE (Windows) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Executes libyuv unit tests on Windows using Intel SDE (Software Development Emulator) with the 'hsw' microarchitecture. Requires Intel SDE to be installed and in the system's PATH. ```shell c:\intelsde\sde -hsw -- out\Release\libyuv_unittest.exe --gtest_filter=* ``` -------------------------------- ### ARM Linux Build with GN Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to generate build configurations for ARM Linux using GN. Supports both release and debug builds for `libyuv_unittest`. ```shell gn gen out/Release "--args=is_debug=false target_cpu=\"arm64\"" gn gen out/Debug "--args=is_debug=true target_cpu=\"arm64\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest ``` -------------------------------- ### Run Unit Tests with Intel SDE (macOS/Linux) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Executes libyuv unit tests on macOS or Linux using Intel SDE with the 'skx' microarchitecture. Requires Intel SDE to be installed and in the system's PATH. The `--gtest_filter='**I420ToARGB_Opt'` argument filters for specific tests. ```shell ~/intelsde/sde -skx -- out/Release/libyuv_unittest --gtest_filter=**I420ToARGB_Opt ``` -------------------------------- ### Unittest Execution on Windows Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Command to run libyuv unit tests on Windows using the compiled executable. It includes options for exception handling and running all tests. ```shell out\Release\libyuv_unittest.exe --gtest_catch_exceptions=0 --gtest_filter="*" ``` -------------------------------- ### Build Library with Make (Linux) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Make commands for building and cleaning the library on Linux using a `linux.mk` Makefile. Supports verbose output and specifying the C++ compiler. ```shell make V=1 -f linux.mk make V=1 -f linux.mk clean make V=1 -f linux.mk CXX=clang++ ``` -------------------------------- ### Build psnr Tool for ARM Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to build the `psnr` tool for ARM cross-compilation using `arm-linux-gnueabihf-g++`. Also shows how to disassemble the resulting executable. ```shell cd util arm-linux-gnueabihf-g++ psnr_main.cc psnr.cc ssim.cc -o psnr arm-linux-gnueabihf-objdump -d psnr ``` -------------------------------- ### Run Specific Unit Test (macOS/Linux) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Executes a specific unit test for the libyuv project on macOS and Linux, using the `--gtest_filter` flag with a wildcard pattern to match the desired test. For example, '*I420ToARGB_Opt' will run tests containing that string. ```shell out/Release/libyuv_unittest --gtest_filter=*I420ToARGB_Opt ``` -------------------------------- ### Android Unit Test Execution Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to run unit tests for libyuv on Android. Includes options for verbose output and filtering specific tests. Also shows how to run tests as benchmarks with specific parameters. ```shell out/Release/bin/run_libyuv_unittest -vv --gtest_filter=* out/Release/bin/run_libyuv_unittest -vv --gtest_filter=* --libyuv_width=1280 --libyuv_height=720 --libyuv_repeat=999 --libyuv_flags=-1 --libyuv_cpu_info=-1 out/Release/bin/run_libyuv_unittest -vv --gtest_filter=* --libyuv_width=1280 --libyuv_height=720 --libyuv_repeat=999 --libyuv_flags=1 --libyuv_cpu_info=1 ``` -------------------------------- ### Build libyuv on Windows using GN and Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md These commands demonstrate how to configure and build the libyuv library on Windows for both Release and Debug configurations, targeting both x64 and x86 architectures. It utilizes GN (Generate Ninja) to create build files and Ninja to perform the compilation. ```batch call gn gen out\Release "--args=is_debug=false target_cpu=\"x64\"" call gn gen out\Debug "--args=is_debug=true target_cpu=\"x64\"" ninja -v -C out\Release ninja -v -C out\Debug call gn gen out\Release "--args=is_debug=false target_cpu=\"x86\"" call gn gen out\Debug "--args=is_debug=true target_cpu=\"x86\"" ninja -v -C out\Release ninja -v -C out\Debug ``` -------------------------------- ### Android Build Instructions with GN Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to generate build configurations for Android using GN (GenerateNinja) for different CPU architectures (arm64, armv7, ia32, mips). Includes steps for debug and release builds, and running unit tests. ```shell gn gen out/Release "--args=is_debug=false target_os=\"android\" target_cpu=\"arm64\"" gn gen out/Debug "--args=is_debug=true target_os=\"android\" target_cpu=\"arm64\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest gn gen out/Release "--args=is_debug=false target_os=\"android\" target_cpu=\"arm\"" gn gen out/Debug "--args=is_debug=true target_os=\"android\" target_cpu=\"arm\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest gn gen out/Release "--args=is_debug=false target_os=\"android\" target_cpu=\"x86\"" gn gen out/Debug "--args=is_debug=true target_os=\"android\" target_cpu=\"x86\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest gn gen out/Release "--args=is_debug=false target_os=\"android\" target_cpu=\"mips64el\" mips_arch_variant=\"r6\" mips_use_msa=true is_component_build=true" gn gen out/Debug "--args=is_debug=true target_os=\"android\" target_cpu=\"mips64el\" mips_arch_variant=\"r6\" mips_use_msa=true is_component_build=true" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest ``` -------------------------------- ### Configure and Sync libyuv with gclient Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This snippet shows how to configure and synchronize the libyuv source code using the gclient tool, which is part of depot tools. It sets up the source directory and fetches the necessary code. It also demonstrates how to specify target operating systems like iOS and Android. ```bash gclient config --name src https://chromium.googlesource.com/libyuv/libyuv gclient sync ``` ```bash solutions = [ { "name" : "src", "url" : "https://chromium.googlesource.com/libyuv/libyuv", "deps_file" : "DEPS", "managed" : True, "custom_deps" : { }, "safesync_url": "", }, ]; target_os = ["android", "linux"]; gclient sync ``` ```bash solutions = [ { "name" : "src", "url" : "https://chromium.googlesource.com/libyuv/libyuv", "deps_file" : "DEPS", "managed" : True, "custom_deps" : { }, "safesync_url": "", }, ]; target_os = ["ios"]; gclient sync ``` -------------------------------- ### Build Target Compilation with Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Ninja commands to build specific targets for the libyuv library, such as the library itself, unit tests, and various tools like `compare`, `yuvconvert`, `psnr`, and `cpuid`. ```shell ninja -C out/Debug libyuv ninja -C out/Debug libyuv_unittest ninja -C out/Debug compare ninja -C out/Debug yuvconvert ninja -C out/Debug psnr ninja -C out/Debug cpuid ``` -------------------------------- ### Build Library with CMake (Default Debug) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md CMake commands to perform a default debug build of the library. It involves creating an output directory, navigating into it, and running CMake and build commands. ```shell mkdir out cd out cmake .. cmake --build . ``` -------------------------------- ### Build libyuv on macOS and Linux using GN and Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This snippet provides the commands to generate build configurations and compile the libyuv library on macOS and Linux systems. It creates both Release and Debug build targets using GN and then uses Ninja to build the library and its unit tests. ```bash gn gen out/Release "--args=is_debug=false" gn gen out/Debug "--args=is_debug=true" ninja -v -C out/Release ninja -v -C out/Debug ``` -------------------------------- ### Build Official libyuv with GN Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This command configures and builds an official, non-debug, and branded version of the libyuv library. It uses GN to set the build arguments for an official build and Ninja to perform the compilation. ```bash gn gen out/Official "--args=is_debug=false is_official_build=true is_chrome_branded=true" ninja -C out/Official ``` -------------------------------- ### MIPS Linux Build with GN Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to generate build configurations for MIPS Linux using GN, targeting `mips64el` with specific variants like `loongson3`. Includes options for component builds and sysroot usage. ```shell gn gen out/Release "--args=is_debug=false target_os=\"linux\" target_cpu=\"mips64el\" mips_arch_variant=\"loongson3\" mips_use_mmi=true is_component_build=false use_sysroot=false use_gold=false" gn gen out/Debug "--args=is_debug=true target_os=\"linux\" target_cpu=\"mips64el\" mips_arch_variant=\"loongson3\" mips_use_mmi=true is_component_build=false use_sysroot=false use_gold=false" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest ``` -------------------------------- ### Build Package (RPM/DEB) with CMake Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md CMake commands to build RPM or DEB packages for the library. This typically involves setting the build type to Release and then using make to package the build artifacts. ```shell mkdir out cd out cmake -DCMAKE_BUILD_TYPE=Release .. make -j4 make package ``` -------------------------------- ### Run Dr. Memory Memcheck (Windows) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Executes unit tests using Dr. Memory's memcheck tool on Windows. Requires Dr. Memory to be installed and added to the system's PATH. The `--gtest_catch_exceptions=0` flag is used to prevent gtest from catching exceptions that Dr. Memory might report. ```shell drmemory out\Debug\libyuv_unittest.exe --gtest_catch_exceptions=0 --gtest_filter=* ``` -------------------------------- ### Enable Memory Sanitizer (MSAN) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Configures the build system to enable the Memory Sanitizer (MSAN) for debugging memory-related issues. This involves generating the build files with specific arguments and then compiling using ninja. ```shell gn gen out/Release" --args=is_debug=false is_msan=true" ninja -v -C out/Release ``` -------------------------------- ### Setup Phase for Test Suite Dependencies Source: https://github.com/signalwire/freeswitch/wiki/Writing-tests-in-FreeSWITCH The setup phase for a test suite ensures necessary modules are loaded before tests run. `fst_requires_module` is used to check for module availability, preventing tests from running if dependencies are missing. This ensures a controlled testing environment. ```c FST_SETUP_BEGIN() { fst_requires_module("mod_tone_stream"); fst_requires_module("mod_sndfile"); fst_requires_module("mod_dptools"); fst_requires_module("mod_test"); } FST_SETUP_END() ``` -------------------------------- ### Analyze Assembly Code with Intel IACA Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Analyzes assembly code using Intel Architecture Code Analyzer (IACA). Requires inserting IACA_ASM_START and IACA_ASM_END macros into the assembly code before building. The script then runs IACA on the compiled object file. ```shell ~/iaca-lin64/bin/iaca.sh -reduceout -arch HSW out/Release/obj/libyuv_internal/compare_gcc.o ``` -------------------------------- ### Android ARM Disassembly Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Commands to disassemble object files for ARM architectures on Android using `aarch64-linux-android-objdump`. This can help in analyzing compiled code. A caveat notes that `optimize_max` might need to be disabled in `BUILD.gn`. ```shell third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv/row_common.o >row_common.txt third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv_neon/row_neon.o >row_neon.txt third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objdump -d ./out/Release/obj/libyuv_neon/row_neon64.o >row_neon64.txt ``` -------------------------------- ### Run All Unit Tests (macOS/Linux) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md Executes all unit tests for the libyuv project on macOS and Linux. The `--gtest_filter='*'` argument can be replaced with specific test names or patterns for targeted testing. ```shell out/Release/libyuv_unittest --gtest_filter="*" ``` -------------------------------- ### Build libyuv for iOS (arm64) using GN and Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md These commands show how to set up and build the libyuv library for iOS devices with an arm64 target architecture. It configures GN for iOS, disables code signing, and specifies the target CPU. Finally, it uses Ninja to build the unit tests. ```bash gn gen out/Release "--args=is_debug=false target_os=\"ios\" ios_enable_code_signing=false target_cpu=\"arm64\"" gn gen out/Debug "--args=is_debug=true target_os=\"ios\" ios_enable_code_signing=false target_cpu=\"arm64\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest ``` -------------------------------- ### Build libyuv for iOS Simulator (x86) using GN and Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This snippet details the process of building libyuv for the iOS simulator, targeting the x86 architecture. It configures GN with appropriate flags for the simulator, including enabling Xcode's Clang compiler and disabling code signing. Ninja is then used to build the unit tests. ```bash gn gen out/Release "--args=is_debug=false target_os=\"ios\" ios_enable_code_signing=false use_xcode_clang=true target_cpu=\"x86\"" gn gen out/Debug "--args=is_debug=true target_os=\"ios\" ios_enable_code_signing=false use_xcode_clang=true target_cpu=\"x86\"" ninja -v -C out/Debug libyuv_unittest ninja -v -C out/Release libyuv_unittest ``` -------------------------------- ### Run FreeSWITCH Module Tests Source: https://github.com/signalwire/freeswitch/wiki/Writing-tests-in-FreeSWITCH These commands demonstrate how to execute tests within the FreeSWITCH build environment. After installation, `make check` runs all configured tests. Alternatively, specific test binaries can be executed directly from the `tests/unit` directory, with options to filter tests by a prefix. ```bash make check ``` ```bash cd tests/unit ./switch_ivr_play_say ``` ```bash cd tests/unit ./switch_ivr_play_say play_and_collect_input ``` -------------------------------- ### Build libSRTP project using Meson Source: https://github.com/signalwire/freeswitch/blob/master/libs/srtp/README.md This example illustrates building libSRTP using the Meson build system, which is cross-platform. It involves setting up the build directory with a specified installation prefix and then compiling the project within that directory. Meson simplifies cross-platform builds and dependency management. ```bash # Setup the build subdirectory meson setup --prefix=/path/to/prefix builddir # Build the project meson compile -C builddir ``` -------------------------------- ### Install FreeSWITCH Meta Package (Debian/Ubuntu) Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/README.md Installs the FreeSWITCH meta package, which includes all necessary components for a full FreeSWITCH installation. This command ensures FreeSWITCH is installed if the repository has been configured. ```bash apt-get install -y freeswitch-meta-all ``` -------------------------------- ### Disassemble iOS libyuv object file Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/getting_started.md This command uses the 'otool' utility to disassemble a specific object file (`row_neon64.o`) from the libyuv build output for iOS. The output is redirected to a text file for inspection, which can be useful for debugging or understanding the compiled code. ```bash otool -tV ./out/Release/obj/libyuv_neon/row_neon64.o >row_neon64.txt ``` -------------------------------- ### Configure FreeSWITCH Repository with FSGET Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/README.md Configures the FreeSWITCH repository using the fsget script. Requires a SignalWire Personal Access Token or API Token. Optional arguments allow specifying release type (release/prerelease) and whether to automatically install FreeSWITCH. ```bash curl -sSL https://freeswitch.org/fsget | bash -s [release|prerelease] [install] ``` -------------------------------- ### Define a Test Suite for switch_ivr_play_say Source: https://github.com/signalwire/freeswitch/wiki/Writing-tests-in-FreeSWITCH Defines the beginning of a test suite named 'switch_ivr_play_say'. Test suites group related tests and can have setup and teardown phases. This is used to organize tests for specific functionalities. ```c FST_SUITE_BEGIN(switch_ivr_play_say) { ``` -------------------------------- ### Install FreeSWITCH Portal via Git Clone Source: https://github.com/signalwire/freeswitch/blob/master/htdocs/portal/README.md This snippet shows how to clone the FreeSWITCH Portal project into the FreeSWITCH htdocs directory. It assumes FreeSWITCH is installed in the default location. No specific inputs or outputs are defined beyond the file system operation. ```bash cd /usr/local/freeswitch/htdocs git clone https://github.com/seven1240/FreeSWITCH-Portal.git portal ``` -------------------------------- ### Install libyuv Components with CMake Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/CMakeLists.txt Defines the installation rules for the compiled libyuv components using CMake's INSTALL command. It specifies the destinations for the yuvconvert executable, static and shared libraries, and header files. ```cmake # install the conversion tool, .so, .a, and all the header files INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert DESTINATION bin ) INSTALL ( TARGETS ${ly_lib_static} DESTINATION lib ) INSTALL ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include ) ``` -------------------------------- ### Install Git and Curl Dependencies (Bash) Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/README.md Installs essential build tools, git and curl, using apt-get. These are prerequisites for cloning the FreeSWITCH repository and downloading build scripts. This command is intended for Debian-based systems. ```bash apt-get update apt-get install -y git curl ``` -------------------------------- ### Build and Test FreeSWITCH with Ninja Source: https://github.com/signalwire/freeswitch/blob/master/libs/srtp/README.md Alternative commands to build, test, and install using Ninja, which can replace the Meson commands. ```shell ninja -C build test ninja -C build install ``` -------------------------------- ### Initialize FreeSWITCH Core for Testing Source: https://github.com/signalwire/freeswitch/wiki/Writing-tests-in-FreeSWITCH This snippet shows how to initialize a FreeSWITCH core instance for unit testing. It requires specifying a configuration directory. This is typically the first step in setting up a testing environment. ```c FST_CORE_BEGIN("./conf_playsay") { ``` -------------------------------- ### Build and Test FreeSWITCH with Meson Source: https://github.com/signalwire/freeswitch/blob/master/libs/srtp/README.md Commands to build, test, and optionally install the FreeSWITCH project using Meson. These commands are executed from the build directory. ```shell meson test -C builddir meson install -C builddir ``` -------------------------------- ### Install cURL Dependency (Debian/Ubuntu) Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/README.md Installs the cURL utility, which is a prerequisite for downloading files from the command line. This command updates package lists and installs cURL non-interactively. ```bash apt update && apt install -y curl ``` -------------------------------- ### Enable and Start FreeSWITCH Docker Service Source: https://github.com/signalwire/freeswitch/blob/master/docker/base_image/README.md These commands are used to enable the systemd service for the FreeSWITCH Docker container, ensuring it starts on boot, and to start the service immediately. ```sh systemd start freeswitch-docker.service systemd enable freeswitch-docker.service ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/signalwire-c/README.md Installs the 'libks2' package, which is a dependency for building signalwire-c. ```bash apt-get update && apt-get -y install libks2 ``` -------------------------------- ### FreeSWITCH Channel Call Control Example in C Source: https://context7.com/signalwire/freeswitch/llms.txt Demonstrates complete call control within FreeSWITCH using C. This includes checking channel readiness, getting current state, ringing, pre-answering, answering, checking media status, and hanging up with a specific cause. It requires the FreeSWITCH API headers and session management. ```c // Complete call control example void handle_inbound_call(switch_core_session_t *session) { switch_channel_t *channel; switch_channel_state_t state; switch_call_cause_t cause; channel = switch_core_session_get_channel(session); // Check if channel is in valid state for processing if (!switch_channel_ready(channel)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Channel not ready\n"); return; } // Get current state state = switch_channel_get_state(channel); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Current state: %s\n", switch_channel_state_name(state)); // Send ring indication if (switch_channel_ring_ready(channel) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to ring\n"); return; } // Pre-answer for early media (optional) switch_channel_pre_answer(channel); // Answer the call if (switch_channel_answer(channel) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to answer\n"); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE); return; } // Check if call is up and media is flowing if (switch_channel_media_up(channel)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Media is up\n"); } // Do call processing... // Hangup with specific cause switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); // Get hangup cause cause = switch_channel_get_cause(channel); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Hangup cause: %s (%d)\n", switch_channel_cause2str(cause), cause); } ``` -------------------------------- ### SCGI Example Request and Response Source: https://github.com/signalwire/freeswitch/blob/master/libs/libscgi/protocol.txt Illustrates a typical SCGI interaction. The web server (client) sends a request with headers and a body, and the SCGI server responds with HTTP headers and a body, then closes the connection. This example shows the concatenation of strings for the request and the response format. ```text Web server sends: "70:" "CONTENT_LENGTH" <00> "27" <00> "SCGI" <00> "1" <00> "REQUEST_METHOD" <00> "POST" <00> "REQUEST_URI" <00> "/deepthought" <00> "," "What is the answer to life?" SCGI server sends: "Status: 200 OK" <0d 0a> "Content-Type: text/plain" <0d 0a> "" <0d 0a> "42" ``` -------------------------------- ### Build Documentation with scons Source: https://github.com/signalwire/freeswitch/blob/master/src/mod/event_handlers/mod_cdr_mongodb/driver/README.md Builds the project documentation using scons. Assumes Sphinx and Doxygen are installed. HTML output will be in the docs/html directory. ```shell scons docs ``` -------------------------------- ### Clone signalwire-c Repository Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/signalwire-c/README.md Clones the signalwire-c repository from GitHub. Requires Git to be installed. ```bash git clone git@github.com:signalwire/signalwire-c.git ``` -------------------------------- ### Set up Local File-based Debian Repository Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/signalwire-c/README.md Configures a local file-based Debian repository to install the 'libks' dependency. This involves scanning package files and updating APT sources. ```bash cd OUT/ && dpkg-scanpackages . | tee OUT/Packages && gzip -f OUT/Packages && printf "deb [trusted=yes] file:$(realpath $(pwd)) .//\n" | tee /etc/apt/sources.list.d/local.list ``` ```bash cd /usr/src/OUT/ && dpkg-scanpackages . | tee /usr/src/OUT/Packages && gzip -f /usr/src/OUT/Packages && printf "deb [trusted=yes] file:/usr/src/OUT .//\n" | tee /etc/apt/sources.list.d/local.list ``` -------------------------------- ### Install FreeSWITCH Packages on Debian Source: https://github.com/signalwire/freeswitch/blob/master/docker/base_image/README.md This command installs the necessary FreeSWITCH configuration packages on a Debian-based system, which is a prerequisite for building a custom FreeSWITCH Docker container. ```sh apt-get install freeswitch-conf-vanilla ``` -------------------------------- ### Install FreeSWITCH Debian Repository Dependencies (Bash) Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/README.md Installs FreeSWITCH build dependencies by configuring the FreeSWITCH Community Release Debian repository using the fsget script. This is the recommended method for simplifying dependency management. It requires a SignalWire Personal Access Token (PAT). ```bash curl -sSL https://freeswitch.org/fsget | bash -s ``` -------------------------------- ### Debug and Release Build with CMake Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/deprecated_builds.md Builds the libyuv library using CMake. Demonstrates how to create a debug build and a release build with a specified installation prefix. ```bash # Default debug build mkdir out cd out cmake .. cmake --build . # Release build/install mkdir out cd outcmake -DCMAKE_INSTALL_PREFIX="/usr/lib" -DCMAKE_BUILD_TYPE="Release" .. cmake --build . --config Release sudo cmake --build . --target install --config Release ``` -------------------------------- ### SRTP Sender Example with rtprw Source: https://github.com/signalwire/freeswitch/blob/master/libs/srtp/README.md Example of using the `rtpw` application as an SRTP sender. It demonstrates setting a master key, enabling encryption and authentication, and specifying destination IP and port. ```shell set k=c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 [sh1]$ test/rtpw -s -k $k -e 128 -a 0.0.0.0 9999 Security services: confidentiality message authentication set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451 setting SSRC to 2078917053 sending word: A sending word: a sending word: aa sending word: aal ... ``` -------------------------------- ### Install Debian Build Tools Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/libsilk/README.md Installs essential build tools and development libraries required for compiling software on a Debian-based system. This includes compilers, build utilities, and package management tools. ```bash apt-get update \ && apt-get -y upgrade \ && apt-get -y install \ build-essential \ cmake \ devscripts \ lsb-release \ docbook-xsl \ pkg-config ``` -------------------------------- ### FreeSWITCH HT-TAPI XML Document Structure Example Source: https://github.com/signalwire/freeswitch/blob/master/src/mod/applications/mod_httapi/docs/mod_httapi_doc.txt This example illustrates the basic XML structure expected by the FreeSWITCH HT-TAPI application. It includes sections for parameters, variables, and work directives, which guide the telephony actions. The `type` attribute must be `xml/freeswitch-httapi`. ```xml someval someval <...> ``` -------------------------------- ### Enable FreeSWITCH SSL in vars.xml Source: https://github.com/signalwire/freeswitch/blob/master/docs/how_to_make_your_own_ca_correctly.txt This XML snippet shows how to enable SSL for both internal and external FreeSWITCH interfaces by setting specific variables in the vars.xml configuration file. ```xml ``` -------------------------------- ### Get Expression Error Position - C Source: https://github.com/signalwire/freeswitch/blob/master/src/mod/applications/mod_expr/expreval.html Retrieves the start and end positions of the last parse error within an expression string. The positions account for newline characters. Pointers to integers are provided to store the start and end positions, which will be -1 if unknown. This function returns void. ```c void exprGetErrorPosition(exprObj *obj, int *start, int *end); ``` -------------------------------- ### Mount FreeSWITCH Configuration in Docker Source: https://github.com/signalwire/freeswitch/blob/master/docker/README.md This command mounts the local 'configuration' directory to the '/etc/freeswitch' directory within the Docker container, allowing for persistent configuration management. ```bash -v $(pwd)/configuration:/etc/freeswitch ``` -------------------------------- ### Handling Cropping with Odd Dimensions (NV21 Example) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/rotation.md Strategy for cropping with odd start Y on UV plane for subsampled formats like NV21. ```APIDOC ## Handling Cropping with Odd Dimensions (NV21 Example) ### Description When cropping from subsampled formats like NV21, issues can arise with odd crop start Y coordinates on the UV plane. A robust method involves inverting the source, pointing to the last row, negating strides, and passing a negative height. The conversion process will re-invert the image, resulting in the correct output. ### Method This strategy can be applied to functions that support negative source heights for inversion. ### Procedure 1. **Invert Source**: Set source pointers to the last row of the intended crop area. 2. **Negate Strides**: Provide negative stride values for the source planes. 3. **Pass Negative Height**: Use a negative value for the `crop_height` (or `src_height` in relevant functions) to indicate the inverted source. This ensures that the UV plane is correctly sampled even with odd starting Y coordinates, and the final output is correctly oriented. ### Example Scenario - Cropping NV21 where `crop_y` is odd. - The resulting `crop_height` is also odd. ### Recommended Steps If `crop_y` is odd and `crop_height` will be odd: - Adjust `src_y`, `src_u`, `src_v` pointers to the last row of the crop. - Pass negative strides for the source planes. - Pass a negative `crop_height` to the relevant libyuv function. This will ensure the UV plane is correctly sampled and the output is properly oriented. ``` -------------------------------- ### Configure Apache for FreeSWITCH SSL Source: https://github.com/signalwire/freeswitch/blob/master/docs/how_to_make_your_own_ca_correctly.txt This configuration block shows how to set up Apache's virtual host to use the generated FreeSWITCH SSL certificate for secure web access. ```apache SSLCertificateFile /usr/local/freeswitch/certs/wss.pem SSLCertificateKeyFile /usr/local/freeswitch/certs/wss.pem SSLCertificateChainFile /usr/local/freeswitch/certs/wss.pem ``` -------------------------------- ### Run libyuv Unit Tests with Address Sanitizer (ASan) Source: https://github.com/signalwire/freeswitch/blob/master/libs/libyuv/docs/deprecated_builds.md Builds and runs libyuv unit tests with AddressSanitizer (ASan) enabled for detecting memory access errors. Requires Valgrind and ASan setup. ```shell GYP_DEFINES="clang=0 target_arch=x64 build_for_tool=asan" python gyp_libyuv ninja -C out/Debug valgrind out/Debug/libyuv_unittest ``` -------------------------------- ### Get Parse Error Position Function (C) Source: https://github.com/signalwire/freeswitch/blob/master/src/mod/applications/mod_expr/readme.txt Introduces the `exprGetErrorPosition` function, which retrieves the start and end positions of a parsing error. This is crucial for debugging and providing detailed feedback on syntax issues. ```c /* Added function exprGetErrorPosition to get start and end position of parse error. */ ``` -------------------------------- ### Create FreeSWITCH Module with App and API (C) Source: https://context7.com/signalwire/freeswitch/llms.txt This C code defines a basic loadable FreeSWITCH module. It includes an application function (`example_app_function`) to handle calls and an API function (`example_api_function`) for module management. The module also registers itself, initializes global variables like call count, and handles thread-safe access using mutexes. It demonstrates event creation and firing, channel variable setting, and file playback within the application, and basic command handling for the API. ```c #include // Module metadata SWITCH_MODULE_LOAD_FUNCTION(mod_example_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_example_shutdown); SWITCH_MODULE_DEFINITION(mod_example, mod_example_load, mod_example_shutdown, NULL); // Module globals static struct { switch_memory_pool_t *pool; int call_count; switch_mutex_t *mutex; } globals; // Application function SWITCH_STANDARD_APP(example_app_function) { switch_channel_t *channel = switch_core_session_get_channel(session); const char *arg = data; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Example app called with: %s\n", arg ? arg : "(no data)"); // Increment call count thread-safely switch_mutex_lock(globals.mutex); globals.call_count++; int count = globals.call_count; switch_mutex_unlock(globals.mutex); // Set channel variable switch_channel_set_variable_printf(channel, "example_call_count", "%d", count); // Play audio switch_ivr_play_file(session, NULL, "/sounds/example.wav", NULL); // Send custom event switch_event_t *event = NULL; if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "example::app_executed") == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-UUID", switch_channel_get_uuid(channel)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Call-Count", "%d", count); switch_event_fire(&event); } } // API function SWITCH_STANDARD_API(example_api_function) { if (!zstr(cmd)) { if (!strcasecmp(cmd, "count")) { stream->write_function(stream, "+OK %d\n", globals.call_count); } else if (!strcasecmp(cmd, "reset")) { switch_mutex_lock(globals.mutex); globals.call_count = 0; switch_mutex_unlock(globals.mutex); stream->write_function(stream, "+OK count reset\n"); } else { stream->write_function(stream, "-ERR Unknown command: %s\n", cmd); } } else { stream->write_function(stream, "-ERR No command specified\n"); } return SWITCH_STATUS_SUCCESS; } // Module load SWITCH_MODULE_LOAD_FUNCTION(mod_example_load) { switch_application_interface_t *app_interface; switch_api_interface_t *api_interface; // Initialize globals memset(&globals, 0, sizeof(globals)); globals.pool = pool; switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool); // Reserve custom event subclass if (switch_event_reserve_subclass("example::app_executed") != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to reserve event subclass\n"); return SWITCH_STATUS_TERM; } // Connect module interface *module_interface = switch_loadable_module_create_module_interface(pool, modname); // Register application SWITCH_ADD_APP(app_interface, "example_app", // app name "Example Application", // short desc "Demonstrates module development", // long desc example_app_function, // function "[data]", // syntax SAF_SUPPORT_NOMEDIA); // flags // Register API SWITCH_ADD_API(api_interface, "example_api", // API name "Example API", // description example_api_function, // function ""); // syntax switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Module loaded successfully\n"); return SWITCH_STATUS_SUCCESS; } // Module shutdown SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_example_shutdown) { // Free custom event subclass switch_event_free_subclass("example::app_executed"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Module shutdown (handled %d calls)", globals.call_count); return SWITCH_STATUS_SUCCESS; } ``` -------------------------------- ### Start a Test Session for IVR Input Collection Source: https://github.com/signalwire/freeswitch/wiki/Writing-tests-in-FreeSWITCH Initiates a test case named 'play_and_collect_input_failure' that involves a FreeSWITCH session. This automatically provides essential session-related variables like `fst_session` and `fst_channel`. It's used for testing functions that interact with a call session. ```c FST_SESSION_BEGIN(play_and_collect_input_failure) { ``` -------------------------------- ### Apply GNU AGPL v3 License to New Programs Source: https://github.com/signalwire/freeswitch/blob/master/docs/zrtp_agpl-3.0.txt This code snippet demonstrates how to apply the GNU Affero General Public License v3 (or later) to a new program. It includes the standard copyright notice, license terms, warranty disclaimer, and a link to the official license. This is typically added to the beginning of each source file. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . ``` -------------------------------- ### Build V8 Binaries Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/libv8/README.md Clones the `depot_tools`, synchronizes the V8 source code to the specified git version, configures the build using `gn`, and then compiles the `d8` binary. This step downloads and builds the V8 engine. ```bash git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git \ && gclient sync --verbose -r $V8_GIT_VERSION \ && cd v8 \ && gn gen out.gn --args="is_debug=true symbol_level=2 blink_symbol_level=1 v8_symbol_level=1 v8_static_library=true is_component_build=false v8_enable_i18n_support=false v8_use_external_startup_data=false" \ && gn args out.gn --list | tee out.gn/gn_args.txt \ && ninja -v d8 -C out.gn \ && cd $BUILD_DIR ``` -------------------------------- ### Build Google Test using GNU Make Source: https://github.com/signalwire/freeswitch/blob/master/libs/libvpx/third_party/googletest/src/README.md This shows the process of building Google Test using a provided Makefile, typically found in the `make/` directory. It assumes GNU Make is available on the system. Running 'make' will compile the Google Test library and a sample test executable. The output can be customized by modifying the `make/Makefile`. ```bash cd ${GTEST_DIR}/make make ./sample1_unittest ``` -------------------------------- ### Install and Set Global Python Version with pyenv Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/libv8/README.md Installs the specified Python version using `pyenv` and sets it as the global default Python interpreter. Requires `pyenv` to be installed and configured. ```bash pyenv install $PYTHON_VERSION \ && pyenv global $PYTHON_VERSION ``` -------------------------------- ### SRTP Receiver Example with rtprw Source: https://github.com/signalwire/freeswitch/blob/master/libs/srtp/README.md Example of using the `rtpw` application as an SRTP receiver. It mirrors the sender example, showing how to use the same key and security parameters to receive encrypted and authenticated data. ```shell [sh2]$ test/rtpw -r -k $k -e 128 -a 0.0.0.0 9999 security services: confidentiality message authentication set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451 19 octets received from SSRC 2078917053 word: A 19 octets received from SSRC 2078917053 word: a 20 octets received from SSRC 2078917053 word: aa 21 octets received from SSRC 2078917053 word: aal ... ``` -------------------------------- ### Build Google Test with Xcode Command Line Source: https://github.com/signalwire/freeswitch/blob/master/libs/libvpx/third_party/googletest/src/README.md Builds the Google Test framework using the 'xcodebuild' command-line tool on macOS. This generates a universal binary framework in the default build location. Refer to the 'xcodebuild' man page for advanced options. ```shell xcodebuild ``` -------------------------------- ### Install Debian Build Dependencies Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/libsilk/README.md Installs the build dependencies required for the libsilk package using `mk-build-deps`. It first updates the package list, then installs dependencies based on the debian/control file, and finally attempts to fix any broken dependencies. ```bash apt-get update \ && mk-build-deps \ --install \ --remove debian/control \ --tool "apt-get -y --no-install-recommends" \ && apt-get -y -f install ``` -------------------------------- ### Build Binary Package Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/signalwire-c/README.md Configures the build using CMake and then builds the binary Debian package. Sets CMAKE_BUILD_TYPE to Debug and CMAKE_INSTALL_PREFIX to /usr. ```bash PACKAGE_RELEASE="${BUILD_NUMBER}.${GIT_SHA}" cmake . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="/usr" && make package ``` -------------------------------- ### Install Build Dependencies for libks Source: https://github.com/signalwire/freeswitch/blob/master/scripts/packaging/build/dependencies/libks/README.md This command installs specific development libraries required for building libks, namely libssl-dev and uuid-dev. It first updates the package list. ```bash apt-get update \ && apt-get -y install \ libssl-dev \ uuid-dev ```