diff --git a/.circleci/config.yml b/.circleci/config.yml index 3961181..c4c16a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: heliconwave/cplusplusdev:latest + - image: heliconwave/circleci-ubuntu-18.04:latest steps: - checkout - setup_remote_docker: @@ -12,7 +12,7 @@ jobs: command: lsb_release -a - run: name: Build CMake Debug - command: mkdir Debug && cd Debug/ && cmake -DCMAKE_BUILD_TYPE=Debug .. && cmake --build . -- -j$(nproc) + command: mkdir Debug && cd Debug/ && cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=ON .. && cmake --build . -- -j$(nproc) - run: name: Build CMake Release command: mkdir Release && cd Release/ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES -DENABLE_TESTS=OFF .. && cmake --build . -- -j$(nproc) @@ -28,7 +28,41 @@ jobs: cat CPackConfig.cmake && cpack --config CPackConfig.cmake - store_artifacts: - path: /root/project/mpeg2ts-0.5.0-Linux.tar.gz + path: /root/project/mpeg2ts-0.6.0-Linux.tar.gz + - persist_to_workspace: + root: /root/project + paths: + - Debug + - Release + build-16.04: + docker: + - image: heliconwave/circleci-ubuntu-16.04:latest + steps: + - checkout + - setup_remote_docker: + docker_layer_caching: true + - run: + name: Print Container Metadata + command: lsb_release -a + - run: + name: Build CMake Debug + command: mkdir Debug && cd Debug/ && cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=OFF .. && cmake --build . -- -j$(nproc) + - run: + name: Build CMake Release + command: mkdir Release && cd Release/ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES -DENABLE_TESTS=OFF .. && cmake --build . -- -j$(nproc) + - run: + name: Creating Artifacts + command: + cpack --version && + echo "include(\"Release/CPackConfig.cmake\")" > CPackConfig.cmake && + echo "set(CPACK_INSTALL_CMAKE_PROJECTS" >> CPackConfig.cmake && + echo " \"Debug;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && + echo " \"Release;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && + echo " )" >> CPackConfig.cmake && + cat CPackConfig.cmake && + cpack --config CPackConfig.cmake + - store_artifacts: + path: /root/project/mpeg2ts-0.6.0-Linux.tar.gz - persist_to_workspace: root: /root/project paths: @@ -44,7 +78,18 @@ jobs: # command: cd /root/project && em++ --version && pwd && rm -rf build/ && mkdir build && cd build/ && emcmake cmake -DCMAKE_CXX_STANDARD=11 -DENABLE_TESTS=OFF -DENABLE_WEBASSEMBLY=ON .. && cmake --build . -- -j$(nproc) test-unit: docker: - - image: heliconwave/cplusplus:latest + - image: heliconwave/circleci-ubuntu-18.04:latest + working_directory: ~/project + steps: + - checkout + - attach_workspace: + at: /root/project + - run: + name: Run CTest + command: pwd && ls -ltrha && cd Debug/ && make unit-tests + test-unit-16.04: + docker: + - image: heliconwave/circleci-ubuntu-16.04:latest working_directory: ~/project steps: - checkout @@ -55,7 +100,7 @@ jobs: command: pwd && ls -ltrha && cd Debug/ && make unit-tests test-component: docker: - - image: heliconwave/cplusplus:latest + - image: heliconwave/circleci-ubuntu-18.04:latest working_directory: ~/project steps: - checkout @@ -66,7 +111,7 @@ jobs: command: cd Debug/ && make component-tests test-benchmark: docker: - - image: heliconwave/cplusplus:latest + - image: heliconwave/circleci-ubuntu-18.04:latest steps: - checkout - attach_workspace: @@ -82,17 +127,21 @@ jobs: - attach_workspace: at: /root/project - run: - name: Run micro benchmark + name: Run memcheck unit tests command: cd Debug/ && ctest -T memcheck workflows: version: 2 build-test-and-deploy: jobs: - build + - build-16.04 # - build-webassembly - test-unit: requires: - build + - test-unit-16.04: + requires: + - build-16.04 - test-component: requires: - build diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..347a6cc --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,50 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at +// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/ubuntu-18.04-git +{ + "name": "Ubuntu 18.04", + "image": "heliconwave/mpeg2ts-ubuntu-18.04:latest", + // The optional 'runArgs' property can be used to specify additional runtime arguments. + "runArgs": [ + // "--env LOCAL_USER_ID=${localEnv:UID}" + // Uncomment the line if you will use a ptrace-based debugger like C++, Go, and Rust. + // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", + + // Uncomment the next line to use a non-root user. See https://aka.ms/vscode-remote/containers/non-root-user. + // "-u", "docker" + ], + + // Runs in the end after image setup + // "postCreateCommand": "/bin/bash /usr/local/bin/entrypoint.sh", + + // Container user VS Code should use when connecting + "remoteUser": "docker", + + // Uncomment the next line if you want to publish any ports for example + // for remote debugging + // "appPort": [1234], + + // "containerEnv": { + // "LOCAL_USER_ID": "${localEnv:UID}" + // }, + + // Set environment variables for VS Code and sub-processes + // "remoteEnv": { + // "LOCAL_USER_ID": "${localEnv:UID}" + // }, + + // Any *default* container specific VS Code settings + // Terminal shell + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // An array of extension IDs that specify the extensions to + // install inside the container when you first attach to it. + "extensions": [ + "ms-vscode.cmake-tools", + "twxs.cmake", + "ms-vscode.cpptools", + "cheshirekow.cmake-format", + "austin.code-gnu-global" + ] +} diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 463e968..557ed41 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -8,12 +8,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macOS-latest, windows-latest] + os: [macos-10.15, windows-latest] steps: - uses: actions/checkout@v1 - name: check versions run: cmake --version - name: cmake configure - run : mkdir build; cd build; cmake -DENABLE_COMPONENT_TESTS=OFF .. + run : mkdir build; cd build; cmake -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug .. - name: cmake build - run: cd build/; ls; pwd; cmake --build . + run: cd build/; pwd; cmake --build . + - name: cmake run unit tests + run: cd build/; cmake --build . --target unit-tests diff --git a/.gitignore b/.gitignore index 7cba6c8..6ea69ca 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ # Project specific files build/ +build_vscode/ tests/gtests .idea/ @@ -58,8 +59,8 @@ Release/ # 3rd-party 3rd-party/nlohmann/* -3rd-party/plog-1.1.4/* -3rd-party/json-3.5.0/* +3rd-party/plog-*/* +3rd-party/json-*/* 3rd-party/.json_extracted 3rd-party/.plog_extracted diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json index 823d6f9..a2dd3a5 100644 --- a/.vscode/cmake-kits.json +++ b/.vscode/cmake-kits.json @@ -14,7 +14,7 @@ "cmakeSettings": { "ENABLE_TESTS": "OFF", "BUILD_SHARED_LIBS": "ON", - "DCMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release" }, "compilers" : { "CXX": "/usr/bin/g++-7" diff --git a/3rd-party/CMakeLists.txt b/3rd-party/CMakeLists.txt index 74c6006..f23d952 100644 --- a/3rd-party/CMakeLists.txt +++ b/3rd-party/CMakeLists.txt @@ -26,8 +26,6 @@ #*******************************************************************/ cmake_minimum_required(VERSION 3.0) project(3rd-party) -set(PLOG_VERSION 1.1.4) -set(NLOHMANN_VERSION 3.5.0) # Must use GNUInstallDirs to install libraries into correct @@ -44,7 +42,7 @@ ExternalProject_Add( INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/plog-${PLOG_VERSION} CMAKE_ARGS -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX= - -D BUILD_SAMPLES=OFF + -D PLOG_BUILD_SAMPLES=OFF ) ############# nlohmann/json @@ -64,8 +62,12 @@ ExternalProject_Add( #------------------------------------------------------------- # Taken from https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project #------------------------------------------------------------- -if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) +if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) message("NOT using Docker! Downloading & configuring google test...") + if (APPLE) + set(CMAKE_CXX_STANDARD 11) + message("Setting CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}") + endif(APPLE) # Download and unpack googletest at configure time configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists_googletest.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/googletest-download/CMakeLists.txt) @@ -99,13 +101,13 @@ if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include") endif() -endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) +endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) ############ google benchmark -if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) +if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) message("NOT using Docker! Downloading & configuring google benchmark...") set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable GTest") @@ -147,4 +149,4 @@ if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include") endif() -endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY) +endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) diff --git a/3rd-party/CMakeLists_benchmark.txt.in b/3rd-party/CMakeLists_benchmark.txt.in index 4bb45e5..384761f 100644 --- a/3rd-party/CMakeLists_benchmark.txt.in +++ b/3rd-party/CMakeLists_benchmark.txt.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.5) project(benchmark-download NONE) diff --git a/3rd-party/CMakeLists_googletest.txt.in b/3rd-party/CMakeLists_googletest.txt.in index ad7749d..e602e4f 100644 --- a/3rd-party/CMakeLists_googletest.txt.in +++ b/3rd-party/CMakeLists_googletest.txt.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.5) project(googletest-download NONE) diff --git a/3rd-party/json-3.9.1.tar.gz b/3rd-party/json-3.9.1.tar.gz new file mode 100644 index 0000000..ed83aba Binary files /dev/null and b/3rd-party/json-3.9.1.tar.gz differ diff --git a/3rd-party/plog-1.1.5.tar.gz b/3rd-party/plog-1.1.5.tar.gz new file mode 100644 index 0000000..557ccf1 Binary files /dev/null and b/3rd-party/plog-1.1.5.tar.gz differ diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb8c37..516ded9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Releases +*V0.6.0* +* [x] Add broader support +* [x] Fix emscripten with CMake +* [x] Add support Ubuntu 16.04 +* [x] Better comments in samples +* [x] Add remote container development environment +* [x] Fix some suggestions +* [x] Add H264 parser application +* [x] Update third-party libs Plog and Json to latest version +* [x] Enable CI testing for Windows and Mac + *V0.5.0* * [x] Add github workflow: Crosscompilation Mac, Windows * [x] Cleanup Sample diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dba5f1..6be2e8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,14 +24,31 @@ # Boston, MA 02111-1307, USA. # #******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( mpeg2ts - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "Main project for MPEG-2 Parsing of transport streams" LANGUAGES CXX ) +else() +project( + mpeg2ts + VERSION 0.6.0 + LANGUAGES CXX +) +endif() + +# Set Language Standard +# Require C++11 and disable extensions for all targets +if(CMAKE_MINOR_VERSION LESS 8) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +endif() + include(CTest) @@ -52,24 +69,34 @@ if(NOT "${CMAKE_CURRENT_LIST_DIR}/cmake" IN_LIST CMAKE_MODULE_PATH) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") endif() +#------------------- +# sub modules +#------------------- +set(BENCHMARK_ENABLE_TESTING OFF) +option(ENABLE_TESTS "Build with tests" OFF) +option(ENABLE_COMPONENT_TESTS "Build with component tests" OFF) +option(BUILD_SAMPLES "Build samples" ON) +option(ENABLE_COVERAGE "Enable GCOV code coverage" OFF) +option(ENABLE_WEBASSEMBLY "Enable Web assembly code" OFF) + +#------------------- +# cmake code +#------------------- include(clang_format) include(cppcheck) include(iwyu) include(doxygen) -include(emscripten) include(valgrind) include(clang_tidy) - +include(emscripten) #------------------- -# sub modules +# third-party #------------------- -set(BENCHMARK_ENABLE_TESTING OFF) -option(ENABLE_TESTS "Build with tests" ON) -option(ENABLE_COMPONENT_TESTS "Build with component tests" ON) -option(BUILD_SAMPLES "Build samples" ON) -option(ENABLE_COVERAGE "Enable GCOV code coverage" OFF) -option(ENABLE_WEBASSEMBLY "Enable Web assembly code" OFF) +set(PLOG_VERSION 1.1.5) +set(NLOHMANN_VERSION 3.9.1) +add_subdirectory(3rd-party) + #------------------- # gcov code coverage @@ -95,11 +122,6 @@ if(ENABLE_COMPONENT_TESTS) add_subdirectory(component_tests) endif() -#------------------- -# third-party -#------------------- -add_subdirectory(3rd-party) - if(NOT CMAKE_INSTALL_BINDIR) include(GNUInstallDirs) @@ -153,9 +175,6 @@ endif() #------------------- # 3rd-party #------------------- -set(PLOG_VERSION 1.1.4) -set(NLOHMANN_VERSION 3.5.0) - include_directories(3rd-party/json-${NLOHMANN_VERSION}/include) include_directories(3rd-party/plog-${PLOG_VERSION}/include) @@ -171,40 +190,21 @@ add_subdirectory(libs) #------------------- # add custom targets #------------------- -add_custom_target(unit-tests - COMMAND ./tests/run_gtests "${CMAKE_CURRENT_LIST_DIR}/assets/bbc_one.ts" -) - -add_custom_target(benchmark-tests - COMMAND ./bench/Parser_Benchmark -) - -#------------------- -# installation -#------------------- -if(NOT WIN32) -install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) - -install(FILES - ${CMAKE_CURRENT_SOURCE_DIR}/libs/mpeg2ts/include/mpeg2ts.h - ${CMAKE_CURRENT_SOURCE_DIR}/libs/mpeg2ts/include/Ts_IEC13818-1.h - ${CMAKE_CURRENT_SOURCE_DIR}/libs/mpeg2ts/include/TsUtilities.h - ${CMAKE_CURRENT_SOURCE_DIR}/libs/mpeg2ts/include/settings.json - ${CMAKE_CURRENT_BINARY_DIR}/libs/mpeg2ts/mpeg2ts_export.h - DESTINATION include/${PROJECT_NAME} -) +if (ENABLE_TESTS) + if (MSVC) + add_custom_target(unit-tests + COMMAND ./tests/${CMAKE_BUILD_TYPE}/run_gtests.exe "${CMAKE_CURRENT_LIST_DIR}/assets/bbc_one.ts" + ) + else() + add_custom_target(unit-tests + COMMAND ./tests/run_gtests "${CMAKE_CURRENT_LIST_DIR}/assets/bbc_one.ts" + ) + endif(MSVC) -install(EXPORT ${PROJECT_NAME}Targets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION lib/cmake/${PROJECT_NAME} -) -endif() + add_custom_target(benchmark-tests + COMMAND ./bench/Parser_Benchmark + ) +endif(ENABLE_TESTS) include(CMakePackageConfigHelpers) write_basic_package_version_file("mpeg2tsConfigVersion.cmake" diff --git a/README.md b/README.md index 4c2ec46..dcab8d8 100644 --- a/README.md +++ b/README.md @@ -114,42 +114,28 @@ NONE ``` where VERBOSE is the maximum log output as compared to NONE which generates no output. The default log output file is `mpeg2ts_log.csv` in csv style for easier use. -## Tsparser -### How to run it -Type `make help` to see all make targets. To start runing the lib: -``` -cd build/ -make all -cd .. -./build/apps/tsparser/tsparser --input assets/test1.ts -``` -Check help in command line (CLI): -``` -./build/apps/tsparser/tsparser --help -``` -Add option --write with the PES PID for writing PES packets to file. -``` -./build/apps/tsparser/tsparser --write 2504 --input assets/bbc_one.ts -``` -Just print PSI tables / PES header can be done by --pid option and the PID. -``` -./build/apps/tsparser/tsparser --pid 258 --input assets/bbc_one.ts -``` +## Apps +For more info on how to use the apps like `tsparser` or `h264parser` please check [README](apps/README.md). ## Docker To simplify building mpeg2ts, building dependencies and tools have been bundled into a docker container. This image can be build locally or downloaded from docker hub. To start using docker commands, simplest is to source the tool source docker/docker-commands.sh -Check `docker/` README for more information. +Check [README](docker/README.md) for more information. ## Tests In order to run all tests just type (currently only available under Linux): -```Bash -make component-tests -make component-benchmark-tests -make unit-tests -``` + + cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=ON .. + +Building: + + make -j $(nproc) + make component-tests + make component-benchmark-tests + make unit-tests + This will run component tests, benchmark and unit-tests. Component tests are developed via `pytest` while the unit tests are via google tests/mocks (`gtest`). The different layers like API, and tsutilities are tested as a component (the whole library as such) while class functions are tested as a unit. ## Windows diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 016ca74..6bfefaf 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -31,4 +31,5 @@ endif() # only build tsparser on UNIX (getopt only exist in Linux) if (UNIX) add_subdirectory(tsparser) + add_subdirectory(h264parser) endif(UNIX) diff --git a/apps/README.md b/apps/README.md new file mode 100644 index 0000000..17ae565 --- /dev/null +++ b/apps/README.md @@ -0,0 +1,53 @@ +# Apps +These 2 apps are Command Line Interface apps that will help you parse either a transport-stream file or a h264 file. + +## h264parser +Example: + + ./h264parser --input myvideo.h264 + +Help dialog: + + H264 parser command-line tool: + USAGE: ./h264parser [-h] [-v] [-l log-level] [-i file] + Option Arguments: + -h [ --help ] Print help messages + -v [ --version ] Print library version + -l [ --log-level NONE|FATAL|ERROR|WARNING|INFO|DEBUG|VERBOSE] Choose what logs are filtered, both file and stdout, default: DEBUG + -i [ --input FILE] Use input file for parsing + + +## tsparser +Example: + + ./tsparser --input assets/test1.ts + +### More usage +To start runing the parser: + + ./tsparser --input assets/test1.ts + +Check help in command line (CLI): + + ./tsparser --help + +Add option --write with the PES PID for writing PES packets to file. + + ./tsparser --write 2504 --input assets/bbc_one.ts + +Just print PSI tables / PES header can be done by --pid option and the PID. + + ./tsparser --pid 258 --input assets/bbc_one.ts + +Help dialog: + + Mpeg2ts lib simple command-line: + USAGE: ./tsparser [-h] [-v] [-p PID] [-w PID] [-m ts|pes|es] [-l log-level] [-i file] + Option Arguments: + -h [ --help ] Print help messages + -v [ --version ] Print library version + -p [ --pid PID] Print PSI tables info with PID + -w [ --write PID] Writes PES packets with PID to file + -m [ --wrmode type] Choose what type of data is written[ts|pes|es] + -l [ --log-level NONE|FATAL|ERROR|WARNING|INFO|DEBUG|VERBOSE] Choose what logs are filtered, both file and stdout, default: DEBUG + -i [ --input FILE] Use input file for parsing diff --git a/apps/WebAssembly/CMakeLists.txt b/apps/WebAssembly/CMakeLists.txt index 4968db5..f213920 100644 --- a/apps/WebAssembly/CMakeLists.txt +++ b/apps/WebAssembly/CMakeLists.txt @@ -1,15 +1,52 @@ -cmake_minimum_required(VERSION 3.12) +#***************************************************************** +# +# Copyright © 2017-2020 kohnech, lnwhome All rights reserved +# +# mpeg2ts - mpeg2ts apps +# +# This file is part of mpeg2ts (Mpeg2 Transport Stream Library). +# +# Unless you have obtained mpeg2ts under a different license, +# this version of mpeg2ts is mpeg2ts|GPL. +# Mpeg2ts|GPL is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, +# or (at your option) any later version. +# +# Mpeg2ts|GPL is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mpeg2ts|GPL; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +#*******************************************************************/ +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( a.out - VERSION 0.0.1 + VERSION 0.6.0 DESCRIPTION "Webassembly main" LANGUAGES CXX ) +else() +project( + a.out + VERSION 0.6.0 + LANGUAGES CXX +) +endif() add_definitions(-std=c++11 -O3) -add_executable(${PROJECT_NAME}) +add_executable( + ${PROJECT_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc +) #if(JS_ONLY) # message(STATUS "Setting compilation target to native JavaScript") @@ -27,12 +64,9 @@ target_include_directories( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src -) - -target_sources( - ${PROJECT_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc + $# For TsParser.h + $# For Mpeg2VideoParser.h + $# For H264Parser.h ) target_link_libraries(${PROJECT_NAME} diff --git a/apps/WebAssembly/src/main.cc b/apps/WebAssembly/src/main.cc index e6ed076..5144b36 100644 --- a/apps/WebAssembly/src/main.cc +++ b/apps/WebAssembly/src/main.cc @@ -22,14 +22,20 @@ #include "emscripten.h" // Project files -#include "Logging.h" -#include "TsParser.h" #include "Ts_IEC13818-1.h" -#include "H264Parser.h" #include "mpeg2ts.h" #include "mpeg2ts_version.h" // Returns current version of mpeg2ts library + +// Private project files +#include "TsParser.h" +#include "H264Parser.h" #include "Mpeg2VideoParser.h" +enum // Define log instances. Default is 0 and is omitted from this enum. +{ + FileLog = 1 +}; + using namespace mpeg2ts; diff --git a/apps/h264parser/CMakeLists.txt b/apps/h264parser/CMakeLists.txt new file mode 100644 index 0000000..e40aecc --- /dev/null +++ b/apps/h264parser/CMakeLists.txt @@ -0,0 +1,74 @@ +#***************************************************************** +# +# Copyright © 2017-2020 kohnech, lnwhome All rights reserved +# +# mpeg2ts - mpeg2ts tsparser +# +# This file is part of mpeg2ts (Mpeg2 Transport Stream Library). +# +# Unless you have obtained mpeg2ts under a different license, +# this version of mpeg2ts is mpeg2ts|GPL. +# Mpeg2ts|GPL is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, +# or (at your option) any later version. +# +# Mpeg2ts|GPL is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mpeg2ts|GPL; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +#******************************************************************/ +cmake_minimum_required(VERSION 3.5) + +if(CMAKE_MINOR_VERSION GREATER 9) +project( + h264parser + VERSION 0.6.0 + DESCRIPTION "CLI Parsing of h264 stream" + LANGUAGES CXX +) +else() +project( + h264parser + VERSION 0.6.0 + LANGUAGES CXX +) +endif() + +add_executable( + ${PROJECT_NAME} + src/main.cc +) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + $# For TsParser.h + $# For Mpeg2VideoParser.h + $# For H264Parser.h +) + +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + h264codec + mpeg2ts # For GetBits() Should actually be moved out to its own lib +) + +set_target_properties( + ${PROJECT_NAME} + PROPERTIES + VERSION ${PROJECT_VERSION} + DEBUG_POSTFIX "-d" +) + +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) # Available in CMake 3.8 +endif() diff --git a/apps/h264parser/src/main.cc b/apps/h264parser/src/main.cc new file mode 100644 index 0000000..d43a668 --- /dev/null +++ b/apps/h264parser/src/main.cc @@ -0,0 +1,213 @@ +/***************************************************************** +* +* Copyright © 2017-2020 kohnech, lnwhome All rights reserved +* +* mpeg2ts - mpeg2ts h264parser +* +* This file is part of mpeg2ts (Mpeg2 Transport Stream Library). +* +* Unless you have obtained mpeg2ts under a different license, +* this version of mpeg2ts is mpeg2ts|GPL. +* Mpeg2ts|GPL is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2, +* or (at your option) any later version. +* +* Mpeg2ts|GPL is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with mpeg2ts|GPL; see the file COPYING. If not, write to the +* Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +* 02111-1307, USA. +* +******************************************************************/ +#include +#include +#include + +// 3rd-party +#include +#include + +// Project files +// #include "mpeg2ts_version.h" // Returns current version of mpeg2ts library + +// Private project files +#include "H264Parser.h" + + +enum // Define log instances. Default is 0 and is omitted from this enum. +{ + FileLog = 1 +}; + +const char LOGFILE_NAME[]{ "h264parser.csv" }; +int LOGFILE_MAXSIZE{ 100 * 1024 }; +int LOGFILE_MAXNUMBEROF{ 10 }; + +const plog::Severity DEFAULT_LOG_LEVEL = plog::debug; + +std::map> g_Options; +std::string g_InputFile; + + + +void display_usage() +{ + printf("H264 parser command-line tool:\n"); + + printf( + "USAGE: ./h264parser [-h] [-v] [-l log-level] [-i file]\n"); + + printf("Option Arguments:\n" + " -h [ --help ] Print help messages\n" + " -v [ --version ] Print library version\n" + " -l [ --log-level NONE|FATAL|ERROR|WARNING|INFO|DEBUG|VERBOSE] Choose " + "what logs are filtered, both file and stdout, default: %s\n" + " -i [ --input FILE] Use input file for parsing\n", + plog::severityToString(DEFAULT_LOG_LEVEL)); +} + + +static const char* optString = "i:l:h?v"; + +struct option longOpts[] = { { "input", 1, nullptr, 'i' }, { "log-level", 1, nullptr, 'l' }, + { "help", 0, nullptr, 'h' }, { "version", 0, nullptr, 'v' }, + { nullptr, 0, nullptr, 0 } }; + +int main(int argc, char** argv) +{ + // Initialize the logger + /// Short macros list + /// LOGV << "verbose"; + /// LOGD << "debug"; + /// LOGI << "info"; + /// LOGW << "warning"; + /// LOGE << "error"; + /// LOGF << "fatal"; + /// LOGN << "none"; + + static plog::RollingFileAppender fileAppender(LOGFILE_NAME, LOGFILE_MAXSIZE, LOGFILE_MAXNUMBEROF); // Create the 1st appender. + static plog::ConsoleAppender consoleAppender; // Create the 2nd appender. + plog::init(DEFAULT_LOG_LEVEL, &fileAppender).addAppender(&consoleAppender); // Initialize the + // logger with the + // both appenders. + plog::init(DEFAULT_LOG_LEVEL, &fileAppender); // Initialize the 2nd logger instance. + + LOGD << "Starting parser of file"; + + for (;;) + { + int opt; + int optInd = -1; + opt = getopt_long(argc, argv, optString, longOpts, &optInd); + if (optInd == -1) + { + for (optInd = 0; longOpts[optInd].name; ++optInd) + { + if (longOpts[optInd].val == opt) + { + LOGD << "optInd: " << optInd; + break; + } + } + if (longOpts[optInd].name == NULL) + { + // the short option was not found; do something + LOGE << "the short option was not found; do something"; // TODO + } + } + + if (opt < 0) + break; + switch (opt) + { + case 'h': /* fall-through is intentional */ + case '?': + { + display_usage(); + exit(EXIT_SUCCESS); + } + case 'v': + { + // printf("version: %s\n", getMpeg2tsVersion().c_str()); + exit(EXIT_SUCCESS); + } + case 'l': + { + LOGD << "Use Default log-level: " << plog::severityToString(DEFAULT_LOG_LEVEL); + std::string logLevel = std::string(optarg); + LOGD << "Got input log-level setting: " << logLevel; + for (auto& c : logLevel) + { + c = static_cast(toupper(c)); + } + plog::Severity severity = plog::severityFromString(logLevel.c_str()); + plog::get()->setMaxSeverity(severity); + LOGD << "Use log-level: " << plog::severityToString(severity) << ", (" << severity << ")"; + break; + } + case 'i': + { + LOGD << "Got file input: " << std::string(optarg); + g_InputFile = std::string(optarg); + break; + } + default: + /* You won't actually get here. */ + break; + } + } // for + + + std::ifstream file(g_InputFile, std::ifstream::binary); + std::vector dataVec; + uint8_t byte; + if (file.is_open()) { + while(file >> byte){ + dataVec.push_back(byte); + } + } + else { + LOGE << "Unable to open file!"; + file.close(); + exit(EXIT_SUCCESS); + } + + h264::H264EsParser h264Parser; + std::vector infos = h264Parser.parse(dataVec); + + for (auto info : infos) + { + LOGD << "----------------------------------------------"; + LOGD << "h264 nal type: " << h264::H264EsParser::toString(info.type); + LOGD << "nal: " << h264::H264EsParser::toString(info.nalUnitType) << " " << info.msg; + if (info.type == h264::H264InfoType::SliceHeader) + { + LOGD << info.slice.sliceTypeStr << ", pps id: " << info.pps.ppsId; + if (info.slice.field) + { + LOGD << "field encoded: " << (info.slice.top ? " top" : " bottom"); + } + else + { + LOGD << "frame encoded"; + } + } + else if (info.type == h264::H264InfoType::SequenceParameterSet) + { + LOGD << "sps id: " << info.pps.spsId << ", luma bits: " << info.sps.lumaBits + << ", chroma bits: " << info.sps.chromaBits << ", size: " << info.sps.width + << " x " << info.sps.height << ", ref pic: " << info.sps.numRefPics; + } + else if (info.type == h264::H264InfoType::PictureParameterSet) + { + LOGD << "sps id: " << info.pps.spsId << "pps id: " << info.pps.ppsId; + } + } + + file.close(); +} diff --git a/apps/tsparser/CMakeLists.txt b/apps/tsparser/CMakeLists.txt index 4480cda..9217c3a 100644 --- a/apps/tsparser/CMakeLists.txt +++ b/apps/tsparser/CMakeLists.txt @@ -24,27 +24,35 @@ # Boston, MA 02111-1307, USA. # #******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( tsparser - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "MPEG-2 CLI Parsing of transport streams" LANGUAGES CXX ) +else() +project( + tsparser + VERSION 0.6.0 + LANGUAGES CXX +) +endif() -add_executable(tsparser) - -target_sources( +add_executable( ${PROJECT_NAME} - PRIVATE - src/main.cc - ) + src/main.cc +) target_include_directories( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src + $# For TsParser.h + $# For Mpeg2VideoParser.h + $# For H264Parser.h ) target_link_libraries( @@ -62,4 +70,6 @@ set_target_properties( DEBUG_POSTFIX "-d" ) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) # Available in CMake 3.8 +endif() diff --git a/apps/tsparser/src/main.cc b/apps/tsparser/src/main.cc index e2cee98..8f557f8 100644 --- a/apps/tsparser/src/main.cc +++ b/apps/tsparser/src/main.cc @@ -42,13 +42,20 @@ #include // Project files -#include "Logging.h" -#include "TsParser.h" #include "Ts_IEC13818-1.h" -#include "H264Parser.h" #include "mpeg2ts.h" #include "mpeg2ts_version.h" // Returns current version of mpeg2ts library + +// Private project files #include "Mpeg2VideoParser.h" +#include "H264Parser.h" +#include "TsParser.h" + + +enum // Define log instances. Default is 0 and is omitted from this enum. +{ + FileLog = 1 +}; using namespace mpeg2ts; diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index ff08992..7e38db3 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -24,7 +24,7 @@ # Boston, MA 02111-1307, USA. # #******************************************************************/ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.5) #------------------- # tests @@ -40,9 +40,17 @@ foreach(ONE_BENCH_CPP ${ALL_BENCH_CPP}) add_executable(${TARGET_NAME} ${ONE_BENCH_CPP}) - target_include_directories(${TARGET_NAME} PRIVATE ../tests) + target_include_directories(${TARGET_NAME} + PRIVATE + $# For CodecTestData.h + $# For EsParser.h + $# For H264Parser.h + $# For Mpeg2VideoParser.h + ) - target_compile_features(${TARGET_NAME} PRIVATE cxx_std_11) + if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${TARGET_NAME} PRIVATE cxx_std_11) + endif() set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${ONE_BENCH_EXEC}) find_package(Threads REQUIRED) diff --git a/cmake/clang_format.cmake b/cmake/clang_format.cmake index 97d0cbe..6f3e1d5 100644 --- a/cmake/clang_format.cmake +++ b/cmake/clang_format.cmake @@ -24,16 +24,16 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) -option(USE_CLANG_FORMAT "Use clang-format for formatting c++ files" ON) +option(USE_CLANG_FORMAT "Use clang-format for formatting c++ files" OFF) if(NOT USE_CLANG_FORMAT) - message(STATUS "Not using clang-tidy!") + message(STATUS " Not using clang-tidy!") return() endif() -message(STATUS "Using clang-format") +message(STATUS " Using clang-format") set(CLANG_VERSION 7) @@ -44,7 +44,7 @@ find_program( ) if(NOT CLANG_FORMAT_EXE) - message(WARNING "clang-format not found on your system. Bailing out...") + message(WARNING " clang-format not found on your system. Bailing out...") return() else() message(STATUS " clang-format found: ${CLANG_FORMAT_EXE}") @@ -55,9 +55,13 @@ endif() # get all project files file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") +if(CMAKE_MINOR_VERSION GREATER 5) + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") +else() + +endif() add_custom_target( clang-format diff --git a/cmake/clang_tidy.cmake b/cmake/clang_tidy.cmake index d18e142..5d6acd9 100644 --- a/cmake/clang_tidy.cmake +++ b/cmake/clang_tidy.cmake @@ -24,16 +24,16 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) -option(USE_CLANG_TIDY "Use clang-tidy for static code analysis" ON) +option(USE_CLANG_TIDY "Use clang-tidy for static code analysis" OFF) if(NOT USE_CLANG_TIDY) - message(STATUS "Not using clang-tidy!") + message(STATUS " Not using clang-tidy!") return() endif() -message(STATUS "Using clang-tidy") +message(STATUS " Using clang-tidy") set(CLANG_VERSION 7) @@ -43,7 +43,7 @@ find_program( ) if(NOT CLANG_TIDY_EXE) - message(WARNING " clang-tidy not found bailing out...") + message(WARNING " clang-tidy not found bailing out...") return() else() message(STATUS " clang-tidy found: ${CLANG_TIDY_EXE}") @@ -64,11 +64,13 @@ message(STATUS " Command : ${DO_CLANG_TIDY}") # get all project files file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Release") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Debug") +if(CMAKE_MINOR_VERSION GREATER 5) + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Release") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Debug") +endif() # src/*.cc -checks=* -- -std=c++11 -I/usr/include/c++/5/ -I./include diff --git a/cmake/cppcheck.cmake b/cmake/cppcheck.cmake index bdea8da..7e488bc 100644 --- a/cmake/cppcheck.cmake +++ b/cmake/cppcheck.cmake @@ -24,16 +24,16 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) -option(USE_CPPCHECK "Use cppcheck for static code analysis" ON) +option(USE_CPPCHECK "Use cppcheck for static code analysis" OFF) if(NOT USE_CPPCHECK) - message(STATUS "Not using cppcheck!") + message(STATUS " Not using cppcheck!") return() endif() -message(STATUS "Using cppcheck") +message(STATUS " Using cppcheck") find_program( CPPCHECK_EXE @@ -42,7 +42,7 @@ find_program( ) if(NOT CPPCHECK_EXE) - message(WARNING "cppcheck not found on your system. Bailing out...") + message(WARNING " cppcheck not found on your system. Bailing out...") return() else() message(STATUS " cppcheck found: ${CPPCHECK_EXE}") @@ -52,9 +52,11 @@ endif() # get all project files file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") -list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") +if(CMAKE_MINOR_VERSION GREATER 5) + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") + list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") +endif() add_custom_target( cppcheck diff --git a/cmake/doxygen.cmake b/cmake/doxygen.cmake index 6d59f74..9d9c6d3 100644 --- a/cmake/doxygen.cmake +++ b/cmake/doxygen.cmake @@ -24,16 +24,16 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) -option(USE_DOXYGEN "Use Doxygen for inline documentation." ON) +option(USE_DOXYGEN "Use Doxygen for inline documentation." OFF) if(NOT USE_DOXYGEN) message(STATUS " Not using Doxygen!") return() endif() -message(STATUS "Using Doxygen") +message(STATUS " Using Doxygen") # Require dot, treat the other components as optional find_package( @@ -42,7 +42,7 @@ find_package( ) if(NOT DOXYGEN_FOUND) - message(WARNING "Doxygen not found on your system. Bailing out...") + message(WARNING " Doxygen not found on your system. Bailing out...") return() else() message(STATUS " doxygen found: ${DOXYGEN_EXECUTABLE}") diff --git a/cmake/emscripten.cmake b/cmake/emscripten.cmake index 72d19c5..14548b6 100644 --- a/cmake/emscripten.cmake +++ b/cmake/emscripten.cmake @@ -24,16 +24,22 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(NOT ENABLE_WEBASSEMBLY) + message(STATUS " Not using emscripten!") + return() +endif() + +message(STATUS " Using emscripten") if(NOT EMSCRIPTEN_PREFIX) - message("EMSCRIPTEN_PREFIX not defined!") + message(STATUS " EMSCRIPTEN_PREFIX not defined!") if(DEFINED ENV{EMSCRIPTEN}) file(TO_CMAKE_PATH "$ENV{EMSCRIPTEN}" EMSCRIPTEN_PREFIX) set(EMSCRIPTEN_PREFIX $ENV{EMSCRIPTEN}) else() set(EMSCRIPTEN_PREFIX "/usr/lib/emscripten") - message(WARNING "Could not find Emscripten toolchain, using /usr/lib/emscripten instead!") + message(WARNING " Could not find Emscripten toolchain, using /usr/lib/emscripten instead!") endif() endif() diff --git a/cmake/iwyu.cmake b/cmake/iwyu.cmake index 1bbf9ed..3b14a7a 100644 --- a/cmake/iwyu.cmake +++ b/cmake/iwyu.cmake @@ -28,17 +28,23 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR) option(USE_IWYU "Use include-what-you-use for static include analysis" OFF) -if (USE_IWYU) +if (NOT USE_IWYU) + message(STATUS " Not using include-what-you-use! To enable it, append -DUSE_IWYU=ON") + return() +endif() - find_program(iwyu_path NAMES include-what-you-use iwyu) - if(NOT iwyu_path) - message(FATAL_ERROR "Could not find the program include-what-you-use") - else() - message(STATUS " Using include-what-you-use include analysis.") - endif() +message(STATUS " Using include-what-you-use") - set_property(TARGET mpeg2ts PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path}) +find_program( + iwyu_exe + NAMES include-what-you-use iwyu +) +if(NOT iwyu_exe) + message(WARNING " Could not find the program include-what-you-use, baling out...") + return() else() - message(STATUS "Note include-what-you-use is NOT enabled. Enable it by append -DUSE_IWYU=ON.") + message(STATUS " Using include-what-you-use include analysis.") endif() + +set_property(TARGET mpeg2ts PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_exe}) diff --git a/cmake/valgrind.cmake b/cmake/valgrind.cmake index 740fc8f..fe2607c 100644 --- a/cmake/valgrind.cmake +++ b/cmake/valgrind.cmake @@ -26,16 +26,28 @@ #*******************************************************************/ cmake_minimum_required(VERSION 3.3 FATAL_ERROR) -option(USE_VALGRIND "Use Valgrind for dynamic profiling / memcheck analysis" ON) +option(USE_VALGRIND "Use Valgrind for dynamic profiling / memcheck analysis" OFF) if(NOT USE_VALGRIND) message(STATUS " Not using Valgrind!") return() endif() -message(STATUS "Using Valgrind") +message(STATUS " Using Valgrind") + +find_program( + MEMORYCHECK_COMMAND + NAMES valgrind +) + +if(NOT MEMORYCHECK_COMMAND) + message(WARNING " valgrind not found on your system. Bailing out...") + return() +else() + message(STATUS " valgrind found: ${MEMORYCHECK_COMMAND}") +endif() + -find_program(MEMORYCHECK_COMMAND NAMES valgrind) set(MEMORYCHECK_COMMAND valgrind) set(CTEST_MEMORYCHECK_COMMAND valgrind ) set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--tool=callgrind -v" ) diff --git a/component_tests/CMakeLists.txt b/component_tests/CMakeLists.txt index a94a3f8..86f5a90 100644 --- a/component_tests/CMakeLists.txt +++ b/component_tests/CMakeLists.txt @@ -24,7 +24,7 @@ # Boston, MA 02111-1307, USA. # #******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) project(CmakeVirtualenv) @@ -34,7 +34,7 @@ set(PYTHON_VERSION 3) # Find Python and Virtualenv. We don't actually use the output of the # find_package, but it'll give nicer errors. -find_package(PythonInterp 2.7 REQUIRED) +find_package(PythonInterp) find_program(VIRTUALENV virtualenv) if(NOT VIRTUALENV) message(FATAL_ERROR "Could not find `virtualenv` in PATH. You may need install by sudo apt-get install virtualenv.") diff --git a/docker/Makefile b/docker/Makefile index 97ce01a..a79bd51 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -47,3 +47,55 @@ docker-image: --file=$(DOCKER_IMAGE_BASE)/Dockerfile \ --tag=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VER) \ --tag=$(DOCKER_IMAGE_NAME):latest ./ + +docker-image-circleci: + docker build \ + --file=$(DOCKER_IMAGE_BASE)/circleci/Dockerfile \ + --tag=heliconwave/circleci-ubuntu-18.04:v1 \ + --tag=heliconwave/circleci-ubuntu-18.04:latest ./ + +docker-image-ubuntu-16.04: + docker build \ + --file=ubuntu_16_04/Dockerfile \ + --tag=heliconwave/mpeg2ts-ubuntu-16.04:v2 \ + --tag=heliconwave/mpeg2ts-ubuntu-16.04:latest ./ + +docker-image-circleci-ubuntu-16.04: + docker build \ + --file=ubuntu_16_04/circleci/Dockerfile \ + --tag=heliconwave/circleci-ubuntu-16.04:v1 \ + --tag=heliconwave/circleci-ubuntu-16.04:latest ./ + +docker-bash-ubuntu-16.04: + docker run \ + --rm \ + --interactive \ + --tty=true \ + --env LOCAL_USER_ID=`id -u ${USER}` \ + --env "TERM=xterm-256color" \ + --volume=$$(pwd)/..:/home/docker/workspace \ + --workdir=/home/docker/workspace \ + heliconwave/mpeg2ts-ubuntu-16.04:latest /bin/bash + +docker-bash-circleci-ubuntu-16.04: + docker run \ + --rm \ + --interactive \ + --tty=true \ + --env LOCAL_USER_ID=`id -u ${USER}` \ + --env "TERM=xterm-256color" \ + --volume=$$(pwd)/..:/home/docker/workspace \ + --workdir=/home/docker/workspace \ + heliconwave/circleci-ubuntu-16.04:latest /bin/bash + + +docker-bash-circleci-ubuntu-18.04: + docker run \ + --rm \ + --interactive \ + --tty=true \ + --env LOCAL_USER_ID=`id -u ${USER}` \ + --env "TERM=xterm-256color" \ + --volume=$$(pwd)/..:/home/docker/workspace \ + --workdir=/home/docker/workspace \ + heliconwave/circleci-ubuntu-18.04:latest /bin/bash diff --git a/docker/Makefile.variables b/docker/Makefile.variables index a3fc174..920b797 100644 --- a/docker/Makefile.variables +++ b/docker/Makefile.variables @@ -1,3 +1,3 @@ DOCKER_IMAGE_BASE=ubuntu_18_04 -DOCKER_IMAGE_NAME=heliconwave/circleci -DOCKER_IMAGE_VER=v19 \ No newline at end of file +DOCKER_IMAGE_NAME=heliconwave/mpeg2ts-ubuntu-18.04 +DOCKER_IMAGE_VER=v3 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 9346615..be52624 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -5,11 +5,12 @@ # fallback USER_ID=${LOCAL_USER_ID:-9001} +echo "LOCAL_USER_ID: $LOCAL_USER_ID" USER=docker UPWD=Docker! echo "Starting with USER: $USER and UID : $USER_ID" -useradd --shell /bin/bash -u $USER_ID -o -c "" -m "$USER" +useradd --shell /bin/bash --uid $USER_ID -o -c "" -m "$USER" # Add user to sudoers echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/10-installer # Add root password @@ -17,5 +18,6 @@ echo "root":$UPWD | chpasswd # Add user password echo "$USER:$UPWD" | chpasswd export HOME=/home/$USER - -exec gosu "$USER" "$@" +su $USER +echo "Starting user:" +whoami diff --git a/docker/ubuntu_16_04/Dockerfile b/docker/ubuntu_16_04/Dockerfile index 5b91bf9..e407f2b 100644 --- a/docker/ubuntu_16_04/Dockerfile +++ b/docker/ubuntu_16_04/Dockerfile @@ -43,20 +43,24 @@ RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/dow ### Builder image ### FROM user as build -RUN apt-get update && apt-get install --yes --no-install-recommends -RUN apt-get install --yes --no-install-recommends apt-utils -RUN apt-get install --yes --no-install-recommends software-properties-common -RUN apt-get install --yes --no-install-recommends build-essential=12.1ubuntu2 -RUN apt-get install --yes --no-install-recommends tstools=1.11-1ubuntu1 -RUN apt-get install --yes --no-install-recommends gdb=7.11.1-0ubuntu1~16.5 -RUN apt-get install --yes --no-install-recommends gdbserver=7.11.1-0ubuntu1~16.5 -RUN apt-get install --yes --no-install-recommends wget=1.17.1-1ubuntu1.4 -RUN apt-get install --yes --no-install-recommends lcov=1.12-2 -RUN apt-get install --yes --no-install-recommends sudo=1.8.16-0ubuntu1.5 -RUN apt-get install --yes --no-install-recommends zip=3.0-11 -RUN apt-get install --yes --no-install-recommends unzip=6.0-20ubuntu1 -RUN apt-get install --yes --no-install-recommends doxygen -RUN apt-get install --yes --no-install-recommends graphviz +RUN apt-get update && apt-get --yes --no-install-recommends install \ + apt-utils \ + software-properties-common \ + build-essential \ + tstools \ + gdb \ + gdbserver \ + wget \ + lcov \ + sudo \ + zip \ + unzip \ + doxygen \ + cmake \ + git \ + graphviz && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* # LLVM Clang ENV CLANG_VERSION=7 @@ -69,31 +73,20 @@ RUN apt-get install --yes --no-install-recommends clang-format-$CLANG_VERSION # python support -RUN apt-get install --yes --no-install-recommends python3-setuptools=20.7.0-1 -RUN apt-get install --yes --no-install-recommends virtualenv=15.0.1+ds-3ubuntu1 -RUN apt-get install --yes --no-install-recommends python3-pip=8.1.1-2ubuntu0.4 -RUN apt-get install --yes --no-install-recommends python3-dev=3.5.1-3 -RUN apt-get install --yes --no-install-recommends python3-virtualenv=15.0.1+ds-3ubuntu1 -RUN apt-get install --yes --no-install-recommends python3-pip +RUN apt-get update && apt-get --yes --no-install-recommends install \ + python3-setuptools=20.7.0-1 \ + virtualenv=15.0.1+ds-3ubuntu1 \ + python3-pip=8.1.1-2ubuntu0.4 \ + python3-dev=3.5.1-3 \ + python3-virtualenv=15.0.1+ds-3ubuntu1 \ + python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* #python packages RUN pip3 install flake8 -# Install latest git -RUN apt-add-repository ppa:git-core/ppa \ - && apt-get update \ - && apt-get install --yes --no-install-recommends git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Install latest cmake -RUN curl -o /cmake-3.13.1-Linux-x86_64.sh -SL "https://cmake.org/files/v3.13/cmake-3.13.1-Linux-x86_64.sh" -RUN mkdir /opt/cmake -RUN sh /cmake-3.13.1-Linux-x86_64.sh --prefix=/opt/cmake --skip-license -RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake -RUN cmake --version - # Install latest cppcheck RUN git clone https://github.com/danmar/cppcheck.git /cppcheck \ && mkdir /cppcheck/build \ diff --git a/docker/ubuntu_16_04/circleci/Dockerfile b/docker/ubuntu_16_04/circleci/Dockerfile new file mode 100644 index 0000000..8e61bb7 --- /dev/null +++ b/docker/ubuntu_16_04/circleci/Dockerfile @@ -0,0 +1,98 @@ +#***************************************************************** +# +# Copyright © 2017-2020 kohnech, lnwhome All rights reserved +# +# mpeg2ts - mpeg2ts Dockerfile +# +# This file is part of mpeg2ts (Mpeg2 Transport Stream Library). +# +# Unless you have obtained mpeg2ts under a different license, +# this version of mpeg2ts is mpeg2ts|GPL. +# Mpeg2ts|GPL is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, +# or (at your option) any later version. +# +# Mpeg2ts|GPL is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mpeg2ts|GPL; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +#******************************************************************/ + +FROM ubuntu:16.04 as base + +### Create user account ### +FROM base as user +RUN apt-get update && apt-get -y --no-install-recommends install \ + ca-certificates=20170717~16.04.1 \ + curl + +RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 +RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture)" \ + && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture).asc" \ + && gpg --verify /usr/local/bin/gosu.asc \ + && rm /usr/local/bin/gosu.asc \ + && chmod +x /usr/local/bin/gosu + +### Builder image ### +FROM user as build + +RUN apt-get update && apt-get --yes --no-install-recommends install \ + apt-utils \ + software-properties-common \ + build-essential \ + wget \ + sudo \ + zip \ + unzip \ + cmake \ + git \ + graphviz && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install gtest/gmock +RUN git clone -q https://github.com/google/googletest.git /googletest \ + && cd googletest \ + && git checkout tags/release-1.8.1 \ + && mkdir -p /googletest/build \ + && cd /googletest/build \ + && cmake .. && make -j 16 && make install \ + && cd / && rm -rf /googletest + +# Install benchmark +RUN git clone -q https://github.com/google/benchmark.git /benchmark \ + && cd benchmark \ + && git checkout tags/v1.4.0 \ + && mkdir -p /benchmark/build \ + && cd /benchmark/build \ + && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j 16 && make install \ + && cd / && rm -rf /benchmark + + +# python support +RUN apt-get update && apt-get --yes --no-install-recommends install \ + python3-setuptools=20.7.0-1 \ + virtualenv=15.0.1+ds-3ubuntu1 \ + python3-pip=8.1.1-2ubuntu0.4 \ + python3-dev=3.5.1-3 \ + python3-virtualenv=15.0.1+ds-3ubuntu1 \ + python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +#python packages +RUN pip3 install flake8 + +# entrypoint +COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +WORKDIR /tmp/workspace diff --git a/docker/ubuntu_18_04/Dockerfile b/docker/ubuntu_18_04/Dockerfile index e584b34..af0d1a1 100644 --- a/docker/ubuntu_18_04/Dockerfile +++ b/docker/ubuntu_18_04/Dockerfile @@ -42,7 +42,9 @@ RUN apt-get update && apt-get --yes --no-install-recommends install \ zip \ unzip \ doxygen \ - graphviz && \ + graphviz \ + cmake \ + git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -82,26 +84,6 @@ RUN pip3 install \ autopep8 \ virtualenv -# Install latest git -RUN apt-add-repository ppa:git-core/ppa \ - && apt-get update \ - && apt-get install --yes --no-install-recommends git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Install latest cmake -ENV CMAKE_VERSION=3.16 -ENV CMAKE_BUILD_VERSION=0 -RUN mkdir /opt/cmake && cd /opt/cmake && \ -wget https://cmake.org/files/v$CMAKE_VERSION/cmake-$CMAKE_VERSION.$CMAKE_BUILD_VERSION.tar.gz && \ -tar -xzvf cmake-$CMAKE_VERSION.$CMAKE_BUILD_VERSION.tar.gz && \ -cd cmake-$CMAKE_VERSION.$CMAKE_BUILD_VERSION/ && \ -./bootstrap -- -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_USE_OPENSSL=OFF && \ -make -j$(nproc) && \ -make install && \ -cmake --version && \ -rm -rf /opt/cmake - # Install latest cppcheck RUN git clone https://github.com/danmar/cppcheck.git /cppcheck \ && mkdir /cppcheck/build \ @@ -137,13 +119,13 @@ RUN git clone https://github.com/include-what-you-use/include-what-you-use.git / # Install as docker user (after entrypoint) # Install Emscripten SDK/toolchain -ENV EMSDK_VERSION=1.38 -ENV EMSDK_BUILD_VERSION=31 +ENV EMSDK_VERSION=1.39 +ENV EMSDK_BUILD_VERSION=5 RUN git clone https://github.com/emscripten-core/emsdk.git /tmp/emsdk && \ cd /tmp/emsdk && \ -./emsdk install sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit && \ -./emsdk activate sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit -ENV PATH="${PATH}:/tmp/emsdk/emscripten/tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION" +./emsdk install $EMSDK_VERSION.$EMSDK_BUILD_VERSION && \ +./emsdk activate $EMSDK_VERSION.$EMSDK_BUILD_VERSION +ENV PATH="${PATH}:/tmp/emsdk:/tmp/emsdk/upstream/emscripten:/tmp/emsdk/node/12.9.1_64bit/bin" RUN echo "PATH: " $PATH RUN em++ --version @@ -151,4 +133,5 @@ RUN em++ --version COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] -WORKDIR /tmp/workspace +# WORKDIR /tmp/workspace +RUN adduser docker diff --git a/docker/ubuntu_18_04/circleci/Dockerfile b/docker/ubuntu_18_04/circleci/Dockerfile new file mode 100644 index 0000000..97643b7 --- /dev/null +++ b/docker/ubuntu_18_04/circleci/Dockerfile @@ -0,0 +1,104 @@ +#***************************************************************** +# +# Copyright © 2017-2020 kohnech, lnwhome All rights reserved +# +# mpeg2ts - mpeg2ts Dockerfile +# +# This file is part of mpeg2ts (Mpeg2 Transport Stream Library). +# +# Unless you have obtained mpeg2ts under a different license, +# this version of mpeg2ts is mpeg2ts|GPL. +# Mpeg2ts|GPL is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, +# or (at your option) any later version. +# +# Mpeg2ts|GPL is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with mpeg2ts|GPL; see the file COPYING. If not, write to +# the Free Software Foundation, 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# +#******************************************************************/ + +FROM ubuntu:18.04 as base + + +RUN apt-get update && apt-get --yes --no-install-recommends install \ + ca-certificates \ + curl \ + gnupg2 \ + gosu \ + apt-utils \ + software-properties-common \ + build-essential \ + wget \ + cmake \ + git \ + valgrind && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +### Builder image ### +FROM base as build + +# python support +RUN apt-get update && \ + apt-get install --yes --no-install-recommends \ + virtualenv \ + python3-setuptools \ + python3-pip \ + python3-dev \ + python3-virtualenv \ + python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +#python packages +RUN pip3 install \ + flake8 \ + autopep8 \ + virtualenv + + +# Install gtest/gmock +RUN git clone -q https://github.com/google/googletest.git /googletest \ + && cd googletest \ + && git checkout tags/release-1.8.1 \ + && mkdir -p /googletest/build \ + && cd /googletest/build \ + && cmake .. && make -j $(nproc) && make install \ + && cd / && rm -rf /googletest + +# Install benchmark +RUN git clone -q https://github.com/google/benchmark.git /benchmark \ + && cd benchmark \ + && git checkout tags/v1.4.0 \ + && mkdir -p /benchmark/build \ + && cd /benchmark/build \ + && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc) && make install \ + && cd / && rm -rf /benchmark + + +# Install as docker user (after entrypoint) +# Install Emscripten SDK/toolchain +# ENV EMSDK_VERSION=1.38 +# ENV EMSDK_BUILD_VERSION=31 +# RUN git clone https://github.com/emscripten-core/emsdk.git /tmp/emsdk && \ +# cd /tmp/emsdk && \ +# ./emsdk install sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit && \ +# ./emsdk activate sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit +# ENV PATH="${PATH}:/tmp/emsdk/emscripten/tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION" +# RUN echo "PATH: " $PATH +# RUN em++ --version + +# entrypoint +COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +WORKDIR /tmp/workspace diff --git a/libs/h264codec/CMakeLists.txt b/libs/h264codec/CMakeLists.txt index a5cb884..25fd953 100644 --- a/libs/h264codec/CMakeLists.txt +++ b/libs/h264codec/CMakeLists.txt @@ -24,14 +24,22 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( h264codec - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "H264 Codec parser lib" LANGUAGES CXX ) +else() +project( + h264codec + VERSION 0.6.0 + LANGUAGES CXX +) +endif() add_library(${PROJECT_NAME}) @@ -43,9 +51,10 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC $ - $ # For CMake generated files: mpeg2ts_version.h , mpeg2ts_export.h $ + PRIVATE $ + $# For EsParser.h ) set_target_properties(${PROJECT_NAME} @@ -57,7 +66,9 @@ set_target_properties(${PROJECT_NAME} DEBUG_POSTFIX "-d" ) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() target_sources( ${PROJECT_NAME} @@ -69,10 +80,6 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/src/H264Codec.cc ) -target_link_libraries(${PROJECT_NAME} - PRIVATE - mpeg2ts # only for EsParser.h include -) add_dependencies(h264codec plog) add_dependencies(h264codec json) diff --git a/libs/mpeg2codec/CMakeLists.txt b/libs/mpeg2codec/CMakeLists.txt index cb82c36..3cef174 100644 --- a/libs/mpeg2codec/CMakeLists.txt +++ b/libs/mpeg2codec/CMakeLists.txt @@ -24,14 +24,22 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( mpeg2codec - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "MPEG2 Codec parser lib" LANGUAGES CXX ) +else() +project( + mpeg2codec + VERSION 0.6.0 + LANGUAGES CXX +) +endif() add_library(${PROJECT_NAME}) @@ -43,9 +51,10 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC $ - $ # For CMake generated files: mpeg2ts_version.h , mpeg2ts_export.h $ + PRIVATE $ + $# For EsParser.h ) set_target_properties( @@ -58,7 +67,9 @@ set_target_properties( DEBUG_POSTFIX "-d" ) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() target_sources( ${PROJECT_NAME} @@ -70,10 +81,6 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/src/Mpeg2Codec.cc ) -target_link_libraries(${PROJECT_NAME} - PRIVATE - mpeg2ts # only for EsParser.h include -) add_dependencies(${PROJECT_NAME} plog) -add_dependencies(${PROJECT_NAME} json) \ No newline at end of file +add_dependencies(${PROJECT_NAME} json) diff --git a/libs/mpeg2ts/CMakeLists.txt b/libs/mpeg2ts/CMakeLists.txt index 3ba180d..c860ff7 100644 --- a/libs/mpeg2ts/CMakeLists.txt +++ b/libs/mpeg2ts/CMakeLists.txt @@ -24,14 +24,22 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( mpeg2ts - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "MPEG-2 Parsing lib of transport streams" LANGUAGES CXX ) +else() +project( + mpeg2ts + VERSION 0.6.0 + LANGUAGES CXX +) +endif() #------------------- # CMake generated files @@ -58,8 +66,9 @@ target_include_directories( PUBLIC $ $ - $ $ # For CMake generated files: mpeg2ts_version.h , mpeg2ts_export.h + PRIVATE + $ ) set_target_properties(${PROJECT_NAME} @@ -71,7 +80,9 @@ set_target_properties(${PROJECT_NAME} DEBUG_POSTFIX "-d" ) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() target_sources( ${PROJECT_NAME} @@ -95,3 +106,28 @@ target_sources( add_dependencies(${PROJECT_NAME} plog) add_dependencies(${PROJECT_NAME} json) + +#------------------- +# installation +#------------------- +install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/include/mpeg2ts.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/Ts_IEC13818-1.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/TsUtilities.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/settings.json + ${CMAKE_CURRENT_BINARY_DIR}/mpeg2ts_export.h + DESTINATION include/${PROJECT_NAME} +) + +install(EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION lib/cmake/${PROJECT_NAME} +) diff --git a/libs/mpeg2ts/src/TsUtilities.cc b/libs/mpeg2ts/src/TsUtilities.cc index d12b229..e6f8974 100644 --- a/libs/mpeg2ts/src/TsUtilities.cc +++ b/libs/mpeg2ts/src/TsUtilities.cc @@ -208,7 +208,7 @@ bool TsUtilities::parseTransportFile(const std::string& a_file) int pos = 0; if (no == 0) { - while (packet[pos] != mpeg2ts::TS_PACKET_SYNC_BYTE) + while (packet[pos] != mpeg2ts::TS_PACKET_SYNC_BYTE)//check out of bound read { LOGV << "need to sync..."; ++pos; diff --git a/samples/TsUtilities/CMakeLists.txt b/samples/TsUtilities/CMakeLists.txt index 1769e58..2ee7173 100644 --- a/samples/TsUtilities/CMakeLists.txt +++ b/samples/TsUtilities/CMakeLists.txt @@ -24,18 +24,31 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) project( sample_tsutilities - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "Sample TsUtilities" LANGUAGES CXX ) +else() +project( + sample_tsutilities + VERSION 0.6.0 + LANGUAGES CXX +) +endif() -add_executable(${PROJECT_NAME}) +add_executable( + ${PROJECT_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp +) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() target_include_directories( ${PROJECT_NAME} @@ -43,14 +56,8 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ) -target_sources( - ${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp -) - -target_link_libraries(${PROJECT_NAME} - PRIVATE mpeg2ts mpeg2codec h264codec diff --git a/samples/TsUtilities/src/main.cpp b/samples/TsUtilities/src/main.cpp index 3647174..898ebfb 100644 --- a/samples/TsUtilities/src/main.cpp +++ b/samples/TsUtilities/src/main.cpp @@ -25,6 +25,12 @@ * ********************************************************************/ +// This sample parses a ts file using TsUtilties hight level API. +// It finds PAT, PMT, PES packets and print statistics. +// Use of this high level API(tsutil::TsUtilities) is not very +// practical/efficient but simple. To achieve efficieny, mpeg2ts API +// is recommended. + #include "TsUtilities.h" #include "mpeg2ts.h" @@ -38,6 +44,10 @@ namespace tsutil { +/* +* This is the callback for each video package containing codec data. +* Note this is only of interest if we would like parse the codec data. +*/ void handleVideoCallback(const std::vector& data, int streamType) { try @@ -133,6 +143,12 @@ void handleVideoCallback(const std::vector& data, int streamType) } // namespace tsutil +/* +* This program takes a transport stream as argument. Example: +* ./sample_tsutilities my_transport_stream.ts +*/ +// Parse ts file. Find PAT, PMT, PES packets and print statisticks. +// Use high level API(tsutil::TsUtilities) which is not very practical/efficient but simple. int main(int argc, char *argv[]) { std::string asset; @@ -146,29 +162,53 @@ int main(int argc, char *argv[]) asset = argv[1]; } + /* + * This is the TsUitilities API that we use to parse the transport stream file. + */ tsutil::TsUtilities util; // TsUtilities High level API + /* + * We only need to register a video callback if we would like to parse the video codec. + * This is not always the case, so this step can be skipped. + */ util.addVideoCallback( [&](const std::vector& a_data, int a_streamType) { tsutil::handleVideoCallback(a_data, a_streamType); } ); - bool success = util.parseTransportFile(argv[1]); LOGD << "Starting parser of file"; + /* + * This API will parse the entire transport stream file. + */ + bool success = util.parseTransportFile(argv[1]); if (!success) { LOGE << "Could not open file"; return EXIT_FAILURE; } + /* + * Returns the PAT table for this stream if existing. + */ mpeg2ts::PatTable pat = util.getPatTable(); LOGD << "Got PAT: " << pat; + /* + * All programs can be found in the Program Map Table (PMT) + * which this API returns. We can have MPTS or SPTS. + */ std::vector pmtPids = util.getPmtPids(); + /* + * The PMTs themselves caries PMT specific data, for more info check + * https://en.wikipedia.org/wiki/Program-specific_information#PMT_(Program_map_specific_data) + */ std::map pmtTables = util.getPmtTables(); + /* + * PMTs also contains Elementary stream specific data + */ for (auto pid : pmtPids) { std::cout << "Got PMT pid: " << pid; @@ -178,18 +218,28 @@ int main(int argc, char *argv[]) } } + /* + * Log the PMTs + */ for (auto table : pmtTables) { LOGD << "PMT PID: " << table.first; LOGD << table.second; } + /* + * This are the streams for the program. It can also be found in the PMT, + * but this API can also be used. + */ std::vector mEsPids = util.getEsPids(); for (auto esPid : mEsPids) { LOGD << "Found elementary stream with Pid: " << esPid; } + /* + * These are the streams packed in PES. They are sorted per PID. + */ std::map> pesPackets = util.getPesPackets(); LOGD << "Got number of PES packets: " << pesPackets.size(); @@ -200,6 +250,9 @@ int main(int argc, char *argv[]) LOGD << "Size of PES packets: " << pes.second.size(); } + /* + * getPidStatistics returns statistics for the transport stream file. + */ mpeg2ts::PidStatisticsMap stat = util.getPidStatistics(); for (auto pid : stat) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0119f1d..989a71c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,24 +24,33 @@ # Boston, MA 02111-1307, USA. # #*******************************************************************/ -cmake_minimum_required(VERSION 3.12) - -include(GoogleTest) +cmake_minimum_required(VERSION 3.5) +if(CMAKE_MINOR_VERSION GREATER 9) +include(GoogleTest) # Introduced in CMake 3.10 project( run_gtests - VERSION 0.5.0 + VERSION 0.6.0 DESCRIPTION "GTests for mpeg2ts lib" LANGUAGES CXX ) +else() +project( + run_gtests + VERSION 0.6.0 + LANGUAGES CXX +) +endif() + #------------------- # Locate GTest +enable_testing() find_package(GTest MODULE) find_library(GMOCK_LIBRARY - NAMES gmock - libgmock - libgmock.a + NAMES gmock + libgmock + libgmock.a PATHS "${GTEST_DIR}" PATH_SUFFIXES lib ) @@ -49,22 +58,26 @@ find_library(GMOCK_LIBRARY include_directories(${GTEST_INCLUDE_DIRS}) if (NOT GTest_FOUND) - message(STATUS "Could NOT Find GTest") + message(WARNING " Could NOT Find GTest") endif() #------------------- # tests #------------------- # Now simply link against gtest, gmock, gtest_main or gmock_main as needed. Eg -add_executable(${PROJECT_NAME}) +add_executable( + ${PROJECT_NAME} + gtest_main.cc +) target_compile_definitions(${PROJECT_NAME} PRIVATE MPEG2TS_DLL_EXPORTS) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(CMAKE_MINOR_VERSION GREATER 7) + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() target_sources(${PROJECT_NAME} PRIVATE - gtest_main.cc GetBits_Tests.cc Mpeg2VideoParser_Tests.cc PsiTables_Tests.cc @@ -81,6 +94,9 @@ target_include_directories( PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/. ${CMAKE_CURRENT_BINARY_DIR}/.. + $# Testing private src/headers + $# Testing private src/headers + $# Testing private src/headers ) if(USE_DOCKER) @@ -88,15 +104,15 @@ if(USE_DOCKER) else(USE_DOCKER) find_package(Threads REQUIRED) target_link_libraries( - ${PROJECT_NAME} + ${PROJECT_NAME} PRIVATE - Threads::Threads + Threads::Threads gmock ) endif(USE_DOCKER) -target_link_libraries(${PROJECT_NAME} - PRIVATE +target_link_libraries(${PROJECT_NAME} + PRIVATE mpeg2ts mpeg2codec h264codec @@ -107,13 +123,17 @@ if(GTEST_HAVE_DISCOVERY) gtest_discover_tests(${PROJECT_NAME} TEST_PREFIX ${exportname}. TEST_LIST ${PROJECT_NAME}_targets) else() - gtest_add_tests( - TARGET - ${PROJECT_NAME} - SOURCES - ${TARGET_SOURCES} - TEST_PREFIX - ${exportname}. - TEST_LIST - ${PROJECT_NAME}_targets) + if(CMAKE_MINOR_VERSION GREATER 8) + # For CMake 3.9 onwards + gtest_add_tests( + TARGET + ${PROJECT_NAME} + SOURCES + ${TARGET_SOURCES} + TEST_PREFIX + ${exportname}. + TEST_LIST + ${PROJECT_NAME}_targets + ) + endif() endif() diff --git a/tests/TsUtilities_Tests.cc b/tests/TsUtilities_Tests.cc index ed1d6c5..523908b 100644 --- a/tests/TsUtilities_Tests.cc +++ b/tests/TsUtilities_Tests.cc @@ -179,7 +179,7 @@ TEST_F(TsUtilitiesTest, test_parseTransportFile_success) { try { - EXPECT_TRUE(m_tsUtil.parseTransportFile(asset_file)); + EXPECT_TRUE(m_tsUtil.parseTransportFile(asset_file)) << "failed to parse file " << asset_file; mpeg2ts::PatTable pat; pat = m_tsUtil.getPatTable(); std::vector pmtPids; @@ -254,7 +254,7 @@ TEST_F(TsUtilitiesTest, test_VideoMediaInfo) { try { - EXPECT_TRUE(m_tsUtil.parseTransportFile(asset_file)); + EXPECT_TRUE(m_tsUtil.parseTransportFile(asset_file)) << "failed to parse file " << asset_file; VideoMediaInfo mediaInfo = m_tsUtil.getVideoMediaInfo(); EXPECT_EQ(mediaInfo.PID, 2304); EXPECT_EQ(mediaInfo.mediaType, MediaType::Video);