From fb988c9226179054d098d9a8758cbff3c7182330 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 30 Dec 2024 13:29:29 -0700 Subject: [PATCH] remove unused files Signed-off-by: Stephen Gutekanst --- autogen.bat | 13 - lpcnet_headers.mk | 44 ---- lpcnet_sources.mk | 44 ---- meson/README.md | 88 ------- scripts/local_build.py | 220 ---------------- scripts/shrink_model.sh | 7 - tar_list.txt | 28 -- tests/test_opus_dred.c | 107 -------- tests/test_opus_extensions.c | 482 ----------------------------------- 9 files changed, 1033 deletions(-) delete mode 100644 autogen.bat delete mode 100644 lpcnet_headers.mk delete mode 100644 lpcnet_sources.mk delete mode 100644 meson/README.md delete mode 100755 scripts/local_build.py delete mode 100755 scripts/shrink_model.sh delete mode 100644 tar_list.txt delete mode 100644 tests/test_opus_dred.c delete mode 100644 tests/test_opus_extensions.c diff --git a/autogen.bat b/autogen.bat deleted file mode 100644 index b7c735b1..00000000 --- a/autogen.bat +++ /dev/null @@ -1,13 +0,0 @@ -@echo off -REM Run this to set up the build system: configure, makefiles, etc. - -setlocal enabledelayedexpansion - -REM Parse the real autogen.sh script for version -for /F "tokens=2 delims= " %%A in ('findstr "dnn/download_model.sh" autogen.sh') do ( - set "model=%%A" -) - -call dnn\download_model.bat %model% - -echo Updating build configuration files, please wait.... diff --git a/lpcnet_headers.mk b/lpcnet_headers.mk deleted file mode 100644 index 520274d7..00000000 --- a/lpcnet_headers.mk +++ /dev/null @@ -1,44 +0,0 @@ -DEEP_PLC_HEAD = \ -dnn/lpcnet.h \ -dnn/burg.h \ -dnn/common.h \ -dnn/freq.h \ -dnn/fargan.h \ -dnn/fargan_data.h \ -dnn/lpcnet_private.h \ -dnn/nnet.h \ -dnn/plc_data.h \ -dnn/vec.h \ -dnn/vec_avx.h \ -dnn/vec_neon.h \ -dnn/pitchdnn.h \ -dnn/pitchdnn_data.h \ -dnn/x86/dnn_x86.h \ -dnn/nnet_arch.h \ -dnn/arm/dnn_arm.h - -DRED_HEAD = \ -dnn/dred_coding.h \ -dnn/dred_config.h \ -dnn/dred_decoder.h \ -dnn/dred_encoder.h \ -dnn/dred_rdovae.h \ -dnn/dred_rdovae_constants.h \ -dnn/dred_rdovae_enc.h \ -dnn/dred_rdovae_enc_data.h \ -dnn/dred_rdovae_dec.h \ -dnn/dred_rdovae_dec_data.h \ -dnn/dred_rdovae_stats_data.h - -OSCE_HEAD= \ -dnn/osce.h \ -dnn/osce_config.h \ -dnn/osce_structs.h \ -dnn/osce_features.h \ -dnn/nndsp.h \ -dnn/lace_data.h \ -dnn/nolace_data.h - -LOSSGEN_HEAD = \ -dnn/lossgen.h \ -dnn/lossgen_data.h diff --git a/lpcnet_sources.mk b/lpcnet_sources.mk deleted file mode 100644 index 991a4109..00000000 --- a/lpcnet_sources.mk +++ /dev/null @@ -1,44 +0,0 @@ -DEEP_PLC_SOURCES = \ -dnn/burg.c \ -dnn/freq.c \ -dnn/fargan.c \ -dnn/fargan_data.c \ -dnn/lpcnet_enc.c \ -dnn/lpcnet_plc.c \ -dnn/lpcnet_tables.c \ -dnn/nnet.c \ -dnn/nnet_default.c \ -dnn/plc_data.c \ -dnn/parse_lpcnet_weights.c \ -dnn/pitchdnn.c \ -dnn/pitchdnn_data.c - -DRED_SOURCES = \ -dnn/dred_rdovae_enc.c \ -dnn/dred_rdovae_enc_data.c \ -dnn/dred_rdovae_dec.c \ -dnn/dred_rdovae_dec_data.c \ -dnn/dred_rdovae_stats_data.c \ -dnn/dred_encoder.c \ -dnn/dred_coding.c \ -dnn/dred_decoder.c - -OSCE_SOURCES = \ -dnn/osce.c \ -dnn/osce_features.c \ -dnn/nndsp.c \ -dnn/lace_data.c \ -dnn/nolace_data.c - -LOSSGEN_SOURCES = \ -dnn/lossgen.c \ -dnn/lossgen_data.c - -DNN_SOURCES_X86_RTCD = dnn/x86/x86_dnn_map.c -DNN_SOURCES_AVX2 = dnn/x86/nnet_avx2.c -DNN_SOURCES_SSE4_1 = dnn/x86/nnet_sse4_1.c -DNN_SOURCES_SSE2 = dnn/x86/nnet_sse2.c - -DNN_SOURCES_ARM_RTCD = dnn/arm/arm_dnn_map.c -DNN_SOURCES_DOTPROD = dnn/arm/nnet_dotprod.c -DNN_SOURCES_NEON = dnn/arm/nnet_neon.c diff --git a/meson/README.md b/meson/README.md deleted file mode 100644 index 08f426b2..00000000 --- a/meson/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# Using the Meson Build System for the Opus Project - -This guide provides instructions for using the Meson build system to build the Opus project with various configuration options. Meson is a fast and efficient build system that aims to be easy to use and understand. - -Please note that software documentation can sometimes become outdated as new versions are released. For the most up-to-date and accurate information, we recommend referring to the official Meson documentation, which can be found at [mesonbuild.com](https://mesonbuild.com/). - -## Prerequisites - -Before proceeding, ensure that you have the following prerequisites installed: - -- [Meson](https://mesonbuild.com/Quick-guide.html) -- [Ninja](https://ninja-build.org/) (recommended as the build backend, although other backends are also available) -- [Git](https://git-scm.com/) (optional, but recommended for version control integration) -- A working C compiler - -## Build and Test Instructions - -Follow the steps below to build the Opus project using Meson. - -### Check out Source -Clone the Opus repository using Git: - -```shell -git clone https://gitlab.xiph.org/xiph/opus -cd opus -``` - -### Configure -To configure the build with Meson, you can set the desired configuration options using the -D flag followed by the option name and value. For the Opus project-specific build options, please refer to the [meson_options.txt](./../meson_options.txt) file. For general Meson options use the command meson `setup --help` to get a list of these options. - -For example, to setup and disable tests, use the following command: - -```shell -meson setup builddir -Dtests=disabled -``` - -### Build - -```shell -meson compile -C builddir -``` - -After a successful build, you can find the compiled Opus library and associated files in the builddir directory. - -### Testing with Meson - -Opus provides a comprehensive test suite to ensure the functionality and correctness of the project. You can execute the tests using Meson's built-in testing functionality. - -To run the Opus tests using Meson: - -```shell -meson test -C builddir -``` - -## Platform Support and Bug Reporting - -The Opus Meson build system aims to provide support for the same platforms as [GStreamer](https://gstreamer.freedesktop.org/), a widely used multimedia framework. GStreamer supports a wide range of operating systems and platforms, including Linux, Windows (MSVC and MingW), Android, macOS, iOS, and various BSD systems. - -While efforts are made to ensure compatibility and stability across these platforms, bugs or issues may still arise in specific configurations. If you encounter any problems during the configuration process or while building the Opus project, we encourage you to file an issue in the [project's issue tracker](https://gitlab.xiph.org/xiph/opus/-/issues). - -When reporting an issue, please provide the following information to help us understand and effectively reproduce the configuration problem: - -1. Detailed description of the issue, including any error messages or unexpected behavior observed. -2. Steps to reproduce the problem, including the Meson command and any specific configuration options used. -3. Operating system and version (e.g., Windows 10, macOS Big Sur, Ubuntu 20.04). -4. Meson version (e.g., Meson 0.60.0). -5. Any relevant information about the platform, toolchain, or dependencies used. -6. Additional context or details that might assist in troubleshooting the issue. - -By providing thorough information when reporting configuration issues, you contribute to improving the Opus project's compatibility and reliability across different platforms. - -We appreciate your help in identifying and addressing any configuration-related problems, ensuring a better experience for all users of the Opus project. - -## Platform Specific Examples - -Note: Examples can become outdated. Always refer to the documentation for the latest reference. - -### Windows Visual Studio - -To generate Visual Studio projects, Meson needs to know the settings of your installed version of Visual Studio. The recommended approach is to run Meson under the Visual Studio Command Prompt. - -You can find the Visual Studio Command Prompt by searching from the Start Menu. However, the name varies for each Visual Studio version. For Visual Studio 2022, look for "x64 Native Tools Command Prompt for VS 2022". The following steps remain the same: - -```shell -meson setup builddir -Dtests=enabled --backend vs -``` - -For more information about the Visual Studio backend options and additional customization, please refer to the [Using with Visual Studio](https://mesonbuild.com/Using-with-Visual-Studio.html) documentation. \ No newline at end of file diff --git a/scripts/local_build.py b/scripts/local_build.py deleted file mode 100755 index ff19922b..00000000 --- a/scripts/local_build.py +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/python3 - -""" -This script tries to build a project with CMake, Meson, and Autotools. -It checks if CMake, Meson, and Autotools are installed, and performs -the configure, build, and optionally test steps for each build system. -""" - -import multiprocessing -import os -import random -import string -import subprocess -import sys -import shutil - - -if sys.platform == "win32": - REPO_DIR = "\\".join(os.path.abspath(__file__).split("\\")[:-2]) -else: - REPO_DIR = "/".join(os.path.abspath(__file__).split("/")[:-2]) - - -def main(): - import argparse - parser = argparse.ArgumentParser() - parser.add_argument("--test", action="store_true", help="Run tests") - parser.add_argument("--cmake", action="store_true", help="Only run CMake") - parser.add_argument("--meson", action="store_true", help="Only run Meson") - if sys.platform != "win32": - parser.add_argument("--autotools", action="store_true", help="Only run Autotools") - args = parser.parse_args() - - test = args.test - cmake_only = args.cmake - meson_only = args.meson - if sys.platform != "win32": - autotools_only = args.autotools - autotools_only = False - - result = [] - os.chdir(REPO_DIR) - - # download model - if sys.platform == "win32": - run_command("autogen.bat") - else: - run_command("./autogen.sh") - - if sys.platform != "win32" and not cmake_only and not meson_only: - result += autotools_build(test) - - if not autotools_only and not meson_only: - result += cmake_build(test) - result += cmake_build(test, extra_options="-DOPUS_NEURAL_FEC=ON") - - if not autotools_only and not cmake_only: - result += meson_build(test) - - print_result(result, test) - -def print_result(result, test=False): - if len(result) == 0: - print("No results available") - return - - headers = ["Name", "Build Passed"] - if test: - headers.append("Test Passed") - - # Calculate the maximum width for each column - column_widths = [max(len(str(row[i])) for row in result) for i in range(len(headers))] - - # Print the headers - header_row = " | ".join(f"{header: <{column_widths[i]}}" for i, header in enumerate(headers)) - print(header_row) - print("-" * len(header_row)) - - # Print the data rows - for row in result: - row_values = [str(value) for value in row[:len(headers)]] # Include values up to the last column to be printed - row_string = " | ".join(f"{row_values[i]: <{column_widths[i]}}" for i in range(len(headers))) - print(row_string) - -def autotools_build(test=False): - build = "Autotools" - autotools_build_succeeded = False - autotools_test_succeeded = False - - if not check_tool_installed("autoreconf") or not check_tool_installed("automake") or not check_tool_installed("autoconf"): - print("Autotools dependencies are not installed. Aborting.") - print("Install with: sudo apt-get install git autoconf automake libtool gcc make") - return [(build, autotools_build_succeeded, autotools_test_succeeded)] - - run_command("./configure") - if run_command("make -j {}".format(get_cpu_core_count())) == 0: - autotools_build_succeeded = True - if test: - if run_command("make check -j {}".format(get_cpu_core_count())) == 0: - autotools_test_succeeded = True - - return [(build, autotools_build_succeeded, autotools_test_succeeded)] - - -def cmake_build(test=False, extra_options=""): - cmake_build_succeeded = False - cmake_test_succeeded = False - build = "CMake" - - if not check_tool_installed("cmake"): - print("CMake is not installed. Aborting.") - if sys.platform != "win32": - print("Install with: sudo apt install cmake") - else: - print("Download and install from: https://cmake.org/download/") - return [(build, cmake_build_succeeded, cmake_test_succeeded)] - - if not check_tool_installed("ninja"): - print("Ninja is not installed. Aborting.") - if sys.platform != "win32": - print("Install with: sudo apt ninja-build ") - else: - print("Download and install from: https://ninja-build.org/") - return [(build, cmake_build_succeeded, cmake_test_succeeded)] - - cmake_build_dir = create_dir_with_random_postfix("cmake-build") - cmake_cfg_cmd = ["cmake", "-S" ".", "-B", cmake_build_dir, "-G", '"Ninja"', "-DCMAKE_BUILD_TYPE=Release", "-DOPUS_BUILD_TESTING=ON", "-DOPUS_BUILD_PROGRAMS=ON", "-DOPUS_FAST_MATH=ON", "-DOPUS_FLOAT_APPROX=ON"] - cmake_cfg_cmd += [option for option in extra_options.split(" ")] - run_command(" ".join(cmake_cfg_cmd)) - cmake_build_cmd = ["cmake", "--build", cmake_build_dir, "-j", "{}".format(get_cpu_core_count())] - cmake_test_cmd = ["ctest", "-j", "{}".format(get_cpu_core_count())] - if sys.platform == "win32": - cmake_build_cmd += ["--config", "Release"] - cmake_test_cmd += ["-C", "Release"] - - if run_command(" ".join(cmake_build_cmd)) == 0: - cmake_build_succeeded = True - - if test: - os.chdir(cmake_build_dir) - if run_command(" ".join(cmake_test_cmd)) == 0: - cmake_test_succeeded = True - os.chdir(REPO_DIR) - - shutil.rmtree(cmake_build_dir) - - if extra_options != "": - build += " with options: " - build += extra_options.replace("-D", "") - return [(build, cmake_build_succeeded, cmake_test_succeeded)] - -def meson_build(test=False, extra_options=""): - build = "Meson" - meson_build_succeeded = False - meson_test_succeeded = False - - if not check_tool_installed("meson"): - print("Meson is not installed. Aborting.") - print("Install with: pip install meson") - return [(build, meson_build_succeeded, meson_test_succeeded)] - - if not check_tool_installed("ninja"): - print("Ninja is not installed. Aborting.") - if sys.platform != "win32": - print("Install with: sudo apt ninja-build ") - else: - print("Download and install from: https://ninja-build.org/") - return [(build, meson_build_succeeded, meson_test_succeeded)] - - meson_build_dir = create_dir_with_random_postfix("meson-build") - meson_cfg_cmd = ["meson", "setup", meson_build_dir] - meson_cfg_cmd += [option for option in extra_options.split(" ")] - run_command(" ".join(meson_cfg_cmd)) - meson_build_cmd = ["meson", "compile", "-C", meson_build_dir] - meson_test_cmd = ["meson", "test", "-C", meson_build_dir] - - if run_command(" ".join(meson_build_cmd)) == 0: - meson_build_succeeded = True - - if test: - os.chdir(meson_build_dir) - if run_command(" ".join(meson_test_cmd)) == 0: - meson_test_succeeded = True - os.chdir(REPO_DIR) - - shutil.rmtree(meson_build_dir) - - if extra_options != "": - build += " with options: " - build += extra_options.replace("-D", "") - return [(build, meson_build_succeeded, meson_test_succeeded)] - -def create_dir_with_random_postfix(dir): - random_chars = "".join(random.choices(string.ascii_letters, k=3)) - dir = dir + "-" + random_chars - dir = os.path.join(os.getcwd(), dir) - os.makedirs(dir) - return dir - -def check_tool_installed(tool): - if sys.platform == "win32": - try: - # Use the "where" command to search for the executable - subprocess.check_output(["where", tool], shell=True) - return True - except subprocess.CalledProcessError: - return False - else: - return run_command(f"command -v {tool}") == 0 - -def run_command(command): - process = subprocess.Popen(command, shell=True) - process.communicate() - return process.returncode - -def get_cpu_core_count(): - return int(max(multiprocessing.cpu_count(), 1)) - -if __name__ == "__main__": - main() diff --git a/scripts/shrink_model.sh b/scripts/shrink_model.sh deleted file mode 100755 index c79a2d59..00000000 --- a/scripts/shrink_model.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -for i in fargan_data.c pitchdnn_data.c dred_rdovae_dec_data.c dred_rdovae_enc_data.c plc_data.c lace_data.c nolace_data.c -do - cat dnn/$i | perl -ne 'if (/DEBUG/ || /#else/) {$skip=1} if (!$skip && !/ifdef DOT_PROD/) {s/^ *//; s/, /,/g; print $_} elsif (/endif/) {$skip=0}' > tmp_data.c - mv tmp_data.c dnn/$i -done diff --git a/tar_list.txt b/tar_list.txt deleted file mode 100644 index 67382dbf..00000000 --- a/tar_list.txt +++ /dev/null @@ -1,28 +0,0 @@ -dnn/models/lace_v2.pth -dnn/models/nolace_v2.pth -dnn/models/nolace_192_v2.pth -dnn/models/nolace_160_v2.pth -dnn/models/fargan48bbr_adv_50.pth -dnn/models/rdovae_sparse5m_32.pth -dnn/models/plc4ar_16.pth -dnn/models/pitch_vsmallconv1.pth -dnn/models/lossgen3_2000.pth -dnn/lace_data.c -dnn/lace_data.h -dnn/nolace_data.c -dnn/nolace_data.h -dnn/fargan_data.c -dnn/fargan_data.h -dnn/pitchdnn_data.c -dnn/pitchdnn_data.h -dnn/plc_data.c -dnn/plc_data.h -dnn/dred_rdovae_constants.h -dnn/dred_rdovae_stats_data.h -dnn/dred_rdovae_enc_data.h -dnn/dred_rdovae_stats_data.c -dnn/dred_rdovae_dec_data.h -dnn/dred_rdovae_enc_data.c -dnn/dred_rdovae_dec_data.c -dnn/lossgen_data.c -dnn/lossgen_data.h diff --git a/tests/test_opus_dred.c b/tests/test_opus_dred.c deleted file mode 100644 index 432b84a3..00000000 --- a/tests/test_opus_dred.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (c) 2023 Amazon - Written by Michael Klingbeil */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#ifndef _WIN32 -#include -#else -#include -#define getpid _getpid -#endif - -/* including sources directly to test internal APIs */ -#define CELT_C /* to make celt_assert work */ -#include "opus.h" -#include "test_opus_common.h" - - - -#define NB_RANDOM_EXTENSIONS 10000000 -#define MAX_EXTENSION_SIZE 200 -#define MAX_NB_EXTENSIONS 100 - -void test_random_dred(void) -{ - int error; - int i; - OpusDREDDecoder *dred_dec; - OpusDRED *dred; - dred_dec = opus_dred_decoder_create(&error); - expect_true(error == OPUS_OK, "opus_dred_decoder_create() failed"); - dred = opus_dred_alloc(&error); - expect_true(error == OPUS_OK, "opus_dred_create() failed"); - for (i=0;i 0) - { - res2 = opus_dred_process(dred_dec, dred, dred); - expect_true(res2 == OPUS_OK, "process should succeed if parse succeeds"); - expect_true(res1 >= dred_end, "end before beginning"); - } - } - opus_dred_free(dred); - opus_dred_decoder_destroy(dred_dec); -} - -int main(int argc, char **argv) -{ - int env_used; - char *env_seed; - env_used=0; - env_seed=getenv("SEED"); - if(argc>1)iseed=atoi(argv[1]); - else if(env_seed) - { - iseed=atoi(env_seed); - env_used=1; - } - else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); - Rw=Rz=iseed; - - fprintf(stderr,"Testing dred. Random seed: %u (%.4X)\n", iseed, fast_rand() % 65535); - if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed); - - test_random_dred(); - fprintf(stderr,"Tests completed successfully.\n"); - return 0; -} diff --git a/tests/test_opus_extensions.c b/tests/test_opus_extensions.c deleted file mode 100644 index 2db72c43..00000000 --- a/tests/test_opus_extensions.c +++ /dev/null @@ -1,482 +0,0 @@ -/* Copyright (c) 2023 Amazon - Written by Michael Klingbeil */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#ifndef _WIN32 -#include -#else -#include -#define getpid _getpid -#endif - -#include "../src/opus_private.h" -#include "test_opus_common.h" - -void test_extensions_generate_success(void) -{ - static const opus_extension_data ext[] = { - {2, 0, (const unsigned char *)"a", 1}, - {32, 10, (const unsigned char *)"DRED", 4}, - {33, 1, (const unsigned char *)"NOT DRED", 8}, - {3, 4, (const unsigned char *)NULL, 0} - }; - - int result; - unsigned char packet[32]; - const unsigned char *p = packet; - result = opus_packet_extensions_generate(packet, 23+4, ext, 4, 1); - expect_true(result == 23+4, "expected length 23+4"); - - /* expect padding */ - expect_true(p[0] == 1 && p[1] == 1 && p[2] == 1 && p[3] == 1, "expected padding"); - p += 4; - - /* extension ID=2 */ - expect_true((p[0] >> 1) == 2, "expected extension id 2"); - /* For extension IDs 1 through 31, L=0 means that no data follows the - extension, whereas L=1 means that exactly one byte of extension data follows. */ - expect_true((p[0] & 0x01) == 1, "expected L-bit set"); - /* content */ - expect_true(p[1] == 'a', "expected extension content"); - p += 2; - - /* next byte should increment the frame count, ID=1, L=0 */ - expect_true(p[0] == 0x02, "bad frame separator"); - p += 1; - /* extension ID=33 */ - expect_true((p[0] >> 1) == 33, "expected extension id 33"); - /* For IDs 32 to 127, L=0 signals that the extension data takes up the - rest of the padding, and L=1 signals that a length indicator follows. */ - expect_true((p[0] & 0x01) == 1, "expected L-bit set"); - /* content */ - expect_true(p[1] == ext[2].len, "expected length"); - p += 2; - expect_true(0 == memcmp(p, ext[2].data, ext[2].len), "expected extension content"); - p += ext[2].len; - - /* advance to frame 4, increment by 3 */ - /* next byte should increment the frame count, ID=1, L=1 */ - expect_true(p[0] == 0x03, "bad frame separator"); - expect_true(p[1] == 0x03, "bad frame increment"); - p += 2; - /* extension ID=3 */ - expect_true((p[0] >> 1) == 3, "expected extension id 3"); - /* For extension IDs 1 through 31, L=0 means that no data follows the - extension, whereas L=1 means that exactly one byte of extension data follows. */ - expect_true((p[0] & 0x01) == 0, "expected L-bit unset"); - p += 1; - - /* advance to frame 10, increment by 6 */ - /* next byte should increment the frame count, ID=1, L=1 */ - expect_true(p[0] == 0x03, "bad frame separator"); - expect_true(p[1] == 0x06, "bad frame increment"); - p += 2; - /* extension ID=32 */ - expect_true((p[0] >> 1) == 32, "expected extension id 32"); - /* For IDs 32 to 127, L=0 signals that the extension data takes up the - rest of the padding */ - expect_true((p[0] & 0x01) == 0, "expected L-bit unset"); - p += 1; - expect_true(0 == memcmp(p, ext[1].data, ext[1].len), "expected extension content"); -} - -void test_extensions_generate_zero(void) -{ - int result; - unsigned char packet[32]; - - /* zero length packet, zero extensions */ - result = opus_packet_extensions_generate(packet, 0, NULL, 0, 1); - expect_true(result == 0, "expected length 0"); -} - -void test_extensions_generate_no_padding(void) -{ - static const opus_extension_data ext[] = { - {2, 0, (const unsigned char *)"a", 1}, - {32, 10, (const unsigned char *)"DRED", 4}, - {33, 1, (const unsigned char *)"NOT DRED", 8}, - {3, 4, (const unsigned char *)NULL, 0} - }; - - int result; - unsigned char packet[32]; - result = opus_packet_extensions_generate(packet, sizeof(packet), ext, 4, 0); - expect_true(result == 23, "expected length 23"); -} - -void test_extensions_generate_fail(void) -{ - static const opus_extension_data ext[] = { - {2, 0, (const unsigned char *)"a", 1}, - {32, 10, (const unsigned char *)"DRED", 4}, - {33, 1, (const unsigned char *)"NOT DRED", 8}, - {3, 4, (const unsigned char *)NULL, 0} - }; - - int result; - unsigned char packet[100]; - - /* buffer too small */ - { - opus_int32 len; - /* this failure can occur at lots of points, so iterate to check as many - as possible */ - for (len=0;len<23;len++) - { - size_t i; - for (i=len;i= 0 && ext_out[j].frame < 48, "expected frame between 0 and 47"); - expect_true(ext_out[j].id >= 2 && ext_out[j].id <= 127, "expected id between 2 and 127"); - expect_true(ext_out[j].data >= payload && ext_out[j].data+ext_out[j].len <= payload+len, "expected data to be within packet"); - } - } -} - -void test_opus_repacketizer_out_range_impl(void) -{ - OpusRepacketizer rp; - unsigned char packet[1024]; - unsigned char packet_out[1024]; - opus_int16 size[48]; - const unsigned char *padding; - opus_int32 padding_len; - opus_extension_data ext_out[10]; - int i; - int nb_ext; - int res, len; - int first_count = 0, second_count = 0; - static const opus_extension_data ext[] = { - {33, 0, (const unsigned char *)"abcdefg", 7}, - {100, 0, (const unsigned char *)"uvwxyz", 6}, - }; - - opus_repacketizer_init(&rp); - - memset(packet, 0, sizeof(packet)); - /* Hybrid Packet with 20 msec frames, Code 3 */ - packet[0] = (15 << 3) | 3; - /* Code 3, padding bit set, 1 frame */ - packet[1] = 1 << 6 | 1; - packet[2] = 0; - packet[3] = 0; - - /* generate 2 extensions, id 33 and 100 */ - len = opus_packet_extensions_generate(&packet[4], sizeof(packet)-4, ext, 2, 0); - /* update the padding length */ - packet[2] = len; - - /* concatenate 3 frames */ - res = opus_repacketizer_cat(&rp, packet, 4+len); - /* for the middle frame, no padding, no extensions */ - packet[1] = 1; - res = opus_repacketizer_cat(&rp, packet, 4); - /* switch back to extensions for the last frame extensions */ - packet[1] = 1 << 6 | 1; - res = opus_repacketizer_cat(&rp, packet, 4+len); - - expect_true(rp.nb_frames == 3, "Expected 3 frames"); - res = opus_repacketizer_out_range_impl(&rp, - 0, 3, /* begin, end */ - packet_out, /* unsigned char *data */ - sizeof(packet_out), /* opus_int32 maxlen */ - 0, /*int self_delimited */ - 0, /* int pad */ - NULL, /* const opus_extension_data *extensions */ - 0 /* int nb_extensions */); - expect_true(res > 0, "expected valid packet length"); - - /* now verify that we have the expected extensions */ - res = opus_packet_parse_impl(packet_out, res, 0, NULL, NULL, size, - NULL, NULL, &padding, &padding_len); - nb_ext = 10; - res = opus_packet_extensions_parse(padding, padding_len, ext_out, &nb_ext); - expect_true(nb_ext == 4, "Expected 4 extensions"); - for (i = 0 ; i < nb_ext; i++) - { - if (ext_out[i].id == 33) - { - opus_test_assert(ext_out[i].len == ext[0].len); - opus_test_assert(0 == memcmp(ext_out[i].data, ext[0].data, ext[0].len)); - first_count++; - } - else if (ext_out[i].id == 100) - { - opus_test_assert(ext_out[i].len == ext[1].len); - opus_test_assert(0 == memcmp(ext_out[i].data, ext[1].data, ext[1].len)); - second_count++; - } - if (i < 2) - opus_test_assert(ext_out[i].frame == 0) - else - opus_test_assert(ext_out[i].frame == 2) - } - opus_test_assert(first_count == 2); - opus_test_assert(second_count == 2); -} - -int main(int argc, char **argv) -{ - int env_used; - char *env_seed; - env_used=0; - env_seed=getenv("SEED"); - if(argc>1)iseed=atoi(argv[1]); - else if(env_seed) - { - iseed=atoi(env_seed); - env_used=1; - } - else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); - Rw=Rz=iseed; - - fprintf(stderr,"Testing extensions. Random seed: %u (%.4X)\n", iseed, fast_rand() % 65535); - if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed); - - test_extensions_generate_success(); - test_extensions_generate_zero(); - test_extensions_generate_no_padding(); - test_extensions_generate_fail(); - test_extensions_parse_success(); - test_extensions_parse_zero(); - test_extensions_parse_fail(); - test_random_extensions_parse(); - test_opus_repacketizer_out_range_impl(); - fprintf(stderr,"Tests completed successfully.\n"); - return 0; -}