Commit 76df34de by 夏楚 Committed by GitHub

Merge pull request #1825 from wasphin/feature/cmake

整理 CMakeLists.txt
parents 6fd20711 8cb73e1b
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
##############################################################################
# jsoncpp
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp JSONCPP_SRC_LIST)
add_library(jsoncpp STATIC ${JSONCPP_SRC_LIST})
target_compile_options(jsoncpp
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(jsoncpp
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
update_cached_list(MK_LINK_LIBRARIES jsoncpp)
##############################################################################
# media-server
set(MediaServer_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/media-server")
# TODO: 补一个函数处理各种库
# 添加 mov、flv 库用于 MP4 录制
if(ENABLE_MP4)
message(STATUS "ENABLE_MP4 defined")
# MOV
set(MediaServer_MOV_ROOT ${MediaServer_ROOT}/libmov)
aux_source_directory(${MediaServer_MOV_ROOT}/include MOV_SRC_LIST)
aux_source_directory(${MediaServer_MOV_ROOT}/source MOV_SRC_LIST)
add_library(mov STATIC ${MOV_SRC_LIST})
add_library(MediaServer::mov ALIAS mov)
target_compile_definitions(mov
PUBLIC -DENABLE_MP4)
target_compile_options(mov
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(mov
PRIVATE
"$<BUILD_INTERFACE:${MediaServer_MOV_ROOT}/include>"
PUBLIC
"$<BUILD_INTERFACE:${MediaServer_MOV_ROOT}/include>")
# FLV
set(MediaServer_FLV_ROOT ${MediaServer_ROOT}/libflv)
aux_source_directory(${MediaServer_FLV_ROOT}/include FLV_SRC_LIST)
aux_source_directory(${MediaServer_FLV_ROOT}/source FLV_SRC_LIST)
add_library(flv STATIC ${FLV_SRC_LIST})
add_library(MediaServer::flv ALIAS flv)
target_compile_options(flv
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(flv
PRIVATE
"$<BUILD_INTERFACE:${MediaServer_FLV_ROOT}/include>"
PUBLIC
"$<BUILD_INTERFACE:${MediaServer_FLV_ROOT}/include>")
update_cached_list(MK_LINK_LIBRARIES
MediaServer::flv MediaServer::mov)
update_cached_list(MK_COMPILE_DEFINITIONS
ENABLE_MP4)
endif()
# 添加 mpeg 用于支持 ts 生成
if(ENABLE_RTPPROXY OR ENABLE_HLS)
# mpeg
set(MediaServer_MPEG_ROOT ${MediaServer_ROOT}/libmpeg)
aux_source_directory(${MediaServer_MPEG_ROOT}/include MPEG_SRC_LIST)
aux_source_directory(${MediaServer_MPEG_ROOT}/source MPEG_SRC_LIST)
add_library(mpeg STATIC ${MPEG_SRC_LIST})
add_library(MediaServer::mpeg ALIAS mpeg)
target_compile_options(mpeg
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(mpeg
PRIVATE
"$<BUILD_INTERFACE:${MediaServer_MPEG_ROOT}/include>"
PUBLIC
"$<BUILD_INTERFACE:${MediaServer_MPEG_ROOT}/include>")
update_cached_list(MK_LINK_LIBRARIES MediaServer::mpeg)
if(ENABLE_RTPPROXY)
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_RTPPROXY)
endif()
if(ENABLE_HLS)
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_HLS)
endif()
endif()
##############################################################################
# toolkit
# TODO: 改造 toolkit 以便直接引用
include(CheckStructHasMember)
include(CheckSymbolExists)
# 检查 sendmmsg 相关依赖并设置对应的宏, 配置 _GNU_SOURCE 以启用 GNU 扩展特性
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_struct_has_member("struct mmsghdr" msg_hdr sys/socket.h HAVE_MMSG_HDR)
check_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG_API)
check_symbol_exists(recvmmsg sys/socket.h HAVE_RECVMMSG_API)
set(COMPILE_DEFINITIONS)
if(HAVE_MMSG_HDR)
list(APPEND COMPILE_DEFINITIONS HAVE_MMSG_HDR)
endif()
if(HAVE_SENDMMSG_API)
list(APPEND COMPILE_DEFINITIONS HAVE_SENDMMSG_API)
endif()
if(HAVE_RECVMMSG_API)
list(APPEND COMPILE_DEFINITIONS HAVE_RECVMMSG_API)
endif()
set(ToolKit_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKit)
# 收集源代码
file(GLOB ToolKit_SRC_LIST
${ToolKit_ROOT}/src/*/*.cpp
${ToolKit_ROOT}/src/*/*.h
${ToolKit_ROOT}/src/*/*.c)
if(IOS)
list(APPEND ToolKit_SRC_LIST
${ToolKit_ROOT}/Network/Socket_ios.mm)
endif()
# 去除 win32 的适配代码
if(NOT WIN32)
list(REMOVE_ITEM ToolKit_SRC_LIST ${ToolKit_ROOT}/win32/getopt.c)
else()
# 防止 Windows.h 包含 Winsock.h
list(APPEND COMPILE_DEFINITIONS
WIN32_LEAN_AND_MEAN MP4V2_NO_STDINT_DEFS
# 禁用警告
_CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
# 添加库
add_library(zltoolkit STATIC ${ToolKit_SRC_LIST})
add_library(ZLMediaKit::ToolKit ALIAS zltoolkit)
target_compile_definitions(zltoolkit
PUBLIC ${COMPILE_DEFINITIONS})
target_compile_options(zltoolkit
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(zltoolkit
PRIVATE
"$<BUILD_INTERFACE:${ToolKit_ROOT}/src>"
PUBLIC
"$<BUILD_INTERFACE:${ToolKit_ROOT}>/src")
update_cached_list(MK_LINK_LIBRARIES ZLMediaKit::ToolKit)
if(USE_SOLUTION_FOLDERS AND (NOT GROUP_BY_EXPLORER))
# 在 IDE 中对文件进行分组, 源文件和头文件分开
set_file_group(${ToolKit_ROOT}/src ${ToolKit_SRC_LIST})
endif()
# 未在使用
if(ENABLE_CXX_API)
# 保留目录结构
install(DIRECTORY ${ToolKit_ROOT}/
DESTINATION ${INSTALL_PATH_INCLUDE}/ZLToolKit
REGEX "(.*[.](md|cpp)|win32)$" EXCLUDE)
install(TARGETS zltoolkit
DESTINATION ${INSTALL_PATH_LIB})
endif()
......@@ -36,5 +36,5 @@ file(GLOB JNI_src_list ${JNI_Root}/*.cpp ${JNI_Root}/*.h)
add_library(zlmediakit_jni SHARED ${JNI_src_list})
#链接
target_link_libraries(zlmediakit_jni -Wl,--start-group log z ${LINK_LIB_LIST} -Wl,--end-group)
target_link_libraries(zlmediakit_jni -Wl,--start-group log z ${MK_LINK_LIBRARIES} -Wl,--end-group)
include_directories(include source)
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
include(GenerateExportHeader)
file(GLOB api_src_list include/*.h source/*.cpp source/*.h source/*.c)
file(GLOB API_SRC_LIST
include/*.h
source/*.c
source/*.cpp
source/*.h)
set(LINK_LIBRARIES ${MK_LINK_LIBRARIES} jsoncpp)
if (IOS)
add_library(mk_api STATIC ${api_src_list})
target_link_libraries(mk_api ${LINK_LIB_LIST} jsoncpp)
if(IOS)
add_library(mk_api STATIC ${API_SRC_LIST})
target_link_libraries(mk_api
PRIVATE ${LINK_LIBRARIES})
return()
endif ()
add_definitions(-DGENERATE_EXPORT)
include_directories(${CMAKE_BINARY_DIR})
set(COMPILE_DEFINITIONS ${MK_COMPILE_DEFINITIONS})
list(APPEND COMPILE_DEFINITIONS GENERATE_EXPORT)
if (ENABLE_API_STATIC_LIB)
add_definitions(-DMediaKitApi_STATIC)
add_library(mk_api STATIC ${api_src_list})
else ()
add_library(mk_api SHARED ${api_src_list})
endif ()
if(ENABLE_API_STATIC_LIB)
add_library(mk_api STATIC ${API_SRC_LIST})
list(APPEND COMPILE_DEFINITIONS MediaKitApi_STATIC)
else()
add_library(mk_api SHARED ${API_SRC_LIST})
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(mk_api -Wl,--start-group jsoncpp ${LINK_LIB_LIST} -Wl,--end-group)
else ()
target_link_libraries(mk_api jsoncpp ${LINK_LIB_LIST})
endif ()
target_compile_definitions(mk_api
PRIVATE ${COMPILE_DEFINITIONS})
target_include_directories(mk_api
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(mk_api -Wl,--start-group ${LINK_LIBRARIES} -Wl,--end-group)
else()
target_link_libraries(mk_api jsoncpp ${LINK_LIBRARIES})
endif()
generate_export_header(mk_api
EXPORT_MACRO_NAME API_EXPORT
BASE_NAME MK_API
STATIC_DEFINE MediaKitApi_STATIC
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/mk_export.h"
)
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/mk_export.h")
add_subdirectory(tests)
file(GLOB api_header_list include/*.h ${CMAKE_BINARY_DIR}/*.h)
install(FILES ${api_header_list} DESTINATION ${INSTALL_PATH_INCLUDE})
install(TARGETS mk_api ARCHIVE DESTINATION ${INSTALL_PATH_LIB} LIBRARY DESTINATION ${INSTALL_PATH_LIB})
\ No newline at end of file
file(GLOB API_HEADER_LIST include/*.h ${CMAKE_CURRENT_BINARY_DIR}/*.h)
install(FILES ${API_HEADER_LIST}
DESTINATION ${INSTALL_PATH_INCLUDE})
install(TARGETS mk_api
ARCHIVE DESTINATION ${INSTALL_PATH_LIB}
LIBRARY DESTINATION ${INSTALL_PATH_LIB})
aux_source_directory(. TEST_SRC_LIST)
include_directories(${PROJECT_BINARY_DIR}/api)
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} TEST_SRC_LIST)
foreach(TEST_SRC ${TEST_SRC_LIST})
STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC})
get_filename_component(TEST_EXE_NAME ${TEST_SRC} NAME_WE)
if (NOT ENABLE_FFMPEG)
if(NOT ENABLE_FFMPEG)
# 过滤掉依赖 FFmpeg 的测试模块
if ("${TEST_EXE_NAME}" MATCHES "player_opencv")
if("${TEST_EXE_NAME}" MATCHES "player_opencv")
continue()
endif ()
endif ()
endif()
endif()
message(STATUS "add c api tester:${TEST_EXE_NAME}")
message(STATUS "add c api tester: ${TEST_EXE_NAME}")
set(exe_name api_tester_${TEST_EXE_NAME})
add_executable(${exe_name} ${TEST_SRC})
if(USE_SOLUTION_FOLDERS)
SET_PROPERTY(TARGET ${exe_name} PROPERTY FOLDER "api_test")
endif()
if(MSVC)
set_target_properties(${exe_name} PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
set_property(TARGET ${exe_name} PROPERTY FOLDER "api_test")
endif()
target_link_libraries(${exe_name} mk_api)
target_compile_options(${exe_name} PRIVATE ${COMPILE_OPTIONS_DEFAULT})
endforeach()
......
if (NOT ENABLE_FFMPEG)
return()
endif ()
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
set(LINK_LIBRARIES ${MK_LINK_LIBRARIES})
find_package(PkgConfig QUIET)
#查找SDL2是否安装
if (PKG_CONFIG_FOUND)
# 查找 SDL2 是否安装
if(PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
if (SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARY_DIRS})
list(APPEND LINK_LIB_LIST ${SDL2_LIBRARIES})
message(STATUS "found library:${SDL2_LIBRARIES}")
endif ()
else ()
if(SDL2_FOUND)
list(APPEND LINK_LIBRARIES PkgConfig::SDL2)
message(STATUS "found library: ${SDL2_LIBRARIES}")
endif()
else()
find_package(SDL2 QUIET)
if (SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${SDL2_LIBRARY})
message(STATUS "found library:${SDL2_LIBRARY}")
endif (SDL2_FOUND)
endif ()
if(SDL2_FOUND)
include_directories(SYSTEM ${SDL2_INCLUDE_DIR})
list(APPEND LINK_LIBRARIES ${SDL2_LIBRARY})
message(STATUS "found library: ${SDL2_LIBRARY}")
endif()
endif()
set(PLAYER_NAME "test_player")
#如果ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译播放器
if (NOT SDL2_FOUND)
message(STATUS "${PLAYER_NAME} disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample")
# 如果 ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译播放器
if(NOT SDL2_FOUND)
message(WARNING "${PLAYER_NAME} disabled, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil ffmpeg/libswresample")
return()
endif ()
endif()
message(STATUS "${PLAYER_NAME} enabled")
aux_source_directory(. SRC_LIST)
add_executable(${PLAYER_NAME} ${SRC_LIST})
target_compile_definitions(${PLAYER_NAME}
PRIVATE ${MK_COMPILE_DEFINITIONS})
target_compile_options(${PLAYER_NAME}
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
if (MSVC)
set_target_properties(${PLAYER_NAME} PROPERTIES COMPILE_FLAGS ${VS_FALGS})
# TODO: 统一参数?
if(MSVC)
set_target_properties(${PLAYER_NAME} PROPERTIES LINK_FLAGS "/SAFESEH:NO /SUBSYSTEM:WINDOWS")
endif ()
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${PLAYER_NAME} -Wl,--start-group ${LINK_LIB_LIST} -Wl,--end-group)
else ()
target_link_libraries(${PLAYER_NAME} ${LINK_LIB_LIST})
endif ()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${PLAYER_NAME} -Wl,--start-group ${LINK_LIBRARIES} -Wl,--end-group)
else()
target_link_libraries(${PLAYER_NAME} ${LINK_LIBRARIES})
endif()
include_directories(../3rdpart)
file(GLOB jsoncpp_src_list ../3rdpart/jsoncpp/*.cpp ../3rdpart/jsoncpp/*.h )
add_library(jsoncpp STATIC ${jsoncpp_src_list})
file(GLOB MediaServer_src_list ./*.cpp ./*.h)
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
if (ENABLE_SERVER_LIB)
add_definitions(-DDISABLE_MAIN)
add_library(MediaServer STATIC ${MediaServer_src_list})
list(APPEND LINK_LIB_LIST MediaServer jsoncpp)
set(LINK_LIB_LIST ${LINK_LIB_LIST} PARENT_SCOPE)
file(GLOB MediaServer_SRC_LIST ./*.cpp ./*.h)
set(COMPILE_DEFINITIONS ${MK_COMPILE_DEFINITIONS})
if(ENABLE_SERVER_LIB)
list(APPEND COMPILE_DEFINITIONS DISABLE_MAIN)
add_library(MediaServer STATIC ${MediaServer_SRC_LIST})
target_compile_definitions(MediaServer
PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(MediaServer
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_link_libraries(MediaServer
PRIVATE ${MK_LINK_LIBRARIES})
update_cached(MK_LINK_LIBRARIES MediaServer)
return()
endif ()
endif()
add_executable(MediaServer ${MediaServer_src_list})
add_executable(MediaServer ${MediaServer_SRC_LIST})
target_compile_definitions(MediaServer
PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(MediaServer
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
if(MSVC)
set_target_properties(MediaServer PROPERTIES COMPILE_FLAGS ${VS_FALGS} )
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(MediaServer -Wl,--start-group ${MK_LINK_LIBRARIES} -Wl,--end-group)
else()
install(TARGETS MediaServer DESTINATION ${INSTALL_PATH_EXECUTABLE})
target_link_libraries(MediaServer ${MK_LINK_LIBRARIES})
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(MediaServer -Wl,--start-group jsoncpp ${LINK_LIB_LIST} -Wl,--end-group)
else ()
target_link_libraries(MediaServer jsoncpp ${LINK_LIB_LIST})
endif ()
install(TARGETS MediaServer DESTINATION ${INSTALL_PATH_RUNTIME})
......@@ -368,6 +368,7 @@ Value makeMediaSourceJson(MediaSource &media){
return item;
}
#if defined(ENABLE_RTPPROXY)
uint16_t openRtpServer(uint16_t local_port, const string &stream_id, bool enable_tcp, const string &local_ip, bool re_use_port, uint32_t ssrc) {
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
if (s_rtpServerMap.find(stream_id) != s_rtpServerMap.end()) {
......@@ -399,6 +400,7 @@ bool closeRtpServer(const string &stream_id) {
s_rtpServerMap.erase(it);
return true;
}
#endif
void getStatisticJson(const function<void(Value &val)> &cb) {
auto obj = std::make_shared<Value>(objectValue);
......
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
file(GLOB MediaKit_SRC_LIST
${CMAKE_CURRENT_SOURCE_DIR}/*/*.c
${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*/*.h)
if(USE_SOLUTION_FOLDERS AND (NOT GROUP_BY_EXPLORER))
# 在 IDE 中对文件进行分组, 源文件和头文件分开
set_file_group("${CMAKE_CURRENT_SOURCE_DIR}" ${MediaKit_SRC_LIST})
endif()
# 添加库
add_library(zlmediakit STATIC ${MediaKit_SRC_LIST})
add_library(ZLMediaKit::MediaKit ALIAS zlmediakit)
set(LINK_LIBRARIES ${MK_LINK_LIBRARIES})
list(REMOVE_ITEM LINK_LIBRARIES ZLMediaKit::MediaKit)
set(COMPILE_DEFINITIONS ${MK_COMPILE_DEFINITIONS})
target_compile_definitions(zlmediakit
PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(zlmediakit
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_link_libraries(zlmediakit
PRIVATE ${LINK_LIBRARIES})
target_include_directories(zlmediakit
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
update_cached_list(MK_LINK_LIBRARIES ZLMediaKit::MediaKit)
# 未在使用
if(ENABLE_CXX_API)
# 保留目录结构
install(DIRECTORY ${MediaKit_Root}/
DESTINATION ${INSTALL_PATH_INCLUDE}/ZLMediaKit
REGEX ".*[.](md|cpp)$" EXCLUDE)
install(TARGETS zlmediakit
DESTINATION ${INSTALL_PATH_LIB})
endif ()
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
file(GLOB SRT_SRC_LIST *.cpp *.h *.hpp)
add_library(srt STATIC ${SRT_SRC_LIST})
add_library(ZLMediaKit::SRT ALIAS srt)
target_link_libraries(srt
PUBLIC
ZLMediaKit::MediaKit
ZLMediaKit::ToolKit)
target_compile_options(srt
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_include_directories(srt
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>")
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_SRT)
update_cached_list(MK_LINK_LIBRARIES ZLMediaKit::SRT)
message(STATUS "srt 功能已开启")
execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/default.pem ${EXECUTABLE_OUTPUT_PATH}/)
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
execute_process(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/default.pem ${EXECUTABLE_OUTPUT_PATH}/)
aux_source_directory(. TEST_SRC_LIST)
foreach (TEST_SRC ${TEST_SRC_LIST})
foreach(TEST_SRC ${TEST_SRC_LIST})
get_filename_component(TEST_EXE_NAME ${TEST_SRC} NAME_WE)
if (NOT ENABLE_WEBRTC)
if(NOT TARGET ZLMediaKit::WebRTC)
# 暂时过滤掉依赖 WebRTC 的测试模块
if ("${TEST_EXE_NAME}" MATCHES "test_rtcp_nack")
if("${TEST_EXE_NAME}" MATCHES "test_rtcp_nack")
continue()
endif ()
endif ()
endif()
endif()
message(STATUS "add test:${TEST_EXE_NAME}")
message(STATUS "add test: ${TEST_EXE_NAME}")
add_executable(${TEST_EXE_NAME} ${TEST_SRC})
target_compile_options(${TEST_EXE_NAME}
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
if(USE_SOLUTION_FOLDERS)
SET_PROPERTY(TARGET ${TEST_EXE_NAME} PROPERTY FOLDER "test")
endif ()
if (MSVC)
set_target_properties(${TEST_EXE_NAME} PROPERTIES COMPILE_FLAGS ${VS_FALGS})
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${TEST_EXE_NAME} -Wl,--start-group ${LINK_LIB_LIST} -Wl,--end-group)
else ()
target_link_libraries(${TEST_EXE_NAME} ${LINK_LIB_LIST})
endif ()
endforeach ()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${TEST_EXE_NAME} -Wl,--start-group ${MK_LINK_LIBRARIES} -Wl,--end-group)
else()
target_link_libraries(${TEST_EXE_NAME} ${MK_LINK_LIBRARIES})
endif()
endforeach()
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# 查找 srtp 是否安装
find_package(SRTP QUIET)
if(NOT SRTP_FOUND OR NOT ENABLE_OPENSSL)
set(ENABLE_WEBRTC OFF)
message(WARNING "srtp 未找到, WebRTC 相关功能打开失败")
return()
endif()
message(STATUS "found library: ${SRTP_LIBRARIES}")
include_directories(SYSTEM ${SRTP_INCLUDE_DIRS})
set(LINK_LIBRARIES ${SRTP_LIBRARIES})
find_package(SCTP QUIET)
if(SCTP_FOUND)
message(STATUS "found library: ${SCTP_INCLUDE_DIRS} ${SCTP_LIBRARIES}")
include_directories(SYSTEM ${SCTP_INCLUDE_DIRS})
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_SCTP)
update_cached_list(LINK_LIBRARIES ${SCTP_LIBRARIES})
message(STATUS "WebRTC datachannel 功能已打开")
endif()
file(GLOB WEBRTC_SRC_LIST
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
add_library(webrtc ${WEBRTC_SRC_LIST})
add_library(ZLMediaKit::WebRTC ALIAS webrtc)
target_compile_options(webrtc
PRIVATE ${COMPILE_OPTIONS_DEFAULT})
target_link_libraries(webrtc
PRIVATE
ZLMediaKit::MediaKit
ZLMediaKit::ToolKit
PUBLIC
${LINK_LIBRARIES})
target_include_directories(webrtc
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>")
message(STATUS "WebRTC 功能已开启")
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_WEBRTC)
update_cached_list(MK_LINK_LIBRARIES ZLMediaKit::WebRTC ${LINK_LIBRARIES})
......@@ -20,18 +20,23 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// #define MS_LOG_DEV_LEVEL 3
#include "SrtpSession.hpp"
#include <cstring> // std::memset(), std::memcpy()
#include "logger.h"
#include "Util/util.h"
#include "Util/logger.h"
#include "Util/util.h"
#include "logger.h"
#include <srtp2/srtp.h>
#include <cstring> // std::memset(), std::memcpy()
#include <vector>
using namespace toolkit;
namespace RTC
{
/* Static. */
namespace RTC {
static std::vector<const char *> errors = {
/* Static. */
static std::vector<const char *> errors = {
// From 0 (srtp_err_status_ok) to 24 (srtp_err_status_pfkey_err).
"success (srtp_err_status_ok)",
"unspecified failure (srtp_err_status_fail)",
......@@ -57,23 +62,36 @@ namespace RTC
"error parsing data (srtp_err_status_parse_err)",
"error encoding data (srtp_err_status_encode_err)",
"error while using semaphores (srtp_err_status_semaphore_err)",
"error while using pfkey (srtp_err_status_pfkey_err)"};
// clang-format on
"error while using pfkey (srtp_err_status_pfkey_err)"
};
/* Static methods. */
const char *DepLibSRTP::GetErrorString(srtp_err_status_t code) {
class DepLibSRTP : public std::enable_shared_from_this<DepLibSRTP> {
public:
using Ptr = std::shared_ptr<DepLibSRTP>;
~DepLibSRTP();
static bool IsError(srtp_err_status_t code);
static const char *GetErrorString(srtp_err_status_t code);
static DepLibSRTP &Instance();
private:
DepLibSRTP();
};
const char *DepLibSRTP::GetErrorString(srtp_err_status_t code) {
// This throws out_of_range if the given index is not in the vector.
return errors.at(code);
}
}
bool DepLibSRTP::IsError(srtp_err_status_t code) {
bool DepLibSRTP::IsError(srtp_err_status_t code) {
return (code != srtp_err_status_ok);
}
}
INSTANCE_IMP(DepLibSRTP);
INSTANCE_IMP(DepLibSRTP);
DepLibSRTP::DepLibSRTP(){
DepLibSRTP::DepLibSRTP() {
MS_TRACE();
MS_DEBUG_TAG(info, "libsrtp version: \"%s\"", srtp_get_version_string());
......@@ -102,10 +120,9 @@ namespace RTC
}
// Set libsrtp event handler.
err = srtp_install_event_handler([](srtp_event_data_t *data){
err = srtp_install_event_handler([](srtp_event_data_t *data) {
MS_TRACE();
switch (data->event)
{
switch (data->event) {
case event_ssrc_collision:
MS_WARN_TAG(srtp, "SSRC collision occurred");
break;
......@@ -124,23 +141,21 @@ namespace RTC
}
});
if (DepLibSRTP::IsError(err))
{
if (DepLibSRTP::IsError(err)) {
MS_THROW_ERROR("srtp_install_event_handler() failed: %s", DepLibSRTP::GetErrorString(err));
}
}
}
DepLibSRTP::~DepLibSRTP(){
DepLibSRTP::~DepLibSRTP() {
MS_TRACE();
srtp_shutdown();
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/* Instance methods. */
/* Instance methods. */
SrtpSession::SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t* key, size_t keyLen)
{
SrtpSession::SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t *key, size_t keyLen) {
_env = DepLibSRTP::Instance().shared_from_this();
MS_TRACE();
......@@ -149,18 +164,15 @@ namespace RTC
// Set all policy fields to 0.
std::memset(&policy, 0, sizeof(srtp_policy_t));
switch (cryptoSuite)
{
case CryptoSuite::AES_CM_128_HMAC_SHA1_80:
{
switch (cryptoSuite) {
case CryptoSuite::AES_CM_128_HMAC_SHA1_80: {
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break;
}
case CryptoSuite::AES_CM_128_HMAC_SHA1_32:
{
case CryptoSuite::AES_CM_128_HMAC_SHA1_32: {
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
// NOTE: Must be 80 for RTCP.
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
......@@ -168,34 +180,28 @@ namespace RTC
break;
}
case CryptoSuite::AEAD_AES_256_GCM:
{
case CryptoSuite::AEAD_AES_256_GCM: {
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp);
break;
}
case CryptoSuite::AEAD_AES_128_GCM:
{
case CryptoSuite::AEAD_AES_128_GCM: {
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp);
break;
}
default:
{
default: {
MS_ABORT("unknown SRTP crypto suite");
}
}
MS_ASSERT(
(int)keyLen == policy.rtp.cipher_key_len,
"given keyLen does not match policy.rtp.cipher_keyLen");
MS_ASSERT((int)keyLen == policy.rtp.cipher_key_len, "given keyLen does not match policy.rtp.cipher_keyLen");
switch (type)
{
switch (type) {
case Type::INBOUND:
policy.ssrc.type = ssrc_any_inbound;
break;
......@@ -217,80 +223,71 @@ namespace RTC
if (DepLibSRTP::IsError(err))
MS_THROW_ERROR("srtp_create() failed: %s", DepLibSRTP::GetErrorString(err));
}
}
SrtpSession::~SrtpSession()
{
SrtpSession::~SrtpSession() {
MS_TRACE();
if (this->session != nullptr)
{
if (this->session != nullptr) {
srtp_err_status_t err = srtp_dealloc(this->session);
if (DepLibSRTP::IsError(err))
MS_ABORT("srtp_dealloc() failed: %s", DepLibSRTP::GetErrorString(err));
}
}
}
bool SrtpSession::EncryptRtp(uint8_t* data, int* len)
{
bool SrtpSession::EncryptRtp(uint8_t *data, int *len) {
MS_TRACE();
srtp_err_status_t err =
srtp_protect(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
srtp_err_status_t err = srtp_protect(this->session, static_cast<void *>(data), reinterpret_cast<int *>(len));
if (DepLibSRTP::IsError(err))
{
if (DepLibSRTP::IsError(err)) {
WarnL << "srtp_protect() failed:" << DepLibSRTP::GetErrorString(err);
return false;
}
return true;
}
}
bool SrtpSession::DecryptSrtp(uint8_t* data, int* len)
{
bool SrtpSession::DecryptSrtp(uint8_t *data, int *len) {
MS_TRACE();
srtp_err_status_t err =
srtp_unprotect(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
srtp_err_status_t err = srtp_unprotect(this->session, static_cast<void *>(data), reinterpret_cast<int *>(len));
if (DepLibSRTP::IsError(err))
{
if (DepLibSRTP::IsError(err)) {
WarnL << "srtp_unprotect() failed:" << DepLibSRTP::GetErrorString(err);
return false;
}
return true;
}
}
bool SrtpSession::EncryptRtcp(uint8_t* data, int* len)
{
bool SrtpSession::EncryptRtcp(uint8_t *data, int *len) {
MS_TRACE();
srtp_err_status_t err = srtp_protect_rtcp(
this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
srtp_err_status_t err = srtp_protect_rtcp(this->session, static_cast<void *>(data), reinterpret_cast<int *>(len));
if (DepLibSRTP::IsError(err))
{
if (DepLibSRTP::IsError(err)) {
WarnL << "srtp_protect_rtcp() failed:" << DepLibSRTP::GetErrorString(err);
return false;
}
return true;
}
}
bool SrtpSession::DecryptSrtcp(uint8_t* data, int* len)
{
bool SrtpSession::DecryptSrtcp(uint8_t *data, int *len) {
MS_TRACE();
srtp_err_status_t err =
srtp_unprotect_rtcp(this->session, static_cast<void*>(data), reinterpret_cast<int*>(len));
srtp_err_status_t err = srtp_unprotect_rtcp(this->session, static_cast<void *>(data), reinterpret_cast<int *>(len));
if (DepLibSRTP::IsError(err))
{
if (DepLibSRTP::IsError(err)) {
WarnL << "srtp_unprotect_rtcp() failed:" << DepLibSRTP::GetErrorString(err);
return false;
}
return true;
}
}
void SrtpSession::RemoveStream(uint32_t ssrc) {
srtp_remove_stream(this->session, uint32_t { htonl(ssrc) });
}
} // namespace RTC
......@@ -20,31 +20,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define MS_RTC_SRTP_SESSION_HPP
#include "Utils.hpp"
#include <srtp2/srtp.h>
#include <vector>
#include <memory>
namespace RTC
{
class DepLibSRTP : public std::enable_shared_from_this<DepLibSRTP>
{
public:
using Ptr = std::shared_ptr<DepLibSRTP>;
~DepLibSRTP();
typedef struct srtp_ctx_t_ *srtp_t;
static bool IsError(srtp_err_status_t code);
static const char *GetErrorString(srtp_err_status_t code);
static DepLibSRTP &Instance();
namespace RTC {
private:
DepLibSRTP();
};
class DepLibSRTP;
class SrtpSession
{
public:
enum class CryptoSuite
{
class SrtpSession {
public:
enum class CryptoSuite {
NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32,
......@@ -52,32 +39,26 @@ namespace RTC
AEAD_AES_128_GCM
};
public:
enum class Type
{
INBOUND = 1,
OUTBOUND
};
public:
enum class Type { INBOUND = 1, OUTBOUND };
public:
SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t* key, size_t keyLen);
public:
SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t *key, size_t keyLen);
~SrtpSession();
public:
bool EncryptRtp(uint8_t* data, int* len);
bool DecryptSrtp(uint8_t* data, int* len);
bool EncryptRtcp(uint8_t* data, int* len);
bool DecryptSrtcp(uint8_t* data, int* len);
void RemoveStream(uint32_t ssrc)
{
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
}
private:
public:
bool EncryptRtp(uint8_t *data, int *len);
bool DecryptSrtp(uint8_t *data, int *len);
bool EncryptRtcp(uint8_t *data, int *len);
bool DecryptSrtcp(uint8_t *data, int *len);
void RemoveStream(uint32_t ssrc);
private:
// Allocated by this.
srtp_t session{ nullptr };
DepLibSRTP::Ptr _env;
};
srtp_t session { nullptr };
std::shared_ptr<DepLibSRTP> _env;
};
} // namespace RTC
#endif
......@@ -13,6 +13,9 @@
#include "Rtcp/RtcpFCI.h"
#include "RtpExt.h"
#include "Rtsp/RtpReceiver.h"
#include <srtp2/srtp.h>
#include <iostream>
#define RTP_SSRC_OFFSET 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论