【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.txt 构建脚本分析 | Oboe 源代码构建脚本分析 )
文章目錄
- 一、Oboe 源碼路徑
- 二、閱讀 CMakeList.txt 查看依賴
- 三、hello-oboe 中 NDK 的 CMakeList.txt 構建腳本
- 四、Oboe 源碼 的 CMakeList.txt 構建腳本 ( 參考 )
相關資源鏈接 :
- Oboe 源碼 : google/oboe
- hello-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.cpp set (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 -Ofast target_compile_options(oboePRIVATE-std=c++14-Wall-Wextra-semi-Wshadow-Wshadow-field-Ofast"$<$<CONFIG:DEBUG>:-Werror>")# Enable logging of D,V for debug builds target_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-v8a install(TARGETS oboeLIBRARY DESTINATION lib/${ANDROID_ABI}ARCHIVE DESTINATION lib/${ANDROID_ABI})# Also install the headers install(DIRECTORY include/oboe DESTINATION include)總結
以上是生活随笔為你收集整理的【Android 高性能音频】hello-oboe 示例解析 ( Oboe 源代码依赖 | CMakeList.txt 构建脚本分析 | Oboe 源代码构建脚本分析 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【计算机网络】网络安全 : 计算机网络安
- 下一篇: 【集合论】容斥原理 ( 复杂示例 )