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

简介: 【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


image.png


设置 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_SOURCES
        jni_bridge.cpp
        HelloOboeEngine.cpp
        SoundGenerator.cpp
        LatencyTuningCallback.cpp
)



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


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


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


# 为 hello-oboe 动态库连接需要的库
target_link_libraries(
        hello-oboe
        android
        log
        oboe    # 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_SOURCES
        jni_bridge.cpp
        HelloOboeEngine.cpp
        SoundGenerator.cpp
        LatencyTuningCallback.cpp
)
# 编译 libhello-oboe 动态库
add_library(
        hello-oboe
        SHARED
        ${DEBUG_UTILS_SOURCES}
        ${APP_SOURCES}
)
# 为 hello-oboe 动态库连接需要的库
target_link_libraries(
        hello-oboe
        android
        log
        oboe    # 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_sources
    src/aaudio/AAudioLoader.cpp
    src/aaudio/AudioStreamAAudio.cpp
    src/common/AudioSourceCaller.cpp
    src/common/AudioStream.cpp
    src/common/AudioStreamBuilder.cpp
    src/common/DataConversionFlowGraph.cpp
    src/common/FilterAudioStream.cpp
    src/common/FixedBlockAdapter.cpp
    src/common/FixedBlockReader.cpp
    src/common/FixedBlockWriter.cpp
    src/common/LatencyTuner.cpp
    src/common/SourceFloatCaller.cpp
    src/common/SourceI16Caller.cpp
    src/common/Utilities.cpp
    src/common/QuirksManager.cpp
    src/fifo/FifoBuffer.cpp
    src/fifo/FifoController.cpp
    src/fifo/FifoControllerBase.cpp
    src/fifo/FifoControllerIndirect.cpp
        src/flowgraph/FlowGraphNode.cpp
    src/flowgraph/ClipToRange.cpp
    src/flowgraph/ManyToMultiConverter.cpp
    src/flowgraph/MonoToMultiConverter.cpp
    src/flowgraph/RampLinear.cpp
    src/flowgraph/SampleRateConverter.cpp
    src/flowgraph/SinkFloat.cpp
    src/flowgraph/SinkI16.cpp
    src/flowgraph/SinkI24.cpp
    src/flowgraph/SourceFloat.cpp
    src/flowgraph/SourceI16.cpp
    src/flowgraph/SourceI24.cpp
    src/flowgraph/resampler/IntegerRatio.cpp
    src/flowgraph/resampler/LinearResampler.cpp
    src/flowgraph/resampler/MultiChannelResampler.cpp
    src/flowgraph/resampler/PolyphaseResampler.cpp
    src/flowgraph/resampler/PolyphaseResamplerMono.cpp
    src/flowgraph/resampler/PolyphaseResamplerStereo.cpp
    src/flowgraph/resampler/SincResampler.cpp
    src/flowgraph/resampler/SincResamplerStereo.cpp
    src/opensles/AudioInputStreamOpenSLES.cpp
    src/opensles/AudioOutputStreamOpenSLES.cpp
    src/opensles/AudioStreamBuffered.cpp
    src/opensles/AudioStreamOpenSLES.cpp
    src/opensles/EngineOpenSLES.cpp
    src/opensles/OpenSLESUtilities.cpp
    src/opensles/OutputMixerOpenSLES.cpp
    src/common/StabilizedCallback.cpp
    src/common/Trace.cpp
    src/common/Version.cpp
    )
# 编译上述源文件 
add_library(oboe ${oboe_sources})
# 指定编译器头文件查找路径 
target_include_directories(oboe
        PRIVATE src
        PUBLIC include)
# 编译标志:
#     Enable -Werror when building debug config
#     Enable -Ofast
target_compile_options(oboe
        PRIVATE
        -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 oboe
        LIBRARY DESTINATION lib/${ANDROID_ABI}
        ARCHIVE DESTINATION lib/${ANDROID_ABI})
# Also install the headers
install(DIRECTORY include/oboe DESTINATION include)



目录
相关文章
|
4天前
|
存储 弹性计算 运维
每天解析一个脚本(25)
【4月更文挑战第22天】shell脚本解析及训练(25)
26 0
|
4天前
|
存储 运维 Shell
每天解析一个脚本(16)
【4月更文挑战第20天】shell脚本解析及训练(16)
17 2
|
4天前
|
存储 运维 监控
每天解析一个脚本(15)
【4月更文挑战第19天】shell脚本解析及训练(15)
64 1
|
24天前
|
XML Java Android开发
Android实现自定义进度条(源码+解析)
Android实现自定义进度条(源码+解析)
51 1
|
1月前
|
Python
区域代理分红商城系统开发源码片段示例规则解析
level = Column(Integer, default=1) # 代理等级,例如:1代表普通用户,2代表初级代理,3代表高级代理等 parent_id = Column(Integer, ForeignKey('user.id')) # 上级代理ID 【更全面的开发源码搭建可V or TG我昵称】 parent = relationship("User", remote_side=[id]) # 上级代理对象
|
1月前
|
Python
潮玩元宇宙游戏开发基础示例规则解析
# 潮玩角色类 class ToyCharacter: def __init__(self, x, y): self.x = x self.y = y self.image = pygame.Surface([50, 50]) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.change
|
1天前
|
运维 关系型数据库 MySQL
每天解析一个脚本(45)
【4月更文挑战第25天】shell脚本解析及训练(45)
6 0
|
1天前
|
运维 监控 Shell
每天解析一个脚本(44)
【4月更文挑战第25天】shell脚本解析及训练(44)
7 0
|
1天前
|
存储 运维 关系型数据库
每天解析一个脚本(39)
【4月更文挑战第25天】shell脚本解析及训练(39)
7 0
|
2天前
|
运维 监控 Shell
每天解析一个脚本(36)
【4月更文挑战第24天】shell脚本解析及训练(36)
8 0

推荐镜像

更多