diff --git a/AutoAnswer/main.cpp b/AutoAnswer/main.cpp index dfed25f59ebbd466441b72c97628f6c6f12147c0..ad6a79eae77ce1752572c7bc4683ceaf569a0ffa 100644 --- a/AutoAnswer/main.cpp +++ b/AutoAnswer/main.cpp @@ -99,12 +99,8 @@ main () std::cout << "Version " << AutoAnswer_VERSION_MAJOR << "." << AutoAnswer_VERSION_MINOR << "." << AutoAnswer_VERSION_PATCH << std::endl << std::endl; - -#ifdef _WIN32 - std::ifstream file = std::ifstream(string_utils::to_wstring("testPreferences.yml")); -#else - std::ifstream file = std::ifstream("testPreferences.yml", std::ios_base::in); -#endif + std::ifstream file; + file_utils::openStream(file, "testPreferences.yml"); assert(file.is_open()); YAML::Node node = YAML::Load(file); diff --git a/GreenScreen/.gitignore b/GreenScreen/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..cc42585b64ae15650b9cf8348aedbb50dd8532d3 --- /dev/null +++ b/GreenScreen/.gitignore @@ -0,0 +1,5 @@ +/GreenScreen +/libonnxruntime.so.1.6.0 +*.mp4 +GreenScreen* +/libonnxruntime.dylib diff --git a/GreenScreen/CMakeLists.txt b/GreenScreen/CMakeLists.txt index 3a65bd217cefce50c52a43e876504bfd54c3ea62..db5ad07b2a965e518a653e2d40bd9db6d6249b34 100644 --- a/GreenScreen/CMakeLists.txt +++ b/GreenScreen/CMakeLists.txt @@ -25,6 +25,8 @@ if(WIN32) set (CONTRIB_PLATFORM ${CONTRIB_PLATFORM_CURT}-windows) set (LIBRARY_FILE_NAME ${ProjectName}.dll) set (FFMPEG ${CONTRIB_PATH}/build/ffmpeg/Build/win32/x64) +else() + message( FATAL_ERROR "\nUse CMake only for Windows! For linux or Android (linux host), use our bash scripts." ) endif() message(Building:\ ${ProjectName}\ ${Version}) @@ -46,8 +48,14 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + +if(TESTPROCESS) + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D__DEBUG__ /MT") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /D__DEBUG__ /MT") +else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MT") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") +endif() set(plugin_SRC main.cpp pluginMediaHandler.cpp @@ -56,6 +64,7 @@ set(plugin_SRC main.cpp ./../lib/accel.cpp ./../lib/frameUtils.cpp ./../lib/frameFilter.cpp + ./../lib/common.cpp ) set(plugin_HDR pluginMediaHandler.h @@ -64,16 +73,19 @@ set(plugin_HDR pluginMediaHandler.h ./../lib/pluglog.h ./../lib/mediaStream.h ./../lib/audioFormat.h + ./../lib/common.h ) +if(TESTPROCESS) + add_executable(${ProjectName} ${plugin_SRC} + ${plugin_HDR} + ) +else() + add_library(${ProjectName} SHARED ${plugin_SRC} + ${plugin_HDR} + ) +endif() - -# add the library -add_library(${ProjectName} SHARED ${plugin_SRC} - ${plugin_HDR} - ) - -if (WIN32) target_include_directories(${ProjectName} PUBLIC ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} ${PLUGINS_LIB} @@ -84,6 +96,7 @@ target_include_directories(${ProjectName} PUBLIC ${PROJECT_BINARY_DIR} ${CONTRIB_PATH}/build/opencv/build/install/include ${ONNX_DIR}/../include/session ${ONNX_DIR}/../include/providers/cuda + ${CONTRIB_PATH}/build/yaml-cpp/include ) target_link_directories(${ProjectName} PUBLIC ${CONTRIB_PATH} ${CONTRIB_PATH}/build/fmt/msvc/Release @@ -93,29 +106,47 @@ target_link_directories(${ProjectName} PUBLIC ${CONTRIB_PATH} ${ONNX_DIR} ${CONTRIB_PATH}/msvc/lib/x64 ${CONTRIB_PATH}/build/fmt/msvc/Release + ${CONTRIB_PATH}/build/yaml-cpp/msvc/Release ) -target_link_libraries(${ProjectName} PUBLIC libavfilter libswscale libavformat libavcodec libavutil libvpx libx264 libopus libmfx +target_link_libraries(${ProjectName} PUBLIC libyaml-cppmd libavfilter libswscale libavformat libavcodec libavutil libvpx libx264 libopus libmfx libzlib ws2_32 Bcrypt Secur32 opencv_imgproc460 opencv_core460 onnxruntime msvcrt) -endif() add_custom_command( TARGET ${ProjectName} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/zlib ${CONTRIB_PATH}/src/zlib COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ffmpeg/ ${CONTRIB_PATH}/src/ffmpeg + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/../contrib/yaml-cpp ${CONTRIB_PATH}/src/yaml-cpp + COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb yaml-cpp COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb zlib COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb ffmpeg - COMMAND python ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --preassemble --plugin=${ProjectName} - COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.lib ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} - COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.dll ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} - COMMAND ${CMAKE_COMMAND} -E make_directory ${JPL_DIRECTORY}/data/model - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/modelSRC/mModel.onnx ${JPL_DIRECTORY}/data/model - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/${PREFERENCESFILENAME}.json ${JPL_DIRECTORY}/data/preferences.json - COMMENT "Assembling Plugin files" + COMMAND cd ${CONTRIB_PATH}/src/ + COMMAND git checkout * ) - -if (WIN32) +if(TESTPROCESS) + add_custom_command( + TARGET ${ProjectName} + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/testPreferences.yml ${PROJECT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/sample.mp4 ${PROJECT_BINARY_DIR}/ + COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.lib ${PROJECT_BINARY_DIR}/Debug + COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.dll ${PROJECT_BINARY_DIR}/Debug + COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/data/model + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/modelSRC/mModel.onnx ${PROJECT_SOURCE_DIR}/data/model + ) +else() + add_custom_command( + TARGET ${ProjectName} + PRE_BUILD + COMMAND python ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --preassemble --plugin=${ProjectName} + COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.lib ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMAND ${CMAKE_COMMAND} -E copy ${ONNX_DIR}/onnxruntime.dll ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMAND ${CMAKE_COMMAND} -E make_directory ${JPL_DIRECTORY}/data/model + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/modelSRC/mModel.onnx ${JPL_DIRECTORY}/data/model + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/${PREFERENCESFILENAME}.json ${JPL_DIRECTORY}/data/preferences.json + COMMENT "Assembling Plugin files" + ) add_custom_command( TARGET ${ProjectName} POST_BUILD @@ -124,5 +155,4 @@ if (WIN32) COMMAND python ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --assemble --plugin=${ProjectName} --extraPath=${EXTRA_PATH} COMMENT "Generating JPL archive" ) - endif() diff --git a/GreenScreen/build.sh b/GreenScreen/build.sh index 5118613b1588c5a7ee339ee27aecf94f65185e02..725334de970fc57444b8ad7ff21681e78c3454e6 100755 --- a/GreenScreen/build.sh +++ b/GreenScreen/build.sh @@ -6,9 +6,10 @@ ARCH=$(uname -m) EXTRAPATH='' # Flags: - # -p: number of processors to use - # -c: Runtime plugin cpu/gpu setting. - # -t: target platform. +# -p: number of processors to use. +# -c: Runtime plugin cpu/gpu setting. +# -t: target platform. +# -d: debug program. if [ -z "${DAEMON}" ]; then DAEMON="./../../daemon" @@ -50,8 +51,12 @@ elif [ "${PROCESSOR}" = "NVIDIA" ]; then PREFERENCESFILENAME="${PREFERENCESFILENAME}-accel" fi -while getopts t:c:p OPT; do +while getopts t:c:p:d OPT; do case "$OPT" in + d) + DEBUG=true + export __DEBUG__=true + ;; t) PLATFORM="${OPTARG}" if [ ${PLATFORM} = "android" ]; then @@ -69,6 +74,7 @@ while getopts t:c:p OPT; do done cp -r ffmpeg ${CONTRIB_PATH}/src/ +cp -r ../contrib/rav1e ${CONTRIB_PATH}/src/ if [ "${PLATFORM}" = "linux-gnu" ] || [ "${PLATFORM}" = "redhat-linux" ] then @@ -81,8 +87,6 @@ then rm .ffmpeg cd ${WORKPATH} - python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME} - CONTRIB_PLATFORM=${CONTRIB_PLATFORM_CURT}-${PLATFORM} ONNX_PATH=${EXTRALIBS_PATH} if [ -z "${EXTRALIBS_PATH}" ] @@ -90,13 +94,23 @@ then ONNX_PATH="${CONTRIB_PATH}/${CONTRIB_PLATFORM}" fi + if [ ${DEBUG} ]; then + OUTPUT="${PLUGIN_NAME}" + CLANG_OPTS="-g -fsanitize=address" + EXTRA_DEBUG_LIBRARIES="-lyaml-cpp -lvdpau -lX11 -lva-drm -lva-x11 -lrav1e" + EXTRA_DEFINES="-D__DEBUG__" + else + python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME} + CLANG_OPTS="-O3 -shared" + OUTPUT="build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" + fi + # Compile - clang++ -std=c++17 -shared -fPIC \ + clang++ -std=c++17 -fPIC ${CLANG_OPTS} \ -Wl,-Bsymbolic,-rpath,"\${ORIGIN}" \ -Wall -Wextra \ - -Wno-unused-variable \ - -Wno-unused-function \ -Wno-unused-parameter \ + ${EXTRA_DEFINES} \ -D${PROCESSOR} \ -I"." \ -I"${DAEMON_SRC}" \ @@ -105,6 +119,7 @@ then -I"${ONNX_PATH}/include/onnxruntime/session" \ -I"${ONNX_PATH}/include/onnxruntime/providers/cuda" \ -I"${PLUGINS_LIB}" \ + ./../lib/common.cpp \ ./../lib/accel.cpp \ ./../lib/frameUtils.cpp \ ./../lib/frameFilter.cpp \ @@ -125,11 +140,26 @@ then -l:libx264.a \ -lopencv_imgproc \ -lopencv_core \ - -lva ${CUBLASLT} \ - -lonnxruntime \ - -o "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" - - cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.so" "build-local/jpl/lib/$CONTRIB_PLATFORM/libonnxruntime.so.1.6.0" + -lvpx \ + -lx264 \ + -lspeex \ + -lopus \ + -lz \ + -lva \ + ${CUBLASLT} -lonnxruntime \ + ${EXTRA_DEBUG_LIBRARIES} \ + -o "${OUTPUT}" + + if [ ${DEBUG} ]; then + cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.so" "libonnxruntime.so.1.6.0" + mkdir -p "./data/model" + cp "./modelSRC/mModel.onnx" "./data/model/mModel.onnx" + else + cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.so" "build-local/jpl/lib/$CONTRIB_PLATFORM/libonnxruntime.so.1.6.0" + mkdir -p "./build-local/jpl/data/model" + cp "./modelSRC/mModel.onnx" "./build-local/jpl/data/model/mModel.onnx" + cp "./${PREFERENCESFILENAME}.json" "./build-local/jpl/data/preferences.json" + fi if [ "${PROCESSOR}" = "NVIDIA" ] then cp "${CUDA_HOME}/lib64/libcudart.so.10.2.89" "build-local/jpl/lib/$CONTRIB_PLATFORM/libcudart.so.10.2" @@ -141,12 +171,8 @@ then cp "${CUDNN_HOME}/libcudnn_ops_infer.so.8" "build-local/jpl/lib/$CONTRIB_PLATFORM/libcudnn_ops_infer.so.8" fi - mkdir "./build-local/jpl/data/model" - cp "./modelSRC/mModel.onnx" "./build-local/jpl/data/model/mModel.onnx" - cp "./${PREFERENCESFILENAME}.json" "./build-local/jpl/data/preferences.json" - elif [ "${PLATFORM}" = "darwin" ] -then +then if [ -f "${CONTRIB_PATH}/native/.ffmpeg" ]; then rm "${CONTRIB_PATH}/native/.ffmpeg" fi @@ -156,8 +182,6 @@ then rm .ffmpeg cd ${WORKPATH} - python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME} - CONTRIB_PLATFORM=${CONTRIB_PLATFORM_CURT}-${PLATFORM} ONNX_PATH=${EXTRALIBS_PATH} if [ -z "${EXTRALIBS_PATH}" ] @@ -165,17 +189,27 @@ then ONNX_PATH="${CONTRIB_PATH}/${CONTRIB_PLATFORM}${CONTRIB_PLATFORM_EXTRA}" fi + if [ ${DEBUG} ]; then + OUTPUT="${PLUGIN_NAME}" + CLANG_OPTS="-g -fsanitize=address" + EXTRA_DEBUG_LIBRARIES="-lyaml-cpp -lrav1e" + EXTRA_DEFINES="-D__DEBUG__" + else + python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME} + CLANG_OPTS="-O3 -shared" + OUTPUT="build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" + fi + # Compile - clang++ -std=c++17 -shared -fPIC \ + clang++ -std=c++17 -fPIC ${CLANG_OPTS} \ -Wl,-no_compact_unwind -Wl,-framework,CoreFoundation \ -Wl,-framework,Security -Wl,-framework,VideoToolbox \ -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo \ -Wl,-framework,OpenCl -Wl,-framework,Accelerate \ -Wl,-rpath,"\${ORIGIN}" \ -Wall -Wextra \ - -Wno-unused-variable \ - -Wno-unused-function \ -Wno-unused-parameter \ + ${EXTRA_DEFINES} \ -D${PROCESSOR} \ -I"." \ -I"${DAEMON_SRC}" \ @@ -183,6 +217,7 @@ then -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}${CONTRIB_PLATFORM_EXTRA}/include/opencv4" \ -I"${ONNX_PATH}/include/onnxruntime/session" \ -I"${PLUGINS_LIB}" \ + ./../lib/common.cpp \ ./../lib/accel.cpp \ ./../lib/frameUtils.cpp \ ./../lib/frameFilter.cpp \ @@ -202,18 +237,26 @@ then -lopencv_imgproc \ -lopencv_core \ -lonnxruntime \ - "/usr/local/opt/speex/lib/libspeex.a" \ - "/usr/local/opt/opus/lib/libopus.a" \ - -o "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" - - cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.dylib" "build-local/jpl/lib/${CONTRIB_PLATFORM}/libonnxruntime.dylib" - install_name_tool -id "@loader_path/libonnxruntime.1.6.0.dylib" "build-local/jpl/lib/${CONTRIB_PLATFORM}/libonnxruntime.dylib" - install_name_tool -id "@loader_path/${SO_FILE_NAME}" "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" - install_name_tool -change "@rpath/libonnxruntime.1.6.0.dylib" "@loader_path/libonnxruntime.dylib" "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" - - mkdir "./build-local/jpl/data/model" - cp "./modelSRC/mModel.onnx" "./build-local/jpl/data/model/mModel.onnx" - cp "./${PREFERENCESFILENAME}.json" "./build-local/jpl/data/preferences.json" + -lspeex \ + -lopus \ + ${EXTRA_DEBUG_LIBRARIES} \ + -o "${OUTPUT}" + + if [ ${DEBUG} ]; then + mkdir -p "./data/model" + cp "./modelSRC/mModel.onnx" "./data/model/mModel.onnx" + cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.dylib" "libonnxruntime.dylib" + install_name_tool -id "@loader_path/libonnxruntime.1.6.0.dylib" "libonnxruntime.dylib" + install_name_tool -id "@loader_path/${PLUGIN_NAME}" "${OUTPUT}" + else + mkdir -p "./build-local/jpl/data/model" + cp "./modelSRC/mModel.onnx" "./build-local/jpl/data/model/mModel.onnx" + cp "./${PREFERENCESFILENAME}.json" "./build-local/jpl/data/preferences.json" + cp "${ONNX_PATH}/lib/onnxruntime/${ONNX_LIBS}/libonnxruntime.dylib" "build-local/jpl/lib/${CONTRIB_PLATFORM}/libonnxruntime.dylib" + install_name_tool -id "@loader_path/libonnxruntime.1.6.0.dylib" "build-local/jpl/lib/${CONTRIB_PLATFORM}/libonnxruntime.dylib" + install_name_tool -id "@loader_path/${SO_FILE_NAME}" "${OUTPUT}" + fi + install_name_tool -change "@rpath/libonnxruntime.1.6.0.dylib" "@loader_path/libonnxruntime.dylib" "${OUTPUT}" if [ -n "${APPLE_SIGN_CERTIFICATE}" ]; then codesign --force --verify --timestamp -o runtime --sign "${APPLE_SIGN_CERTIFICATE}" "build-local/jpl/lib/${CONTRIB_PLATFORM}/libonnxruntime.dylib" @@ -407,12 +450,14 @@ then buildlib done - mkdir "./build-local/jpl/data/model" + mkdir -p "./build-local/jpl/data/model" cp "./modelSRC/mModel.ort" "./build-local/jpl/data/model/mModel.ort" cp "./${PREFERENCESFILENAME}-accel.json" "./build-local/jpl/data/preferences.json" fi -python3 ./../SDK/jplManipulation.py --assemble --plugin=${PLUGIN_NAME} --distribution=${PLATFORM} --extraPath=${ONNX_LIBS} +if [ ! ${DEBUG} ]; then + python3 ./../SDK/jplManipulation.py --assemble --plugin=${PLUGIN_NAME} --distribution=${PLATFORM} --extraPath=${ONNX_LIBS} +fi cd ${CONTRIB_PATH}/src/ffmpeg/ # ffmpeg build configuration files were changed during plugin build # this git checkout will remove these changes diff --git a/GreenScreen/data/model/.gitignore b/GreenScreen/data/model/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9898231f1e674d676d6bc00b7df58c2ecc513354 --- /dev/null +++ b/GreenScreen/data/model/.gitignore @@ -0,0 +1 @@ +/mModel.onnx diff --git a/GreenScreen/ffmpeg/rules.mak b/GreenScreen/ffmpeg/rules.mak index c97236a1a5d67b304629f22afff3a90353c5d685..372c048683b146b97428892d426332cabd3f344a 100644 --- a/GreenScreen/ffmpeg/rules.mak +++ b/GreenScreen/ffmpeg/rules.mak @@ -3,7 +3,15 @@ FFMPEG_URL := https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/$(FFMPEG_HASH).t PKGS+=ffmpeg +ifdef HAVE_ANDROID +DEPS_ffmpeg = iconv zlib vpx opus speex x264 +else +ifdef __DEBUG__ +DEPS_ffmpeg = iconv zlib vpx opus speex x264 rav1e +else DEPS_ffmpeg = iconv zlib vpx opus speex x264 +endif +endif FFMPEGCONF = \ --cc="$(CC)" \ @@ -169,6 +177,12 @@ FFMPEGCONF += \ --enable-filter=colorkey \ --enable-filter=split +ifdef __DEBUG__ +FFMPEGCONF += \ + --enable-librav1e\ + --enable-encoder=librav1e \ + --enable-muxer=mp4 +endif #platform specific options diff --git a/GreenScreen/ffmpeg/windows-configure-make.sh b/GreenScreen/ffmpeg/windows-configure-make.sh index b6ec0d90d4cb20134a964bbd069b58c440304e5e..f288dc5f270d43aa37f958935c78646462308af6 100644 --- a/GreenScreen/ffmpeg/windows-configure-make.sh +++ b/GreenScreen/ffmpeg/windows-configure-make.sh @@ -109,6 +109,9 @@ FFMPEGCONF+=' --enable-encoder=png --enable-decoder=png' +FFMPEGCONF+=' + --enable-muxer=mp4' + #filters FFMPEGCONF+=' --enable-filter=scale diff --git a/GreenScreen/main.cpp b/GreenScreen/main.cpp index eef75af755b4c5029d0668366a5baf6e5bbdd0cc..156bf692669636b029f2703be75e4ddec624586b 100644 --- a/GreenScreen/main.cpp +++ b/GreenScreen/main.cpp @@ -26,6 +26,14 @@ #include <plugin/jamiplugin.h> #include "pluginMediaHandler.h" +#ifdef __DEBUG__ +#include <assert.h> +#include <yaml-cpp/yaml.h> +#include <fstream> +#include <AVFrameIO.h> +#include <common.h> +#endif + #ifdef WIN32 #define EXPORT_PLUGIN __declspec(dllexport) #else @@ -45,7 +53,7 @@ EXPORT_PLUGIN JAMI_PluginExitFunc JAMI_dynPluginInit(const JAMI_PluginAPI* api) { std::cout << "*******************" << std::endl; - std::cout << "** GREENSCREEN **" << std::endl; + std::cout << "** GreenScreen **" << std::endl; std::cout << "*******************" << std::endl << std::endl; std::cout << "Version " << GreenScreen_VERSION_MAJOR << "." << GreenScreen_VERSION_MINOR << "." << GreenScreen_VERSION_PATCH << std::endl; @@ -66,3 +74,47 @@ JAMI_dynPluginInit(const JAMI_PluginAPI* api) return nullptr; } } + +#ifdef __DEBUG__ + +int +main () +{ + std::cout << "*********************************" << std::endl; + std::cout << "** GreenScreen Debug Version **" << std::endl; + std::cout << "*********************************" << std::endl; + std::cout << "Version " << GreenScreen_VERSION_MAJOR << "." << GreenScreen_VERSION_MINOR << "." + << GreenScreen_VERSION_PATCH << std::endl << std::endl; + + std::ifstream file; + file_utils::openStream(file, "testPreferences.yml"); + + assert(file.is_open()); + YAML::Node node = YAML::Load(file); + + assert(node.IsMap()); + std::map<std::string, std::string> preferences; + for (const auto& kv : node) { + preferences[kv.first.as<std::string>()] = kv.second.as<std::string>(); + std::cout << "Key: " << kv.first.as<std::string>() << "; Value: " << kv.second.as<std::string>() << std::endl; + } + +#ifdef _WIN32 + std::string dataPath = "../data"; +#else + std::string dataPath = "data"; +#endif + preferences["background"] = dataPath + separator() + preferences["background"]; + + auto fmp = std::make_unique<jami::PluginMediaHandler>(std::move(preferences), std::move(dataPath)); + + auto subject = std::make_shared<jami::PublishObservable<AVFrame*>>(); + + // Valid Read frames from sample file and send to subscriber + std::cout << "Test 1" << std::endl << "Sent video: " << preferences["sample"] << std::endl; + fmp->notifyAVFrameSubject(StreamData("testCall", false, StreamType::video, "origin", "destiny"), subject); + av_utils::readAndNotifyAVFrame(preferences["sample"], subject.get(), preferences["output"], AVMEDIA_TYPE_VIDEO); + + return 0; +} +#endif diff --git a/GreenScreen/package.json b/GreenScreen/package.json index c4773e65fde10d9b9a86afbb2081bc95d749ba88..13f516d057d478ccd6d2e47d1ff27506d76b1bf5 100644 --- a/GreenScreen/package.json +++ b/GreenScreen/package.json @@ -4,11 +4,11 @@ "extractLibs": false, "deps": [ "fmt", - "ffmpeg", "opencv" ], "defines": [ - "NVIDIA=False" + "NVIDIA=False", + "TESTPROCESS=False" ], "custom_scripts": { "pre_build": [ diff --git a/GreenScreen/pluginProcessor.cpp b/GreenScreen/pluginProcessor.cpp index 52b7d17e9306c1931471f72dbd8b1075d6a20998..ff189f126739c249ecaa7ff6055fd38782d4a695 100644 --- a/GreenScreen/pluginProcessor.cpp +++ b/GreenScreen/pluginProcessor.cpp @@ -27,10 +27,7 @@ extern "C" { } #include <frameUtils.h> #include <pluglog.h> - -#ifdef WIN32 #include <common.h> -#endif const char sep = separator(); @@ -321,7 +318,6 @@ PluginProcessor::loadBackground() if (mainFilter_.initialize(mainFilterDescription_, {maskms_, bgStream_, ims2_}) < 0) return; - int got_frame; AVCodecContext* pCodecCtx; AVPacket* packet; @@ -376,6 +372,8 @@ PluginProcessor::loadBackground() frameFree(bgImage); avcodec_close(pCodecCtx); + avcodec_free_context(&pCodecCtx); + av_packet_unref(packet); av_packet_free(&packet); pFormatCtx_.reset(); } diff --git a/GreenScreen/sample.mp4 b/GreenScreen/sample.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f71fcb8f46f609dbe52048262363759901ccd366 Binary files /dev/null and b/GreenScreen/sample.mp4 differ diff --git a/GreenScreen/testPreferences.yml b/GreenScreen/testPreferences.yml new file mode 100644 index 0000000000000000000000000000000000000000..32a64ab91782a4b94caada3fb03cb203da78436b --- /dev/null +++ b/GreenScreen/testPreferences.yml @@ -0,0 +1,6 @@ +background: "backgrounds/background2.jpeg" +blur: "0" +blurlevel: "8" +streamslist: "out" +sample: "sample.mp4" +output: "processed.mp4" \ No newline at end of file diff --git a/contrib/yaml-cpp/package.json b/contrib/yaml-cpp/package.json new file mode 100644 index 0000000000000000000000000000000000000000..fba0139e0a7afa1070ea655cf8c5371cadcdbcde --- /dev/null +++ b/contrib/yaml-cpp/package.json @@ -0,0 +1,17 @@ +{ + "name": "yaml-cpp", + "version": "24fa1b33805c9a91df0f32c46c28e314dd7ad96f", + "url": "https://github.com/jbeder/yaml-cpp/archive/__VERSION__.tar.gz", + "deps": [], + "patches": [], + "win_patches": [], + "project_paths": ["msvc/yaml-cpp.vcxproj"], + "with_env" : "", + "custom_scripts": { + "pre_build": [ + "mkdir msvc & cd msvc & cmake .. -G %CMAKE_GENERATOR% -DCMAKE_CXX_FLAGS_RELEASE='/MT'" + ], + "build": [], + "post_build": [] + } +} \ No newline at end of file diff --git a/lib/AVFrameIO.h b/lib/AVFrameIO.h index 867ffa8bc39665170b7a08f35becb23620c072c0..6845d3394db2da19f23457a1068fd5f2481e36e8 100644 --- a/lib/AVFrameIO.h +++ b/lib/AVFrameIO.h @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2022 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ extern "C" { #include <libavcodec/avcodec.h>