Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-native-audio-api/RNAudioAPI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version_flag = "-DAUDIOAPI_VERSION=#{package_json['version']}"

worklets_preprocessor_flag = check_if_worklets_enabled() ? '-DRN_AUDIO_API_ENABLE_WORKLETS=1' : ''
ffmpeg_flag = $RN_AUDIO_API_FFMPEG_DISABLED ? '-DRN_AUDIO_API_FFMPEG_DISABLED=1' : ''
skip_ffmpeg_argument = $RN_AUDIO_API_FFMPEG_DISABLED ? 'skipffmpeg' : ''

Pod::Spec.new do |s|
s.name = "RNAudioAPI"
Expand Down Expand Up @@ -50,7 +51,7 @@ Pod::Spec.new do |s|

s.prepare_command = <<-CMD
chmod +x scripts/download-prebuilt-binaries.sh
scripts/download-prebuilt-binaries.sh ios
scripts/download-prebuilt-binaries.sh ios #{skip_ffmpeg_argument}
CMD

# Assumes Pods dir is nested under ios project dir
Expand Down
5 changes: 2 additions & 3 deletions packages/react-native-audio-api/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ android {

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
buildConfigField "boolean", "RN_AUDIO_API_ENABLE_WORKLETS", "${isWorkletsAvailable}"


buildConfigField "boolean", "RN_AUDIO_API_FFMPEG_DISABLED", isFFmpegDisabled().toString()

externalNativeBuild {
cmake {
Expand Down Expand Up @@ -310,7 +309,7 @@ def assertMinimalReactNativeVersion = task assertMinimalReactNativeVersionTask {
task downloadPrebuiltBinaries(type: Exec) {
commandLine 'chmod', '+x', '../scripts/download-prebuilt-binaries.sh'
commandLine 'bash', '../scripts/download-prebuilt-binaries.sh'
args 'android'
args 'android', isFFmpegDisabled() ? 'skipffmpeg' : ''
}

// Make preBuild depend on the download task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ cmake_minimum_required(VERSION 3.12.0)
file(GLOB_RECURSE ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/audioapi/*.cpp")
file(GLOB_RECURSE COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/audioapi/*.cpp" "${COMMON_CPP_DIR}/audioapi/*.c")

if (RN_AUDIO_API_FFMPEG_DISABLED)
list(REMOVE_ITEM COMMON_CPP_SOURCES
"${COMMON_CPP_DIR}/audioapi/libs/ffmpeg/FFmpegDecoding.cpp"
)
endif()

set_source_files_properties(
${COMMON_CPP_SOURCES}/dsp/*.cpp
PROPERTIES
Expand All @@ -21,10 +27,12 @@ foreach(lib IN ITEMS opus opusfile ogg vorbis vorbisenc vorbisfile crypto ssl)
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION ${EXTERNAL_DIR}/${ANDROID_ABI}/lib${lib}.a)
endforeach()

foreach (lib IN ITEMS avcodec avformat avutil swresample)
add_library(${lib} SHARED IMPORTED)
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION ${JNI_LIBS_DIR}/${ANDROID_ABI}/lib${lib}.so)
endforeach()
if (NOT RN_AUDIO_API_FFMPEG_DISABLED)
foreach (lib IN ITEMS avcodec avformat avutil swresample)
add_library(${lib} SHARED IMPORTED)
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION ${JNI_LIBS_DIR}/${ANDROID_ABI}/lib${lib}.so)
endforeach()
endif()

find_package(ReactAndroid REQUIRED CONFIG)
find_package(fbjni REQUIRED CONFIG)
Expand Down Expand Up @@ -120,6 +128,13 @@ else()
)
endif()

if (RN_AUDIO_API_FFMPEG_DISABLED)
target_compile_definitions(
react-native-audio-api
PRIVATE RN_AUDIO_API_FFMPEG_DISABLED=1
)
endif()

target_link_libraries(react-native-audio-api
${LINK_LIBRARIES}
${RN_VERSION_LINK_LIBRARIES}
Expand All @@ -129,11 +144,16 @@ target_link_libraries(react-native-audio-api
vorbis
vorbisenc
vorbisfile
avcodec
avformat
avutil
swresample
crypto
ssl
z
)

if(NOT RN_AUDIO_API_FFMPEG_DISABLED)
target_link_libraries(react-native-audio-api
avcodec
avformat
avutil
swresample
)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
#include <type_traits>
#include <utility>

#ifdef __cpp_lib_hardware_interference_size
using std::hardware_constructive_interference_size;
using std::hardware_destructive_interference_size;
#else
constexpr std::size_t hardware_constructive_interference_size = 64;
constexpr std::size_t hardware_destructive_interference_size = 64;
#endif

namespace audioapi::channels::spsc {

/// @brief Overflow strategy for sender when the channel is full
Expand Down Expand Up @@ -414,17 +422,17 @@ class InnerChannel {
T *buffer_;

/// Producer-side data (accessed by sender thread)
alignas(std::hardware_destructive_interference_size) std::atomic<size_t> sendCursor_{0};
alignas(std::hardware_destructive_interference_size) size_t rcvCursorCache_{
alignas(hardware_constructive_interference_size) std::atomic<size_t> sendCursor_{0};
alignas(hardware_constructive_interference_size) size_t rcvCursorCache_{
0}; // reduces cache coherency

/// Consumer-side data (accessed by receiver thread)
alignas(std::hardware_destructive_interference_size) std::atomic<size_t> rcvCursor_{0};
alignas(std::hardware_destructive_interference_size) size_t sendCursorCache_{
alignas(hardware_constructive_interference_size) std::atomic<size_t> rcvCursor_{0};
alignas(hardware_constructive_interference_size) size_t sendCursorCache_{
0}; // reduces cache coherency

/// Flag indicating if the oldest element is occupied
alignas(std::hardware_destructive_interference_size) std::atomic<bool> oldestOccupied_{false};
alignas(hardware_constructive_interference_size) std::atomic<bool> oldestOccupied_{false};

friend class Sender<T, Strategy, Wait>;
friend class Receiver<T, Strategy, Wait>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ else
PROJECT_ROOT="$(pwd)"
fi

if [ "$2" == "skipffmpeg" ]; then
SKIP_FFMPEG=true
else
SKIP_FFMPEG=false
fi

JNILIBS_DESTINATION="${PROJECT_ROOT}/android/src/main"
NORMAL_DESTINATION="${PROJECT_ROOT}/common/cpp/audioapi/external"

Expand All @@ -28,6 +34,10 @@ for name in "${DOWNLOAD_NAMES[@]}"; do
# Get the directory name from the zip name (e.g., "armeabi-v7a.zip" -> "armeabi-v7a")
EXTRACTED_DIR_NAME="${name%.zip}"

if [[ ("$EXTRACTED_DIR_NAME" == "ffmpeg_ios" || "$EXTRACTED_DIR_NAME" == "jniLibs") && "$SKIP_FFMPEG" == true ]]; then
continue
fi

# Determine the final output path
if [[ "$name" == "jniLibs.zip" ]]; then
OUTPUT_DIR="${JNILIBS_DESTINATION}"
Expand Down