完成FFmpeg相关代码迁移改造

This commit is contained in:
ziyue 2022-05-25 14:50:26 +08:00
parent fa70af7cce
commit 0739b1ddd2
5 changed files with 113 additions and 83 deletions

View File

@ -102,6 +102,7 @@ option(ENABLE_MEM_DEBUG "Enable Memory Debug" false)
option(ENABLE_ASAN "Enable Address Sanitize" false)
option(ENABLE_WEBRTC "Enable WebRTC" true)
option(ENABLE_PLAYER "Enable Player" true)
option(ENABLE_FFMPEG "Enable FFmpeg" true)
option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" true)
option(ENABLE_API_STATIC_LIB "Enable mk_api static lib" false)
option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON)
@ -200,13 +201,108 @@ endif ()
set(LINK_LIB_LIST zlmediakit zltoolkit)
##jemalloc
#find_package(JEMALLOC QUIET)
#if (JEMALLOC_FOUND)
# message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"")
# include_directories(${JEMALLOC_INCLUDE_DIR})
# list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES})
#endif ()
if (ENABLE_FFMPEG)
find_package(PkgConfig QUIET)
#ffmpeg/libutil
if (PKG_CONFIG_FOUND)
pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil)
if (AVUTIL_FOUND)
include_directories(${AVUTIL_INCLUDE_DIRS})
link_directories(${AVUTIL_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
message(STATUS "found library:${AVUTIL_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libavcodec
if (PKG_CONFIG_FOUND)
pkg_check_modules(AVCODEC QUIET IMPORTED_TARGET libavcodec)
if (AVCODEC_FOUND)
include_directories(${AVCODEC_INCLUDE_DIRS})
link_directories(${AVCODEC_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
message(STATUS "found library:${AVCODEC_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libswscale
if (PKG_CONFIG_FOUND)
pkg_check_modules(SWSCALE QUIET IMPORTED_TARGET libswscale)
if (SWSCALE_FOUND)
include_directories(${SWSCALE_INCLUDE_DIRS})
link_directories(${SWSCALE_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${SWSCALE_LIBRARIES})
message(STATUS "found library:${SWSCALE_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libswresample
if (PKG_CONFIG_FOUND)
pkg_check_modules(SWRESAMPLE QUIET IMPORTED_TARGET libswresample)
if (SWRESAMPLE_FOUND)
include_directories(${SWRESAMPLE_INCLUDE_DIRS})
link_directories(${SWRESAMPLE_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${SWRESAMPLE_LIBRARIES})
message(STATUS "found library:${SWRESAMPLE_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libutil
if (NOT AVUTIL_FOUND)
find_package(AVUTIL QUIET)
if (AVUTIL_FOUND)
include_directories(${AVUTIL_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
message(STATUS "found library:${AVUTIL_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libavcodec
if (NOT AVCODEC_FOUND)
find_package(AVCODEC QUIET)
if (AVCODEC_FOUND)
include_directories(${AVCODEC_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
message(STATUS "found library:${AVCODEC_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libswscale
if (NOT SWSCALE_FOUND)
find_package(SWSCALE QUIET)
if (SWSCALE_FOUND)
include_directories(${SWSCALE_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${SWSCALE_LIBRARIES})
message(STATUS "found library:${SWSCALE_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libswresample
if (NOT SWRESAMPLE_FOUND)
find_package(SWRESAMPLE QUIET)
if (SWRESAMPLE_FOUND)
include_directories(${SWRESAMPLE_INCLUDE_DIRS})
list(APPEND LINK_LIB_LIST ${SWRESAMPLE_LIBRARIES})
message(STATUS "found library:${SWRESAMPLE_LIBRARIES}")
endif ()
endif ()
if (AVUTIL_FOUND AND AVCODEC_FOUND AND SWSCALE_FOUND AND SWRESAMPLE_FOUND)
add_definitions(-DENABLE_FFMPEG)
else ()
set(ENABLE_FFMPEG off)
message(WARNING "ffmpeg相关功能未找到")
endif ()
endif ()
#jemalloc
find_package(JEMALLOC QUIET)
if (JEMALLOC_FOUND)
message(STATUS "found library:\"${JEMALLOC_LIBRARIES}\"")
include_directories(${JEMALLOC_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${JEMALLOC_LIBRARIES})
endif ()
#openssl
find_package(OpenSSL QUIET)

View File

@ -28,7 +28,6 @@ extern "C" {
#include "Network/Buffer.h"
#include "SDLAudioDevice.h"
#include "FFMpegDecoder.h"
class AudioSRCDelegate {
public:

View File

@ -1,5 +1,8 @@
find_package(PkgConfig QUIET)
if (NOT ENABLE_FFMPEG)
return()
endif ()
find_package(PkgConfig QUIET)
#SDL2
if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
@ -18,70 +21,16 @@ else ()
endif (SDL2_FOUND)
endif ()
#ffmpeg/libutil
if (PKG_CONFIG_FOUND)
pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil)
if (AVUTIL_FOUND)
include_directories(${AVUTIL_INCLUDE_DIRS})
link_directories(${AVUTIL_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
message(STATUS "found library:${AVUTIL_LIBRARIES}")
endif ()
else ()
find_package(AVUTIL QUIET)
if (AVUTIL_FOUND)
include_directories(${AVUTIL_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
message(STATUS "found library:${AVUTIL_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libswresample
if (PKG_CONFIG_FOUND)
pkg_check_modules(SWRESAMPLE QUIET IMPORTED_TARGET libswresample)
if (SWRESAMPLE_FOUND)
include_directories(${SWRESAMPLE_INCLUDE_DIRS})
link_directories(${SWRESAMPLE_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${SWRESAMPLE_LIBRARIES})
message(STATUS "found library:${SWRESAMPLE_LIBRARIES}")
endif ()
else ()
find_package(SWRESAMPLE QUIET)
if (SWRESAMPLE_FOUND)
include_directories(${SWRESAMPLE_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${SWRESAMPLE_LIBRARIES})
message(STATUS "found library:${SWRESAMPLE_LIBRARIES}")
endif ()
endif ()
#ffmpeg/libavcodec
if (PKG_CONFIG_FOUND)
pkg_check_modules(AVCODEC QUIET IMPORTED_TARGET libavcodec)
if (AVCODEC_FOUND)
include_directories(${AVCODEC_INCLUDE_DIRS})
link_directories(${AVCODEC_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
message(STATUS "found library:${AVCODEC_LIBRARIES}")
endif ()
else ()
find_package(AVCODEC QUIET)
if (AVCODEC_FOUND)
include_directories(${AVCODEC_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
message(STATUS "found library:${AVCODEC_LIBRARIES}")
endif ()
endif ()
set(PLAYER_NAME "test_player")
#ffmpeg/libavcodec ffmpeg/libavcodec SDL
if (SDL2_FOUND AND AVCODEC_FOUND AND AVUTIL_FOUND AND SWRESAMPLE_FOUND)
message(STATUS "${PLAYER_NAME} enabled")
else ()
if (NOT SDL2_FOUND)
message(STATUS "${PLAYER_NAME} disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample")
return()
endif ()
message(STATUS "${PLAYER_NAME} enabled")
aux_source_directory(. SRC_LIST)
add_executable(${PLAYER_NAME} ${SRC_LIST})
@ -95,17 +44,3 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
else ()
target_link_libraries(${PLAYER_NAME} ${LINK_LIB_LIST})
endif ()

View File

@ -19,7 +19,7 @@
#define DEFAULT_SAMPLERATE 48000
#define DEFAULT_FORMAT AUDIO_S16
#define DEFAULT_CHANNEL 2
#define DEFAULT_SAMPLES 1024
#define DEFAULT_SAMPLES 2048
class AudioSRC;

View File

@ -14,7 +14,7 @@
#include "Rtsp/UDPServer.h"
#include "Player/MediaPlayer.h"
#include "Util/onceToken.h"
#include "FFMpegDecoder.h"
#include "Codec/Transcode.h"
#include "YuvDisplayer.h"
#include "AudioSRC.h"
using namespace std;
@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
}
auto pcm = swr->inputFrame(frame);
auto len = pcm->get()->nb_samples * pcm->get()->channels * av_get_bytes_per_sample((enum AVSampleFormat)pcm->get()->format);
audio_player->playPCM((const char *) (pcm->get()->data[0]), len);
audio_player->playPCM((const char *) (pcm->get()->data[0]), MIN(len, frame->get()->linesize[0]));
});
auto audio_delegate = std::make_shared<FrameWriterInterfaceHelper>( [decoder](const Frame::Ptr &frame) {
return decoder->inputFrame(frame, false);