├── .circleci └── config.yml ├── .clang-format ├── .devcontainer └── devcontainer.json ├── .flake8 ├── .github └── workflows │ └── ccpp.yml ├── .gitignore ├── .vscode └── cmake-kits.json ├── 3rd-party ├── CMakeLists.txt ├── CMakeLists_benchmark.txt.in ├── CMakeLists_googletest.txt.in ├── gtest-1.8.0.tar.gz ├── json-3.5.0.tar.gz ├── json-3.9.1.tar.gz ├── nlohmann.tar.gz ├── plog-1.1.4.tar.gz └── plog-1.1.5.tar.gz ├── CHANGELOG.md ├── CMakeLists.txt ├── CMakePresets.json ├── CMakeSettings.json ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── apps ├── CMakeLists.txt ├── README.md ├── WebAssembly │ ├── 220px-Web_Assembly_Logo.svg.png │ ├── CMakeLists.txt │ ├── README.md │ ├── app.js │ ├── buildem.sh │ ├── github.png │ ├── index.html │ ├── src │ │ └── main.cc │ └── styles.css ├── h264parser │ ├── CMakeLists.txt │ └── src │ │ └── main.cc └── tsparser │ ├── CMakeLists.txt │ └── src │ └── main.cc ├── assets ├── bbc_one.ts └── test1.ts ├── bench ├── CMakeLists.txt └── Parser_Benchmark.cpp ├── cmake ├── CodeCoverage.cmake ├── clang_format.cmake ├── clang_tidy.cmake ├── cppcheck.cmake ├── doxygen.cmake ├── emscripten.cmake ├── iwyu.cmake ├── toolchains │ └── emscripten-wasm.cmake └── valgrind.cmake ├── component_tests ├── CMakeLists.txt ├── __init__.py ├── cmdline_test.py ├── conftest.py ├── requirements.txt └── tsparser.py ├── docker ├── Makefile ├── Makefile.variables ├── README.md ├── docker-commands.sh ├── entrypoint.sh ├── ubuntu_16_04 │ ├── Dockerfile │ └── circleci │ │ └── Dockerfile └── ubuntu_18_04 │ ├── Dockerfile │ └── circleci │ └── Dockerfile ├── gen_package.bat ├── gen_package.sh ├── images ├── Ts-lib_SW_Architecture.png ├── circleci.png ├── cmake.png ├── codacy.png ├── docker.png └── ts_lib_oss.png ├── libs ├── CMakeLists.txt ├── common │ ├── CMakeLists.txt │ ├── include │ │ └── GetBits.h │ └── src │ │ └── GetBits.cc ├── h264codec │ ├── CMakeLists.txt │ ├── include │ │ └── H264Codec.h │ └── src │ │ ├── H264Codec.cc │ │ ├── H264Parser.cc │ │ └── H264Parser.h ├── mpeg2codec │ ├── CMakeLists.txt │ ├── include │ │ └── Mpeg2Codec.h │ └── src │ │ ├── Mpeg2Codec.cc │ │ ├── Mpeg2VideoParser.cc │ │ └── Mpeg2VideoParser.h └── mpeg2ts │ ├── CMakeLists.txt │ ├── include │ ├── TsUtilities.h │ ├── Ts_IEC13818-1.h │ ├── mpeg2ts.h │ └── settings.json │ └── src │ ├── EsParser.h │ ├── JsonSettings.cc │ ├── JsonSettings.h │ ├── Logging.h │ ├── PesPacket.cc │ ├── PsiTables.cc │ ├── TsDemuxer.cc │ ├── TsPacketInfo.cc │ ├── TsParser.cc │ ├── TsParser.h │ ├── TsStatistics.cc │ ├── TsStatistics.h │ ├── TsUtilities.cc │ └── mpeg2ts_version.h.in ├── mpeg2ts.code-workspace ├── mpeg2tsConfig.cmake ├── samples └── TsUtilities │ ├── CMakeLists.txt │ ├── settings.json.in │ └── src │ └── main.cpp └── tests ├── CMakeLists.txt ├── CodecTestData.h ├── GetBits_Tests.cc ├── H264Parser_Tests.cc ├── Mpeg2VideoParser_Tests.cc ├── PsiTables_Tests.cc ├── TsDemuxer_Tests.cc ├── TsPacketTestData.h ├── TsParser_Tests.cc ├── TsStatistics_Tests.cc ├── TsUtilities_Tests.cc ├── gtest_main.cc └── valgrind_suppress.txt /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build-ubuntu-18.04: 4 | docker: 5 | - image: heliconwave/circleci-ubuntu-18.04:latest 6 | steps: 7 | - checkout 8 | - setup_remote_docker: 9 | docker_layer_caching: true 10 | - run: 11 | name: Print Container Metadata 12 | command: lsb_release -a 13 | - run: 14 | name: Build CMake Debug 15 | command: mkdir Debug && cd Debug/ && cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=ON .. && cmake --build . -- -j$(nproc) 16 | - run: 17 | name: Build CMake Release 18 | command: mkdir Release && cd Release/ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES -DENABLE_TESTS=OFF .. && cmake --build . -- -j$(nproc) 19 | - run: 20 | name: Creating Artifacts 21 | command: 22 | cpack --version && 23 | echo "include(\"Release/CPackConfig.cmake\")" > CPackConfig.cmake && 24 | echo "set(CPACK_INSTALL_CMAKE_PROJECTS" >> CPackConfig.cmake && 25 | echo " \"Debug;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && 26 | echo " \"Release;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && 27 | echo " )" >> CPackConfig.cmake && 28 | cat CPackConfig.cmake && 29 | cpack --config CPackConfig.cmake 30 | - store_artifacts: 31 | path: /root/project/mpeg2ts-0.6.0-Linux.tar.gz 32 | - persist_to_workspace: 33 | root: /root/project 34 | paths: 35 | - Debug 36 | - Release 37 | build-ubuntu-16.04: 38 | docker: 39 | - image: heliconwave/circleci-ubuntu-16.04:latest 40 | steps: 41 | - checkout 42 | - setup_remote_docker: 43 | docker_layer_caching: true 44 | - run: 45 | name: Print Container Metadata 46 | command: lsb_release -a 47 | - run: 48 | name: Build CMake Debug 49 | command: mkdir Debug && cd Debug/ && cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=OFF .. && cmake --build . -- -j$(nproc) 50 | - run: 51 | name: Build CMake Release 52 | command: mkdir Release && cd Release/ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=YES -DENABLE_TESTS=OFF .. && cmake --build . -- -j$(nproc) 53 | - run: 54 | name: Creating Artifacts 55 | command: 56 | cpack --version && 57 | echo "include(\"Release/CPackConfig.cmake\")" > CPackConfig.cmake && 58 | echo "set(CPACK_INSTALL_CMAKE_PROJECTS" >> CPackConfig.cmake && 59 | echo " \"Debug;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && 60 | echo " \"Release;mpeg2ts;ALL;/\"" >> CPackConfig.cmake && 61 | echo " )" >> CPackConfig.cmake && 62 | cat CPackConfig.cmake && 63 | cpack --config CPackConfig.cmake 64 | - store_artifacts: 65 | path: /root/project/mpeg2ts-0.6.0-Linux.tar.gz 66 | - persist_to_workspace: 67 | root: /root/project 68 | paths: 69 | - Debug 70 | - Release 71 | # build-webassembly: 72 | # docker: 73 | # - image: heliconwave/emscripten:latest 74 | # steps: 75 | # - checkout 76 | # - run: 77 | # name: Build CMake WebAssembly 78 | # 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) 79 | test-unit-u18.04: 80 | docker: 81 | - image: heliconwave/circleci-ubuntu-18.04:latest 82 | working_directory: ~/project 83 | steps: 84 | - checkout 85 | - attach_workspace: 86 | at: /root/project 87 | - run: 88 | name: Run CTest 89 | command: pwd && ls -ltrha && cd Debug/ && make unit-tests 90 | test-unit-u16.04: 91 | docker: 92 | - image: heliconwave/circleci-ubuntu-16.04:latest 93 | working_directory: ~/project 94 | steps: 95 | - checkout 96 | - attach_workspace: 97 | at: /root/project 98 | - run: 99 | name: Run CTest 100 | command: pwd && ls -ltrha && cd Debug/ && make unit-tests 101 | test-component: 102 | docker: 103 | - image: heliconwave/circleci-ubuntu-18.04:latest 104 | working_directory: ~/project 105 | steps: 106 | - checkout 107 | - attach_workspace: 108 | at: /root/project 109 | - run: 110 | name: Component Tests 111 | command: cd Debug/ && make component-tests 112 | test-benchmark: 113 | docker: 114 | - image: heliconwave/circleci-ubuntu-18.04:latest 115 | steps: 116 | - checkout 117 | - attach_workspace: 118 | at: /root/project 119 | - run: 120 | name: Run micro benchmark 121 | command: cd Debug/ && make benchmark-tests 122 | test-memcheck: 123 | docker: 124 | - image: heliconwave/cplusplus:latest 125 | steps: 126 | - checkout 127 | - attach_workspace: 128 | at: /root/project 129 | - run: 130 | name: Run memcheck unit tests 131 | command: cd Debug/ && ctest -T memcheck 132 | workflows: 133 | version: 2 134 | build-test-and-deploy: 135 | jobs: 136 | - build-ubuntu-18.04 137 | - build-ubuntu-16.04 138 | # - build-webassembly 139 | - test-unit-u18.04: 140 | requires: 141 | - build-ubuntu-18.04 142 | - test-unit-u16.04: 143 | requires: 144 | - build-ubuntu-16.04 145 | - test-component: 146 | requires: 147 | - build-ubuntu-18.04 148 | - test-benchmark: 149 | requires: 150 | - build-ubuntu-18.04 151 | - test-memcheck: 152 | requires: 153 | - build-ubuntu-18.04 154 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -4 2 | AlignEscapedNewlinesLeft: true 3 | AlignTrailingComments: true 4 | AllowAllParametersOfDeclarationOnNextLine: false 5 | AllowShortFunctionsOnASingleLine: false 6 | AllowShortIfStatementsOnASingleLine: false 7 | AllowShortLoopsOnASingleLine: false 8 | AlwaysBreakBeforeMultilineStrings: false 9 | AlwaysBreakTemplateDeclarations: false 10 | BinPackParameters: false 11 | BreakBeforeBinaryOperators: false 12 | BreakBeforeBraces: Allman 13 | BreakBeforeTernaryOperators: false 14 | BreakConstructorInitializersBeforeComma: true 15 | ColumnLimit: 100 16 | CommentPragmas: '' 17 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 18 | ConstructorInitializerIndentWidth: 4 19 | ContinuationIndentWidth: 0 20 | Cpp11BracedListStyle: false 21 | DerivePointerBinding: false 22 | IndentCaseLabels: false 23 | IndentFunctionDeclarationAfterType: false 24 | IndentWidth: 4 25 | Language: Cpp 26 | MaxEmptyLinesToKeep: 2 27 | NamespaceIndentation: None 28 | ObjCSpaceAfterProperty: true 29 | ObjCSpaceBeforeProtocolList: true 30 | PenaltyBreakBeforeFirstCallParameter: 100 31 | PenaltyBreakComment: 100 32 | PenaltyBreakFirstLessLess: 0 33 | PenaltyBreakString: 100 34 | PenaltyExcessCharacter: 1 35 | PenaltyReturnTypeOnItsOwnLine: 20 36 | PointerBindsToType: true 37 | SpaceBeforeAssignmentOperators: true 38 | SpaceBeforeParens: ControlStatements 39 | SpaceInEmptyParentheses: false 40 | SpacesBeforeTrailingComments: 1 41 | SpacesInAngles: false 42 | SpacesInCStyleCastParentheses: false 43 | SpacesInContainerLiterals: false 44 | SpacesInParentheses: false 45 | Standard: Cpp11 46 | TabWidth: 4 47 | UseTab: Never 48 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at 2 | // https://github.com/microsoft/vscode-dev-containers/tree/master/containers/ubuntu-18.04-git 3 | { 4 | "name": "Ubuntu 18.04", 5 | "image": "heliconwave/mpeg2ts-ubuntu-18.04:latest", 6 | // The optional 'runArgs' property can be used to specify additional runtime arguments. 7 | "runArgs": [ 8 | // "--env LOCAL_USER_ID=${localEnv:UID}" 9 | // Uncomment the line if you will use a ptrace-based debugger like C++, Go, and Rust. 10 | // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", 11 | 12 | // Uncomment the next line to use a non-root user. See https://aka.ms/vscode-remote/containers/non-root-user. 13 | // "-u", "docker" 14 | ], 15 | 16 | // Runs in the end after image setup 17 | // "postCreateCommand": "/bin/bash /usr/local/bin/entrypoint.sh", 18 | 19 | // Container user VS Code should use when connecting 20 | "remoteUser": "docker", 21 | 22 | // Uncomment the next line if you want to publish any ports for example 23 | // for remote debugging 24 | // "appPort": [1234], 25 | 26 | // "containerEnv": { 27 | // "LOCAL_USER_ID": "${localEnv:UID}" 28 | // }, 29 | 30 | // Set environment variables for VS Code and sub-processes 31 | // "remoteEnv": { 32 | // "LOCAL_USER_ID": "${localEnv:UID}" 33 | // }, 34 | 35 | // Any *default* container specific VS Code settings 36 | // Terminal shell 37 | "settings": { 38 | "terminal.integrated.shell.linux": "/bin/bash" 39 | }, 40 | 41 | // An array of extension IDs that specify the extensions to 42 | // install inside the container when you first attach to it. 43 | "extensions": [ 44 | "ms-vscode.cmake-tools", 45 | "twxs.cmake", 46 | "ms-vscode.cpptools", 47 | "cheshirekow.cmake-format", 48 | "austin.code-gnu-global" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 85 3 | -------------------------------------------------------------------------------- /.github/workflows/ccpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | name: building 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [macos-latest, windows-latest, ubuntu-22.04] 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: check versions 15 | run: cmake --version 16 | - name: cmake configure 17 | run : mkdir build; cd build; cmake -DENABLE_TESTS=ON -DENABLE_COMPONENT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug .. 18 | - name: cmake build 19 | run: cd build/; pwd; cmake --build . 20 | - name: cmake run unit tests 21 | run: cd build/; cmake --build . --target unit-tests 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | *.a 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Compiled Dynamic libraries 16 | *.so 17 | *.dylib 18 | *.dll 19 | *.exp 20 | *.ilk 21 | *.pdb 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | 38 | 39 | # Project specific files 40 | build/ 41 | build_vscode/ 42 | tests/gtests 43 | .idea/ 44 | 45 | downloaded_files/ 46 | cmdline_test.log 47 | *~ 48 | 49 | 50 | # MSVC 51 | *.TMP 52 | *.suo 53 | Debug/ 54 | Release/ 55 | .vs/ 56 | *.VC.db 57 | *.VC.opendb 58 | *.csv 59 | 60 | # 3rd-party 61 | 3rd-party/nlohmann/* 62 | 3rd-party/plog-*/* 63 | 3rd-party/json-*/* 64 | 3rd-party/.json_extracted 65 | 3rd-party/.plog_extracted 66 | 67 | # VS Code 68 | .vscode/c_cpp_properties.json 69 | .pytest_cache/ 70 | *.PES 71 | component_tests/__pycache__/ 72 | env/ 73 | .vscode/ipch/ 74 | 75 | # TestTsLib 76 | msvc/2015/TestTsLib/TestTsLib/mpeg2ts.pdb 77 | msvc/2015/TestTsLib/TestTsLib/mpeg2ts.ilk 78 | msvc/2015/TestTsLib/TestTsLib/mpeg2ts.dll 79 | msvc/2015/TestTsLib/TestTsLib/mpeg2ts.lib 80 | msvc/2015/TestTsLib/TestTsLib/mpeg2ts.exp 81 | msvc/2015/TestTsLib/TestTsLib/settings.json 82 | 83 | # CPack 84 | CPackConfig.cmake 85 | 86 | # Windows CPack 87 | _CPack_Packages 88 | -------------------------------------------------------------------------------- /.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Linux-GCC-7.3.0-GTest", 4 | "cmakeSettings": { 5 | "ENABLE_TESTS": "ON", 6 | "BUILD_SHARED_LIBS": "OFF" 7 | }, 8 | "compilers" : { 9 | "CXX": "/usr/bin/g++-7" 10 | } 11 | }, 12 | { 13 | "name": "Linux-GCC-7.3.0-Release", 14 | "cmakeSettings": { 15 | "ENABLE_TESTS": "OFF", 16 | "BUILD_SHARED_LIBS": "ON", 17 | "CMAKE_BUILD_TYPE": "Release" 18 | }, 19 | "compilers" : { 20 | "CXX": "/usr/bin/g++-7" 21 | } 22 | }, 23 | { 24 | "name": "Windows-SharedLib-VS2017-x64", 25 | "cmakeSettings": { 26 | "ENABLE_TESTS": "OFF", 27 | "BUILD_SHARED_LIBS": "YES" 28 | }, 29 | "visualStudio": "VisualStudio.15.0", 30 | "visualStudioArchitecture": "amd64", 31 | "preferredGenerator" : { 32 | "name" : "Visual Studio 15 2017", 33 | "platform": "x64" 34 | } 35 | }, 36 | { 37 | "name": "Windows-SharedLib-VS2017-x86", 38 | "cmakeSettings": { 39 | "ENABLE_TESTS": "OFF", 40 | "BUILD_SHARED_LIBS": "YES" 41 | }, 42 | "visualStudio": "VisualStudio.15.0", 43 | "visualStudioArchitecture": "x86", 44 | "preferredGenerator" : { 45 | "name" : "Visual Studio 15 2017", 46 | "platform": "x86" 47 | } 48 | }, 49 | { 50 | "name": "Windows-Gtests-StaticLib-VS2017-x64", 51 | "cmakeSettings": { 52 | "ENABLE_TESTS": "ON", 53 | "BUILD_SHARED_LIBS": "NO" 54 | }, 55 | "visualStudio": "VisualStudio.15.0", 56 | "visualStudioArchitecture": "amd64", 57 | "preferredGenerator" : { 58 | "name" : "Visual Studio 15 2017", 59 | "platform": "x64" 60 | } 61 | }, 62 | { 63 | "name": "Windows-Gtests-StaticLib-VS2017-x86", 64 | "cmakeSettings": { 65 | "ENABLE_TESTS": "ON", 66 | "BUILD_SHARED_LIBS": "NO" 67 | }, 68 | "visualStudio": "VisualStudio.15.0", 69 | "visualStudioArchitecture": "x86", 70 | "preferredGenerator" : { 71 | "name" : "Visual Studio 15 2017", 72 | "platform": "x86" 73 | } 74 | }, 75 | { 76 | "name": "MacOS-Clang-Debug-static-libs", 77 | "cmakeSettings": { 78 | "ENABLE_TESTS": "ON", 79 | "ENABLE_COMPONENT_TESTS": "ON", 80 | "BUILD_SHARED_LIBS": "OFF", 81 | "CMAKE_BUILD_TYPE": "Debug" 82 | }, 83 | "compilers" : { 84 | "C": "/usr/bin/clang", 85 | "CXX": "/usr/bin/clang++" 86 | } 87 | }, 88 | { 89 | "name": "MacOS-Clang-Debug-dynamic-libs", 90 | "cmakeSettings": { 91 | "ENABLE_TESTS": "ON", 92 | "ENABLE_COMPONENT_TESTS": "ON", 93 | "BUILD_SHARED_LIBS": "ON", 94 | "CMAKE_BUILD_TYPE": "Debug" 95 | }, 96 | "compilers" : { 97 | "C": "/usr/bin/clang", 98 | "CXX": "/usr/bin/clang++" 99 | } 100 | } 101 | ] 102 | -------------------------------------------------------------------------------- /3rd-party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts 3rd-party 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.0) 28 | project(3rd-party) 29 | 30 | 31 | # Must use GNUInstallDirs to install libraries into correct 32 | # locations on all platforms. 33 | include(GNUInstallDirs) 34 | 35 | include(ExternalProject) 36 | 37 | ############# plog 38 | 39 | ExternalProject_Add( 40 | plog 41 | URL ${CMAKE_CURRENT_SOURCE_DIR}/plog-${PLOG_VERSION}.tar.gz 42 | INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/plog-${PLOG_VERSION} 43 | CMAKE_ARGS -D CMAKE_BUILD_TYPE=Release 44 | -D CMAKE_INSTALL_PREFIX= 45 | -D PLOG_BUILD_SAMPLES=OFF 46 | ) 47 | 48 | ############# nlohmann/json 49 | 50 | ExternalProject_Add( 51 | json 52 | URL ${CMAKE_CURRENT_SOURCE_DIR}/json-${NLOHMANN_VERSION}.tar.gz 53 | INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/json-${NLOHMANN_VERSION} 54 | CMAKE_ARGS -D CMAKE_BUILD_TYPE=Release 55 | -D BUILD_TESTING=OFF 56 | -D CMAKE_INSTALL_PREFIX= 57 | ) 58 | 59 | 60 | ############ google test 61 | 62 | #------------------------------------------------------------- 63 | # Taken from https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project 64 | #------------------------------------------------------------- 65 | if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) 66 | message("NOT using Docker! Downloading & configuring google test...") 67 | if (APPLE) 68 | set(CMAKE_CXX_STANDARD 11) 69 | message("Setting CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}") 70 | endif(APPLE) 71 | 72 | # Download and unpack googletest at configure time 73 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists_googletest.txt.in ${CMAKE_CURRENT_BINARY_DIR}/googletest-download/CMakeLists.txt) 74 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 75 | RESULT_VARIABLE result 76 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download 77 | ) 78 | if(result) 79 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") 80 | endif() 81 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 82 | RESULT_VARIABLE result 83 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) 84 | if(result) 85 | message(FATAL_ERROR "Build step for googletest failed: ${result}") 86 | endif() 87 | 88 | # Prevent overriding the parent project's compiler/linker 89 | # settings on Windows 90 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 91 | 92 | # Add googletest directly to our build. This defines 93 | # the gtest and gtest_main targets. 94 | add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src 95 | ${CMAKE_CURRENT_BINARY_DIR}/googletest-build 96 | EXCLUDE_FROM_ALL) 97 | 98 | # The gtest/gtest_main targets carry header search path 99 | # dependencies automatically when using CMake 2.8.11 or 100 | # later. Otherwise we have to add them here ourselves. 101 | if (CMAKE_VERSION VERSION_LESS 2.8.11) 102 | include_directories("${gtest_SOURCE_DIR}/include") 103 | endif() 104 | endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) 105 | 106 | 107 | ############ google benchmark 108 | 109 | 110 | if(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) 111 | message("NOT using Docker! Downloading & configuring google benchmark...") 112 | 113 | set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable GTest") 114 | # Build release version 115 | set(DCMAKE_BUILD_TYPE RELEASE) 116 | # If you want to self-test benchmark lib too, turn me ON 117 | # 118 | set(BENCHMARK_ENABLE_TESTING OFF) 119 | 120 | # Download and unpack benchmark at configure time 121 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists_benchmark.txt.in ${CMAKE_CURRENT_BINARY_DIR}/benchmark-download/CMakeLists.txt) 122 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . 123 | RESULT_VARIABLE result 124 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/benchmark-download ) 125 | if(result) 126 | message(FATAL_ERROR "CMake step for benchmark failed: ${result}") 127 | endif() 128 | execute_process(COMMAND ${CMAKE_COMMAND} --build . 129 | RESULT_VARIABLE result 130 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/benchmark-download ) 131 | if(result) 132 | message(FATAL_ERROR "Build step for benchmark failed: ${result}") 133 | endif() 134 | 135 | 136 | # Prevent overriding the parent project's compiler/linker 137 | # settings on Windows 138 | #set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 139 | 140 | # Add benchmark directly to our build. This defines 141 | # the gtest and gtest_main targets. 142 | add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/benchmark-src 143 | ${CMAKE_CURRENT_BINARY_DIR}/benchmark-build 144 | EXCLUDE_FROM_ALL) 145 | 146 | # The gtest/gtest_main targets carry header search path 147 | # dependencies automatically when using CMake 2.8.11 or 148 | # later. Otherwise we have to add them here ourselves. 149 | if (CMAKE_VERSION VERSION_LESS 2.8.11) 150 | include_directories("${gtest_SOURCE_DIR}/include") 151 | endif() 152 | endif(NOT USE_DOCKER AND NOT ENABLE_WEBASSEMBLY AND ENABLE_TESTS) 153 | -------------------------------------------------------------------------------- /3rd-party/CMakeLists_benchmark.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(benchmark-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(benchmark 7 | GIT_REPOSITORY https://github.com/google/benchmark.git 8 | GIT_TAG main 9 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/benchmark-src" 10 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/benchmark-build" 11 | GIT_SHALLOW 1 12 | CONFIGURE_COMMAND "" 13 | BUILD_COMMAND "" 14 | INSTALL_COMMAND "" 15 | TEST_COMMAND "" 16 | ) 17 | -------------------------------------------------------------------------------- /3rd-party/CMakeLists_googletest.txt.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add(googletest 7 | GIT_REPOSITORY https://github.com/google/googletest.git 8 | GIT_TAG main 9 | GIT_SHALLOW 1 10 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 11 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 12 | CONFIGURE_COMMAND "" 13 | BUILD_COMMAND "" 14 | INSTALL_COMMAND "" 15 | TEST_COMMAND "" 16 | ) 17 | -------------------------------------------------------------------------------- /3rd-party/gtest-1.8.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/gtest-1.8.0.tar.gz -------------------------------------------------------------------------------- /3rd-party/json-3.5.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/json-3.5.0.tar.gz -------------------------------------------------------------------------------- /3rd-party/json-3.9.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/json-3.9.1.tar.gz -------------------------------------------------------------------------------- /3rd-party/nlohmann.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/nlohmann.tar.gz -------------------------------------------------------------------------------- /3rd-party/plog-1.1.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/plog-1.1.4.tar.gz -------------------------------------------------------------------------------- /3rd-party/plog-1.1.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/3rd-party/plog-1.1.5.tar.gz -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Releases 2 | 3 | *V0.6.0* 4 | * [x] Add broader support 5 | * [x] Fix emscripten with CMake 6 | * [x] Add support Ubuntu 16.04 7 | * [x] Better comments in samples 8 | * [x] Add remote container development environment 9 | * [x] Fix some suggestions 10 | * [x] Add H264 parser application 11 | * [x] Update third-party libs Plog and Json to latest version 12 | * [x] Enable CI testing for Windows and Mac 13 | 14 | *V0.5.0* 15 | * [x] Add github workflow: Crosscompilation Mac, Windows 16 | * [x] Cleanup Sample 17 | * [x] Added License 18 | * [x] Cleanup old Makefiles 19 | * [x] Added Contributing.md 20 | * [x] Remove msvc project files 21 | * [x] Added clang-tidy to CMake 22 | * [x] Added Valgrind memcheck 23 | * [x] Refactor CircleCi build using workflow 24 | * [x] Shrink Docker image size 25 | * [x] Add CircleCI badge 26 | * [x] Add CSS style to web page 27 | * [x] Refactor CMake structure 28 | * [x] Add compilation with Emscripten (webassembly) 29 | * [x] Add Doxygen and some comments 30 | * [x] Format CMake files 31 | * [x] Separate codec libs from parser lib 32 | * [x] Issue-233 Mac, fix issue with LLVM 9.0 33 | 34 | *V0.4.0* 35 | * [BUG-208] Build static and shared lib and package 36 | * [BUG-200] Add version info 37 | * [FEAT-195] Fix docker CMake 38 | * [x] Correct IWYU mistakes 39 | * [x] Fix Windows solution 40 | * [BUG-214] Turn of build plog samples 41 | * [BUG-207] Port Windows proj to CMake 42 | * [BUG-207] Update Windows support 43 | * [x] Add samples 44 | * [x] Fix gtest and benchmark build as 3rd-party 45 | * [BUG-220] Create Windows release script generator 46 | 47 | *V0.3.0* 48 | * [BUG-202] Fix TsUtilities crash when file not aligned to ts-packets 49 | * [BUG-191] Add CPack and package both debug/release build 50 | * [BUG-192] Add CMake finder for find_package 51 | * [BUG-193] Run include-what-you-use 52 | * [FEAT-181] Add include-what-you-use to CMake 53 | * [x] Update use Ubuntu 18.04 CircleCI 54 | * [FEAT-182] Improve Docker user 55 | * [FEAT-178] Port Make to CMake 56 | * [FEAT-174] Add cppcheck to CMake 57 | * [x] Port component-tests to CMake 58 | * [x] Port 3rd-party to CMake 59 | * [x] Add CMake install target 60 | * [x] Update CircleCI only use CMake 61 | * [x] Add version number from CMake to tsparser 62 | * [x] Add debug and release build 63 | * [FEAT-175, FEAT-177] Improve CMake considerable using modern CMake 64 | 65 | *V0.2.1* 66 | * [x] Fix build Release version and build issues (hotfix-0.2.1) 67 | 68 | *V0.2* 69 | * [x] Compile on Windows fixes 70 | * [FEAT-163] Add codec parsers to TsUtilities 71 | * [BUG-157] Codec parsers missing API 72 | * [FEAT-166] Add micro google benchmark tests 73 | * [BUG-161] Add H264/H262 unit tests 74 | * [FEAT-158] Add benchmark tests 75 | * [x] Add component tests to H264 parsing 76 | * [x] Update README. 77 | * [x] Apply C++ best practises (Lefticus) 78 | * [x] Apply clang formating/analyze 79 | * [FEAT-117] Use move instead of copying 80 | * [FEAT-51/52] Add codec parsing (H264/H262) 81 | * [FEAT-54] Add basic descriptor parsing 82 | * [FEAT-128] Add CMake 83 | * [FEAT-132] Add better code coverage 84 | * [FEAT-126] Use Wextra and Wpedantic with GCC 85 | * [FEAT-130] Add docker commands via bash 86 | * [FEAT-32] Add code coverage 87 | * [x] Added gtests to Windows proj 88 | * [x] Merge TestTsLib.proj into mpeg2ts.sln 89 | * [FEAT-102] Fixed some TODOs 90 | 91 | *V0.1* 92 | 93 | * Added first version of API (mpeg2ts.h) 94 | * Added Windows support and build artifacts (mpeg2ts.lib/dll) 95 | * Added Linux build artifacts (libmpeg2ts.so/a) 96 | * Added high-level TsUtilities.h API for convinience 97 | * Added first version H.264 support 98 | * Added support for short version CLI for tsparser (Linux only) 99 | * Fixed bug not finding and printing out error for settings.json 100 | 101 | *V0.0.2.rc1* 102 | 103 | * Add logging libary: Plog 104 | * Fixed bug 68: Cannot parse Hbo Asset 105 | * Add component-tests to CircleCi 106 | * Fixed bug 66: Dolby asset caused crash 107 | * Support Multiple Program Transport Streams (MPTS) 108 | * Added file input --input option to CLI 109 | * Fixed bug 49: Could not skip more than 64 bits in parser. 110 | * Added non root user to Docker containers 111 | 112 | *V0.0.1* 113 | 114 | * build so lib 115 | * Added es write 116 | * fixed PCR bug 117 | * Added build folder 118 | * Added PES parsing 119 | * Added multi PES cli option 120 | * Added PMT parsing 121 | * Added PAT parsing 122 | * Added Demuxer -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "x64-Release", 5 | "generator": "Ninja", 6 | "configurationType": "Release", 7 | "inheritEnvironments": [ 8 | "msvc_x64_x64" 9 | ], 10 | "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", 11 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 12 | "cmakeCommandArgs": "", 13 | "buildCommandArgs": "-v", 14 | "ctestCommandArgs": "" 15 | }, 16 | { 17 | "name": "x64-Debug", 18 | "generator": "Ninja", 19 | "configurationType": "Debug", 20 | "inheritEnvironments": [ 21 | "msvc_x64_x64" 22 | ], 23 | "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", 24 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 25 | "cmakeCommandArgs": "", 26 | "buildCommandArgs": "-v", 27 | "ctestCommandArgs": "" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Welcome Contributing to MPEG2TS 2 | 3 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 4 | 5 | * Reporting a bug 6 | * Discussing the current state of the code 7 | * Submitting a fix 8 | * Proposing new features 9 | * Becoming a maintainer 10 | 11 | ## We Develop with Github 12 | 13 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 14 | 15 | Pull requests are the best way to propose changes to the codebase (we use Git Flow as a branch strategy). We actively welcome your pull requests: 16 | 17 | * Fork the repo and create your branch from `develop`. 18 | * If you've added code that should be tested, add tests. 19 | * If you've changed APIs, update the documentation. 20 | * Ensure the test suite passes. 21 | * Make sure your code lints and formats (clang-tidy). 22 | * Issue the pull request! 23 | 24 | 25 | ## We Use Git Flow 26 | Most important main branches are: 27 | 28 | * **develop** (continous development) 29 | * **master** (stores releases) 30 | 31 | Along these there are a number of supporting branches: 32 | 33 | * feature branches 34 | * release branches 35 | * hotfix branches 36 | 37 | For more information about Git flow, please check [here](https://nvie.com/posts/a-successful-git-branching-model/). 38 | 39 | ## Issues 40 | We use GitHub issues to track public bugs. Report a bug by opening a new issue; it's that easy! 41 | Write bug reports with detail, background, and sample code 42 | 43 | This is an example of a bug report. 44 | Great Bug Reports tend to have: 45 | 46 | A quick summary and/or background 47 | Steps to reproduce 48 | Be specific! 49 | Give sample code if you can. My stackoverflow question includes sample code that anyone with a base R setup can run to reproduce what I was seeing 50 | What you expected would happen 51 | What actually happens 52 | Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 53 | 54 | ## Code style 55 | Format and lint the C++ code using clang. We use C++ core guidelines as [style](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines). 56 | 57 | 58 | make clang-format 59 | make clang-tidy 60 | 61 | ## License 62 | Any contributions you make will be under the MPEG2TS GPL v2 License (see License). 63 | 64 | In short, when you submit code changes, your submissions are understood to be under the same MPEG2TS GPL v2 that covers the project. Feel free to contact the maintainers if that's a concern. Report bugs using Github's issues. 65 | 66 | 67 | ## References 68 | 69 | This document was adapted from the open-source contribution guidelines for Facebook's Draft -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2 apps 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | if(ENABLE_WEBASSEMBLY) 28 | add_subdirectory(WebAssembly) 29 | endif() 30 | 31 | # only build tsparser on UNIX (getopt only exist in Linux) 32 | if (UNIX) 33 | add_subdirectory(tsparser) 34 | add_subdirectory(h264parser) 35 | endif(UNIX) 36 | -------------------------------------------------------------------------------- /apps/README.md: -------------------------------------------------------------------------------- 1 | # Apps 2 | These 2 apps are Command Line Interface apps that will help you parse either a transport-stream file or a h264 file. 3 | 4 | ## h264parser 5 | Example: 6 | 7 | ./h264parser --input myvideo.h264 8 | 9 | Help dialog: 10 | 11 | H264 parser command-line tool: 12 | USAGE: ./h264parser [-h] [-v] [-l log-level] [-i file] 13 | Option Arguments: 14 | -h [ --help ] Print help messages 15 | -v [ --version ] Print library version 16 | -l [ --log-level NONE|FATAL|ERROR|WARNING|INFO|DEBUG|VERBOSE] Choose what logs are filtered, both file and stdout, default: DEBUG 17 | -i [ --input FILE] Use input file for parsing 18 | 19 | 20 | ## tsparser 21 | Example: 22 | 23 | ./tsparser --input assets/test1.ts 24 | 25 | ### More usage 26 | To start runing the parser: 27 | 28 | ./tsparser --input assets/test1.ts 29 | 30 | Check help in command line (CLI): 31 | 32 | ./tsparser --help 33 | 34 | Add option --write with the PES PID for writing PES packets to file. 35 | 36 | ./tsparser --write 2306 --input assets/bbc_one.ts 37 | 38 | Just print PSI tables / PES header can be done by --pid option and the PID. 39 | 40 | ./tsparser --pid 258 --input assets/bbc_one.ts 41 | 42 | Help dialog: 43 | 44 | Mpeg2ts lib simple command-line: 45 | USAGE: ./tsparser [-h] [-v] [-p PID] [-w PID] [-m ts|pes|es] [-l log-level] [-i file] 46 | Option Arguments: 47 | -h [ --help ] Print help messages 48 | -v [ --version ] Print library version 49 | -p [ --pid PID] Print PSI tables info with PID 50 | -w [ --write PID] Writes PES packets with PID to file 51 | -m [ --wrmode type] Choose what type of data is written[ts|pes|es] 52 | -l [ --log-level NONE|FATAL|ERROR|WARNING|INFO|DEBUG|VERBOSE] Choose what logs are filtered, both file and stdout, default: DEBUG 53 | -i [ --input FILE] Use input file for parsing 54 | -------------------------------------------------------------------------------- /apps/WebAssembly/220px-Web_Assembly_Logo.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/apps/WebAssembly/220px-Web_Assembly_Logo.svg.png -------------------------------------------------------------------------------- /apps/WebAssembly/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts apps 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | a.out 32 | VERSION 0.6.0 33 | DESCRIPTION "Webassembly main" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | a.out 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_definitions(-std=c++11 -O3) 45 | 46 | add_executable( 47 | ${PROJECT_NAME} 48 | ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc 49 | ) 50 | 51 | #if(JS_ONLY) 52 | # message(STATUS "Setting compilation target to native JavaScript") 53 | # set(CMAKE_EXECUTABLE_SUFFIX ".js") 54 | # set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-s EXPORTED_FUNCTIONS='[_webAsmEntryPoint]'") 55 | #else(JS_ONLY) 56 | # message(STATUS "Setting compilation target to WASM") 57 | # set(CMAKE_EXECUTABLE_SUFFIX ".wasm") 58 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-std=c++11 -O3 -s WASM=1 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[cwrap, ccall]'" ) 59 | #EXPORTED_FUNCTIONS='[_webAsmEntryPoint]' 60 | #endif(JS_ONLY) 61 | 62 | 63 | target_include_directories( 64 | ${PROJECT_NAME} 65 | PRIVATE 66 | ${CMAKE_CURRENT_SOURCE_DIR}/src 67 | $# For TsParser.h 68 | $# For Mpeg2VideoParser.h 69 | $# For H264Parser.h 70 | ) 71 | 72 | target_link_libraries(${PROJECT_NAME} 73 | PRIVATE 74 | mpeg2ts 75 | mpeg2codec 76 | h264codec 77 | ) 78 | -------------------------------------------------------------------------------- /apps/WebAssembly/README.md: -------------------------------------------------------------------------------- 1 | # Webassembly 2 | With binary code directly executed by a browser as a plugin with embedded ABI from Javascript anything is now possible. Therefore a good begining is to be able to build mpeg2ts lib with em++ (Emscripten toolchain). Here is the toolchain command via CMake: 3 | 4 | ## Building 5 | First it requires you to first run the toolchain environment scipt (finding the programs): 6 | ```Bash 7 | source ./emsdk_env.sh 8 | ``` 9 | 10 | then building via cmake (assumes you are in the root of the repo): 11 | ```Bash 12 | mkdir build 13 | cd build/ 14 | 15 | emcmake cmake -DCMAKE_CXX_STANDARD=11 -DENABLE_TESTS=OFF -DENABLE_WEBASSEMBLY=ON .. 16 | ``` 17 | 18 | ## Run the app 19 | After building as described above copy the artifacts `a.out.js` and `a.out.wasm` to your source apps folder and 20 | open the `index.html` in a browser and you are runing the web app. 21 | 22 | 23 | ## Installing the emscripten SDK 24 | Building the latest SDK: 25 | ```Bash 26 | git clone https://github.com/emscripten-core/emsdk.git 27 | cd emsdk/ 28 | ./emsdk install latest 29 | ./emsdk activate latest 30 | source ./emsdk_env.sh 31 | ``` 32 | 33 | Building a certain version: 34 | ```Bash 35 | ./emsdk install 1.39.5 36 | source ./emsdk_env.sh 37 | ``` -------------------------------------------------------------------------------- /apps/WebAssembly/buildem.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ROOT_FOLDER=$(pwd)/../.. 4 | APP_FOLDER=$ROOT_FOLDER/apps/WebAssembly 5 | LIB_FOLDER=$ROOT_FOLDER/libs 6 | 7 | em++ -std=c++11 -O3 -s WASM=1 -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 -s \ 8 | "EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap', 'ccall']" \ 9 | -I $LIB_FOLDER/mpeg2codec/include \ 10 | -I $LIB_FOLDER/h264codec/include \ 11 | -I $LIB_FOLDER/mpeg2codec/src \ 12 | -I $LIB_FOLDER/h264codec/src \ 13 | -I $LIB_FOLDER/mpeg2ts/src \ 14 | -I $ROOT_FOLDER/build/libs/mpeg2ts \ 15 | -I $LIB_FOLDER/mpeg2ts/include \ 16 | -I $ROOT_FOLDER/3rd-party/plog-1.1.4/include \ 17 | -I $ROOT_FOLDER/3rd-party/json-3.5.0/include \ 18 | $APP_FOLDER/src/main.cc \ 19 | $LIB_FOLDER/mpeg2ts/src/TsStatistics.cc \ 20 | $LIB_FOLDER/mpeg2ts/src/TsParser.cc \ 21 | $LIB_FOLDER/mpeg2ts/src/TsDemuxer.cc \ 22 | $LIB_FOLDER/mpeg2ts/src/GetBits.cc \ 23 | $LIB_FOLDER/mpeg2ts/src/PsiTables.cc \ 24 | $LIB_FOLDER/h264codec/src/H264Parser.cc \ 25 | $LIB_FOLDER/mpeg2codec/src/Mpeg2VideoParser.cc \ 26 | $LIB_FOLDER/mpeg2codec/src/Mpeg2Codec.cc \ 27 | -------------------------------------------------------------------------------- /apps/WebAssembly/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/apps/WebAssembly/github.png -------------------------------------------------------------------------------- /apps/WebAssembly/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MPEG-2 transport stream analyzer 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 24 | 25 | 26 | 31 | 34 | 37 | 38 | 39 | 42 | 43 | 44 | 49 | 54 | 55 | 56 | 59 | 60 | 61 | 64 | 65 |
16 |

MPEG-2 transport stream analyzer

17 |
21 |
Select MPEG-2 transport stream file 22 |
23 |
27 | 28 | 29 |
PIDdiscontinuity errorscontinuity counter errorsPTS missingDTS missing
30 |
32 | Powered by 33 | 35 | Powered by 36 |
40 | 41 |
45 |
46 | Start offset 47 |
48 |
50 |
51 | End offset 52 |
53 |
57 | 58 |
62 | 63 |
66 | C++ engine powering this webpage is available on request. Email here. 67 | or here. 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /apps/WebAssembly/styles.css: -------------------------------------------------------------------------------- 1 | #pid_stats { 2 | font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; 3 | border-collapse: collapse; 4 | width: 100%; 5 | } 6 | 7 | #pid_stats td, #pid_stats th { 8 | border: 1px solid #ddd; 9 | padding: 8px; 10 | } 11 | 12 | #pid_stats tr:nth-child(even) { 13 | background-color: #f2f2f2; 14 | } 15 | 16 | #pid_stats tr:hover { 17 | background-color: #ddd; 18 | } 19 | 20 | #pid_stats th { 21 | padding-top: 12px; 22 | padding-bottom: 12px; 23 | text-align: left; 24 | background-color: #358eb1; 25 | color: white; 26 | } 27 | 28 | body { 29 | background-color: #eaebed; 30 | } 31 | 32 | h2 { 33 | color: #358eb1; 34 | font-size: 48px; 35 | font-family: 'Signika', sans-serif; 36 | padding-bottom: 10px; 37 | } 38 | 39 | a { 40 | color: red; 41 | font-family: 'Signika', sans-serif; 42 | } 43 | 44 | .select_text { 45 | font-size: 18px; 46 | font-family: 'Signika', sans-serif 47 | } -------------------------------------------------------------------------------- /apps/h264parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts tsparser 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | h264parser 32 | VERSION 0.6.0 33 | DESCRIPTION "CLI Parsing of h264 stream" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | h264parser 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_executable( 45 | ${PROJECT_NAME} 46 | src/main.cc 47 | ) 48 | 49 | target_include_directories( 50 | ${PROJECT_NAME} 51 | PRIVATE 52 | ${CMAKE_CURRENT_SOURCE_DIR}/src 53 | $# For TsParser.h 54 | $# For Mpeg2VideoParser.h 55 | $# For H264Parser.h 56 | ) 57 | 58 | target_link_libraries( 59 | ${PROJECT_NAME} 60 | PRIVATE 61 | h264codec 62 | common # For GetBits() 63 | ) 64 | 65 | set_target_properties( 66 | ${PROJECT_NAME} 67 | PROPERTIES 68 | VERSION ${PROJECT_VERSION} 69 | DEBUG_POSTFIX "-d" 70 | ) 71 | 72 | if(CMAKE_MINOR_VERSION GREATER 7) 73 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) # Available in CMake 3.8 74 | endif() 75 | -------------------------------------------------------------------------------- /apps/tsparser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts tsparser 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | tsparser 32 | VERSION 0.6.0 33 | DESCRIPTION "MPEG-2 CLI Parsing of transport streams" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | tsparser 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_executable( 45 | ${PROJECT_NAME} 46 | src/main.cc 47 | ) 48 | 49 | target_include_directories( 50 | ${PROJECT_NAME} 51 | PRIVATE 52 | ${CMAKE_CURRENT_SOURCE_DIR}/src 53 | $# For TsParser.h 54 | $# For Mpeg2VideoParser.h 55 | $# For H264Parser.h 56 | ) 57 | 58 | target_link_libraries( 59 | ${PROJECT_NAME} 60 | PRIVATE 61 | mpeg2ts 62 | mpeg2codec 63 | h264codec 64 | common # For GetBits() 65 | ) 66 | 67 | set_target_properties( 68 | ${PROJECT_NAME} 69 | PROPERTIES 70 | VERSION ${PROJECT_VERSION} 71 | DEBUG_POSTFIX "-d" 72 | ) 73 | 74 | if(CMAKE_MINOR_VERSION GREATER 7) 75 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) # Available in CMake 3.8 76 | endif() 77 | -------------------------------------------------------------------------------- /assets/bbc_one.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/assets/bbc_one.ts -------------------------------------------------------------------------------- /assets/test1.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/assets/test1.ts -------------------------------------------------------------------------------- /bench/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts bench 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | #------------------- 30 | # tests 31 | #------------------- 32 | 33 | file(GLOB_RECURSE ALL_BENCH_CPP *.cpp) 34 | 35 | foreach(ONE_BENCH_CPP ${ALL_BENCH_CPP}) 36 | get_filename_component(ONE_BENCH_EXEC ${ONE_BENCH_CPP} NAME_WE) 37 | 38 | # Avoid name collision 39 | set(TARGET_NAME Bench_${ONE_BENCH_EXEC}) 40 | 41 | add_executable(${TARGET_NAME} ${ONE_BENCH_CPP}) 42 | 43 | target_include_directories(${TARGET_NAME} 44 | PRIVATE 45 | $# For CodecTestData.h 46 | $# For EsParser.h 47 | $# For H264Parser.h 48 | $# For Mpeg2VideoParser.h 49 | ) 50 | 51 | if(CMAKE_MINOR_VERSION GREATER 7) 52 | target_compile_features(${TARGET_NAME} PRIVATE cxx_std_11) 53 | endif() 54 | 55 | set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${ONE_BENCH_EXEC}) 56 | find_package(Threads REQUIRED) 57 | target_link_libraries(${TARGET_NAME} 58 | PRIVATE 59 | Threads::Threads 60 | mpeg2ts 61 | benchmark 62 | mpeg2codec 63 | h264codec 64 | common 65 | ${CMAKE_THREAD_LIBS_INIT} 66 | ) 67 | 68 | # If you want to run benchmarks with the "make test" command, uncomment me 69 | #add_test(${TARGET_NAME} ${ONE_BENCH_EXEC}) 70 | endforeach() 71 | -------------------------------------------------------------------------------- /bench/Parser_Benchmark.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts benchmark 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | *******************************************************************/ 27 | 28 | #include 29 | #include 30 | 31 | #include "CodecTestData.h" 32 | #include "EsParser.h" 33 | #include "H264Parser.h" 34 | #include "Mpeg2VideoParser.h" 35 | 36 | /// DUMMY tests 37 | 38 | static void BM_StringCreation(benchmark::State& state) 39 | { 40 | for (auto _ : state) 41 | std::string empty_string; 42 | } 43 | // Register the function as a benchmark 44 | BENCHMARK(BM_StringCreation); 45 | 46 | // Define another benchmark 47 | static void BM_StringCopy(benchmark::State& state) 48 | { 49 | std::string x = "hello"; 50 | for (auto _ : state) 51 | std::string copy(x); 52 | } 53 | BENCHMARK(BM_StringCopy); 54 | 55 | /////////// parser bench 56 | 57 | //// H264 58 | 59 | static void BM_H264EsParser_findStartCodes(benchmark::State& state) 60 | { 61 | h264::H264EsParser parser; 62 | 63 | for (auto _ : state) 64 | { 65 | std::vector ind = parser.findStartCodes(h262_with_sequence_header_code); 66 | } 67 | } 68 | BENCHMARK(BM_H264EsParser_findStartCodes); 69 | 70 | 71 | static void BM_H264EsParser_parse(benchmark::State& state) 72 | { 73 | h264::H264EsParser parser; 74 | 75 | for (auto _ : state) 76 | { 77 | std::vector data = parser.parse(h262_with_sequence_header_code); 78 | } 79 | } 80 | BENCHMARK(BM_H264EsParser_parse); 81 | 82 | ////// H262 83 | 84 | static void BM_Mpeg2VideoEsParser_findStartCodes(benchmark::State& state) 85 | { 86 | mpeg2::Mpeg2VideoEsParser parser; 87 | 88 | for (auto _ : state) 89 | { 90 | std::vector ind = parser.findStartCodes(h262_with_sequence_header_code); 91 | } 92 | } 93 | BENCHMARK(BM_H264EsParser_findStartCodes); 94 | 95 | static void BM_Mpeg2VideoEsParser_parse(benchmark::State& state) 96 | { 97 | mpeg2::Mpeg2VideoEsParser parser; 98 | 99 | for (auto _ : state) 100 | { 101 | std::vector data = parser.parse(h262_with_sequence_header_code); 102 | } 103 | } 104 | BENCHMARK(BM_Mpeg2VideoEsParser_parse); 105 | 106 | BENCHMARK_MAIN(); 107 | -------------------------------------------------------------------------------- /cmake/clang_format.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | option(USE_CLANG_FORMAT "Use clang-format for formatting c++ files" OFF) 30 | 31 | if(NOT USE_CLANG_FORMAT) 32 | message(STATUS " Not using clang-tidy!") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using clang-format") 37 | 38 | set(CLANG_VERSION 7) 39 | 40 | find_program( 41 | CLANG_FORMAT_EXE 42 | NAMES "clang-format-${CLANG_VERSION}" 43 | DOC "Path to clang-format executable" 44 | ) 45 | 46 | if(NOT CLANG_FORMAT_EXE) 47 | message(WARNING " clang-format not found on your system. Bailing out...") 48 | return() 49 | else() 50 | message(STATUS " clang-format found: ${CLANG_FORMAT_EXE}") 51 | set(DO_CLANG_FORMAT "${CLANG_FORMAT_EXE}" "-i -style=file") 52 | endif() 53 | 54 | 55 | # get all project files 56 | file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) 57 | 58 | if(CMAKE_MINOR_VERSION GREATER 5) 59 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") 60 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") 61 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") 62 | else() 63 | 64 | endif() 65 | 66 | add_custom_target( 67 | clang-format 68 | COMMAND ${CLANG_FORMAT_EXE} 69 | -style=file 70 | -i 71 | ${ALL_SOURCE_FILES} 72 | ) 73 | -------------------------------------------------------------------------------- /cmake/clang_tidy.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | option(USE_CLANG_TIDY "Use clang-tidy for static code analysis" OFF) 30 | 31 | if(NOT USE_CLANG_TIDY) 32 | message(STATUS " Not using clang-tidy!") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using clang-tidy") 37 | 38 | set(CLANG_VERSION 7) 39 | 40 | find_program( 41 | CLANG_TIDY_EXE 42 | NAMES "clang-tidy-${CLANG_VERSION}" 43 | ) 44 | 45 | if(NOT CLANG_TIDY_EXE) 46 | message(WARNING " clang-tidy not found bailing out...") 47 | return() 48 | else() 49 | message(STATUS " clang-tidy found: ${CLANG_TIDY_EXE}") 50 | endif() 51 | 52 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 53 | message(STATUS " clang-tidy : ON") 54 | message(STATUS " Program exe : ${CLANG_TIDY_EXE}") 55 | message(STATUS " Extra flags : ${CXX_CLANG_TIDY_EXTRA_FLAGS}") 56 | if(NOT CXX_CLANG_TIDY_EXTRA_FLAGS) 57 | set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}") 58 | else() 59 | set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "${CXX_CLANG_TIDY_EXTRA_FLAGS}") 60 | endif() 61 | message(STATUS " Command : ${DO_CLANG_TIDY}") 62 | 63 | 64 | # get all project files 65 | file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) 66 | 67 | if(CMAKE_MINOR_VERSION GREATER 5) 68 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") 69 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") 70 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") 71 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Release") 72 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "Debug") 73 | endif() 74 | 75 | # src/*.cc -checks=* -- -std=c++11 -I/usr/include/c++/5/ -I./include 76 | 77 | add_custom_target( 78 | clang-tidy 79 | COMMAND ${CLANG_TIDY_EXE} 80 | ${ALL_SOURCE_FILES} 81 | -checks=* 82 | -- -std=c++11 83 | -I/usr/include/c++/7 -I./include 84 | } 85 | ) 86 | -------------------------------------------------------------------------------- /cmake/cppcheck.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | option(USE_CPPCHECK "Use cppcheck for static code analysis" OFF) 30 | 31 | if(NOT USE_CPPCHECK) 32 | message(STATUS " Not using cppcheck!") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using cppcheck") 37 | 38 | find_program( 39 | CPPCHECK_EXE 40 | NAMES "cppcheck" 41 | DOC "Path to cppcheck executable" 42 | ) 43 | 44 | if(NOT CPPCHECK_EXE) 45 | message(WARNING " cppcheck not found on your system. Bailing out...") 46 | return() 47 | else() 48 | message(STATUS " cppcheck found: ${CPPCHECK_EXE}") 49 | endif() 50 | 51 | 52 | # get all project files 53 | file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.cc) 54 | 55 | if(CMAKE_MINOR_VERSION GREATER 5) 56 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "3rd-party") 57 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "gtest") 58 | list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX "build") 59 | endif() 60 | 61 | add_custom_target( 62 | cppcheck 63 | COMMAND ${CPPCHECK_EXE} 64 | --enable=all 65 | --std=c++11 66 | --verbose 67 | --quiet 68 | ${ALL_SOURCE_FILES} 69 | ) 70 | -------------------------------------------------------------------------------- /cmake/doxygen.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | option(USE_DOXYGEN "Use Doxygen for inline documentation." OFF) 30 | 31 | if(NOT USE_DOXYGEN) 32 | message(STATUS " Not using Doxygen!") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using Doxygen") 37 | 38 | # Require dot, treat the other components as optional 39 | find_package( 40 | Doxygen 41 | OPTIONAL_COMPONENTS dot mscgen dia 42 | ) 43 | 44 | if(NOT DOXYGEN_FOUND) 45 | message(WARNING " Doxygen not found on your system. Bailing out...") 46 | return() 47 | else() 48 | message(STATUS " doxygen found: ${DOXYGEN_EXECUTABLE}") 49 | 50 | doxygen_add_docs( 51 | doxygen 52 | ${PROJECT_SOURCE_DIR}/README.md ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/samples 53 | COMMENT "Generate doxygen pages" 54 | ) 55 | endif() 56 | -------------------------------------------------------------------------------- /cmake/emscripten.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(NOT ENABLE_WEBASSEMBLY) 30 | message(STATUS " Not using emscripten!") 31 | return() 32 | endif() 33 | 34 | message(STATUS " Using emscripten") 35 | 36 | if(NOT EMSCRIPTEN_PREFIX) 37 | message(STATUS " EMSCRIPTEN_PREFIX not defined!") 38 | if(DEFINED ENV{EMSCRIPTEN}) 39 | file(TO_CMAKE_PATH "$ENV{EMSCRIPTEN}" EMSCRIPTEN_PREFIX) 40 | set(EMSCRIPTEN_PREFIX $ENV{EMSCRIPTEN}) 41 | else() 42 | set(EMSCRIPTEN_PREFIX "/usr/lib/emscripten") 43 | message(WARNING " Could not find Emscripten toolchain, using /usr/lib/emscripten instead!") 44 | endif() 45 | endif() 46 | -------------------------------------------------------------------------------- /cmake/iwyu.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.3 FATAL_ERROR) 28 | 29 | option(USE_IWYU "Use include-what-you-use for static include analysis" OFF) 30 | 31 | if (NOT USE_IWYU) 32 | message(STATUS " Not using include-what-you-use! To enable it, append -DUSE_IWYU=ON") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using include-what-you-use") 37 | 38 | find_program( 39 | iwyu_exe 40 | NAMES include-what-you-use iwyu 41 | ) 42 | 43 | if(NOT iwyu_exe) 44 | message(WARNING " Could not find the program include-what-you-use, baling out...") 45 | return() 46 | else() 47 | message(STATUS " Using include-what-you-use include analysis.") 48 | endif() 49 | 50 | set_property(TARGET mpeg2ts PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_exe}) 51 | -------------------------------------------------------------------------------- /cmake/toolchains/emscripten-wasm.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Toolchain for cross-compiling to JS using Emscripten with WebAssembly 3 | # 4 | # Modify EMSCRIPTEN_PREFIX to your liking; use EMSCRIPTEN environment variable 5 | # to point to it or pass it explicitly via -DEMSCRIPTEN_PREFIX=. 6 | # 7 | # mkdir build-emscripten-wasm && cd build-emscripten-wasm 8 | # cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchains/generic/Emscripten-wasm.cmake 9 | # 10 | 11 | #set(CMAKE_SYSTEM_NAME Emscripten) 12 | set(CMAKE_SYSTEM_NAME Generic) # To avoid warning "System is unknown to CMake..." 13 | 14 | set(EMSCRIPTEN_TOOLCHAIN_PATH "${EMSCRIPTEN_PREFIX}/system") 15 | 16 | if(CMAKE_HOST_WIN32) 17 | set(EMCC_SUFFIX ".bat") 18 | else() 19 | set(EMCC_SUFFIX "") 20 | endif() 21 | set(CMAKE_C_COMPILER "${EMSCRIPTEN_PREFIX}/emcc${EMCC_SUFFIX}") 22 | set(CMAKE_CXX_COMPILER "${EMSCRIPTEN_PREFIX}/em++${EMCC_SUFFIX}") 23 | set(CMAKE_AR "${EMSCRIPTEN_PREFIX}/emar${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten ar") 24 | set(CMAKE_RANLIB "${EMSCRIPTEN_PREFIX}/emranlib${EMCC_SUFFIX}" CACHE FILEPATH "Emscripten ranlib") 25 | 26 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} 27 | "${EMSCRIPTEN_TOOLCHAIN_PATH}" 28 | "${EMSCRIPTEN_PREFIX}") 29 | 30 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 31 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 32 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 33 | 34 | # Otherwise FindCorrade fails to find _CORRADE_MODULE_DIR. Why the heck is this 35 | # not implicit is beyond me. 36 | set(CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_FIND_ROOT_PATH}) 37 | 38 | # Compared to the classic (asm.js) compilation, -s WASM=1 is added to both 39 | # compiler and linker. The *_INIT variables are available since CMake 3.7, so 40 | # it won't work in earlier versions. Sorry. 41 | cmake_minimum_required(VERSION 3.7) 42 | set(CMAKE_CXX_FLAGS_INIT "-s WASM=1") 43 | set(CMAKE_EXE_LINKER_FLAGS_INIT "-s WASM=1") 44 | set(CMAKE_CXX_FLAGS_RELEASE_INIT "-DNDEBUG -O3") 45 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "-O3 --llvm-lto 1") 46 | set(CMAKE_CXX_STANDARD 11) 47 | -------------------------------------------------------------------------------- /cmake/valgrind.cmake: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts cmake 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.3 FATAL_ERROR) 28 | 29 | option(USE_VALGRIND "Use Valgrind for dynamic profiling / memcheck analysis" OFF) 30 | 31 | if(NOT USE_VALGRIND) 32 | message(STATUS " Not using Valgrind!") 33 | return() 34 | endif() 35 | 36 | message(STATUS " Using Valgrind") 37 | 38 | find_program( 39 | MEMORYCHECK_COMMAND 40 | NAMES valgrind 41 | ) 42 | 43 | if(NOT MEMORYCHECK_COMMAND) 44 | message(WARNING " valgrind not found on your system. Bailing out...") 45 | return() 46 | else() 47 | message(STATUS " valgrind found: ${MEMORYCHECK_COMMAND}") 48 | endif() 49 | 50 | 51 | set(MEMORYCHECK_COMMAND valgrind) 52 | set(CTEST_MEMORYCHECK_COMMAND valgrind ) 53 | set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--tool=callgrind -v" ) 54 | set(CTEST_MEMORYCHECK_TYPE "Valgrind") 55 | set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full") 56 | set(MEMORYCHECK_SUPPRESSIONS_FILE 57 | "${PROJECT_SOURCE_DIR}/tests/valgrind_suppress.txt") 58 | message( 59 | STATUS 60 | " MemCheck will use ${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS} ${MEMORYCHECK_SUPPRESSIONS_FILE}" 61 | ) 62 | message( 63 | STATUS 64 | " Read the Documentation for the meaning of these flags: http://valgrind.org/docs/manual/mc-manual.html" 65 | ) 66 | set(USE_MEM_CHECK ON) 67 | -------------------------------------------------------------------------------- /component_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts component_tests 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | project(CmakeVirtualenv) 30 | 31 | enable_testing() 32 | 33 | set(PYTHON_VERSION 3) 34 | 35 | # Find Python and Virtualenv. We don't actually use the output of the 36 | # find_package, but it'll give nicer errors. 37 | find_package(PythonInterp) 38 | find_program(VIRTUALENV virtualenv) 39 | if(NOT VIRTUALENV) 40 | message(FATAL_ERROR "Could not find `virtualenv` in PATH. You may need install by sudo apt-get install virtualenv.") 41 | return() 42 | endif() 43 | 44 | set(VIRTUALENV ${VIRTUALENV} -p python${PYTHON_VERSION}) 45 | 46 | # Generate the virtualenv and ensure it's up to date. 47 | add_custom_command( 48 | OUTPUT venv 49 | COMMAND ${VIRTUALENV} venv 50 | ) 51 | add_custom_command( 52 | OUTPUT venv.stamp 53 | DEPENDS venv requirements.txt 54 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt requirements.txt 55 | COMMAND ./venv/bin/pip install -r requirements.txt --upgrade 56 | ) 57 | 58 | # Build command line to run py.test. 59 | set(PYTEST 60 | ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/python${PYTHON_VERSION} 61 | ${CMAKE_CURRENT_BINARY_DIR}/venv/bin/py.test 62 | ) 63 | 64 | add_custom_target( 65 | Tests 66 | ALL 67 | DEPENDS venv.stamp 68 | SOURCES requirements.txt 69 | ) 70 | 71 | # add_test(NAME run_tests 72 | # COMMAND ${PYTEST} --benchmark-skip ${CMAKE_CURRENT_SOURCE_DIR}/cmdline_test.py 73 | # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 74 | # ) 75 | 76 | # add_test (NAME python-tests 77 | # COMMAND ${PYTHON_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR} 78 | # WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 79 | # ) 80 | 81 | add_custom_target( 82 | component-tests 83 | COMMAND ${PYTEST} --benchmark-skip ${CMAKE_CURRENT_SOURCE_DIR} 84 | ) 85 | 86 | add_custom_target( 87 | component-benchmark-tests 88 | COMMAND ${PYTEST} --benchmark-enable --benchmark-only ${CMAKE_CURRENT_SOURCE_DIR} 89 | ) 90 | 91 | add_custom_target( 92 | version 93 | COMMAND ${PYTEST} --version 94 | ) 95 | -------------------------------------------------------------------------------- /component_tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/component_tests/__init__.py -------------------------------------------------------------------------------- /component_tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest 2 | gitpython 3 | xmltodict 4 | pytest-benchmark -------------------------------------------------------------------------------- /component_tests/tsparser.py: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts tsparser.py 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | import os 28 | import time 29 | import sys 30 | import git 31 | import subprocess 32 | import fnmatch 33 | 34 | 35 | def git_root(path): 36 | git_repo = git.Repo(path, search_parent_directories=True) 37 | git_root = git_repo.git.rev_parse("--show-toplevel") 38 | return git_root 39 | 40 | 41 | def project_root(): 42 | return "%s" % git_root("./") 43 | 44 | def find(pattern, path): 45 | result = [] 46 | for root, dirs, files in os.walk(path): 47 | for name in files: 48 | if fnmatch.fnmatch(name, pattern): 49 | result.append(os.path.join(root, name)) 50 | return result 51 | 52 | class TsParser(object): 53 | """This object reflects TsParser executable.""" 54 | parser = find('tsparser-d', project_root()) 55 | parser = parser[0] 56 | print("Using tsparser exe: {}".format(parser)) 57 | 58 | def __init__(self, logger): 59 | self.proc = None 60 | self.log = logger 61 | 62 | def __enter__(self): 63 | return self 64 | 65 | def __exit__(self, exc_type, exc_value, traceback): 66 | try: 67 | self.stop() 68 | except Exception as e: 69 | print("TsParser failed to stop: %r" % e) 70 | assert exc_type is None 71 | 72 | def start(self, **kwargs): 73 | """Start a process with arguments""" 74 | return self._start(**kwargs) 75 | 76 | def _start(self, **kwargs): 77 | """Internal function that forks a new process of executable with given 78 | arguments""" 79 | cmd = self.start_cmd(**kwargs) 80 | self.log.info("start command: %s" % cmd) 81 | 82 | self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, 83 | stderr=subprocess.PIPE, 84 | universal_newlines=True) 85 | out, err, exitcode = self.wait() 86 | 87 | #self.log.info(out) 88 | if err is not "": 89 | self.log.error(err) 90 | sys.stderr.write(err) 91 | 92 | return exitcode, out, err 93 | 94 | def start_cmd(self, **kwargs): 95 | args = self._collect_args(**kwargs) 96 | cmd = [self.parser] 97 | cmd.extend(args) 98 | return cmd 99 | 100 | def wait(self, timeout=60): 101 | """Wait for the process to exit""" 102 | print("Waiting for parser process to exit") 103 | wait_start_time = time.time() 104 | out, err = self.proc.communicate() 105 | print("Parser process done after ", 106 | round(time.time() - wait_start_time), " seconds") 107 | exitcode = self.proc.returncode 108 | return out, err, exitcode 109 | 110 | @classmethod 111 | def _collect_args(self, info=None, extra_args=None): 112 | """Collects all the input arguments for the process.""" 113 | args = [] 114 | 115 | if info: 116 | args.append('--info') 117 | args.append(info) 118 | if extra_args: 119 | args.extend(extra_args) 120 | 121 | args = (str(a) for a in args) 122 | return args 123 | -------------------------------------------------------------------------------- /docker/Makefile: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts Makefile 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | 28 | include Makefile.variables 29 | 30 | 31 | ## Project 32 | COMPONENT_NAME ?= mpeg2ts 33 | export PROJ_ROOT := $(CURDIR) 34 | 35 | .PHONY: all docker-image 36 | 37 | help: 38 | @echo 39 | @echo ' docker-image - builds new docker image with name:tag in Makefile.' 40 | @echo 41 | 42 | all: help 43 | 44 | # Build docker image 45 | docker-image: 46 | docker build \ 47 | --file=$(DOCKER_IMAGE_BASE)/Dockerfile \ 48 | --tag=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VER) \ 49 | --tag=$(DOCKER_IMAGE_NAME):latest ./ 50 | 51 | docker-image-circleci: 52 | docker build \ 53 | --file=$(DOCKER_IMAGE_BASE)/circleci/Dockerfile \ 54 | --tag=heliconwave/circleci-ubuntu-18.04:$(DOCKER_IMAGE_VER) \ 55 | --tag=heliconwave/circleci-ubuntu-18.04:latest ./ 56 | 57 | docker-image-ubuntu-16.04: 58 | docker build \ 59 | --file=ubuntu_16_04/Dockerfile \ 60 | --tag=heliconwave/mpeg2ts-ubuntu-16.04:v2 \ 61 | --tag=heliconwave/mpeg2ts-ubuntu-16.04:latest ./ 62 | 63 | docker-image-circleci-ubuntu-18.04: 64 | docker build \ 65 | --file=ubuntu_18_04/circleci/Dockerfile \ 66 | --tag=heliconwave/circleci-ubuntu-18.04:$(DOCKER_IMAGE_VER) \ 67 | --tag=heliconwave/circleci-ubuntu-18.04:latest ./ 68 | 69 | docker-image-circleci-ubuntu-16.04: 70 | docker build \ 71 | --file=ubuntu_16_04/circleci/Dockerfile \ 72 | --tag=heliconwave/circleci-ubuntu-16.04:$(DOCKER_IMAGE_VER) \ 73 | --tag=heliconwave/circleci-ubuntu-16.04:latest ./ 74 | 75 | docker-bash-ubuntu-16.04: 76 | docker run \ 77 | --rm \ 78 | --interactive \ 79 | --tty=true \ 80 | --env LOCAL_USER_ID=`id -u ${USER}` \ 81 | --env "TERM=xterm-256color" \ 82 | --volume=$$(pwd)/..:/home/docker/workspace \ 83 | --workdir=/home/docker/workspace \ 84 | heliconwave/mpeg2ts-ubuntu-16.04:latest /bin/bash 85 | 86 | docker-bash-circleci-ubuntu-16.04: 87 | docker run \ 88 | --rm \ 89 | --interactive \ 90 | --tty=true \ 91 | --env LOCAL_USER_ID=`id -u ${USER}` \ 92 | --env "TERM=xterm-256color" \ 93 | --volume=$$(pwd)/..:/home/docker/workspace \ 94 | --workdir=/home/docker/workspace \ 95 | heliconwave/circleci-ubuntu-16.04:latest /bin/bash 96 | 97 | 98 | docker-bash-circleci-ubuntu-18.04: 99 | docker run \ 100 | --rm \ 101 | --interactive \ 102 | --tty=true \ 103 | --env LOCAL_USER_ID=`id -u ${USER}` \ 104 | --env "TERM=xterm-256color" \ 105 | --volume=$$(pwd)/..:/home/docker/workspace \ 106 | --workdir=/home/docker/workspace \ 107 | heliconwave/circleci-ubuntu-18.04:latest /bin/bash 108 | -------------------------------------------------------------------------------- /docker/Makefile.variables: -------------------------------------------------------------------------------- 1 | DOCKER_IMAGE_BASE=ubuntu_18_04 2 | DOCKER_IMAGE_NAME=heliconwave/mpeg2ts-ubuntu-18.04 3 | DOCKER_IMAGE_VER=v4 4 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | 3 | To virtualize the Application build time dependencies they have been collected inside a docker image following 4 | docker best practises. You only need to remember to source the 5 | ``` 6 | source docker/docker-commands.sh 7 | ``` 8 | and you will be ready to run commands inside the docker container like. Here is a list of all commands. 9 | 10 | | Command | Meaning | 11 | |----------------------|-----------------------------| 12 | | docker-bash | run a bash command inside a docker container 13 | | docker-make | run a make command inside a docker container 14 | | docker-interactive | starts a bash session inside a docker container 15 | | docker-run | run a command inside a docker container 16 | 17 | ## Examples 18 | 19 | configuring CMake: 20 | ```Bash 21 | cd build/ 22 | docker-bash cmake .. 23 | ``` 24 | building 25 | ```Bash 26 | docker-bash make -j $(nproc) 27 | ``` 28 | and testing: 29 | ```Bash 30 | docker-bash unit-tests 31 | ``` 32 | for example. 33 | If you want to run a custom bash command you can do it by: 34 | ```Bash 35 | docker-bash make help 36 | ``` 37 | for instance. To get an interactive bash session type: 38 | ```Bash 39 | docker-interactive 40 | ``` 41 | which will give you a docker shell: 42 | ```Bash 43 | docker@48fefc2ad3cf:/tmp/workspace/build 44 | ``` 45 | 46 | ### Docker image 47 | To just use the latest image just pull from our private registry/repository @ DockerHub: 48 | ``` 49 | docker pull heliconwave/circleci:v1 50 | ``` 51 | To build the image your self: 52 | ``` 53 | make docker-image 54 | ``` 55 | -------------------------------------------------------------------------------- /docker/docker-commands.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #***************************************************************** 3 | # 4 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 5 | # 6 | # mpeg2ts - mpeg2ts samples 7 | # 8 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 9 | # 10 | # Unless you have obtained mpeg2ts under a different license, 11 | # this version of mpeg2ts is mpeg2ts|GPL. 12 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU General Public License as 14 | # published by the Free Software Foundation; either version 2, 15 | # or (at your option) any later version. 16 | # 17 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU General Public License 23 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 24 | # the Free Software Foundation, 59 Temple Place - Suite 330, 25 | # Boston, MA 02111-1307, USA. 26 | # 27 | #*******************************************************************/ 28 | 29 | # get git root 30 | get_repo_root(){ 31 | local REPO_ROOT="$(git rev-parse --show-toplevel)" 32 | echo "$REPO_ROOT" 33 | } 34 | 35 | # get sub directory in source three 36 | get_sub_dir() { 37 | REPO_ROOT=$(get_repo_root) 38 | CUR_DIR=$(pwd) 39 | SUB_DIR=$(echo "$CUR_DIR" | grep -oP "^$REPO_ROOT\K.*") 40 | echo "$SUB_DIR" 41 | } 42 | 43 | # Run commands inside docker container 44 | docker_run() { 45 | REPO_ROOT=$(get_repo_root) 46 | echo "Using REPO_ROOT: " "$REPO_ROOT" 47 | source $REPO_ROOT/docker/Makefile.variables 48 | 49 | SUB_DIR=$(get_sub_dir) 50 | echo "SUB_DIR: " "$SUB_DIR" 51 | 52 | echo "Starting container: " "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VER" 53 | 54 | echo "Got command: " "$*" 55 | USER_ID=$(id -u $USER) 56 | echo "Using USER_ID:" $USER_ID 57 | 58 | docker run --env LOCAL_USER_ID=$USER_ID \ 59 | --rm \ 60 | --volume $REPO_ROOT:/tmp/workspace \ 61 | --workdir /tmp/workspace$SUB_DIR \ 62 | --env "TERM=xterm-256color" \ 63 | --tty \ 64 | --entrypoint /tmp/workspace/docker/entrypoint.sh \ 65 | "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VER" \ 66 | $* 67 | } 68 | 69 | # start tty session inside docker container 70 | docker-interactive() { 71 | REPO_ROOT=$(get_repo_root) 72 | echo "Using REPO_ROOT: " "$REPO_ROOT" 73 | source $REPO_ROOT/docker/Makefile.variables 74 | 75 | SUB_DIR=$(get_sub_dir) 76 | echo "SUB_DIR: " "$SUB_DIR" 77 | 78 | echo "Starting container: " "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VER" 79 | 80 | echo "Got command: " "$*" 81 | USER_ID=$(id -u $USER) 82 | echo "Using USER_ID:" $USER_ID 83 | 84 | docker run --env LOCAL_USER_ID=$USER_ID \ 85 | --rm \ 86 | --interactive \ 87 | --volume $REPO_ROOT:/tmp/workspace \ 88 | --workdir /tmp/workspace$SUB_DIR \ 89 | --env "TERM=xterm-256color" \ 90 | --tty \ 91 | --entrypoint /tmp/workspace/docker/entrypoint.sh \ 92 | "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_VER" /bin/bash 93 | } 94 | 95 | # Run make target inside docker 96 | docker-make() { 97 | docker_run make "${@}" 98 | } 99 | 100 | # Run bash command inside docker 101 | docker-bash() { 102 | docker_run "${@}" 103 | } 104 | -------------------------------------------------------------------------------- /docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Add local user 4 | # Either use the LOCAL_USER_ID if passed in at runtime or 5 | # fallback 6 | 7 | USER_ID=${LOCAL_USER_ID:-9001} 8 | echo "LOCAL_USER_ID: $LOCAL_USER_ID" 9 | USER=docker 10 | UPWD=Docker! 11 | 12 | echo "Starting with USER: $USER and UID : $USER_ID" 13 | useradd --shell /bin/bash --uid $USER_ID -o -c "" -m "$USER" 14 | # Add user to sudoers 15 | echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/10-installer 16 | # Add root password 17 | echo "root":$UPWD | chpasswd 18 | # Add user password 19 | echo "$USER:$UPWD" | chpasswd 20 | export HOME=/home/$USER 21 | su $USER 22 | echo "Starting user:" 23 | whoami 24 | -------------------------------------------------------------------------------- /docker/ubuntu_16_04/Dockerfile: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts Dockerfile 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | 28 | FROM ubuntu:16.04 as base 29 | 30 | ### Create user account ### 31 | FROM base as user 32 | RUN apt-get update && apt-get -y --no-install-recommends install \ 33 | ca-certificates=20170717~16.04.1 \ 34 | curl 35 | 36 | RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 37 | RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture)" \ 38 | && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture).asc" \ 39 | && gpg --verify /usr/local/bin/gosu.asc \ 40 | && rm /usr/local/bin/gosu.asc \ 41 | && chmod +x /usr/local/bin/gosu 42 | 43 | ### Builder image ### 44 | FROM user as build 45 | 46 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 47 | apt-utils \ 48 | software-properties-common \ 49 | build-essential \ 50 | tstools \ 51 | gdb \ 52 | gdbserver \ 53 | wget \ 54 | lcov \ 55 | sudo \ 56 | zip \ 57 | unzip \ 58 | doxygen \ 59 | cmake \ 60 | openssh-client \ 61 | git \ 62 | graphviz && \ 63 | apt-get clean && \ 64 | rm -rf /var/lib/apt/lists/* 65 | 66 | # LLVM Clang 67 | ENV CLANG_VERSION=7 68 | RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 69 | RUN apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$CLANG_VERSION main" 70 | RUN apt-get update 71 | #RUN apt-get install --yes --no-install-recommends clang-$CLANG_VERSION 72 | RUN apt-get install --yes --no-install-recommends clang-tidy-$CLANG_VERSION 73 | RUN apt-get install --yes --no-install-recommends clang-format-$CLANG_VERSION 74 | 75 | 76 | # python support 77 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 78 | python3-setuptools=20.7.0-1 \ 79 | virtualenv=15.0.1+ds-3ubuntu1 \ 80 | python3-pip=8.1.1-2ubuntu0.4 \ 81 | python3-dev=3.5.1-3 \ 82 | python3-virtualenv=15.0.1+ds-3ubuntu1 \ 83 | python3-pip && \ 84 | apt-get clean && \ 85 | rm -rf /var/lib/apt/lists/* 86 | 87 | 88 | #python packages 89 | RUN pip3 install flake8 90 | 91 | # Install latest cppcheck 92 | RUN git clone https://github.com/danmar/cppcheck.git /cppcheck \ 93 | && mkdir /cppcheck/build \ 94 | && cd /cppcheck/build \ 95 | && cmake .. && cmake --build . -- -j16 && make install \ 96 | && cd / && rm -rf /cppcheck 97 | 98 | # Install gtest/gmock 99 | RUN git clone -q https://github.com/google/googletest.git /googletest \ 100 | && cd googletest \ 101 | && git checkout tags/release-1.8.1 \ 102 | && mkdir -p /googletest/build \ 103 | && cd /googletest/build \ 104 | && cmake .. && make && make install \ 105 | && cd / && rm -rf /googletest 106 | 107 | # Install benchmark 108 | RUN git clone -q https://github.com/google/benchmark.git /benchmark \ 109 | && cd benchmark \ 110 | && git checkout tags/v1.4.0 \ 111 | && mkdir -p /benchmark/build \ 112 | && cd /benchmark/build \ 113 | && cmake -DCMAKE_BUILD_TYPE=Release .. && make && make install \ 114 | && cd / && rm -rf /benchmark 115 | 116 | # entrypoint 117 | COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh 118 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 119 | 120 | WORKDIR /tmp/workspace 121 | -------------------------------------------------------------------------------- /docker/ubuntu_16_04/circleci/Dockerfile: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts Dockerfile 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | 28 | FROM ubuntu:16.04 as base 29 | 30 | ### Create user account ### 31 | FROM base as user 32 | RUN apt-get update && apt-get -y --no-install-recommends install \ 33 | ca-certificates=20170717~16.04.1 \ 34 | curl 35 | 36 | RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 37 | RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture)" \ 38 | && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.4/gosu-$(dpkg --print-architecture).asc" \ 39 | && gpg --verify /usr/local/bin/gosu.asc \ 40 | && rm /usr/local/bin/gosu.asc \ 41 | && chmod +x /usr/local/bin/gosu 42 | 43 | ### Builder image ### 44 | FROM user as build 45 | 46 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 47 | apt-utils \ 48 | software-properties-common \ 49 | build-essential \ 50 | wget \ 51 | sudo \ 52 | zip \ 53 | unzip \ 54 | cmake \ 55 | openssh-client \ 56 | git \ 57 | graphviz && \ 58 | apt-get clean && \ 59 | rm -rf /var/lib/apt/lists/* 60 | 61 | # Install gtest/gmock 62 | RUN git clone -q https://github.com/google/googletest.git /googletest \ 63 | && cd googletest \ 64 | && git checkout tags/release-1.8.1 \ 65 | && mkdir -p /googletest/build \ 66 | && cd /googletest/build \ 67 | && cmake .. && make -j 16 && make install \ 68 | && cd / && rm -rf /googletest 69 | 70 | # Install benchmark 71 | RUN git clone -q https://github.com/google/benchmark.git /benchmark \ 72 | && cd benchmark \ 73 | && git checkout tags/v1.4.0 \ 74 | && mkdir -p /benchmark/build \ 75 | && cd /benchmark/build \ 76 | && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j 16 && make install \ 77 | && cd / && rm -rf /benchmark 78 | 79 | 80 | # python support 81 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 82 | python3-setuptools \ 83 | virtualenv \ 84 | python3-pip \ 85 | python3-dev \ 86 | python3-virtualenv \ 87 | python3-pip && \ 88 | apt-get clean && \ 89 | rm -rf /var/lib/apt/lists/* 90 | 91 | 92 | #python packages 93 | RUN pip3 install flake8 94 | 95 | # entrypoint 96 | COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh 97 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 98 | 99 | WORKDIR /tmp/workspace 100 | -------------------------------------------------------------------------------- /docker/ubuntu_18_04/Dockerfile: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts Dockerfile 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | 28 | FROM ubuntu:18.04 as base 29 | 30 | 31 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 32 | ca-certificates \ 33 | curl \ 34 | gnupg2 \ 35 | gosu \ 36 | apt-utils \ 37 | software-properties-common \ 38 | build-essential \ 39 | wget \ 40 | lcov \ 41 | sudo \ 42 | zip \ 43 | unzip \ 44 | doxygen \ 45 | graphviz \ 46 | cmake \ 47 | openssh-client \ 48 | git && \ 49 | apt-get clean && \ 50 | rm -rf /var/lib/apt/lists/* 51 | 52 | ### Builder image ### 53 | FROM base as build 54 | 55 | # LLVM Clang 56 | ENV CLANG_VERSION=7 57 | RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ 58 | apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-$CLANG_VERSION main" && \ 59 | apt-get update && \ 60 | apt-get install --yes --no-install-recommends clang-$CLANG_VERSION \ 61 | clang-tidy-$CLANG_VERSION \ 62 | clang-format-$CLANG_VERSION \ 63 | llvm-$CLANG_VERSION-dev \ 64 | libclang-$CLANG_VERSION-dev && \ 65 | apt-get clean && \ 66 | rm -rf /var/lib/apt/lists/* 67 | 68 | 69 | # python support 70 | RUN apt-get update && \ 71 | apt-get install --yes --no-install-recommends \ 72 | virtualenv \ 73 | python3-setuptools \ 74 | python3-pip \ 75 | python3-dev \ 76 | python3-virtualenv \ 77 | python3-pip && \ 78 | apt-get clean && \ 79 | rm -rf /var/lib/apt/lists/* 80 | 81 | 82 | #python packages 83 | RUN pip3 install \ 84 | flake8 \ 85 | autopep8 \ 86 | virtualenv 87 | 88 | # Install latest cppcheck 89 | RUN git clone https://github.com/danmar/cppcheck.git /cppcheck \ 90 | && mkdir /cppcheck/build \ 91 | && cd /cppcheck/build \ 92 | && cmake .. && cmake --build . -- -j16 && make install \ 93 | && cd / && rm -rf /cppcheck 94 | 95 | # Install gtest/gmock 96 | RUN git clone -q https://github.com/google/googletest.git /googletest \ 97 | && cd googletest \ 98 | && git checkout tags/release-1.8.1 \ 99 | && mkdir -p /googletest/build \ 100 | && cd /googletest/build \ 101 | && cmake .. && make -j $(nproc) && make install \ 102 | && cd / && rm -rf /googletest 103 | 104 | # Install benchmark 105 | RUN git clone -q https://github.com/google/benchmark.git /benchmark \ 106 | && cd benchmark \ 107 | && git checkout tags/v1.4.0 \ 108 | && mkdir -p /benchmark/build \ 109 | && cd /benchmark/build \ 110 | && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc) && make install \ 111 | && cd / && rm -rf /benchmark 112 | 113 | # Install latest iwyu 114 | RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /iwyu \ 115 | && mkdir /iwyu/build \ 116 | && cd /iwyu && git checkout clang_$CLANG_VERSION.0 \ 117 | && cd /iwyu/build \ 118 | && cmake .. && cmake --build . -- -j$(nproc) && make install \ 119 | && cd / && rm -rf /iwyu 120 | 121 | # Install as docker user (after entrypoint) 122 | # Install Emscripten SDK/toolchain 123 | ENV EMSDK_VERSION=1.39 124 | ENV EMSDK_BUILD_VERSION=5 125 | RUN git clone https://github.com/emscripten-core/emsdk.git /tmp/emsdk && \ 126 | cd /tmp/emsdk && \ 127 | ./emsdk install $EMSDK_VERSION.$EMSDK_BUILD_VERSION && \ 128 | ./emsdk activate $EMSDK_VERSION.$EMSDK_BUILD_VERSION 129 | ENV PATH="${PATH}:/tmp/emsdk:/tmp/emsdk/upstream/emscripten:/tmp/emsdk/node/12.9.1_64bit/bin" 130 | RUN echo "PATH: " $PATH 131 | RUN em++ --version 132 | 133 | # entrypoint 134 | COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh 135 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 136 | 137 | # WORKDIR /tmp/workspace 138 | RUN adduser docker 139 | -------------------------------------------------------------------------------- /docker/ubuntu_18_04/circleci/Dockerfile: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts Dockerfile 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #******************************************************************/ 27 | 28 | FROM ubuntu:18.04 as base 29 | 30 | 31 | RUN apt-get update && apt-get --yes --no-install-recommends install \ 32 | ca-certificates \ 33 | curl \ 34 | gnupg2 \ 35 | gosu \ 36 | apt-utils \ 37 | software-properties-common \ 38 | build-essential \ 39 | wget \ 40 | cmake \ 41 | openssh-client \ 42 | git \ 43 | valgrind && \ 44 | apt-get clean && \ 45 | rm -rf /var/lib/apt/lists/* 46 | 47 | ### Builder image ### 48 | FROM base as build 49 | 50 | # python support 51 | RUN apt-get update && \ 52 | apt-get install --yes --no-install-recommends \ 53 | virtualenv \ 54 | python3-setuptools \ 55 | python3-pip \ 56 | python3-dev \ 57 | python3-virtualenv \ 58 | python3-pip && \ 59 | apt-get clean && \ 60 | rm -rf /var/lib/apt/lists/* 61 | 62 | 63 | #python packages 64 | RUN pip3 install \ 65 | flake8 \ 66 | autopep8 \ 67 | virtualenv 68 | 69 | 70 | # Install gtest/gmock 71 | RUN git clone -q https://github.com/google/googletest.git /googletest \ 72 | && cd googletest \ 73 | && git checkout tags/release-1.8.1 \ 74 | && mkdir -p /googletest/build \ 75 | && cd /googletest/build \ 76 | && cmake .. && make -j $(nproc) && make install \ 77 | && cd / && rm -rf /googletest 78 | 79 | # Install benchmark 80 | RUN git clone -q https://github.com/google/benchmark.git /benchmark \ 81 | && cd benchmark \ 82 | && git checkout tags/v1.4.0 \ 83 | && mkdir -p /benchmark/build \ 84 | && cd /benchmark/build \ 85 | && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j$(nproc) && make install \ 86 | && cd / && rm -rf /benchmark 87 | 88 | 89 | # Install as docker user (after entrypoint) 90 | # Install Emscripten SDK/toolchain 91 | # ENV EMSDK_VERSION=1.38 92 | # ENV EMSDK_BUILD_VERSION=31 93 | # RUN git clone https://github.com/emscripten-core/emsdk.git /tmp/emsdk && \ 94 | # cd /tmp/emsdk && \ 95 | # ./emsdk install sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit && \ 96 | # ./emsdk activate sdk-tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION-64bit 97 | # ENV PATH="${PATH}:/tmp/emsdk/emscripten/tag-$EMSDK_VERSION.$EMSDK_BUILD_VERSION" 98 | # RUN echo "PATH: " $PATH 99 | # RUN em++ --version 100 | 101 | # entrypoint 102 | COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh 103 | ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] 104 | 105 | WORKDIR /tmp/workspace 106 | -------------------------------------------------------------------------------- /gen_package.bat: -------------------------------------------------------------------------------- 1 | REM Create releases for Windows with CMake 2 | 3 | $echo off 4 | REM *** Get source dir 5 | set SRC_DIR=%~dp0 6 | REM echo %SRC_DIR% 7 | 8 | echo %SRC_DIR% 9 | 10 | title Build mpeg2ts 11 | echo Build mpeg2ts Windows 12 | 13 | 14 | echo "1. Create Release/ folders for libraries" 15 | 16 | set BUILD_RELEASE_DIR=Release 17 | set BUILD_DEBUG_DIR=Debug 18 | 19 | echo %BUILD_RELEASE_DIR% exist, removing %SRC_DIR%\%BUILD_RELEASE_DIR% and creating new one... 20 | 21 | if exist %BUILD_RELEASE_DIR% ( 22 | echo %BUILD_RELEASE_DIR% exist, removing %SRC_DIR%\%BUILD_RELEASE_DIR% and creating new one... 23 | rmdir /s /q %SRC_DIR%\%BUILD_RELEASE_DIR% 24 | ) 25 | 26 | echo create new directory: %BUILD_RELEASE_DIR% 27 | mkdir %BUILD_RELEASE_DIR% 28 | 29 | cd %SRC_DIR%\%BUILD_RELEASE_DIR% 30 | dir 31 | 32 | echo "2.a Configure CMake" 33 | echo Configuring for x86 34 | set CMAKE_CONFIGURE_CMD=cmake -G "Visual Studio 15 2017" --arch "x86" -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON .. 35 | 36 | echo CMake configure command: 37 | echo %CMAKE_CONFIGURE_CMD% 38 | %CMAKE_CONFIGURE_CMD% 39 | if %errorlevel% neq 0 exit /b %errorlevel% 40 | 41 | echo "2.b Build CMake" 42 | set CMAKE_BUILD_CMD=cmake --build . --config Release --target mpeg2ts 43 | echo CMake build command: 44 | echo %CMAKE_BUILD_CMD% 45 | %CMAKE_BUILD_CMD% 46 | if %errorlevel% neq 0 exit /b %errorlevel% 47 | 48 | cd %SRC_DIR% 49 | echo "3. Create CPackConfig.cmake" 50 | echo include("Release/CPackConfig.cmake") > CPackConfig.cmake 51 | echo set(CPACK_INSTALL_CMAKE_PROJECTS "Release;mpeg2ts;ALL;/") >> CPackConfig.cmake 52 | 53 | echo "4. Generate package" 54 | cpack -G WIX --config CPackConfig.cmake -C Release 55 | -------------------------------------------------------------------------------- /gen_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script to package both debug and release build with CPack 3 | #***************************************************************** 4 | # 5 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 6 | # 7 | # mpeg2ts - mpeg2ts gen_package.sh 8 | # 9 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 10 | # 11 | # Unless you have obtained mpeg2ts under a different license, 12 | # this version of mpeg2ts is mpeg2ts|GPL. 13 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU General Public License as 15 | # published by the Free Software Foundation; either version 2, 16 | # or (at your option) any later version. 17 | # 18 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | # GNU General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU General Public License 24 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 25 | # the Free Software Foundation, 59 Temple Place - Suite 330, 26 | # Boston, MA 02111-1307, USA. 27 | # 28 | #*******************************************************************/ 29 | 30 | echo "1. Create debug/ release/ folders for shared libraries" 31 | 32 | build_types=(Debug Release) 33 | 34 | for i in ${build_types[@]}; do 35 | echo mkdir: $i 36 | mkdir $i 37 | done 38 | 39 | echo "2. Configure CMake" 40 | for type in ${build_types[@]}; do 41 | echo "Configure and build / $type shared lib" 42 | cd $type 43 | cmake -DCMAKE_BUILD_TYPE=$type -DBUILD_SHARED_LIBS=YES -DENABLE_TESTS=OFF .. 44 | make -j $(nproc) 45 | cd .. 46 | done 47 | 48 | 49 | echo "3. Create CPackConfig.cmake" 50 | echo 'include("Release/CPackConfig.cmake") 51 | set(CPACK_INSTALL_CMAKE_PROJECTS 52 | "Debug;mpeg2ts;ALL;/" 53 | "Release;mpeg2ts;ALL;/" 54 | )' > CPackConfig.cmake 55 | 56 | echo "4. Generate package" 57 | cpack --config CPackConfig.cmake 58 | -------------------------------------------------------------------------------- /images/Ts-lib_SW_Architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/Ts-lib_SW_Architecture.png -------------------------------------------------------------------------------- /images/circleci.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/circleci.png -------------------------------------------------------------------------------- /images/cmake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/cmake.png -------------------------------------------------------------------------------- /images/codacy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/codacy.png -------------------------------------------------------------------------------- /images/docker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/docker.png -------------------------------------------------------------------------------- /images/ts_lib_oss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/images/ts_lib_oss.png -------------------------------------------------------------------------------- /libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts libs 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | add_subdirectory(common) 28 | add_subdirectory(mpeg2ts) 29 | add_subdirectory(h264codec) 30 | add_subdirectory(mpeg2codec) 31 | -------------------------------------------------------------------------------- /libs/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | if(CMAKE_MINOR_VERSION GREATER 9) 4 | project( 5 | common 6 | VERSION 0.6.0 7 | DESCRIPTION "Common utility lib" 8 | LANGUAGES CXX 9 | ) 10 | else() 11 | project( 12 | common 13 | VERSION 0.6.0 14 | LANGUAGES CXX 15 | ) 16 | endif() 17 | 18 | add_library(${PROJECT_NAME} STATIC) 19 | 20 | # shared libraries need PIC 21 | if (BUILD_SHARED_LIBS) 22 | set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1) 23 | endif() 24 | 25 | target_include_directories(${PROJECT_NAME} 26 | PUBLIC 27 | $ 28 | $ 29 | PRIVATE 30 | $ 31 | ) 32 | 33 | set_target_properties(${PROJECT_NAME} 34 | PROPERTIES 35 | VERSION ${PROJECT_VERSION} 36 | SOVERSION ${PROJECT_VERSION_MAJOR} 37 | EXPORT_NAME ${PROJECT_NAME} 38 | CXX_LINK_WHAT_YOU_USE TRUE 39 | DEBUG_POSTFIX "-d" 40 | ) 41 | 42 | if(CMAKE_MINOR_VERSION GREATER 7) 43 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 44 | endif() 45 | 46 | target_sources( 47 | ${PROJECT_NAME} 48 | PRIVATE 49 | ${CMAKE_CURRENT_SOURCE_DIR}/include/GetBits.h 50 | ${CMAKE_CURRENT_SOURCE_DIR}/src/GetBits.cc 51 | ) 52 | 53 | # mpeg2ts needs install common dependency 54 | install(TARGETS ${PROJECT_NAME} EXPORT mpeg2tsTargets 55 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 56 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 57 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 58 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 59 | ) 60 | -------------------------------------------------------------------------------- /libs/common/include/GetBits.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _GETBITS_H 28 | #define _GETBITS_H 29 | 30 | #include // for uint8_t, uint64_t 31 | #include // for size_t 32 | #include // for runtime_error 33 | #include // for string 34 | 35 | class GetBits 36 | { 37 | public: 38 | GetBits(); 39 | 40 | virtual ~GetBits() = default; 41 | /*! 42 | * Parses maximum 64 bits by bit from data and returns results 43 | * * @note NOTE! This function does only parse up to 64 bits. 44 | * Passing a request greater than 64 bits will trigger an out of bound 45 | * exception. 46 | * @param requestedBits Number of bits to parse 47 | * @param data Data to parse 48 | * @return Parsed bits 49 | */ 50 | uint64_t getBits(int a_requestedBits); 51 | 52 | /*! 53 | * Resets bit reader to start over reading from a buffer with 54 | * start index and buffer size as parameters settings. 55 | * @param srcBytes The buffer to read from 56 | * @param srcSize The buffer size to read from 57 | * @param inx The start byte offset to start read from 58 | */ 59 | void resetBits(const uint8_t* a_srcBytes, std::size_t a_srcSize, std::size_t a_inx = 0); 60 | 61 | /*! 62 | * Skips amount of bits of any size. This function can skip any number 63 | * of bits as long as its inside the data scope, otherwise it will trigger 64 | * an out of bound exception. 65 | * @param skipBits Skip amount of bits. 66 | */ 67 | void skipBits(int a_skipBits); 68 | 69 | /*! 70 | * Return offset to current byte 71 | */ 72 | std::size_t getByteInx() const; 73 | 74 | /*! 75 | * Skips entire bytes instead of bits. Good to use when skip large block of data. 76 | * @param skipBytes Number of bytes to skip. 77 | */ 78 | void skipBytes(int a_skipBytes); 79 | 80 | /*! 81 | * For debugging the data in store up to current parsed index. 82 | */ 83 | void printSrcBytes() const; 84 | 85 | protected: 86 | uint8_t mNumStoredBits; 87 | uint8_t mBitStore; 88 | std::size_t mSrcInx; 89 | std::size_t mSize; 90 | const uint8_t* mSrcBytes; 91 | }; 92 | 93 | class GetBitsException : public std::runtime_error 94 | { 95 | public: 96 | GetBitsException(const std::string msg) 97 | : std::runtime_error(msg) 98 | { 99 | } 100 | 101 | virtual ~GetBitsException() = default; 102 | }; 103 | 104 | #endif /* _GETBITS_H */ 105 | -------------------------------------------------------------------------------- /libs/common/src/GetBits.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for printf, size_t 28 | 29 | #include "GetBits.h" 30 | 31 | GetBits::GetBits() 32 | : mNumStoredBits{ 0 } 33 | , mBitStore{ 0 } 34 | , mSrcInx{ 0 } 35 | , mSize{ 0 } 36 | , mSrcBytes{ nullptr } 37 | { 38 | } 39 | 40 | uint64_t GetBits::getBits(int a_requestedBits) 41 | { 42 | uint64_t ret{ 0 }; 43 | 44 | if (mSrcBytes == nullptr) 45 | { 46 | throw GetBitsException("null input data"); 47 | } 48 | 49 | if (a_requestedBits > 64) 50 | { 51 | throw GetBitsException("Cannot parse more than 64 individual bits at a time."); 52 | } 53 | 54 | while (a_requestedBits > 0) 55 | { 56 | if (mNumStoredBits == 0) 57 | { 58 | if (mSrcInx >= mSize) 59 | { 60 | throw GetBitsException("getBits: Out of bound read"); 61 | } 62 | 63 | mNumStoredBits = 8; 64 | mBitStore = mSrcBytes[mSrcInx++]; 65 | } 66 | 67 | int bitsToFromStore = mNumStoredBits > a_requestedBits ? a_requestedBits : mNumStoredBits; 68 | ret = (ret << bitsToFromStore) | (mBitStore >> (8 - bitsToFromStore)); 69 | 70 | a_requestedBits -= bitsToFromStore; 71 | mNumStoredBits = static_cast(mNumStoredBits - bitsToFromStore); 72 | mBitStore = static_cast(mBitStore << bitsToFromStore); 73 | } 74 | 75 | return ret; 76 | } 77 | 78 | void GetBits::resetBits(const uint8_t* a_srcBytes, std::size_t a_srcSize, size_t a_inx) 79 | { 80 | mNumStoredBits = 0; 81 | mBitStore = 0; 82 | mSrcInx = a_inx; 83 | mSize = a_srcSize; 84 | mSrcBytes = a_srcBytes; 85 | } 86 | 87 | void GetBits::skipBits(int a_skipBits) 88 | { 89 | if (a_skipBits <= 64) 90 | { 91 | getBits(a_skipBits); 92 | return; 93 | } 94 | 95 | int n{ a_skipBits / 64 }; 96 | int rem{ a_skipBits % 64 }; 97 | 98 | for (int i = 0; i < n; ++i) 99 | { 100 | mNumStoredBits = 0; 101 | mBitStore = 0; 102 | mSrcInx += 8; 103 | 104 | if (mSrcInx >= mSize) 105 | { 106 | throw GetBitsException("skipBits: Out of bound read"); 107 | } 108 | } 109 | 110 | getBits(rem); 111 | } 112 | 113 | void GetBits::skipBytes(int a_skipBytes) 114 | { 115 | if ((mSrcInx + a_skipBytes) >= mSize) 116 | { 117 | throw GetBitsException("getBits: Out of bound read mSrcInx: " + std::to_string(mSrcInx)); 118 | } 119 | else 120 | { 121 | mNumStoredBits = 0; 122 | mBitStore = 0; 123 | mSrcInx += a_skipBytes; 124 | } 125 | } 126 | 127 | std::size_t GetBits::getByteInx() const 128 | { 129 | return mNumStoredBits == 0 ? mSrcInx : mSrcInx - 1; 130 | } 131 | 132 | 133 | void GetBits::printSrcBytes() const 134 | { 135 | for (std::size_t i = mSrcInx; i < mSize; ++i) 136 | { 137 | printf("%02X", mSrcBytes[i]); 138 | } 139 | printf("\n"); 140 | } 141 | -------------------------------------------------------------------------------- /libs/h264codec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts lib 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | h264codec 32 | VERSION 0.6.0 33 | DESCRIPTION "H264 Codec parser lib" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | h264codec 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_library(${PROJECT_NAME}) 45 | 46 | # shared libraries need PIC 47 | if (BUILD_SHARED_LIBS) 48 | set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1) 49 | endif() 50 | 51 | target_include_directories(${PROJECT_NAME} 52 | PUBLIC 53 | $ 54 | $ 55 | PRIVATE 56 | $ 57 | $# For EsParser.h 58 | ) 59 | 60 | set_target_properties(${PROJECT_NAME} 61 | PROPERTIES 62 | VERSION ${PROJECT_VERSION} 63 | SOVERSION ${PROJECT_VERSION_MAJOR} 64 | EXPORT_NAME ${PROJECT_NAME} 65 | CXX_LINK_WHAT_YOU_USE TRUE 66 | DEBUG_POSTFIX "-d" 67 | ) 68 | 69 | if(CMAKE_MINOR_VERSION GREATER 7) 70 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 71 | endif() 72 | 73 | target_sources( 74 | ${PROJECT_NAME} 75 | PUBLIC 76 | ${CMAKE_CURRENT_SOURCE_DIR}/include/H264Codec.h 77 | PRIVATE 78 | ${CMAKE_CURRENT_SOURCE_DIR}/src/H264Parser.h 79 | ${CMAKE_CURRENT_SOURCE_DIR}/src/H264Parser.cc 80 | ${CMAKE_CURRENT_SOURCE_DIR}/src/H264Codec.cc 81 | ) 82 | 83 | target_link_libraries( 84 | ${PROJECT_NAME} 85 | PRIVATE 86 | common # For GetBits() 87 | ) 88 | 89 | add_dependencies(${PROJECT_NAME} plog) 90 | add_dependencies(${PROJECT_NAME} json) 91 | -------------------------------------------------------------------------------- /libs/h264codec/include/H264Codec.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts h264 lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _H264CODEC_H 28 | #define _H264CODEC_H 29 | 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | namespace h264 { 37 | 38 | enum class H264InfoType 39 | { 40 | Info, 41 | SliceHeader, 42 | SequenceParameterSet, 43 | PictureParameterSet 44 | }; 45 | 46 | 47 | struct EsInfoH264SliceHeader 48 | { 49 | int sliceType{ 0 }; 50 | std::string sliceTypeStr{ "" }; 51 | int ppsId{ 0 }; 52 | bool field{ false }; // or frame 53 | bool top{ false }; // or bottom 54 | int frame_num{ 0 }; 55 | }; 56 | 57 | 58 | struct EsInfoH264SequenceParameterSet 59 | { 60 | int profileIdc{ 0 }; 61 | int levelIdc{ 0 }; 62 | int spsId{ 0 }; 63 | int lumaBits{ 0 }; 64 | int chromaBits{ 0 }; 65 | int numRefPics{ 0 }; 66 | int width{ 0 }; 67 | int height{ 0 }; 68 | }; 69 | 70 | 71 | struct EsInfoH264PictureParameterSet 72 | { 73 | int ppsId{ 0 }; 74 | int spsId{ 0 }; 75 | }; 76 | 77 | 78 | /// ITU-T Rec.H H.264 Table 7-1 – NAL unit type codes 79 | enum class NalUnitType 80 | { 81 | Unspecified = 0, 82 | Coded_slice_of_a_non_IDR_picture = 1, 83 | Coded_slice_data_partition_A = 2, 84 | Coded_slice_data_partition_B = 3, 85 | Coded_slice_data_partition_C = 4, 86 | Coded_slice_of_an_IDR_picture = 5, 87 | Supplemental_enhancement_information_SEI = 6, 88 | Sequence_parameter_set = 7, 89 | Picture_parameter_set = 8, 90 | Access_unit_delimiter = 9, 91 | End_of_sequence = 10, 92 | End_of_stream = 11, 93 | Filler_data = 12 94 | }; 95 | 96 | 97 | struct EsInfoH264 98 | { 99 | H264InfoType type; 100 | NalUnitType nalUnitType{ NalUnitType::Unspecified }; 101 | std::string msg{ "" }; 102 | EsInfoH264SliceHeader slice; 103 | EsInfoH264SequenceParameterSet sps; 104 | EsInfoH264PictureParameterSet pps; 105 | }; 106 | 107 | class H264EsParser; 108 | class H264Codec 109 | { 110 | public: 111 | H264Codec(); 112 | ~H264Codec(); 113 | 114 | /*! 115 | * @brief Parses a binary buffer containing H264 codec data and 116 | * let the specialization analyze the results. 117 | * @param buf The binary data to parse 118 | * @return H264 parsed metadata 119 | */ 120 | std::vector parse(const std::vector& buf); 121 | 122 | /*! 123 | * @brief Analyze the content on data after startcodes. 124 | */ 125 | std::vector analyze(); 126 | 127 | /*! 128 | * @brief Convert H264InfoType to string 129 | * @return H264InfoType string 130 | */ 131 | std::string toString(H264InfoType e); 132 | 133 | /*! 134 | * @brief Convert NalUnitType to string 135 | * @return NalUnitType string 136 | */ 137 | std::string toString(NalUnitType e); 138 | private: 139 | // Non copyable 140 | H264Codec(const H264Codec&); 141 | H264Codec& operator=(const H264Codec&); 142 | // Non movable 143 | H264Codec(H264Codec&&); 144 | H264Codec& operator=(H264Codec&&); 145 | 146 | std::unique_ptr mPimpl; 147 | }; 148 | 149 | 150 | } // namespace h264 151 | 152 | #endif /* _H264CODEC_H */ -------------------------------------------------------------------------------- /libs/h264codec/src/H264Codec.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts h264 lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include "H264Codec.h" 28 | 29 | #include "H264Parser.h" 30 | 31 | 32 | namespace h264 33 | { 34 | H264Codec::H264Codec() 35 | : mPimpl{ new H264EsParser() } 36 | { 37 | } 38 | 39 | H264Codec::~H264Codec() 40 | { 41 | } 42 | 43 | 44 | std::vector H264Codec::parse(const std::vector& buf) 45 | { 46 | return mPimpl->parse(buf); 47 | } 48 | 49 | std::vector H264Codec::analyze() 50 | { 51 | return mPimpl->analyze(); 52 | } 53 | 54 | std::string H264Codec::toString(H264InfoType e) 55 | { 56 | return mPimpl->toString(e); 57 | } 58 | 59 | std::string H264Codec::toString(NalUnitType e) 60 | { 61 | return mPimpl->toString(e); 62 | } 63 | 64 | } // namespace h264 -------------------------------------------------------------------------------- /libs/h264codec/src/H264Parser.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts h264 lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _H264PARSER_H 28 | #define _H264PARSER_H 29 | 30 | #include // for uint8_t 31 | #include // for size_t 32 | #include // for map, _Rb_tree_const_iterator 33 | #include // for string, basic_string 34 | #include // for pair 35 | #include // for vector 36 | 37 | /// Project files 38 | #include "EsParser.h" // for EsParser 39 | #include "GetBits.h" // for GetBits 40 | #include "H264Codec.h" 41 | 42 | 43 | namespace h264 44 | { 45 | 46 | 47 | class H264EsParser : public EsParser, public GetBits 48 | { 49 | public: 50 | H264EsParser(const H264EsParser& arg) = delete; 51 | H264EsParser& operator=(const H264EsParser& arg) = delete; 52 | H264EsParser() 53 | : EsParser({ 0x00, 0x00, 0x00, 0x01 }) 54 | , log2_max_frame_num_minus4(0) 55 | , separate_colour_plane_flag(0) 56 | , frame_mbs_only_flag(0) 57 | { 58 | } 59 | 60 | virtual ~H264EsParser() = default; 61 | 62 | /// @brief Parses a binary buffer containing codec data like H262 or H264 and 63 | /// let the specialization analyze the results. 64 | /// @param buf The binary data to parse 65 | std::vector parse(const std::vector& buf); 66 | 67 | /// @brief Analyze the content on data after startcodes. 68 | std::vector analyze(); 69 | 70 | static std::string toString(H264InfoType e); 71 | static std::string toString(NalUnitType e); 72 | 73 | private: 74 | std::string seipayloadTypeToString(uint64_t payloadType); 75 | 76 | void slice_header(NalUnitType nal_unit_type, EsInfoH264& info); 77 | uint64_t getBitsDecodeUGolomb(); 78 | void scaling_list(uint8_t* scalingList, std::size_t sizeOfScalingList); 79 | void seq_parameter_set_rbsp(NalUnitType nal_unit_type, EsInfoH264& info); 80 | void pic_parameter_set_rbsp(NalUnitType nal_unit_type, EsInfoH264& info); 81 | 82 | void parse_vui(); 83 | 84 | // sps data 85 | uint8_t log2_max_frame_num_minus4; 86 | uint64_t separate_colour_plane_flag; 87 | uint64_t frame_mbs_only_flag; 88 | }; 89 | 90 | inline std::string H264EsParser::toString(H264InfoType e) 91 | { 92 | const std::map MyEnumStrings{ 93 | { H264InfoType::Info, "Info" }, 94 | { H264InfoType::SliceHeader, "SliceHeader" }, 95 | { H264InfoType::SequenceParameterSet, "SequenceParameterSet" }, 96 | { H264InfoType::PictureParameterSet, "PictureParameterSet" } 97 | }; 98 | auto it = MyEnumStrings.find(e); 99 | return it == MyEnumStrings.end() ? "Out of range" : it->second; 100 | } 101 | 102 | inline std::string H264EsParser::toString(NalUnitType e) 103 | { 104 | const std::map MyEnumStrings{ 105 | { NalUnitType::Unspecified, "Unspecified" }, 106 | { NalUnitType::Coded_slice_of_a_non_IDR_picture, "Coded_slice_of_a_non_IDR_picture" }, 107 | { NalUnitType::Coded_slice_data_partition_A, "Coded_slice_data_partition_A" }, 108 | { NalUnitType::Coded_slice_data_partition_B, "Coded_slice_data_partition_B" }, 109 | { NalUnitType::Coded_slice_data_partition_C, "Coded_slice_data_partition_C" }, 110 | { NalUnitType::Coded_slice_of_an_IDR_picture, "Coded_slice_of_an_IDR_picture" }, 111 | { NalUnitType::Supplemental_enhancement_information_SEI, 112 | "Supplemental_enhancement_information_SEI" }, 113 | { NalUnitType::Sequence_parameter_set, "Sequence_parameter_set" }, 114 | { NalUnitType::Picture_parameter_set, "Picture_parameter_set" }, 115 | { NalUnitType::Access_unit_delimiter, "Access_unit_delimiter" }, 116 | { NalUnitType::End_of_sequence, "End_of_sequence" }, 117 | { NalUnitType::End_of_stream, "End_of_stream" }, 118 | { NalUnitType::Filler_data, "Filler_data" } 119 | }; 120 | auto it = MyEnumStrings.find(e); 121 | return it == MyEnumStrings.end() ? "Out of range" : it->second; 122 | } 123 | } 124 | 125 | #endif /* _H264PARSER_H */ 126 | -------------------------------------------------------------------------------- /libs/mpeg2codec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts lib 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | mpeg2codec 32 | VERSION 0.6.0 33 | DESCRIPTION "MPEG2 Codec parser lib" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | mpeg2codec 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_library(${PROJECT_NAME}) 45 | 46 | # shared libraries need PIC 47 | if (BUILD_SHARED_LIBS) 48 | set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1) 49 | endif() 50 | 51 | target_include_directories(${PROJECT_NAME} 52 | PUBLIC 53 | $ 54 | $ 55 | PRIVATE 56 | $ 57 | $# For EsParser.h 58 | ) 59 | 60 | set_target_properties( 61 | ${PROJECT_NAME} 62 | PROPERTIES 63 | VERSION ${PROJECT_VERSION} 64 | SOVERSION ${PROJECT_VERSION_MAJOR} 65 | EXPORT_NAME ${PROJECT_NAME} 66 | CXX_LINK_WHAT_YOU_USE TRUE 67 | DEBUG_POSTFIX "-d" 68 | ) 69 | 70 | if(CMAKE_MINOR_VERSION GREATER 7) 71 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 72 | endif() 73 | 74 | target_sources( 75 | ${PROJECT_NAME} 76 | PUBLIC 77 | ${CMAKE_CURRENT_SOURCE_DIR}/include/Mpeg2Codec.h 78 | PRIVATE 79 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Mpeg2VideoParser.h 80 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Mpeg2VideoParser.cc 81 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Mpeg2Codec.cc 82 | ) 83 | 84 | target_link_libraries( 85 | ${PROJECT_NAME} 86 | PRIVATE 87 | common # For GetBits() 88 | ) 89 | 90 | add_dependencies(${PROJECT_NAME} plog) 91 | add_dependencies(${PROJECT_NAME} json) 92 | -------------------------------------------------------------------------------- /libs/mpeg2codec/include/Mpeg2Codec.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _MPEG2CODEC_H 28 | #define _MPEG2CODEC_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace mpeg2 { 36 | 37 | enum class Mpeg2Type 38 | { 39 | Info, 40 | SliceCode, 41 | SequenceHeader 42 | }; 43 | 44 | struct EsInfoMpeg2PictureSliceCode 45 | { 46 | uint64_t picType{ 0 }; // I, B, P 47 | }; 48 | 49 | struct EsInfoMpeg2SequenceHeader 50 | { 51 | int width{ 0 }, height{ 0 }; 52 | std::string aspect{ "" }; 53 | std::string framerate{ "" }; 54 | }; 55 | 56 | struct EsInfoMpeg2 57 | { 58 | Mpeg2Type type; 59 | int picture{ 0 }; // slice 60 | std::string msg{ "" }; 61 | EsInfoMpeg2PictureSliceCode slice; 62 | EsInfoMpeg2SequenceHeader sequence; 63 | }; 64 | 65 | class Mpeg2VideoEsParser; // forward declaration 66 | 67 | /*! 68 | * @brief Mpeg2 codec parser API 69 | */ 70 | class Mpeg2Codec 71 | { 72 | public: 73 | Mpeg2Codec(); 74 | ~Mpeg2Codec(); 75 | 76 | /*! 77 | * @brief Parses a binary buffer containing codec MPEG2 data and 78 | * let the specialization analyze the results. 79 | * @param buf The binary data to parse 80 | * @return Codec parsed meta-data 81 | */ 82 | std::vector parse(const std::vector& buf); 83 | 84 | /*! 85 | * @brief Analyze the content on data after startcodes. 86 | */ 87 | std::vector analyze(); 88 | 89 | /*! 90 | * @brief Convert Mpeg2Type to string 91 | * @return Mpeg2Type string 92 | */ 93 | std::string toString(Mpeg2Type e); 94 | 95 | private: 96 | // Non copyable 97 | Mpeg2Codec(const Mpeg2Codec&); 98 | Mpeg2Codec& operator=(const Mpeg2Codec&); 99 | // Non movable 100 | Mpeg2Codec(Mpeg2Codec&&); 101 | Mpeg2Codec& operator=(Mpeg2Codec&&); 102 | 103 | std::unique_ptr mPimpl; 104 | }; 105 | 106 | 107 | } // namespace mpeg2 108 | 109 | #endif /* _MPEG2CODEC_H */ -------------------------------------------------------------------------------- /libs/mpeg2codec/src/Mpeg2Codec.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include 28 | 29 | 30 | #include "Mpeg2Codec.h" 31 | 32 | #include "Mpeg2VideoParser.h" 33 | 34 | namespace mpeg2 35 | { 36 | 37 | Mpeg2Codec::Mpeg2Codec() 38 | : mPimpl(new Mpeg2VideoEsParser()) 39 | { 40 | } 41 | 42 | Mpeg2Codec::~Mpeg2Codec() 43 | { 44 | } 45 | 46 | 47 | std::vector Mpeg2Codec::parse(const std::vector& buf) 48 | { 49 | return mPimpl->parse(buf); 50 | } 51 | 52 | /// @brief Analyze the content on data after startcodes. 53 | std::vector Mpeg2Codec::analyze() 54 | { 55 | return mPimpl->analyze(); 56 | } 57 | 58 | std::string Mpeg2Codec::toString(Mpeg2Type e) 59 | { 60 | return mPimpl->toString(e); 61 | } 62 | 63 | } // namespace mpeg2 -------------------------------------------------------------------------------- /libs/mpeg2codec/src/Mpeg2VideoParser.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for end, begin 28 | #include // for bad_alloc 29 | #include // for operator<<, ostringstream, basic_ostream 30 | 31 | // 3rd-party 32 | #include // for LOGE 33 | #include "plog/Record.h" // for Record 34 | 35 | // Project files 36 | #include "Mpeg2VideoParser.h" 37 | 38 | namespace mpeg2 39 | { 40 | 41 | 42 | std::vector Mpeg2VideoEsParser::parse(const std::vector& a_buf) 43 | { 44 | std::vector ret; 45 | 46 | std::vector startCodes = findStartCodes(a_buf); 47 | 48 | // No startcodes -> no parsing 49 | if (startCodes.size() == 0) 50 | return ret; 51 | 52 | // There is nothing to parse if the frame only contains a NAL startcode 53 | if (a_buf.size() <= m_startCode.size()) 54 | return ret; 55 | 56 | for (std::size_t ind = 0; ind < startCodes.size(); ++ind) 57 | { 58 | // create sub vector 59 | try 60 | { 61 | mPicture.clear(); 62 | std::vector::const_iterator first = 63 | a_buf.begin() + startCodes[ind] + m_startCode.size(); // skip start code 64 | std::vector::const_iterator last; 65 | // the last startcode is a corner case 66 | // also only have 1 startcode is a corner case 67 | if (ind == (startCodes.size() - 1) || startCodes.size() == 1) 68 | { 69 | last = a_buf.end(); 70 | } 71 | else 72 | { 73 | last = a_buf.begin() + startCodes[ind + 1]; 74 | } 75 | 76 | std::vector newVec(first, last); 77 | mPicture = newVec; 78 | 79 | std::vector b = analyze(); 80 | ret.insert(std::end(ret), std::begin(b), std::end(b)); 81 | } 82 | catch (std::bad_alloc& e) 83 | { 84 | LOGE << "std::Exception what: %s\n" << e.what(); 85 | } 86 | } 87 | 88 | return ret; 89 | } 90 | 91 | 92 | std::vector Mpeg2VideoEsParser::analyze() 93 | { 94 | resetBits(mPicture.data(), mPicture.size()); 95 | std::ostringstream msg; 96 | 97 | EsInfoMpeg2 info; 98 | std::vector ret; 99 | 100 | info.type = Mpeg2Type::Info; 101 | info.picture = mPicture[0]; 102 | if (info.picture == 0 && mPicture.size() > 4) 103 | { 104 | info.type = Mpeg2Type::SliceCode; 105 | skipBits(10 + 8); 106 | info.slice.picType = static_cast(getBits(3)); 107 | switch (info.slice.picType) 108 | { 109 | case 1: 110 | msg << "I"; 111 | break; 112 | case 2: 113 | msg << "P"; 114 | break; 115 | case 3: 116 | msg << "B"; 117 | break; 118 | default: 119 | msg << "forbiden/reserved"; 120 | }; 121 | info.msg = msg.str(); 122 | } 123 | else if (info.picture >= 0x01 && info.picture <= 0xaf) 124 | { 125 | info.msg = "slice_start_code"; 126 | } 127 | else if (info.picture == 0xb0 && info.picture == 0xb1 && info.picture == 0xb6) 128 | { 129 | info.msg = "reserved"; 130 | } 131 | else if (info.picture == 0xb2) 132 | { 133 | info.msg = "user_data_start_code"; 134 | } 135 | else if (info.picture == 0xb3) 136 | { 137 | info.type = Mpeg2Type::SequenceHeader; 138 | info.msg = "sequence_header_code "; 139 | skipBits(8); 140 | info.sequence.width = static_cast(getBits(12)); 141 | info.sequence.height = static_cast(getBits(12)); 142 | uint8_t aspect_ratio_information = static_cast(getBits(4)); 143 | uint8_t frame_rate_code = static_cast(getBits(4)); 144 | info.sequence.aspect = AspectToString[aspect_ratio_information]; 145 | info.sequence.framerate = FrameRateToString[frame_rate_code]; 146 | } 147 | else if (info.picture == 0xb4) 148 | { 149 | info.msg = "sequence_error_code"; 150 | } 151 | else if (info.picture == 0xb5) 152 | { 153 | info.msg = "extension_start_code"; 154 | } 155 | else if (info.picture == 0xb7) 156 | { 157 | info.msg = "sequence_end_code"; 158 | } 159 | else if (info.picture == 0xb8) 160 | { 161 | info.msg = "group_start_code"; 162 | } 163 | else 164 | { 165 | info.msg = "system start code"; 166 | } 167 | ret.push_back(std::move(info)); 168 | return ret; 169 | } 170 | 171 | std::map Mpeg2VideoEsParser::AspectToString = 172 | { { 0, "forbiden" }, { 1, "square" }, { 2, "3x4" }, { 3, "9x16" }, 173 | { 4, "1x121" }, { 5, "reserved" }, { 6, "reserved" }, { 7, "reserved" } }; 174 | 175 | std::map Mpeg2VideoEsParser::FrameRateToString = 176 | { { 0, "forbiden" }, { 1, "23.97" }, { 2, "24" }, { 3, "25" }, 177 | { 4, "29.97" }, { 5, "30" }, { 6, "50" }, { 7, "59.94" }, 178 | { 8, "60" }, { 9, "reserved" }, { 10, "reserved" }, { 11, "reserved" }, 179 | { 12, "reserved" }, { 13, "reserved" }, { 14, "reserved" }, { 15, "reserved" } }; 180 | } 181 | -------------------------------------------------------------------------------- /libs/mpeg2codec/src/Mpeg2VideoParser.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _MPEG2VIDEOPARSER_H 28 | #define _MPEG2VIDEOPARSER_H 29 | 30 | #include // for uint8_t, uint64_t 31 | #include // for map, _Rb_tree_const_iterator 32 | #include // for string, basic_string 33 | #include // for pair 34 | #include // for vector 35 | 36 | // Project files 37 | #include "EsParser.h" // for EsParser 38 | #include "GetBits.h" // for GetBits 39 | #include "Mpeg2Codec.h" 40 | 41 | namespace mpeg2 42 | { 43 | 44 | /*! 45 | * @brief Mpeg2 codec parser implementation 46 | */ 47 | class Mpeg2VideoEsParser : public GetBits, public EsParser 48 | { 49 | public: 50 | Mpeg2VideoEsParser(const Mpeg2VideoEsParser& arg) = delete; 51 | Mpeg2VideoEsParser& operator=(const Mpeg2VideoEsParser& arg) = delete; 52 | 53 | Mpeg2VideoEsParser() 54 | : EsParser({ 0x00, 0x00, 0x01 }) 55 | { 56 | } 57 | 58 | virtual ~Mpeg2VideoEsParser() = default; 59 | 60 | /// @brief Parses a binary buffer containing codec data like H262 or H264 and 61 | /// let the specialization analyze the results. 62 | /// @param buf The binary data to parse 63 | std::vector parse(const std::vector& buf); 64 | 65 | /// @brief Analyze the content on data after startcodes. 66 | std::vector analyze(); 67 | 68 | static std::string toString(Mpeg2Type e); 69 | 70 | private: 71 | static std::map AspectToString; 72 | static std::map FrameRateToString; 73 | }; 74 | 75 | 76 | inline std::string Mpeg2VideoEsParser::toString(Mpeg2Type e) 77 | { 78 | const std::map MyEnumStrings{ { Mpeg2Type::Info, "Info" }, 79 | { Mpeg2Type::SliceCode, "SliceCode" }, 80 | { Mpeg2Type::SequenceHeader, 81 | "SequenceHeader" } }; 82 | auto it = MyEnumStrings.find(e); 83 | return it == MyEnumStrings.end() ? "Out of range" : it->second; 84 | } 85 | } 86 | 87 | #endif /* _MPEG2VIDEOPARSER_H */ 88 | -------------------------------------------------------------------------------- /libs/mpeg2ts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts lib 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | mpeg2ts 32 | VERSION 0.6.0 33 | DESCRIPTION "MPEG-2 Parsing lib of transport streams" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | mpeg2ts 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | #------------------- 45 | # CMake generated files 46 | #------------------- 47 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/mpeg2ts_version.h.in mpeg2ts_version.h @ONLY) 48 | 49 | #------------------- 50 | # shared / static lib 51 | # use cmake -DBUILD_SHARED_LIBS=YES .. to build shared libs 52 | #------------------- 53 | add_library(${PROJECT_NAME}) 54 | 55 | # shared libraries need PIC 56 | if (BUILD_SHARED_LIBS) 57 | set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE 1) 58 | endif() 59 | 60 | # Exporter for DLLs 61 | include(GenerateExportHeader) 62 | generate_export_header(${PROJECT_NAME}) 63 | 64 | target_include_directories( 65 | ${PROJECT_NAME} 66 | PUBLIC 67 | $ 68 | $ 69 | $ # For CMake generated files: mpeg2ts_version.h , mpeg2ts_export.h 70 | PRIVATE 71 | $ 72 | ) 73 | 74 | set_target_properties(${PROJECT_NAME} 75 | PROPERTIES 76 | VERSION ${PROJECT_VERSION} 77 | SOVERSION ${PROJECT_VERSION_MAJOR} 78 | EXPORT_NAME ${PROJECT_NAME} 79 | CXX_LINK_WHAT_YOU_USE TRUE 80 | DEBUG_POSTFIX "-d" 81 | ) 82 | 83 | if(CMAKE_MINOR_VERSION GREATER 7) 84 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 85 | endif() 86 | 87 | target_sources( 88 | ${PROJECT_NAME} 89 | PRIVATE 90 | ${CMAKE_CURRENT_SOURCE_DIR}/src/EsParser.h 91 | ${CMAKE_CURRENT_SOURCE_DIR}/src/JsonSettings.h 92 | ${CMAKE_CURRENT_SOURCE_DIR}/src/JsonSettings.cc 93 | ${CMAKE_CURRENT_SOURCE_DIR}/src/Logging.h 94 | ${CMAKE_CURRENT_SOURCE_DIR}/src/PesPacket.cc 95 | ${CMAKE_CURRENT_SOURCE_DIR}/src/PsiTables.cc 96 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsDemuxer.cc 97 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsPacketInfo.cc 98 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsParser.h 99 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsParser.cc 100 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsStatistics.h 101 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsStatistics.cc 102 | ${CMAKE_CURRENT_SOURCE_DIR}/src/TsUtilities.cc 103 | ) 104 | 105 | target_link_libraries( 106 | ${PROJECT_NAME} 107 | PRIVATE 108 | common # For GetBits() 109 | ) 110 | 111 | add_dependencies(${PROJECT_NAME} plog) 112 | add_dependencies(${PROJECT_NAME} json) 113 | 114 | #------------------- 115 | # installation 116 | #------------------- 117 | install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets 118 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 119 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 120 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 121 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 122 | ) 123 | 124 | install(FILES 125 | ${CMAKE_CURRENT_SOURCE_DIR}/include/mpeg2ts.h 126 | ${CMAKE_CURRENT_SOURCE_DIR}/include/Ts_IEC13818-1.h 127 | ${CMAKE_CURRENT_SOURCE_DIR}/include/TsUtilities.h 128 | ${CMAKE_CURRENT_SOURCE_DIR}/include/settings.json 129 | ${CMAKE_CURRENT_BINARY_DIR}/mpeg2ts_export.h 130 | DESTINATION include/${PROJECT_NAME} 131 | ) 132 | 133 | install(EXPORT ${PROJECT_NAME}Targets 134 | FILE ${PROJECT_NAME}Targets.cmake 135 | NAMESPACE ${PROJECT_NAME}:: 136 | DESTINATION lib/cmake/${PROJECT_NAME} 137 | ) 138 | -------------------------------------------------------------------------------- /libs/mpeg2ts/include/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "settings": { 3 | "logLevel": "DEBUG", 4 | "logFileName": "mpeg2ts_log.csv", 5 | "logFileMaxSize": 102400, 6 | "logFileMaxNumberOf": 10 7 | } 8 | } -------------------------------------------------------------------------------- /libs/mpeg2ts/src/EsParser.h: -------------------------------------------------------------------------------- 1 | 2 | /***************************************************************** 3 | * 4 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 5 | * 6 | * mpeg2ts - mpeg2ts lib 7 | * 8 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 9 | * 10 | * Unless you have obtained mpeg2ts under a different license, 11 | * this version of mpeg2ts is mpeg2ts|GPL. 12 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU General Public License as 14 | * published by the Free Software Foundation; either version 2, 15 | * or (at your option) any later version. 16 | * 17 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 24 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 25 | * 02111-1307, USA. 26 | * 27 | ********************************************************************/ 28 | #ifndef _ESPARSER_H 29 | #define _ESPARSER_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | 40 | struct EsInfo 41 | { 42 | virtual ~EsInfo(){}; 43 | }; 44 | 45 | class EsParser 46 | { 47 | public: 48 | EsParser(std::vector a_startCode) 49 | : m_startCode{ a_startCode } 50 | { 51 | } 52 | 53 | virtual ~EsParser() = default; 54 | 55 | 56 | /// @brief Finds startcode in a binary buffer by using std search algorithm 57 | /// @param buf The binary data to find startcodes in 58 | std::vector findStartCodes(const std::vector& buf); 59 | 60 | protected: 61 | std::vector mPicture; 62 | std::vector m_startCode; 63 | }; 64 | 65 | inline std::vector EsParser::findStartCodes(const std::vector& a_buf) 66 | { 67 | std::vector indexes{}; 68 | auto it{ a_buf.begin() }; 69 | while ((it = std::search(it, a_buf.end(), m_startCode.begin(), m_startCode.end())) != a_buf.end()) 70 | { 71 | indexes.push_back(std::distance(a_buf.begin(), it++)); 72 | } 73 | return indexes; 74 | } 75 | 76 | #endif /* _ESPARSER_H */ 77 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/JsonSettings.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include "JsonSettings.h" 28 | 29 | // Dont allow json.hpp throw exceptions 30 | #define JSON_THROW_USER 31 | 32 | #include "nlohmann/json.hpp" // for basic_json<>::value_type, basic_json 33 | 34 | #include 35 | #include // for operator<<, basic_ostream, ifstream, cerr 36 | #include // for allocator, operator+, string, char_traits 37 | 38 | using json = nlohmann::json; 39 | 40 | 41 | bool Settings::loadFile(std::string a_file) 42 | { 43 | // 1. Open file 44 | std::ifstream ifs(a_file); 45 | if (ifs.fail()) 46 | { 47 | std::string errMsg = "Could not find settings file: " + a_file; 48 | throw LoadException(errMsg); 49 | return false; 50 | } 51 | 52 | // 2. Load and read file 53 | try 54 | { 55 | ifs >> mJ; 56 | return true; 57 | } 58 | catch (std::exception& e) 59 | { 60 | std::cerr << "Could not load asset file: " << a_file << ", with exception: " << e.what() << '\n'; 61 | std::string errMsg = "Could not load asset file: " + a_file + ", with exception: " + e.what(); 62 | throw LoadException(errMsg); 63 | return false; 64 | } 65 | } 66 | 67 | void Settings::loadJson(json a_js) 68 | { 69 | mJ = a_js; 70 | } 71 | 72 | std::string Settings::getLogLevel() const 73 | { 74 | std::string str = mJ["settings"]["logLevel"]; 75 | return str; 76 | } 77 | 78 | std::string Settings::getLogFileName() const 79 | { 80 | std::string str = mJ["settings"]["logFileName"]; 81 | return str; 82 | } 83 | 84 | int Settings::getLogFileMaxSize() const 85 | { 86 | return mJ["settings"]["logFileMaxSize"]; 87 | } 88 | 89 | int Settings::getLogFileMaxNumberOf() const 90 | { 91 | return mJ["settings"]["logFileMaxNumberOf"]; 92 | } 93 | 94 | ///////////////// LoadException ///////////////////////// 95 | 96 | LoadException::LoadException(const std::string& a_message) 97 | : m_message(a_message) 98 | { 99 | } 100 | 101 | LoadException::LoadException(const std::exception a_e) 102 | : m_message(a_e.what()) 103 | { 104 | } 105 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/JsonSettings.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _JSONSETTINGS_H 28 | #define _JSONSETTINGS_H 29 | 30 | /*! 31 | * This file loads the settings json file which contains 32 | * runtime configurations... 33 | */ 34 | 35 | #include // for exception 36 | #include // for string 37 | 38 | // 3rd-party 39 | #include "nlohmann/json.hpp" // for json 40 | 41 | 42 | using json = nlohmann::json; 43 | 44 | class Settings 45 | { 46 | public: 47 | explicit Settings() = default; 48 | ~Settings() = default; 49 | 50 | bool loadFile(std::string); 51 | void loadJson(json); 52 | std::string getLogLevel() const; 53 | std::string getLogFileName() const; 54 | int getLogFileMaxSize() const; 55 | int getLogFileMaxNumberOf() const; 56 | 57 | private: 58 | json mJ; 59 | }; 60 | 61 | class LoadException : public std::exception 62 | { 63 | private: 64 | std::string m_message; 65 | 66 | public: 67 | explicit LoadException() = default; 68 | explicit LoadException(const std::string& a_message); 69 | explicit LoadException(const std::exception a_e); 70 | virtual const char* what() const throw() 71 | { 72 | return m_message.c_str(); 73 | } 74 | }; 75 | 76 | #endif /* _JSONSETTINGS_H */ 77 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/Logging.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _LOGGING_H 28 | #define _LOGGING_H 29 | 30 | enum // Define log instances. Default is 0 and is omitted from this enum. 31 | { 32 | FileLog = 1 33 | }; 34 | 35 | #endif /* _LOGGING_H */ 36 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/PesPacket.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for operator<<, basic_ostream::operator<<, ostream 28 | #include "mpeg2ts.h" // for PesPacket, operator<< 29 | 30 | namespace mpeg2ts 31 | { 32 | 33 | std::ostream& operator<<(std::ostream& ss, const PesPacket& rhs) 34 | { 35 | ss << "\n-------------PesPacket-------------\n"; 36 | ss << "packet_start_code_prefix:" << std::hex << rhs.packet_start_code_prefix << std::dec << '\n'; 37 | ss << "stream_id: " << static_cast(rhs.stream_id) << '\n'; 38 | ss << "PES_packet_length: " << static_cast(rhs.PES_packet_length) << '\n'; 39 | 40 | ss << "PES_scrambling_control: " << static_cast(rhs.PES_scrambling_control) << '\n'; 41 | ss << "PES_priority: " << static_cast(rhs.PES_priority) << '\n'; 42 | ss << "data_alignment_indicator: " << static_cast(rhs.data_alignment_indicator) << '\n'; 43 | ss << "copyright: " << static_cast(rhs.copyright) << '\n'; 44 | ss << "original_or_copy: " << static_cast(rhs.original_or_copy) << '\n'; 45 | ss << "PTS_DTS_flags: " << static_cast(rhs.PTS_DTS_flags) << '\n'; 46 | ss << "ESCR_flag: " << static_cast(rhs.ESCR_flag) << '\n'; 47 | ss << "ES_rate_flag: " << static_cast(rhs.ES_rate_flag) << '\n'; 48 | ss << "DSM_trick_mode_flag: " << static_cast(rhs.DSM_trick_mode_flag) << '\n'; 49 | ss << "additional_copy_info_flag: " << static_cast(rhs.additional_copy_info_flag) << '\n'; 50 | ss << "PES_CRC_flag: " << static_cast(rhs.PES_CRC_flag) << '\n'; 51 | ss << "PES_extension_flag: " << static_cast(rhs.PES_extension_flag) << '\n'; 52 | 53 | ss << "pts: " << rhs.pts << '\n'; 54 | ss << "dts: " << rhs.dts << '\n'; 55 | 56 | ss << "PES_header_data_length: " << static_cast(rhs.PES_header_data_length) << '\n'; 57 | return ss; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/TsDemuxer.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for uint8_t 28 | #include // for function 29 | #include // for map, _Rb_tree_iterator, map<>::mapped... 30 | #include // for unique_ptr 31 | 32 | // 3rd-party 33 | #include "plog/Log.h" // for LOGE_ 34 | 35 | #include "Logging.h" // for FileLog 36 | #include "TsParser.h" // for TsParser 37 | #include "TsStatistics.h" // for TsStatistics 38 | #include "Ts_IEC13818-1.h" // for PSI_TABLE_ID_PAT, PSI_TABLE_ID_PMT 39 | #include "mpeg2ts.h" // for TsDemuxer, TsPacketInfo, PsiCallBackFnc 40 | #include "mpeg2ts_version.h" // for getMpeg2tsVersion() 41 | 42 | 43 | namespace mpeg2ts 44 | { 45 | TsDemuxer::TsDemuxer() 46 | : mParser{ std::unique_ptr(new TsParser()) } 47 | { 48 | } 49 | 50 | TsDemuxer::~TsDemuxer() 51 | { 52 | } 53 | 54 | 55 | void TsDemuxer::demux(const uint8_t* a_tsPacket) 56 | { 57 | TsPacketInfo tsPacketInfo = {}; 58 | mParser->parseTsPacketInfo(a_tsPacket, tsPacketInfo); 59 | 60 | if (tsPacketInfo.errorIndicator) 61 | { 62 | mParser->mStatistics.addTsPacketErrorIndicator(); 63 | } 64 | 65 | if (tsPacketInfo.pid == TS_PACKET_PID_NULL) 66 | { 67 | mParser->mStatistics.addTsPacketNullPacketCounter(); 68 | return; // Skip null packets, they contain no info 69 | } 70 | 71 | if (mTsCallbackMap.find(tsPacketInfo.pid) != mTsCallbackMap.end()) 72 | { 73 | mTsCallbackMap[tsPacketInfo.pid](a_tsPacket, tsPacketInfo, mHandlers[tsPacketInfo.pid]); 74 | } 75 | 76 | if (mPsiCallbackMap.find(tsPacketInfo.pid) != mPsiCallbackMap.end()) 77 | { 78 | // Check what table 79 | int table_id; 80 | mParser->collectTable(a_tsPacket, tsPacketInfo, table_id, mOrigin); 81 | 82 | if (table_id == PSI_TABLE_ID_PAT) 83 | { 84 | // Error check 85 | if (tsPacketInfo.pid != TS_PACKET_PID_PAT) 86 | { 87 | LOGE_(FileLog) << "ERROR: Stream does not conform to 13818-1 TS standard."; 88 | } 89 | else 90 | { 91 | PatTable pat = mParser->parsePatPacket(tsPacketInfo.pid); 92 | mPsiCallbackMap[tsPacketInfo.pid](mParser->getRawTable(tsPacketInfo.pid), &pat, 93 | tsPacketInfo.pid, mHandlers[tsPacketInfo.pid]); 94 | } 95 | } 96 | else if (table_id == PSI_TABLE_ID_PMT) 97 | { 98 | 99 | PmtTable pmt = mParser->parsePmtPacket(tsPacketInfo.pid); 100 | mPsiCallbackMap[tsPacketInfo.pid](mParser->getRawTable(tsPacketInfo.pid), &pmt, 101 | tsPacketInfo.pid, mHandlers[tsPacketInfo.pid]); 102 | } 103 | } 104 | 105 | if (mPesCallbackMap.find(tsPacketInfo.pid) != mPesCallbackMap.end()) 106 | { 107 | PesPacket pes; 108 | if (mParser->collectPes(a_tsPacket, tsPacketInfo, pes, mOrigin)) 109 | { 110 | mPesCallbackMap[tsPacketInfo.pid](pes.mPesBuffer, pes, tsPacketInfo.pid, 111 | mHandlers[tsPacketInfo.pid]); 112 | } 113 | } 114 | 115 | mParser->mStatistics.addTsPacketCounter(); 116 | } 117 | 118 | void TsDemuxer::addPsiPid(int a_pid, PsiCallBackFnc a_cb, void* a_hdl) 119 | { 120 | mPsiCallbackMap[a_pid] = a_cb; 121 | mHandlers[a_pid] = a_hdl; 122 | } 123 | 124 | void TsDemuxer::addPesPid(int a_pid, PesCallBackFnc a_cb, void* a_hdl) 125 | { 126 | mPesCallbackMap[a_pid] = a_cb; 127 | mHandlers[a_pid] = a_hdl; 128 | } 129 | 130 | void TsDemuxer::addTsPid(int a_pid, TsCallBackFnc a_cb, void* a_hdl) 131 | { 132 | mTsCallbackMap[a_pid] = a_cb; 133 | mHandlers[a_pid] = a_hdl; 134 | } 135 | 136 | PidStatisticsMap TsDemuxer::getPidStatistics() const 137 | { 138 | return mParser->mStatistics.getPidStatistics(); 139 | } 140 | 141 | TsCounters TsDemuxer::getTsCounters() const 142 | { 143 | return mParser->mStatistics.getTsCounters(); 144 | } 145 | 146 | std::string TsDemuxer::getMpeg2tsLibVersion() const 147 | { 148 | return getMpeg2tsVersion(); 149 | } 150 | 151 | unsigned TsDemuxer::getMpeg2tsLibVersionMajor() const 152 | { 153 | return getMpeg2tsVersionMajor(); 154 | } 155 | 156 | unsigned TsDemuxer::getMpeg2tsLibVersionMinor() const 157 | { 158 | return getMpeg2tsVersionMinor(); 159 | } 160 | 161 | unsigned TsDemuxer::getMpeg2tsLibVersionPatch() const 162 | { 163 | return getMpeg2tsVersionPatch(); 164 | } 165 | 166 | unsigned TsDemuxer::getMpeg2tsLibVersionTweak() const 167 | { 168 | return getMpeg2tsVersionTweak(); 169 | } 170 | 171 | void TsDemuxer::setOrigin(int64_t origin) 172 | { 173 | mOrigin = origin; 174 | } 175 | 176 | int64_t TsDemuxer::getOrigin(int pid) 177 | { 178 | return mParser->getOrigin(pid); 179 | } 180 | 181 | } // mpeg2ts 182 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/TsPacketInfo.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for operator<<, ostream, basic_ostream, basic_ostre... 28 | 29 | #include "mpeg2ts.h" // for TsPacketInfo, operator<< 30 | 31 | namespace mpeg2ts 32 | { 33 | 34 | std::ostream& operator<<(std::ostream& ss, const TsPacketInfo& rhs) 35 | { 36 | ss << "-------------TsPacketInfo------------- " << '\n'; 37 | ss << "PID: " << rhs.pid << '\n'; 38 | ss << "errorIndicator: " << static_cast(rhs.errorIndicator) << '\n'; 39 | ss << "isPayloadStart: " << static_cast(rhs.isPayloadStart) << '\n'; 40 | ss << "hasAdaptationField: " << rhs.hasAdaptationField << '\n'; 41 | ss << "hasPayload: " << rhs.hasPayload << '\n'; 42 | ss << "hasPrivateData: " << rhs.hasPrivateData << '\n'; 43 | ss << "hasRandomAccess: " << rhs.hasRandomAccess << '\n'; 44 | ss << "isScrambled: " << rhs.isScrambled << '\n'; 45 | ss << "isDiscontinuity: " << rhs.isDiscontinuity << '\n'; 46 | ss << "continuityCounter: " << static_cast(rhs.continuityCounter) << '\n'; 47 | 48 | ss << "pcr: " << rhs.pcr << '\n'; 49 | ss << "opcr: " << rhs.opcr << '\n'; 50 | 51 | ss << "pts: " << rhs.pts << '\n'; 52 | ss << "dts: " << rhs.dts << '\n'; 53 | 54 | if (rhs.hasPrivateData) 55 | { 56 | ss << "privateDataSize: " << rhs.privateDataSize << '\n'; 57 | ss << "privateDataOffset: " << rhs.privateDataOffset << '\n'; 58 | } 59 | if (rhs.hasPayload) 60 | { 61 | ss << "payloadSize: " << rhs.payloadSize << '\n'; 62 | ss << "payloadStartOffset: " << static_cast(rhs.payloadStartOffset) << '\n'; 63 | } 64 | ss << "isError: " << rhs.isError << '\n'; 65 | return ss; 66 | } 67 | 68 | } // namespace mpeg2ts 69 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/TsParser.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _TSPARSER_H 28 | #define _TSPARSER_H 29 | 30 | #include // for uint8_t, uint64_t 31 | #include // for map 32 | 33 | // Project files 34 | #include "GetBits.h" // for GetBits 35 | #include "TsStatistics.h" // for TsStatistics 36 | #include "Ts_IEC13818-1.h" // for TsAdaptationFieldHeader, TsHeader 37 | #include "mpeg2ts.h" // for ByteVector, TsPacketInfo (ptr only) 38 | 39 | namespace mpeg2ts 40 | { 41 | 42 | class TsParser : private GetBits 43 | { 44 | public: 45 | /*! 46 | * Parse information about one ts-packet to find useful information 47 | * like for example PES-start, PCR, DTS, 48 | * @param pkt Pointer to ts-packet. 49 | * @param info Ts-packet information describing this packet. 50 | */ 51 | void parseTsPacketInfo(const uint8_t* packet, TsPacketInfo& outInfo); 52 | 53 | /*! 54 | * Checks if the ts-packet has correct sync byte. 55 | * @param packet Pointer to Ts-packet first byte. 56 | * @return True if valid sync byte, else false 57 | */ 58 | bool checkSyncByte(const uint8_t* byte); 59 | 60 | /*! 61 | * Return a copy of the TsHeader. 62 | * @param packet Pointer to ts-packet. 63 | * @return TsHeader. 64 | */ 65 | TsHeader parseTsHeader(const uint8_t* packet); 66 | 67 | /*! 68 | * Checks if a pts-packet has the adaptation field. 69 | * @param hdr TsPacket header 70 | * @return True if it has adaptation field, else false. 71 | */ 72 | bool checkHasAdaptationField(TsHeader hdr); 73 | 74 | /*! 75 | * Checks if a ts-packet has the adaptation field. 76 | * @param hdr TsPacket header 77 | * @return True if it has payload, else false. 78 | */ 79 | bool checkHasPayload(TsHeader hdr); 80 | 81 | /*! 82 | * Return a copy of the TsAdaptationFieldHeader 83 | * @return TsAdaptationFieldHeader 84 | */ 85 | TsAdaptationFieldHeader parseAdaptationFieldHeader(); 86 | 87 | /*! 88 | * Parse adaptation field data acoording to ISO/IEC 13818-1:2015 89 | * @param packet Pointer to ts-packet. 90 | * @param outInfo Return TsPacketInfo 91 | */ 92 | void parseAdaptationFieldData(const uint8_t* packet, TsPacketInfo& outInfo); 93 | 94 | /*! 95 | * Parse PCR from a ts-packet 96 | * @return The PCR value. 97 | */ 98 | uint64_t parsePcr(); 99 | 100 | /*! 101 | * Parses Collects all parts of table and parses basic table information (eg table id) 102 | * @param tsPacket mpeg2 transport stream packet with table in payload 103 | * @param tsPacketInfo Input packet inforamtion 104 | * @param table_id Collected table id 105 | */ 106 | void collectTable(const uint8_t* tsPacket, const TsPacketInfo& tsPacketInfo, int& table_id, int64_t origin = -1); 107 | /*! 108 | * Parses PSI table 109 | * @param packet 110 | * @param info 111 | * @param psiTable 112 | */ 113 | void parsePsiTable(const ByteVector& table, PsiTable& tableInfo); 114 | 115 | /*! 116 | * Parses PAT table 117 | * @param packet 118 | * @param info 119 | * @return 120 | */ 121 | PatTable parsePatPacket(int pid); 122 | 123 | /*! 124 | * Parse PMT table 125 | * @param packet 126 | * @param info 127 | * @return 128 | */ 129 | PmtTable parsePmtPacket(int pid); 130 | 131 | /*! 132 | * Collects several TS-Packets for assembling a complete PES-Packet. 133 | * When collected this function returns true, during collection (un-complete PES) 134 | * it returns false. No errors are considered at the moment. 135 | * @param tsPacket The packet to collect. 136 | * @param tsPacketInfo Pre-parsed metadata about this TS-Packet. 137 | * @param pesPacket collected PES but only ready/complete/collected when true 138 | * @return True if collected a complete PES-Packet false in all other cases 139 | */ 140 | bool collectPes(const uint8_t* tsPacket, const TsPacketInfo& tsPacketInfo, PesPacket& pesPacket, int64_t origin = -1); 141 | 142 | /*! 143 | * Parses the start of a new PES-Packet. This is typically done before collecting 144 | * several TS-Packets for generating a complete PES-Packet. This function is used 145 | * internally by collectPes(). 146 | */ 147 | void parsePesPacket(int pid); 148 | 149 | /*! 150 | * Return raw bytes of table at pid 151 | */ 152 | ByteVector& getRawTable(int pid); 153 | 154 | int64_t getOrigin(int pid) 155 | { 156 | return mOrigins[pid]; 157 | } 158 | TsStatistics mStatistics; 159 | 160 | private: 161 | // TODO maybe 1 parser per pid? 162 | std::map mSectionBuffer; 163 | std::map mSectionLength; 164 | std::map mTableId; 165 | std::map mReadSectionLength; 166 | std::map mPesPacket; 167 | std::map mOrigins; 168 | }; 169 | 170 | } // namespace mpeg2ts 171 | 172 | #endif /* _TSPARSER_H */ 173 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/TsStatistics.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include // for map 28 | #include // for basic_ostream::operator<< 29 | 30 | // 3rd-party 31 | #include "plog/Record.h" // for Record 32 | #include "plog/Log.h" // for LOGD_ 33 | 34 | // project files 35 | #include "Logging.h" // for FileLog 36 | #include "mpeg2ts.h" // for PidStatistic, PidStatisticsMap, TsCounters 37 | #include "TsStatistics.h" 38 | 39 | namespace mpeg2ts 40 | { 41 | 42 | // constants 43 | const int64_t TsStatistics::CLOCK_90_KHZ = 90000; 44 | const int64_t TsStatistics::TIME_STAMP_JUMP_DISCONTINUITY_LEVEL = 3 * CLOCK_90_KHZ; 45 | 46 | TsStatistics::TsStatistics() 47 | { 48 | } 49 | 50 | void TsStatistics::checkCCError(int a_pid, uint8_t a_cc) 51 | { 52 | if (mPidStatistics[a_pid].lastCC == PidStatistic::INVALID_CC) 53 | { 54 | mPidStatistics[a_pid].lastCC = a_cc; 55 | } 56 | if (mPidStatistics[a_pid].lastCC != a_cc) 57 | { 58 | if (((mPidStatistics[a_pid].lastCC + 1) & 0x0f) != a_cc) 59 | { 60 | ++mPidStatistics[a_pid].numberOfCCErrors; 61 | LOGD_(FileLog) << "Continuity counter error at ts packet " << mCounters.mTsPacketCounter << " on pid " 62 | << a_pid << ", last: " << static_cast(mPidStatistics[a_pid].lastCC) 63 | << ", cur: " << static_cast(a_cc) << '\n'; 64 | } 65 | mPidStatistics[a_pid].lastCC = a_cc; 66 | } 67 | } 68 | 69 | void TsStatistics::checkTsDiscontinuity(int a_pid, bool a_isDiscontinuous) 70 | { 71 | if (a_isDiscontinuous) 72 | { 73 | ++mPidStatistics[a_pid].numberOfTsDiscontinuities; 74 | LOGD_(FileLog) << "Transport stream discontinuity at ts packet " 75 | << mCounters.mTsPacketCounter << " on pid " << a_pid << '\n'; 76 | } 77 | } 78 | 79 | void TsStatistics::buildPtsHistogram(int a_pid, int64_t a_pts) 80 | { 81 | if (a_pts == -1) 82 | { 83 | mPidStatistics[a_pid].numberOfMissingPts++; 84 | return; 85 | } 86 | if (mPidStatistics[a_pid].lastPts == -1) 87 | { 88 | mPidStatistics[a_pid].lastPts = a_pts; 89 | return; 90 | } 91 | auto diff = a_pts - mPidStatistics[a_pid].lastPts; 92 | mPidStatistics[a_pid].ptsHistogram[diff]++; 93 | if (diff > TIME_STAMP_JUMP_DISCONTINUITY_LEVEL) 94 | { 95 | LOGD_(FileLog) 96 | << "PTS discontinuity at ts packet " << mCounters.mTsPacketCounter << " on pid " << a_pid 97 | << " pts-1 " << mPidStatistics[a_pid].lastPts << " pts-0 " << a_pts << " pts diff " << diff; 98 | } 99 | mPidStatistics[a_pid].lastPts = a_pts; 100 | } 101 | 102 | void TsStatistics::buildDtsHistogram(int a_pid, int64_t a_dts) 103 | { 104 | if (a_dts == -1) 105 | { 106 | mPidStatistics[a_pid].numberOfMissingDts++; 107 | return; 108 | } 109 | if (mPidStatistics[a_pid].lastDts == -1) 110 | { 111 | mPidStatistics[a_pid].lastDts = a_dts; 112 | return; 113 | } 114 | auto diff = a_dts - mPidStatistics[a_pid].lastDts; 115 | mPidStatistics[a_pid].dtsHistogram[diff]++; 116 | if (diff > TIME_STAMP_JUMP_DISCONTINUITY_LEVEL) 117 | { 118 | LOGD_(FileLog) << "DTS discontinuity at ts packet " << mCounters.mTsPacketCounter 119 | << " on pid " << a_pid << " dts-1 " << mPidStatistics[a_pid].lastDts 120 | << " dts-0 " << a_dts << " dts diff " << diff << '\n'; 121 | } 122 | 123 | mPidStatistics[a_pid].lastDts = a_dts; 124 | } 125 | 126 | void TsStatistics::buildPcrHistogram(int a_pid, int64_t a_pcr) 127 | { 128 | if (a_pcr == -1) 129 | { 130 | return; 131 | } 132 | if (mPidStatistics[a_pid].lastPcr == -1) 133 | { 134 | mPidStatistics[a_pid].lastPcr = a_pcr; 135 | return; 136 | } 137 | auto diff = a_pcr - mPidStatistics[a_pid].lastPcr; 138 | mPidStatistics[a_pid].pcrHistogram[diff]++; 139 | if (diff > TIME_STAMP_JUMP_DISCONTINUITY_LEVEL * 300) 140 | { 141 | LOGD_(FileLog) << "PCR discontinuity at ts packet " << mCounters.mTsPacketCounter 142 | << " on pid " << a_pid << " pcr-1 " << mPidStatistics[a_pid].lastPcr 143 | << " pcr-0 " << a_pcr << " pcr diff " << diff << '\n'; 144 | } 145 | 146 | mPidStatistics[a_pid].lastPcr = a_pcr; 147 | } 148 | 149 | } // namespace mpeg2ts 150 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/TsStatistics.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #ifndef _TSSTATISTICS_H 28 | #define _TSSTATISTICS_H 29 | 30 | #include // for int64_t, for uint8_t 31 | 32 | #include "mpeg2ts.h" // for TsCounters, PidStatisticsMap 33 | 34 | namespace mpeg2ts 35 | { 36 | class TsStatistics 37 | { 38 | public: 39 | // Constants 40 | static const int64_t CLOCK_90_KHZ; 41 | static const int64_t TIME_STAMP_JUMP_DISCONTINUITY_LEVEL; // 3s 42 | 43 | explicit TsStatistics(); 44 | 45 | /*! 46 | * Calculates Continuity errors. 47 | * @param pid Filtered PID. 48 | * @param cc Current TS packets Continuity Counter. 49 | */ 50 | void checkCCError(int pid, uint8_t cc); 51 | 52 | /*! 53 | * Book keep flagged TS packets discontinuities. 54 | * @param pid Filtered PID. 55 | * @param isDiscontinuous Whether or not this is a discontinuity. 56 | */ 57 | void checkTsDiscontinuity(int pid, bool isDiscontinuous); 58 | 59 | /*! 60 | * Build a histogram of PTS differences between 2 time samples. 61 | * @param pid Filtered PID. 62 | * @param pts Program Time Stamp value. 63 | */ 64 | void buildPtsHistogram(int pid, int64_t pts); 65 | 66 | /*! 67 | * Build a histogram of DTS differences between 2 time samples. 68 | * @param pid Filtered PID. 69 | * @param pts Display Time Stamp value. 70 | */ 71 | void buildDtsHistogram(int pid, int64_t dts); 72 | 73 | /*! 74 | * Build a histogram of PCR differences between 2 time samples. 75 | * @param pid Filtered PID. 76 | * @param pts Program Clock Reference value. 77 | */ 78 | void buildPcrHistogram(int pid, int64_t pcr); 79 | 80 | PidStatisticsMap getPidStatistics() const; 81 | TsCounters getTsCounters() const; 82 | 83 | void addTsPacketErrorIndicator(); 84 | void addTsPacketNullPacketCounter(); 85 | void addTsPacketCounter(); 86 | 87 | private: 88 | PidStatisticsMap mPidStatistics; 89 | TsCounters mCounters; 90 | }; 91 | 92 | inline PidStatisticsMap TsStatistics::getPidStatistics() const 93 | { 94 | return mPidStatistics; 95 | } 96 | 97 | inline TsCounters TsStatistics::getTsCounters() const 98 | { 99 | return mCounters; 100 | } 101 | 102 | inline void TsStatistics::addTsPacketErrorIndicator() 103 | { 104 | ++mCounters.mTsPacketErrorIndicator; 105 | } 106 | 107 | inline void TsStatistics::addTsPacketNullPacketCounter() 108 | { 109 | ++mCounters.mTsPacketNullPacketCounter; 110 | } 111 | 112 | inline void TsStatistics::addTsPacketCounter() 113 | { 114 | ++mCounters.mTsPacketCounter; 115 | } 116 | 117 | } // namespace mpeg2ts 118 | 119 | #endif /* _TSSTATISTICS_H */ 120 | -------------------------------------------------------------------------------- /libs/mpeg2ts/src/mpeg2ts_version.h.in: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts lib 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include 28 | 29 | inline std::string getMpeg2tsVersion() 30 | { 31 | return "@mpeg2ts_VERSION@"; 32 | } 33 | 34 | inline unsigned getMpeg2tsVersionMajor() 35 | { 36 | return @mpeg2ts_VERSION_MAJOR@; 37 | } 38 | 39 | inline unsigned getMpeg2tsVersionMinor() 40 | { 41 | return @mpeg2ts_VERSION_MINOR@ +0; 42 | } 43 | 44 | inline unsigned getMpeg2tsVersionPatch() 45 | { 46 | return @mpeg2ts_VERSION_PATCH@ +0; 47 | } 48 | 49 | inline unsigned getMpeg2tsVersionTweak() 50 | { 51 | return @mpeg2ts_VERSION_TWEAK@ +0; 52 | } 53 | -------------------------------------------------------------------------------- /mpeg2ts.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "./" 5 | } 6 | ], 7 | "settings": { 8 | "editor.tokenColorCustomizations": { 9 | "textMateRules": [ 10 | { 11 | "scope": "googletest.failed", 12 | "settings": { 13 | "foreground": "#f00" 14 | } 15 | }, 16 | { 17 | "scope": "googletest.passed", 18 | "settings": { 19 | "foreground": "#0f0" 20 | } 21 | }, 22 | { 23 | "scope": "googletest.run", 24 | "settings": { 25 | "foreground": "#0f0" 26 | } 27 | } 28 | ] 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mpeg2tsConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | #find_dependency() 3 | include("${CMAKE_CURRENT_LIST_DIR}/mpeg2tsTargets.cmake") -------------------------------------------------------------------------------- /samples/TsUtilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts samples 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | project( 31 | sample_tsutilities 32 | VERSION 0.6.0 33 | DESCRIPTION "Sample TsUtilities" 34 | LANGUAGES CXX 35 | ) 36 | else() 37 | project( 38 | sample_tsutilities 39 | VERSION 0.6.0 40 | LANGUAGES CXX 41 | ) 42 | endif() 43 | 44 | add_executable( 45 | ${PROJECT_NAME} 46 | ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp 47 | ) 48 | 49 | if(CMAKE_MINOR_VERSION GREATER 7) 50 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 51 | endif() 52 | 53 | target_include_directories( 54 | ${PROJECT_NAME} 55 | PRIVATE 56 | ${CMAKE_CURRENT_SOURCE_DIR}/src 57 | ) 58 | 59 | target_link_libraries(${PROJECT_NAME} 60 | PRIVATE 61 | mpeg2ts 62 | mpeg2codec 63 | h264codec 64 | ) 65 | 66 | set(LOGFILE_LEVEL "DEBUG") 67 | configure_file(settings.json.in settings.json) 68 | -------------------------------------------------------------------------------- /samples/TsUtilities/settings.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "settings": { 3 | "logLevel": "@LOGFILE_LEVEL@", 4 | "logFileName": "${PROJECT_NAME}.csv", 5 | "logFileMaxSize": 102400, 6 | "logFileMaxNumberOf": 10 7 | } 8 | } -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #***************************************************************** 2 | # 3 | # Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | # 5 | # mpeg2ts - mpeg2ts tests 6 | # 7 | # This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | # 9 | # Unless you have obtained mpeg2ts under a different license, 10 | # this version of mpeg2ts is mpeg2ts|GPL. 11 | # Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | # modify it under the terms of the GNU General Public License as 13 | # published by the Free Software Foundation; either version 2, 14 | # or (at your option) any later version. 15 | # 16 | # Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with mpeg2ts|GPL; see the file COPYING. If not, write to 23 | # the Free Software Foundation, 59 Temple Place - Suite 330, 24 | # Boston, MA 02111-1307, USA. 25 | # 26 | #*******************************************************************/ 27 | cmake_minimum_required(VERSION 3.5) 28 | 29 | if(CMAKE_MINOR_VERSION GREATER 9) 30 | include(GoogleTest) # Introduced in CMake 3.10 31 | project( 32 | run_gtests 33 | VERSION 0.6.0 34 | DESCRIPTION "GTests for mpeg2ts lib" 35 | LANGUAGES CXX 36 | ) 37 | else() 38 | project( 39 | run_gtests 40 | VERSION 0.6.0 41 | LANGUAGES CXX 42 | ) 43 | endif() 44 | 45 | 46 | #------------------- 47 | # Locate GTest 48 | enable_testing() 49 | find_package(GTest MODULE) 50 | find_library(GMOCK_LIBRARY 51 | NAMES gmock 52 | libgmock 53 | libgmock.a 54 | PATHS "${GTEST_DIR}" 55 | PATH_SUFFIXES lib 56 | ) 57 | 58 | include_directories(${GTEST_INCLUDE_DIRS}) 59 | 60 | if (NOT GTest_FOUND) 61 | message(WARNING " Could NOT Find GTest") 62 | endif() 63 | 64 | #------------------- 65 | # tests 66 | #------------------- 67 | # Now simply link against gtest, gmock, gtest_main or gmock_main as needed. Eg 68 | add_executable( 69 | ${PROJECT_NAME} 70 | gtest_main.cc 71 | ) 72 | 73 | target_compile_definitions(${PROJECT_NAME} PRIVATE MPEG2TS_DLL_EXPORTS) 74 | 75 | if(CMAKE_MINOR_VERSION GREATER 7) 76 | target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) 77 | endif() 78 | 79 | target_sources(${PROJECT_NAME} 80 | PRIVATE 81 | GetBits_Tests.cc 82 | Mpeg2VideoParser_Tests.cc 83 | PsiTables_Tests.cc 84 | TsDemuxer_Tests.cc 85 | TsPacketTestData.h 86 | TsParser_Tests.cc 87 | TsStatistics_Tests.cc 88 | TsUtilities_Tests.cc 89 | H264Parser_Tests.cc 90 | ) 91 | 92 | target_include_directories( 93 | ${PROJECT_NAME} 94 | PRIVATE 95 | ${CMAKE_CURRENT_SOURCE_DIR}/. 96 | ${CMAKE_CURRENT_BINARY_DIR}/.. 97 | $# Testing private src/headers 98 | $# Testing private src/headers 99 | $# Testing private src/headers 100 | ) 101 | 102 | if(USE_DOCKER) 103 | target_link_libraries(${PROJECT_NAME} PRIVATE ${GMOCK_LIBRARY} ${GTEST_LIBRARY} pthread) 104 | else(USE_DOCKER) 105 | find_package(Threads REQUIRED) 106 | target_link_libraries( 107 | ${PROJECT_NAME} 108 | PRIVATE 109 | Threads::Threads 110 | gmock 111 | ) 112 | endif(USE_DOCKER) 113 | 114 | target_link_libraries(${PROJECT_NAME} 115 | PRIVATE 116 | mpeg2ts 117 | mpeg2codec 118 | h264codec 119 | common 120 | ) 121 | 122 | 123 | if(GTEST_HAVE_DISCOVERY) 124 | gtest_discover_tests(${PROJECT_NAME} TEST_PREFIX ${exportname}. TEST_LIST 125 | ${PROJECT_NAME}_targets) 126 | else() 127 | if(CMAKE_MINOR_VERSION GREATER 8) 128 | # For CMake 3.9 onwards 129 | gtest_add_tests( 130 | TARGET 131 | ${PROJECT_NAME} 132 | SOURCES 133 | ${TARGET_SOURCES} 134 | TEST_PREFIX 135 | ${exportname}. 136 | TEST_LIST 137 | ${PROJECT_NAME}_targets 138 | ) 139 | endif() 140 | endif() 141 | -------------------------------------------------------------------------------- /tests/H264Parser_Tests.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts tests 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include 28 | #include 29 | 30 | /// Project files CUT (Class Under Test) 31 | #include "H264Parser.h" 32 | 33 | #include "CodecTestData.h" 34 | 35 | using namespace h264; 36 | 37 | 38 | class H264ParserTest : public ::testing::Test 39 | { 40 | public: 41 | void SetUp() override 42 | { 43 | } 44 | 45 | void TearDown() override 46 | { 47 | } 48 | H264EsParser parser; 49 | }; 50 | 51 | 52 | TEST_F(H264ParserTest, test_bare_findStartCodes) 53 | { 54 | std::vector testVec = { 0, 0, 1 }; 55 | std::vector testVec2 = { 0, 0, 0, 1 }; 56 | 57 | std::vector ret = parser.findStartCodes(testVec); 58 | std::vector ret2 = parser.findStartCodes(testVec2); 59 | 60 | EXPECT_EQ(0, ret.size()); 61 | EXPECT_EQ(1, ret2.size()); 62 | EXPECT_EQ(0, ret2[0]); 63 | } 64 | 65 | 66 | TEST_F(H264ParserTest, test_findStartCodes_1) 67 | { 68 | std::vector testVec = { 0, 0, 0, 1 }; 69 | 70 | std::vector ret = parser.findStartCodes(testVec); 71 | 72 | EXPECT_EQ(1, ret.size()); 73 | EXPECT_EQ(0, ret[0]); 74 | } 75 | 76 | 77 | TEST_F(H264ParserTest, test_findStartCodes_2) 78 | { 79 | std::vector testVec = { 0, 1 }; 80 | 81 | std::vector ret = parser.findStartCodes(testVec); 82 | 83 | EXPECT_EQ(0, ret.size()); 84 | } 85 | 86 | 87 | TEST_F(H264ParserTest, test_findStartCodes_3) 88 | { 89 | std::vector testVec = { 0, 0, 0 }; 90 | 91 | std::vector ret = parser.findStartCodes(testVec); 92 | 93 | EXPECT_EQ(0, ret.size()); 94 | } 95 | 96 | 97 | TEST_F(H264ParserTest, test_findStartCodes_4) 98 | { 99 | std::vector testVec1 = { 0, 0, 0 }; 100 | std::vector testVec2 = { 1 }; 101 | 102 | std::vector ret = parser.findStartCodes(testVec1); 103 | EXPECT_EQ(0, ret.size()); 104 | } 105 | 106 | 107 | TEST_F(H264ParserTest, test_findStartCodes_5) 108 | { 109 | std::vector testVec1 = { 0, 0 }; 110 | std::vector testVec2 = { 0, 1 }; 111 | 112 | std::vector ret = parser.findStartCodes(testVec1); 113 | 114 | EXPECT_EQ(0, ret.size()); 115 | } 116 | 117 | 118 | TEST_F(H264ParserTest, test_findStartCodes_6) 119 | { 120 | std::vector testVec1 = { 0 }; 121 | std::vector testVec2 = { 0, 0, 1 }; 122 | 123 | std::vector ret = parser.findStartCodes(testVec1); 124 | 125 | EXPECT_EQ(0, ret.size()); 126 | } 127 | 128 | 129 | TEST_F(H264ParserTest, test_findStartCodes_7) 130 | { 131 | std::vector testVec = { 1, 2, 3, 0, 0, 0, 1, 4, 5, 6, 7, 0, 0, 0, 1 }; 132 | 133 | std::vector ret = parser.findStartCodes(testVec); 134 | 135 | EXPECT_EQ(2, ret.size()); 136 | EXPECT_EQ(3, ret[0]); 137 | EXPECT_EQ(11, ret[1]); 138 | } 139 | 140 | 141 | TEST_F(H264ParserTest, test_findStartCodes_8) 142 | { 143 | std::vector testVec = { 1, 2, 3, 0, 1, 0, 0, 1 }; 144 | 145 | std::vector ret = parser.findStartCodes(testVec); 146 | 147 | EXPECT_EQ(0, ret.size()); 148 | } 149 | -------------------------------------------------------------------------------- /tests/gtest_main.cc: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * 3 | * Copyright © 2017-2020 kohnech, lnwhome All rights reserved 4 | * 5 | * mpeg2ts - mpeg2ts tests 6 | * 7 | * This file is part of mpeg2ts (Mpeg2 Transport Stream Library). 8 | * 9 | * Unless you have obtained mpeg2ts under a different license, 10 | * this version of mpeg2ts is mpeg2ts|GPL. 11 | * Mpeg2ts|GPL is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU General Public License as 13 | * published by the Free Software Foundation; either version 2, 14 | * or (at your option) any later version. 15 | * 16 | * Mpeg2ts|GPL is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with mpeg2ts|GPL; see the file COPYING. If not, write to the 23 | * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 24 | * 02111-1307, USA. 25 | * 26 | ********************************************************************/ 27 | #include 28 | #include 29 | 30 | // Global asset 31 | std::string asset_file; 32 | 33 | int main(int argc, char** argv) 34 | { 35 | ::testing::InitGoogleTest(&argc, argv); 36 | ::testing::InitGoogleMock(&argc, argv); 37 | 38 | if (argc != 2) 39 | { 40 | std::cout << "You must use asset input for unit tests, example:\n"; 41 | std::cout << "./run_gtests ~/Videos/bbc_one.ts\n"; 42 | return 0; 43 | } 44 | 45 | asset_file = argv[1]; 46 | 47 | if (asset_file.find("bbc_one.ts") == std::string::npos) 48 | { 49 | std::cout << "Must be asset bbc_one.ts!" << '\n'; 50 | return 0; 51 | } 52 | 53 | std::cout << "asset_file: " << asset_file << '\n'; 54 | 55 | return RUN_ALL_TESTS(); 56 | // system("PAUSE"); 57 | // return 0; 58 | } -------------------------------------------------------------------------------- /tests/valgrind_suppress.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skullanbones/mpeg2ts/72e5611d9391a82053b804b577274a4c3e08cf33/tests/valgrind_suppress.txt --------------------------------------------------------------------------------