diff --git a/.gitignore b/.gitignore index 022991be..c02a2fb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -build/ -build/* +/build* *.DS_Store .pydevproject .settings diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d74c1ef6..131e0c81 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,7 +17,7 @@ linux-builder: - export LIBOPENSHOT_AUDIO_DIR=$CI_PROJECT_DIR/build/install-x64 - mkdir -p build; cd build; - mkdir -p install-x64/python; - - cmake -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/build/install-x64" -D"CMAKE_BUILD_TYPE:STRING=Release" ../ + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/build/install-x64" -D"CMAKE_BUILD_TYPE:STRING=Release" ../ - make - make install - make doc @@ -46,7 +46,7 @@ mac-builder: - export LIBOPENSHOT_AUDIO_DIR=$CI_PROJECT_DIR/build/install-x64 - mkdir -p build; cd build; - mkdir -p install-x64/python; - - cmake -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/build/install-x64" -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc48/bin/g++-4.8 -DCMAKE_C_COMPILER=/usr/local/opt/gcc48/bin/gcc-4.8 -DCMAKE_PREFIX_PATH=/usr/local/qt5/5.5/clang_64 -DPYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -DPYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib -DPython_FRAMEWORKS=/Library/Frameworks/Python.framework/ -D"CMAKE_BUILD_TYPE:STRING=Debug" -D"CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" -D"CMAKE_OSX_DEPLOYMENT_TARGET=10.9" -D"CMAKE_INSTALL_RPATH_USE_LINK_PATH=1" -D"ENABLE_RUBY=0" ../ + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR/build/install-x64" -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc48/bin/g++-4.8 -DCMAKE_C_COMPILER=/usr/local/opt/gcc48/bin/gcc-4.8 -DCMAKE_PREFIX_PATH=/usr/local/qt5/5.5/clang_64 -DPYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -DPYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib -DPython_FRAMEWORKS=/Library/Frameworks/Python.framework/ -D"CMAKE_BUILD_TYPE:STRING=Debug" -D"CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" -D"CMAKE_OSX_DEPLOYMENT_TARGET=10.9" -D"CMAKE_INSTALL_RPATH_USE_LINK_PATH=1" -D"ENABLE_RUBY=0" ../ - make - make install - mv install-x64/lib/python3.6/site-packages/*openshot* install-x64/python @@ -71,14 +71,14 @@ windows-builder-x64: - $env:LIBOPENSHOT_AUDIO_DIR = "$CI_PROJECT_DIR\build\install-x64" - $env:UNITTEST_DIR = "C:\msys64\usr" - $env:ZMQDIR = "C:\msys64\usr" + - $env:RESVGDIR = "C:\msys64\usr" - $env:Path = "C:\msys64\mingw64\bin;C:\msys64\mingw64\lib;C:\msys64\usr\lib\cmake\UnitTest++;C:\msys64\home\jonathan\depot_tools;C:\msys64\usr;C:\msys64\usr\lib;" + $env:Path; - New-Item -ItemType Directory -Force -Path build - New-Item -ItemType Directory -Force -Path build\install-x64\python - cd build - - cmake -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR\build\install-x64" -G "MinGW Makefiles" -D"CMAKE_BUILD_TYPE:STRING=Release" ../ + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR\build\install-x64" -G "MSYS Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make -D"CMAKE_BUILD_TYPE:STRING=Release" ../ - mingw32-make install - - Move-Item -Force -path "install-x64\lib\python3.6\site-packages\*openshot*" -destination "install-x64\python\" - - cp src\libopenshot.dll install-x64\lib + - Move-Item -Force -path "install-x64\lib\python3.7\site-packages\*openshot*" -destination "install-x64\python\" - New-Item -path "install-x64/share/" -Name "$CI_PROJECT_NAME" -Value "CI_PROJECT_NAME:$CI_PROJECT_NAME`nCI_COMMIT_REF_NAME:$CI_COMMIT_REF_NAME`nCI_COMMIT_SHA:$CI_COMMIT_SHA`nCI_JOB_ID:$CI_JOB_ID" -ItemType file -force - $PREV_GIT_LABEL=(git describe --tags --abbrev=0) - git log "$PREV_GIT_LABEL..HEAD" --oneline --pretty=format:"%C(auto,yellow)%h%C(auto,magenta)% %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(25,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D" --date=short > "install-x64/share/$CI_PROJECT_NAME.log" @@ -100,16 +100,15 @@ windows-builder-x86: - Expand-Archive -Path artifacts.zip -DestinationPath . - $env:LIBOPENSHOT_AUDIO_DIR = "$CI_PROJECT_DIR\build\install-x86" - $env:UNITTEST_DIR = "C:\msys32\usr" - - $env:RESVGDIR = "C:\msys32\usr\local" + - $env:RESVGDIR = "C:\msys32\usr" - $env:ZMQDIR = "C:\msys32\usr" - $env:Path = "C:\msys32\mingw32\bin;C:\msys32\mingw32\lib;C:\msys32\usr\lib\cmake\UnitTest++;C:\msys32\home\jonathan\depot_tools;C:\msys32\usr;C:\msys32\usr\lib;" + $env:Path; - New-Item -ItemType Directory -Force -Path build - New-Item -ItemType Directory -Force -Path build\install-x86\python - cd build - - cmake -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR\build\install-x86" -G "MinGW Makefiles" -D"CMAKE_BUILD_TYPE:STRING=Release" -D"CMAKE_CXX_FLAGS=-m32" -D"CMAKE_EXE_LINKER_FLAGS=-Wl,--large-address-aware" -D"CMAKE_C_FLAGS=-m32" ../ + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D"CMAKE_INSTALL_PREFIX:PATH=$CI_PROJECT_DIR\build\install-x86" -G "MSYS Makefiles" -DCMAKE_MAKE_PROGRAM=mingw32-make -D"CMAKE_BUILD_TYPE:STRING=Release" -D"CMAKE_CXX_FLAGS=-m32" -D"CMAKE_EXE_LINKER_FLAGS=-Wl,--large-address-aware" -D"CMAKE_C_FLAGS=-m32" ../ - mingw32-make install - - Move-Item -Force -path "install-x86\lib\python3.6\site-packages\*openshot*" -destination "install-x86\python\" - - cp src\libopenshot.dll install-x86\lib + - Move-Item -Force -path "install-x86\lib\python3.7\site-packages\*openshot*" -destination "install-x86\python\" - New-Item -path "install-x86/share/" -Name "$CI_PROJECT_NAME" -Value "CI_PROJECT_NAME:$CI_PROJECT_NAME`nCI_COMMIT_REF_NAME:$CI_COMMIT_REF_NAME`nCI_COMMIT_SHA:$CI_COMMIT_SHA`nCI_JOB_ID:$CI_JOB_ID" -ItemType file -force - $PREV_GIT_LABEL=(git describe --tags --abbrev=0) - git log "$PREV_GIT_LABEL..HEAD" --oneline --pretty=format:"%C(auto,yellow)%h%C(auto,magenta)% %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(25,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D" --date=short > "install-x86/share/$CI_PROJECT_NAME.log" diff --git a/CMakeLists.txt b/CMakeLists.txt index ede6ebbf..d4e658f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,49 +39,45 @@ For more information, please visit . ################ ADD CMAKE MODULES ################## set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules") -################ GET VERSION INFORMATION FROM VERSION.H ################## -message(STATUS "Determining Version Number (from Version.h file)") +################ PROJECT VERSION #################### +set(PROJECT_VERSION_FULL "0.2.3-dev1") +set(PROJECT_SO_VERSION 17) -#### Get the lines related to libopenshot version from the Version.h header -file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/Version.h - OPENSHOT_VERSION_LINES - REGEX "#define[ ]+OPENSHOT_VERSION_.*[0-9]+;.*") - -#### Set each line into its own variable - -list (GET OPENSHOT_VERSION_LINES 0 LINE_MAJOR) -list (GET OPENSHOT_VERSION_LINES 1 LINE_MINOR) -list (GET OPENSHOT_VERSION_LINES 2 LINE_BUILD) -list (GET OPENSHOT_VERSION_LINES 3 LINE_SO) - -#### Get the version number out of each line -STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_MAJOR[ ]+([0-9]+);(.*)" "\\1" MAJOR_VERSION "${LINE_MAJOR}") -STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_MINOR[ ]+([0-9]+);(.*)" "\\1" MINOR_VERSION "${LINE_MINOR}") -STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_BUILD[ ]+([0-9]+);(.*)" "\\1" BUILD_VERSION "${LINE_BUILD}") -STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_SO[ ]+([0-9]+);(.*)" "\\1" SO_VERSION "${LINE_SO}") - -message(STATUS "MAJOR Version: ${MAJOR_VERSION}") -message(STATUS "MINOR Version: ${MINOR_VERSION}") -message(STATUS "BUILD Version: ${BUILD_VERSION}") -message(STATUS "SO/API/ABI Version: ${SO_VERSION}") -message(STATUS "Determining Version Number - done") +# Remove the dash and anything following, to get the #.#.# version for project() +STRING(REGEX REPLACE "\-.*$" "" VERSION_NUM "${PROJECT_VERSION_FULL}") ################### SETUP PROJECT ################### -PROJECT(libopenshot LANGUAGES C CXX - VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION}) +# This will define the following variables +# PROJECT_NAME +# PROJECT_VERSION, libopenshot_VERSION +# PROJECT_VERSION_MAJOR, libopenshot_VERSION_MAJOR +# PROJECT_VERSION_MINOR, libopenshot_VERSION_MINOR +# PROJECT_VERSION_PATCH, libopenshot_VERSION_PATCH +PROJECT(libopenshot LANGUAGES C CXX VERSION ${VERSION_NUM}) message(" Generating build files for OpenShot Building ${PROJECT_NAME} (version ${PROJECT_VERSION}) - SO/API/ABI Version: ${SO_VERSION} + SO/API/ABI Version: ${PROJECT_SO_VERSION} ") -#### Work around a GCC < 9 bug with handling of _Pragma() in macros -#### See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578 -if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") AND - (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "9.0.0")) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-integrated-cpp") -endif() +# Define install paths according to system conventions +# XXX: This must be AFTER THE PROJECT() COMMAND w/ languages enabled, +# in order to properly configure CMAKE_INSTALL_LIBDIR path +include(GNUInstallDirs) + +########## Configure Version.h header ############## +configure_file(include/OpenShotVersion.h.in include/OpenShotVersion.h @ONLY) +# We'll want that installed later +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/OpenShotVersion.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot) + +############### Set up include paths ################# +list(APPEND OPENSHOT_INCLUDE_DIRS + include + include/effects + include/Qt + ${CMAKE_CURRENT_BINARY_DIR}/include ) #### Enable C++11 (for std::shared_ptr support) set(CMAKE_CXX_STANDARD 11) @@ -104,5 +100,11 @@ add_subdirectory(tests) # Find Doxygen (used for documentation) include(cmake/Modules/UseDoxygen.cmake) -file(GLOB_RECURSE doc_files ${CMAKE_CURRENT_BINARY_DIR}/doc/html/*.*) -INSTALL(FILES ${doc_files} DESTINATION share/doc/libopenshot) +# Install docs, if the user builds them with `make doc` +install(CODE "MESSAGE(\"Checking for documentation files to install...\")") +install(CODE "MESSAGE(\"(Compile with 'make doc' command, requires Doxygen)\")") + +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/ + DESTINATION ${CMAKE_INSTALL_DOCDIR}/API + MESSAGE_NEVER # Don't spew about file copies + OPTIONAL ) # No error if the docs aren't found diff --git a/cmake/Modules/FindOpenShotAudio.cmake b/cmake/Modules/FindOpenShotAudio.cmake index 0aeb0e1f..a0cb9200 100644 --- a/cmake/Modules/FindOpenShotAudio.cmake +++ b/cmake/Modules/FindOpenShotAudio.cmake @@ -5,34 +5,112 @@ # LIBOPENSHOT_AUDIO_INCLUDE_DIRS - The juce.h include directories # LIBOPENSHOT_AUDIO_LIBRARIES - The libraries needed to use juce -message("$ENV{LIBOPENSHOT_AUDIO_DIR}") +if("$ENV{LIBOPENSHOT_AUDIO_DIR}" AND NOT "${OpenShotAudio_FIND_QUIETLY}") + message(STATUS "Looking for OpenShotAudio in: $ENV{LIBOPENSHOT_AUDIO_DIR}") +endif() -# Find the libopenshot-audio header files -find_path(LIBOPENSHOT_AUDIO_INCLUDE_DIR JuceHeader.h - PATHS $ENV{LIBOPENSHOT_AUDIO_DIR}/include/libopenshot-audio/ - /usr/include/libopenshot-audio/ - /usr/local/include/libopenshot-audio/ ) +# Find the libopenshot-audio header files (check env/cache vars first) +find_path( + LIBOPENSHOT_AUDIO_INCLUDE_DIR + JuceHeader.h + HINTS + ENV LIBOPENSHOT_AUDIO_DIR + PATHS + ${LIBOPENSHOT_AUDIO_DIR} + PATH_SUFFIXES + include/libopenshot-audio + libopenshot-audio + include + NO_DEFAULT_PATH +) -# Find the libopenshot-audio.so (check env var first) -find_library(LIBOPENSHOT_AUDIO_LIBRARY - NAMES libopenshot-audio openshot-audio - PATHS $ENV{LIBOPENSHOT_AUDIO_DIR}/lib/ NO_DEFAULT_PATH) +# Find the libopenshot-audio header files (fallback to std. paths) +find_path( + LIBOPENSHOT_AUDIO_INCLUDE_DIR + JuceHeader.h + HINTS + ENV LIBOPENSHOT_AUDIO_DIR + PATHS + ${LIBOPENSHOT_AUDIO_DIR} + PATH_SUFFIXES + include/libopenshot-audio + libopenshot-audio + include +) -# Find the libopenshot-audio.so / libopenshot-audio.dll library (fallback) -find_library(LIBOPENSHOT_AUDIO_LIBRARY - NAMES libopenshot-audio openshot-audio - HINTS $ENV{LIBOPENSHOT_AUDIO_DIR}/lib/ - /usr/lib/ - /usr/lib/libopenshot-audio/ - /usr/local/lib/ ) +# Find libopenshot-audio.so / libopenshot-audio.dll (check env/cache vars first) +find_library( + LIBOPENSHOT_AUDIO_LIBRARY + NAMES + libopenshot-audio + openshot-audio + HINTS + ENV LIBOPENSHOT_AUDIO_DIR + PATHS + ${LIBOPENSHOT_AUDIO_DIR} + PATH_SUFFIXES + lib/libopenshot-audio + libopenshot-audio + lib + NO_DEFAULT_PATH +) -set(LIBOPENSHOT_AUDIO_LIBRARIES ${LIBOPENSHOT_AUDIO_LIBRARY}) -set(LIBOPENSHOT_AUDIO_LIBRARY ${LIBOPENSHOT_AUDIO_LIBRARIES}) +# Find libopenshot-audio.so / libopenshot-audio.dll (fallback) +find_library( + LIBOPENSHOT_AUDIO_LIBRARY + NAMES + libopenshot-audio + openshot-audio + HINTS + ENV LIBOPENSHOT_AUDIO_DIR + PATHS + ${LIBOPENSHOT_AUDIO_DIR} + PATH_SUFFIXES + lib/libopenshot-audio + libopenshot-audio + lib +) -set(LIBOPENSHOT_AUDIO_INCLUDE_DIRS ${LIBOPENSHOT_AUDIO_INCLUDE_DIR} ) +set(LIBOPENSHOT_AUDIO_LIBRARIES "${LIBOPENSHOT_AUDIO_LIBRARY}") +set(LIBOPENSHOT_AUDIO_LIBRARY "${LIBOPENSHOT_AUDIO_LIBRARIES}") +set(LIBOPENSHOT_AUDIO_INCLUDE_DIRS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}") + +if(LIBOPENSHOT_AUDIO_INCLUDE_DIR AND EXISTS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}/JuceHeader.h") + file(STRINGS "${LIBOPENSHOT_AUDIO_INCLUDE_DIR}/JuceHeader.h" libosa_version_str + REGEX "versionString.*=.*\"[^\"]+\"") + if(libosa_version_str MATCHES "versionString.*=.*\"([^\"]+)\"") + set(LIBOPENSHOT_AUDIO_VERSION_STRING ${CMAKE_MATCH_1}) + endif() + unset(libosa_version_str) + string(REGEX REPLACE "^([0-9]+\.[0-9]+\.[0-9]+).*$" "\\1" + LIBOPENSHOT_AUDIO_VERSION "${LIBOPENSHOT_AUDIO_VERSION_STRING}") +endif() + +# If we couldn't parse M.N.B version, don't keep any of it +if(NOT LIBOPENSHOT_AUDIO_VERSION) + unset(LIBOPENSHOT_AUDIO_VERSION) + unset(LIBOPENSHOT_AUDIO_VERSION_STRING) +endif() + +# Determine compatibility with requested version in find_package() +if(OpenShotAudio_FIND_VERSION AND LIBOPENSHOT_AUDIO_VERSION) + if("${OpenShotAudio_FIND_VERSION}" STREQUAL "${LIBOPENSHOT_AUDIO_VERSION}") + set(OpenShotAudio_VERSION_EXACT TRUE) + endif() + if("${OpenShotAudio_FIND_VERSION}" VERSION_GREATER "${LIBOPENSHOT_AUDIO_VERSION}") + set(OpenShotAudio_VERSION_COMPATIBLE FALSE) + else() + set(OpenShotAudio_VERSION_COMPATIBLE TRUE) + endif() +endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set LIBOPENSHOT_AUDIO_FOUND to TRUE # if all listed variables are TRUE -find_package_handle_standard_args(LIBOPENSHOT_AUDIO DEFAULT_MSG - LIBOPENSHOT_AUDIO_LIBRARY LIBOPENSHOT_AUDIO_INCLUDE_DIR) +find_package_handle_standard_args(OpenShotAudio + REQUIRED_VARS + LIBOPENSHOT_AUDIO_LIBRARY + LIBOPENSHOT_AUDIO_INCLUDE_DIRS + VERSION_VAR + LIBOPENSHOT_AUDIO_VERSION_STRING +) diff --git a/doc/HW-ACCEL.md b/doc/HW-ACCEL.md index b8ee7b4e..cbcf5e63 100644 --- a/doc/HW-ACCEL.md +++ b/doc/HW-ACCEL.md @@ -7,20 +7,22 @@ our support for this in the future! The following table summarizes our current level of support: -| | Linux Decode | Linux Encode | Mac Decode | Mac Encode |Windows Decode| Windows Encode | Notes | -|--------------------|------------------------|----------------------|------------------|----------------|--------------|------------------|------------------| -| VA-API | :heavy_check_mark: | :heavy_check_mark: | - | - | - | - | *Linux Only* | -| VDPAU | :heavy_check_mark:(+) |:white_check_mark:(++)| - | - | - | - | *Linux Only* | -| CUDA (NVDEC/NVENC) | :x:(+++) | :heavy_check_mark: | - | - | - |:heavy_check_mark:| *Cross Platform* | -| VideoToolBox | - | - |:heavy_check_mark:| :x:(++++) | - | - | *Mac Only* | -| DXVA2 | - | - | - | - | :x:(+++) | - | *Windows Only* | -| D3D11VA | - | - | - | - | :x:(+++) | - | *Windows Only* | -| QSV | :x:(+++) | :x: | :x: | :x: | :x: | :x: | *Cross Platform* | +| | Linux Decode | Linux Encode | Mac Decode | Mac Encode | Windows Decode | Windows Encode | Notes | +|--------------------|:---------------:|:--------------:|:----------:|:--------------:|:--------------:|:--------------:|------------------| +| VA-API | ✔️   | ✔️   | - | - | - | - | *Linux Only* | +| VDPAU | ✔️ 1 | ✅ 2 | - | - | - | - | *Linux Only* | +| CUDA (NVDEC/NVENC) | ❌ 3 | ✔️   | - | - | - | ✔️   | *Cross Platform* | +| VideoToolBox | - | - | ✔️   | ❌ 4 | - | - | *Mac Only* | +| DXVA2 | - | - | - | - | ❌ 3 | - | *Windows Only* | +| D3D11VA | - | - | - | - | ❌ 3 | - | *Windows Only* | +| QSV | ❌ 3 | ❌   | ❌   | ❌   | ❌   | ❌   | *Cross Platform* | -* *(+) VDPAU for some reason needs a card number one higher than it really is* -* *(++) VDPAU is a decoder only.* -* *(+++) Green frames (pixel data not correctly tranferred back to system memory)* -* *(++++) Crashes and burns* +#### Notes + +1. VDPAU for some reason needs a card number one higher than it really is +2. VDPAU is a decoder only +3. Green frames (pixel data not correctly tranferred back to system memory) +4. Crashes and burns ## Supported FFmpeg Versions @@ -37,7 +39,7 @@ included. The following settings are use by libopenshot to enable, disable, and control the various hardware acceleration features. -``` +```{cpp} /// Use video codec for faster video decoding (if supported) int HARDWARE_DECODER = 0; @@ -76,9 +78,9 @@ in Ubuntu 18.04) for the AppImage to work with hardware acceleration. An AppImage that works on both systems (supporting libva and libva2), might be possible when no libva is included in the AppImage. -* vaapi is working for intel and AMD -* vaapi is working for decode only for nouveau -* nVidia driver is working for export only +* vaapi is working for intel and AMD +* vaapi is working for decode only for nouveau +* nVidia driver is working for export only ## AMD Graphics Cards (RadeonOpenCompute/ROCm) diff --git a/include/Exceptions.h b/include/Exceptions.h index 0fb2bb1e..c5228f13 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -32,7 +32,6 @@ #define OPENSHOT_EXCEPTIONS_H #include -using namespace std; namespace openshot { @@ -45,11 +44,11 @@ namespace openshot { class BaseException : public std::exception //: public exception { protected: - string m_message; + std::string m_message; public: - BaseException(string message) : m_message(message) { } - virtual ~BaseException() throw () {} - virtual const char* what() const throw () { + BaseException(std::string message) : m_message(message) { } + virtual ~BaseException() noexcept {} + virtual const char* what() const noexcept { // return custom message return m_message.c_str(); } @@ -59,13 +58,12 @@ namespace openshot { class ChunkNotFound : public BaseException { public: - string file_path; int64_t frame_number; int64_t chunk_number; int64_t chunk_frame; - ChunkNotFound(string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame) + ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame) : BaseException(message), frame_number(frame_number), chunk_number(chunk_number), chunk_frame(chunk_frame) { } - virtual ~ChunkNotFound() throw () {} + virtual ~ChunkNotFound() noexcept {} }; @@ -73,132 +71,129 @@ namespace openshot { class DecklinkError : public BaseException { public: - DecklinkError(string message) + DecklinkError(std::string message) : BaseException(message) { } - virtual ~DecklinkError() throw () {} + virtual ~DecklinkError() noexcept {} }; /// Exception when decoding audio packet class ErrorDecodingAudio : public BaseException { public: - string file_path; int64_t frame_number; - ErrorDecodingAudio(string message, int64_t frame_number) + ErrorDecodingAudio(std::string message, int64_t frame_number) : BaseException(message), frame_number(frame_number) { } - virtual ~ErrorDecodingAudio() throw () {} + virtual ~ErrorDecodingAudio() noexcept {} }; /// Exception when encoding audio packet class ErrorEncodingAudio : public BaseException { public: - string file_path; int64_t frame_number; - ErrorEncodingAudio(string message, int64_t frame_number) + ErrorEncodingAudio(std::string message, int64_t frame_number) : BaseException(message), frame_number(frame_number) { } - virtual ~ErrorEncodingAudio() throw () {} + virtual ~ErrorEncodingAudio() noexcept {} }; /// Exception when encoding audio packet class ErrorEncodingVideo : public BaseException { public: - string file_path; int64_t frame_number; - ErrorEncodingVideo(string message, int64_t frame_number) + ErrorEncodingVideo(std::string message, int64_t frame_number) : BaseException(message), frame_number(frame_number) { } - virtual ~ErrorEncodingVideo() throw () {} + virtual ~ErrorEncodingVideo() noexcept {} }; /// Exception when an invalid # of audio channels are detected class InvalidChannels : public BaseException { public: - string file_path; - InvalidChannels(string message, string file_path) + std::string file_path; + InvalidChannels(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidChannels() throw () {} + virtual ~InvalidChannels() noexcept {} }; /// Exception when no valid codec is found for a file class InvalidCodec : public BaseException { public: - string file_path; - InvalidCodec(string message, string file_path) + std::string file_path; + InvalidCodec(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidCodec() throw () {} + virtual ~InvalidCodec() noexcept {} }; /// Exception for files that can not be found or opened class InvalidFile : public BaseException { public: - string file_path; - InvalidFile(string message, string file_path) + std::string file_path; + InvalidFile(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidFile() throw () {} + virtual ~InvalidFile() noexcept {} }; /// Exception when no valid format is found for a file class InvalidFormat : public BaseException { public: - string file_path; - InvalidFormat(string message, string file_path) + std::string file_path; + InvalidFormat(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidFormat() throw () {} + virtual ~InvalidFormat() noexcept {} }; /// Exception for invalid JSON class InvalidJSON : public BaseException { public: - string file_path; - InvalidJSON(string message, string file_path) + std::string file_path; + InvalidJSON(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidJSON() throw () {} + virtual ~InvalidJSON() noexcept {} }; /// Exception when invalid encoding options are used class InvalidOptions : public BaseException { public: - string file_path; - InvalidOptions(string message, string file_path) + std::string file_path; + InvalidOptions(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidOptions() throw () {} + virtual ~InvalidOptions() noexcept {} }; /// Exception when invalid sample rate is detected during encoding class InvalidSampleRate : public BaseException { public: - string file_path; - InvalidSampleRate(string message, string file_path) + std::string file_path; + InvalidSampleRate(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~InvalidSampleRate() throw () {} + virtual ~InvalidSampleRate() noexcept {} }; /// Exception for missing JSON Change key class InvalidJSONKey : public BaseException { public: - string json; - InvalidJSONKey(string message, string json) + std::string json; + InvalidJSONKey(std::string message, std::string json) : BaseException(message), json(json) { } - virtual ~InvalidJSONKey() throw () {} + virtual ~InvalidJSONKey() noexcept {} }; /// Exception when no streams are found in the file class NoStreamsFound : public BaseException { public: - string file_path; - NoStreamsFound(string message, string file_path) + std::string file_path; + NoStreamsFound(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~NoStreamsFound() throw () {} + virtual ~NoStreamsFound() noexcept {} }; /// Exception for frames that are out of bounds. @@ -207,9 +202,9 @@ namespace openshot { public: int64_t FrameRequested; int64_t MaxFrames; - OutOfBoundsFrame(string message, int64_t frame_requested, int64_t max_frames) + OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames) : BaseException(message), FrameRequested(frame_requested), MaxFrames(max_frames) { } - virtual ~OutOfBoundsFrame() throw () {} + virtual ~OutOfBoundsFrame() noexcept {} }; /// Exception for an out of bounds key-frame point. @@ -218,59 +213,59 @@ namespace openshot { public: int PointRequested; int MaxPoints; - OutOfBoundsPoint(string message, int point_requested, int max_points) + OutOfBoundsPoint(std::string message, int point_requested, int max_points) : BaseException(message), PointRequested(point_requested), MaxPoints(max_points) { } - virtual ~OutOfBoundsPoint() throw () {} + virtual ~OutOfBoundsPoint() noexcept {} }; /// Exception when memory could not be allocated class OutOfMemory : public BaseException { public: - string file_path; - OutOfMemory(string message, string file_path) + std::string file_path; + OutOfMemory(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~OutOfMemory() throw () {} + virtual ~OutOfMemory() noexcept {} }; /// Exception when a reader is closed, and a frame is requested class ReaderClosed : public BaseException { public: - string file_path; - ReaderClosed(string message, string file_path) + std::string file_path; + ReaderClosed(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~ReaderClosed() throw () {} + virtual ~ReaderClosed() noexcept {} }; /// Exception when resample fails class ResampleError : public BaseException { public: - string file_path; - ResampleError(string message, string file_path) + std::string file_path; + ResampleError(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~ResampleError() throw () {} + virtual ~ResampleError() noexcept {} }; /// Exception when too many seek attempts happen class TooManySeeks : public BaseException { public: - string file_path; - TooManySeeks(string message, string file_path) + std::string file_path; + TooManySeeks(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~TooManySeeks() throw () {} + virtual ~TooManySeeks() noexcept {} }; /// Exception when a writer is closed, and a frame is requested class WriterClosed : public BaseException { public: - string file_path; - WriterClosed(string message, string file_path) + std::string file_path; + WriterClosed(std::string message, std::string file_path) : BaseException(message), file_path(file_path) { } - virtual ~WriterClosed() throw () {} + virtual ~WriterClosed() noexcept {} }; } diff --git a/include/FFmpegUtilities.h b/include/FFmpegUtilities.h index e3df704b..c673305e 100644 --- a/include/FFmpegUtilities.h +++ b/include/FFmpegUtilities.h @@ -91,12 +91,11 @@ #endif // This wraps an unsafe C macro to be C++ compatible function - static const std::string av_make_error_string(int errnum) + inline static const std::string av_make_error_string(int errnum) { char errbuf[AV_ERROR_MAX_STRING_SIZE]; av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE); - std::string errstring(errbuf); - return errstring; + return (std::string)errbuf; } // Redefine the C macro to use our new C++ function @@ -106,13 +105,13 @@ // Define this for compatibility #ifndef PixelFormat #define PixelFormat AVPixelFormat - #endif + #endif #ifndef PIX_FMT_RGBA #define PIX_FMT_RGBA AV_PIX_FMT_RGBA - #endif + #endif #ifndef PIX_FMT_NONE #define PIX_FMT_NONE AV_PIX_FMT_NONE - #endif + #endif #ifndef PIX_FMT_RGB24 #define PIX_FMT_RGB24 AV_PIX_FMT_RGB24 #endif @@ -150,11 +149,12 @@ #define AV_REGISTER_ALL #define AVCODEC_REGISTER_ALL #define AV_FILENAME url + #define AV_SET_FILENAME(oc, f) oc->AV_FILENAME = av_strdup(f) #define MY_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() av_frame_alloc() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type @@ -185,11 +185,12 @@ #define AV_REGISTER_ALL av_register_all(); #define AVCODEC_REGISTER_ALL avcodec_register_all(); #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() av_frame_alloc() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) #define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context) #define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type @@ -223,11 +224,12 @@ #define AV_REGISTER_ALL av_register_all(); #define AVCODEC_REGISTER_ALL avcodec_register_all(); #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() av_frame_alloc() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) - #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) + #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) #define AV_FREE_CONTEXT(av_context) avcodec_close(av_context) #define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type @@ -253,6 +255,7 @@ #define AV_REGISTER_ALL av_register_all(); #define AVCODEC_REGISTER_ALL avcodec_register_all(); #define AV_FILENAME filename + #define AV_SET_FILENAME(oc, f) snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", f) #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() avcodec_alloc_frame() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height) diff --git a/include/Frame.h b/include/Frame.h index cb855fe4..1048c9cf 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -65,9 +65,6 @@ #include "MagickUtilities.h" #endif -#pragma SWIG nowarn=362 -using namespace std; - namespace openshot { /** @@ -131,7 +128,7 @@ namespace openshot int width; int height; int sample_rate; - string color; + std::string color; int64_t max_audio_sample; ///< The max audio sample count added to this frame /// Constrain a color value from 0 to 255 @@ -147,13 +144,13 @@ namespace openshot Frame(); /// Constructor - image only (48kHz audio silence) - Frame(int64_t number, int width, int height, string color); + Frame(int64_t number, int width, int height, std::string color); /// Constructor - audio only (300x200 blank image) Frame(int64_t number, int samples, int channels); /// Constructor - image & audio - Frame(int64_t number, int width, int height, string color, int samples, int channels); + Frame(int64_t number, int width, int height, std::string color, int samples, int channels); /// Copy constructor Frame ( const Frame &other ); @@ -165,7 +162,7 @@ namespace openshot virtual ~Frame(); /// Add (or replace) pixel data to the frame (based on a solid color) - void AddColor(int new_width, int new_height, string new_color); + void AddColor(int new_width, int new_height, std::string new_color); /// Add (or replace) pixel data to the frame void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_); @@ -283,7 +280,7 @@ namespace openshot void SampleRate(int orig_sample_rate) { sample_rate = orig_sample_rate; }; /// Save the frame image to the specified path. The image format can be BMP, JPG, JPEG, PNG, PPM, XBM, XPM - void Save(string path, float scale, string format="PNG", int quality=100); + void Save(std::string path, float scale, std::string format="PNG", int quality=100); /// Set frame number void SetFrameNumber(int64_t number); @@ -293,8 +290,8 @@ namespace openshot /// Thumbnail the frame image with tons of options to the specified path. The image format is determined from the extension (i.e. image.PNG, image.JPEG). /// This method allows for masks, overlays, background color, and much more accurate resizing (including padding and centering) - void Thumbnail(string path, int new_width, int new_height, string mask_path, string overlay_path, - string background_color, bool ignore_aspect, string format="png", int quality=100, float rotate=0.0); + void Thumbnail(std::string path, int new_width, int new_height, std::string mask_path, std::string overlay_path, + std::string background_color, bool ignore_aspect, std::string format="png", int quality=100, float rotate=0.0); /// Play audio samples for this frame void Play(); diff --git a/include/OpenShot.h b/include/OpenShot.h index 35cba101..5273ff0d 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -96,7 +96,7 @@ */ // Include the version number of OpenShot Library -#include "Version.h" +#include "OpenShotVersion.h" // Include all other classes #include "AudioBufferSource.h" diff --git a/include/Version.h b/include/OpenShotVersion.h.in similarity index 68% rename from include/Version.h rename to include/OpenShotVersion.h.in index ec9e94a6..89f4ed52 100644 --- a/include/Version.h +++ b/include/OpenShotVersion.h.in @@ -31,18 +31,16 @@ #ifndef OPENSHOT_VERSION_H #define OPENSHOT_VERSION_H -// Crazy c++ macro to convert an integer into a string -#ifndef STRINGIZE - #define STRINGIZE_(x) #x - #define STRINGIZE(x) STRINGIZE_(x) -#endif +#define OPENSHOT_VERSION_ALL "@PROJECT_VERSION@" /// A string of the entire version "Major.Minor.Build" +#define OPENSHOT_VERSION_FULL "@PROJECT_VERSION_FULL@" /// A string of the full version identifier, including suffixes (e.g. "0.0.0-dev0") -#define OPENSHOT_VERSION_MAJOR 0; /// Major version number is incremented when huge features are added or improved. -#define OPENSHOT_VERSION_MINOR 2; /// Minor version is incremented when smaller (but still very important) improvements are added. -#define OPENSHOT_VERSION_BUILD 3; /// Build number is incremented when minor bug fixes and less important improvements are added. -#define OPENSHOT_VERSION_SO 17; /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link) -#define OPENSHOT_VERSION_MAJOR_MINOR STRINGIZE(OPENSHOT_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_VERSION_MINOR); /// A string of the "Major.Minor" version -#define OPENSHOT_VERSION_ALL STRINGIZE(OPENSHOT_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_VERSION_MINOR) "." STRINGIZE(OPENSHOT_VERSION_BUILD); /// A string of the entire version "Major.Minor.Build" +#define OPENSHOT_VERSION_MAJOR_MINOR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@" /// A string of the "Major.Minor" version + +#define OPENSHOT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ /// Major version number is incremented when huge features are added or improved. +#define OPENSHOT_VERSION_MINOR @PROJECT_VERSION_MINOR@ /// Minor version is incremented when smaller (but still very important) improvements are added. +#define OPENSHOT_VERSION_BUILD @PROJECT_VERSION_PATCH@ /// Build number is incremented when minor bug fixes and less important improvements are added. + +#define OPENSHOT_VERSION_SO @PROJECT_SO_VERSION@ /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link) #include using namespace std; diff --git a/include/Qt/PlayerDemo.h b/include/Qt/PlayerDemo.h index e5d304a4..cfed78bd 100644 --- a/include/Qt/PlayerDemo.h +++ b/include/Qt/PlayerDemo.h @@ -57,7 +57,7 @@ public: ~PlayerDemo(); protected: - void keyPressEvent(QKeyEvent *event); + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; private slots: diff --git a/include/Tests.h b/include/Tests.h deleted file mode 100644 index b647cb0e..00000000 --- a/include/Tests.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file - * @brief Header file for UnitTests - * @author Jonathan Thomas - * - * @ref License - */ - -/* LICENSE - * - * Copyright (c) 2008-2019 OpenShot Studios, LLC - * . This file is part of - * OpenShot Library (libopenshot), an open-source project dedicated to - * delivering high quality video editing and animation solutions to the - * world. For more information visit . - * - * OpenShot Library (libopenshot) is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * OpenShot Library (libopenshot) 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with OpenShot Library. If not, see . - */ - -#ifndef OPENSHOT_UNITTESTS_H -#define OPENSHOT_UNITTESTS_H - - #ifndef TEST_MEDIA_PATH - #define TEST_MEDIA_PATH "../../src/examples/" - #endif - -#endif diff --git a/include/ZmqLogger.h b/include/ZmqLogger.h index 96e16213..2dc1a0cb 100644 --- a/include/ZmqLogger.h +++ b/include/ZmqLogger.h @@ -45,8 +45,6 @@ #include "JuceHeader.h" -using namespace std; - namespace openshot { /** @@ -58,11 +56,11 @@ namespace openshot { class ZmqLogger { private: CriticalSection loggerCriticalSection; - string connection; + std::string connection; // Logfile related vars - string file_path; - ofstream log_file; + std::string file_path; + std::ofstream log_file; bool enabled; /// ZMQ Context @@ -96,30 +94,31 @@ namespace openshot { static ZmqLogger * Instance(); /// Append debug information - void AppendDebugMethod(string method_name, string arg1_name, float arg1_value, - string arg2_name, float arg2_value, - string arg3_name, float arg3_value, - string arg4_name, float arg4_value, - string arg5_name, float arg5_value, - string arg6_name, float arg6_value); + void AppendDebugMethod(std::string method_name, + std::string arg1_name="", float arg1_value=-1.0, + std::string arg2_name="", float arg2_value=-1.0, + std::string arg3_name="", float arg3_value=-1.0, + std::string arg4_name="", float arg4_value=-1.0, + std::string arg5_name="", float arg5_value=-1.0, + std::string arg6_name="", float arg6_value=-1.0); /// Close logger (sockets and/or files) void Close(); /// Set or change connection info for logger (i.e. tcp://*:5556) - void Connection(string new_connection); + void Connection(std::string new_connection); /// Enable/Disable logging void Enable(bool is_enabled) { enabled = is_enabled;}; /// Set or change the file path (optional) - void Path(string new_path); + void Path(std::string new_path); /// Log message to all subscribers of this logger (if any) - void Log(string message); + void Log(std::string message); /// Log message to a file (if path set) - void LogToFile(string message); + void LogToFile(std::string message); }; } diff --git a/include/effects/Brightness.h b/include/effects/Brightness.h index fd43f784..eb33d338 100644 --- a/include/effects/Brightness.h +++ b/include/effects/Brightness.h @@ -75,8 +75,8 @@ namespace openshot /// Default constructor, which takes 2 curves. The curves adjust the brightness and // contrast of a frame's image. /// - /// @param new_brightness The curve to adjust the brightness (between 100 and -100) - /// @param new_contrast The curve to adjust the contrast (3 is typical, 20 is a lot, 0 is invalid) + /// @param new_brightness The curve to adjust the brightness (from -1 to +1, 0 is default/"off") + /// @param new_contrast The curve to adjust the contrast (3 is typical, 20 is a lot, 100 is max. 0 is invalid) Brightness(Keyframe new_brightness, Keyframe new_contrast); /// @brief This method is required for all derived classes of EffectBase, and returns a diff --git a/src/AudioReaderSource.cpp b/src/AudioReaderSource.cpp index 4c42d2ed..8195d03b 100644 --- a/src/AudioReaderSource.cpp +++ b/src/AudioReaderSource.cpp @@ -66,7 +66,7 @@ void AudioReaderSource::GetMoreSamplesFromReader() } // Debug - ZmqLogger::Instance()->AppendDebugMethod("AudioReaderSource::GetMoreSamplesFromReader", "amount_needed", amount_needed, "amount_remaining", amount_remaining, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("AudioReaderSource::GetMoreSamplesFromReader", "amount_needed", amount_needed, "amount_remaining", amount_remaining); // Init estimated buffer equal to the current frame position (before getting more samples) estimated_frame = frame_number; @@ -149,7 +149,7 @@ juce::AudioSampleBuffer* AudioReaderSource::reverse_buffer(juce::AudioSampleBuff int channels = buffer->getNumChannels(); // Debug - ZmqLogger::Instance()->AppendDebugMethod("AudioReaderSource::reverse_buffer", "number_of_samples", number_of_samples, "channels", channels, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("AudioReaderSource::reverse_buffer", "number_of_samples", number_of_samples, "channels", channels); // Reverse array (create new buffer to hold the reversed version) AudioSampleBuffer *reversed = new juce::AudioSampleBuffer(channels, number_of_samples); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52692210..55a13484 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,9 @@ # along with OpenShot Library. If not, see . ################################################################################ +# Pick up our include directories from the parent context +include_directories(${OPENSHOT_INCLUDE_DIRS}) + ################ OPTIONS ################## # Optional build settings for libopenshot OPTION(USE_SYSTEM_JSONCPP "Use system installed JsonCpp" OFF) @@ -109,7 +112,7 @@ ENDIF (AVRESAMPLE_FOUND) ################# LIBOPENSHOT-AUDIO ################### # Find JUCE-based openshot Audio libraries -FIND_PACKAGE(OpenShotAudio REQUIRED) +FIND_PACKAGE(OpenShotAudio 0.1.8 REQUIRED) # Include Juce headers (needed for compile) include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS}) @@ -302,7 +305,7 @@ add_library(openshot SHARED set_target_properties(openshot PROPERTIES VERSION ${PROJECT_VERSION} - SOVERSION ${SO_VERSION} + SOVERSION ${PROJECT_SO_VERSION} INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" ) @@ -403,6 +406,7 @@ set(LIB_INSTALL_DIR lib${LIB_SUFFIX}) # determine correct lib folder INSTALL( TARGETS openshot ARCHIVE DESTINATION ${LIB_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} + RUNTIME DESTINATION ${LIB_INSTALL_DIR} COMPONENT library ) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ diff --git a/src/CacheDisk.cpp b/src/CacheDisk.cpp index 4d446746..b1b1876b 100644 --- a/src/CacheDisk.cpp +++ b/src/CacheDisk.cpp @@ -495,6 +495,8 @@ Json::Value CacheDisk::JsonValue() { string errors; bool success = reader->parse( json_ranges.c_str(), json_ranges.c_str() + json_ranges.size(), &ranges, &errors ); + delete reader; + if (success) root["ranges"] = ranges; @@ -512,7 +514,9 @@ void CacheDisk::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), - value.c_str() + value.size(), &root, &errors ); + value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -522,7 +526,7 @@ void CacheDisk::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/CacheMemory.cpp b/src/CacheMemory.cpp index 4de6bb1f..7bd480e4 100644 --- a/src/CacheMemory.cpp +++ b/src/CacheMemory.cpp @@ -345,10 +345,11 @@ Json::Value CacheMemory::JsonValue() { Json::Value ranges; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( json_ranges.c_str(), json_ranges.c_str() + json_ranges.size(), &ranges, &errors ); + delete reader; if (success) root["ranges"] = ranges; @@ -368,6 +369,7 @@ void CacheMemory::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -377,7 +379,7 @@ void CacheMemory::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/ChunkReader.cpp b/src/ChunkReader.cpp index 8d5b466e..9fc8756c 100644 --- a/src/ChunkReader.cpp +++ b/src/ChunkReader.cpp @@ -121,7 +121,7 @@ void ChunkReader::load_json() info.audio_timebase.den = root["audio_timebase"]["den"].asInt(); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON could not be parsed (or is invalid).", path); @@ -235,7 +235,7 @@ std::shared_ptr ChunkReader::GetFrame(int64_t requested_frame) local_reader = new FFmpegReader(chunk_video_path); local_reader->Open(); // open reader - } catch (InvalidFile) + } catch (const InvalidFile& e) { // Invalid Chunk (possibly it is not found) throw ChunkNotFound(path, requested_frame, location.number, location.frame); @@ -285,10 +285,11 @@ void ChunkReader::SetJson(string value) { Json::Value root; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -298,7 +299,7 @@ void ChunkReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Clip.cpp b/src/Clip.cpp index 8c669042..3bf6030d 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -79,9 +79,9 @@ void Clip::init_settings() wave_color = Color((unsigned char)0, (unsigned char)123, (unsigned char)255, (unsigned char)255); // Init crop settings - crop_gravity = GRAVITY_CENTER; - crop_width = Keyframe(-1.0); - crop_height = Keyframe(-1.0); + crop_gravity = GRAVITY_TOP_LEFT; + crop_width = Keyframe(1.0); + crop_height = Keyframe(1.0); crop_x = Keyframe(0.0); crop_y = Keyframe(0.0); @@ -123,7 +123,7 @@ void Clip::init_reader_rotation() { try { float rotate_metadata = strtof(reader->info.metadata["rotate"].c_str(), 0); rotation = Keyframe(rotate_metadata); - } catch (exception e) {} + } catch (const std::exception& e) {} } else // Default no rotation @@ -259,7 +259,7 @@ void Clip::Open() void Clip::Close() { if (reader) { - ZmqLogger::Instance()->AppendDebugMethod("Clip::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Clip::Close"); // Close the reader reader->Close(); @@ -616,7 +616,7 @@ std::shared_ptr Clip::GetOrCreateFrame(int64_t number) try { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame); // Attempt to get a frame (but this could fail if a reader has just been closed) new_frame = reader->GetFrame(number); @@ -634,7 +634,7 @@ std::shared_ptr Clip::GetOrCreateFrame(int64_t number) } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Clip::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame); // Create blank frame new_frame = std::make_shared(number, reader->info.width, reader->info.height, "#000000", samples_in_frame, reader->info.channels); @@ -716,6 +716,19 @@ string Clip::PropertiesJSON(int64_t requested_frame) { root["has_audio"] = add_property_json("Enable Audio", has_audio.GetValue(requested_frame), "int", "", &has_audio, -1, 1.0, false, requested_frame); root["has_video"] = add_property_json("Enable Video", has_video.GetValue(requested_frame), "int", "", &has_video, -1, 1.0, false, requested_frame); + // Add enable audio/video choices (dropdown style) + root["has_audio"]["choices"].append(add_property_choice_json("Auto", -1, has_audio.GetValue(requested_frame))); + root["has_audio"]["choices"].append(add_property_choice_json("Off", 0, has_audio.GetValue(requested_frame))); + root["has_audio"]["choices"].append(add_property_choice_json("On", 1, has_audio.GetValue(requested_frame))); + root["has_video"]["choices"].append(add_property_choice_json("Auto", -1, has_video.GetValue(requested_frame))); + root["has_video"]["choices"].append(add_property_choice_json("Off", 0, has_video.GetValue(requested_frame))); + root["has_video"]["choices"].append(add_property_choice_json("On", 1, has_video.GetValue(requested_frame))); + + root["crop_x"] = add_property_json("Crop X", crop_x.GetValue(requested_frame), "float", "", &crop_x, -1.0, 1.0, false, requested_frame); + root["crop_y"] = add_property_json("Crop Y", crop_y.GetValue(requested_frame), "float", "", &crop_y, -1.0, 1.0, false, requested_frame); + root["crop_width"] = add_property_json("Crop Width", crop_width.GetValue(requested_frame), "float", "", &crop_width, 0.0, 1.0, false, requested_frame); + root["crop_height"] = add_property_json("Crop Height", crop_height.GetValue(requested_frame), "float", "", &crop_height, 0.0, 1.0, false, requested_frame); + root["wave_color"] = add_property_json("Wave Color", 0.0, "color", "", &wave_color.red, 0, 255, false, requested_frame); root["wave_color"]["red"] = add_property_json("Red", wave_color.red.GetValue(requested_frame), "float", "", &wave_color.red, 0, 255, false, requested_frame); root["wave_color"]["blue"] = add_property_json("Blue", wave_color.blue.GetValue(requested_frame), "float", "", &wave_color.blue, 0, 255, false, requested_frame); @@ -791,10 +804,12 @@ void Clip::SetJson(string value) { Json::Value root; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -804,7 +819,7 @@ void Clip::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Color.cpp b/src/Color.cpp index 21c3f146..b219e695 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -116,6 +116,8 @@ void Color::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -125,7 +127,7 @@ void Color::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp index 5baeb5bf..739d693f 100644 --- a/src/Coordinate.cpp +++ b/src/Coordinate.cpp @@ -77,8 +77,10 @@ void Coordinate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -88,7 +90,7 @@ void Coordinate::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/DecklinkReader.cpp b/src/DecklinkReader.cpp index 230a6689..3af5e3fc 100644 --- a/src/DecklinkReader.cpp +++ b/src/DecklinkReader.cpp @@ -272,8 +272,10 @@ void DecklinkReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -283,7 +285,7 @@ void DecklinkReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/DummyReader.cpp b/src/DummyReader.cpp index aa1e6a56..346430dc 100644 --- a/src/DummyReader.cpp +++ b/src/DummyReader.cpp @@ -150,8 +150,10 @@ void DummyReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -161,7 +163,7 @@ void DummyReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp index 9bf30986..463a2c2c 100644 --- a/src/EffectBase.cpp +++ b/src/EffectBase.cpp @@ -106,8 +106,10 @@ void EffectBase::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -117,7 +119,7 @@ void EffectBase::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 10d89051..511a3183 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -209,7 +209,7 @@ static enum AVPixelFormat get_hw_dec_format(AVCodecContext *ctx, const enum AVPi break; } } - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::get_hw_dec_format (Unable to decode this file using hardware decode)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::get_hw_dec_format (Unable to decode this file using hardware decode)"); return AV_PIX_FMT_NONE; } @@ -385,11 +385,11 @@ void FFmpegReader::Open() { #elif defined(__APPLE__) if( adapter_ptr != NULL ) { #endif - ZmqLogger::Instance()->AppendDebugMethod("Decode Device present using device", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Decode Device present using device"); } else { adapter_ptr = NULL; // use default - ZmqLogger::Instance()->AppendDebugMethod("Decode Device not present using default", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Decode Device not present using default"); } hw_device_ctx = NULL; @@ -445,14 +445,14 @@ void FFmpegReader::Open() { // TODO: needs va_config! #if ENABLE_VAAPI ((AVVAAPIHWConfig *)hwconfig)->config_id = ((VAAPIDecodeContext *)(pCodecCtx->priv_data))->va_config; -#endif constraints = av_hwdevice_get_hwframe_constraints(hw_device_ctx,hwconfig); +#endif if (constraints) { if (pCodecCtx->coded_width < constraints->min_width || pCodecCtx->coded_height < constraints->min_height || pCodecCtx->coded_width > constraints->max_width || pCodecCtx->coded_height > constraints->max_height) { - ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n"); hw_de_supported = 0; retry_decode_open = 1; AV_FREE_CONTEXT(pCodecCtx); @@ -477,13 +477,13 @@ void FFmpegReader::Open() { max_h = openshot::Settings::Instance()->DE_LIMIT_HEIGHT_MAX; //max_w = ((getenv( "LIMIT_WIDTH_MAX" )==NULL) ? MAX_SUPPORTED_WIDTH : atoi(getenv( "LIMIT_WIDTH_MAX" ))); max_w = openshot::Settings::Instance()->DE_LIMIT_WIDTH_MAX; - ZmqLogger::Instance()->AppendDebugMethod("Constraints could not be found using default limit\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Constraints could not be found using default limit\n"); //cerr << "Constraints could not be found using default limit\n"; if (pCodecCtx->coded_width < 0 || pCodecCtx->coded_height < 0 || pCodecCtx->coded_width > max_w || pCodecCtx->coded_height > max_h ) { - ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("DIMENSIONS ARE TOO LARGE for hardware acceleration\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height); hw_de_supported = 0; retry_decode_open = 1; AV_FREE_CONTEXT(pCodecCtx); @@ -493,13 +493,13 @@ void FFmpegReader::Open() { } } else { - ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("\nDecode hardware acceleration is used\n", "Max Width :", max_w, "Max Height :", max_h, "Frame width :", pCodecCtx->coded_width, "Frame height :", pCodecCtx->coded_height); retry_decode_open = 0; } } } // if hw_de_on && hw_de_supported else { - ZmqLogger::Instance()->AppendDebugMethod("\nDecode in software is used\n", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("\nDecode in software is used\n"); } #else retry_decode_open = 0; @@ -577,7 +577,7 @@ void FFmpegReader::Close() { // Mark as "closed" is_open = false; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::Close"); if (packet) { // Remove previous packet before getting next one @@ -792,13 +792,13 @@ std::shared_ptr FFmpegReader::GetFrame(int64_t requested_frame) { throw InvalidFile("Could not detect the duration of the video or audio stream.", path); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "requested_frame", requested_frame, "last_frame", last_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "requested_frame", requested_frame, "last_frame", last_frame); // Check the cache for this frame std::shared_ptr frame = final_cache.GetFrame(requested_frame); if (frame) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "returned cached frame", requested_frame, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "returned cached frame", requested_frame); // Return the cached frame return frame; @@ -809,7 +809,7 @@ std::shared_ptr FFmpegReader::GetFrame(int64_t requested_frame) { frame = final_cache.GetFrame(requested_frame); if (frame) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "returned cached frame on 2nd look", requested_frame, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "returned cached frame on 2nd look", requested_frame); // Return the cached frame } else { @@ -867,7 +867,7 @@ std::shared_ptr FFmpegReader::ReadStream(int64_t requested_frame) { omp_set_nested(true); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream", "requested_frame", requested_frame, "OPEN_MP_NUM_PROCESSORS", OPEN_MP_NUM_PROCESSORS, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream", "requested_frame", requested_frame, "OPEN_MP_NUM_PROCESSORS", OPEN_MP_NUM_PROCESSORS); #pragma omp parallel { @@ -990,7 +990,7 @@ std::shared_ptr FFmpegReader::ReadStream(int64_t requested_frame) { } // end omp parallel // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream (Completed)", "packets_processed", packets_processed, "end_of_stream", end_of_stream, "largest_frame_processed", largest_frame_processed, "Working Cache Count", working_cache.Count(), "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ReadStream (Completed)", "packets_processed", packets_processed, "end_of_stream", end_of_stream, "largest_frame_processed", largest_frame_processed, "Working Cache Count", working_cache.Count()); // End of stream? if (end_of_stream) @@ -1065,7 +1065,7 @@ bool FFmpegReader::GetAVFrame() { hw_de_av_device_type = hw_de_av_device_type_global; if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Packet not sent)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Packet not sent)"); } else { AVFrame *next_frame2; @@ -1083,17 +1083,17 @@ bool FFmpegReader::GetAVFrame() { break; } if (ret != 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (invalid return frame received)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (invalid return frame received)"); } if (hw_de_on && hw_de_supported) { int err; if (next_frame2->format == hw_de_av_pix_fmt) { next_frame->format = AV_PIX_FMT_YUV420P; if ((err = av_hwframe_transfer_data(next_frame,next_frame2,0)) < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Failed to transfer data to output frame)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Failed to transfer data to output frame)"); } if ((err = av_frame_copy_props(next_frame,next_frame2)) < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Failed to copy props to output frame)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Failed to copy props to output frame)"); } } } @@ -1206,14 +1206,14 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) { RemoveAVFrame(pFrame); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (Skipped)", "requested_frame", requested_frame, "current_frame", current_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (Skipped)", "requested_frame", requested_frame, "current_frame", current_frame); // Skip to next frame without decoding or caching return; } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (Before)", "requested_frame", requested_frame, "current_frame", current_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (Before)", "requested_frame", requested_frame, "current_frame", current_frame); // Init some things local (for OpenMP) PixelFormat pix_fmt = AV_GET_CODEC_PIXEL_FORMAT(pStream, pCodecCtx); @@ -1352,7 +1352,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) { } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (After)", "requested_frame", requested_frame, "current_frame", current_frame, "f->number", f->number, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessVideoPacket (After)", "requested_frame", requested_frame, "current_frame", current_frame, "f->number", f->number); } // end omp task @@ -1367,14 +1367,14 @@ void FFmpegReader::ProcessAudioPacket(int64_t requested_frame, int64_t target_fr // Are we close enough to decode the frame's audio? if (target_frame < (requested_frame - 20)) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Skipped)", "requested_frame", requested_frame, "target_frame", target_frame, "starting_sample", starting_sample, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Skipped)", "requested_frame", requested_frame, "target_frame", target_frame, "starting_sample", starting_sample); // Skip to next frame without decoding or caching return; } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Before)", "requested_frame", requested_frame, "target_frame", target_frame, "starting_sample", starting_sample, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (Before)", "requested_frame", requested_frame, "target_frame", target_frame, "starting_sample", starting_sample); // Init an AVFrame to hold the decoded audio samples int frame_finished = 0; @@ -1491,7 +1491,7 @@ void FFmpegReader::ProcessAudioPacket(int64_t requested_frame, int64_t target_fr // Allocate audio buffer int16_t *audio_buf = new int16_t[AVCODEC_MAX_AUDIO_FRAME_SIZE + MY_INPUT_BUFFER_PADDING_SIZE]; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (ReSample)", "packet_samples", packet_samples, "info.channels", info.channels, "info.sample_rate", info.sample_rate, "aCodecCtx->sample_fmt", AV_GET_SAMPLE_FORMAT(aStream, aCodecCtx), "AV_SAMPLE_FMT_S16", AV_SAMPLE_FMT_S16, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (ReSample)", "packet_samples", packet_samples, "info.channels", info.channels, "info.sample_rate", info.sample_rate, "aCodecCtx->sample_fmt", AV_GET_SAMPLE_FORMAT(aStream, aCodecCtx), "AV_SAMPLE_FMT_S16", AV_SAMPLE_FMT_S16); // Create output frame AVFrame *audio_converted = AV_ALLOCATE_FRAME(); @@ -1652,7 +1652,7 @@ void FFmpegReader::ProcessAudioPacket(int64_t requested_frame, int64_t target_fr AV_FREE_FRAME(&audio_frame); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (After)", "requested_frame", requested_frame, "starting_frame", target_frame, "end_frame", starting_frame_number - 1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ProcessAudioPacket (After)", "requested_frame", requested_frame, "starting_frame", target_frame, "end_frame", starting_frame_number - 1); } @@ -1831,7 +1831,7 @@ void FFmpegReader::UpdatePTSOffset(bool is_video) { video_pts_offset = 0 - max(GetVideoPTS(), (int64_t) info.video_timebase.ToInt() * 10); // debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdatePTSOffset (Video)", "video_pts_offset", video_pts_offset, "is_video", is_video, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdatePTSOffset (Video)", "video_pts_offset", video_pts_offset, "is_video", is_video); } } else { // AUDIO PACKET @@ -1841,7 +1841,7 @@ void FFmpegReader::UpdatePTSOffset(bool is_video) { audio_pts_offset = 0 - max(packet->pts, (int64_t) info.audio_timebase.ToInt() * 10); // debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdatePTSOffset (Audio)", "audio_pts_offset", audio_pts_offset, "is_video", is_video, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdatePTSOffset (Audio)", "audio_pts_offset", audio_pts_offset, "is_video", is_video); } } } @@ -1874,14 +1874,14 @@ int64_t FFmpegReader::ConvertVideoPTStoFrame(int64_t pts) { if (current_video_frame < frame) // has missing frames - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ConvertVideoPTStoFrame (detected missing frame)", "calculated frame", frame, "previous_video_frame", previous_video_frame, "current_video_frame", current_video_frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ConvertVideoPTStoFrame (detected missing frame)", "calculated frame", frame, "previous_video_frame", previous_video_frame, "current_video_frame", current_video_frame); // Sometimes frames are missing due to varying timestamps, or they were dropped. Determine // if we are missing a video frame. const GenericScopedLock lock(processingCriticalSection); while (current_video_frame < frame) { if (!missing_video_frames.count(current_video_frame)) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ConvertVideoPTStoFrame (tracking missing frame)", "current_video_frame", current_video_frame, "previous_video_frame", previous_video_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::ConvertVideoPTStoFrame (tracking missing frame)", "current_video_frame", current_video_frame, "previous_video_frame", previous_video_frame); missing_video_frames.insert(pair(current_video_frame, previous_video_frame)); missing_video_frames_source.insert(pair(previous_video_frame, current_video_frame)); } @@ -1965,16 +1965,16 @@ AudioLocation FFmpegReader::GetAudioPTSLocation(int64_t pts) { location.frame = previous_packet_location.frame; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (Audio Gap Detected)", "Source Frame", orig_frame, "Source Audio Sample", orig_start, "Target Frame", location.frame, "Target Audio Sample", location.sample_start, "pts", pts, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (Audio Gap Detected)", "Source Frame", orig_frame, "Source Audio Sample", orig_start, "Target Frame", location.frame, "Target Audio Sample", location.sample_start, "pts", pts); } else { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (Audio Gap Ignored - too big)", "Previous location frame", previous_packet_location.frame, "Target Frame", location.frame, "Target Audio Sample", location.sample_start, "pts", pts, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (Audio Gap Ignored - too big)", "Previous location frame", previous_packet_location.frame, "Target Frame", location.frame, "Target Audio Sample", location.sample_start, "pts", pts); const GenericScopedLock lock(processingCriticalSection); for (int64_t audio_frame = previous_packet_location.frame; audio_frame < location.frame; audio_frame++) { if (!missing_audio_frames.count(audio_frame)) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (tracking missing frame)", "missing_audio_frame", audio_frame, "previous_audio_frame", previous_packet_location.frame, "new location frame", location.frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAudioPTSLocation (tracking missing frame)", "missing_audio_frame", audio_frame, "previous_audio_frame", previous_packet_location.frame, "new location frame", location.frame); missing_audio_frames.insert(pair(audio_frame, previous_packet_location.frame - 1)); } } @@ -2043,7 +2043,7 @@ bool FFmpegReader::CheckMissingFrame(int64_t requested_frame) { checked_count = checked_frames[requested_frame]; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame", "requested_frame", requested_frame, "has_missing_frames", has_missing_frames, "missing_video_frames.size()", missing_video_frames.size(), "checked_count", checked_count, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame", "requested_frame", requested_frame, "has_missing_frames", has_missing_frames, "missing_video_frames.size()", missing_video_frames.size(), "checked_count", checked_count); // Missing frames (sometimes frame #'s are skipped due to invalid or missing timestamps) map::iterator itr; @@ -2089,12 +2089,12 @@ bool FFmpegReader::CheckMissingFrame(int64_t requested_frame) { std::shared_ptr missing_frame = CreateFrame(requested_frame); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (Is Previous Video Frame Final)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "missing_source_frame", missing_source_frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (Is Previous Video Frame Final)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "missing_source_frame", missing_source_frame); // If previous frame found, copy image from previous to missing frame (else we'll just wait a bit and try again later) if (parent_frame != NULL) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (AddImage from Previous Video Frame)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "missing_source_frame", missing_source_frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (AddImage from Previous Video Frame)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "missing_source_frame", missing_source_frame); // Add this frame to the processed map (since it's already done) std::shared_ptr parent_image = parent_frame->GetImage(); @@ -2115,7 +2115,7 @@ bool FFmpegReader::CheckMissingFrame(int64_t requested_frame) { int samples_per_frame = Frame::GetSamplesPerFrame(missing_frame->number, info.fps, info.sample_rate, info.channels); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (Add Silence for Missing Audio Frame)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "samples_per_frame", samples_per_frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckMissingFrame (Add Silence for Missing Audio Frame)", "requested_frame", requested_frame, "missing_frame->number", missing_frame->number, "samples_per_frame", samples_per_frame); // Add this frame to the processed map (since it's already done) missing_frame->AddAudioSilence(samples_per_frame); @@ -2224,7 +2224,7 @@ void FFmpegReader::CheckWorkingFrames(bool end_of_stream, int64_t requested_fram const GenericScopedLock lock(processingCriticalSection); if (missing_video_frames_source.count(f->number)) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckWorkingFrames (add frame to missing cache)", "f->number", f->number, "is_seek_trash", is_seek_trash, "Missing Cache Count", missing_frames.Count(), "Working Cache Count", working_cache.Count(), "Final Cache Count", final_cache.Count(), "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::CheckWorkingFrames (add frame to missing cache)", "f->number", f->number, "is_seek_trash", is_seek_trash, "Missing Cache Count", missing_frames.Count(), "Working Cache Count", working_cache.Count(), "Final Cache Count", final_cache.Count()); missing_frames.Add(f); } @@ -2431,6 +2431,8 @@ void FFmpegReader::SetJson(string value) { string errors; bool success = reader->parse(value.c_str(), value.c_str() + value.size(), &root, &errors); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -2439,7 +2441,7 @@ void FFmpegReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) { + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); } diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index 663e8ab0..94d03e76 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -151,7 +151,7 @@ void FFmpegWriter::auto_detect_format() { // initialize streams void FFmpegWriter::initialize_streams() { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::initialize_streams", "fmt->video_codec", fmt->video_codec, "fmt->audio_codec", fmt->audio_codec, "AV_CODEC_ID_NONE", AV_CODEC_ID_NONE, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::initialize_streams", "fmt->video_codec", fmt->video_codec, "fmt->audio_codec", fmt->audio_codec, "AV_CODEC_ID_NONE", AV_CODEC_ID_NONE); // Add the audio and video streams using the default format codecs and initialize the codecs video_st = NULL; @@ -315,7 +315,7 @@ void FFmpegWriter::SetAudioOptions(bool has_audio, string codec, int sample_rate if (original_channels == 0) original_channels = info.channels; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::SetAudioOptions (" + codec + ")", "sample_rate", sample_rate, "channels", channels, "bit_rate", bit_rate, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::SetAudioOptions (" + codec + ")", "sample_rate", sample_rate, "channels", channels, "bit_rate", bit_rate); // Enable / Disable audio info.has_audio = has_audio; @@ -468,7 +468,7 @@ void FFmpegWriter::SetOption(StreamType stream, string name, string value) { AV_OPTION_SET(st, c->priv_data, name.c_str(), value.c_str(), c); } - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::SetOption (" + (string)name + ")", "stream == VIDEO_STREAM", stream == VIDEO_STREAM, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::SetOption (" + (string)name + ")", "stream == VIDEO_STREAM", stream == VIDEO_STREAM); // Muxing dictionary is not part of the codec context. // Just reusing SetOption function to set popular multiplexing presets. @@ -504,7 +504,7 @@ void FFmpegWriter::PrepareStreams() { if (!info.has_audio && !info.has_video) throw InvalidOptions("No video or audio options have been set. You must set has_video or has_audio (or both).", path); - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::PrepareStreams [" + path + "]", "info.has_audio", info.has_audio, "info.has_video", info.has_video, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::PrepareStreams [" + path + "]", "info.has_audio", info.has_audio, "info.has_video", info.has_video); // Initialize the streams (i.e. add the streams) initialize_streams(); @@ -525,9 +525,7 @@ void FFmpegWriter::WriteHeader() { } // Force the output filename (which doesn't always happen for some reason) - snprintf(oc->AV_FILENAME, sizeof(oc->AV_FILENAME), "%s", path.c_str()); - - // Write the stream header, if any + AV_SET_FILENAME(oc, path.c_str()); // Add general metadata (if any) for (std::map::iterator iter = info.metadata.begin(); iter != info.metadata.end(); ++iter) { @@ -543,6 +541,7 @@ void FFmpegWriter::WriteHeader() { if (is_mp4 || is_mov) av_dict_copy(&dict, mux_dict, 0); + // Write the stream header if (avformat_write_header(oc, &dict) != 0) { throw InvalidFile("Could not write header to file.", path); }; @@ -554,7 +553,7 @@ void FFmpegWriter::WriteHeader() { // Mark as 'written' write_header = true; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteHeader", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteHeader"); } // Add a frame to the queue waiting to be encoded. @@ -571,7 +570,7 @@ void FFmpegWriter::WriteFrame(std::shared_ptr frame) { if (info.has_audio && audio_st) spooled_audio_frames.push_back(frame); - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteFrame", "frame->number", frame->number, "spooled_video_frames.size()", spooled_video_frames.size(), "spooled_audio_frames.size()", spooled_audio_frames.size(), "cache_size", cache_size, "is_writing", is_writing, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteFrame", "frame->number", frame->number, "spooled_video_frames.size()", spooled_video_frames.size(), "spooled_audio_frames.size()", spooled_audio_frames.size(), "cache_size", cache_size, "is_writing", is_writing); // Write the frames once it reaches the correct cache size if (spooled_video_frames.size() == cache_size || spooled_audio_frames.size() == cache_size) { @@ -592,7 +591,7 @@ void FFmpegWriter::WriteFrame(std::shared_ptr frame) { // Write all frames in the queue to the video file. void FFmpegWriter::write_queued_frames() { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_queued_frames", "spooled_video_frames.size()", spooled_video_frames.size(), "spooled_audio_frames.size()", spooled_audio_frames.size(), "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_queued_frames", "spooled_video_frames.size()", spooled_video_frames.size(), "spooled_audio_frames.size()", spooled_audio_frames.size()); // Flip writing flag is_writing = true; @@ -700,7 +699,7 @@ void FFmpegWriter::write_queued_frames() { // Write a block of frames from a reader void FFmpegWriter::WriteFrame(ReaderBase *reader, int64_t start, int64_t length) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteFrame (from Reader)", "start", start, "length", length, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteFrame (from Reader)", "start", start, "length", length); // Loop through each frame (and encoded it) for (int64_t number = start; number <= length; number++) { @@ -733,7 +732,7 @@ void FFmpegWriter::WriteTrailer() { // Mark as 'written' write_trailer = true; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteTrailer", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::WriteTrailer"); } // Flush encoders @@ -818,8 +817,7 @@ void FFmpegWriter::flush_encoders() { #endif // IS_FFMPEG_3_2 if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, - "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code); } if (!got_packet) { stop_encoding = 1; @@ -841,7 +839,7 @@ void FFmpegWriter::flush_encoders() { // Write packet error_code = av_interleaved_write_frame(oc, &pkt); if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code); } // Deallocate memory (if needed) @@ -876,7 +874,7 @@ void FFmpegWriter::flush_encoders() { error_code = avcodec_encode_audio2(audio_codec, &pkt, NULL, &got_packet); #endif if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code); } if (!got_packet) { stop_encoding = 1; @@ -902,7 +900,7 @@ void FFmpegWriter::flush_encoders() { // Write packet error_code = av_interleaved_write_frame(oc, &pkt); if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::flush_encoders ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code); } // deallocate memory for packet @@ -987,7 +985,7 @@ void FFmpegWriter::Close() { write_header = false; write_trailer = false; - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::Close"); } // Add an AVFrame to the cache @@ -1214,9 +1212,9 @@ AVStream *FFmpegWriter::add_video_stream() { AV_COPY_PARAMS_FROM_CONTEXT(st, c); #if (LIBAVFORMAT_VERSION_MAJOR < 58) - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + (string)fmt->name + " : " + (string)av_get_pix_fmt_name(c->pix_fmt) + ")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", c->pix_fmt, "oc->oformat->flags", oc->oformat->flags, "AVFMT_RAWPICTURE", AVFMT_RAWPICTURE, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + (string)fmt->name + " : " + (string)av_get_pix_fmt_name(c->pix_fmt) + ")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", c->pix_fmt, "oc->oformat->flags", oc->oformat->flags, "AVFMT_RAWPICTURE", AVFMT_RAWPICTURE); #else - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + (string)fmt->name + " : " + (string)av_get_pix_fmt_name(c->pix_fmt) + ")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", c->pix_fmt, "oc->oformat->flags", oc->oformat->flags, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + (string)fmt->name + " : " + (string)av_get_pix_fmt_name(c->pix_fmt) + ")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", c->pix_fmt, "oc->oformat->flags", oc->oformat->flags); #endif return st; @@ -1290,7 +1288,7 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st) { av_dict_set(&st->metadata, iter->first.c_str(), iter->second.c_str(), 0); } - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_audio", "audio_codec->thread_count", audio_codec->thread_count, "audio_input_frame_size", audio_input_frame_size, "buffer_size", AVCODEC_MAX_AUDIO_FRAME_SIZE + MY_INPUT_BUFFER_PADDING_SIZE, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_audio", "audio_codec->thread_count", audio_codec->thread_count, "audio_input_frame_size", audio_input_frame_size, "buffer_size", AVCODEC_MAX_AUDIO_FRAME_SIZE + MY_INPUT_BUFFER_PADDING_SIZE); } // open video codec @@ -1332,15 +1330,15 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st) { #elif defined(__APPLE__) if( adapter_ptr != NULL ) { #endif - ZmqLogger::Instance()->AppendDebugMethod("Encode Device present using device", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Encode Device present using device"); } else { adapter_ptr = NULL; // use default - ZmqLogger::Instance()->AppendDebugMethod("Encode Device not present using default", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Encode Device not present using default"); } if (av_hwdevice_ctx_create(&hw_device_ctx, hw_en_av_device_type, adapter_ptr, NULL, 0) < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_video : Codec name: ", info.vcodec.c_str(), -1, " ERROR creating\n", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_video : Codec name: ", info.vcodec.c_str(), -1, " ERROR creating\n", -1); throw InvalidCodec("Could not create hwdevice", path); } } @@ -1390,7 +1388,7 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st) { av_dict_set(&st->metadata, iter->first.c_str(), iter->second.c_str(), 0); } - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_video", "video_codec->thread_count", video_codec->thread_count, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::open_video", "video_codec->thread_count", video_codec->thread_count); } @@ -1543,7 +1541,7 @@ void FFmpegWriter::write_audio_packets(bool is_final) { AV_FREE_FRAME(&audio_converted); all_queued_samples = NULL; // this array cleared with above call - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets (Successfully completed 1st resampling)", "nb_samples", nb_samples, "remaining_frame_samples", remaining_frame_samples, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets (Successfully completed 1st resampling)", "nb_samples", nb_samples, "remaining_frame_samples", remaining_frame_samples); } // Loop until no more samples @@ -1633,7 +1631,7 @@ void FFmpegWriter::write_audio_packets(bool is_final) { AV_FREE_FRAME(&audio_frame); all_queued_samples = NULL; // this array cleared with above call - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets (Successfully completed 2nd resampling for Planar formats)", "nb_samples", nb_samples, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets (Successfully completed 2nd resampling for Planar formats)", "nb_samples", nb_samples); } else { // Create a new array @@ -1721,12 +1719,12 @@ void FFmpegWriter::write_audio_packets(bool is_final) { /* write the compressed frame in the media file */ int error_code = av_interleaved_write_frame(oc, &pkt); if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code); } } if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_audio_packets ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code); } // deallocate AVFrame @@ -1828,7 +1826,7 @@ void FFmpegWriter::process_video_packet(std::shared_ptr frame) { // Fill with data AV_COPY_PICTURE_DATA(frame_source, (uint8_t *) pixels, PIX_FMT_RGBA, source_image_width, source_image_height); - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::process_video_packet", "frame->number", frame->number, "bytes_source", bytes_source, "bytes_final", bytes_final, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::process_video_packet", "frame->number", frame->number, "bytes_source", bytes_source, "bytes_final", bytes_final); // Resize & convert pixel format sws_scale(scaler, frame_source->data, frame_source->linesize, 0, @@ -1848,9 +1846,9 @@ void FFmpegWriter::process_video_packet(std::shared_ptr frame) { // write video frame bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame *frame_final) { #if (LIBAVFORMAT_VERSION_MAJOR >= 58) - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet", "frame->number", frame->number, "oc->oformat->flags", oc->oformat->flags, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet", "frame->number", frame->number, "oc->oformat->flags", oc->oformat->flags); #else - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet", "frame->number", frame->number, "oc->oformat->flags & AVFMT_RAWPICTURE", oc->oformat->flags & AVFMT_RAWPICTURE, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet", "frame->number", frame->number, "oc->oformat->flags & AVFMT_RAWPICTURE", oc->oformat->flags & AVFMT_RAWPICTURE); if (oc->oformat->flags & AVFMT_RAWPICTURE) { // Raw video case. @@ -1869,7 +1867,7 @@ bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame *fra /* write the compressed frame in the media file */ int error_code = av_interleaved_write_frame(oc, &pkt); if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code); return false; } @@ -1927,7 +1925,7 @@ bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame *fra } error_code = ret; if (ret < 0 ) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet (Frame not sent)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet (Frame not sent)"); if (ret == AVERROR(EAGAIN) ) { cerr << "Frame EAGAIN" << "\n"; } @@ -2001,7 +1999,7 @@ bool FFmpegWriter::write_video_packet(std::shared_ptr frame, AVFrame *fra /* write the compressed frame in the media file */ int error_code = av_interleaved_write_frame(oc, &pkt); if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet ERROR [" + (string) av_err2str(error_code) + "]", "error_code", error_code); return false; } } diff --git a/src/Frame.cpp b/src/Frame.cpp index ccbb65d5..49fb7358 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -833,10 +833,11 @@ void Frame::AddImage(std::shared_ptr new_image, bool only_odd_lines) int start = 0; if (only_odd_lines) start = 1; - for (int row = start; row < image->height(); row += 2) { - memcpy((unsigned char *) pixels, new_pixels + (row * image->bytesPerLine()), image->bytesPerLine()); - new_pixels += image->bytesPerLine(); - } + + for (int row = start; row < image->height(); row += 2) { + memcpy((unsigned char *) pixels, new_pixels + (row * image->bytesPerLine()), image->bytesPerLine()); + new_pixels += image->bytesPerLine(); + } // Update height and width width = image->width(); diff --git a/src/FrameMapper.cpp b/src/FrameMapper.cpp index 1f6b7629..ff7cf1ce 100644 --- a/src/FrameMapper.cpp +++ b/src/FrameMapper.cpp @@ -99,7 +99,7 @@ void FrameMapper::AddField(Field field) // whether the frame rate is increasing or decreasing. void FrameMapper::Init() { - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Init (Calculate frame mappings)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Init (Calculate frame mappings)"); // Do not initialize anything if just a picture with no audio if (info.has_video and !info.has_audio and info.has_single_image) @@ -342,7 +342,7 @@ MappedFrame FrameMapper::GetMappedFrame(int64_t TargetFrameNumber) TargetFrameNumber = frames.size(); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetMappedFrame", "TargetFrameNumber", TargetFrameNumber, "frames.size()", frames.size(), "frames[...].Odd", frames[TargetFrameNumber - 1].Odd.Frame, "frames[...].Even", frames[TargetFrameNumber - 1].Even.Frame, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetMappedFrame", "TargetFrameNumber", TargetFrameNumber, "frames.size()", frames.size(), "frames[...].Odd", frames[TargetFrameNumber - 1].Odd.Frame, "frames[...].Even", frames[TargetFrameNumber - 1].Even.Frame); // Return frame return frames[TargetFrameNumber - 1]; @@ -358,7 +358,7 @@ std::shared_ptr FrameMapper::GetOrCreateFrame(int64_t number) try { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame); // Attempt to get a frame (but this could fail if a reader has just been closed) new_frame = reader->GetFrame(number); @@ -375,7 +375,7 @@ std::shared_ptr FrameMapper::GetOrCreateFrame(int64_t number) } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame); // Create blank frame new_frame = std::make_shared(number, info.width, info.height, "#000000", samples_in_frame, reader->info.channels); @@ -409,14 +409,14 @@ std::shared_ptr FrameMapper::GetFrame(int64_t requested_frame) int minimum_frames = 1; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetFrame (Loop through frames)", "requested_frame", requested_frame, "minimum_frames", minimum_frames, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetFrame (Loop through frames)", "requested_frame", requested_frame, "minimum_frames", minimum_frames); // Loop through all requested frames for (int64_t frame_number = requested_frame; frame_number < requested_frame + minimum_frames; frame_number++) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetFrame (inside omp for loop)", "frame_number", frame_number, "minimum_frames", minimum_frames, "requested_frame", requested_frame, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::GetFrame (inside omp for loop)", "frame_number", frame_number, "minimum_frames", minimum_frames, "requested_frame", requested_frame); // Get the mapped frame MappedFrame mapped = GetMappedFrame(frame_number); @@ -634,7 +634,7 @@ void FrameMapper::Open() { if (reader) { - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Open", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Open"); // Open the reader reader->Open(); @@ -649,7 +649,7 @@ void FrameMapper::Close() // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(getFrameCriticalSection); - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::Close"); // Close internal reader reader->Close(); @@ -701,8 +701,10 @@ void FrameMapper::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -712,7 +714,7 @@ void FrameMapper::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -782,7 +784,7 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr frame, int64_t orig int samples_in_frame = frame->GetAudioSamplesCount(); ChannelLayout channel_layout_in_frame = frame->ChannelsLayout(); - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio", "frame->number", frame->number, "original_frame_number", original_frame_number, "channels_in_frame", channels_in_frame, "samples_in_frame", samples_in_frame, "sample_rate_in_frame", sample_rate_in_frame, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio", "frame->number", frame->number, "original_frame_number", original_frame_number, "channels_in_frame", channels_in_frame, "samples_in_frame", samples_in_frame, "sample_rate_in_frame", sample_rate_in_frame); // Get audio sample array float* frame_samples_float = NULL; @@ -818,7 +820,7 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr frame, int64_t orig if (error_code < 0) { - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio ERROR [" + (string)av_err2str(error_code) + "]", "error_code", error_code); throw ErrorEncodingVideo("Error while resampling audio in frame mapper", frame->number); } @@ -917,7 +919,7 @@ void FrameMapper::ResampleMappedAudio(std::shared_ptr frame, int64_t orig // Add samples to frame for this channel frame->AddAudio(true, channel_filter, 0, channel_buffer, position, 1.0f); - ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio (Add audio to channel)", "number of samples", position, "channel_filter", channel_filter, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("FrameMapper::ResampleMappedAudio (Add audio to channel)", "number of samples", position, "channel_filter", channel_filter); } // Update frame's audio meta data diff --git a/src/ImageReader.cpp b/src/ImageReader.cpp index 62439d82..a0b7e8f3 100644 --- a/src/ImageReader.cpp +++ b/src/ImageReader.cpp @@ -67,7 +67,7 @@ void ImageReader::Open() image->backgroundColor(Magick::Color("none")); MAGICK_IMAGE_ALPHA(image, true); } - catch (Magick::Exception e) { + catch (const Magick::Exception& e) { // raise exception throw InvalidFile("File could not be opened.", path); } @@ -165,6 +165,8 @@ void ImageReader::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -174,7 +176,7 @@ void ImageReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/ImageWriter.cpp b/src/ImageWriter.cpp index e0b7a5b6..2b1e3fc0 100644 --- a/src/ImageWriter.cpp +++ b/src/ImageWriter.cpp @@ -128,7 +128,7 @@ void ImageWriter::WriteFrame(std::shared_ptr frame) // Write a block of frames from a reader void ImageWriter::WriteFrame(ReaderBase* reader, int64_t start, int64_t length) { - ZmqLogger::Instance()->AppendDebugMethod("ImageWriter::WriteFrame (from Reader)", "start", start, "length", length, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("ImageWriter::WriteFrame (from Reader)", "start", start, "length", length); // Loop through each frame (and encoded it) for (int64_t number = start; number <= length; number++) @@ -156,7 +156,7 @@ void ImageWriter::Close() // Close writer is_open = false; - ZmqLogger::Instance()->AppendDebugMethod("ImageWriter::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("ImageWriter::Close"); } #endif //USE_IMAGEMAGICK diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index 31393d17..94618135 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -200,7 +200,7 @@ Point Keyframe::GetPreviousPoint(Point p) { else return Points[0]; - } catch (OutOfBoundsPoint) { + } catch (const OutOfBoundsPoint& e) { // No previous point return Point(-1, -1); } @@ -373,8 +373,10 @@ void Keyframe::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -384,7 +386,7 @@ void Keyframe::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Point.cpp b/src/Point.cpp index b0e85658..fd23da55 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -140,8 +140,10 @@ void Point::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -151,7 +153,7 @@ void Point::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Profiles.cpp b/src/Profiles.cpp index 9c2b3014..e57f7aa3 100644 --- a/src/Profiles.cpp +++ b/src/Profiles.cpp @@ -120,7 +120,7 @@ Profile::Profile(string path) { } } - catch (exception e) + catch (const std::exception& e) { // Error parsing profile file throw InvalidFile("Profile could not be found or loaded (or is invalid).", path); @@ -171,8 +171,10 @@ void Profile::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -182,7 +184,7 @@ void Profile::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/QtImageReader.cpp b/src/QtImageReader.cpp index bd1c4bc8..9107e51f 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -77,12 +77,15 @@ void QtImageReader::Open() // If defined and found in CMake, utilize the libresvg for parsing // SVG files and rasterizing them to QImages. // Only use resvg for files ending in '.svg' or '.svgz' - if (path.find(".svg") != std::string::npos || - path.find(".svgz") != std::string::npos) { + if (path.find(".svg") != std::string::npos || path.find(".svgz") != std::string::npos) { ResvgRenderer renderer(QString::fromStdString(path)); if (!renderer.isValid()) { - success = false; + // Attempt to open file (old method using Qt5 limited SVG parsing) + success = image->load(QString::fromStdString(path)); + if (success) { + image = std::shared_ptr(new QImage(image->convertToFormat(QImage::Format_RGBA8888))); + } } else { image = std::shared_ptr(new QImage(renderer.defaultSize(), QImage::Format_RGBA8888)); @@ -225,17 +228,25 @@ std::shared_ptr QtImageReader::GetFrame(int64_t requested_frame) // If defined and found in CMake, utilize the libresvg for parsing // SVG files and rasterizing them to QImages. // Only use resvg for files ending in '.svg' or '.svgz' - if (path.find(".svg") != std::string::npos || - path.find(".svgz") != std::string::npos) { + if (path.find(".svg") != std::string::npos || path.find(".svgz") != std::string::npos) { ResvgRenderer renderer(QString::fromStdString(path)); if (renderer.isValid()) { + // Scale SVG size to keep aspect ratio, and fill the max_size as best as possible + QSize svg_size(renderer.defaultSize().width(), renderer.defaultSize().height()); + svg_size.scale(max_width, max_height, Qt::KeepAspectRatio); - cached_image = std::shared_ptr(new QImage(QSize(max_width, max_height), QImage::Format_RGBA8888)); + // Create empty QImage + cached_image = std::shared_ptr(new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_RGBA8888)); cached_image->fill(Qt::transparent); + // Render SVG into QImage QPainter p(cached_image.get()); renderer.render(&p); p.end(); + } else { + // Resize current rasterized SVG (since we failed to parse original SVG file with resvg) + cached_image = std::shared_ptr(new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation))); + cached_image = std::shared_ptr(new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888))); } } else { // We need to resize the original image to a smaller image (for performance reasons) @@ -293,8 +304,10 @@ void QtImageReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -304,7 +317,7 @@ void QtImageReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/TextReader.cpp b/src/TextReader.cpp index 9c664535..27f503e1 100644 --- a/src/TextReader.cpp +++ b/src/TextReader.cpp @@ -224,8 +224,10 @@ void TextReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -235,7 +237,7 @@ void TextReader::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index c04cb291..296e7a93 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -194,7 +194,7 @@ double Timeline::calculate_time(int64_t number, Fraction rate) std::shared_ptr Timeline::apply_effects(std::shared_ptr frame, int64_t timeline_frame_number, int layer) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects", "frame->number", frame->number, "timeline_frame_number", timeline_frame_number, "layer", layer, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects", "frame->number", frame->number, "timeline_frame_number", timeline_frame_number, "layer", layer); // Find Effects at this position and layer list::iterator effect_itr; @@ -210,7 +210,7 @@ std::shared_ptr Timeline::apply_effects(std::shared_ptr frame, int bool does_effect_intersect = (effect_start_position <= timeline_frame_number && effect_end_position >= timeline_frame_number && effect->Layer() == layer); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects (Does effect intersect)", "effect->Position()", effect->Position(), "does_effect_intersect", does_effect_intersect, "timeline_frame_number", timeline_frame_number, "layer", layer, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects (Does effect intersect)", "effect->Position()", effect->Position(), "does_effect_intersect", does_effect_intersect, "timeline_frame_number", timeline_frame_number, "layer", layer); // Clip is visible if (does_effect_intersect) @@ -220,7 +220,7 @@ std::shared_ptr Timeline::apply_effects(std::shared_ptr frame, int long effect_frame_number = timeline_frame_number - effect_start_position + effect_start_frame; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects (Process Effect)", "effect_frame_number", effect_frame_number, "does_effect_intersect", does_effect_intersect, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::apply_effects (Process Effect)", "effect_frame_number", effect_frame_number, "does_effect_intersect", does_effect_intersect); // Apply the effect to this frame frame = effect->GetFrame(frame, effect_frame_number); @@ -242,7 +242,7 @@ std::shared_ptr Timeline::GetOrCreateFrame(Clip* clip, int64_t number) try { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetOrCreateFrame (from reader)", "number", number, "samples_in_frame", samples_in_frame); // Attempt to get a frame (but this could fail if a reader has just been closed) #pragma omp critical (T_GetOtCreateFrame) @@ -260,7 +260,7 @@ std::shared_ptr Timeline::GetOrCreateFrame(Clip* clip, int64_t number) } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetOrCreateFrame (create blank)", "number", number, "samples_in_frame", samples_in_frame); // Create blank frame new_frame = std::make_shared(number, Settings::Instance()->MAX_WIDTH, Settings::Instance()->MAX_HEIGHT, "#000000", samples_in_frame, info.channels); @@ -285,13 +285,13 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in return; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer", "new_frame->number", new_frame->number, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer", "new_frame->number", new_frame->number, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number); /* REPLACE IMAGE WITH WAVEFORM IMAGE (IF NEEDED) */ if (source_clip->Waveform()) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Generate Waveform Image)", "source_frame->number", source_frame->number, "source_clip->Waveform()", source_clip->Waveform(), "clip_frame_number", clip_frame_number, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Generate Waveform Image)", "source_frame->number", source_frame->number, "source_clip->Waveform()", source_clip->Waveform(), "clip_frame_number", clip_frame_number); // Get the color of the waveform int red = source_clip->wave_color.red.GetInt(clip_frame_number); @@ -319,7 +319,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in /* COPY AUDIO - with correct volume */ if (source_clip->Reader()->info.has_audio) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Copy Audio)", "source_clip->Reader()->info.has_audio", source_clip->Reader()->info.has_audio, "source_frame->GetAudioChannelsCount()", source_frame->GetAudioChannelsCount(), "info.channels", info.channels, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Copy Audio)", "source_clip->Reader()->info.has_audio", source_clip->Reader()->info.has_audio, "source_frame->GetAudioChannelsCount()", source_frame->GetAudioChannelsCount(), "info.channels", info.channels, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number); if (source_frame->GetAudioChannelsCount() == info.channels && source_clip->has_audio.GetInt(clip_frame_number) != 0) for (int channel = 0; channel < source_frame->GetAudioChannelsCount(); channel++) @@ -375,7 +375,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in } else // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (No Audio Copied - Wrong # of Channels)", "source_clip->Reader()->info.has_audio", source_clip->Reader()->info.has_audio, "source_frame->GetAudioChannelsCount()", source_frame->GetAudioChannelsCount(), "info.channels", info.channels, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (No Audio Copied - Wrong # of Channels)", "source_clip->Reader()->info.has_audio", source_clip->Reader()->info.has_audio, "source_frame->GetAudioChannelsCount()", source_frame->GetAudioChannelsCount(), "info.channels", info.channels, "clip_frame_number", clip_frame_number, "timeline_frame_number", timeline_frame_number); } @@ -385,7 +385,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in return; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Get Source Image)", "source_frame->number", source_frame->number, "source_clip->Waveform()", source_clip->Waveform(), "clip_frame_number", clip_frame_number, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Get Source Image)", "source_frame->number", source_frame->number, "source_clip->Waveform()", source_clip->Waveform(), "clip_frame_number", clip_frame_number); // Get actual frame image data source_image = source_frame->GetImage(); @@ -409,7 +409,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Set Alpha & Opacity)", "alpha", alpha, "source_frame->number", source_frame->number, "clip_frame_number", clip_frame_number, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Set Alpha & Opacity)", "alpha", alpha, "source_frame->number", source_frame->number, "clip_frame_number", clip_frame_number); } /* RESIZE SOURCE IMAGE - based on scale type */ @@ -421,7 +421,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in source_size.scale(Settings::Instance()->MAX_WIDTH, Settings::Instance()->MAX_HEIGHT, Qt::KeepAspectRatio); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_FIT)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_FIT)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height()); break; } case (SCALE_STRETCH): { @@ -429,7 +429,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in source_size.scale(Settings::Instance()->MAX_WIDTH, Settings::Instance()->MAX_HEIGHT, Qt::IgnoreAspectRatio); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_STRETCH)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_STRETCH)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height()); break; } case (SCALE_CROP): { @@ -443,7 +443,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in source_size.scale(height_size.width(), height_size.height(), Qt::KeepAspectRatio); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_CROP)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_CROP)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height()); break; } case (SCALE_NONE): { @@ -455,11 +455,48 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in source_size.scale(Settings::Instance()->MAX_WIDTH * source_width_ratio, Settings::Instance()->MAX_HEIGHT * source_height_ratio, Qt::KeepAspectRatio); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_NONE)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Scale: SCALE_NONE)", "source_frame->number", source_frame->number, "source_width", source_size.width(), "source_height", source_size.height()); break; } } + float crop_x = source_clip->crop_x.GetValue(clip_frame_number); + float crop_y = source_clip->crop_y.GetValue(clip_frame_number); + float crop_w = source_clip->crop_width.GetValue(clip_frame_number); + float crop_h = source_clip->crop_height.GetValue(clip_frame_number); + switch(source_clip->crop_gravity) + { + case (GRAVITY_TOP): + crop_x += 0.5; + break; + case (GRAVITY_TOP_RIGHT): + crop_x += 1.0; + break; + case (GRAVITY_LEFT): + crop_y += 0.5; + break; + case (GRAVITY_CENTER): + crop_x += 0.5; + crop_y += 0.5; + break; + case (GRAVITY_RIGHT): + crop_x += 1.0; + crop_y += 0.5; + break; + case (GRAVITY_BOTTOM_LEFT): + crop_y += 1.0; + break; + case (GRAVITY_BOTTOM): + crop_x += 0.5; + crop_y += 1.0; + break; + case (GRAVITY_BOTTOM_RIGHT): + crop_x += 1.0; + crop_y += 1.0; + break; + } + + /* GRAVITY LOCATION - Initialize X & Y to the correct values (before applying location curves) */ float x = 0.0; // left float y = 0.0; // top @@ -550,7 +587,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Transform: Composite Image Layer: Prepare)", "source_frame->number", source_frame->number, "new_frame->GetImage()->width()", new_frame->GetImage()->width(), "transformed", transformed, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Transform: Composite Image Layer: Prepare)", "source_frame->number", source_frame->number, "new_frame->GetImage()->width()", new_frame->GetImage()->width(), "transformed", transformed); /* COMPOSITE SOURCE IMAGE (LAYER) ONTO FINAL IMAGE */ std::shared_ptr new_image; @@ -567,7 +604,7 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in // Composite a new layer onto the image painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - painter.drawImage(0, 0, *source_image); + painter.drawImage(0, 0, *source_image, crop_x * source_image->width(), crop_y * source_image->height(), crop_w * source_image->width(), crop_h * source_image->height()); // Draw frame #'s on top of image (if needed) if (source_clip->display != FRAME_DISPLAY_NONE) { @@ -595,13 +632,13 @@ void Timeline::add_layer(std::shared_ptr new_frame, Clip* source_clip, in painter.end(); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Transform: Composite Image Layer: Completed)", "source_frame->number", source_frame->number, "new_frame->GetImage()->width()", new_frame->GetImage()->width(), "transformed", transformed, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::add_layer (Transform: Composite Image Layer: Completed)", "source_frame->number", source_frame->number, "new_frame->GetImage()->width()", new_frame->GetImage()->width(), "transformed", transformed); } // Update the list of 'opened' clips void Timeline::update_open_clips(Clip *clip, bool does_clip_intersect) { - ZmqLogger::Instance()->AppendDebugMethod("Timeline::update_open_clips (before)", "does_clip_intersect", does_clip_intersect, "closing_clips.size()", closing_clips.size(), "open_clips.size()", open_clips.size(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::update_open_clips (before)", "does_clip_intersect", does_clip_intersect, "closing_clips.size()", closing_clips.size(), "open_clips.size()", open_clips.size()); // is clip already in list? bool clip_found = open_clips.count(clip); @@ -629,14 +666,14 @@ void Timeline::update_open_clips(Clip *clip, bool does_clip_intersect) } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::update_open_clips (after)", "does_clip_intersect", does_clip_intersect, "clip_found", clip_found, "closing_clips.size()", closing_clips.size(), "open_clips.size()", open_clips.size(), "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::update_open_clips (after)", "does_clip_intersect", does_clip_intersect, "clip_found", clip_found, "closing_clips.size()", closing_clips.size(), "open_clips.size()", open_clips.size()); } // Sort clips by position on the timeline void Timeline::sort_clips() { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::SortClips", "clips.size()", clips.size(), "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::SortClips", "clips.size()", clips.size()); // sort clips clips.sort(CompareClips()); @@ -652,7 +689,7 @@ void Timeline::sort_effects() // Close the reader (and any resources it was consuming) void Timeline::Close() { - ZmqLogger::Instance()->AppendDebugMethod("Timeline::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::Close"); // Close all open clips list::iterator clip_itr; @@ -697,7 +734,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) frame = final_cache->GetFrame(requested_frame); if (frame) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Cached frame found)", "requested_frame", requested_frame, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Cached frame found)", "requested_frame", requested_frame); // Return cached frame return frame; @@ -716,7 +753,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) frame = final_cache->GetFrame(requested_frame); if (frame) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Cached frame found on 2nd look)", "requested_frame", requested_frame, "", -1, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Cached frame found on 2nd look)", "requested_frame", requested_frame); // Return cached frame return frame; @@ -736,7 +773,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) omp_set_nested(true); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame", "requested_frame", requested_frame, "minimum_frames", minimum_frames, "OPEN_MP_NUM_PROCESSORS", OPEN_MP_NUM_PROCESSORS, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame", "requested_frame", requested_frame, "minimum_frames", minimum_frames, "OPEN_MP_NUM_PROCESSORS", OPEN_MP_NUM_PROCESSORS); // GENERATE CACHE FOR CLIPS (IN FRAME # SEQUENCE) // Determine all clip frames, and request them in order (to keep resampled audio in sequence) @@ -769,7 +806,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) for (int64_t frame_number = requested_frame; frame_number < requested_frame + minimum_frames; frame_number++) { // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (processing frame)", "frame_number", frame_number, "omp_get_thread_num()", omp_get_thread_num(), "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (processing frame)", "frame_number", frame_number, "omp_get_thread_num()", omp_get_thread_num()); // Init some basic properties about this frame int samples_in_frame = Frame::GetSamplesPerFrame(frame_number, info.fps, info.sample_rate, info.channels); @@ -784,7 +821,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) } // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Adding solid color)", "frame_number", frame_number, "info.width", info.width, "info.height", info.height, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Adding solid color)", "frame_number", frame_number, "info.width", info.width, "info.height", info.height); // Add Background Color to 1st layer (if animated or not black) if ((color.red.Points.size() > 1 || color.green.Points.size() > 1 || color.blue.Points.size() > 1) || @@ -792,7 +829,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) new_frame->AddColor(Settings::Instance()->MAX_WIDTH, Settings::Instance()->MAX_HEIGHT, color.GetColorHex(frame_number)); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Loop through clips)", "frame_number", frame_number, "clips.size()", clips.size(), "nearby_clips.size()", nearby_clips.size(), "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Loop through clips)", "frame_number", frame_number, "clips.size()", clips.size(), "nearby_clips.size()", nearby_clips.size()); // Find Clips near this time for (int clip_index = 0; clip_index < nearby_clips.size(); clip_index++) @@ -805,7 +842,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) bool does_clip_intersect = (clip_start_position <= frame_number && clip_end_position >= frame_number); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Does clip intersect)", "frame_number", frame_number, "clip->Position()", clip->Position(), "clip->Duration()", clip->Duration(), "does_clip_intersect", does_clip_intersect, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Does clip intersect)", "frame_number", frame_number, "clip->Position()", clip->Position(), "clip->Duration()", clip->Duration(), "does_clip_intersect", does_clip_intersect); // Clip is visible if (does_clip_intersect) @@ -841,19 +878,19 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) long clip_frame_number = frame_number - clip_start_position + clip_start_frame; // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Calculate clip's frame #)", "clip->Position()", clip->Position(), "clip->Start()", clip->Start(), "info.fps.ToFloat()", info.fps.ToFloat(), "clip_frame_number", clip_frame_number, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Calculate clip's frame #)", "clip->Position()", clip->Position(), "clip->Start()", clip->Start(), "info.fps.ToFloat()", info.fps.ToFloat(), "clip_frame_number", clip_frame_number); // Add clip's frame as layer add_layer(new_frame, clip, clip_frame_number, frame_number, is_top_clip, max_volume); } else // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (clip does not intersect)", "frame_number", frame_number, "does_clip_intersect", does_clip_intersect, "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (clip does not intersect)", "frame_number", frame_number, "does_clip_intersect", does_clip_intersect); } // end clip loop // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Add frame to cache)", "frame_number", frame_number, "info.width", info.width, "info.height", info.height, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (Add frame to cache)", "frame_number", frame_number, "info.width", info.width, "info.height", info.height); // Set frame # on mapped frame #pragma omp ordered @@ -868,7 +905,7 @@ std::shared_ptr Timeline::GetFrame(int64_t requested_frame) } // end parallel // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (end parallel region)", "requested_frame", requested_frame, "omp_get_thread_num()", omp_get_thread_num(), "", -1, "", -1, "", -1, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::GetFrame (end parallel region)", "requested_frame", requested_frame, "omp_get_thread_num()", omp_get_thread_num()); // Return frame (or blank frame) return final_cache->GetFrame(requested_frame); @@ -905,7 +942,7 @@ vector Timeline::find_intersecting_clips(int64_t requested_frame, int num (clip_end_position >= min_requested_frame || clip_end_position >= max_requested_frame); // Debug output - ZmqLogger::Instance()->AppendDebugMethod("Timeline::find_intersecting_clips (Is clip near or intersecting)", "requested_frame", requested_frame, "min_requested_frame", min_requested_frame, "max_requested_frame", max_requested_frame, "clip->Position()", clip->Position(), "does_clip_intersect", does_clip_intersect, "", -1); + ZmqLogger::Instance()->AppendDebugMethod("Timeline::find_intersecting_clips (Is clip near or intersecting)", "requested_frame", requested_frame, "min_requested_frame", min_requested_frame, "max_requested_frame", max_requested_frame, "clip->Position()", clip->Position(), "does_clip_intersect", does_clip_intersect); // Open (or schedule for closing) this clip, based on if it's intersecting or not #pragma omp critical (reader_lock) @@ -997,8 +1034,10 @@ void Timeline::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -1008,7 +1047,7 @@ void Timeline::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -1094,8 +1133,10 @@ void Timeline::ApplyJsonDiff(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success || !root.isArray()) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid).", ""); @@ -1123,7 +1164,7 @@ void Timeline::ApplyJsonDiff(string value) { } } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/WriterBase.cpp b/src/WriterBase.cpp index bc16e7e0..f677215a 100644 --- a/src/WriterBase.cpp +++ b/src/WriterBase.cpp @@ -203,8 +203,10 @@ void WriterBase::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -214,7 +216,7 @@ void WriterBase::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/ZmqLogger.cpp b/src/ZmqLogger.cpp index f9ecc875..89d2798a 100644 --- a/src/ZmqLogger.cpp +++ b/src/ZmqLogger.cpp @@ -30,6 +30,10 @@ #include "../include/ZmqLogger.h" +#if USE_RESVG == 1 + #include "ResvgQt.h" +#endif + using namespace std; using namespace openshot; @@ -54,6 +58,13 @@ ZmqLogger *ZmqLogger::Instance() // Init enabled to False (force user to call Enable()) m_pInstance->enabled = false; + + #if USE_RESVG == 1 + // Init resvg logging (if needed) + // This can only happen 1 time or it will crash + ResvgRenderer::initLog(); + #endif + } return m_pInstance; @@ -149,6 +160,9 @@ void ZmqLogger::Path(string new_path) void ZmqLogger::Close() { + // Disable logger as it no longer needed + enabled = false; + // Close file (if already open) if (log_file.is_open()) log_file.close(); @@ -162,12 +176,13 @@ void ZmqLogger::Close() } // Append debug information -void ZmqLogger::AppendDebugMethod(string method_name, string arg1_name, float arg1_value, - string arg2_name, float arg2_value, - string arg3_name, float arg3_value, - string arg4_name, float arg4_value, - string arg5_name, float arg5_value, - string arg6_name, float arg6_value) +void ZmqLogger::AppendDebugMethod(string method_name, + string arg1_name, float arg1_value, + string arg2_name, float arg2_value, + string arg3_name, float arg3_value, + string arg4_name, float arg4_value, + string arg5_name, float arg5_value, + string arg6_name, float arg6_value) { if (!enabled) // Don't do anything @@ -206,4 +221,4 @@ void ZmqLogger::AppendDebugMethod(string method_name, string arg1_name, float ar // Send message through ZMQ Log(message.str()); } -} \ No newline at end of file +} diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index eb7c989a..9afabd41 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -26,7 +26,7 @@ ############### SWIG PYTHON BINDINGS ################ -FIND_PACKAGE(SWIG 2.0 REQUIRED) +FIND_PACKAGE(SWIG 3.0 REQUIRED) INCLUDE(${SWIG_USE_FILE}) ### Enable some legacy SWIG behaviors, in newer CMAKEs @@ -50,6 +50,12 @@ if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot) SET(CMAKE_SWIG_FLAGS "") + ### Suppress a ton of warnings in the generated SWIG C++ code + set(SWIG_CXX_FLAGS "-Wno-unused-variable -Wno-unused-function -Wno-deprecated-copy -Wno-class-memaccess -Wno-cast-function-type \ +-Wno-unused-parameter -Wno-catch-value -Wno-sign-compare -Wno-ignored-qualifiers") + separate_arguments(sw_flags UNIX_COMMAND ${SWIG_CXX_FLAGS}) + set_property(SOURCE openshot.i PROPERTY GENERATED_COMPILE_OPTIONS ${sw_flags}) + ### Add the SWIG interface file (which defines all the SWIG methods) if (CMAKE_VERSION VERSION_LESS 3.8.0) swig_add_module(pyopenshot python openshot.i) @@ -65,7 +71,7 @@ if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) target_link_libraries(${SWIG_MODULE_pyopenshot_REAL_NAME} ${PYTHON_LIBRARIES} openshot) - ### Check if the following Debian-friendly python module path exists + ### Check if the following Debian-friendly python module path exists SET(PYTHON_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages") if (NOT EXISTS ${PYTHON_MODULE_PATH}) diff --git a/src/bindings/python/openshot.i b/src/bindings/python/openshot.i index 74d2705b..512224ef 100644 --- a/src/bindings/python/openshot.i +++ b/src/bindings/python/openshot.i @@ -27,6 +27,9 @@ %module openshot +/* Suppress warnings about ignored operator= */ +%warnfilter(362); + /* Enable inline documentation */ %feature("autodoc", "1"); @@ -53,7 +56,7 @@ %shared_ptr(Frame) %{ -#include "../../../include/Version.h" +#include "OpenShotVersion.h" #include "../../../include/ReaderBase.h" #include "../../../include/WriterBase.h" #include "../../../include/CacheBase.h" @@ -117,7 +120,7 @@ } } -%include "../../../include/Version.h" +%include "OpenShotVersion.h" %include "../../../include/ReaderBase.h" %include "../../../include/WriterBase.h" %include "../../../include/CacheBase.h" diff --git a/src/bindings/ruby/CMakeLists.txt b/src/bindings/ruby/CMakeLists.txt index e0987ca4..4b962e73 100644 --- a/src/bindings/ruby/CMakeLists.txt +++ b/src/bindings/ruby/CMakeLists.txt @@ -24,9 +24,11 @@ # along with OpenShot Library. If not, see . ################################################################################ +# Pick up our include directories from the parent context +include_directories(${OPENSHOT_INCLUDE_DIRS}) ############### RUBY BINDINGS ################ -FIND_PACKAGE(SWIG 2.0 REQUIRED) +FIND_PACKAGE(SWIG 3.0 REQUIRED) INCLUDE(${SWIG_USE_FILE}) ### Enable some legacy SWIG behaviors, in newer CMAKEs @@ -49,6 +51,11 @@ IF (RUBY_FOUND) set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot) SET(CMAKE_SWIG_FLAGS "") + ### Suppress a ton of warnings in the generated SWIG C++ code + set(SWIG_CXX_FLAGS "-Wno-unused-variable -Wno-unused-function -Wno-deprecated-copy -Wno-class-memaccess -Wno-cast-function-type \ +-Wno-unused-parameter -Wno-catch-value -Wno-sign-compare -Wno-ignored-qualifiers") + separate_arguments(sw_flags UNIX_COMMAND ${SWIG_CXX_FLAGS}) + set_property(SOURCE openshot.i PROPERTY GENERATED_COMPILE_OPTIONS ${sw_flags}) ### Add the SWIG interface file (which defines all the SWIG methods) if (CMAKE_VERSION VERSION_LESS 3.8.0) diff --git a/src/bindings/ruby/openshot.i b/src/bindings/ruby/openshot.i index 775421b6..1f3e0d99 100644 --- a/src/bindings/ruby/openshot.i +++ b/src/bindings/ruby/openshot.i @@ -27,6 +27,9 @@ %module openshot +/* Suppress warnings about ignored operator= */ +%warnfilter(362); + /* Enable inline documentation */ %feature("autodoc", "1"); @@ -65,7 +68,7 @@ namespace std { #define RB_RSHIFT(a, b) RSHIFT(a, b) #undef RSHIFT #endif -#include "../../../include/Version.h" +#include "OpenShotVersion.h" #include "../../../include/ReaderBase.h" #include "../../../include/WriterBase.h" #include "../../../include/CacheBase.h" @@ -127,7 +130,7 @@ namespace std { %} #endif -%include "../../../include/Version.h" +%include "OpenShotVersion.h" %include "../../../include/ReaderBase.h" %include "../../../include/WriterBase.h" %include "../../../include/CacheBase.h" diff --git a/src/effects/Bars.cpp b/src/effects/Bars.cpp index 4320e618..6d731d9c 100644 --- a/src/effects/Bars.cpp +++ b/src/effects/Bars.cpp @@ -145,8 +145,10 @@ void Bars::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -156,7 +158,7 @@ void Bars::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -207,4 +209,3 @@ string Bars::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Blur.cpp b/src/effects/Blur.cpp index db036133..7946e249 100644 --- a/src/effects/Blur.cpp +++ b/src/effects/Blur.cpp @@ -282,8 +282,10 @@ void Blur::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -293,7 +295,7 @@ void Blur::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -338,4 +340,3 @@ string Blur::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Brightness.cpp b/src/effects/Brightness.cpp index 67d45824..3a1a4bdb 100644 --- a/src/effects/Brightness.cpp +++ b/src/effects/Brightness.cpp @@ -136,8 +136,10 @@ void Brightness::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -147,7 +149,7 @@ void Brightness::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -186,4 +188,3 @@ string Brightness::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/ChromaKey.cpp b/src/effects/ChromaKey.cpp index 397c7ab1..2e2dc511 100644 --- a/src/effects/ChromaKey.cpp +++ b/src/effects/ChromaKey.cpp @@ -129,8 +129,10 @@ void ChromaKey::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -140,7 +142,7 @@ void ChromaKey::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/effects/ColorShift.cpp b/src/effects/ColorShift.cpp index f4fab883..10f22217 100644 --- a/src/effects/ColorShift.cpp +++ b/src/effects/ColorShift.cpp @@ -228,8 +228,10 @@ void ColorShift::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -239,7 +241,7 @@ void ColorShift::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -296,4 +298,3 @@ string ColorShift::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Crop.cpp b/src/effects/Crop.cpp index 99f8f124..7ff6ec0b 100644 --- a/src/effects/Crop.cpp +++ b/src/effects/Crop.cpp @@ -146,6 +146,8 @@ void Crop::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -155,7 +157,7 @@ void Crop::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/effects/Deinterlace.cpp b/src/effects/Deinterlace.cpp index c698dbd1..65f00ff6 100644 --- a/src/effects/Deinterlace.cpp +++ b/src/effects/Deinterlace.cpp @@ -123,8 +123,10 @@ void Deinterlace::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -134,7 +136,7 @@ void Deinterlace::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/effects/Hue.cpp b/src/effects/Hue.cpp index a75b4a1f..fd33272d 100644 --- a/src/effects/Hue.cpp +++ b/src/effects/Hue.cpp @@ -130,8 +130,10 @@ void Hue::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -141,7 +143,7 @@ void Hue::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -177,4 +179,3 @@ string Hue::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Mask.cpp b/src/effects/Mask.cpp index b952ba62..9f19475d 100644 --- a/src/effects/Mask.cpp +++ b/src/effects/Mask.cpp @@ -183,8 +183,10 @@ void Mask::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -194,7 +196,7 @@ void Mask::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/effects/Negate.cpp b/src/effects/Negate.cpp index 1b9decdc..938030bc 100644 --- a/src/effects/Negate.cpp +++ b/src/effects/Negate.cpp @@ -84,8 +84,10 @@ void Negate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -95,7 +97,7 @@ void Negate::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); diff --git a/src/effects/Pixelate.cpp b/src/effects/Pixelate.cpp index 95d88b71..d7c3fa12 100644 --- a/src/effects/Pixelate.cpp +++ b/src/effects/Pixelate.cpp @@ -141,8 +141,10 @@ void Pixelate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -152,7 +154,7 @@ void Pixelate::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -200,4 +202,3 @@ string Pixelate::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Saturation.cpp b/src/effects/Saturation.cpp index 4278b0b8..98818127 100644 --- a/src/effects/Saturation.cpp +++ b/src/effects/Saturation.cpp @@ -141,8 +141,10 @@ void Saturation::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -152,7 +154,7 @@ void Saturation::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -188,4 +190,3 @@ string Saturation::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Shift.cpp b/src/effects/Shift.cpp index 0e802c99..c22844e7 100644 --- a/src/effects/Shift.cpp +++ b/src/effects/Shift.cpp @@ -161,8 +161,10 @@ void Shift::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -172,7 +174,7 @@ void Shift::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -211,4 +213,3 @@ string Shift::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Wave.cpp b/src/effects/Wave.cpp index cfcb70c7..6e3bd48a 100644 --- a/src/effects/Wave.cpp +++ b/src/effects/Wave.cpp @@ -144,8 +144,10 @@ void Wave::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -155,7 +157,7 @@ void Wave::SetJson(string value) { // Set all values that match SetJsonValue(root); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -203,4 +205,3 @@ string Wave::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b1782774..5e18fcf3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,9 @@ # along with OpenShot Library. If not, see . ################################################################################ +# Pick up our include directories from the parent context +include_directories(${OPENSHOT_INCLUDE_DIRS}) + SET(TEST_MEDIA_PATH "${PROJECT_SOURCE_DIR}/src/examples/") ################ WINDOWS ################## @@ -109,7 +112,7 @@ ENDIF (AVRESAMPLE_FOUND) ################# LIBOPENSHOT-AUDIO ################### # Find JUCE-based openshot Audio libraries -FIND_PACKAGE(OpenShotAudio REQUIRED) +FIND_PACKAGE(OpenShotAudio 0.1.8 REQUIRED) # Include Juce headers (needed for compile) include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS}) diff --git a/tests/Clip_Tests.cpp b/tests/Clip_Tests.cpp index c77e44b6..1b7475f4 100644 --- a/tests/Clip_Tests.cpp +++ b/tests/Clip_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot; @@ -118,6 +117,7 @@ TEST(Clip_Properties) string errors; bool success = reader->parse( properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -129,7 +129,7 @@ TEST(Clip_Properties) CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool()); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -154,7 +154,7 @@ TEST(Clip_Properties) CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool()); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -178,7 +178,7 @@ TEST(Clip_Properties) CHECK_EQUAL(false, root["alpha"]["keyframe"].asBool()); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); @@ -203,12 +203,15 @@ TEST(Clip_Properties) CHECK_EQUAL(true, root["alpha"]["keyframe"].asBool()); } - catch (exception e) + catch (const std::exception& e) { // Error parsing JSON (or missing keys) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); } + + // Free up the reader we allocated + delete reader; } TEST(Clip_Effects) diff --git a/tests/FFmpegReader_Tests.cpp b/tests/FFmpegReader_Tests.cpp index 4ef570ae..68aba4bb 100644 --- a/tests/FFmpegReader_Tests.cpp +++ b/tests/FFmpegReader_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot; diff --git a/tests/FFmpegWriter_Tests.cpp b/tests/FFmpegWriter_Tests.cpp index 53a9cbf2..8cb10e15 100644 --- a/tests/FFmpegWriter_Tests.cpp +++ b/tests/FFmpegWriter_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot; diff --git a/tests/FrameMapper_Tests.cpp b/tests/FrameMapper_Tests.cpp index ce43fc20..f400d830 100644 --- a/tests/FrameMapper_Tests.cpp +++ b/tests/FrameMapper_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot; diff --git a/tests/ImageWriter_Tests.cpp b/tests/ImageWriter_Tests.cpp index d44bbd84..4236b462 100644 --- a/tests/ImageWriter_Tests.cpp +++ b/tests/ImageWriter_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot; @@ -81,4 +80,4 @@ TEST(ImageWriter_Test_Gif) CHECK_EQUAL(11, (int)pixels[pixel_index + 2]); CHECK_EQUAL(255, (int)pixels[pixel_index + 3]); } -#endif \ No newline at end of file +#endif diff --git a/tests/Timeline_Tests.cpp b/tests/Timeline_Tests.cpp index 1290bee7..0bb42b89 100644 --- a/tests/Timeline_Tests.cpp +++ b/tests/Timeline_Tests.cpp @@ -30,7 +30,6 @@ #include "UnitTest++.h" #include "../include/OpenShot.h" -#include "../include/Tests.h" using namespace std; using namespace openshot;