1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.t

【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.t

时间:2020-02-16 08:09:10

相关推荐

【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.t

文章目录

一、Oboe 源码路径二、阅读 CMakeList.txt 查看依赖三、hello-oboe 中 NDK 的 CMakeList.txt 构建脚本四、Oboe 源码 的 CMakeList.txt 构建脚本 ( 参考 )

相关资源链接 :

Oboe 源码: google/oboehello-oboe源码地址 : google/oboe/samples/hello-oboe

一、Oboe 源码路径

在 oboe-1.4.3 代码示例 中的 hello-oboe 示例 , 没有添加 Oboe 的网络依赖 ( jcenter / maven ) , 因为在示例中有 Oboe 的源码 , 其路径是在 oboe-1.4.3 目录下 , 在 oboe/releases 页面下载的 Oboe 源码及示例程序 , 解压后的 oboe-1.4.3\src 路径下 ;

oboe-1.4.3\src 就是 Oboe 的 C++ 源码路径 , 其中包含了 AAudio 和 OpenSL ES 播放器的代码 ;

根据手机版本不同 , 调用不同的播放 , Android 8.0 Oreo( API Level 26 ) 及以上的手机使用 AAudio 播放器 , 8.0 以下 ( 不包含 ) 的手机使用 OpenSL ES 播放器 ;

二、阅读 CMakeList.txt 查看依赖

hello-oboe 中的 CMakeList.txt 构建脚本分析 :

构建脚本位置 oboe-1.4.3\samples\hello-oboe\src\main\cpp\CMakeLists.txt

设置 Oboe 库的目录路径 oboe-1.4.3 路径, 这是整个下载的发布版本源码的总根目录

set (OBOE_DIR ../../../../../)

添加 Oboe 库 , 作为 子工程 ; Oboe 源码不在本源码路径内 , 需要为其指定一个二进制输出文件目录 ; 系统会查找 ${OBOE_DIR} 目录下的 CMakeList.txt 文件 , 编译该配置文件对应的 Oboe 函数库 ;

add_subdirectory(${OBOE_DIR} ./oboe-bin)

上述设置就是编译 oboe-1.4.3\src 下的 Oboe 源码 ;

设置本项目 hello-oboe 中的 NDK 编译所需的源文件 , 定义变量 APP_SOURCES , 内容是四个 cpp 文件.

# 指定 APP 编译源文件 , 定义变量 APP_SOURCES , 内容是四个 cpp 文件.set (APP_SOURCESjni_bridge.cppHelloOboeEngine.cppSoundGenerator.cppLatencyTuningCallback.cpp)

编译本项目 hello-oboe 中的 动态库 ;

# 编译 libhello-oboe 动态库add_library(hello-oboeSHARED${DEBUG_UTILS_SOURCES}${APP_SOURCES})

链接动态库 , 链接 之前编译的 hello-oboe , 编译的 oboe 源码 , 以及 android , log 日志库 ;

# 为 hello-oboe 动态库连接需要的库target_link_libraries(hello-oboeandroidlogoboe # Oboe 库, 是 oboe-1.4.3/CMakeList.txt 编译出的函数库)

三、hello-oboe 中 NDK 的 CMakeList.txt 构建脚本

cmake_minimum_required(VERSION 3.4.1)### INCLUDE OBOE LIBRARY #### 设置 Oboe 库的目录路径 oboe-1.4.3 路径, 这是整个下载的发布版本源码的总根目录set (OBOE_DIR ../../../../../)# 添加 Oboe 库 , 作为子工程 ; Oboe 源码不在本源码路径内 , 需要为其指定一个二进制输出文件目录# 系统会查找 ${OBOE_DIR} 目录下的 CMakeList.txt 文件 , 编译该配置文件对应的 Oboe 函数库add_subdirectory(${OBOE_DIR} ./oboe-bin)# 包含 Oboe 库对应的头文件 , 和本应用中使用到的头文件include_directories(${OBOE_DIR}/include ${OBOE_DIR}/samples/shared)# 调试程序代码# 定义变量 DEBUG_UTILS_PATH , 该变量值为 "${OBOE_DIR}/samples/debug-utils"# 使用时, 使用 DEBUG_UTILS_PATH 代替后面的 "${OBOE_DIR}/samples/debug-utils" 字符串set (DEBUG_UTILS_PATH "${OBOE_DIR}/samples/debug-utils")# 定义变量 DEBUG_UTILS_SOURCES , 该变量值为 ${DEBUG_UTILS_PATH}/trace.cppset (DEBUG_UTILS_SOURCES ${DEBUG_UTILS_PATH}/trace.cpp)# 将指定的目录添加到编译器的搜索路径之下 , 该目录会被解析成当前源码路径的相对路径include_directories(${DEBUG_UTILS_PATH})### END OBOE INCLUDE SECTION #### 指定 APP 编译源文件 , 定义变量 APP_SOURCES , 内容是四个 cpp 文件.set (APP_SOURCESjni_bridge.cppHelloOboeEngine.cppSoundGenerator.cppLatencyTuningCallback.cpp)# 编译 libhello-oboe 动态库add_library(hello-oboeSHARED${DEBUG_UTILS_SOURCES}${APP_SOURCES})# 为 hello-oboe 动态库连接需要的库target_link_libraries(hello-oboeandroidlogoboe # Oboe 库, 是 oboe-1.4.3/CMakeList.txt 编译出的函数库)# 打开 gcc 可选标志位: 如果源码级别的调试出现问题# 关闭 -Ofast ( 再进行调试 ), 调试完毕后继续打开# target_compile_options 编译目标文件时 , 为 gcc 指定编译选项# hello-oboe 是编译的 target 目标# PRIVATE 指的是后续参数的作用域# PRIVATE 和 PUBLIC 作用域 , 会将选项填充到 target 目标文件的 COMPILE_OPTIONS 属性中# PUBLIC 和 INTERFACE 作用域 , 会将选项填充到 target 目标文件的 INTERFACE_COMPILE_OPTIONS 属性中target_compile_options(hello-oboe PRIVATE -Wall -Werror "$<$<CONFIG:RELEASE>:-Ofast>")

四、Oboe 源码 的 CMakeList.txt 构建脚本 ( 参考 )

先定义 oboe_sources 变量 , 其中内容是 oboe-1.4.3\src 路径下的所有 cpp 源码文件 ;

add_library(oboe ${oboe_sources}) 操作 , 编译上述 路径下的源文件 , 编译的函数库名称是 oboe ;

cmake_minimum_required(VERSION 3.4.1)# Set the name of the project and store it in PROJECT_NAME. Also set the following variables:# PROJECT_SOURCE_DIR (usually the root directory where Oboe has been cloned e.g.)# PROJECT_BINARY_DIR (usually the containing project's binary directory,# e.g. ${OBOE_HOME}/samples/RhythmGame/.externalNativeBuild/cmake/ndkExtractorDebug/x86/oboe-bin)project(oboe)set (oboe_sourcessrc/aaudio/AAudioLoader.cppsrc/aaudio/AudioStreamAAudio.cppsrc/common/AudioSourceCaller.cppsrc/common/AudioStream.cppsrc/common/AudioStreamBuilder.cppsrc/common/DataConversionFlowGraph.cppsrc/common/FilterAudioStream.cppsrc/common/FixedBlockAdapter.cppsrc/common/FixedBlockReader.cppsrc/common/FixedBlockWriter.cppsrc/common/LatencyTuner.cppsrc/common/SourceFloatCaller.cppsrc/common/SourceI16Caller.cppsrc/common/Utilities.cppsrc/common/QuirksManager.cppsrc/fifo/FifoBuffer.cppsrc/fifo/FifoController.cppsrc/fifo/FifoControllerBase.cppsrc/fifo/FifoControllerIndirect.cppsrc/flowgraph/FlowGraphNode.cppsrc/flowgraph/ClipToRange.cppsrc/flowgraph/ManyToMultiConverter.cppsrc/flowgraph/MonoToMultiConverter.cppsrc/flowgraph/RampLinear.cppsrc/flowgraph/SampleRateConverter.cppsrc/flowgraph/SinkFloat.cppsrc/flowgraph/SinkI16.cppsrc/flowgraph/SinkI24.cppsrc/flowgraph/SourceFloat.cppsrc/flowgraph/SourceI16.cppsrc/flowgraph/SourceI24.cppsrc/flowgraph/resampler/IntegerRatio.cppsrc/flowgraph/resampler/LinearResampler.cppsrc/flowgraph/resampler/MultiChannelResampler.cppsrc/flowgraph/resampler/PolyphaseResampler.cppsrc/flowgraph/resampler/PolyphaseResamplerMono.cppsrc/flowgraph/resampler/PolyphaseResamplerStereo.cppsrc/flowgraph/resampler/SincResampler.cppsrc/flowgraph/resampler/SincResamplerStereo.cppsrc/opensles/AudioInputStreamOpenSLES.cppsrc/opensles/AudioOutputStreamOpenSLES.cppsrc/opensles/AudioStreamBuffered.cppsrc/opensles/AudioStreamOpenSLES.cppsrc/opensles/EngineOpenSLES.cppsrc/opensles/OpenSLESUtilities.cppsrc/opensles/OutputMixerOpenSLES.cppsrc/common/StabilizedCallback.cppsrc/common/Trace.cppsrc/common/Version.cpp)# 编译上述源文件 add_library(oboe ${oboe_sources})# 指定编译器头文件查找路径 target_include_directories(oboePRIVATE srcPUBLIC include)# 编译标志:#Enable -Werror when building debug config#Enable -Ofasttarget_compile_options(oboePRIVATE-std=c++14-Wall-Wextra-semi-Wshadow-Wshadow-field-Ofast"$<$<CONFIG:DEBUG>:-Werror>")# Enable logging of D,V for debug buildstarget_compile_definitions(oboe PUBLIC $<$<CONFIG:DEBUG>:OBOE_ENABLE_LOGGING=1>)target_link_libraries(oboe PRIVATE log OpenSLES)# When installing oboe put the libraries in the lib/<ABI> folder e.g. lib/arm64-v8ainstall(TARGETS oboeLIBRARY DESTINATION lib/${ANDROID_ABI}ARCHIVE DESTINATION lib/${ANDROID_ABI})# Also install the headersinstall(DIRECTORY include/oboe DESTINATION include)

【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.txt 构建脚本分析 | Oboe 源代码构建脚本分析 )

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。