diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a5d1958..57d01be7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ option(ENABLE_FFMPEG "Enable FFmpeg" OFF) option(ENABLE_HLS "Enable HLS" ON) option(ENABLE_JEMALLOC_STATIC "Enable static linking to the jemalloc library" OFF) option(ENABLE_JEMALLOC_DUMP "Enable jemalloc to dump malloc statistics" OFF) +option(ENABLE_TCMALLOC "Enable linking to the tcmalloc library" OFF) option(ENABLE_MEM_DEBUG "Enable Memory Debug" OFF) option(ENABLE_MP4 "Enable MP4" ON) option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" ON) @@ -256,8 +257,8 @@ endif() # Multiple modules depend on ffmpeg related libraries, unified search if(ENABLE_FFMPEG) find_package(PkgConfig QUIET) - # 查找 ffmpeg/libutil 是否安装 - # find ffmpeg/libutil installed + # 查找 ffmpeg/libavutil 是否安装 + # find ffmpeg/libavutil installed if(PKG_CONFIG_FOUND) pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil) if(AVUTIL_FOUND) @@ -296,8 +297,19 @@ if(ENABLE_FFMPEG) endif() endif() - # 查找 ffmpeg/libutil 是否安装 - # find ffmpeg/libutil installed + # 查找 ffmpeg/libavfilter 是否安装 + # find ffmpeg/libavfilter installed + if(PKG_CONFIG_FOUND) + pkg_check_modules(AVFILTER QUIET IMPORTED_TARGET libavfilter) + if(AVFILTER_FOUND) + update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVFILTER) + message(STATUS "found library: ${AVFILTER_LIBRARIES}") + endif() + endif() + + + # 查找 ffmpeg/libavutil 是否安装 + # find ffmpeg/libavutil installed if(NOT AVUTIL_FOUND) find_package(AVUTIL QUIET) if(AVUTIL_FOUND) @@ -349,7 +361,6 @@ if(ENABLE_FFMPEG) endif() endif() - if(AVUTIL_FOUND AND AVCODEC_FOUND AND SWSCALE_FOUND AND SWRESAMPLE_FOUND AND AVFILTER_FOUND) update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FFMPEG) update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS}) @@ -411,6 +422,19 @@ if(JEMALLOC_FOUND) endif () endif() +# 查找 tcmalloc 是否安装 +# find tcmalloc installed +if(ENABLE_TCMALLOC) + find_package(TCMALLOC QUIET) + if(TCMALLOC_FOUND) + message(STATUS "Link with tcmalloc library: ${TCMALLOC_LIBRARIES}") + update_cached_list(MK_LINK_LIBRARIES ${TCMALLOC_LIBRARIES}) + else() + set(ENABLE_TCMALLOC OFF) + message(WARNING "tcmalloc 相关功能未找到") + endif() +endif() + # 查找 openssl 是否安装 # find openssl installed find_package(OpenSSL QUIET) diff --git a/cmake/FindAVFILTER.cmake b/cmake/FindAVFILTER.cmake new file mode 100644 index 00000000..7b36f32a --- /dev/null +++ b/cmake/FindAVFILTER.cmake @@ -0,0 +1,16 @@ +find_path(AVFILTER_INCLUDE_DIR + NAMES libavfilter/avfilter.h + HINTS ${FFMPEG_PATH_ROOT} + PATH_SUFFIXES include) + +find_library(AVFILTER_LIBRARY + NAMES avfilter + HINTS ${FFMPEG_PATH_ROOT} + PATH_SUFFIXES bin lib) + +set(AVFILTER_LIBRARIES ${AVFILTER_LIBRARY}) +set(AVFILTER_INCLUDE_DIRS ${AVFILTER_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(AVFILTER DEFAULT_MSG AVFILTER_LIBRARY AVFILTER_INCLUDE_DIR) diff --git a/cmake/FindTCMALLOC.cmake b/cmake/FindTCMALLOC.cmake new file mode 100644 index 00000000..5ae681aa --- /dev/null +++ b/cmake/FindTCMALLOC.cmake @@ -0,0 +1,16 @@ +find_path(Tcmalloc_INCLUDE_DIR + NAMES google/tcmalloc.h +) + +find_library(Tcmalloc_LIBRARY + NAMES tcmalloc_minimal tcmalloc +) + +set(TCMALLOC_LIBRARIES ${Tcmalloc_LIBRARY}) +set(TCMALLOC_INCLUDE_DIRS ${Tcmalloc_INCLUDE_DIR}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCMALLOC + DEFAULT_MSG + TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIRS +) diff --git a/src/Codec/Transcode.cpp b/src/Codec/Transcode.cpp index e3c09cce..9f5d1125 100644 --- a/src/Codec/Transcode.cpp +++ b/src/Codec/Transcode.cpp @@ -239,7 +239,7 @@ AVFrame *FFmpegFrame::get() const { void FFmpegFrame::fillPicture(AVPixelFormat target_format, int target_width, int target_height) { auto buffer_size = av_image_get_buffer_size(target_format, target_width, target_height, 32); - _data = std::make_unique(buffer_size); + _data = std::unique_ptr(new char[buffer_size]); av_image_fill_arrays(_frame->data, _frame->linesize, (uint8_t *)_data.get(), target_format, target_width, target_height, 32); } @@ -839,14 +839,14 @@ std::tuple FFmpegUtils::saveFrame(const FFmpegFrame::Ptr &fra buffersrc = avfilter_get_by_name("buffer"); - if (ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, _filter_graph.get()) < 0) { + if ((ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, _filter_graph.get())) < 0) { ss << "avfilter_graph_create_filter buffersrc failed: " << ret << " " << ffmpeg_err(ret); DebugL << ss; return make_tuple(false, ss.data()); } buffersink = avfilter_get_by_name("buffersink"); - if (ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, _filter_graph.get()) < 0) { + if ((ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, _filter_graph.get())) < 0) { ss << "avfilter_graph_create_filter buffersink failed: " << ret << " " << ffmpeg_err(ret); return make_tuple(false, ss.data()); }