├── plugins ├── code │ ├── common │ │ ├── CMakeLists.txt │ │ ├── Common │ │ │ ├── CMakeLists.txt │ │ │ └── plugins_common.h │ │ └── Debugger │ │ │ ├── CMakeLists.txt │ │ │ └── plugins_debugger.h │ ├── j2k_dec │ │ ├── CMakeLists.txt │ │ └── kakadu │ │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ ├── j2k_dec_kakadu_plugin.cpp │ │ │ ├── j2k_dec_kakadu.h │ │ │ └── j2k_dec_kakadu.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── cmake │ │ │ └── kakaduConfig.cmake │ │ │ └── README.md │ ├── tiff_dec │ │ ├── CMakeLists.txt │ │ ├── libtiff │ │ │ ├── src │ │ │ │ ├── CMakeLists.txt │ │ │ │ └── tiff_dec_libtiff.cpp │ │ │ ├── CMakeLists.txt │ │ │ └── cmake │ │ │ │ └── TIFFConfig.cmake │ │ └── README.md │ ├── image_transformer │ │ ├── CMakeLists.txt │ │ └── dummy │ │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ └── image_transformer_dummy.cpp │ │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ ├── hevc_enc │ │ ├── x265 │ │ │ ├── src │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── hevc_enc_x265_utils.h │ │ │ │ └── hevc_enc_x265.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── cmake │ │ │ │ └── x265Config.cmake │ │ │ └── README.md │ │ ├── CMakeLists.txt │ │ └── beamr │ │ │ ├── src │ │ │ ├── CMakeLists.txt │ │ │ ├── hevc_enc_beamr_utils.h │ │ │ ├── hevc_enc_beamr_impl.h │ │ │ ├── hevc_enc_beamr_utils.cpp │ │ │ └── hevc_enc_beamr.cpp │ │ │ ├── README.md │ │ │ ├── CMakeLists.txt │ │ │ └── cmake │ │ │ └── beamrConfig.cmake │ └── api │ │ ├── CMakeLists.txt │ │ ├── j2k_dec │ │ ├── CMakeLists.txt │ │ └── j2k_dec_api.h │ │ ├── hevc_enc │ │ ├── CMakeLists.txt │ │ └── hevc_enc_api.h │ │ ├── tiff_dec │ │ ├── CMakeLists.txt │ │ └── tiff_dec_api.h │ │ ├── prores_dec │ │ ├── CMakeLists.txt │ │ └── prores_dec_api.h │ │ ├── pcm_watermarker │ │ ├── CMakeLists.txt │ │ └── pcm_watermarker_api.h │ │ └── image_transformer │ │ ├── CMakeLists.txt │ │ └── image_transformer_api.h ├── CMakeLists.txt └── BUILDING.md ├── README.md └── LICENSE /plugins/code/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(Common) 2 | add_subdirectory(Debugger) -------------------------------------------------------------------------------- /plugins/code/j2k_dec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (DEE_PLUGINS_ENABLE_KAKADU_J2K_DECODER) 2 | add_subdirectory(kakadu) 3 | endif() -------------------------------------------------------------------------------- /plugins/code/tiff_dec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (DEE_PLUGINS_ENABLE_LIBTIFF_TIFF_DECODER) 2 | add_subdirectory(libtiff) 3 | endif() -------------------------------------------------------------------------------- /plugins/code/image_transformer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (DEE_PLUGINS_ENABLE_DUMMY_IMAGE_TRANSFORMER) 2 | add_subdirectory(dummy) 3 | endif() -------------------------------------------------------------------------------- /plugins/code/tiff_dec/libtiff/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(dee_plugin_tiff_dec_libtiff 2 | PRIVATE 3 | tiff_dec_libtiff.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /plugins/code/image_transformer/dummy/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(dee_plugin_image_transformer_dummy 2 | PRIVATE 3 | image_transformer_dummy.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /plugins/code/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(api) 2 | add_subdirectory(common) 3 | add_subdirectory(hevc_enc) 4 | add_subdirectory(image_transformer) 5 | add_subdirectory(j2k_dec) 6 | add_subdirectory(tiff_dec) -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(dee_plugin_hevc_enc_x265 2 | PRIVATE 3 | hevc_enc_x265_utils.cpp 4 | hevc_enc_x265_utils.h 5 | hevc_enc_x265.cpp 6 | ) 7 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(DEE_PLUGINS_ENABLE_BEAMR_HEVC_ENCODER) 2 | add_subdirectory(beamr) 3 | endif() 4 | 5 | if(DEE_PLUGINS_ENABLE_X265_HEVC_ENCODER) 6 | add_subdirectory(x265) 7 | endif() -------------------------------------------------------------------------------- /plugins/code/api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(hevc_enc) 2 | add_subdirectory(image_transformer) 3 | add_subdirectory(j2k_dec) 4 | add_subdirectory(prores_dec) 5 | add_subdirectory(tiff_dec) 6 | add_subdirectory(pcm_watermarker) 7 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(dee_plugin_hevc_enc_beamr 2 | PRIVATE 3 | hevc_enc_beamr_impl.cpp 4 | hevc_enc_beamr_impl.h 5 | hevc_enc_beamr_utils.cpp 6 | hevc_enc_beamr_utils.h 7 | hevc_enc_beamr.cpp 8 | ) 9 | -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(dee_plugin_j2k_dec_kakadu_base 2 | PUBLIC 3 | FILE_SET HEADERS 4 | FILES 5 | j2k_dec_kakadu.h 6 | PRIVATE 7 | j2k_dec_kakadu.cpp 8 | ) 9 | 10 | target_sources(dee_plugin_j2k_dec_kakadu 11 | PRIVATE 12 | j2k_dec_kakadu_plugin.cpp 13 | ) 14 | -------------------------------------------------------------------------------- /plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.24) 2 | 3 | project(dee-plugins) 4 | 5 | option(DEE_PLUGINS_ENABLE_BEAMR_HEVC_ENCODER "Enables beamr HEVC encoder" ON) 6 | option(DEE_PLUGINS_ENABLE_X265_HEVC_ENCODER "Enables x265 HEVC encoder" ON) 7 | option(DEE_PLUGINS_ENABLE_KAKADU_J2K_DECODER "Enables kakadu J2K decoder" ON) 8 | option(DEE_PLUGINS_ENABLE_LIBTIFF_TIFF_DECODER "Enables libtiff TIFF decoder" ON) 9 | option(DEE_PLUGINS_ENABLE_DUMMY_IMAGE_TRANSFORMER "Enables dummy image transformer" ON) 10 | 11 | include(GNUInstallDirs) 12 | 13 | add_subdirectory(code) -------------------------------------------------------------------------------- /plugins/code/common/Common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(plugins_common INTERFACE) 2 | add_library(dee_plugins::plugins_common ALIAS plugins_common) 3 | 4 | target_sources(plugins_common 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | plugins_common.h 10 | ) 11 | 12 | include(GNUInstallDirs) 13 | install(TARGETS plugins_common 14 | EXPORT plugins_commonTargets 15 | FILE_SET HEADERS 16 | ) 17 | 18 | install(EXPORT plugins_commonTargets 19 | NAMESPACE dee_plugins:: 20 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 21 | ) 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dolby-encoding-engine 2 | 3 | This repository contains various additions to Dolby Encoding Engine (DEE), such as plugins allowing integration of 3rd party components. 4 | 5 | :mega: If you need stable source code, use [release archives](https://github.com/DolbyLaboratories/dolby-encoding-engine/releases) to get components associated with specific DEE version. 6 | 7 | Master branch is updated outside of DEE release schedule. 8 | It may happen, that master branch is ahead of DEE release and contains compatibility-breaking changes. In that case, published components cannot be used with latest, public DEE release. 9 | -------------------------------------------------------------------------------- /plugins/code/common/Debugger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(plugins_debugger INTERFACE) 2 | add_library(dee_plugins::plugins_debugger ALIAS plugins_debugger) 3 | 4 | target_sources(plugins_debugger 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | plugins_debugger.h 10 | ) 11 | 12 | include(GNUInstallDirs) 13 | install(TARGETS plugins_debugger 14 | EXPORT plugins_debuggerTargets 15 | FILE_SET HEADERS 16 | ) 17 | 18 | install(EXPORT plugins_debuggerTargets 19 | NAMESPACE dee_plugins:: 20 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 21 | ) 22 | -------------------------------------------------------------------------------- /plugins/code/api/j2k_dec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(j2k_dec_api INTERFACE) 2 | add_library(dee_plugins::j2k_dec_api ALIAS j2k_dec_api) 3 | 4 | target_sources(j2k_dec_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | j2k_dec_api.h 10 | ) 11 | 12 | target_link_libraries(j2k_dec_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS j2k_dec_api 19 | EXPORT j2k_dec_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT j2k_dec_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/api/hevc_enc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(hevc_enc_api INTERFACE) 2 | add_library(dee_plugins::hevc_enc_api ALIAS hevc_enc_api) 3 | 4 | target_sources(hevc_enc_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | hevc_enc_api.h 10 | ) 11 | 12 | target_link_libraries(hevc_enc_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS hevc_enc_api 19 | EXPORT hevc_enc_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT hevc_enc_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/api/tiff_dec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(tiff_dec_api INTERFACE) 2 | add_library(dee_plugins::tiff_dec_api ALIAS tiff_dec_api) 3 | 4 | target_sources(tiff_dec_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | tiff_dec_api.h 10 | ) 11 | 12 | target_link_libraries(tiff_dec_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS tiff_dec_api 19 | EXPORT tiff_dec_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT tiff_dec_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/api/prores_dec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(prores_dec_api INTERFACE) 2 | add_library(dee_plugins::prores_dec_api ALIAS prores_dec_api) 3 | 4 | target_sources(prores_dec_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | prores_dec_api.h 10 | ) 11 | 12 | target_link_libraries(prores_dec_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS prores_dec_api 19 | EXPORT prores_dec_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT prores_dec_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/api/pcm_watermarker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(pcm_watermarker_api INTERFACE) 2 | add_library(dee_plugins::pcm_watermarker_api ALIAS pcm_watermarker_api) 3 | 4 | target_sources(pcm_watermarker_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | pcm_watermarker_api.h 10 | ) 11 | 12 | target_link_libraries(pcm_watermarker_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS pcm_watermarker_api 19 | EXPORT pcm_watermarker_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT pcm_watermarker_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/api/image_transformer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(image_transformer_api INTERFACE) 2 | add_library(dee_plugins::image_transformer_api ALIAS image_transformer_api) 3 | 4 | target_sources(image_transformer_api 5 | INTERFACE 6 | FILE_SET HEADERS 7 | BASE_DIRS . 8 | FILES 9 | image_transformer_api.h 10 | ) 11 | 12 | target_link_libraries(image_transformer_api 13 | INTERFACE 14 | dee_plugins::plugins_common 15 | ) 16 | 17 | include(GNUInstallDirs) 18 | install(TARGETS image_transformer_api 19 | EXPORT image_transformer_apiTargets 20 | FILE_SET HEADERS 21 | ) 22 | 23 | install(EXPORT image_transformer_apiTargets 24 | NAMESPACE dee_plugins:: 25 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 26 | ) 27 | -------------------------------------------------------------------------------- /plugins/code/image_transformer/dummy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(dee_plugin_image_transformer_dummy SHARED) 2 | add_library(dee_plugins::dee_plugin_image_transformer_dummy ALIAS dee_plugin_image_transformer_dummy) 3 | 4 | target_compile_features(dee_plugin_image_transformer_dummy 5 | PRIVATE 6 | cxx_std_11 7 | ) 8 | 9 | target_link_libraries(dee_plugin_image_transformer_dummy 10 | PRIVATE 11 | dee_plugins::image_transformer_api 12 | ) 13 | 14 | install(TARGETS dee_plugin_image_transformer_dummy 15 | EXPORT dee_plugin_image_transformer_dummyTargets 16 | ) 17 | 18 | install(EXPORT dee_plugin_image_transformer_dummyTargets 19 | NAMESPACE dee_plugins:: 20 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 21 | ) 22 | 23 | add_subdirectory(src) 24 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") 2 | find_package(x265 REQUIRED) 3 | 4 | add_library(dee_plugin_hevc_enc_x265 SHARED) 5 | add_library(dee_plugins::dee_plugin_hevc_enc_x265 ALIAS dee_plugin_hevc_enc_x265) 6 | 7 | target_compile_features(dee_plugin_hevc_enc_x265 8 | PRIVATE 9 | cxx_std_11 10 | ) 11 | 12 | target_link_libraries(dee_plugin_hevc_enc_x265 13 | PRIVATE 14 | dee_plugins::hevc_enc_api 15 | x265::x265 16 | ) 17 | 18 | install(TARGETS dee_plugin_hevc_enc_x265 19 | EXPORT dee_plugin_hevc_enc_x265Targets 20 | ) 21 | 22 | install(EXPORT dee_plugin_hevc_enc_x265Targets 23 | NAMESPACE dee_plugins:: 24 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 25 | ) 26 | 27 | add_subdirectory(src) 28 | -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/src/j2k_dec_kakadu_plugin.cpp: -------------------------------------------------------------------------------- 1 | #include "j2k_dec_kakadu.h" 2 | 3 | static 4 | Status 5 | kakadu_set_property 6 | (J2kDecHandle /**< [in/out] Decoder instance handle */ 7 | , const Property* /**< [in] Property to write */ 8 | ) 9 | { 10 | return STATUS_ERROR; 11 | } 12 | 13 | static 14 | J2kDecApi kakadu_plugin_api = 15 | { 16 | "kakadu" 17 | ,kakadu_get_info 18 | ,kakadu_get_size 19 | ,kakadu_init 20 | ,kakadu_close 21 | ,kakadu_process 22 | ,kakadu_set_property 23 | ,kakadu_get_property 24 | ,kakadu_get_message 25 | }; 26 | 27 | DLB_EXPORT 28 | J2kDecApi* j2kDecGetApi() 29 | { 30 | return &kakadu_plugin_api; 31 | } 32 | 33 | DLB_EXPORT 34 | int j2kDecGetApiVersion(void) 35 | { 36 | return J2K_DEC_API_VERSION; 37 | } 38 | -------------------------------------------------------------------------------- /plugins/code/tiff_dec/libtiff/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") 2 | 3 | find_package(TIFF CONFIG REQUIRED) 4 | add_library(dee_plugin_tiff_dec_libtiff SHARED) 5 | add_library(dee_plugins::dee_plugin_tiff_dec_libtiff ALIAS dee_plugin_tiff_dec_libtiff) 6 | 7 | target_compile_features(dee_plugin_tiff_dec_libtiff 8 | PRIVATE 9 | cxx_std_11 10 | ) 11 | 12 | target_link_libraries(dee_plugin_tiff_dec_libtiff 13 | PRIVATE 14 | dee_plugins::tiff_dec_api 15 | TIFF::TIFF 16 | ) 17 | 18 | install(TARGETS dee_plugin_tiff_dec_libtiff 19 | EXPORT dee_plugin_tiff_dec_libtiffTargets 20 | ) 21 | 22 | install(EXPORT dee_plugin_tiff_dec_libtiffTargets 23 | NAMESPACE dee_plugins:: 24 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 25 | ) 26 | 27 | add_subdirectory(src) 28 | -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/src/j2k_dec_kakadu.h: -------------------------------------------------------------------------------- 1 | #include "j2k_dec_api.h" 2 | 3 | size_t 4 | kakadu_get_info 5 | (const PropertyInfo** info); 6 | 7 | size_t 8 | kakadu_get_size(); 9 | 10 | Status 11 | kakadu_init 12 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 13 | ,const J2kDecInitParams* init_params /**< [in] Properties to init decoder instance */ 14 | ); 15 | 16 | Status 17 | kakadu_close 18 | (J2kDecHandle handle 19 | ); 20 | 21 | Status 22 | kakadu_process 23 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 24 | ,const J2kDecInput* in /**< [in] Encoded input */ 25 | ,J2kDecOutput* out /**< [out] Decoded output */ 26 | ); 27 | 28 | Status 29 | kakadu_get_property 30 | (J2kDecHandle /**< [in/out] Decoder instance handle */ 31 | , Property* /**< [in/out] Property to read */ 32 | ); 33 | 34 | const char* 35 | kakadu_get_message 36 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 37 | ); 38 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/cmake/x265Config.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 4 | if(CMAKE_OSX_ARCHITECTURES) 5 | if ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES) 6 | message(FATAL_ERROR "Building macOS universal binaries is not supported") 7 | endif() 8 | endif() 9 | 10 | set(X265_LIBNAME "libx265.dylib") 11 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 12 | set(X265_LIBNAME "libx265.dll") 13 | set(X265_IMPLIB "libx265.lib") 14 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 15 | set(X265_LIBNAME "libx265.so") 16 | else() 17 | message(FATAL_ERROR "Not supported OS/architecture") 18 | endif() 19 | 20 | add_library(x265::x265 SHARED IMPORTED) 21 | 22 | set_target_properties(x265::x265 23 | PROPERTIES 24 | IMPORTED_LOCATION "$ENV{X265ROOT}/lib/${X265_LIBNAME}" 25 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{X265ROOT}/include" 26 | ) 27 | 28 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 29 | set_target_properties(x265::x265 PROPERTIES 30 | IMPORTED_IMPLIB "$ENV{X265ROOT}/lib/${X265_IMPLIB}" 31 | ) 32 | endif() -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/README.md: -------------------------------------------------------------------------------- 1 | # Beamr HEVC encoder plugin for Dolby Encoding Engine 2 | 3 | Provided source code was built and tested using Beamr5x-4.7.5.6. 4 | 5 | ## Build tools 6 | 7 | - Visual Studio 2022 8 | - gcc 11.5 (or higher) 9 | 10 | ## Prerequisites 11 | 12 | To build the plugin, Beamr5x SDK is required, and the environment variable `BEAMR_SDK` pointing to the kit folder. 13 | The typical structure of the kit folder is presented below. 14 | 15 | ```bash 16 | BEAMR_SDK 17 | ├── Beamr_5_Installation_Notes.pdf 18 | ├── bin 19 | ├── common_primitives 20 | │ ├── include 21 | │ └── src 22 | ├── inc 23 | ├── lib 24 | ├── lib64 25 | ├── license 26 | └── samples 27 | ``` 28 | 29 | The build uses files in following folders: 30 | 31 | - $BEAMR_SDK/common_primitives/include 32 | - $BEAMR_SDK/common_primitives/src 33 | - $BEAMR_SDK/inc 34 | - $BEAMR_SDK/lib 35 | - $BEAMR_SDK/lib64 36 | 37 | ## Build instructions 38 | 39 | Extract the kit folder from the archive and set the `BEAMR_SDK` environment variable. 40 | 41 | Build the plugin (see [BUILDING.md](../../../BUILDING.md)), then copy `libdee_plugin_hevc_enc_beamr.so` or `libdee_plugin_hevc_enc_beamr.dll` (depending on your operating system) to the DEE installation folder. The file can be renamed, but the extension must remain unchanged. 42 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") 2 | find_package(beamr REQUIRED COMPONENTS encoder common_primitives) 3 | 4 | add_library(dee_plugin_hevc_enc_beamr SHARED) 5 | add_library(dee_plugins::dee_plugin_hevc_enc_beamr ALIAS dee_plugin_hevc_enc_beamr) 6 | 7 | target_compile_features(dee_plugin_hevc_enc_beamr 8 | PRIVATE 9 | cxx_std_11 10 | ) 11 | 12 | if(MSVC AND MSVC_VERSION GREATER_EQUAL 1930) 13 | # libmmt.lib conflicts with libucrt.lib in MSVC >= 19.3x 14 | # with the following error: "libucrt.lib(frexp.obj) : error LNK2005: frexp already defined in libmmt.lib(frexp_iface_c99.obj)" 15 | # most likely caused by libmmt.lib being too old and no longer fully compatibile with new libcurt.lib 16 | target_link_options(dee_plugin_hevc_enc_beamr PRIVATE "/FORCE:MULTIPLE") 17 | endif() 18 | 19 | target_link_libraries(dee_plugin_hevc_enc_beamr 20 | PRIVATE 21 | dee_plugins::plugins_debugger 22 | dee_plugins::hevc_enc_api 23 | beamr::encoder 24 | beamr::common_primitives 25 | ) 26 | 27 | install(TARGETS dee_plugin_hevc_enc_beamr 28 | EXPORT dee_plugin_hevc_enc_beamrTargets 29 | ) 30 | 31 | install(EXPORT dee_plugin_hevc_enc_beamrTargets 32 | NAMESPACE dee_plugins:: 33 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 34 | ) 35 | 36 | add_subdirectory(src) -------------------------------------------------------------------------------- /plugins/code/tiff_dec/libtiff/cmake/TIFFConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 4 | if(CMAKE_OSX_ARCHITECTURES) 5 | if ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES) 6 | message(FATAL_ERROR "Building macOS universal binaries is not supported") 7 | endif() 8 | endif() 9 | 10 | set(LIBTIFF_NAME "libtiff.dylib") 11 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 12 | set(LIBTIFF_NAME "tiff.dll") 13 | set(LIBTIFF_IMPLIB "tiff.lib") 14 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 15 | set(LIBTIFF_NAME "libtiff.so") 16 | else() 17 | message(FATAL_ERROR "Not supported OS/architecture") 18 | endif() 19 | 20 | 21 | add_library(TIFF::TIFF SHARED IMPORTED) 22 | set_target_properties(TIFF::TIFF 23 | PROPERTIES 24 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{LIBTIFFROOT}/include" 25 | ) 26 | 27 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 28 | set_target_properties(TIFF::TIFF 29 | PROPERTIES 30 | IMPORTED_LOCATION "$ENV{LIBTIFFROOT}/bin/${LIBTIFF_NAME}" 31 | IMPORTED_IMPLIB "$ENV{LIBTIFFROOT}/lib/${LIBTIFF_IMPLIB}" 32 | ) 33 | else() 34 | set_target_properties(TIFF::TIFF 35 | PROPERTIES 36 | IMPORTED_LOCATION "$ENV{LIBTIFFROOT}/lib/${LIBTIFF_NAME}" 37 | ) 38 | endif() 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /plugins/BUILDING.md: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | 3 | - CMake 3.24 or newer 4 | - gcc 11.5 or Visual Studio 2022 5 | 6 | # Instructions 7 | 8 | ## Configure 9 | 10 | By default, this CMake project builds all plugins. 11 | 12 | For detailed instructions on where each plugin expects its dependent libraries to be located, please refer to the plugin's README file (e.g. x265 HEVC encoder plugin's [README.md](code/hevc_enc/x265/README.md)). 13 | 14 | To exclude specific plugins from the build, use the appropriate CMake option during configuration. For example, to disable the Beamr HEVC encoder plugin: 15 | 16 | ```bash 17 | cmake -B build -S . -DDEE_PLUGINS_ENABLE_BEAMR_HEVC_ENCODER=OFF 18 | ``` 19 | 20 | Depending on the target platform, it may be necessary to specify options such as the MSVC multi-threaded statically linked runtime library using `-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded"`, or position-independent code using `-DCMAKE_POSITION_INDEPENDENT_CODE=ON`. 21 | 22 | Specifying an option that is unsupported on a given platform will simply be ignored, so it is fine to provide both settings: 23 | 24 | ```bash 25 | cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -DCMAKE_POSITION_INDEPENDENT_CODE=ON 26 | ``` 27 | 28 | Please refer to [CMakeLists.txt](CMakeLists.txt) for more build options. 29 | 30 | ## Build 31 | 32 | To build the project, run: 33 | 34 | ```bash 35 | cmake --build build --config Release -j 36 | ``` -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") 2 | find_package(kakadu REQUIRED) 3 | 4 | add_library(dee_plugin_j2k_dec_kakadu_base STATIC) 5 | add_library(dee_plugins::dee_plugin_j2k_dec_kakadu_base ALIAS dee_plugin_j2k_dec_kakadu_base) 6 | 7 | target_sources(dee_plugin_j2k_dec_kakadu_base 8 | PUBLIC 9 | FILE_SET HEADERS 10 | TYPE HEADERS 11 | BASE_DIRS src 12 | ) 13 | 14 | target_link_libraries(dee_plugin_j2k_dec_kakadu_base 15 | PUBLIC 16 | dee_plugins::j2k_dec_api 17 | PRIVATE 18 | kakadu::kakadu 19 | ) 20 | 21 | install(TARGETS dee_plugin_j2k_dec_kakadu_base 22 | EXPORT dee_plugin_j2k_dec_kakadu_baseTargets 23 | FILE_SET HEADERS 24 | ) 25 | 26 | install(EXPORT dee_plugin_j2k_dec_kakadu_baseTargets 27 | NAMESPACE dee_plugins:: 28 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 29 | ) 30 | 31 | add_library(dee_plugin_j2k_dec_kakadu SHARED) 32 | add_library(dee_plugins::dee_plugin_j2k_dec_kakadu ALIAS dee_plugin_j2k_dec_kakadu) 33 | 34 | target_link_libraries(dee_plugin_j2k_dec_kakadu 35 | PRIVATE 36 | dee_plugins::dee_plugin_j2k_dec_kakadu_base 37 | ) 38 | 39 | install(TARGETS dee_plugin_j2k_dec_kakadu 40 | EXPORT dee_plugin_j2k_dec_kakaduTargets 41 | ) 42 | 43 | install(EXPORT dee_plugin_j2k_dec_kakaduTargets 44 | NAMESPACE dee_plugins:: 45 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dee_plugins" 46 | ) 47 | 48 | add_subdirectory(src) 49 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/README.md: -------------------------------------------------------------------------------- 1 | # x265 HEVC encoder plugin for Dolby Encoding Engine 2 | 3 | The provided source code was built and tested using the x265 library version 4.1. 4 | 5 | ## Requirements: 6 | - Windows: 7 | - Visual Studio 2022 8 | - [NASM](https://nasm.us/pub/nasm/releasebuilds/?C=M;O=D) 9 | - [CMake](https://github.com/Kitware/CMake/releases/tag/v3.31.8) 10 | - Linux: 11 | - gcc 11.5 12 | - [NASM](https://nasm.us/pub/nasm/releasebuilds/?C=M;O=D) 13 | - [CMake](https://github.com/Kitware/CMake/releases/tag/v3.31.8) 14 | 15 | ## Building x265 library 16 | The x265 library has to be build with multi-bitdepth (8/10/12-bit) support and in shared format. 17 | - Navigate to [x265 git repository](https://bitbucket.org/multicoreware/x265_git/src/4.1/build/) and locate `multilib` file for your platform. 18 | - Execute `multilib` file to build `x265` library. 19 | - Multi-bitdepth library will be located in newly created `8bit` directory 20 | 21 | ## Building x265 plugin 22 | - Setup the library directory as pesented below. Copy necessary files from the [previous step](#building-x265-library): 23 | ```bash 24 | x265_root 25 | ├── include 26 | │   ├── x265_config.h 27 | │   └── x265.h 28 | └── lib 29 | └── libx265.so or libx265.lib 30 | ``` 31 | 32 | - Set `X265ROOT` environment variable pointing to `x265_root`. 33 | - Build the plugin (see [BUILDING.md](../../../BUILDING.md)) 34 | - Copy x265 shared library (`libx265.so` or `libx265.dll`) 35 | and plugin library (`libdee_plugin_hevc_enc_x265.so` or `dee_plugin_hevc_enc_x265.dll`) to the DEE installation folder. The plugin library file can be renamed, but the extension must remain unchanged. 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD-3-Clause-Clear 2 | 3 | Copyright (c) 2017-2025 Dolby Laboratories 4 | Copyright (c) 2017-2025 Dolby International AB 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted (subject to the limitations in the disclaimer 9 | below) provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in 16 | the documentation and/or other materials provided with the 17 | distribution. 18 | 19 | * Neither the name of the copyright holder nor the names of its 20 | contributors may be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED 24 | BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 26 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /plugins/code/tiff_dec/README.md: -------------------------------------------------------------------------------- 1 | # libtiff TIFF decoder plugin for Dolby Encoding Engine 2 | 3 | The provided source code was built and tested using the libtiff version 4.7.0. 4 | 5 | ## Build tools: 6 | - Visual Studio 2022 7 | - gcc 11.5 8 | 9 | ## Prerequisites: 10 | 11 | To build the plugin, you must first build and install the [libtiff 4.7.0](https://gitlab.com/libtiff/libtiff/-/releases/v4.7.0) `tiff` shared library. 12 | Use `cmake` to build and install libtiff libraries. Navigate to the extracted directory in terminal and invoke: 13 | - See all available configuration options: 14 | - `cmake -h` 15 | - Generate project with specific install prefix (and other options): 16 | - `cmake -B build -S . --install-prefix [other options]` 17 | - Build project: 18 | - `cmake --build build --config Release -j` 19 | - Install project to `INSTALL_PATH`: 20 | - `cmake --install build` 21 | 22 | Once built and installed, define `LIBTIFFROOT` environment variable to point to `INSTALL_PATH` defined during configuration step. 23 | Example `LIBTIFFROOT` directory structure (for Windows) is presented below. 24 | 25 | ```bash 26 | LIBTIFFROOT 27 | ├───bin 28 | │ fax2ps.exe 29 | │ fax2tiff.exe 30 | │ pal2rgb.exe 31 | │ ... 32 | │ tiff.dll 33 | ├───include 34 | │ tiff.h 35 | │ tiffconf.h 36 | │ tiffio.h 37 | │ tiffio.hxx 38 | │ tiffvers.h 39 | │ 40 | └───lib 41 | │ tiff.lib 42 | │ tiffxx.lib 43 | ... 44 | ``` 45 | 46 | ## Build instructions 47 | 48 | Build the plugin (see [BUILDING.md](../../BUILDING.md)), then copy the `tiff` shared library and plugin library: 49 | - on Linux: `LIBTIFFROOT/lib/libtiff.so` and `libdee_plugin_tiff_dec_libtiff.so` 50 | - on Windows: `LIBTIFFROOT/bin/tiff.dll` and `libdee_plugin_tiff_dec_libtiff.dll` 51 | 52 | to the DEE installation folder. The plugin library file may be renamed, but its file extension must remain unchanged. 53 | -------------------------------------------------------------------------------- /plugins/code/api/pcm_watermarker/pcm_watermarker_api.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEE_PLUGINS_PCM_WATERMARKER_API_H__ 2 | #define __DEE_PLUGINS_PCM_WATERMARKER_API_H__ 3 | 4 | #include "plugins_common.h" 5 | #include 6 | 7 | #define PCM_WATERMARKER_API_VERSION 1 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct PcmWatermarkerFrame{ 14 | PcmWatermarkerFrame() { 15 | buffer = nullptr; 16 | channelsCount = 0; 17 | samplesCount = 0; 18 | stride = 0; 19 | } 20 | 21 | PcmWatermarkerFrame(float** buffer, uint32_t channelsCount, uint64_t samplesCount, uint32_t stride) { 22 | buffer = buffer; 23 | channelsCount = channelsCount; 24 | samplesCount = samplesCount; 25 | stride = stride; 26 | } 27 | 28 | float** buffer; 29 | uint32_t channelsCount; 30 | uint64_t samplesCount; 31 | uint32_t stride; 32 | }; 33 | 34 | typedef struct { 35 | const Property* properties; 36 | size_t count; 37 | } PcmWatermarkerInitParams; 38 | 39 | typedef void* PcmWatermarkerHandle; 40 | 41 | typedef size_t (*PcmWatermarkerGetInfo)(const PropertyInfo** info); 42 | 43 | typedef size_t (*PcmWatermarkerGetSize)(); 44 | 45 | typedef Status (*PcmWatermarkerInit)(PcmWatermarkerHandle handle, const PcmWatermarkerInitParams* initParams); 46 | 47 | typedef Status (*PcmWatermarkerClose)(PcmWatermarkerHandle handle); 48 | 49 | typedef Status (*PcmWatermarkerProcess) (PcmWatermarkerHandle handle, PcmWatermarkerFrame* inFrame); 50 | 51 | typedef const char* (*PcmWatermarkerGetMessage)(PcmWatermarkerHandle handle); 52 | 53 | typedef struct { 54 | const char* pluginName; 55 | PcmWatermarkerGetInfo getInfo; 56 | PcmWatermarkerGetSize getSize; 57 | PcmWatermarkerInit init; 58 | PcmWatermarkerClose close; 59 | PcmWatermarkerProcess process; 60 | PcmWatermarkerGetMessage getMessage; 61 | } PcmWatermarkerApi; 62 | 63 | DLB_EXPORT 64 | PcmWatermarkerApi* pcmWatermarkerGetApi(); 65 | 66 | typedef PcmWatermarkerApi* (*PcmWatermarkerGetApi)(); 67 | 68 | DLB_EXPORT 69 | int pcmWatermarkerGetApiVersion(void); 70 | 71 | typedef int (*PcmWatermarkerGetApiVersion)(void); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/cmake/kakaduConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 4 | if(CMAKE_OSX_ARCHITECTURES) 5 | if ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES) 6 | message(FATAL_ERROR "Building macOS universal binaries is not supported") 7 | elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") 8 | set(MACOS_ARCH "arm64") 9 | elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") 10 | set(MACOS_ARCH "x86_64") 11 | endif() 12 | else() 13 | set(MACOS_ARCH "${CMAKE_SYSTEM_PROCESSOR}") 14 | endif() 15 | 16 | set(KAKADU_LIBNAME "libkdu_v84R.so") 17 | if(MACOS_ARCH STREQUAL "arm64") 18 | set(KAKADU_LIBDIR "lib/Mac-arm-64-gcc") 19 | elseif(MACOS_ARCH STREQUAL "x86_64") 20 | set(KAKADU_LIBDIR "lib/Mac-x86-64-gcc") 21 | else() 22 | message(FATAL_ERROR "Unsupported macOS architecture") 23 | endif() 24 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 25 | set(KAKADU_LIBDIR "../bin_x64") 26 | set(KAKADU_LIBNAME "kdu_v84R.dll") 27 | set(KAKADU_IMPLIBDIR "../lib_x64") 28 | set(KAKADU_IMPLIBNAME "kdu_v84R.lib") 29 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 30 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)") 31 | set(KAKADU_LIBDIR "lib/Linux-arm-64-gcc") 32 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)") 33 | set(KAKADU_LIBDIR "lib/Linux-x86-64-gcc") 34 | else() 35 | message(FATAL_ERROR "Unsupported Linux architecture") 36 | endif() 37 | set(KAKADU_LIBNAME "libkdu_v84R.so") 38 | else() 39 | message(FATAL_ERROR "Not supported OS/architecture") 40 | endif() 41 | 42 | add_library(kakadu::kdu SHARED IMPORTED) 43 | set_target_properties(kakadu::kdu 44 | PROPERTIES 45 | IMPORTED_LOCATION "$ENV{KDUROOT}/${KAKADU_LIBDIR}/${KAKADU_LIBNAME}" 46 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{KDUROOT}/coresys/common" 47 | ) 48 | 49 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows") 50 | set_target_properties(kakadu::kdu 51 | PROPERTIES 52 | IMPORTED_IMPLIB "$ENV{KDUROOT}/${KAKADU_IMPLIBDIR}/${KAKADU_IMPLIBNAME}" 53 | ) 54 | endif() 55 | 56 | add_library(support STATIC) 57 | add_library(kakadu::support ALIAS support) 58 | target_include_directories(support 59 | PUBLIC 60 | "$ENV{KDUROOT}/apps/support" 61 | ) 62 | target_sources(support 63 | PRIVATE 64 | "$ENV{KDUROOT}/apps/support/kdu_stripe_decompressor.cpp" 65 | "$ENV{KDUROOT}/apps/support/avx2_stripe_transfer.cpp" 66 | "$ENV{KDUROOT}/apps/support/ssse3_stripe_transfer.cpp" 67 | "$ENV{KDUROOT}/apps/support/neon_stripe_transfer.cpp" 68 | "$ENV{KDUROOT}/apps/support/supp_local.cpp" 69 | ) 70 | target_link_libraries(support 71 | PRIVATE 72 | kakadu::kdu 73 | ) 74 | 75 | add_library(kakadu::kakadu INTERFACE IMPORTED) 76 | target_link_libraries(kakadu::kakadu 77 | INTERFACE 78 | kakadu::kdu 79 | kakadu::support 80 | ) -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/src/hevc_enc_beamr_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_HEVC_ENC_BEAMR_UTILS_H__ 34 | #define __DEE_PLUGINS_HEVC_ENC_BEAMR_UTILS_H__ 35 | 36 | #include "hevc_enc_api.h" 37 | #include 38 | #include 39 | 40 | std::vector split(const std::string& s, const std::string& delim); 41 | int64_t parseInt(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count); 42 | std::string parseString(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count); 43 | std::string parseStringList(const std::string& name, 44 | const std::string& value, 45 | const std::string& listDelim, 46 | const std::string& enums); 47 | bool parseBool(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count); 48 | 49 | int64_t string2int(const std::string& name, const std::string& value, int64_t minValue, int64_t maxValue); 50 | bool string2bool(const std::string& name, const std::string& value); 51 | 52 | struct FramePeriod { 53 | int numUnitsInTick; 54 | int timeScale; 55 | }; 56 | 57 | FramePeriod string2FramePeriod(const std::string& s); 58 | int color_primaries2int(const std::string& s); 59 | int transfer_characteristics2int(const std::string& s); 60 | int matrix_coefficients2int(const std::string& s); 61 | 62 | void checkFileReadable(const std::string& path); 63 | void checkFileWritable(const std::string& path); 64 | 65 | #endif //__DEE_PLUGINS_HEVC_ENC_BEAMR_UTILS_H__ 66 | -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/README.md: -------------------------------------------------------------------------------- 1 | # Kakadu JPEG2000 decoder plugin for Dolby Encoding Engine 2 | 3 | The provided source code was built and tested using the Kakadu SDK version 8.4. 4 | 5 | ## Build tools: 6 | - Visual Studio 2022 7 | - gcc 11.5 8 | 9 | ## Prerequisites: 10 | 11 | To build the plugin, you must first build the Kakadu `coresys` shared library. The build files for `coresys` are typically located in the `coresys/make` directory (for Linux and macOS Makefiles), or directly in the `coresys` folder (for Windows Visual Studio `.sln` files). Once built, define `KDUROOT` environment variable pointing to the Kakadu source tree. 12 | 13 | A typical Kakadu SDK directory structure is shown below. Note that, in addition to the `coresys` library, the plugin requires additional source files located in the `apps/support` directory, as well as headers from the `coresys/common` folder. 14 | 15 | ```bash 16 | ├── KDUROOT 17 | │ ├── apps 18 | │ │ ├── support 19 | │ │ │ ├── avx2_stripe_transfer.cpp 20 | │ │ │ ├── kdu_region_animator.h 21 | │ │ │ ├── kdu_region_compositor.h 22 | │ │ │ ├── kdu_region_decompressor.h 23 | │ │ │ ├── kdu_stripe_compressor.h 24 | │ │ │ ├── kdu_stripe_decompressor.cpp 25 | │ │ │ ├── kdu_stripe_decompressor.h 26 | │ │ │ ├── neon_region_compositor_local.h 27 | │ │ │ ├── neon_region_decompressor_local.h 28 | │ │ │ ├── neon_stripe_transfer_local.h 29 | │ │ │ ├── neon_stripe_transfer.cpp 30 | │ │ │ ├── region_animator_local.h 31 | │ │ │ ├── region_compositor_local.h 32 | │ │ │ ├── region_decompressor_local.h 33 | │ │ │ ├── ssse3_stripe_transfer.cpp 34 | │ │ │ ├── stripe_compressor_local.h 35 | │ │ │ ├── stripe_decompressor_local.h 36 | │ │ │ ├── supp_local.cpp 37 | │ │ │ ├── supp_local.h 38 | │ │ │ ├── x86_region_compositor_local.h 39 | │ │ │ ├── x86_region_decompressor_local.h 40 | │ │ │ ├── x86_stripe_transfer_local.h 41 | │ │ │ └── ... 42 | │ │ └── ... 43 | │ ├── coresys 44 | │ │ ├── common 45 | │ │ │ ├── arch_masm64.asm 46 | │ │ │ ├── kdu_arch.cpp 47 | │ │ │ ├── kdu_arch.h 48 | │ │ │ ├── kdu_block_coding.h 49 | │ │ │ ├── kdu_compressed.h 50 | │ │ │ ├── kdu_elementary.h 51 | │ │ │ ├── kdu_kernels.h 52 | │ │ │ ├── kdu_messaging.h 53 | │ │ │ ├── kdu_params.h 54 | │ │ │ ├── kdu_roi_processing.h 55 | │ │ │ ├── kdu_sample_processing.h 56 | │ │ │ ├── kdu_threads.h 57 | │ │ │ ├── kdu_ubiquitous.h 58 | │ │ │ └── kdu_utils.h 59 | │ │ ├── make 60 | │ │ │ ├── Makefile-Linux-x86-64-gcc 61 | │ │ │ ├── Makefile-Mac-x86-64-gcc 62 | │ │ │ ├── Makefile-Mac-arm-64-gcc 63 | │ │ │ └── ... 64 | │ │ └── ... 65 | │ ├── lib 66 | │ │ ├── Linux-x86-64-gcc 67 | │ │ │   └── libkdu_v84R.so 68 | │ │ ├── Mac-x86-64-gcc 69 | │ │ │ └── libkdu_v84R.so 70 | │ │ └── ... 71 | │ └── ... 72 | ├── bin_x64 73 | │ └── kdu_v84R.dll 74 | └── lib_x64 75 | └── kdu_v84R.lib 76 | ``` 77 | 78 | ## Build instructions 79 | 80 | Set up the Kakadu directory as described above, and set the `KDUROOT` environment variable to point to that folder. Note that on Windows, the binaries are located outside the `KDUROOT` folder, as this is where Kakadu build files place them by default. 81 | 82 | Build the plugin (see [BUILDING.md](../../../BUILDING.md)), then copy the Kakadu shared libraries (e.g., `libkdu_v84R.so` or `kdu_v84R.dll`) and the plugin library (e.g., `libdee_plugin_j2k_dec_kakadu.so` or `dee_plugin_j2k_dec_kakadu.dll`) to the DEE installation folder. The plugin library file may be renamed, but its file extension must remain unchanged. 83 | -------------------------------------------------------------------------------- /plugins/code/common/Common/plugins_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_COMMON_H__ 34 | #define __DEE_PLUGINS_COMMON_H__ 35 | 36 | #include 37 | 38 | /** @brief Status code */ 39 | typedef enum { 40 | STATUS_OK = 0, 41 | STATUS_WARNING, 42 | STATUS_ERROR, 43 | } Status; 44 | 45 | /** @brief Property read/write structure */ 46 | typedef struct { 47 | const char* name; /**< Name of property */ 48 | char* value; /**< Value of property */ 49 | size_t maxValueSz; /**< Size of buffer pointed by 'value' */ 50 | } Property; 51 | 52 | /** @brief Type o property 53 | * Defines how property is presented in XML schema. 54 | */ 55 | typedef enum { 56 | PROPERTY_TYPE_STRING = 0, 57 | PROPERTY_TYPE_INTEGER, 58 | PROPERTY_TYPE_DECIMAL, 59 | PROPERTY_TYPE_BOOLEAN, 60 | } PropertyType; 61 | 62 | /** @brief Type of access to property */ 63 | typedef enum { 64 | ACCESS_TYPE_WRITE = 0, 65 | ACCESS_TYPE_WRITE_INIT, /**< Writable only during init */ 66 | ACCESS_TYPE_READ, 67 | ACCESS_TYPE_RW, 68 | ACCESS_TYPE_USER, /**< Means ACCESS_TYPE_WRITE_INIT + show in XML */ 69 | } AccessType; 70 | 71 | /** @brief Property information structure */ 72 | typedef struct { 73 | const char* name; /**< Name of property */ 74 | PropertyType type; /**< Type of property */ 75 | const char* description; /**< Description of property */ 76 | const char* defval; /**< Default value of property */ 77 | const char* values; /**< List of supported values or range if numeric type */ 78 | int minOccurs; /**< Minimal required number of occurrences */ 79 | int maxOccurs; /**< Maximal supported number of occurrences */ 80 | AccessType access; /**< Type of access to property */ 81 | } PropertyInfo; 82 | 83 | /** @brief Set of properties to init */ 84 | typedef struct { 85 | const Property* properties; /**< Pointer to array of properties */ 86 | size_t count; /**< Number of properties in array */ 87 | } InitParams; 88 | 89 | #ifdef __cplusplus 90 | #ifdef WIN32 91 | #ifdef __GNUC__ 92 | #define DLB_EXPORT extern "C" __attribute__((dllexport)) 93 | #else 94 | #define DLB_EXPORT extern "C" __declspec(dllexport) 95 | #endif 96 | #else 97 | #ifdef __GNUC__ 98 | #define DLB_EXPORT extern "C" __attribute__((visibility("default"))) 99 | #else 100 | #define DLB_EXPORT extern "C" 101 | #endif 102 | #endif 103 | #else 104 | #ifdef WIN32 105 | #ifdef __GNUC__ 106 | #define DLB_EXPORT __attribute__((dllexport)) 107 | #else 108 | #define DLB_EXPORT __declspec(dllexport) 109 | #endif 110 | #else 111 | #ifdef __GNUC__ 112 | #define DLB_EXPORT __attribute__((visibility("default"))) 113 | #else 114 | #define DLB_EXPORT 115 | #endif 116 | #endif 117 | #endif 118 | 119 | #endif /* __DEE_PLUGINS_COMMON_H__ */ 120 | -------------------------------------------------------------------------------- /plugins/code/image_transformer/dummy/src/image_transformer_dummy.cpp: -------------------------------------------------------------------------------- 1 | #include "image_transformer_api.h" 2 | 3 | #include 4 | 5 | static const PropertyInfo img_transformer_info[] = { 6 | { "string_param", PROPERTY_TYPE_STRING, "Dummy string parameter.", NULL, NULL, 0, 1, ACCESS_TYPE_USER}, 7 | { "int_param", PROPERTY_TYPE_INTEGER, "Dummy int parameter.", "-1", "0:10", 0, 1, ACCESS_TYPE_USER}, 8 | { "count_frames", PROPERTY_TYPE_BOOLEAN, "Count the number of frames processed by the plugin.", "false", "true:1:false:0", 0, 1, ACCESS_TYPE_USER} 9 | }; 10 | 11 | static size_t img_transformer_dummy_get_info(const PropertyInfo** info) { 12 | *info = img_transformer_info; 13 | return sizeof(img_transformer_info) / sizeof(PropertyInfo); 14 | } 15 | 16 | struct img_transformer_dummy_data_t { 17 | std::string stringParam; 18 | int intParam{-1}; 19 | int frameCount{0}; 20 | bool countFrames{false}; 21 | std::string msg; 22 | }; 23 | 24 | /* This structure can contain only pointers and simple types */ 25 | struct img_transformer_dummy_t{ 26 | img_transformer_dummy_data_t* data; 27 | }; 28 | 29 | static size_t img_transformer_dummy_get_size() { 30 | return sizeof(img_transformer_dummy_t); 31 | } 32 | 33 | static Status img_transformer_dummy_init(ImgTransformerHandle handle, const ImgTransformerInitParams* init_params) { 34 | img_transformer_dummy_t* state = (img_transformer_dummy_t*)handle; 35 | state->data = new img_transformer_dummy_data_t; 36 | auto invalidValue = [&](const std::string& option, const std::string& value, const std::string& expectedValues) { 37 | return "Invalid '"+option+"' option value: '"+value+"'. Expected value: "+expectedValues+"."; 38 | }; 39 | for (int i = 0; i < (int)init_params->count; i++){ 40 | std::string name(init_params->properties[i].name); 41 | std::string value(init_params->properties[i].value); 42 | if (name == "string_param") { 43 | state->data->stringParam = value; 44 | } else if (name == "int_param") { 45 | state->data->intParam = std::atoi(value.c_str()); 46 | } else if(name == "count_frames") { 47 | if(value == "true" || value == "1") 48 | state->data->countFrames = true; 49 | else if (value == "false" || value == "0") 50 | state->data->countFrames = false; 51 | else { 52 | state->data->msg = invalidValue(name, value, "true:1:false:0"); 53 | return STATUS_ERROR; 54 | } 55 | } else { 56 | state->data->msg = "Could not recognise option '" + name +"'."; 57 | return STATUS_ERROR; 58 | } 59 | } 60 | return STATUS_OK; 61 | } 62 | 63 | static Status img_transformer_dummy_close(ImgTransformerHandle handle) { 64 | img_transformer_dummy_t* state = (img_transformer_dummy_t*)handle; 65 | if (state && state->data) { 66 | delete state->data; 67 | state->data = nullptr; 68 | } 69 | return STATUS_OK; 70 | } 71 | 72 | static Status img_transformer_dummy_process(ImgTransformerHandle handle, ImgTransformerFrame*) { 73 | img_transformer_dummy_t* state = (img_transformer_dummy_t*)handle; 74 | state->data->msg = ""; 75 | if(state->data->intParam >= 0) 76 | state->data->msg += "\nImage transformer dummy int param: " + std::to_string(state->data->intParam); 77 | if(!state->data->stringParam.empty()) 78 | state->data->msg += "\nImage transformer dummy string param: " + state->data->stringParam; 79 | if(state->data->countFrames) 80 | state->data->msg += "\nImage transformer frame count: " + std::to_string(++state->data->frameCount); 81 | 82 | return STATUS_OK; 83 | } 84 | 85 | static const char* img_transformer_dummy_get_message(ImgTransformerHandle handle) { 86 | img_transformer_dummy_t* state = (img_transformer_dummy_t*)handle; 87 | if (state && state->data) 88 | return state->data->msg.empty() ? NULL : state->data->msg.c_str(); 89 | else 90 | return NULL; 91 | } 92 | 93 | static ImgTransformerApi img_transformer_dummy_plugin_api = {"dummy", 94 | img_transformer_dummy_get_info, 95 | img_transformer_dummy_get_size, 96 | img_transformer_dummy_init, 97 | img_transformer_dummy_close, 98 | img_transformer_dummy_process, 99 | img_transformer_dummy_get_message}; 100 | 101 | DLB_EXPORT 102 | ImgTransformerApi* imgTransformerGetApi() { 103 | return &img_transformer_dummy_plugin_api; 104 | } 105 | 106 | DLB_EXPORT 107 | int imgTransformerGetApiVersion(void) { 108 | return IMG_TRANSFORMER_API_VERSION; 109 | } 110 | -------------------------------------------------------------------------------- /plugins/code/api/j2k_dec/j2k_dec_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_J2K_DEC_API_H__ 34 | #define __DEE_PLUGINS_J2K_DEC_API_H__ 35 | 36 | #include "plugins_common.h" 37 | 38 | #define J2K_DEC_API_VERSION 2 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Framework sets/gets following properties. Each j2k_dec plugin should handle them. 45 | * PROPERTY : TYPE : VALUES : WHERE : COMMENT 46 | * ----------------------------------------------------------------------------- 47 | * width : integer : n/a : j2k_dec_init 48 | * height : integer : n/a : j2k_dec_init 49 | * temp_file_num : integer : n/a : j2k_dec_get_property : accessed before j2k_dec_init, optional, should be used if plugin needs some temp files 50 | * temp_file : string : n/a : j2k_dec_init : occurs multiple times, according to value retrieved from 'temp_file_num' 51 | * 52 | * Additionally, j2k_dec_init_params_t structure will contain all plugin-specific properties set via user's configuration (ACCESS_TYPE_USER). 53 | * 54 | */ 55 | 56 | /** @brief Set of properties to init decoder */ 57 | typedef struct { 58 | const Property* properties; /**< Pointer to array of properties */ 59 | size_t count; /**< Number of properties in array */ 60 | } J2kDecInitParams; 61 | 62 | /** @brief j2k_dec input */ 63 | typedef struct { 64 | void* buffer; /**< Pointer to J2K frame */ 65 | size_t size; /**< Size of J2K frame */ 66 | } J2kDecInput; 67 | 68 | /** @brief j2k_dec output */ 69 | typedef struct { 70 | size_t width; /**< Width of decoded picture */ 71 | size_t height; /**< Height of decoded picture */ 72 | void* buffer[3]; /**< Pointers to RGB planes, 16 bits per pixel */ 73 | } J2kDecOutput; 74 | 75 | /** @brief Handle to decoder instance 76 | * j2k_dec_handle_t is actually pointer to decoder context 77 | * defined by plugin's private type. Caller sees that as void*. 78 | */ 79 | typedef void* J2kDecHandle; 80 | 81 | /** @brief Get info about supported properties 82 | * @return Number of properties in info array 83 | */ 84 | typedef size_t (*J2kDecGetInfo)(const PropertyInfo** info); /**< [out] Pointer to array with property information */ 85 | 86 | /** @brief Get size of decoder context 87 | * @return Size in bytes 88 | */ 89 | typedef size_t (*J2kDecGetSize)(void); 90 | 91 | /** @brief Initialize decoder instance 92 | * @return status code 93 | */ 94 | typedef Status (*J2kDecInit)(J2kDecHandle handle, /**< [in/out] Decoder instance handle */ 95 | const J2kDecInitParams* initParams); /**< [in] Properties to init decoder instance */ 96 | 97 | /** @brief Close decoder instance 98 | * @return status code 99 | */ 100 | typedef Status (*J2kDecClose)(J2kDecHandle handle); /**< [in/out] Decoder instance handle */ 101 | 102 | /** @brief Decode j2k picture. Each call must produce decoded picture. 103 | * @return status code 104 | */ 105 | typedef Status (*J2kDecProcess)(J2kDecHandle handle, /**< [in/out] Decoder instance handle */ 106 | const J2kDecInput* in, /**< [in] Encoded input */ 107 | J2kDecOutput* out); /**< [out] Decoded output */ 108 | 109 | /** @brief Property setter 110 | * @return status code 111 | */ 112 | typedef Status (*J2kDecSetProperty)(J2kDecHandle handle, /**< [in/out] Decoder instance handle */ 113 | const Property* property); /**< [in] Property to write */ 114 | 115 | /** @brief Property getter 116 | * @return status code 117 | */ 118 | typedef Status (*J2kDecGetProperty)(J2kDecHandle handle, /**< [in/out] Decoder instance handle */ 119 | Property* property); /**< [in/out] Property to read */ 120 | 121 | /** @brief Get string describing last warning or error occurred 122 | * @return Pointer to string with message 123 | */ 124 | typedef const char* (*J2kDecGetMessage)(J2kDecHandle handle); /**< [in/out] Decoder instance handle */ 125 | 126 | /** @brief Structure with pointers to all API functions */ 127 | typedef struct { 128 | const char* pluginName; 129 | J2kDecGetInfo getInfo; 130 | J2kDecGetSize getSize; 131 | J2kDecInit init; 132 | J2kDecClose close; 133 | J2kDecProcess process; 134 | J2kDecSetProperty setProperty; 135 | J2kDecGetProperty getProperty; 136 | J2kDecGetMessage getMessage; 137 | } J2kDecApi; 138 | 139 | /** @brief Export symbol to access implementation of J2K Decoder plugin 140 | * @return pointer to j2k_dec_api_t 141 | */ 142 | DLB_EXPORT 143 | J2kDecApi* j2kDecGetApi(void); 144 | 145 | /** @brief Definition of pointer to j2kDecGetApi function */ 146 | typedef J2kDecApi* (*J2kDecGetApi)(void); 147 | 148 | /** @brief Export symbol to access API version of j2k decoder plugin 149 | * @return integer representing API version 150 | */ 151 | DLB_EXPORT 152 | int j2kDecGetApiVersion(void); 153 | 154 | /** @brief Definition of pointer to j2kDecGetApiVersion function */ 155 | typedef int (*J2kDecGetApiVersion)(void); 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | 161 | #endif // __DEE_PLUGINS_J2K_DEC_API_H__ 162 | -------------------------------------------------------------------------------- /plugins/code/api/prores_dec/prores_dec_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2018-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_PRORES_DEC_API_H__ 34 | #define __DEE_PLUGINS_PRORES_DEC_API_H__ 35 | 36 | #include "plugins_common.h" 37 | #include 38 | 39 | #define PRORES_DEC_API_VERSION 3 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Framework sets/gets following properties. Each prores_dec plugin should handle them. 46 | * PROPERTY : TYPE : VALUES : WHERE : COMMENT 47 | * ----------------------------------------------------------------------------- 48 | * width : integer : n/a : prores_dec_init 49 | * height : integer : n/a : prores_dec_init 50 | * codec : string : "ap4h:ap4x:apch:apcn:apco:apcs" : prores_dec_init : codec type of the input PRORES frames 51 | * output_format : string : "yuv422p16le:rgb48le" : prores_dec_init : desired format of decoded data 52 | * 53 | * Additionally, prores_dec_init_params_t structure will contain all plugin-specific properties set via user's configuration (ACCESS_TYPE_USER). 54 | * 55 | */ 56 | 57 | 58 | /** @brief Set of properties to init decoder */ 59 | typedef struct { 60 | const Property* properties; /**< Pointer to array of properties */ 61 | int count; /**< Number of properties in array */ 62 | } ProresDecInitParams; 63 | 64 | /** @brief prores_dec input */ 65 | typedef struct { 66 | void* buffer; /**< Pointer to PRORES frame */ 67 | uint64_t size; /**< Size of PRORES frame */ 68 | } ProresDecInput; 69 | 70 | /** @brief prores_dec output */ 71 | typedef struct { 72 | void* buffer; /**< Pointer to decoded frame */ 73 | uint64_t size; /**< Size of decoded frame */ 74 | } ProresDecOutput; 75 | 76 | /** @brief Handle to decoder instance 77 | * prores_dec_handle_t is actually pointer to decoder context 78 | * defined by plugin's private type. Caller sees that as void*. 79 | */ 80 | typedef void* ProresDecHandle; 81 | 82 | /** @brief Get info about supported properties 83 | * @param info Pointer to array with property information 84 | * @return Number of properties in info array 85 | */ 86 | typedef int (*ProresDecGetInfo)(const PropertyInfo** info); 87 | 88 | /** @brief Create decoder instance 89 | * @param handle Decoder instance handle 90 | * @return status code 91 | */ 92 | typedef Status (*ProresDecCreate)(ProresDecHandle* handle); 93 | 94 | /** @brief Initialize decoder instance 95 | * @param handle Decoder instance handle 96 | * @param initParams Properties to init decoder instance 97 | * @return status code 98 | */ 99 | typedef Status (*ProresDecInit)(ProresDecHandle handle, const ProresDecInitParams* initParams); 100 | 101 | /** @brief Close decoder instance 102 | * @param handle Decoder instance handle 103 | * @return status code 104 | */ 105 | typedef Status (*ProresDecClose)(ProresDecHandle handle); 106 | 107 | /** @brief Decode prores picture. Each call must produce decoded picture. 108 | * @param handle Decoder instance handle 109 | * @param in Encoded input 110 | * @param out Decoded output 111 | * @return status code 112 | */ 113 | typedef Status (*ProresDecProcess)(ProresDecHandle handle, const ProresDecInput* in, ProresDecOutput* out); 114 | 115 | /** @brief Property setter 116 | * @param handle Decoder instance handle 117 | * @param property Property to write 118 | * @return status code 119 | */ 120 | typedef Status (*ProresDecSetProperty)(ProresDecHandle handle, const Property* property); 121 | 122 | /** @brief Property getter 123 | * @param handle Decoder instance handle 124 | * @param property Property to read 125 | * @return status code 126 | */ 127 | typedef Status (*ProresDecGetProperty)(ProresDecHandle handle, Property* property); 128 | 129 | /** @brief Get string describing last warning or error occurred 130 | * @param handle Decoder instance handle 131 | * @return Pointer to string with message 132 | */ 133 | typedef const char* (*ProresDecGetMessage)(ProresDecHandle handle); 134 | 135 | /** @brief Structure with pointers to all API functions */ 136 | typedef struct { 137 | const char* pluginName; 138 | ProresDecGetInfo getInfo; 139 | ProresDecCreate create; 140 | ProresDecInit init; 141 | ProresDecClose close; 142 | ProresDecProcess process; 143 | ProresDecSetProperty setProperty; 144 | ProresDecGetProperty getProperty; 145 | ProresDecGetMessage getMessage; 146 | } ProresDecApi; 147 | 148 | /** @brief Export symbol to access implementation of PRORES Decoder plugin 149 | * @return pointer to prores_dec_api_t 150 | */ 151 | DLB_EXPORT 152 | ProresDecApi* proresDecGetApi(void); 153 | 154 | /** @brief Definition of pointer to proresDecGetApi function */ 155 | typedef ProresDecApi* (*ProresDecGetApi)(void); 156 | 157 | /** @brief Export symbol to access API version of PRORES Decoder plugin 158 | * @return integer representing API version 159 | */ 160 | DLB_EXPORT 161 | int proresDecGetApiVersion(void); 162 | 163 | /** @brief Definition of pointer to proresDecGetApiVersion function */ 164 | typedef int (*ProresDecGetApiVersion)(void); 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif // __DEE_PLUGINS_PRORES_DEC_API_H__ 171 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/src/hevc_enc_x265_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_HEVC_ENC_X265_UTILS_H__ 34 | #define __DEE_PLUGINS_HEVC_ENC_X265_UTILS_H__ 35 | 36 | #include "hevc_enc_api.h" 37 | #include "x265.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | typedef struct 48 | { 49 | HevcEncNalType type; 50 | std::vector payload; 51 | } nalu_t; 52 | 53 | typedef struct 54 | { 55 | std::string msg; 56 | bool pending_header; 57 | bool info; 58 | size_t max_output_data; 59 | int bit_depth; 60 | int width; 61 | int height; 62 | std::string profile; 63 | std::string color_space; 64 | std::string frame_rate; 65 | std::string multi_pass; 66 | std::string stats_file; 67 | int data_rate; 68 | int max_vbv_data_rate; 69 | int vbv_buffer_size; 70 | std::string preset; 71 | std::string tune; 72 | bool open_gop; 73 | int max_intra_period; 74 | int min_intra_period; 75 | bool intra_refresh; 76 | int max_bframes; 77 | int lookahead_frames; 78 | int frame_threads; 79 | int nr_inter; 80 | int nr_intra; 81 | int cbqpoffs; 82 | int crqpoffs; 83 | std::string range; 84 | int scenecut; 85 | int scenecut_bias; 86 | int min_cu_size; 87 | int max_cu_size; 88 | int qg_size; 89 | bool rc_grain; 90 | 91 | std::string color_primaries; 92 | std::string transfer_characteristics; 93 | std::string matrix_coefficients; 94 | std::string chromaSampleLocation; 95 | 96 | // master-display 97 | bool mastering_display_enabled; 98 | int mastering_display_sei_x1; 99 | int mastering_display_sei_y1; 100 | int mastering_display_sei_x2; 101 | int mastering_display_sei_y2; 102 | int mastering_display_sei_x3; 103 | int mastering_display_sei_y3; 104 | int mastering_display_sei_wx; 105 | int mastering_display_sei_wy; 106 | int mastering_display_sei_max_lum; 107 | int mastering_display_sei_min_lum; 108 | 109 | // max-cll 110 | bool light_level_enabled; 111 | int light_level_max_content; 112 | int light_level_max_frame_average; 113 | 114 | bool force_slice_type; 115 | bool uhd_bd; 116 | bool concatenation_flag; 117 | 118 | std::string level_idc; 119 | std::string psy_rd; 120 | bool wpp; 121 | std::vector output_buffer; 122 | std::vector::iterator last_used_nal; 123 | std::vector output; 124 | std::list> internal_params; 125 | 126 | } hevc_enc_x265_data_t; 127 | 128 | /* This structure can contain only pointers and simple types */ 129 | typedef struct 130 | { 131 | 132 | const x265_api* api; 133 | x265_param* param; 134 | x265_encoder* encoder; 135 | hevc_enc_x265_data_t* data; 136 | bool lib_initialized; 137 | } hevc_enc_x265_t; 138 | 139 | void 140 | init_defaults 141 | (hevc_enc_x265_t* state); 142 | 143 | bool 144 | parse_init_params 145 | (hevc_enc_x265_t* state 146 | ,const HevcEncInitParams* init_params); 147 | 148 | bool 149 | set_param 150 | (hevc_enc_x265_t* state 151 | ,const std::string& name 152 | ,const std::string& value); 153 | 154 | bool 155 | set_preset 156 | (hevc_enc_x265_t* state 157 | ,const std::string& preset 158 | ,const std::string& tune); 159 | 160 | HevcEncNalType 161 | cast_nal_type 162 | (const uint32_t type); 163 | 164 | int 165 | get_color_prim_number 166 | (std::string); 167 | 168 | int 169 | get_transfer_characteristics_number 170 | (std::string); 171 | 172 | int 173 | get_matrix_coefficients_number 174 | (std::string); 175 | 176 | void 177 | get_config_msg 178 | (hevc_enc_x265_t* state 179 | ,std::list>& native_params 180 | ,std::string& msg); 181 | 182 | int 183 | frametype_to_slicetype 184 | (HevcEncFrameType in_type); 185 | 186 | bool 187 | filter_native_params 188 | (hevc_enc_x265_t* state 189 | ,std::list>& params); 190 | 191 | std::pair 192 | fps_to_num_denom 193 | (const std::string& fps); 194 | 195 | #endif // __DEE_PLUGINS_HEVC_ENC_X265_UTILS_H__ 196 | -------------------------------------------------------------------------------- /plugins/code/common/Debugger/plugins_debugger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_DEBUGGER_H__ 34 | #define __DEE_PLUGINS_DEBUGGER_H__ 35 | 36 | void prologue(void* pCtx, const char* func, const char* vaargs, const char* parent, unsigned int line); 37 | 38 | template 39 | void epilogue( 40 | void* pCtx, const char* func, const char* vaargs, const char* parent, unsigned int line, RetvalType retval); 41 | 42 | // With args 43 | #define FUNCTION(func, ...) \ 44 | prologue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 45 | func(__VA_ARGS__); \ 46 | epilogue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, nullptr); 47 | 48 | #define FUNCTION_RETVALA(retval, func, ...) \ 49 | prologue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 50 | auto retval = func(__VA_ARGS__); \ 51 | epilogue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 52 | 53 | #define FUNCTION_RETVAL(retval, func, ...) \ 54 | prologue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 55 | retval = func(__VA_ARGS__); \ 56 | epilogue(nullptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 57 | 58 | #define FUNCTION_T(func, ...) \ 59 | prologue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 60 | func(__VA_ARGS__); \ 61 | epilogue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, nullptr); 62 | 63 | #define FUNCTION_T_RETVALA(retval, func, ...) \ 64 | prologue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 65 | auto retval = func(__VA_ARGS__); \ 66 | epilogue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 67 | 68 | #define FUNCTION_T_RETVAL(retval, func, ...) \ 69 | prologue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 70 | retval = func(__VA_ARGS__); \ 71 | epilogue(this, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 72 | 73 | #define FUNCTION_P(ptr, func, ...) \ 74 | prologue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 75 | func(__VA_ARGS__); \ 76 | epilogue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, nullptr); 77 | 78 | #define FUNCTION_P_RETVALA(ptr, retval, func, ...) \ 79 | prologue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 80 | auto retval = func(__VA_ARGS__); \ 81 | epilogue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 82 | 83 | #define FUNCTION_P_RETVAL(ptr, retval, func, ...) \ 84 | prologue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__); \ 85 | retval = func(__VA_ARGS__); \ 86 | epilogue(ptr, #func, #__VA_ARGS__, __FUNCTION__, __LINE__, retval); 87 | 88 | // Without without 89 | #define FUNCTIONV(func) \ 90 | prologue(nullptr, #func, "", __FUNCTION__, __LINE__); \ 91 | func(); \ 92 | epilogue(nullptr, #func, "", __FUNCTION__, __LINE__, nullptr); 93 | 94 | #define FUNCTIONV_RETVALA(retval, func) \ 95 | prologue(nullptr, #func, "", __FUNCTION__, __LINE__); \ 96 | auto retval = func(); \ 97 | epilogue(nullptr, #func, "", __FUNCTION__, __LINE__, retval); 98 | 99 | #define FUNCTIONV_RETVAL(retval, func) \ 100 | prologue(nullptr, #func, "", __FUNCTION__, __LINE__); \ 101 | retval = func(); \ 102 | epilogue(nullptr, #func, "", __FUNCTION__, __LINE__, retval); 103 | 104 | #define FUNCTIONV_T(func) \ 105 | prologue(this, #func, "", __FUNCTION__, __LINE__); \ 106 | func(); \ 107 | epilogue(this, #func, "", __FUNCTION__, __LINE__, nullptr); 108 | 109 | #define FUNCTIONV_T_RETVALA(retval, func) \ 110 | prologue(this, #func, "", __FUNCTION__, __LINE__); \ 111 | auto retval = func(); \ 112 | epilogue(this, #func, "", __FUNCTION__, __LINE__, retval); 113 | 114 | #define FUNCTIONV_T_RETVAL(retval, func) \ 115 | prologue(this, #func, "", __FUNCTION__, __LINE__); \ 116 | retval = func(); \ 117 | epilogue(this, #func, "", __FUNCTION__, __LINE__, retval); 118 | 119 | #define FUNCTIONV_P(ptr, func) \ 120 | prologue(ptr, #func, "", __FUNCTION__, __LINE__); \ 121 | func(); \ 122 | epilogue(ptr, #func, "", __FUNCTION__, __LINE__, nullptr); 123 | 124 | #define FUNCTIONV_P_RETVALA(ptr, retval, func) \ 125 | prologue(ptr, #func, "", __FUNCTION__, __LINE__); \ 126 | auto retval = func(); \ 127 | epilogue(ptr, #func, "", __FUNCTION__, __LINE__, retval); 128 | 129 | #define FUNCTIONV_P_RETVAL(ptr, retval, func) \ 130 | prologue(ptr, #func, "", __FUNCTION__, __LINE__); \ 131 | retval = func(); \ 132 | epilogue(ptr, #func, "", __FUNCTION__, __LINE__, retval); 133 | 134 | #endif //__DEE_PLUGINS_DEBUGGER_H__ 135 | -------------------------------------------------------------------------------- /plugins/code/api/image_transformer/image_transformer_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_IMG_TRANSFORMER_API_H__ 34 | #define __DEE_PLUGINS_IMG_TRANSFORMER_API_H__ 35 | 36 | #include "plugins_common.h" 37 | #include 38 | #define IMG_TRANSFORMER_API_VERSION 1 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef enum { 45 | PLANAR = 0, 46 | INTERLEAVED 47 | }ImgTransformerArrangement; 48 | 49 | typedef enum { 50 | FORMAT_UNKNOWN = 0, 51 | FORMAT_RAW, 52 | FORMAT_JPEG2000, 53 | FORMAT_PRORES, 54 | FORMAT_TIFF, 55 | }ImgTransformerFormat; 56 | 57 | typedef enum { 58 | CODEC_UNSPECIFIED = 0, 59 | CODEC_JPEG2000, 60 | CODEC_PRORES_APCH, 61 | CODEC_PRORES_APCN, 62 | CODEC_PRORES_APCS, 63 | CODEC_PRORES_APCO, 64 | CODEC_PRORES_AP4H, 65 | CODEC_PRORES_AP4X, 66 | CODEC_TIFF, 67 | CODEC_NONE, 68 | }ImgTransformerCodec; 69 | 70 | typedef enum { 71 | CHROMA_UNKNOWN = 0, 72 | CHROMA_ACES, /**< Academy Color Encoding Space primaries */ 73 | CHROMA_DCI, /**< DCI P3 primaries with 0.314, 0.351 white */ 74 | CHROMA_P3D65, /**< Standard Pulsar display space */ 75 | CHROMA_REC709, /**< RGB, primaries / white per Rec. 709 */ 76 | CHROMA_REC2020 /**< RGB, primaries / white per Rec. 2020 */ 77 | }ImgTransformerChroma; 78 | 79 | typedef enum { 80 | COLOR_SPACE_UNKNOWN = 0, 81 | COLOR_SPACE_RGB, /**< RGB */ 82 | COLOR_SPACE_REC709_YUV, /**< Y'U'V' per Rec. 709 */ 83 | COLOR_SPACE_REC2020_YUV, /**< Y'U'V' per Rec. 2020 */ 84 | COLOR_SPACE_IPTc2 /**< Proposed mobile representation */ 85 | }ImgTransformerColorspace; 86 | 87 | typedef enum { 88 | EOTF_UNKNOWN = 0, 89 | EOTF_PQ, /**< PQ encoding */ 90 | EOTF_BT1886, /**< Rec. BT1886 gamma */ 91 | EOTF_REC709, /**< Rec. 709 gamma with linear section at bottom */ 92 | EOTF_HLG, 93 | }ImgTransformerEotf; 94 | 95 | typedef enum { 96 | RANGE_UNKNOWN = 0, 97 | RANGE_COMPUTER, /**< Computer or full range, 0 thru (2^bits - 1)) */ 98 | RANGE_SDI, /**< SMPTE SDI valid range (16 thru (2^bits - 17)) */ 99 | RANGE_LEGAL /**< SMPTE SDI valid range, scale = 2^(bits - 8), 16*scale thru 235*scale for luma / 240*scale for chroma */ 100 | }ImgTransformerRange; 101 | 102 | typedef enum { 103 | BIT_DEPTH_UNKNOWN = 0, 104 | BIT_DEPTH_UINT8, /**< 8 bits per color */ 105 | BIT_DEPTH_UINT10_LSB, /**< 10 lower bits of 16 (0 - 1023) */ 106 | BIT_DEPTH_UINT12_LSB, /**< 12 lower bits of 16 (0 - 4095) */ 107 | BIT_DEPTH_UINT14_LSB, /**< 14 lower bits of 16 (0 - 16383) */ 108 | BIT_DEPTH_UINT16 /**< 16 bits per color */ 109 | }ImgTransformerBitdepth; 110 | 111 | typedef enum { 112 | SUBSAMPLING_S444 = 0, 113 | SUBSAMPLING_S422, 114 | SUBSAMPLING_S420, 115 | }ImgTransformerSubsampling; 116 | 117 | typedef struct { 118 | int64_t numerator; 119 | int64_t denominator; 120 | }ImgTransformerPts; 121 | 122 | typedef struct { 123 | int64_t top; 124 | int64_t bottom; 125 | int64_t left; 126 | int64_t right; 127 | } ImgTransformerLetterbox; 128 | 129 | typedef struct { 130 | double cfr; 131 | int64_t start; 132 | int64_t duration; 133 | int64_t preroll; 134 | int64_t postroll; 135 | }ImgTransformerProgram; 136 | 137 | typedef struct { 138 | uint8_t* buffer; 139 | // int64_t bufferSize; 140 | int64_t size; 141 | } ImgTransformerData; 142 | 143 | typedef struct { 144 | char* metadataFilename; 145 | int64_t metadataPosition; 146 | ImgTransformerFormat format; 147 | ImgTransformerCodec codec; 148 | ImgTransformerProgram program; 149 | int64_t width; 150 | int64_t height; 151 | ImgTransformerSubsampling subsampling; 152 | ImgTransformerBitdepth bitdepth; 153 | ImgTransformerChroma chroma; 154 | ImgTransformerColorspace colorspace; 155 | ImgTransformerEotf eotf; 156 | ImgTransformerRange range; 157 | ImgTransformerLetterbox letterbox; 158 | ImgTransformerPts pts; 159 | ImgTransformerArrangement arrangement; 160 | } ImgTransformerMetadata; 161 | 162 | typedef struct { 163 | ImgTransformerMetadata metadata; 164 | ImgTransformerData data; 165 | } ImgTransformerFrame; 166 | 167 | typedef struct { 168 | const Property* properties; 169 | size_t count; 170 | } ImgTransformerInitParams; 171 | 172 | typedef void* ImgTransformerHandle; 173 | 174 | typedef size_t (*ImgTransformerGetInfo)(const PropertyInfo** info); 175 | 176 | typedef size_t (*ImgTransformerGetSize)(); 177 | 178 | typedef Status (*ImgTransformerInit)(ImgTransformerHandle handle, const ImgTransformerInitParams* initParams); 179 | 180 | typedef Status (*ImgTransformerClose)(ImgTransformerHandle handle); 181 | 182 | typedef Status (*ImgTransformerProcess) (ImgTransformerHandle handle, ImgTransformerFrame* inFrame); 183 | 184 | typedef const char* (*ImgTransformerGetMessage)(ImgTransformerHandle handle); 185 | 186 | typedef struct { 187 | const char* pluginName; 188 | ImgTransformerGetInfo getInfo; 189 | ImgTransformerGetSize getSize; 190 | ImgTransformerInit init; 191 | ImgTransformerClose close; 192 | ImgTransformerProcess process; 193 | ImgTransformerGetMessage getMessage; 194 | } ImgTransformerApi; 195 | 196 | DLB_EXPORT 197 | ImgTransformerApi* imgTransformerGetApi(); 198 | 199 | typedef ImgTransformerApi* (*ImgTransformerGetApi)(); 200 | 201 | DLB_EXPORT 202 | int imgTransformerGetApiVersion(void); 203 | 204 | typedef int (*ImgTransformerGetApiVersion)(void); 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif // __DLB_PLUGINS_MP4_MUX_API_H__ -------------------------------------------------------------------------------- /plugins/code/api/tiff_dec/tiff_dec_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_TIFF_DEC_API_H__ 34 | #define __DEE_PLUGINS_TIFF_DEC_API_H__ 35 | 36 | #include "plugins_common.h" 37 | 38 | #define TIFF_DEC_API_VERSION 1 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Framework sets/gets following properties. Each tiff_dec plugin should handle them. 45 | * PROPERTY : TYPE : VALUES : WHERE : COMMENT 46 | * ----------------------------------------------------------------------------- 47 | * temp_file_num : integer : n/a : tiff_dec_get_property : accessed before tiff_dec_init, optional, should be used 48 | * if plugin needs some temp files temp_file : string : n/a : tiff_dec_init : occurs multiple times, according to value 49 | * retrieved from 'temp_file_num' 50 | * 51 | * Additionally, tiff_dec_init_params_t structure will contain all plugin-specific properties set via XML interface 52 | * (ACCESS_TYPE_USER). 53 | * 54 | */ 55 | 56 | /** @brief Set of properties to init decoder */ 57 | typedef struct { 58 | const Property* properties; /**< Pointer to array of properties */ 59 | uint64_t count; /**< Number of properties in array */ 60 | } TiffDecInitParams; 61 | 62 | /** @brief tiff_dec input */ 63 | typedef struct { 64 | void* buffer; /**< Pointer to TIFF frame */ 65 | uint64_t size; /**< Size of TIFF frame */ 66 | } TiffDecInput; 67 | 68 | /** @brief Format of output picture. Formats follow ffmpeg convention. */ 69 | typedef enum { 70 | TIFF_FORMAT_RGB48LE = 0, /**< Planar RGB, 16 bits per component. */ 71 | TIFF_FORMAT_YUV444P16LE, /**< Planar YUV 444, 16 bits per component. */ 72 | TIFF_FORMAT_YUV422P16LE, /**< Planar YUV 422, 16 bits per component. */ 73 | TIFF_FORMAT_YUV420P16LE /**< Planar YUV 420, 16 bits per component. */ 74 | } TiffFormat; 75 | 76 | /** @brief tiff_dec output */ 77 | typedef struct { 78 | uint64_t width; /**< Width of decoded picture */ 79 | uint64_t height; /**< Height of decoded picture */ 80 | void* buffer[3]; /**< Pointers to RGB or YUV components. */ 81 | TiffFormat format; /**< Format of output picture. */ 82 | } TiffDecOutput; 83 | 84 | /** @brief Handle to decoder instance 85 | * tiff_dec_handle_t is actually pointer to decoder context 86 | * defined by plugin's private type. Caller sees that as void*. 87 | */ 88 | typedef void* TiffDecHandle; 89 | 90 | /** @brief Get info about supported properties 91 | * @return Number of properties in info array 92 | */ 93 | typedef size_t (*TiffDecGetInfo)(const PropertyInfo** info); /**< [out] Pointer to array with property information */ 94 | 95 | /** @brief Get size of decoder context 96 | * @return Size in bytes 97 | */ 98 | typedef uint64_t (*TiffDecGetSize)(void); 99 | 100 | /** @brief Initialize decoder instance 101 | * @return status code 102 | */ 103 | typedef Status (*TiffDecInit)(TiffDecHandle handle, /**< [in/out] Decoder instance handle */ 104 | const TiffDecInitParams* initParams); /**< [in] Properties to init decoder instance */ 105 | 106 | /** @brief Close decoder instance 107 | * @return status code 108 | */ 109 | typedef Status (*TiffDecClose)(TiffDecHandle handle); /**< [in/out] Decoder instance handle */ 110 | 111 | /** @brief Decode tiff picture. Each call must produce decoded picture. 112 | * @return status code 113 | */ 114 | typedef Status (*TiffDecProcess)(TiffDecHandle handle, /**< [in/out] Decoder instance handle */ 115 | const TiffDecInput* in, /**< [in] Encoded input */ 116 | TiffDecOutput* out); /**< [out] Decoded output */ 117 | 118 | /** @brief Property setter 119 | * @return status code 120 | */ 121 | typedef Status (*TiffDecSetProperty)(TiffDecHandle handle, /**< [in/out] Decoder instance handle */ 122 | const Property* property); /**< [in] Property to write */ 123 | 124 | /** @brief Property getter 125 | * @return status code 126 | */ 127 | typedef Status (*TiffDecGetProperty)(TiffDecHandle handle, /**< [in/out] Decoder instance handle */ 128 | Property* property); /**< [in/out] Property to read */ 129 | 130 | /** @brief Get string describing last warning or error occurred 131 | * @return Pointer to string with message 132 | */ 133 | typedef const char* (*TiffDecGetMessage)(TiffDecHandle handle); /**< [in/out] Decoder instance handle */ 134 | 135 | /** @brief Structure with pointers to all API functions */ 136 | typedef struct { 137 | const char* pluginName; 138 | TiffDecGetInfo getInfo; 139 | TiffDecGetSize getSize; 140 | TiffDecInit init; 141 | TiffDecClose close; 142 | TiffDecProcess process; 143 | TiffDecSetProperty setProperty; 144 | TiffDecGetProperty getProperty; 145 | TiffDecGetMessage getMessage; 146 | } TiffDecApi; 147 | 148 | /** @brief Export symbol to access implementation of TIFF Decoder plugin 149 | * @return pointer to tiff_dec_api_t 150 | */ 151 | DLB_EXPORT 152 | TiffDecApi* tiffDecGetApi(void); 153 | 154 | /** @brief Definition of pointer to tiffDecGetApi function */ 155 | typedef TiffDecApi* (*TiffDecGetApi)(void); 156 | 157 | /** @brief Export symbol to access API version of tiff decoder plugin 158 | * @return integer representing API version 159 | */ 160 | DLB_EXPORT 161 | int tiffDecGetApiVersion(void); 162 | 163 | /** @brief Definition of pointer to tiffDecGetApiVersion function */ 164 | typedef int (*TiffDecGetApiVersion)(void); 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif // __DEE_PLUGINS_TIFF_DEC_API_H__ 171 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/src/hevc_enc_beamr_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_HEVC_ENC_BEAMR_IMPL_H__ 34 | #define __DEE_PLUGINS_HEVC_ENC_BEAMR_IMPL_H__ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "hevc_enc_api.h" 50 | #include "hevc_enc_beamr_utils.h" 51 | 52 | #include "vh3_default_callbacks.h" 53 | #include "vh3_encode.h" 54 | 55 | struct PluginCtrl { 56 | std::string msg; 57 | 58 | std::deque temp_file; 59 | uint64_t max_output_data{0}; 60 | uint8_t bit_depth; 61 | uint16_t width; 62 | uint16_t height; 63 | std::string color_space{"i420"}; 64 | std::string frame_rate; 65 | unsigned int data_rate{15000}; 66 | unsigned int max_vbv_data_rate{15000}; 67 | unsigned int vbv_buffer_size{30000}; 68 | std::string range{"full"}; 69 | std::string multi_pass{"off"}; 70 | std::string stats_file; 71 | std::string color_primaries; 72 | std::string transfer_characteristics; 73 | std::string matrix_coefficients; 74 | int chromaloc{0}; 75 | int64_t mastering_display_sei_x1{-1}; 76 | int64_t mastering_display_sei_y1{-1}; 77 | int64_t mastering_display_sei_x2{-1}; 78 | int64_t mastering_display_sei_y2{-1}; 79 | int64_t mastering_display_sei_x3{-1}; 80 | int64_t mastering_display_sei_y3{-1}; 81 | int64_t mastering_display_sei_wx{-1}; 82 | int64_t mastering_display_sei_wy{-1}; 83 | int64_t mastering_display_sei_max_lum{-1}; 84 | int64_t mastering_display_sei_min_lum{-1}; 85 | int64_t light_level_max_content{-1}; 86 | int64_t light_level_max_frame_average{-1}; 87 | bool force_slice_type{false}; 88 | bool uhd_bd{false}; 89 | std::string preset{"medium"}; 90 | std::string modifier; 91 | uint16_t gop_intra_period{32}; 92 | uint16_t gop_idr_period{1}; 93 | uint8_t gop_min_intra_period{4}; 94 | uint8_t gop_minigop_size{8}; 95 | uint8_t gop_min_minigop_size{8}; 96 | uint8_t gop_max_refs{4}; 97 | uint8_t me_scene_change{0}; 98 | int32_t pps_cb_qp_offset{0}; 99 | int32_t pps_cr_qp_offset{0}; 100 | std::list param; 101 | std::string native_config_file; 102 | std::string gop_structure_in_file; 103 | std::string gop_structure_out_file; 104 | int debug_level{0}; 105 | }; 106 | 107 | // Forward declaration of callback functions 108 | extern "C" { 109 | vh3_rec_send_cb cb_rec_send; 110 | vh3_ms_send_cb cb_ms_send; 111 | vh3_notify_cb cb_notify; 112 | void cb_settings_change(void* ctx, const char* msg); 113 | } 114 | 115 | struct vh3_Nal { 116 | vh3_NalInfo info; 117 | const vh3_MediaSample* ms; 118 | }; 119 | 120 | struct SliceInfo { 121 | int64_t index{-1}; 122 | vh3_SliceType type{VH3_SLICE_UNKNOWN}; 123 | int8_t idr_flag{0}; 124 | }; 125 | 126 | class Encoder { 127 | public: 128 | Encoder(); 129 | virtual ~Encoder(); 130 | std::string getVersion(); 131 | std::string getMessage(); 132 | void init(PluginCtrl& ctrl); 133 | void feed(const HevcEncPicture* in); 134 | void flush(); 135 | void getNal(HevcEncOutput* out, uint64_t maxSize); 136 | void close(); 137 | 138 | int debugLevel{0}; 139 | 140 | protected: 141 | static const size_t MAX_STRING_SIZE{4096}; 142 | std::string version{"Beamr SDK"}; 143 | std::mutex dataLock; 144 | vh3_EncoderHandle hEnc; 145 | hevce_settings_t settings; 146 | std::deque qMS; 147 | std::vector nal; 148 | std::unique_ptr outBufferMem; 149 | uint8_t* outBuffer{nullptr}; 150 | uint64_t outBufferSize{0}; 151 | uint64_t nalUnitsToRelease{0}; 152 | vh3_CallbacksTable_t cbTable; 153 | char stringBuffer[Encoder::MAX_STRING_SIZE + 1]; 154 | std::list pendingErrors; 155 | std::list pendingMsgs; 156 | bool flushing{false}; 157 | bool opened{false}; 158 | int vuiNumUnitsInTick{-1}; 159 | int vuiTimeScale{-1}; 160 | bool useSpsFramerate{false}; 161 | uint64_t frameIndex{0}; 162 | uint64_t recFrameIndex{0}; 163 | std::string dualPassFileName; 164 | std::vector dualPassBuffer; 165 | std::ifstream gopStructureIn; 166 | std::ofstream gopStructureOut; 167 | std::deque slices; 168 | std::deque gopSlices; 169 | 170 | void checkPendingErrors(); 171 | void checkErrorCode(const hevc_error_t errCode); 172 | void message(const char* fmt, ...); 173 | void message(const std::string& s); 174 | void error(const char* fmt, ...); 175 | void readFrame(const HevcEncPicture* in, vh3_Picture* pic); 176 | void releaseNalUnits(); 177 | void parseGopStructureFile(); 178 | void reportSliceInfo(vh3_RecPictureInfo* info); 179 | 180 | hevc_error_t notify(vh3_Notification a); 181 | hevc_error_t recSend(const vh3_Picture* pic, vh3_RecPictureInfo info); 182 | hevc_error_t msSend(const vh3_MediaSample* ms, vh3_NalInfo info); 183 | void settingsChange(const char* msg); 184 | 185 | friend hevc_error_t VSSHSDKAPI cb_notify(void* ctx, vh3_Notification a); 186 | friend hevc_error_t VSSHSDKAPI cb_rec_send(void* ctx, const vh3_Picture* pic, vh3_RecPictureInfo info); 187 | friend hevc_error_t VSSHSDKAPI cb_ms_send(void* ctx, const vh3_MediaSample* ms, vh3_NalInfo info); 188 | friend void cb_settings_change(void* ctx, const char* msg); 189 | 190 | uint32_t modifierValue(const std::string& str); 191 | uint16_t presetValue(const std::string& str); 192 | }; 193 | 194 | /* This structure can contain only pointers and simple types */ 195 | struct PluginContext { 196 | PluginCtrl* ctrl{nullptr}; 197 | Encoder* encoder{nullptr}; 198 | }; 199 | 200 | #endif //__DEE_PLUGINS_HEVC_ENC_BEAMR_IMPL_H__ 201 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/cmake/beamrConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | add_library(beamr::common_primitives INTERFACE IMPORTED) 4 | target_include_directories(beamr::common_primitives 5 | INTERFACE 6 | "$ENV{BEAMR_SDK}/common_primitives/include" 7 | ) 8 | target_sources(beamr::common_primitives 9 | INTERFACE 10 | "$ENV{BEAMR_SDK}/common_primitives/src/AllocationPool.cpp" 11 | "$ENV{BEAMR_SDK}/common_primitives/src/vh3_default_callbacks.cpp" 12 | "$ENV{BEAMR_SDK}/common_primitives/src/vh3_thread_manager.cpp" 13 | ) 14 | 15 | add_library(beamr::common INTERFACE IMPORTED) 16 | target_link_libraries(beamr::common 17 | INTERFACE 18 | beamr::hevc-cmn 19 | beamr::vpl 20 | beamr::vsl 21 | $<$:beamr::ircmt> 22 | $<$:beamr::svml_dispmt> 23 | $<$:beamr::mmt> 24 | $<$:beamr::irc> 25 | $<$:beamr::imf> 26 | $<$:beamr::svml> 27 | beamr::common_primitives 28 | ) 29 | 30 | add_library(beamr::encoder INTERFACE IMPORTED) 31 | target_link_libraries(beamr::encoder 32 | INTERFACE 33 | beamr::hevc-enc 34 | beamr::common 35 | ) 36 | 37 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 38 | if(CMAKE_OSX_ARCHITECTURES) 39 | if ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES) 40 | message(FATAL_ERROR "Building macOS universal binaries is not supported") 41 | elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") 42 | set(MACOS_ARCH "arm64") 43 | elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") 44 | set(MACOS_ARCH "x86_64") 45 | endif() 46 | else() 47 | set(MACOS_ARCH "${CMAKE_SYSTEM_PROCESSOR}") 48 | endif() 49 | 50 | if(MACOS_ARCH STREQUAL "arm64") 51 | set(BEAMR_HEVC_ENC_LIBNAME "libhevc-enc-marm64g.a") 52 | set(BEAMR_HEVC_CMN_LIBNAME "libhevc-cmn-marm64g.a") 53 | set(BEAMR_VPL_LIBNAME "libvpl-marm64g.a") 54 | set(BEAMR_VSL_LIBNAME "libvsl-marm64g.a") 55 | elseif(MACOS_ARCH STREQUAL "x86_64") 56 | set(BEAMR_HEVC_ENC_LIBNAME "libhevc-enc-m64g.a") 57 | set(BEAMR_HEVC_CMN_LIBNAME "libhevc-cmn-m64g.a") 58 | set(BEAMR_VPL_LIBNAME "libvpl-m64g.a") 59 | set(BEAMR_VSL_LIBNAME "libvsl-m64g.a") 60 | else() 61 | message(FATAL_ERROR "Unsupported macOS architecture") 62 | endif() 63 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") 64 | set(BEAMR_HEVC_ENC_LIBNAME "libhevc-enc-w64i-MT.lib") 65 | set(BEAMR_HEVC_CMN_LIBNAME "libhevc-cmn-w64i-MT.lib") 66 | set(BEAMR_VPL_LIBNAME "libvpl-w64i-MT.lib") 67 | set(BEAMR_VSL_LIBNAME "libvsl-w64i-MT.lib") 68 | set(BEAMR_IRCMT_LIBNAME "libircmt.lib") 69 | set(BEAMR_SVML_DISPMT_LIBNAME "svml_dispmt.lib") 70 | set(BEAMR_MMT_LIBNAME "libmmt.lib") 71 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 72 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)") 73 | set(BEAMR_HEVC_ENC_LIBNAME "libhevc-enc-l64i.a") 74 | set(BEAMR_HEVC_CMN_LIBNAME "libhevc-cmn-l64i.a") 75 | set(BEAMR_VPL_LIBNAME "libvpl-l64i.a") 76 | set(BEAMR_VSL_LIBNAME "libvsl-l64i.a") 77 | set(BEAMR_IRC_LIBNAME "libirc.a") 78 | set(BEAMR_IMF_LIBNAME "libimf.a") 79 | set(BEAMR_SVML_LIBNAME "libsvml.a") 80 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)") 81 | set(BEAMR_HEVC_ENC_LIBNAME "libhevc-enc-larm64g.a") 82 | set(BEAMR_HEVC_CMN_LIBNAME "libhevc-cmn-larm64g.a") 83 | set(BEAMR_VPL_LIBNAME "libvpl-larm64g.a") 84 | set(BEAMR_VSL_LIBNAME "libvsl-larm64g.a") 85 | else() 86 | message(FATAL_ERROR "Unsupported linux architecture: ${CMAKE_SYSTEM_PROCESSOR}") 87 | endif() 88 | else() 89 | message(FATAL_ERROR "Not supported OS/architecture") 90 | endif() 91 | 92 | add_library(beamr::hevc-enc STATIC IMPORTED) 93 | set_target_properties(beamr::hevc-enc 94 | PROPERTIES 95 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib/${BEAMR_HEVC_ENC_LIBNAME}" 96 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 97 | ) 98 | target_link_options(beamr::hevc-enc 99 | INTERFACE 100 | "$<$:/NODEFAULTLIB:libirc.lib;/NODEFAULTLIB:svml_disp.lib;/NODEFAULTLIB:libm.lib>" 101 | ) 102 | 103 | add_library(beamr::hevc-cmn STATIC IMPORTED) 104 | set_target_properties(beamr::hevc-cmn 105 | PROPERTIES 106 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib/${BEAMR_HEVC_CMN_LIBNAME}" 107 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 108 | ) 109 | target_link_options(beamr::hevc-cmn 110 | INTERFACE 111 | "$<$:/NODEFAULTLIB:libirc.lib;/NODEFAULTLIB:svml_disp.lib;/NODEFAULTLIB:libm.lib>" 112 | ) 113 | 114 | add_library(beamr::vpl STATIC IMPORTED) 115 | set_target_properties(beamr::vpl 116 | PROPERTIES 117 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib/${BEAMR_VPL_LIBNAME}" 118 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 119 | ) 120 | target_link_options(beamr::vpl 121 | INTERFACE 122 | "$<$:/NODEFAULTLIB:libirc.lib;/NODEFAULTLIB:svml_disp.lib;/NODEFAULTLIB:libm.lib>" 123 | ) 124 | 125 | add_library(beamr::vsl STATIC IMPORTED) 126 | set_target_properties(beamr::vsl 127 | PROPERTIES 128 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib/${BEAMR_VSL_LIBNAME}" 129 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 130 | ) 131 | target_link_options(beamr::vsl 132 | INTERFACE 133 | "$<$:/NODEFAULTLIB:libirc.lib;/NODEFAULTLIB:svml_disp.lib;/NODEFAULTLIB:libm.lib>" 134 | ) 135 | 136 | if(BEAMR_IRCMT_LIBNAME) 137 | add_library(beamr::ircmt STATIC IMPORTED) 138 | set_target_properties(beamr::ircmt 139 | PROPERTIES 140 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_IRCMT_LIBNAME}" 141 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 142 | ) 143 | endif() 144 | 145 | if(BEAMR_SVML_DISPMT_LIBNAME) 146 | add_library(beamr::svml_dispmt STATIC IMPORTED) 147 | set_target_properties(beamr::svml_dispmt 148 | PROPERTIES 149 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_SVML_DISPMT_LIBNAME}" 150 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 151 | ) 152 | endif() 153 | 154 | if(BEAMR_MMT_LIBNAME) 155 | add_library(beamr::mmt STATIC IMPORTED) 156 | set_target_properties(beamr::mmt 157 | PROPERTIES 158 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_MMT_LIBNAME}" 159 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 160 | ) 161 | endif() 162 | 163 | if(BEAMR_IRC_LIBNAME) 164 | add_library(beamr::irc STATIC IMPORTED) 165 | 166 | set_target_properties(beamr::irc 167 | PROPERTIES 168 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_IRC_LIBNAME}" 169 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 170 | ) 171 | endif() 172 | 173 | if(BEAMR_IMF_LIBNAME) 174 | add_library(beamr::imf STATIC IMPORTED) 175 | 176 | set_target_properties(beamr::imf 177 | PROPERTIES 178 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_IMF_LIBNAME}" 179 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 180 | ) 181 | endif() 182 | 183 | if(BEAMR_SVML_LIBNAME) 184 | add_library(beamr::svml STATIC IMPORTED) 185 | 186 | set_target_properties(beamr::svml 187 | PROPERTIES 188 | IMPORTED_LOCATION "$ENV{BEAMR_SDK}/lib64/${BEAMR_SVML_LIBNAME}" 189 | INTERFACE_INCLUDE_DIRECTORIES "$ENV{BEAMR_SDK}/inc" 190 | ) 191 | endif() 192 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/src/hevc_enc_beamr_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "hevc_enc_beamr_utils.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | void split(const std::string& s, const std::string delim, Out result) { 15 | std::stringstream ss; 16 | ss.str(s); 17 | std::string item; 18 | 19 | std::string tempString = s; 20 | for (;;) { 21 | auto pos = tempString.find(delim); 22 | 23 | if (!tempString.substr(0, pos).empty()) 24 | *(result++) = tempString.substr(0, pos); 25 | 26 | if (std::string::npos == pos) 27 | break; 28 | tempString = tempString.substr(pos + delim.size(), std::string::npos); 29 | } 30 | } 31 | 32 | std::vector split(const std::string& s, const std::string& delim) { 33 | std::vector elems; 34 | split(s, delim, std::back_inserter(elems)); 35 | return elems; 36 | } 37 | 38 | int64_t string2int(const std::string& name, const std::string& value, int64_t minValue, int64_t maxValue) { 39 | int64_t ival = std::stoll(value); 40 | if (ival < minValue || ival > maxValue) { 41 | std::string err = "Invalid '" + name + "' value."; 42 | throw std::runtime_error(err); 43 | } 44 | return ival; 45 | } 46 | 47 | bool string2bool(const std::string& name, const std::string& value) { 48 | if (value != "true" && value != "false") { 49 | std::string err = "Invalid '" + name + "' value."; 50 | throw std::runtime_error(err); 51 | } 52 | return (value == "true"); 53 | } 54 | 55 | int64_t parseInt(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count) { 56 | for (size_t i = 0; i < count; i++) { 57 | if (name == std::string(schema[i].name)) { 58 | int64_t minVal = std::numeric_limits::min(); 59 | int64_t maxVal = std::numeric_limits::max(); 60 | if (schema[i].values) { 61 | auto tok = split(std::string(schema[i].values), ":"); 62 | minVal = std::stoi(tok[0]); 63 | if (tok.size() > 1) 64 | maxVal = std::stoi(tok[1]); 65 | } 66 | return string2int(name, value, minVal, maxVal); 67 | } 68 | } 69 | throw std::runtime_error("Unknown property: " + name); 70 | } 71 | 72 | std::string parseString(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count) { 73 | for (size_t i = 0; i < count; i++) { 74 | if (name == std::string(schema[i].name)) { 75 | if (schema[i].values) { 76 | auto tok = split(std::string(schema[i].values), ":"); 77 | if (std::find(tok.begin(), tok.end(), value) == tok.end()) { 78 | std::string err = "Invalid '" + name + "' value."; 79 | throw std::runtime_error(err); 80 | } 81 | } 82 | return value; 83 | } 84 | } 85 | throw std::runtime_error("Unknown property: " + name); 86 | } 87 | 88 | std::string parseStringList(const std::string& name, 89 | const std::string& value, 90 | const std::string& listDelim, 91 | const std::string& enums) { 92 | auto tok = split(std::string(enums), ":"); 93 | auto items = split(value, listDelim); 94 | for (auto& item : items) { 95 | if (std::find(tok.begin(), tok.end(), item) == tok.end()) { 96 | std::string err = "Invalid '" + name + "' value (" + item + ")."; 97 | throw std::runtime_error(err); 98 | } 99 | } 100 | return value; 101 | } 102 | 103 | bool parseBool(const std::string& name, const std::string& value, const PropertyInfo* schema, size_t count) { 104 | for (size_t i = 0; i < count; i++) { 105 | if (name == std::string(schema[i].name)) { 106 | return string2bool(name, value); 107 | } 108 | } 109 | throw std::runtime_error("Unknown property: " + name); 110 | } 111 | 112 | FramePeriod string2FramePeriod(const std::string& s) { 113 | FramePeriod fp; 114 | memset(&fp, 0, sizeof(fp)); 115 | if ("23.976" == s) { 116 | fp.timeScale = 24000; 117 | fp.numUnitsInTick = 1001; 118 | } 119 | else if ("24" == s) { 120 | fp.timeScale = 24; 121 | fp.numUnitsInTick = 1; 122 | } 123 | else if ("25" == s) { 124 | fp.timeScale = 25; 125 | fp.numUnitsInTick = 1; 126 | } 127 | else if ("29.97" == s) { 128 | fp.timeScale = 30000; 129 | fp.numUnitsInTick = 1001; 130 | } 131 | else if ("30" == s) { 132 | fp.timeScale = 30; 133 | fp.numUnitsInTick = 1; 134 | } 135 | else if ("48" == s) { 136 | fp.timeScale = 48; 137 | fp.numUnitsInTick = 1; 138 | } 139 | else if ("50" == s) { 140 | fp.timeScale = 50; 141 | fp.numUnitsInTick = 1; 142 | } 143 | else if ("59.94" == s) { 144 | fp.timeScale = 60000; 145 | fp.numUnitsInTick = 1001; 146 | } 147 | else if ("60" == s) { 148 | fp.timeScale = 60; 149 | fp.numUnitsInTick = 1; 150 | } 151 | else if ("119.88" == s) { 152 | fp.timeScale = 120000; 153 | fp.numUnitsInTick = 1001; 154 | } 155 | else if ("120" == s) { 156 | fp.timeScale = 120; 157 | fp.numUnitsInTick = 1; 158 | } 159 | return fp; 160 | } 161 | 162 | static std::map color_primaries_map = { 163 | {"bt_709", 1}, {"unspecified", 2}, {"bt_601_625", 5}, {"bt_601_525", 6}, {"bt_2020", 9}, 164 | }; 165 | 166 | static std::map transfer_characteristics_map = { 167 | {"bt_709", 1}, {"unspecified", 2}, {"bt_601_625", 4}, {"bt_601_525", 6}, {"smpte_st_2084", 16}, {"std_b67", 18}, 168 | }; 169 | 170 | static std::map matrix_coefficients_map = { 171 | {"bt_709", 1}, {"unspecified", 2}, {"bt_601_625", 4}, {"bt_601_525", 6}, {"bt_2020", 9}, 172 | }; 173 | 174 | int color_primaries2int(const std::string& s) { 175 | return color_primaries_map[s]; 176 | } 177 | int transfer_characteristics2int(const std::string& s) { 178 | return transfer_characteristics_map[s]; 179 | } 180 | int matrix_coefficients2int(const std::string& s) { 181 | return matrix_coefficients_map[s]; 182 | } 183 | 184 | #ifdef WIN32 185 | static const std::string dirSeparator = "\\"; 186 | #else 187 | static const std::string dirSeparator = "/"; 188 | #endif 189 | 190 | std::string abspath(const std::string& path, const std::string& head) { 191 | bool isAbsolute = false; 192 | if (path.size()) { 193 | #ifdef WIN32 194 | if (path.size() > 2) { 195 | char d = path[0]; 196 | char c = path[1]; 197 | char s = path[2]; 198 | isAbsolute = (':' == c && dirSeparator[0] == s && ((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))); 199 | } 200 | #else 201 | isAbsolute = (dirSeparator[0] == path[0]); 202 | #endif 203 | } 204 | 205 | std::string r = path; 206 | if (!isAbsolute) 207 | r = head + dirSeparator + path; 208 | return r; 209 | } 210 | 211 | void checkFileReadable(const std::string& path) { 212 | std::ifstream file(path, std::ifstream::binary); 213 | if (!file.is_open()) { 214 | std::string msg = "Could not open file \"" + path + "\" for reading"; 215 | throw std::runtime_error(msg); 216 | } 217 | } 218 | 219 | void checkFileWritable(const std::string& path) { 220 | std::ofstream file(path, std::ofstream::binary); 221 | if (!file.is_open()) { 222 | std::string msg = "Could not open file \"" + path + "\" for writing"; 223 | throw std::runtime_error(msg); 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /plugins/code/tiff_dec/libtiff/src/tiff_dec_libtiff.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #include "tiff_dec_api.h" 44 | #include "tiffio.h" 45 | 46 | static const int temp_file_num = 0; 47 | static std::string temp_file_num_str = std::to_string(temp_file_num); 48 | 49 | static const PropertyInfo tiff_dec_libtiff_info[] = { 50 | {"temp_file_num", PROPERTY_TYPE_INTEGER, "Indicates how many temp files this plugin requires.", 51 | temp_file_num_str.c_str(), NULL, 0, 1, ACCESS_TYPE_READ}, 52 | {"temp_file", PROPERTY_TYPE_INTEGER, "Path to temp file.", NULL, NULL, temp_file_num, temp_file_num, 53 | ACCESS_TYPE_WRITE_INIT}, 54 | }; 55 | 56 | static size_t libtiff_get_info(const PropertyInfo** info) { 57 | *info = tiff_dec_libtiff_info; 58 | return sizeof(tiff_dec_libtiff_info) / sizeof(PropertyInfo); 59 | } 60 | 61 | typedef struct { 62 | std::string msg; 63 | uint16_t* outputBuffer; 64 | uint16_t* lineBuffer; 65 | std::vector tempFile; 66 | } tiff_dec_libtiff_data_t; 67 | 68 | /* This structure can contain only pointers and simple types */ 69 | typedef struct { 70 | tiff_dec_libtiff_data_t* data; 71 | } tiff_dec_libtiff_t; 72 | 73 | static uint64_t libtiff_get_size() { 74 | return sizeof(tiff_dec_libtiff_t); 75 | } 76 | 77 | static void init_data(tiff_dec_libtiff_data_t* data) { 78 | data->outputBuffer = NULL; 79 | data->lineBuffer = NULL; 80 | data->msg.clear(); 81 | data->tempFile.clear(); 82 | } 83 | 84 | static Status libtiff_init(TiffDecHandle handle, const TiffDecInitParams* init_params) { 85 | tiff_dec_libtiff_t* state = (tiff_dec_libtiff_t*)handle; 86 | state->data = new tiff_dec_libtiff_data_t; 87 | 88 | init_data(state->data); 89 | 90 | for (uint64_t i = 0; i < init_params->count; i++) { 91 | std::string name(init_params->properties[i].name); 92 | std::string value(init_params->properties[i].value); 93 | 94 | if ("temp_file" == name) { 95 | state->data->tempFile.push_back(value); 96 | } 97 | else { 98 | state->data->msg += "\nUnknown XML property: " + name; 99 | return STATUS_ERROR; 100 | } 101 | } 102 | 103 | if ((int)state->data->tempFile.size() < temp_file_num) { 104 | state->data->msg = "Need more temp files."; 105 | return STATUS_ERROR; 106 | } 107 | 108 | state->data->msg = "LIBTIFF version: " + std::string(TIFFLIB_VERSION_STR); 109 | 110 | return STATUS_OK; 111 | } 112 | 113 | static Status libtiff_close(TiffDecHandle handle) { 114 | tiff_dec_libtiff_t* state = (tiff_dec_libtiff_t*)handle; 115 | 116 | if (state->data) { 117 | if (state->data->outputBuffer) { 118 | delete[] state->data->outputBuffer; 119 | state->data->outputBuffer = NULL; 120 | } 121 | if (state->data->lineBuffer) { 122 | delete[] state->data->lineBuffer; 123 | state->data->lineBuffer = NULL; 124 | } 125 | delete state->data; 126 | state->data = NULL; 127 | } 128 | 129 | return STATUS_OK; 130 | } 131 | 132 | struct TiffStream { 133 | char* data; 134 | uint64_t size; 135 | uint64_t pos; 136 | }; 137 | 138 | tsize_t tiff_Read(thandle_t st, tdata_t buffer, tsize_t size) { 139 | auto s = (TiffStream*)st; 140 | auto remainignBytes = s->size - s->pos; 141 | if (size > (tsize_t)remainignBytes) 142 | size = (tsize_t)remainignBytes; 143 | memcpy(buffer, s->data + s->pos, size); 144 | s->pos += (uint64_t)size; 145 | return size; 146 | }; 147 | 148 | tsize_t tiff_Write(thandle_t, tdata_t, tsize_t) { 149 | return 0; 150 | }; 151 | 152 | int tiff_Close(thandle_t) { 153 | return 0; 154 | }; 155 | 156 | toff_t tiff_Seek(thandle_t st, toff_t pos, int whence) { 157 | auto s = (TiffStream*)st; 158 | if (SEEK_SET == whence) 159 | s->pos = (uint64_t)pos; 160 | else if (SEEK_CUR == whence) 161 | s->pos += (uint64_t)pos; 162 | 163 | if (s->pos > s->size) 164 | s->pos = s->size; 165 | 166 | return (toff_t)s->pos; 167 | }; 168 | 169 | toff_t tiff_Size(thandle_t st) { 170 | auto s = (TiffStream*)st; 171 | return (toff_t)s->size; 172 | }; 173 | 174 | int tiff_Map(thandle_t, tdata_t*, toff_t*) { 175 | return 0; 176 | }; 177 | 178 | void tiff_Unmap(thandle_t, tdata_t, toff_t) { 179 | return; 180 | }; 181 | 182 | static Status libtiff_process(TiffDecHandle handle, const TiffDecInput* in, TiffDecOutput* out) { 183 | tiff_dec_libtiff_t* state = (tiff_dec_libtiff_t*)handle; 184 | 185 | state->data->msg.clear(); 186 | 187 | TiffStream stream; 188 | stream.data = (char*)in->buffer; 189 | stream.pos = 0; 190 | stream.size = in->size; 191 | 192 | TIFF* inTiff = TIFFClientOpen("Memory", "r", (thandle_t)&stream, tiff_Read, tiff_Write, tiff_Seek, tiff_Close, 193 | tiff_Size, tiff_Map, tiff_Unmap); 194 | 195 | uint32 width = 0; 196 | uint32 height = 0; 197 | uint16 bitsPerSample = 0; 198 | uint16 nsamples = 0; 199 | uint16 photometric = 0; 200 | uint16 subsampling[2] = {0, 0}; 201 | 202 | TIFFGetField(inTiff, TIFFTAG_IMAGEWIDTH, &width); 203 | TIFFGetField(inTiff, TIFFTAG_IMAGELENGTH, &height); 204 | TIFFGetField(inTiff, TIFFTAG_BITSPERSAMPLE, &bitsPerSample); 205 | TIFFGetField(inTiff, TIFFTAG_SAMPLESPERPIXEL, &nsamples); 206 | TIFFGetField(inTiff, TIFFTAG_PHOTOMETRIC, &photometric); 207 | 208 | if (bitsPerSample != 16) { 209 | state->data->msg = "Unsupported bit-depth: " + std::to_string(bitsPerSample); 210 | TIFFClose(inTiff); 211 | return STATUS_ERROR; 212 | } 213 | 214 | TiffFormat format; 215 | if (PHOTOMETRIC_RGB == photometric) { 216 | format = TIFF_FORMAT_RGB48LE; 217 | } 218 | else if (PHOTOMETRIC_YCBCR == photometric) { 219 | TIFFGetField(inTiff, TIFFTAG_YCBCRSUBSAMPLING, &subsampling[0], &subsampling[1]); 220 | if (1 == subsampling[0] && 1 == subsampling[1]) { 221 | format = TIFF_FORMAT_YUV444P16LE; 222 | } 223 | else { 224 | state->data->msg = 225 | "Unsupported subsampling: " + std::to_string(subsampling[0]) + "," + std::to_string(subsampling[1]); 226 | TIFFClose(inTiff); 227 | return STATUS_ERROR; 228 | } 229 | } 230 | else { 231 | state->data->msg = "Unsupported photometric interpretation: " + std::to_string(photometric); 232 | TIFFClose(inTiff); 233 | return STATUS_ERROR; 234 | } 235 | const int maxPlaneNum = 4; 236 | uint64_t buffer_size = width * height * maxPlaneNum; 237 | if (!state->data->outputBuffer) 238 | state->data->outputBuffer = new uint16_t[buffer_size]; 239 | if (!state->data->lineBuffer) 240 | state->data->lineBuffer = new uint16_t[buffer_size]; 241 | 242 | uint64_t pixNum = width * height; 243 | memset(state->data->outputBuffer, 0, buffer_size); 244 | uint16* plane[maxPlaneNum]; 245 | for (int i = 0; i < maxPlaneNum; i++) { 246 | plane[i] = &state->data->outputBuffer[i * pixNum]; 247 | } 248 | 249 | out->buffer[0] = (void*)plane[0]; 250 | out->buffer[1] = (void*)plane[1]; 251 | out->buffer[2] = (void*)plane[2]; 252 | 253 | uint16_t* line = state->data->lineBuffer; 254 | for (uint32 row = 0; row < height; row++) { 255 | if (!TIFFReadScanline(inTiff, line, row)) { 256 | state->data->msg = "TIFFReadScanline failed"; 257 | TIFFClose(inTiff); 258 | return STATUS_ERROR; 259 | } 260 | 261 | for (uint32 i = 0; i < width; i++) { 262 | for (uint32 s = 0; s < nsamples; s++) { 263 | *(plane[s]++) = line[(i*nsamples)+s]; 264 | } 265 | } 266 | } 267 | 268 | out->width = width; 269 | out->height = height; 270 | out->format = format; 271 | 272 | TIFFClose(inTiff); 273 | return STATUS_OK; 274 | } 275 | 276 | static Status libtiff_set_property(TiffDecHandle, const Property*) { 277 | return STATUS_ERROR; 278 | } 279 | 280 | static Status libtiff_get_property(TiffDecHandle handle, Property* property) { 281 | tiff_dec_libtiff_t* state = (tiff_dec_libtiff_t*)handle; 282 | if (NULL == state) 283 | return STATUS_ERROR; 284 | 285 | if (NULL != property->name) { 286 | std::string name(property->name); 287 | if ("temp_file_num" == name) { 288 | strcpy(property->value, std::to_string(temp_file_num).c_str()); 289 | return STATUS_OK; 290 | } 291 | } 292 | return STATUS_ERROR; 293 | } 294 | 295 | 296 | static const char* libtiff_get_message(TiffDecHandle handle) { 297 | tiff_dec_libtiff_t* state = (tiff_dec_libtiff_t*)handle; 298 | if (state && state->data) 299 | return state->data->msg.empty() ? NULL : state->data->msg.c_str(); 300 | else 301 | return NULL; 302 | } 303 | 304 | static TiffDecApi libtiff_plugin_api = { 305 | "libtiff", libtiff_get_info, libtiff_get_size, libtiff_init, libtiff_close, 306 | libtiff_process, libtiff_set_property, libtiff_get_property, libtiff_get_message}; 307 | 308 | DLB_EXPORT 309 | TiffDecApi* tiffDecGetApi() { 310 | return &libtiff_plugin_api; 311 | } 312 | 313 | DLB_EXPORT 314 | int tiffDecGetApiVersion(void) { 315 | return TIFF_DEC_API_VERSION; 316 | } 317 | -------------------------------------------------------------------------------- /plugins/code/j2k_dec/kakadu/src/j2k_dec_kakadu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #include "j2k_dec_kakadu.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifdef _WIN32 // suppress windows kdu warnings 44 | #pragma warning(push) 45 | #pragma warning(disable: 4458) // declaration of '...' hides class member 46 | #pragma warning(disable: 4100) // '...': unreferenced formal parameter 47 | #endif //_WIN32 48 | // Kakadu core includes 49 | #include "kdu_elementary.h" 50 | #include "kdu_messaging.h" 51 | #include "kdu_params.h" 52 | #include "kdu_sample_processing.h" 53 | #include "kdu_compressed.h" 54 | 55 | // Kakadu support includes 56 | #include "kdu_stripe_decompressor.h" 57 | #ifdef _WIN32 58 | #pragma warning(pop) 59 | #endif 60 | 61 | 62 | using namespace kdu_supp; 63 | 64 | #define MAX_PLANES (3) 65 | 66 | static 67 | const 68 | PropertyInfo j2k_dec_kakadu_info[] = 69 | { 70 | { "width", PROPERTY_TYPE_INTEGER, "Picture width", NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT }, 71 | { "height", PROPERTY_TYPE_INTEGER, "Picture height", NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT }, 72 | { "thread_num", PROPERTY_TYPE_INTEGER, "Number of threads used for decoding. Value '0' disables multi-threading.", "8", "0:255", 0, 1, ACCESS_TYPE_USER } 73 | }; 74 | 75 | size_t 76 | kakadu_get_info 77 | (const PropertyInfo** info) 78 | { 79 | *info = j2k_dec_kakadu_info; 80 | return sizeof(j2k_dec_kakadu_info) / sizeof(PropertyInfo); 81 | } 82 | 83 | struct j2k_dec_kakadu_data_t 84 | { 85 | std::string msg; 86 | size_t width; 87 | size_t height; 88 | int thread_num; 89 | kdu_int16* output_buffer; 90 | short* reorder_buffer; 91 | kdu_thread_env env; 92 | }; 93 | 94 | /* This structure can contain only pointers and simple types */ 95 | struct j2k_dec_kakadu_t 96 | { 97 | j2k_dec_kakadu_data_t* data; 98 | }; 99 | 100 | 101 | class j2k_buffer : public kdu_compressed_source 102 | { 103 | public: 104 | j2k_buffer() 105 | { 106 | m_buffer = NULL; 107 | m_curpos = NULL; 108 | m_buffer_size = 0; 109 | m_capabilities = KDU_SOURCE_CAP_SEQUENTIAL | KDU_SOURCE_CAP_SEEKABLE; 110 | } 111 | 112 | ~j2k_buffer() 113 | { 114 | } 115 | 116 | void open(void* buffer, kdu_long buffer_size) 117 | { 118 | m_buffer = (char*)buffer; 119 | m_buffer_size = buffer_size; 120 | m_curpos = m_buffer; 121 | } 122 | 123 | virtual int get_capabilities() { return m_capabilities; } 124 | 125 | virtual bool seek(kdu_long offset) 126 | { 127 | assert(m_buffer != NULL); 128 | assert(m_curpos != NULL); 129 | if (!(m_capabilities & KDU_SOURCE_CAP_SEEKABLE)) return false; 130 | m_curpos = m_buffer + offset; 131 | return true; 132 | } 133 | 134 | virtual kdu_long get_pos() { return (m_buffer==NULL)?-1:m_curpos-m_buffer; } 135 | 136 | virtual int read(kdu_byte *buf, int num_bytes) 137 | { 138 | assert(m_buffer != NULL); 139 | assert(m_curpos != NULL); 140 | if ((kdu_long)num_bytes > m_buffer_size-get_pos()) num_bytes = (int)(m_buffer_size-get_pos()); 141 | memcpy(buf, m_curpos, num_bytes); 142 | m_curpos += num_bytes; 143 | return num_bytes; 144 | } 145 | 146 | 147 | private: 148 | int m_capabilities; 149 | kdu_long m_buffer_size; 150 | char* m_buffer; 151 | char* m_curpos; 152 | }; 153 | 154 | size_t 155 | kakadu_get_size() 156 | { 157 | return sizeof(j2k_dec_kakadu_t); 158 | } 159 | 160 | static 161 | void 162 | init_data 163 | (j2k_dec_kakadu_data_t* data) 164 | { 165 | data->output_buffer = NULL; 166 | data->reorder_buffer = NULL; 167 | data->width = 0; 168 | data->height = 0; 169 | data->thread_num = 8; 170 | data->msg.clear(); 171 | } 172 | 173 | Status 174 | kakadu_init 175 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 176 | ,const J2kDecInitParams* init_params /**< [in] Properties to init decoder instance */ 177 | ) 178 | { 179 | j2k_dec_kakadu_t* state = (j2k_dec_kakadu_t*)handle; 180 | state->data = new j2k_dec_kakadu_data_t; 181 | 182 | init_data(state->data); 183 | for (size_t i = 0; i < init_params->count; i++) 184 | { 185 | std::string name(init_params->properties[i].name); 186 | std::string value(init_params->properties[i].value); 187 | 188 | try { 189 | if ("width" == name) 190 | { 191 | state->data->width = std::stoi(value); 192 | } 193 | else if ("height" == name) 194 | { 195 | state->data->height = std::stoi(value); 196 | } 197 | else if ("thread_num" == name) 198 | { 199 | state->data->thread_num = std::stoi(value); 200 | } 201 | else 202 | { 203 | state->data->msg += "Unknown property: " + name; 204 | return STATUS_ERROR; 205 | } 206 | } catch(std::exception&){ 207 | state->data->msg += "Invalid '" + name + "' value: " + value; 208 | return STATUS_ERROR; 209 | } 210 | } 211 | 212 | if (state->data->width <= 0) 213 | { 214 | state->data->msg = "Invalid 'width' value."; 215 | return STATUS_ERROR; 216 | } 217 | 218 | if (state->data->width <= 0) 219 | { 220 | state->data->msg = "Invalid 'width' value."; 221 | return STATUS_ERROR; 222 | } 223 | 224 | if (state->data->thread_num < 0 || state->data->thread_num > 255) 225 | { 226 | state->data->msg = "Invalid 'thread_num' value: " + std::to_string(state->data->thread_num); 227 | return STATUS_ERROR; 228 | } 229 | 230 | int buffer_size = (int)(state->data->width*state->data->height*MAX_PLANES); 231 | state->data->output_buffer = new kdu_int16[buffer_size]; 232 | state->data->reorder_buffer = new short[buffer_size]; 233 | 234 | if (state->data->thread_num) { 235 | state->data->env.create(); 236 | for (int nt=1; nt < state->data->thread_num; nt++) 237 | if (!state->data->env.add_thread()) 238 | state->data->thread_num = nt; 239 | } 240 | 241 | state->data->msg = "Initialized Kakadu j2k decoder version " + std::string(kdu_core::kdu_get_core_version()); 242 | return STATUS_OK; 243 | } 244 | 245 | Status 246 | kakadu_close 247 | (J2kDecHandle handle 248 | ) 249 | { 250 | j2k_dec_kakadu_t* state = (j2k_dec_kakadu_t*)handle; 251 | state->data->msg.clear(); 252 | 253 | if (state->data) 254 | { 255 | if (state->data->thread_num) 256 | if (state->data->env.exists()) 257 | state->data->env.destroy(); 258 | 259 | if (state->data->output_buffer) delete [] state->data->output_buffer; 260 | if (state->data->reorder_buffer) delete [] state->data->reorder_buffer; 261 | if(state->data) { 262 | delete state->data; 263 | state->data = nullptr; 264 | } 265 | } 266 | 267 | return STATUS_OK; 268 | } 269 | 270 | static 271 | void 272 | prepare_output 273 | (j2k_dec_kakadu_t* state 274 | ,J2kDecOutput* out) 275 | { 276 | out->width = state->data->width; 277 | out->height = state->data->height; 278 | size_t plane_bytes = out->width*out->height*2; 279 | out->buffer[0] = state->data->output_buffer; 280 | out->buffer[1] = (char*)out->buffer[0] + plane_bytes; 281 | out->buffer[2] = (char*)out->buffer[1] + plane_bytes; 282 | } 283 | 284 | Status 285 | kakadu_process 286 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 287 | ,const J2kDecInput* in /**< [in] Encoded input */ 288 | ,J2kDecOutput* out /**< [out] Decoded output */ 289 | ) 290 | { 291 | j2k_dec_kakadu_t* state = (j2k_dec_kakadu_t*)handle; 292 | state->data->msg.clear(); 293 | 294 | j2k_buffer input; 295 | input.open(in->buffer, (kdu_long)in->size); 296 | kdu_codestream codestream; codestream.create(&input); 297 | codestream.set_fussy(); 298 | 299 | int num_components = codestream.get_num_components(); 300 | if (num_components != 3) 301 | { 302 | state->data->msg = "Picture must consist of 3 components."; 303 | return STATUS_ERROR; 304 | } 305 | 306 | codestream.apply_input_restrictions(0,num_components,0,0,NULL); 307 | 308 | kdu_dims dims0, dims1, dims2; 309 | codestream.get_dims(0,dims0); 310 | codestream.get_dims(1,dims1); 311 | codestream.get_dims(2,dims2); 312 | 313 | if (dims0 != dims1 || dims0 != dims2) 314 | { 315 | state->data->msg = "Mismatching dimensions."; 316 | return STATUS_ERROR; 317 | } 318 | 319 | int bit_depth[] = {16, 16, 16}; 320 | bool is_signed[] = {false, false, false}; 321 | 322 | bool force_precise=true; 323 | bool want_fastest=false; 324 | kdu_stripe_decompressor decompressor; 325 | if (state->data->thread_num) 326 | decompressor.start(codestream, force_precise, want_fastest, &state->data->env); 327 | else 328 | decompressor.start(codestream, force_precise, want_fastest, NULL); 329 | 330 | int stripe_heights[3] = {dims0.size.y, dims1.size.y, dims2.size.y}; 331 | int sample_offsets[3] = {0, dims0.size.x*dims0.size.y, dims0.size.x*dims0.size.y + dims1.size.x*dims1.size.y}; 332 | int sample_gaps[3] = {1, 1, 1}; 333 | decompressor.pull_stripe(state->data->output_buffer,stripe_heights, sample_offsets, sample_gaps, NULL, bit_depth, is_signed); 334 | decompressor.finish(); 335 | codestream.destroy(); 336 | prepare_output(state, out); 337 | 338 | return STATUS_OK; 339 | } 340 | 341 | Status 342 | kakadu_get_property 343 | (J2kDecHandle /**< [in/out] Decoder instance handle */ 344 | , Property* /**< [in/out] Property to read */ 345 | ) 346 | { 347 | return STATUS_ERROR; 348 | } 349 | 350 | const char* 351 | kakadu_get_message 352 | (J2kDecHandle handle /**< [in/out] Decoder instance handle */ 353 | ) 354 | { 355 | j2k_dec_kakadu_t* state = (j2k_dec_kakadu_t*)handle; 356 | if (state && state->data) 357 | return state->data->msg.empty() ? NULL : state->data->msg.c_str(); 358 | else 359 | return NULL; 360 | } 361 | 362 | -------------------------------------------------------------------------------- /plugins/code/api/hevc_enc/hevc_enc_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef __DEE_PLUGINS_HEVC_ENC_API_H__ 34 | #define __DEE_PLUGINS_HEVC_ENC_API_H__ 35 | 36 | #include "plugins_common.h" 37 | 38 | #define HEVC_ENC_API_VERSION 2 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Framework sets/gets following properties. Each hevc_enc plugin should handle them. 45 | * PROPERTY : TYPE : VALUES : WHERE : COMMENT 46 | * ----------------------------------------------------------------------------- 47 | * width : integer : n/a : hevc_enc_init 48 | * height : integer : n/a : hevc_enc_init 49 | * bit_depth : enum : [8,10] : hevc_enc_init : in DEE it is always '10' 50 | * frame_rate : enum : [23.976,24,25,29.97,30,48,59.94,60] : hevc_enc_init 51 | * color_space : enum : [i400,i420,i422,i444] : hevc_enc_init : in DEE it is always 'i420' 52 | * data_rate : integer : n/a : hevc_enc_init : value in kbps 53 | * max_vbv_data_rate : integer : n/a : hevc_enc_init : value in kbps 54 | * vbv_buffer_size : integer : n/a : hevc_enc_init : value in kb 55 | * range : enum : [limited,full] : hevc_enc_init : each workflow provides required value 56 | * multi_pass : enum : [off,1st,nth,last] : hevc_enc_init 57 | * stats_file : string : n/a : hevc_enc_init : temp file to write stats in multipass encoding 58 | * max_output_data : integer : n/a : hevc_enc_set_property : framework indicates max size of buffer before each 'process' call 59 | * max_pass_num : integer : n/a : hevc_enc_get_property : accessed before hevc_enc_init 60 | * absolute_pass_num : integer : n/a : hevc_enc_init : when encoding multiple times (in multipass encoding or in multiple output streams) this value states the index number of the current encoding 61 | * temp_file_num : integer : n/a : hevc_enc_get_property : accessed before hevc_enc_init, optional, should be used if plugin needs some temp files 62 | * temp_file : string : n/a : hevc_enc_init : occurs multiple times, according to value retrieved from 'temp_file_num' 63 | * color_primaries : enum : [unspecified,bt_709,bt_601_625,bt_601_525,bt_2020] : hevc_enc_init : each workflow provides required value 64 | * transfer_characteristics : enum : [unspecified,bt_709,bt_601_625,bt_601_525,smpte_st_2084,std_b67] : hevc_enc_init : each workflow provides required value 65 | * matrix_coefficients : enum : [unspecified,bt_709,bt_601_625,bt_601_525,bt_2020] : hevc_enc_init : each workflow provides required value 66 | * chromaloc : integer : [0,5] : hevc_enc_init : each workflow provides required value 67 | * mastering_display_sei_x1 : integer : [0,50000] : hevc_enc_init : first primary x : optional, used when encoding HDR10-compatible streams 68 | * mastering_display_sei_y1 : integer : [0,50000] : hevc_enc_init : first primary y : optional, used when encoding HDR10-compatible streams 69 | * mastering_display_sei_x2 : integer : [0,50000] : hevc_enc_init : second primary x : optional, used when encoding HDR10-compatible streams 70 | * mastering_display_sei_y2 : integer : [0,50000] : hevc_enc_init : second primary y : optional, used when encoding HDR10-compatible streams 71 | * mastering_display_sei_x3 : integer : [0,50000] : hevc_enc_init : third primary x : optional, used when encoding HDR10-compatible streams 72 | * mastering_display_sei_y3 : integer : [0,50000] : hevc_enc_init : third primary y : optional, used when encoding HDR10-compatible streams 73 | * mastering_display_sei_wx : integer : [0,50000] : hevc_enc_init : white point x : optional, used when encoding HDR10-compatible streams 74 | * mastering_display_sei_wy : integer : [0,50000] : hevc_enc_init : white point y : optional, used when encoding HDR10-compatible streams 75 | * mastering_display_sei_max_lum : integer : [0:2000000000] : hevc_enc_init : maximum display luminance : optional, used when encoding HDR10-compatible streams 76 | * mastering_display_sei_min_lum : integer : [0:2000000000] : hevc_enc_init : minimum display luminance : optional, used when encoding HDR10-compatible streams 77 | * light_level_max_content : integer : [0,65535] : hevc_enc_init : optional, used when encoding HDR10-compatible streams 78 | * light_level_max_frame_average : integer : [0,65535] : hevc_enc_init : optional, used when encoding HDR10-compatible streams 79 | * force_slice_type : [true,false] : hevc_enc_init : optional, when present and set to 'true' indicates that frame_type in hevc_enc_picture_t might come with value different than HEVC_ENC_FRAME_TYPE_AUTO 80 | * uhd_bd : [true,false] : hevc_enc_init : optional, used to indicate that stream must conform Ultra HD Blu-ray spec 81 | * 82 | * Additionally, hevc_enc_init_params_t structure will contain all plugin-specific properties set via XML interface (ACCESS_TYPE_USER). 83 | * 84 | */ 85 | 86 | /** @brief Set of properties to init encoder */ 87 | typedef struct { 88 | const Property* properties; /**< Pointer to array of properties */ 89 | size_t count; /**< Number of properties in array */ 90 | } HevcEncInitParams; 91 | 92 | /** @brief Color Space */ 93 | typedef enum { 94 | HEVC_ENC_COLOR_SPACE_I400 = 0, 95 | HEVC_ENC_COLOR_SPACE_I420, 96 | HEVC_ENC_COLOR_SPACE_I422, 97 | HEVC_ENC_COLOR_SPACE_I444, 98 | } HevcEncColorSpace; 99 | 100 | /** @brief Type of video frame */ 101 | typedef enum { 102 | HEVC_ENC_FRAME_TYPE_AUTO = 0, 103 | HEVC_ENC_FRAME_TYPE_IDR, 104 | HEVC_ENC_FRAME_TYPE_I, 105 | HEVC_ENC_FRAME_TYPE_P, 106 | HEVC_ENC_FRAME_TYPE_B, 107 | HEVC_ENC_FRAME_TYPE_BREF, 108 | } HevcEncFrameType; 109 | 110 | /** @brief Picture structure 111 | * Points to video data and describes how it should be interpreted. 112 | */ 113 | typedef struct { 114 | int bitDepth; /**< 8 or 10 bits */ 115 | void* plane[3]; /**< Pointers to Y, Cb and Cr planes */ 116 | int stride[3]; /**< Number of bytes between rows (for each plane) */ 117 | 118 | size_t width; 119 | size_t height; 120 | HevcEncColorSpace colorSpace; 121 | HevcEncFrameType frameType; 122 | } HevcEncPicture; 123 | 124 | /** @brief NAL unit types. 125 | * In DEE only HEVC_ENC_NAL_UNIT_ACCESS_UNIT_DELIMITER is important. 126 | * All other NAL units can be set to HEVC_ENC_NAL_UNIT_OTHER. 127 | */ 128 | typedef enum { 129 | HEVC_ENC_NAL_UNIT_CODED_SLICE_TRAIL_N = 0, 130 | HEVC_ENC_NAL_UNIT_CODED_SLICE_TRAIL_R, 131 | HEVC_ENC_NAL_UNIT_CODED_SLICE_TSA_N, 132 | HEVC_ENC_NAL_UNIT_CODED_SLICE_TLA_R, 133 | HEVC_ENC_NAL_UNIT_CODED_SLICE_STSA_N, 134 | HEVC_ENC_NAL_UNIT_CODED_SLICE_STSA_R, 135 | HEVC_ENC_NAL_UNIT_CODED_SLICE_RADL_N, 136 | HEVC_ENC_NAL_UNIT_CODED_SLICE_RADL_R, 137 | HEVC_ENC_NAL_UNIT_CODED_SLICE_RASL_N, 138 | HEVC_ENC_NAL_UNIT_CODED_SLICE_RASL_R, 139 | HEVC_ENC_NAL_UNIT_CODED_SLICE_BLA_W_LP = 16, 140 | HEVC_ENC_NAL_UNIT_CODED_SLICE_BLA_W_RADL, 141 | HEVC_ENC_NAL_UNIT_CODED_SLICE_BLA_N_LP, 142 | HEVC_ENC_NAL_UNIT_CODED_SLICE_IDR_W_RADL, 143 | HEVC_ENC_NAL_UNIT_CODED_SLICE_IDR_N_LP, 144 | HEVC_ENC_NAL_UNIT_CODED_SLICE_CRA, 145 | HEVC_ENC_NAL_UNIT_VPS = 32, 146 | HEVC_ENC_NAL_UNIT_SPS, 147 | HEVC_ENC_NAL_UNIT_PPS, 148 | HEVC_ENC_NAL_UNIT_ACCESS_UNIT_DELIMITER, 149 | HEVC_ENC_NAL_UNIT_EOS, 150 | HEVC_ENC_NAL_UNIT_EOB, 151 | HEVC_ENC_NAL_UNIT_FILLER_DATA, 152 | HEVC_ENC_NAL_UNIT_PREFIX_SEI, 153 | HEVC_ENC_NAL_UNIT_SUFFIX_SEI, 154 | HEVC_ENC_NAL_UNIT_OTHER, 155 | HEVC_ENC_NAL_UNIT_INVALID = 64, 156 | } HevcEncNalType; 157 | 158 | /** @brief NAL unit structure */ 159 | typedef struct { 160 | HevcEncNalType type; /**< Type of NAL unit */ 161 | size_t size; /**< Size of payload */ 162 | void* payload; /**< Pointer to payload */ 163 | } HevcEncNal; 164 | 165 | /** @brief Output frame structure */ 166 | typedef struct { 167 | HevcEncNal* nal; /**< Buffer of NAL units */ 168 | size_t nalNum; /**< Number of units in buffer */ 169 | } HevcEncOutput; 170 | 171 | /** @brief Handle to encoder instance 172 | * hevc_enc_handle_t is actually pointer to encoder context 173 | * defined by plugin's private type. Caller sees that as void*. 174 | */ 175 | typedef void* HevcEncHandle; 176 | 177 | /** @brief Get info about supported properties 178 | * @return Number of properties in info array 179 | */ 180 | typedef size_t (*HevcEncGetInfo)(const PropertyInfo** info); /**< [out] Pointer to array with property information */ 181 | 182 | /** @brief Get size of encoder context 183 | * @return Size in bytes 184 | */ 185 | typedef size_t (*HevcEncGetSize)(void); 186 | 187 | /** @brief Initialize encoder instance 188 | * @return status code 189 | */ 190 | typedef Status (*HevcEncInit)(HevcEncHandle handle, /**< [in/out] Encoder instance handle */ 191 | const HevcEncInitParams* initParams); /**< [in] Properties to init encoder instance */ 192 | 193 | /** @brief Close encoder instance 194 | * @return status code 195 | */ 196 | typedef Status (*HevcEncClose)(HevcEncHandle handle); /**< [in/out] Encoder instance handle */ 197 | 198 | /** @brief Encode array of pictures. In DEE picture_num is always '1'. 199 | * Should produce complete access unit, if available. 200 | * If buffer size (max_output_data) is too small to handle access unit, 201 | * plugin must keep it until bigger buffer is available. 202 | * Function sets pointer to output data, so it must 203 | * stay in plugin's memory until next 'process' call. 204 | * @return status code 205 | */ 206 | typedef Status (*HevcEncProcess)(HevcEncHandle handle, /**< [in/out] Encoder instance handle */ 207 | const HevcEncPicture* picture, /**< [in] Pointer to array of pictures */ 208 | const size_t pictureNum, /**< [in] Number of pictures in array */ 209 | HevcEncOutput* output); /**< [out] Output buffer */ 210 | 211 | /** @brief Flush encoder 212 | * @return status code 213 | */ 214 | typedef Status (*HevcEncFlush)(HevcEncHandle handle, /**< [in/out] Encoder instance handle */ 215 | HevcEncOutput* output, /**< [in/out] Output buffer */ 216 | int* isEmpty); /**< [out] Flush indicator */ 217 | 218 | /** @brief Property setter 219 | * @return status code 220 | */ 221 | typedef Status (*HevcEncSetProperty)(HevcEncHandle handle, /**< [in/out] Encoder instance handle */ 222 | const Property* property); /**< [in] Property to write */ 223 | 224 | /** @brief Property getter 225 | * @return status code 226 | */ 227 | typedef Status (*HevcEncGetProperty)(HevcEncHandle handle, /**< [in/out] Encoder instance handle */ 228 | Property* property); /**< [in/out] Property to read */ 229 | 230 | /** @brief Get string describing last warning or error occurred 231 | * @return Pointer to string with message 232 | */ 233 | typedef const char* (*HevcEncGetMessage)(HevcEncHandle handle); /**< [in/out] Encoder instance handle */ 234 | 235 | /** @brief Structure with pointers to all API functions */ 236 | typedef struct { 237 | const char* pluginName; 238 | HevcEncGetInfo getInfo; 239 | HevcEncGetSize getSize; 240 | HevcEncInit init; 241 | HevcEncClose close; 242 | HevcEncProcess process; 243 | HevcEncFlush flush; 244 | HevcEncSetProperty setProperty; 245 | HevcEncGetProperty getProperty; 246 | HevcEncGetMessage getMessage; 247 | } HevcEncApi; 248 | 249 | /** @brief Export symbol to access implementation of HEVC Encoder plugin 250 | * @return pointer to hevc_enc_api_t 251 | */ 252 | DLB_EXPORT 253 | HevcEncApi* hevcEncGetApi(void); 254 | 255 | /** @brief Definition of pointer to hevcEncGetApi function */ 256 | typedef HevcEncApi* (*HevcEncGetApi)(void); 257 | 258 | /** @brief Export symbol to access API version of HEVC Encoder plugin 259 | * @return integer representing API version 260 | */ 261 | DLB_EXPORT 262 | int hevcEncGetApiVersion(void); 263 | 264 | /** @brief Definition of pointer to hevcEncGetApiVersion function */ 265 | typedef int (*HevcEncGetApiVersion)(void); 266 | 267 | #ifdef __cplusplus 268 | } 269 | #endif 270 | 271 | #endif // __DEE_PLUGINS_HEVC_ENC_API_H__ 272 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/beamr/src/hevc_enc_beamr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "hevc_enc_api.h" 34 | #include "hevc_enc_beamr_impl.h" 35 | #include "hevc_enc_beamr_utils.h" 36 | 37 | #include 38 | 39 | static const std::string pluginName{"beamr"}; 40 | 41 | static const PropertyInfo propertyInfo[] = { 42 | {"max_pass_num", PROPERTY_TYPE_INTEGER, "Indicates how many passes encoder can perform (0 = unlimited).", "3", NULL, 43 | 0, 1, ACCESS_TYPE_READ}, 44 | {"absolute_pass_num", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 45 | {"max_output_data", PROPERTY_TYPE_INTEGER, "Limits number of output bytes (0 = unlimited).", "0", NULL, 0, 1, 46 | ACCESS_TYPE_WRITE}, 47 | {"bit_depth", PROPERTY_TYPE_STRING, NULL, NULL, "8:10", 1, 1, ACCESS_TYPE_WRITE_INIT}, 48 | {"width", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT}, 49 | {"height", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT}, 50 | {"color_space", PROPERTY_TYPE_STRING, NULL, "i420", "i400:i420:i422:i444", 0, 1, ACCESS_TYPE_WRITE_INIT}, 51 | {"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60:119.88:120", 1, 1, 52 | ACCESS_TYPE_WRITE_INIT}, 53 | {"data_rate", PROPERTY_TYPE_INTEGER, "Average data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 54 | {"max_vbv_data_rate", PROPERTY_TYPE_INTEGER, "Max VBV ctrl rate in kbps.", "15000", NULL, 0, 1, 55 | ACCESS_TYPE_WRITE_INIT}, 56 | {"vbv_buffer_size", PROPERTY_TYPE_INTEGER, "VBV buffer size in kb.", "30000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 57 | {"range", PROPERTY_TYPE_STRING, NULL, "full", "limited:full", 0, 1, ACCESS_TYPE_WRITE_INIT}, 58 | {"multi_pass", PROPERTY_TYPE_STRING, NULL, "off", "off:1st:nth:last", 0, 1, ACCESS_TYPE_WRITE_INIT}, 59 | {"stats_file", PROPERTY_TYPE_STRING, NULL, NULL, NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 60 | {"color_primaries", PROPERTY_TYPE_STRING, NULL, "unspecified", "unspecified:bt_709:bt_601_625:bt_601_525:bt_2020", 61 | 0, 1, ACCESS_TYPE_WRITE_INIT}, 62 | {"transfer_characteristics", PROPERTY_TYPE_STRING, NULL, "unspecified", 63 | "unspecified:bt_709:bt_601_625:bt_601_525:smpte_st_2084:std_b67", 0, 1, ACCESS_TYPE_WRITE_INIT}, 64 | {"matrix_coefficients", PROPERTY_TYPE_STRING, NULL, "unspecified", 65 | "unspecified:bt_709:bt_601_625:bt_601_525:bt_2020", 0, 1, ACCESS_TYPE_WRITE_INIT}, 66 | {"chromaloc", PROPERTY_TYPE_INTEGER, NULL, "0", "0:5", 0, 1, ACCESS_TYPE_WRITE_INIT}, 67 | {"mastering_display_sei_x1", PROPERTY_TYPE_INTEGER, "First primary x.", "0", "0:50000", 0, 1, 68 | ACCESS_TYPE_WRITE_INIT}, 69 | {"mastering_display_sei_y1", PROPERTY_TYPE_INTEGER, "First primary y.", "0", "0:50000", 0, 1, 70 | ACCESS_TYPE_WRITE_INIT}, 71 | {"mastering_display_sei_x2", PROPERTY_TYPE_INTEGER, "Second primary x.", "0", "0:50000", 0, 1, 72 | ACCESS_TYPE_WRITE_INIT}, 73 | {"mastering_display_sei_y2", PROPERTY_TYPE_INTEGER, "Second primary y.", "0", "0:50000", 0, 1, 74 | ACCESS_TYPE_WRITE_INIT}, 75 | {"mastering_display_sei_x3", PROPERTY_TYPE_INTEGER, "Third primary x.", "0", "0:50000", 0, 1, 76 | ACCESS_TYPE_WRITE_INIT}, 77 | {"mastering_display_sei_y3", PROPERTY_TYPE_INTEGER, "Third primary y.", "0", "0:50000", 0, 1, 78 | ACCESS_TYPE_WRITE_INIT}, 79 | {"mastering_display_sei_wx", PROPERTY_TYPE_INTEGER, "White point x.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT}, 80 | {"mastering_display_sei_wy", PROPERTY_TYPE_INTEGER, "White point y.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT}, 81 | {"mastering_display_sei_max_lum", PROPERTY_TYPE_INTEGER, "Maximum display luminance.", "0", "0:2000000000", 0, 1, 82 | ACCESS_TYPE_WRITE_INIT}, 83 | {"mastering_display_sei_min_lum", PROPERTY_TYPE_INTEGER, "Minimum display luminance.", "0", "0:2000000000", 0, 1, 84 | ACCESS_TYPE_WRITE_INIT}, 85 | {"light_level_max_content", PROPERTY_TYPE_INTEGER, NULL, "0", "0:65535", 0, 1, ACCESS_TYPE_WRITE_INIT}, 86 | {"light_level_max_frame_average", PROPERTY_TYPE_INTEGER, NULL, "0", "0:65535", 0, 1, ACCESS_TYPE_WRITE_INIT}, 87 | {"force_slice_type", PROPERTY_TYPE_BOOLEAN, "Indicates that framework will try to force specific slice type.", 88 | "false", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 89 | {"uhd_bd", PROPERTY_TYPE_BOOLEAN, "Indicates UHD-BD encoding.", "false", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}, 90 | 91 | // Properties visible in the interface 92 | {"preset", PROPERTY_TYPE_STRING, "Encoder preset (initial state of encoder configuration).", "medium", 93 | "insanely_slow:ultra_slow:very_slow:slower:slow:medium:medium_plus:fast:faster:ultra_fast:insanely_fast", 0, 1, 94 | ACCESS_TYPE_USER}, 95 | {"modifier", PROPERTY_TYPE_STRING, 96 | "One or more modifiers combined with '+' sign. Supported modifiers: low_delay, tune_psnr, realtime, cinema, " 97 | "bluray, hdr10, hlg, tune_vmaf, low_bitrate.", 98 | NULL, NULL, 0, 1, ACCESS_TYPE_USER}, 99 | {"gop_intra_period", PROPERTY_TYPE_INTEGER, "GOP length.", "32", "0:65535", 0, 1, ACCESS_TYPE_USER}, 100 | {"gop_idr_period", PROPERTY_TYPE_INTEGER, "Frequency of IDR frames / I frames.", "1", "0:65535", 0, 1, 101 | ACCESS_TYPE_USER}, 102 | {"gop_min_intra_period", PROPERTY_TYPE_INTEGER, "Minimum distance between I-frames.", "4", "0:255", 0, 1, 103 | ACCESS_TYPE_USER}, 104 | {"gop_minigop_size", PROPERTY_TYPE_INTEGER, "GOP structure (no. of B-frames + 1).", "8", "1:16", 0, 1, 105 | ACCESS_TYPE_USER}, 106 | {"gop_min_minigop_size", PROPERTY_TYPE_INTEGER, "Minimal miniGOP size for adaptive miniGOP mode.", "8", 107 | "1:16", 0, 1, ACCESS_TYPE_USER}, 108 | {"gop_max_refs", PROPERTY_TYPE_INTEGER, 109 | "Maximum reference frames that will be evaluated for inter-prediction.", "4", "1:8", 0, 1, 110 | ACCESS_TYPE_USER}, 111 | {"me_scene_change", PROPERTY_TYPE_INTEGER, "Scene change detection sensitivity.", "0", "0:90", 0, 1, 112 | ACCESS_TYPE_USER}, 113 | {"pps_cb_qp_offset", PROPERTY_TYPE_INTEGER, "Offset to the luma QP used for deriving Cb chroma QP.", "0", "-12:12", 114 | 0, 1, ACCESS_TYPE_USER}, 115 | {"pps_cr_qp_offset", PROPERTY_TYPE_INTEGER, "Offset to the luma QP used for deriving Cr chroma QP.", "0", "-12:12", 116 | 0, 1, ACCESS_TYPE_USER}, 117 | {"native_config_file", PROPERTY_TYPE_STRING, "File with encoder configuration in native Beamr syntax.", NULL, NULL, 118 | 0, 1, ACCESS_TYPE_USER}, 119 | { "temp_file_num", PROPERTY_TYPE_INTEGER, "Indicates how many temp files this plugin requires.", "1", NULL, 0, 1, ACCESS_TYPE_READ}, 120 | { "temp_file", PROPERTY_TYPE_INTEGER, "Path to temp file.", NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT }, 121 | {"param", PROPERTY_TYPE_STRING, 122 | "Native Beamr parameter using syntax \"name=value\". Use ':' separator to enter multiple parameters under single " 123 | "tag.", 124 | NULL, NULL, 0, 100, ACCESS_TYPE_USER}, 125 | {"gop_structure_in_file", PROPERTY_TYPE_STRING, "File with GOP structure to force.", NULL, NULL, 0, 1, 126 | ACCESS_TYPE_USER}, 127 | {"gop_structure_out_file", PROPERTY_TYPE_STRING, "File store encoded GOP structure.", NULL, NULL, 0, 1, 128 | ACCESS_TYPE_USER}, 129 | {"debug_level", PROPERTY_TYPE_INTEGER, "0 - log errors, 1 - log encoder messages, 2 - debug trace to stderr.", "0", 130 | "0:2", 0, 1, ACCESS_TYPE_USER}}; 131 | 132 | static size_t getInfo(const PropertyInfo** info) { 133 | *info = propertyInfo; 134 | return sizeof(propertyInfo) / sizeof(PropertyInfo); 135 | } 136 | 137 | static size_t getSize() { 138 | return sizeof(PluginContext); 139 | } 140 | 141 | static Status init(HevcEncHandle handle, const HevcEncInitParams* init_params) { 142 | PluginContext* state = (PluginContext*)handle; 143 | if (state->ctrl) 144 | delete state->ctrl; 145 | state->ctrl = new PluginCtrl; 146 | if (state->encoder) 147 | delete state->encoder; 148 | state->encoder = new Encoder; 149 | 150 | try { 151 | const PropertyInfo* schema = propertyInfo; 152 | size_t count = sizeof(propertyInfo) / sizeof(PropertyInfo); 153 | 154 | for (int i = 0; i < (int)init_params->count; i++) { 155 | std::string name(init_params->properties[i].name); 156 | std::string value(init_params->properties[i].value); 157 | 158 | try { 159 | if ("temp_file" == name) { 160 | state->ctrl->temp_file.push_back(value); 161 | } 162 | else if ("absolute_pass_num" == name) { 163 | continue; 164 | } 165 | else if ("bit_depth" == name) { 166 | state->ctrl->bit_depth = (uint8_t)parseInt(name, value, schema, count); 167 | } 168 | else if ("width" == name) { 169 | state->ctrl->width = (uint16_t)parseInt(name, value, schema, count); 170 | } 171 | else if ("height" == name) { 172 | state->ctrl->height = (uint16_t)parseInt(name, value, schema, count); 173 | } 174 | else if ("height" == name) { 175 | state->ctrl->color_space = parseString(name, value, schema, count); 176 | } 177 | else if ("frame_rate" == name) { 178 | state->ctrl->frame_rate = parseString(name, value, schema, count); 179 | } 180 | else if ("data_rate" == name) { 181 | state->ctrl->data_rate = (unsigned int)parseInt(name, value, schema, count); 182 | } 183 | else if ("max_vbv_data_rate" == name) { 184 | state->ctrl->max_vbv_data_rate = (unsigned int)parseInt(name, value, schema, count); 185 | } 186 | else if ("vbv_buffer_size" == name) { 187 | state->ctrl->vbv_buffer_size = (unsigned int)parseInt(name, value, schema, count); 188 | } 189 | else if ("range" == name) { 190 | state->ctrl->range = parseString(name, value, schema, count); 191 | } 192 | else if ("multi_pass" == name) { 193 | state->ctrl->multi_pass = parseString(name, value, schema, count); 194 | } 195 | else if ("stats_file" == name) { 196 | state->ctrl->stats_file = parseString(name, value, schema, count); 197 | } 198 | else if ("color_primaries" == name) { 199 | state->ctrl->color_primaries = parseString(name, value, schema, count); 200 | } 201 | else if ("transfer_characteristics" == name) { 202 | state->ctrl->transfer_characteristics = parseString(name, value, schema, count); 203 | } 204 | else if ("matrix_coefficients" == name) { 205 | state->ctrl->matrix_coefficients = parseString(name, value, schema, count); 206 | } 207 | else if ("chromaloc" == name) { 208 | state->ctrl->chromaloc = (int)parseInt(name, value, schema, count); 209 | } 210 | else if ("mastering_display_sei_x1" == name) { 211 | state->ctrl->mastering_display_sei_x1 = (int64_t)parseInt(name, value, schema, count); 212 | } 213 | else if ("mastering_display_sei_y1" == name) { 214 | state->ctrl->mastering_display_sei_y1 = (int64_t)parseInt(name, value, schema, count); 215 | } 216 | else if ("mastering_display_sei_x2" == name) { 217 | state->ctrl->mastering_display_sei_x2 = (int64_t)parseInt(name, value, schema, count); 218 | } 219 | else if ("mastering_display_sei_y2" == name) { 220 | state->ctrl->mastering_display_sei_y2 = (int64_t)parseInt(name, value, schema, count); 221 | } 222 | else if ("mastering_display_sei_x3" == name) { 223 | state->ctrl->mastering_display_sei_x3 = (int64_t)parseInt(name, value, schema, count); 224 | } 225 | else if ("mastering_display_sei_y3" == name) { 226 | state->ctrl->mastering_display_sei_y3 = (int64_t)parseInt(name, value, schema, count); 227 | } 228 | else if ("mastering_display_sei_wx" == name) { 229 | state->ctrl->mastering_display_sei_wx = (int64_t)parseInt(name, value, schema, count); 230 | } 231 | else if ("mastering_display_sei_wy" == name) { 232 | state->ctrl->mastering_display_sei_wy = (int64_t)parseInt(name, value, schema, count); 233 | } 234 | else if ("mastering_display_sei_max_lum" == name) { 235 | state->ctrl->mastering_display_sei_max_lum = (int64_t)parseInt(name, value, schema, count); 236 | } 237 | else if ("mastering_display_sei_min_lum" == name) { 238 | state->ctrl->mastering_display_sei_min_lum = (int64_t)parseInt(name, value, schema, count); 239 | } 240 | else if ("light_level_max_content" == name) { 241 | state->ctrl->light_level_max_content = (int64_t)parseInt(name, value, schema, count); 242 | } 243 | else if ("light_level_max_frame_average" == name) { 244 | state->ctrl->light_level_max_frame_average = (int64_t)parseInt(name, value, schema, count); 245 | } 246 | else if ("force_slice_type" == name) { 247 | // The fact we handle this property means that encoder can force slice type 248 | state->ctrl->force_slice_type = parseBool(name, value, schema, count); 249 | } 250 | else if ("uhd_bd" == name) { 251 | // The fact we handle this property means that encoder can encode UHD-BD 252 | state->ctrl->uhd_bd = parseBool(name, value, schema, count); 253 | } 254 | else if ("preset" == name) { 255 | state->ctrl->preset = parseString(name, value, schema, count); 256 | } 257 | else if ("modifier" == name) { 258 | state->ctrl->modifier = parseStringList( 259 | name, value, "+", 260 | "low_delay:tune_psnr:realtime:cinema:bluray:hdr10:hlg:tune_vmaf:low_bitrate"); 261 | } 262 | else if ("gop_intra_period" == name) { 263 | state->ctrl->gop_intra_period = (uint16_t)parseInt(name, value, schema, count); 264 | } 265 | else if ("gop_idr_period" == name) { 266 | state->ctrl->gop_idr_period = (uint16_t)parseInt(name, value, schema, count); 267 | } 268 | else if ("gop_min_intra_period" == name) { 269 | state->ctrl->gop_min_intra_period = (uint8_t)parseInt(name, value, schema, count); 270 | } 271 | else if ("gop_minigop_size" == name) { 272 | state->ctrl->gop_minigop_size = (uint8_t)parseInt(name, value, schema, count); 273 | } 274 | else if ("gop_min_minigop_size" == name) { 275 | state->ctrl->gop_min_minigop_size = (uint8_t)parseInt(name, value, schema, count); 276 | } 277 | else if ("gop_max_refs" == name) { 278 | state->ctrl->gop_max_refs = (uint8_t)parseInt(name, value, schema, count); 279 | } 280 | else if ("me_scene_change" == name) { 281 | state->ctrl->me_scene_change = (uint8_t)parseInt(name, value, schema, count); 282 | } 283 | else if ("pps_cb_qp_offset" == name) { 284 | state->ctrl->pps_cb_qp_offset = (uint32_t)parseInt(name, value, schema, count); 285 | } 286 | else if ("pps_cr_qp_offset" == name) { 287 | state->ctrl->pps_cr_qp_offset = (uint32_t)parseInt(name, value, schema, count); 288 | } 289 | else if ("native_config_file" == name) { 290 | state->ctrl->native_config_file = value; 291 | } 292 | else if ("param" == name) { 293 | state->ctrl->param.push_back(value); 294 | } 295 | else if ("gop_structure_in_file" == name) { 296 | state->ctrl->gop_structure_in_file = value; 297 | } 298 | else if ("gop_structure_out_file" == name) { 299 | state->ctrl->gop_structure_out_file = value; 300 | } 301 | else if ("debug_level" == name) { 302 | state->ctrl->debug_level = (int)parseInt(name, value, schema, count); 303 | } 304 | else if ("color_space" == name) { 305 | continue; //hardcoded to i420 anyways 306 | } 307 | else { 308 | state->ctrl->msg += "\nUnknown property: " + name; 309 | } 310 | } 311 | catch (std::exception& e) { 312 | state->ctrl->msg += "\n" + std::string(e.what()); 313 | } 314 | } 315 | 316 | if (state->ctrl->msg.size()) { 317 | return STATUS_ERROR; 318 | } 319 | 320 | state->encoder->init(*state->ctrl); 321 | 322 | if (!state->ctrl->msg.empty()) { 323 | return STATUS_ERROR; 324 | } 325 | else { 326 | state->ctrl->msg += state->encoder->getVersion(); 327 | } 328 | 329 | std::ifstream beamrCfg(state->ctrl->temp_file[0]); 330 | std::string line; 331 | while (std::getline(beamrCfg, line)) { 332 | state->ctrl->msg += "\n"; 333 | state->ctrl->msg += line; 334 | } 335 | state->ctrl->msg += state->encoder->getMessage(); 336 | } 337 | catch (std::exception& e) { 338 | state->ctrl->msg = std::string(e.what()); 339 | auto debugMsg = state->encoder->getMessage(); 340 | if (debugMsg.size()) 341 | state->ctrl->msg = debugMsg + "\n" + state->ctrl->msg; 342 | return STATUS_ERROR; 343 | } 344 | return STATUS_OK; 345 | } 346 | 347 | static Status close(HevcEncHandle handle) { 348 | PluginContext* state = (PluginContext*)handle; 349 | state->ctrl->msg.clear(); 350 | try { 351 | if (state->encoder) 352 | state->encoder->close(); 353 | 354 | if (state->ctrl) { 355 | delete state->ctrl; 356 | state->ctrl = nullptr; 357 | } 358 | 359 | if (state->encoder) { 360 | delete state->encoder; 361 | state->encoder = nullptr; 362 | } 363 | } 364 | catch (std::exception& e) { 365 | state->ctrl->msg = std::string(e.what()); 366 | auto debugMsg = state->encoder->getMessage(); 367 | if (debugMsg.size()) 368 | state->ctrl->msg = debugMsg + "\n" + state->ctrl->msg; 369 | return STATUS_ERROR; 370 | } 371 | return STATUS_OK; 372 | } 373 | 374 | static Status 375 | process(HevcEncHandle handle, const HevcEncPicture* picture, const size_t pictureNum, HevcEncOutput* output) { 376 | PluginContext* state = (PluginContext*)handle; 377 | state->ctrl->msg.clear(); 378 | try { 379 | for (size_t i = 0; i < pictureNum; i++) 380 | state->encoder->feed(&picture[i]); 381 | 382 | state->encoder->getNal(output, state->ctrl->max_output_data); 383 | state->ctrl->msg = state->encoder->getMessage(); 384 | return STATUS_OK; 385 | } 386 | catch (std::exception& e) { 387 | state->ctrl->msg = std::string(e.what()); 388 | auto debugMsg = state->encoder->getMessage(); 389 | if (debugMsg.size()) 390 | state->ctrl->msg = debugMsg + "\n" + state->ctrl->msg; 391 | return STATUS_ERROR; 392 | } 393 | } 394 | 395 | static Status flush(HevcEncHandle handle, HevcEncOutput* output, int* isEmpty) { 396 | PluginContext* state = (PluginContext*)handle; 397 | state->ctrl->msg.clear(); 398 | try { 399 | state->encoder->flush(); 400 | state->encoder->getNal(output, state->ctrl->max_output_data); 401 | state->ctrl->msg = state->encoder->getMessage(); 402 | *isEmpty = (output->nalNum == 0); 403 | return STATUS_OK; 404 | } 405 | catch (std::exception& e) { 406 | state->ctrl->msg = std::string(e.what()); 407 | auto debugMsg = state->encoder->getMessage(); 408 | if (debugMsg.size()) 409 | state->ctrl->msg = debugMsg + "\n" + state->ctrl->msg; 410 | return STATUS_ERROR; 411 | } 412 | } 413 | 414 | static Status setProperty(HevcEncHandle handle, const Property* property) { 415 | PluginContext* state = (PluginContext*)handle; 416 | 417 | if (state->ctrl) { 418 | state->ctrl->msg.clear(); 419 | if (property->name == std::string("max_output_data")) { 420 | state->ctrl->max_output_data = atoi(property->value); 421 | return STATUS_OK; 422 | } 423 | } 424 | 425 | return STATUS_ERROR; 426 | } 427 | 428 | static Status getProperty(HevcEncHandle handle, Property* property) { 429 | PluginContext* state = (PluginContext*)handle; 430 | if (state->ctrl) 431 | state->ctrl->msg.clear(); 432 | 433 | if (NULL != property->name) { 434 | std::string name(property->name); 435 | if ("max_pass_num" == name) { 436 | strcpy(property->value, "2"); 437 | return STATUS_OK; 438 | } 439 | else if ("temp_file_num" == name) { 440 | strcpy(property->value, "1"); 441 | return STATUS_OK; 442 | } 443 | } 444 | return STATUS_ERROR; 445 | } 446 | 447 | static const char* getMessage(HevcEncHandle handle) { 448 | PluginContext* state = (PluginContext*)handle; 449 | if (state && state->ctrl) 450 | return state->ctrl->msg.empty() ? NULL : state->ctrl->msg.c_str(); 451 | else 452 | return NULL; 453 | } 454 | 455 | static HevcEncApi beamrPluginApi = {pluginName.c_str(), getInfo, getSize, init, close, process, flush, 456 | setProperty, getProperty, getMessage}; 457 | 458 | DLB_EXPORT 459 | HevcEncApi* hevcEncGetApi() { 460 | return &beamrPluginApi; 461 | } 462 | 463 | DLB_EXPORT 464 | int hevcEncGetApiVersion() { 465 | return HEVC_ENC_API_VERSION; 466 | } 467 | -------------------------------------------------------------------------------- /plugins/code/hevc_enc/x265/src/hevc_enc_x265.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD 3-Clause License 3 | * 4 | * Copyright (c) 2017-2019, Dolby Laboratories 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #include "hevc_enc_api.h" 34 | #include "hevc_enc_x265_utils.h" 35 | #include 36 | #include 37 | 38 | static 39 | const 40 | PropertyInfo hevc_enc_x265_info[] = 41 | { 42 | 43 | {"max_pass_num", PROPERTY_TYPE_INTEGER, "Indicates how many passes encoder can perform (0 = unlimited).", "3", NULL, 0, 1, ACCESS_TYPE_READ} 44 | ,{"max_output_data", PROPERTY_TYPE_INTEGER, "Limits number of output bytes (0 = unlimited).", "0", NULL, 0, 1, ACCESS_TYPE_WRITE} 45 | ,{"bit_depth", PROPERTY_TYPE_STRING, NULL, NULL, "8:10", 1, 1, ACCESS_TYPE_WRITE_INIT} 46 | ,{"width", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT} 47 | ,{"height", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT} 48 | ,{"color_space", PROPERTY_TYPE_STRING, NULL, "i420", "i400:i420:i422:i444", 0, 1, ACCESS_TYPE_WRITE_INIT} 49 | ,{"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60:119.88:120", 1, 1, ACCESS_TYPE_WRITE_INIT} 50 | ,{"data_rate", PROPERTY_TYPE_INTEGER, "Average data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT} 51 | ,{"max_vbv_data_rate", PROPERTY_TYPE_INTEGER, "Max VBV data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT} 52 | ,{"vbv_buffer_size", PROPERTY_TYPE_INTEGER, "VBV buffer size in kb.", "30000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT} 53 | ,{"range", PROPERTY_TYPE_STRING, NULL, "full", "limited:full", 0, 1, ACCESS_TYPE_WRITE_INIT} 54 | ,{"multi_pass", PROPERTY_TYPE_STRING, NULL, "off", "off:1st:nth:last", 0, 1, ACCESS_TYPE_WRITE_INIT} 55 | ,{"stats_file", PROPERTY_TYPE_STRING, NULL, NULL, NULL, 0, 1, ACCESS_TYPE_WRITE_INIT} 56 | 57 | , { "color_primaries", PROPERTY_TYPE_STRING, NULL, "unspecified", "unspecified:bt_709:bt_601_625:bt_601_525:bt_2020", 0, 1, ACCESS_TYPE_WRITE_INIT } 58 | , { "transfer_characteristics", PROPERTY_TYPE_STRING, NULL, "unspecified", "unspecified:bt_709:bt_601_625:bt_601_525:smpte_st_2084:std_b67", 0, 1, ACCESS_TYPE_WRITE_INIT } 59 | , { "matrix_coefficients", PROPERTY_TYPE_STRING, NULL, "unspecified", "unspecified:bt_709:bt_601_625:bt_601_525:bt_2020", 0, 1, ACCESS_TYPE_WRITE_INIT } 60 | , { "chromaloc", PROPERTY_TYPE_INTEGER, NULL, "0", "0:5", 0, 1, ACCESS_TYPE_WRITE_INIT } 61 | 62 | // master-display 63 | ,{ "mastering_display_sei_x1", PROPERTY_TYPE_INTEGER, "First primary x.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 64 | ,{ "mastering_display_sei_y1", PROPERTY_TYPE_INTEGER, "First primary y.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 65 | ,{ "mastering_display_sei_x2", PROPERTY_TYPE_INTEGER, "Second primary x.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 66 | ,{ "mastering_display_sei_y2", PROPERTY_TYPE_INTEGER, "Second primary y.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 67 | ,{ "mastering_display_sei_x3", PROPERTY_TYPE_INTEGER, "Third primary x.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 68 | ,{ "mastering_display_sei_y3", PROPERTY_TYPE_INTEGER, "Third primary y.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 69 | ,{ "mastering_display_sei_wx", PROPERTY_TYPE_INTEGER, "White point x.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 70 | ,{ "mastering_display_sei_wy", PROPERTY_TYPE_INTEGER, "White point y.", "0", "0:50000", 0, 1, ACCESS_TYPE_WRITE_INIT } 71 | ,{ "mastering_display_sei_max_lum", PROPERTY_TYPE_INTEGER, "Maximum display luminance.", "0", "0:2000000000", 0, 1, ACCESS_TYPE_WRITE_INIT } 72 | ,{ "mastering_display_sei_min_lum", PROPERTY_TYPE_INTEGER, "Minimum display luminance.", "0", "0:2000000000", 0, 1, ACCESS_TYPE_WRITE_INIT } 73 | 74 | // max-cll 75 | ,{ "light_level_max_content", PROPERTY_TYPE_INTEGER, NULL, "0", "0:65535", 0, 1, ACCESS_TYPE_WRITE_INIT } 76 | ,{ "light_level_max_frame_average", PROPERTY_TYPE_INTEGER, NULL, "0", "0:65535", 0, 1, ACCESS_TYPE_WRITE_INIT } 77 | 78 | ,{ "force_slice_type", PROPERTY_TYPE_BOOLEAN, "Indicates that framework will try to force specific slice type.", "false", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT } 79 | 80 | // Only properties below (ACCESS_TYPE_USER) can be modified 81 | ,{"preset", PROPERTY_TYPE_STRING, "Sets parameters to preselected values.", "medium", "placebo:veryslow:slower:slow:medium:fast:faster:veryfast:superfast:ultrafast", 0, 1, ACCESS_TYPE_USER} 82 | ,{"tune", PROPERTY_TYPE_STRING, "Tune the settings for a particular type of source or situation.", "none", "none:psnr:ssim:grain:fastdecode:zerolatency", 0, 1, ACCESS_TYPE_USER} 83 | ,{"open_gop", PROPERTY_TYPE_BOOLEAN, "Allows I-slices to be non-IDR.", "false", NULL, 0, 1, ACCESS_TYPE_USER} 84 | ,{"max_intra_period", PROPERTY_TYPE_INTEGER, "Max intra period in frames.", "25", "1:65535", 0, 1, ACCESS_TYPE_USER} 85 | ,{"min_intra_period", PROPERTY_TYPE_INTEGER, "Min intra period in frames (0 = auto).", "0", "0:65535", 0, 1, ACCESS_TYPE_USER} 86 | ,{"intra_refresh", PROPERTY_TYPE_BOOLEAN, "Enables Periodic Intra Refresh(PIR) instead of keyframe insertion.", "false", NULL, 0, 1, ACCESS_TYPE_USER} 87 | ,{"max_bframes", PROPERTY_TYPE_INTEGER, "Maximum number of consecutive b-frames.", "4", "0:16", 0, 1, ACCESS_TYPE_USER} 88 | ,{"scenecut", PROPERTY_TYPE_INTEGER, "Defines how aggressively I-frames need to be inserted. The higher the threshold value, the more aggressive the I-frame placement. Value 0 disables adaptive I frame placement", "40", NULL, 0, 1, ACCESS_TYPE_USER} 89 | ,{"scenecut_bias", PROPERTY_TYPE_INTEGER, "Represents the percentage difference between the inter cost and intra cost of a frame used in scenecut detection. Values between 5 and 15 are recommended.", "5", "0:100", 0, 1, ACCESS_TYPE_USER} 90 | ,{"lookahead_frames", PROPERTY_TYPE_INTEGER, "Number of frames to look ahead. Must be between the maximum consecutive bframe count and 250.", "20", "0:250", 0, 1, ACCESS_TYPE_USER} 91 | ,{"concatenation_flag", PROPERTY_TYPE_BOOLEAN, "Set concatenation flag in 1st buffer timing SEI.", "false", "", 0, 1, ACCESS_TYPE_USER } 92 | ,{"info", PROPERTY_TYPE_BOOLEAN, "Enables informational SEI in the stream headers which describes the encoder version, build info, and encode parameters.", "false", NULL, 0, 1, ACCESS_TYPE_USER } 93 | ,{"frame_threads", PROPERTY_TYPE_INTEGER, "Number of concurrently encoded frames (0 = autodetect). Value 1 can improve encode quality, but significantly reduces performance.", "0", "0:16", 0, 1, ACCESS_TYPE_USER } 94 | ,{"nr_inter", PROPERTY_TYPE_INTEGER, "Inter frame noise reduction strength (0 = disabled).", "0", "0:2000", 0, 1, ACCESS_TYPE_USER } 95 | ,{"nr_intra", PROPERTY_TYPE_INTEGER, "Intra frame noise reduction strength (0 = disabled).", "0", "0:2000", 0, 1, ACCESS_TYPE_USER } 96 | ,{"cbqpoffs", PROPERTY_TYPE_INTEGER, "Offset of Cb chroma QP from the luma QP selected by rate control.", "0", "-12:12", 0, 1, ACCESS_TYPE_USER } 97 | ,{"crqpoffs", PROPERTY_TYPE_INTEGER, "Offset of Cr chroma QP from the luma QP selected by rate control.", "0", "-12:12", 0, 1, ACCESS_TYPE_USER } 98 | 99 | ,{"min_cu_size", PROPERTY_TYPE_STRING, "Minimum CU size (width and height).", "8", "8:16:32", 0, 1, ACCESS_TYPE_USER } 100 | ,{"max_cu_size", PROPERTY_TYPE_STRING, "Maximum CU size (width and height).", "64", "16:32:64", 0, 1, ACCESS_TYPE_USER } 101 | ,{"qg_size", PROPERTY_TYPE_STRING, "Enable adaptive quantization for sub-CTUs. ", "64", "16:32:64", 0, 1, ACCESS_TYPE_USER } 102 | ,{"rc_grain", PROPERTY_TYPE_BOOLEAN, "Enables a specialized ratecontrol algorithm for film grain content.", "false", NULL, 0, 1, ACCESS_TYPE_USER } 103 | ,{"level_idc", PROPERTY_TYPE_STRING, "Minimum decoder requirement level.", "0", "0:1.0:10:2.0:20:2.1:21:3.0:30:3.1:31:4.0:40:4.1:41:5.0:50:5.1:51:5.2:52:6.0:60:6.1:61:6.2:62:8.5:85", 0, 1, ACCESS_TYPE_USER } 104 | ,{"psy_rd", PROPERTY_TYPE_DECIMAL, "Influence rate distortion optimized mode decision to preserve the energy of the source image in the encoded image at the expense of compression efficiency.", "2.0", "0:5", 0, 1, ACCESS_TYPE_USER } 105 | ,{"wpp", PROPERTY_TYPE_BOOLEAN, "Enable Wavefront Parallel Processing.", "false", NULL, 0, 1, ACCESS_TYPE_USER } 106 | 107 | ,{"profile", PROPERTY_TYPE_STRING, "Enforce the requirements of the specified HEVC profile", "auto", "auto:main:main10:main-intra:main10-intra:main444-8:main444-intra:main422-10:main422-10-intra:main444-10:main444-10-intra:main12:main12-intra:main422-12:main422-12-intra:main444-12:main444-12-intra", 0, 1, ACCESS_TYPE_USER } 108 | ,{"param", PROPERTY_TYPE_STRING, "Sets any x265 parameter using syntax \"name=value\" or just \"name\" for boolean flags. Use ':' separator to enter multiple values under one tag. If value contains colon, use semicolon instead.", NULL, NULL, 0, 100, ACCESS_TYPE_USER} 109 | }; 110 | 111 | static 112 | size_t 113 | x265_get_info 114 | (const PropertyInfo** info 115 | ) 116 | { 117 | *info = hevc_enc_x265_info; 118 | return sizeof(hevc_enc_x265_info)/sizeof(PropertyInfo); 119 | } 120 | 121 | static 122 | size_t 123 | x265_get_size() 124 | { 125 | return sizeof(hevc_enc_x265_t); 126 | } 127 | 128 | static 129 | Status 130 | x265_init 131 | (HevcEncHandle handle 132 | ,const HevcEncInitParams* init_params 133 | ) 134 | { 135 | const x265_api* api; 136 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 137 | state->data = new hevc_enc_x265_data_t; 138 | init_defaults(state); 139 | state->lib_initialized = false; 140 | state->data->pending_header = true; 141 | state->data->msg.clear(); 142 | state->data->last_used_nal = state->data->output_buffer.begin(); 143 | 144 | try 145 | { 146 | if (!parse_init_params(state, init_params)) 147 | { 148 | std::string errmsg = "Parsing init params failed:" + state->data->msg; 149 | state->data->msg = errmsg; 150 | return STATUS_ERROR; 151 | } 152 | } 153 | catch (...) 154 | { 155 | std::string errmsg = "An exception occurred when parsing init params. " + state->data->msg; 156 | state->data->msg = errmsg; 157 | return STATUS_ERROR; 158 | } 159 | 160 | 161 | if (0 == state->data->max_output_data) 162 | { 163 | state->data->max_output_data = INT32_MAX; 164 | } 165 | 166 | // CRF mode does not support 'hrd' option, which is required 167 | if (0 == state->data->data_rate) 168 | { 169 | state->data->msg = "CRF encoding is not supported."; 170 | return STATUS_ERROR; 171 | } 172 | 173 | if (state->data->qg_size < state->data->min_cu_size || state->data->qg_size > state->data->max_cu_size) 174 | { 175 | state->data->msg = "qg_size must be a value between min_cu_size and max_cu_size."; 176 | return STATUS_ERROR; 177 | } 178 | 179 | api = state->api = x265_api_get(state->data->bit_depth); 180 | if (!api) 181 | { 182 | state->data->msg = "x265_api_get() failed for " + std::to_string(state->data->bit_depth) + " bit."; 183 | return STATUS_ERROR; 184 | } 185 | 186 | state->param = api->param_alloc(); 187 | 188 | if (!state->param) 189 | { 190 | state->data->msg = "param_alloc() failed."; 191 | return STATUS_ERROR; 192 | } 193 | 194 | api->param_default(state->param); 195 | state->param->forceFlush = 0; 196 | 197 | bool ok = set_preset(state, state->data->preset, state->data->tune); 198 | 199 | std::list> native_params; 200 | 201 | if(state->data->force_slice_type) 202 | { 203 | state->data->max_intra_period = 65535; 204 | state->data->min_intra_period = 0; 205 | } 206 | 207 | auto num_denom = fps_to_num_denom(state->data->frame_rate); 208 | std::string fps_arg = std::to_string(num_denom.first) + "/" + std::to_string(num_denom.second); 209 | 210 | native_params.push_back({"annexb", ""}); 211 | native_params.push_back({"repeat-headers", ""}); 212 | native_params.push_back({"aud", ""}); 213 | native_params.push_back({"hrd", ""}); 214 | native_params.push_back({"hash", "1"}); 215 | native_params.push_back({"log-level", "0"}); 216 | native_params.push_back({"sar", "1"}); 217 | native_params.push_back({"input-csp", state->data->color_space}); 218 | native_params.push_back({"input-res", std::to_string(state->data->width)+"x"+std::to_string(state->data->height)}); 219 | native_params.push_back({"fps", fps_arg}); 220 | native_params.push_back({state->data->open_gop ? "open-gop" : "no-open-gop", ""}); 221 | native_params.push_back({state->data->info ? "info" : "no-info", ""}); 222 | native_params.push_back({"keyint", std::to_string(state->data->max_intra_period)}); 223 | native_params.push_back({"min-keyint", std::to_string(state->data->min_intra_period)}); 224 | native_params.push_back({"bframes", std::to_string(state->data->max_bframes)}); 225 | native_params.push_back({"rc-lookahead", std::to_string(state->data->lookahead_frames)}); 226 | if (state->data->intra_refresh) native_params.push_back({"intra-refresh", ""}); 227 | 228 | native_params.push_back({"bitrate", std::to_string(state->data->data_rate)}); 229 | native_params.push_back({"vbv-maxrate", std::to_string(state->data->max_vbv_data_rate)}); 230 | native_params.push_back({"vbv-bufsize", std::to_string(state->data->vbv_buffer_size)}); 231 | 232 | native_params.push_back({"range", state->data->range}); 233 | 234 | native_params.push_back({"frame-threads", std::to_string(state->data->frame_threads)}); 235 | native_params.push_back({"nr-inter", std::to_string(state->data->nr_inter)}); 236 | native_params.push_back({"nr-intra", std::to_string(state->data->nr_intra)}); 237 | native_params.push_back({"cbqpoffs", std::to_string(state->data->cbqpoffs)}); 238 | native_params.push_back({"crqpoffs", std::to_string(state->data->crqpoffs)}); 239 | 240 | native_params.push_back({"scenecut", std::to_string(state->data->scenecut)}); 241 | native_params.push_back({"scenecut-bias", std::to_string(state->data->scenecut_bias)}); 242 | 243 | native_params.push_back({"min-cu-size", std::to_string(state->data->min_cu_size)}); 244 | native_params.push_back({"ctu", std::to_string(state->data->max_cu_size)}); 245 | native_params.push_back({"qg-size", std::to_string(state->data->qg_size)}); 246 | native_params.push_back({state->data->rc_grain ? "rc-grain" : "no-rc-grain", ""}); 247 | native_params.push_back({"level-idc", state->data->level_idc}); 248 | native_params.push_back({state->data->wpp ? "wpp" : "no-wpp", ""}); 249 | native_params.push_back({"psy-rd", state->data->psy_rd}); 250 | native_params.push_back({"colorprim", std::to_string(get_color_prim_number(state->data->color_primaries))}); 251 | native_params.push_back({"transfer", std::to_string(get_transfer_characteristics_number(state->data->transfer_characteristics))}); 252 | native_params.push_back({"colormatrix", std::to_string(get_matrix_coefficients_number(state->data->matrix_coefficients))}); 253 | native_params.push_back({"chromaloc", state->data->chromaSampleLocation}); 254 | 255 | if (state->data->concatenation_flag) native_params.push_back({"hrd-concat", ""}); 256 | 257 | 258 | if (state->data->mastering_display_enabled == true) 259 | { 260 | // --master-display G(gx,gy)B(bx,by)R(rx,ry)WP(wpx,wpy)L(max_peak_lum,min_peak_lum) 261 | std::string master_display = 262 | "G(" + std::to_string(state->data->mastering_display_sei_x1) + "," + std::to_string(state->data->mastering_display_sei_y1) + ")" 263 | + "B(" + std::to_string(state->data->mastering_display_sei_x2) + "," + std::to_string(state->data->mastering_display_sei_y2) + ")" 264 | + "R(" + std::to_string(state->data->mastering_display_sei_x3) + "," + std::to_string(state->data->mastering_display_sei_y3) + ")" 265 | + "WP(" + std::to_string(state->data->mastering_display_sei_wx) + "," + std::to_string(state->data->mastering_display_sei_wy) + ")" 266 | + "L(" + std::to_string(state->data->mastering_display_sei_max_lum) + "," + std::to_string(state->data->mastering_display_sei_min_lum) + ")"; 267 | native_params.push_back({"master-display", master_display}); 268 | } 269 | 270 | if (state->data->light_level_enabled == true) 271 | { 272 | // --max-cll max_cll,max_fall 273 | std::string max_cll = std::to_string(state->data->light_level_max_content) + "," + std::to_string(state->data->light_level_max_frame_average); 274 | native_params.push_back({"max-cll", max_cll}); 275 | } 276 | 277 | if (state->data->uhd_bd == true) 278 | { 279 | native_params.push_back({"level-idc", "5.1"}); 280 | native_params.push_back({"uhd-bd", ""}); 281 | /* When encoding Dolby Vision profile 7 (BD), placement of B/P frames must be deterministic. 282 | This can be achieved by forcing B frame every time. 283 | IDRs and P frames are still emitted, but only at known positions. 284 | It should change the interpretation of option "bframes", from "max", to "exact" number. */ 285 | native_params.push_back({"b-adapt", "0"}); 286 | } 287 | 288 | for (auto ip : state->data->internal_params) 289 | { 290 | native_params.push_back({ip.first, ip.second}); 291 | } 292 | 293 | if (state->data->multi_pass != "off") 294 | { 295 | if (state->data->multi_pass == "1st") native_params.push_back({"pass", "1"}); 296 | else if (state->data->multi_pass == "nth") native_params.push_back({"pass", "3"}); 297 | else if (state->data->multi_pass == "last") native_params.push_back({"pass", "2"}); 298 | 299 | if (!state->data->stats_file.empty()) native_params.push_back({"stats", state->data->stats_file}); 300 | } 301 | 302 | if (!filter_native_params(state, native_params)) 303 | { 304 | return STATUS_ERROR; 305 | } 306 | 307 | for (auto p : native_params) 308 | { 309 | if (!p.second.empty()) 310 | { 311 | ok &= set_param(state, p.first, p.second); 312 | } 313 | else 314 | { 315 | ok &= set_param(state, p.first, ""); 316 | } 317 | } 318 | 319 | if (state->data->profile != "auto") 320 | { 321 | if (x265_param_apply_profile(state->param, state->data->profile.c_str()) != 0) 322 | { 323 | std::string errmsg = "Setting profile " + state->data->profile + "failed."; 324 | state->data->msg = errmsg; 325 | return STATUS_ERROR; 326 | } 327 | } 328 | 329 | if (!ok) 330 | { 331 | std::string errmsg = "Setting params failed:" + state->data->msg; 332 | state->data->msg = errmsg; 333 | return STATUS_ERROR; 334 | } 335 | 336 | state->encoder = api->encoder_open(state->param); 337 | if (!state->encoder) 338 | { 339 | state->data->msg = "encoder_open() failed."; 340 | return STATUS_ERROR; 341 | } 342 | state->lib_initialized = true; 343 | 344 | get_config_msg(state, native_params, state->data->msg); 345 | return STATUS_OK; 346 | } 347 | 348 | static 349 | Status 350 | x265_close 351 | (HevcEncHandle handle 352 | ) 353 | { 354 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 355 | state->data->msg.clear(); 356 | 357 | if (state->lib_initialized) 358 | { 359 | state->api->encoder_close(state->encoder); 360 | state->api->cleanup(); 361 | state->lib_initialized = false; 362 | } 363 | 364 | // Stats file is set and removed by caller, 365 | // but cutree file has to be handled by plugin. 366 | if (!state->data->stats_file.empty() && "last" == state->data->multi_pass) 367 | { 368 | std::string cutree_file = state->data->stats_file + ".cutree"; 369 | std::remove(cutree_file.c_str()); 370 | } 371 | 372 | if (state->data) { 373 | delete state->data; 374 | state->data = nullptr; 375 | } 376 | if (state->param) state->api->param_free(state->param); 377 | 378 | 379 | return STATUS_OK; 380 | } 381 | 382 | static 383 | Status 384 | x265_process 385 | (HevcEncHandle handle 386 | ,const HevcEncPicture* picture 387 | ,const size_t picture_num 388 | ,HevcEncOutput* output 389 | ) 390 | { 391 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 392 | 393 | x265_nal *p_nal; 394 | uint32_t nal_count = 0; 395 | state->data->msg.clear(); 396 | 397 | if (state->data->pending_header && !state->param->bRepeatHeaders) 398 | { 399 | state->data->pending_header = false; 400 | if (state->api->encoder_headers(state->encoder, &p_nal, &nal_count) < 0) 401 | { 402 | state->data->msg = "Failure generating stream headers."; 403 | return STATUS_ERROR; 404 | } 405 | if (nal_count) 406 | { 407 | for (uint32_t j = 0; j < nal_count; j++) 408 | { 409 | nalu_t nalu; 410 | nalu.type = cast_nal_type(p_nal[j].type); 411 | nalu.payload.resize(p_nal[j].sizeBytes); 412 | memcpy(nalu.payload.data(), p_nal[j].payload, p_nal[j].sizeBytes); 413 | state->data->output_buffer.push_back(nalu); 414 | } 415 | } 416 | } 417 | else if (state->data->last_used_nal != state->data->output_buffer.begin()) 418 | { 419 | state->data->output_buffer.erase(state->data->output_buffer.begin(), state->data->last_used_nal); 420 | } 421 | 422 | x265_picture input_picture; 423 | state->api->picture_init(state->param, &input_picture); 424 | for (size_t i = 0; i < picture_num; i++) 425 | { 426 | input_picture.bitDepth = picture[i].bitDepth; 427 | 428 | if (input_picture.bitDepth != state->data->bit_depth) 429 | { 430 | state->data->msg = "Bit depth mismatch."; 431 | return STATUS_ERROR; 432 | } 433 | 434 | input_picture.colorSpace = picture[i].colorSpace; 435 | input_picture.sliceType = frametype_to_slicetype(picture[i].frameType); 436 | 437 | int width = (int)picture[i].width; 438 | int height = (int)picture[i].height; 439 | uint32_t framesize = 0; 440 | uint32_t pixelbytes = input_picture.bitDepth > 8 ? 2 : 1; 441 | for (int j = 0; j < x265_cli_csps[input_picture.colorSpace].planes; j++) 442 | { 443 | uint32_t w = width >> x265_cli_csps[input_picture.colorSpace].width[j]; 444 | uint32_t h = height >> x265_cli_csps[input_picture.colorSpace].height[j]; 445 | framesize += w * h * pixelbytes; 446 | } 447 | 448 | input_picture.height = height; 449 | input_picture.framesize = framesize; 450 | input_picture.stride[0] = picture[i].stride[0]; 451 | input_picture.stride[1] = picture[i].stride[1]; 452 | input_picture.stride[2] = picture[i].stride[2]; 453 | input_picture.planes[0] = picture[i].plane[0]; 454 | input_picture.planes[1] = picture[i].plane[1]; 455 | input_picture.planes[2] = picture[i].plane[2]; 456 | 457 | int num_encoded = state->api->encoder_encode(state->encoder, &p_nal, &nal_count, &input_picture, NULL); 458 | if (num_encoded < 0) 459 | { 460 | state->data->msg = "encoder_encode() failed."; 461 | return STATUS_ERROR; 462 | } 463 | for (uint32_t j = 0; j < nal_count; j++) 464 | { 465 | nalu_t nalu; 466 | nalu.type = cast_nal_type(p_nal[j].type); 467 | nalu.payload.resize(p_nal[j].sizeBytes); 468 | memcpy(nalu.payload.data(), p_nal[j].payload, p_nal[j].sizeBytes); 469 | state->data->output_buffer.push_back(nalu); 470 | } 471 | 472 | } 473 | 474 | size_t size_acc = 0; 475 | int nal_index = 0; 476 | state->data->last_used_nal = state->data->output_buffer.begin(); 477 | 478 | state->data->output.clear(); 479 | while (size_acc < state->data->max_output_data && nal_index < (int)state->data->output_buffer.size()) 480 | { 481 | HevcEncNal nal; 482 | nal.type = state->data->output_buffer[nal_index].type; 483 | nal.payload = (void*)state->data->output_buffer[nal_index].payload.data(); 484 | nal.size = state->data->output_buffer[nal_index].payload.size(); 485 | state->data->output.push_back(nal); 486 | size_acc += nal.size; 487 | nal_index += 1; 488 | state->data->last_used_nal++; 489 | } 490 | 491 | output->nal = state->data->output.data(); 492 | output->nalNum = state->data->output.size(); 493 | return STATUS_OK; 494 | } 495 | 496 | static 497 | Status 498 | x265_flush 499 | (HevcEncHandle handle 500 | ,HevcEncOutput* output 501 | ,int* is_empty 502 | ) 503 | { 504 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 505 | 506 | if (state->data->last_used_nal != state->data->output_buffer.begin()) 507 | { 508 | state->data->output_buffer.erase(state->data->output_buffer.begin(), state->data->last_used_nal); 509 | } 510 | 511 | x265_nal *p_nal; 512 | uint32_t nal_count = 0; 513 | int num_encoded = state->api->encoder_encode(state->encoder, &p_nal, &nal_count, NULL, NULL); 514 | if (num_encoded < 0) 515 | { 516 | state->data->msg = "encoder_encode() failed."; 517 | return STATUS_ERROR; 518 | } 519 | else if (0 == num_encoded) 520 | { 521 | *is_empty = 1; 522 | output->nalNum = 0; 523 | output->nal = NULL; 524 | return STATUS_OK; 525 | } 526 | 527 | for (uint32_t j = 0; j < nal_count; j++) 528 | { 529 | nalu_t nalu; 530 | nalu.type = cast_nal_type(p_nal[j].type); 531 | nalu.payload.resize(p_nal[j].sizeBytes); 532 | memcpy(nalu.payload.data(), p_nal[j].payload, p_nal[j].sizeBytes); 533 | state->data->output_buffer.push_back(nalu); 534 | } 535 | 536 | size_t size_acc = 0; 537 | int nal_index = 0; 538 | state->data->last_used_nal = state->data->output_buffer.begin(); 539 | 540 | state->data->output.clear(); 541 | while (size_acc < state->data->max_output_data && nal_index < (int)state->data->output_buffer.size()) 542 | { 543 | HevcEncNal nal; 544 | nal.type = state->data->output_buffer[nal_index].type; 545 | nal.payload = (void*)state->data->output_buffer[nal_index].payload.data(); 546 | nal.size = state->data->output_buffer[nal_index].payload.size(); 547 | state->data->output.push_back(nal); 548 | size_acc += nal.size; 549 | nal_index += 1; 550 | state->data->last_used_nal++; 551 | } 552 | 553 | output->nal = state->data->output.data(); 554 | output->nalNum = state->data->output.size(); 555 | *is_empty = 0; 556 | 557 | return STATUS_OK; 558 | } 559 | 560 | static 561 | Status 562 | x265_set_property 563 | (HevcEncHandle handle 564 | ,const Property* property 565 | ) 566 | { 567 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 568 | if (NULL == state) return STATUS_ERROR; 569 | 570 | if (property->name == std::string("max_output_data")) 571 | { 572 | state->data->max_output_data = atoi(property->value); 573 | return STATUS_OK; 574 | } 575 | 576 | return STATUS_ERROR; 577 | } 578 | 579 | static 580 | Status 581 | x265_get_property 582 | (HevcEncHandle handle 583 | ,Property* property 584 | ) 585 | { 586 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 587 | if (NULL == state) return STATUS_ERROR; 588 | 589 | if (NULL != property->name) 590 | { 591 | std::string name(property->name); 592 | if ("max_pass_num" == name) 593 | { 594 | strcpy(property->value, "3"); 595 | return STATUS_OK; 596 | } 597 | } 598 | return STATUS_ERROR; 599 | } 600 | 601 | static 602 | const char* 603 | x265_get_message 604 | (HevcEncHandle handle 605 | ) 606 | { 607 | hevc_enc_x265_t* state = (hevc_enc_x265_t*)handle; 608 | if (state && state->data) 609 | return state->data->msg.empty() ? NULL : state->data->msg.c_str(); 610 | else 611 | return NULL; 612 | } 613 | 614 | static 615 | HevcEncApi x265_plugin_api = 616 | { 617 | "x265" 618 | ,x265_get_info 619 | ,x265_get_size 620 | ,x265_init 621 | ,x265_close 622 | ,x265_process 623 | ,x265_flush 624 | ,x265_set_property 625 | ,x265_get_property 626 | ,x265_get_message 627 | }; 628 | 629 | DLB_EXPORT 630 | HevcEncApi* hevcEncGetApi() 631 | { 632 | return &x265_plugin_api; 633 | } 634 | 635 | DLB_EXPORT 636 | int hevcEncGetApiVersion() 637 | { 638 | return HEVC_ENC_API_VERSION; 639 | } 640 | --------------------------------------------------------------------------------