当前位置:   article > 正文

WebRTC KVS(亚马逊版)环境编译_kvs webrtc

kvs webrtc

Amazon KVS WebRTC

KVS WebRTC SDK C

  1. # WebRTC C语言版本
  2. git clone https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-c.git

KVS WebRTC SDK C++

  1. # WebRTC C++语言版本
  2. git clone https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git

KVS Producer SDK C

git clone https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git

KVS PIC

git clone https://github.com/awslabs/amazon-kinesis-video-streams-pic.git

安装编译环境

在Ubuntu与树莓派系统下你可以通过以下命令一键安装:

  1. #Ubuntu
  2. sudo apt-get install pkg-config cmake libcap2 libcap-dev -y
  3. #MacOS
  4. brew install cmake pkg-config srtp

相关配置

然后在已经 CheckOut 的根目录下创建一个名叫 build 的子目录,然后进入该目录并执行 CMake 命令

  1. mkdir -p amazon-kinesis-video-streams-webrtc-sdk-c/build
  2. cd amazon-kinesis-video-streams-webrtc-sdk-c/build
  3. cmake ..

源码已经提供了一个使用 GStreamer 的案例来采集与编码视频流,然后也通过这个库发送出去。只有当 pkg-config 发现系统上安装了GStreamer时,才会去这么构建。

  1. #MacOS
  2. brew install gstreamer gst-plugins-base gst-plugins-good

编译提示

如果你希望进行交叉编译,那么在构建库及其所有依赖项时 CCCXX 是必须的。与此同时,你还需要设置: BUILD_OPENSSL_PLATFORMBUILD_LIBSRTP_HOST_PLATFORMBUILD_LIBSRTP_DESTINATION_PLATFORM

静态库

如果在cmake的时候设置了 -DBUILD_STATIC_LIBS=TRUE,那么所有依赖库以及 KVS WebRTC 库都将被编译成静态库。

依赖库编译

libmbedtls

选用MbedTLS,弃用OpenSSL

  1. GIT_REPOSITORY https://github.com/ARMmbed/mbedtls.git
  2. GIT_TAG v2.25.0

生成的头文件

  • mbedtls/xxx.h
  • psa/xxx.h

生成库文件(CMake静态库链接必须按此顺序):

  • libmbedx509.a
  • libmbedtls.a
  • libmbedcrypto.a

其中,需要修复CMakeLists.txt的问题:

libwebsockets(移)

推荐选用

  1. GIT_REPOSITORY https://github.com/warmcat/libwebsockets.git
  2. GIT_TAG v4.2.2

生成的头文件:

  • libwebsockets/xxx.h
  • libwebsockets.h

生成库文件:

  • libwebsockets.a

libsrtp

必须引用

  1. GIT_REPOSITORY https://github.com/cisco/libsrtp.git
  2. GIT_TAG bd0f27ec0e299ad101a396dde3f7c90d48efc8fc

生成的头文件:

  • srtp2/xxx.h

生成库文件:

  • libsrtp2.a

libusrsctp

必须引用

  1. GIT_REPOSITORY https://github.com/sctplab/usrsctp.git
  2. GIT_TAG 1ade45cbadfd19298d2c47dc538962d4425ad2dd

生成的头文件

  • usrsctp.h

生成库文件:

  • libusrsctp.a

libkvspic

  1. GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-pic.git
  2. GIT_TAG afc15aff555090424d6b92ef316116e85004a479

编译方法:

cmake .. -DBUILD_STATIC=ON -DBUILD_COMMON_LWS=ON -DBUILD_COMMON_CURL=OFF -DUSE_OPENSSL=OFF -DUSE_MBEDTLS=ON

生成头文件

  • com/xxx.h

生成库文件:

  • libkvspic.a
  • libkvspicClient.a
  • libkvspicState.a
  • libkvspicUtils.a

libkvsproducer(移)

  1. GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git
  2. GIT_TAG c7fce9e06021452ff3c42dc70c8360606b22ad53

生成的头文件

  • lws_config.h

生成库文件:

  • libkvsCommonLws.a

核心库编译

libkvswebrtc

编译方法:

  1. cmake .. \
  2. -DCMAKE_BUILD_TYPE=Release \
  3. -DCMAKE_MAKE_PROGRAM=make \
  4. -DCMAKE_C_COMPILER=gcc \
  5. -DCMAKE_CXX_COMPILER=g++ \
  6. -DBUILD_STATIC_LIBS=ON \
  7. -DUSE_OPENSSL=OFF \
  8. -DUSE_MBEDTLS=ON \
  9. -DENABLE_SIGNALING_CLIENT=OFF
  10. make

生成头文件

  • com/xxx.h

生成库文件:

  • libkvsWebrtcClient.a
  • libkvsWebrtcSignalingClient.a(移出)

裁剪掉信令模块

当我们不希望再使用Amazon自带的信令模块时,我们就不得不进行裁剪。好在KVS WebRTC代码的独立性很强,裁剪的过程中遇到的困难并不多。

首先,我们需要修改CMakeLists.txt

  1. option(ENABLE_SIGNALING_CLIENT "Enables signaling client" OFF) # 自定义添加的开关
  2. # building websockets
  3. # ---- 在这里移除掉Websocket库的依赖,由上层自己去选用信令形式
  4. if (ENABLE_SIGNALING_CLIENT)
  5. set(BUILD_ARGS
  6. -DBUILD_STATIC_LIBS=${BUILD_STATIC_LIBS}
  7. -DOPENSSL_DIR=${OPEN_SRC_INSTALL_PREFIX}
  8. -DUSE_OPENSSL=${USE_OPENSSL}
  9. -DUSE_MBEDTLS=${USE_MBEDTLS}
  10. #-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} #暂时不需要
  11. -DMBEDTLS_INCLUDE_DIRS=${MBEDTLS_INCLUDE_DIRS} #指定MBEDTLS时必须指定
  12. -DMBEDTLS_LIBRARIES=${MBEDTLS_LIBRARIES}) #指定MBEDTLS时必须指定
  13. build_dependency(websockets ${BUILD_ARGS})
  14. endif ()
  15. # building kvsCommonLws also builds kvspic
  16. # ---- 在这里移除掉Websocket库的依赖,由上层自己去选用信令形式
  17. set(BUILD_ARGS
  18. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  19. -DUSE_OPENSSL=${USE_OPENSSL}
  20. -DUSE_MBEDTLS=${USE_MBEDTLS}
  21. -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  22. -DBUILD_COMMON_LWS=${ENABLE_SIGNALING_CLIENT} #如果不启用Websocket,也没必要启用LWS了
  23. -DMBEDTLS_INCLUDE_DIRS=${MBEDTLS_INCLUDE_DIRS} #指定MBEDTLS时必须指定
  24. -DMBEDTLS_LIBRARIES=${MBEDTLS_LIBRARIES}) #指定MBEDTLS时必须指定
  25. build_dependency(kvsCommonLws ${BUILD_ARGS})
  26. # 如果不启用Websocket,那么也不会进行依赖检查
  27. if (ENABLE_SIGNALING_CLIENT)
  28. if (WIN32)
  29. SET(LIBWEBSOCKETS_LIBRARIES "websockets.lib")
  30. else ()
  31. pkg_check_modules(LIBWEBSOCKETS REQUIRED libwebsockets)
  32. endif ()
  33. else ()
  34. # 添加宏定义
  35. if (ENABLE_SIGNALING_CLIENT)
  36. add_definitions(-DENABLE_SIGNALING_CLIENT)
  37. endif ()
  38. # 不再需要包容Signaling目录下的c文件了
  39. if (ENABLE_SIGNALING_CLIENT)
  40. file(GLOB WEBRTC_SIGNALING_CLIENT_SOURCE_FILES "src/source/Signaling/*.c")
  41. endif ()
  42. # 不需要再编译libkvsWebrtcSignalingClient.a库了
  43. if (ENABLE_SIGNALING_CLIENT)
  44. add_library(kvsWebrtcSignalingClient ${LINKAGE} ${WEBRTC_SIGNALING_CLIENT_SOURCE_FILES})
  45. target_link_libraries(
  46. kvsWebrtcSignalingClient
  47. PUBLIC
  48. kvsCommonLws
  49. ${LIBWEBSOCKETS_LIBRARIES}
  50. PRIVATE kvspicUtils
  51. kvspicState
  52. ${CMAKE_THREAD_LIBS_INIT}
  53. ${EXTRA_DEPS}
  54. ${OPENSSL_SSL_LIBRARY}
  55. ${OPENSSL_CRYPTO_LIBRARY}
  56. ${GPERFTOOLS_MALLOC_LIBRARIES}
  57. ${GPERFTOOLS_PROFILER_LIBRARIES}
  58. ${MBEDTLS_LIBRARIES})
  59. endif ()
  60. if (ENABLE_SIGNALING_CLIENT)
  61. install(TARGETS kvsWebrtcClient kvsWebrtcSignalingClient
  62. LIBRARY DESTINATION lib
  63. ARCHIVE DESTINATION lib
  64. )
  65. else ()
  66. install(TARGETS kvsWebrtcClient
  67. LIBRARY DESTINATION lib
  68. ARCHIVE DESTINATION lib
  69. )
  70. endif ()
  71. # 如果不支持SignalingClient,那么这些案例也没必要编译了
  72. if (BUILD_SAMPLE)
  73. if (ENABLE_SIGNALING_CLIENT)
  74. # copy sample frames to build folder, in case developer runs sample program with command `samples/kvsWebrtcClientMaster` from `build` dir.
  75. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples/opusSampleFrames" DESTINATION .)
  76. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples/h264SampleFrames" DESTINATION .)
  77. add_subdirectory(samples)
  78. endif ()
  79. endif ()

然后修改头文件src/source/Include_i.h

  1. // Websocket
  2. #if defined ENABLE_SIGNALING_CLIENT
  3. #include <libwebsockets.h>
  4. #else
  5. #include <poll.h> //Ice模块依赖
  6. #endif
  7. // Signaling
  8. #if defined(ENABLE_SIGNALING_CLIENT)
  9. #include "Signaling/FileCache.h"
  10. #include "Signaling/Signaling.h"
  11. #include "Signaling/ChannelInfo.h"
  12. #include "Signaling/StateMachine.h"
  13. #include "Signaling/LwsApiCalls.h"
  14. #endif

依赖头文件

CMakeLists.txt

  1. target_include_directories(${PROJECT_NAME} PRIVATE
  2. ${PROJECT_SOURCE_DIR}/src
  3. ${PROJECT_SOURCE_DIR}/include
  4. ${PROJECT_SOURCE_DIR}/include/com/amazonaws
  5. )

依赖库文件

CMakeLists.txt

  1. list(APPEND KVS_WEBRTC_LIBRARY
  2. ${PROJECT_SOURCE_DIR}/lib/libkvsWebrtcClient.a
  3. ${PROJECT_SOURCE_DIR}/lib/libkvspic.a
  4. #${PROJECT_SOURCE_DIR}/lib/libkvspicClient.a
  5. #${PROJECT_SOURCE_DIR}/lib/libkvspicState.a
  6. #${PROJECT_SOURCE_DIR}/lib/libkvspicUtils.a
  7. )
  8. list(APPEND MBEDTLS_LIBRARY
  9. ${PROJECT_SOURCE_DIR}/lib/libmbedtls.a
  10. ${PROJECT_SOURCE_DIR}/lib/libmbedcrypto.a
  11. ${PROJECT_SOURCE_DIR}/lib/libmbedx509.a
  12. )
  13. list(APPEND SRTP_LIBRARY
  14. ${PROJECT_SOURCE_DIR}/lib/libsrtp2.a
  15. )
  16. list(APPEND USRSCTP_LIBRARY
  17. ${PROJECT_SOURCE_DIR}/lib/libusrsctp.a
  18. )
  19. target_link_libraries(${PROJECT_NAME} PUBLIC
  20. ${KVS_WEBRTC_LIBRARY}
  21. ${MBEDTLS_LIBRARY}
  22. ${SRTP_LIBRARY}
  23. ${USRSCTP_LIBRARY}
  24. )

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/612920
推荐阅读
相关标签
  

闽ICP备14008679号