react-native-audio-api 0.11.0-alpha.1 → 0.11.0-nightly-9f40b78-20251108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +13 -11
  2. package/RNAudioAPI.podspec +20 -15
  3. package/android/build.gradle +33 -3
  4. package/android/src/main/cpp/audioapi/CMakeLists.txt +6 -3
  5. package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +5 -0
  6. package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +1 -0
  7. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +30 -142
  8. package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +13 -40
  9. package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +4 -2
  10. package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
  11. package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +6 -0
  12. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +31 -3
  13. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +21 -9
  14. package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +27 -6
  15. package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +11 -0
  16. package/android/src/oldarch/NativeAudioAPIModuleSpec.java +4 -0
  17. package/common/cpp/audioapi/AudioAPIModuleInstaller.h +30 -2
  18. package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +12 -17
  19. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +18 -0
  20. package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -0
  21. package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +26 -30
  22. package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
  23. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +47 -0
  24. package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +20 -0
  25. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +18 -97
  26. package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +6 -18
  27. package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +1 -1
  28. package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +1 -1
  29. package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +1 -1
  30. package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +15 -26
  31. package/common/cpp/audioapi/core/AudioNode.h +3 -2
  32. package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
  33. package/common/cpp/audioapi/core/BaseAudioContext.cpp +10 -0
  34. package/common/cpp/audioapi/core/BaseAudioContext.h +2 -0
  35. package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +69 -32
  36. package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +37 -1
  37. package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +210 -0
  38. package/common/cpp/audioapi/core/effects/ConvolverNode.h +55 -0
  39. package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +82 -36
  40. package/common/cpp/audioapi/core/inputs/AudioRecorder.h +31 -52
  41. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +14 -17
  42. package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
  43. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +7 -0
  44. package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +1 -0
  45. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +8 -14
  46. package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +0 -1
  47. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +14 -19
  48. package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +3 -3
  49. package/common/cpp/audioapi/core/sources/StreamerNode.cpp +64 -64
  50. package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -10
  51. package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +5 -0
  52. package/common/cpp/audioapi/core/utils/Constants.h +2 -1
  53. package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +12 -8
  54. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +3 -3
  55. package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +1 -1
  56. package/common/cpp/audioapi/dsp/AudioUtils.cpp +1 -1
  57. package/common/cpp/audioapi/dsp/Convolver.cpp +213 -0
  58. package/common/cpp/audioapi/dsp/Convolver.h +45 -0
  59. package/common/cpp/audioapi/dsp/FFT.cpp +0 -26
  60. package/common/cpp/audioapi/dsp/FFT.h +26 -2
  61. package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -1
  62. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +4 -4
  63. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
  64. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
  65. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +3 -1
  66. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +2 -2
  67. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/defs.h +3 -0
  68. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/packet.h +1 -1
  69. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/smpte_436m.h +254 -0
  70. package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/version.h +1 -1
  71. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +6 -6
  72. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version.h +2 -2
  73. package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version_major.h +2 -0
  74. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avassert.h +5 -2
  75. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
  76. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/channel_layout.h +2 -2
  77. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/csp.h +1 -1
  78. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/dict.h +1 -1
  79. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/ffversion.h +1 -1
  80. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/film_grain_params.h +1 -1
  81. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/frame.h +1 -1
  82. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hdr_dynamic_vivid_metadata.h +3 -3
  83. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext.h +1 -1
  84. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_opencl.h +1 -1
  85. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_qsv.h +0 -1
  86. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_vulkan.h +1 -1
  87. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/iamf.h +2 -2
  88. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/lfg.h +2 -2
  89. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/log.h +2 -2
  90. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/mathematics.h +1 -1
  91. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/opt.h +4 -4
  92. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rational.h +1 -1
  93. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rc4.h +1 -1
  94. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/refstruct.h +1 -1
  95. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/spherical.h +6 -0
  96. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tdrdi.h +1 -1
  97. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tx.h +1 -1
  98. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/version.h +3 -3
  99. package/common/cpp/audioapi/external/ffmpeg_include/libavutil/video_hint.h +1 -1
  100. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/swresample.h +1 -1
  101. package/common/cpp/audioapi/external/ffmpeg_include/libswresample/version.h +1 -1
  102. package/common/cpp/audioapi/jsi/JsiPromise.cpp +33 -56
  103. package/common/cpp/audioapi/jsi/JsiPromise.h +41 -11
  104. package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +2 -3
  105. package/common/cpp/audioapi/libs/ffmpeg/relinking.md +24 -0
  106. package/common/cpp/audioapi/utils/AlignedAllocator.hpp +50 -0
  107. package/common/cpp/audioapi/utils/AudioBus.cpp +28 -0
  108. package/common/cpp/audioapi/utils/AudioBus.h +3 -0
  109. package/common/cpp/audioapi/utils/ThreadPool.hpp +59 -1
  110. package/common/cpp/test/CMakeLists.txt +19 -14
  111. package/common/cpp/test/src/AudioParamTest.cpp +1 -1
  112. package/common/cpp/test/src/AudioScheduledSourceTest.cpp +134 -0
  113. package/common/cpp/test/src/ConstantSourceTest.cpp +1 -1
  114. package/common/cpp/test/src/GainTest.cpp +1 -1
  115. package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +4 -4
  116. package/common/cpp/test/src/OscillatorTest.cpp +1 -1
  117. package/common/cpp/test/src/StereoPannerTest.cpp +1 -1
  118. package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +389 -0
  119. package/common/cpp/test/src/biquad/BiquadFilterChromium.h +64 -0
  120. package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +284 -0
  121. package/common/cpp/test/src/biquad/BiquadFilterTest.h +40 -0
  122. package/ios/audioapi/ios/AudioAPIModule.h +2 -1
  123. package/ios/audioapi/ios/AudioAPIModule.mm +34 -9
  124. package/ios/audioapi/ios/core/IOSAudioRecorder.h +10 -28
  125. package/ios/audioapi/ios/core/IOSAudioRecorder.mm +30 -117
  126. package/ios/audioapi/ios/core/NativeAudioRecorder.h +9 -4
  127. package/ios/audioapi/ios/core/NativeAudioRecorder.m +71 -29
  128. package/ios/audioapi/ios/core/utils/AudioDecoder.mm +0 -1
  129. package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
  130. package/ios/audioapi/ios/system/AudioSessionManager.h +2 -0
  131. package/ios/audioapi/ios/system/AudioSessionManager.mm +24 -0
  132. package/ios/audioapi/ios/system/LockScreenManager.h +0 -1
  133. package/ios/audioapi/ios/system/LockScreenManager.mm +6 -19
  134. package/lib/commonjs/api.js +141 -76
  135. package/lib/commonjs/api.js.map +1 -1
  136. package/lib/commonjs/api.web.js +8 -0
  137. package/lib/commonjs/api.web.js.map +1 -1
  138. package/lib/commonjs/core/AudioContext.js +1 -1
  139. package/lib/commonjs/core/AudioContext.js.map +1 -1
  140. package/lib/commonjs/core/AudioRecorder.js +13 -171
  141. package/lib/commonjs/core/AudioRecorder.js.map +1 -1
  142. package/lib/commonjs/core/BaseAudioContext.js +28 -25
  143. package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
  144. package/lib/commonjs/core/ConvolverNode.js +37 -0
  145. package/lib/commonjs/core/ConvolverNode.js.map +1 -0
  146. package/lib/commonjs/core/OfflineAudioContext.js +1 -1
  147. package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
  148. package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
  149. package/lib/commonjs/system/AudioManager.js +3 -0
  150. package/lib/commonjs/system/AudioManager.js.map +1 -1
  151. package/lib/commonjs/types.js +0 -46
  152. package/lib/commonjs/types.js.map +1 -1
  153. package/lib/commonjs/utils/index.js +19 -21
  154. package/lib/commonjs/utils/index.js.map +1 -1
  155. package/lib/commonjs/web-core/AudioContext.js +12 -0
  156. package/lib/commonjs/web-core/AudioContext.js.map +1 -1
  157. package/lib/commonjs/web-core/ConvolverNode.js +40 -0
  158. package/lib/commonjs/web-core/ConvolverNode.js.map +1 -0
  159. package/lib/commonjs/web-core/ConvolverNodeOptions.js +6 -0
  160. package/lib/commonjs/web-core/ConvolverNodeOptions.js.map +1 -0
  161. package/lib/commonjs/web-core/OfflineAudioContext.js +12 -0
  162. package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
  163. package/lib/module/api.js +16 -15
  164. package/lib/module/api.js.map +1 -1
  165. package/lib/module/api.web.js +1 -0
  166. package/lib/module/api.web.js.map +1 -1
  167. package/lib/module/core/AudioContext.js +2 -2
  168. package/lib/module/core/AudioContext.js.map +1 -1
  169. package/lib/module/core/AudioRecorder.js +13 -171
  170. package/lib/module/core/AudioRecorder.js.map +1 -1
  171. package/lib/module/core/BaseAudioContext.js +29 -26
  172. package/lib/module/core/BaseAudioContext.js.map +1 -1
  173. package/lib/module/core/ConvolverNode.js +31 -0
  174. package/lib/module/core/ConvolverNode.js.map +1 -0
  175. package/lib/module/core/OfflineAudioContext.js +2 -2
  176. package/lib/module/core/OfflineAudioContext.js.map +1 -1
  177. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
  178. package/lib/module/system/AudioManager.js +3 -0
  179. package/lib/module/system/AudioManager.js.map +1 -1
  180. package/lib/module/types.js +1 -45
  181. package/lib/module/types.js.map +1 -1
  182. package/lib/module/utils/index.js +15 -2
  183. package/lib/module/utils/index.js.map +1 -1
  184. package/lib/module/web-core/AudioContext.js +12 -0
  185. package/lib/module/web-core/AudioContext.js.map +1 -1
  186. package/lib/module/web-core/ConvolverNode.js +34 -0
  187. package/lib/module/web-core/ConvolverNode.js.map +1 -0
  188. package/lib/module/web-core/ConvolverNodeOptions.js +4 -0
  189. package/lib/module/web-core/ConvolverNodeOptions.js.map +1 -0
  190. package/lib/module/web-core/OfflineAudioContext.js +12 -0
  191. package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
  192. package/lib/typescript/api.d.ts +19 -17
  193. package/lib/typescript/api.d.ts.map +1 -1
  194. package/lib/typescript/api.web.d.ts +1 -0
  195. package/lib/typescript/api.web.d.ts.map +1 -1
  196. package/lib/typescript/core/AudioContext.d.ts.map +1 -1
  197. package/lib/typescript/core/AudioRecorder.d.ts +7 -62
  198. package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
  199. package/lib/typescript/core/BaseAudioContext.d.ts +3 -1
  200. package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
  201. package/lib/typescript/core/ConvolverNode.d.ts +12 -0
  202. package/lib/typescript/core/ConvolverNode.d.ts.map +1 -0
  203. package/lib/typescript/events/types.d.ts +0 -16
  204. package/lib/typescript/events/types.d.ts.map +1 -1
  205. package/lib/typescript/interfaces.d.ts +9 -42
  206. package/lib/typescript/interfaces.d.ts.map +1 -1
  207. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -0
  208. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
  209. package/lib/typescript/system/AudioManager.d.ts +1 -0
  210. package/lib/typescript/system/AudioManager.d.ts.map +1 -1
  211. package/lib/typescript/types.d.ts +8 -79
  212. package/lib/typescript/types.d.ts.map +1 -1
  213. package/lib/typescript/utils/index.d.ts +5 -2
  214. package/lib/typescript/utils/index.d.ts.map +1 -1
  215. package/lib/typescript/web-core/AudioContext.d.ts +3 -0
  216. package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
  217. package/lib/typescript/web-core/BaseAudioContext.d.ts +2 -0
  218. package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
  219. package/lib/typescript/web-core/ConvolverNode.d.ts +11 -0
  220. package/lib/typescript/web-core/ConvolverNode.d.ts.map +1 -0
  221. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts +6 -0
  222. package/lib/typescript/web-core/ConvolverNodeOptions.d.ts.map +1 -0
  223. package/lib/typescript/web-core/OfflineAudioContext.d.ts +3 -0
  224. package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
  225. package/package.json +14 -5
  226. package/scripts/download-prebuilt-binaries.sh +61 -0
  227. package/scripts/rnaa_utils.rb +8 -0
  228. package/scripts/validate-worklets-version.js +28 -0
  229. package/src/api.ts +45 -18
  230. package/src/api.web.ts +1 -0
  231. package/src/core/AudioContext.ts +3 -2
  232. package/src/core/AudioRecorder.ts +24 -211
  233. package/src/core/BaseAudioContext.ts +67 -60
  234. package/src/core/ConvolverNode.ts +35 -0
  235. package/src/core/OfflineAudioContext.ts +2 -2
  236. package/src/events/types.ts +0 -18
  237. package/src/interfaces.ts +16 -52
  238. package/src/specs/NativeAudioAPIModule.ts +1 -0
  239. package/src/system/AudioManager.ts +4 -0
  240. package/src/types.ts +9 -90
  241. package/src/utils/index.ts +22 -2
  242. package/src/web-core/AudioContext.tsx +25 -0
  243. package/src/web-core/BaseAudioContext.tsx +2 -0
  244. package/src/web-core/ConvolverNode.tsx +43 -0
  245. package/src/web-core/ConvolverNodeOptions.tsx +6 -0
  246. package/src/web-core/OfflineAudioContext.tsx +25 -0
  247. package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +0 -37
  248. package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +0 -187
  249. package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +0 -57
  250. package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +0 -34
  251. package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +0 -133
  252. package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +0 -3
  253. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +0 -154
  254. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +0 -41
  255. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +0 -429
  256. package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +0 -113
  257. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +0 -47
  258. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +0 -28
  259. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +0 -269
  260. package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +0 -47
  261. package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +0 -31
  262. package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +0 -18
  263. package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
  264. package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
  265. package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
  266. package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
  267. package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
  268. package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
  269. package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
  270. package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
  271. package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
  272. package/android/src/main/jniLibs/x86/libavformat.so +0 -0
  273. package/android/src/main/jniLibs/x86/libavutil.so +0 -0
  274. package/android/src/main/jniLibs/x86/libswresample.so +0 -0
  275. package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
  276. package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
  277. package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
  278. package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
  279. package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
  280. package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
  281. package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
  282. package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
  283. package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
  284. package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
  285. package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
  286. package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
  287. package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
  288. package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
  289. package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
  290. package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
  291. package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
  292. package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
  293. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
  294. package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
  295. package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
  296. package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
  297. package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
  298. package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
  299. package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
  300. package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
  301. package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
  302. package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
  303. package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
  304. package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
  305. package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
  306. package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
  307. package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
  308. package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
  309. package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
  310. package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
  311. package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +0 -44
  312. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +0 -1
  313. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
  314. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +0 -1
  315. package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
  316. package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +0 -44
  317. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +0 -1
  318. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
  319. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +0 -1
  320. package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
  321. package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +0 -44
  322. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +0 -1
  323. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
  324. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +0 -1
  325. package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
  326. package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +0 -44
  327. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +0 -1
  328. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
  329. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +0 -1
  330. package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
  331. package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
  332. package/common/cpp/audioapi/external/x86/libogg.a +0 -0
  333. package/common/cpp/audioapi/external/x86/libopus.a +0 -0
  334. package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
  335. package/common/cpp/audioapi/external/x86/libssl.a +0 -0
  336. package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
  337. package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
  338. package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
  339. package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
  340. package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
  341. package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
  342. package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
  343. package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
  344. package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
  345. package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
  346. package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
  347. package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +0 -32
  348. package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +0 -111
  349. package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +0 -391
  350. package/ios/audioapi/ios/core/IOSAudioFileOptions.h +0 -36
  351. package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +0 -140
  352. package/ios/audioapi/ios/core/IOSAudioFileWriter.h +0 -51
  353. package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +0 -223
  354. package/ios/audioapi/ios/core/IOSRecorderCallback.h +0 -57
  355. package/ios/audioapi/ios/core/IOSRecorderCallback.mm +0 -189
  356. package/lib/commonjs/utils/bitEnums.js +0 -33
  357. package/lib/commonjs/utils/bitEnums.js.map +0 -1
  358. package/lib/module/utils/bitEnums.js +0 -27
  359. package/lib/module/utils/bitEnums.js.map +0 -1
  360. package/lib/typescript/utils/bitEnums.d.ts +0 -4
  361. package/lib/typescript/utils/bitEnums.d.ts.map +0 -1
  362. package/src/utils/bitEnums.ts +0 -51
@@ -1,429 +0,0 @@
1
- #include <android/log.h>
2
- #include <cmath>
3
-
4
- extern "C" {
5
- #include <libavformat/avio.h>
6
- }
7
-
8
- #include <audioapi/android/core/utils/AndroidFileWriterBackend.h>
9
- #include <audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h>
10
- #include <audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h>
11
-
12
- constexpr double BYTES_TO_MB = 1024.0 * 1024.0;
13
-
14
- namespace audioapi {
15
-
16
- FFmpegAudioFileWriter::FFmpegAudioFileWriter(
17
- float sampleRate,
18
- size_t channelCount,
19
- size_t bitRate,
20
- size_t androidFlags)
21
- : AndroidFileWriterBackend(
22
- sampleRate,
23
- channelCount,
24
- bitRate,
25
- androidFlags) {
26
- fileOptions_ = std::make_shared<FFmpegAudioFileOptions>(
27
- sampleRate, channelCount, bitRate, androidFlags);
28
- }
29
-
30
- FFmpegAudioFileWriter::~FFmpegAudioFileWriter() {
31
- isFileOpen_.store(false);
32
- fileOptions_.reset();
33
- }
34
-
35
- std::string FFmpegAudioFileWriter::openFile(
36
- int32_t streamSampleRate,
37
- int32_t streamChannelCount,
38
- int32_t streamMaxBufferSize) {
39
- filePath_ = fileOptions_->getFilePath("audio");
40
-
41
- streamSampleRate_ = streamSampleRate;
42
- streamChannelCount_ = streamChannelCount;
43
- streamMaxBufferSize_ = streamMaxBufferSize;
44
- framesWritten_.store(0);
45
- nextPts_ = 0;
46
-
47
- const AVCodec *codec = fileOptions_->getCodec();
48
- AVFormatContext *rawFormatCtx = nullptr;
49
-
50
- if (avformat_alloc_output_context2(
51
- &rawFormatCtx,
52
- nullptr,
53
- fileOptions_->getMuxerName().c_str(),
54
- filePath_.c_str()) < 0 ||
55
- !rawFormatCtx) {
56
- __android_log_print(
57
- ANDROID_LOG_ERROR,
58
- "FFmpegFileWriter",
59
- "Failed to allocate FFmpeg format context for file: %s",
60
- filePath_.c_str());
61
- return "";
62
- }
63
-
64
- formatCtx_ = AVFormatContextPtr(rawFormatCtx);
65
- stream_ = avformat_new_stream(formatCtx_.get(), codec);
66
-
67
- encoderCtx_ = AVCodecContextPtr(avcodec_alloc_context3(codec));
68
-
69
- if (!encoderCtx_) {
70
- __android_log_print(
71
- ANDROID_LOG_ERROR,
72
- "FFmpegFileWriter",
73
- "Failed to allocate FFmpeg codec context for file");
74
- return "";
75
- }
76
-
77
- AVDictionary *codecOptions = nullptr;
78
- size_t bitRate = fileOptions_->getBitRate();
79
- int flacCompressionLevel = fileOptions_->getFlacCompressionLevel();
80
- av_channel_layout_default(
81
- &encoderCtx_->ch_layout, fileOptions_->getChannelCount());
82
-
83
- encoderCtx_->sample_rate = fileOptions_->getSampleRate();
84
- encoderCtx_->sample_fmt = fileOptions_->getSampleFormat();
85
-
86
- if (bitRate > 0) {
87
- encoderCtx_->bit_rate = bitRate;
88
- }
89
-
90
- if (flacCompressionLevel >= 0) {
91
- av_dict_set_int(
92
- &codecOptions, "compression_level", flacCompressionLevel, 0);
93
- }
94
-
95
- if (avcodec_open2(encoderCtx_.get(), codec, &codecOptions) < 0) {
96
- __android_log_print(
97
- ANDROID_LOG_ERROR,
98
- "FFmpegFileWriter",
99
- "Failed to open FFmpeg codec for file");
100
- av_dict_free(&codecOptions);
101
- return "";
102
- }
103
-
104
- av_dict_free(&codecOptions);
105
-
106
- if (avcodec_parameters_from_context(stream_->codecpar, encoderCtx_.get()) <
107
- 0) {
108
- __android_log_print(
109
- ANDROID_LOG_ERROR,
110
- "FFmpegFileWriter",
111
- "Failed to copy codec parameters to stream for file");
112
- return "";
113
- }
114
-
115
- if (!(formatCtx_->oformat->flags & AVFMT_NOFILE)) {
116
- if (avio_open(&formatCtx_->pb, filePath_.c_str(), AVIO_FLAG_WRITE) < 0) {
117
- __android_log_print(
118
- ANDROID_LOG_ERROR,
119
- "FFmpegFileWriter",
120
- "Failed to open output file: %s",
121
- filePath_.c_str());
122
- return "";
123
- }
124
- }
125
-
126
- stream_->time_base =
127
- AVRational{1, static_cast<int>(encoderCtx_->sample_rate)};
128
-
129
- if (avformat_write_header(formatCtx_.get(), nullptr) < 0) {
130
- __android_log_print(
131
- ANDROID_LOG_ERROR,
132
- "FFmpegFileWriter",
133
- "Failed to write header to file: %s",
134
- filePath_.c_str());
135
- return "";
136
- }
137
-
138
- frame_ = AVFramePtr(av_frame_alloc());
139
- packet_ = AVPacketPtr(av_packet_alloc());
140
-
141
- resampleCtx_ = SwrContextPtr(swr_alloc());
142
-
143
- AVChannelLayout inChannelLayout;
144
- av_channel_layout_default(&inChannelLayout, streamChannelCount_);
145
-
146
- av_opt_set_chlayout(resampleCtx_.get(), "in_chlayout", &inChannelLayout, 0);
147
-
148
- av_opt_set_chlayout(
149
- resampleCtx_.get(), "out_chlayout", &encoderCtx_->ch_layout, 0);
150
-
151
- av_opt_set_int(resampleCtx_.get(), "in_sample_rate", streamSampleRate, 0);
152
-
153
- av_opt_set_int(
154
- resampleCtx_.get(), "out_sample_rate", encoderCtx_->sample_rate, 0);
155
-
156
- av_opt_set_sample_fmt(
157
- resampleCtx_.get(), "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
158
-
159
- av_opt_set_sample_fmt(
160
- resampleCtx_.get(), "out_sample_fmt", encoderCtx_->sample_fmt, 0);
161
-
162
- if (swr_init(resampleCtx_.get()) < 0) {
163
- __android_log_print(
164
- ANDROID_LOG_ERROR,
165
- "FFmpegFileWriter",
166
- "Failed to initialize resampler for file: %s",
167
- filePath_.c_str());
168
- return "";
169
- }
170
-
171
- int contextFrameRatio = 2;
172
-
173
- if (encoderCtx_->frame_size > 0) {
174
- contextFrameRatio = static_cast<int>(std::ceil(
175
- static_cast<double>(streamMaxBufferSize_) /
176
- static_cast<double>(encoderCtx_->frame_size)));
177
- }
178
-
179
- int fifoSize = std::max(
180
- encoderCtx_->frame_size > 0
181
- ? encoderCtx_->frame_size * contextFrameRatio * 2
182
- : streamMaxBufferSize_ * 2,
183
- 4096);
184
-
185
- audioFifo_ = AVAudioFifoPtr(av_audio_fifo_alloc(
186
- encoderCtx_->sample_fmt, encoderCtx_->ch_layout.nb_channels, fifoSize));
187
-
188
- __android_log_print(
189
- ANDROID_LOG_INFO,
190
- "FFmpegFileWriter",
191
- "Using audio FIFO size of %d frames",
192
- fifoSize);
193
-
194
- isFileOpen_.store(true);
195
-
196
- return filePath_;
197
- }
198
-
199
- std::tuple<double, double> FFmpegAudioFileWriter::closeFile() {
200
- if (!isFileOpen()) {
201
- return {0.0, 0.0};
202
- }
203
-
204
- isFileOpen_.store(false);
205
-
206
- const int frameSize =
207
- encoderCtx_->frame_size > 0 ? encoderCtx_->frame_size : 512;
208
-
209
- while (av_audio_fifo_size(audioFifo_.get()) > 0) {
210
- const int chunkSize =
211
- std::min(av_audio_fifo_size(audioFifo_.get()), frameSize);
212
-
213
- frame_->nb_samples = chunkSize;
214
- av_channel_layout_copy(&frame_->ch_layout, &encoderCtx_->ch_layout);
215
- frame_->format = encoderCtx_->sample_fmt;
216
- frame_->sample_rate = encoderCtx_->sample_rate;
217
-
218
- if (av_frame_get_buffer(frame_.get(), 0) < 0) {
219
- __android_log_print(
220
- ANDROID_LOG_ERROR,
221
- "FFmpegFileWriter",
222
- "Failed to allocate audio frame buffer during flushing");
223
- break;
224
- }
225
-
226
- int fifoReadFrameCount =
227
- av_audio_fifo_read(audioFifo_.get(), (void **)frame_->data, chunkSize);
228
-
229
- if (fifoReadFrameCount != chunkSize) {
230
- __android_log_print(
231
- ANDROID_LOG_ERROR,
232
- "FFmpegFileWriter",
233
- "Failed to read audio samples from FIFO during flushing");
234
- break;
235
- }
236
-
237
- frame_->pts = nextPts_;
238
- nextPts_ += chunkSize;
239
-
240
- if (avcodec_send_frame(encoderCtx_.get(), frame_.get()) < 0) {
241
- __android_log_print(
242
- ANDROID_LOG_ERROR,
243
- "FFmpegFileWriter",
244
- "Failed to send audio frame to encoder during flushing");
245
- av_frame_unref(frame_.get());
246
- break;
247
- }
248
-
249
- av_frame_unref(frame_.get());
250
- }
251
-
252
- avcodec_send_frame(encoderCtx_.get(), nullptr);
253
-
254
- while (avcodec_receive_packet(encoderCtx_.get(), packet_.get()) == 0) {
255
- av_packet_rescale_ts(
256
- packet_.get(),
257
- AVRational{1, encoderCtx_->sample_rate},
258
- stream_->time_base);
259
- packet_->stream_index = stream_->index;
260
- av_interleaved_write_frame(formatCtx_.get(), packet_.get());
261
- av_packet_unref(packet_.get());
262
- }
263
-
264
- if (av_write_trailer(formatCtx_.get()) < 0) {
265
- __android_log_print(
266
- ANDROID_LOG_ERROR,
267
- "FFmpegFileWriter",
268
- "Failed to write trailer to file: %s",
269
- filePath_.c_str());
270
- }
271
-
272
- double fileSizeInMB = avio_size(formatCtx_->pb) / BYTES_TO_MB;
273
- double durationInSeconds = getCurrentDuration();
274
-
275
- if (formatCtx_ && formatCtx_->pb) {
276
- avio_closep(&formatCtx_->pb);
277
- }
278
-
279
- resampleCtx_.reset();
280
- frame_.reset();
281
- packet_.reset();
282
- encoderCtx_.reset();
283
- formatCtx_.reset();
284
- audioFifo_.reset();
285
-
286
- filePath_ = "";
287
- return {fileSizeInMB, durationInSeconds};
288
- }
289
-
290
- bool FFmpegAudioFileWriter::writeAudioData(void *data, int numFrames) {
291
- if (!isFileOpen()) {
292
- return false;
293
- }
294
-
295
- int outputLength = av_rescale_rnd(
296
- numFrames, encoderCtx_->sample_rate, streamSampleRate_, AV_ROUND_UP);
297
-
298
- frame_->nb_samples = outputLength;
299
- av_channel_layout_copy(&frame_->ch_layout, &encoderCtx_->ch_layout);
300
- frame_->format = encoderCtx_->sample_fmt;
301
- frame_->sample_rate = encoderCtx_->sample_rate;
302
-
303
- if (av_frame_get_buffer(frame_.get(), 0) < 0) {
304
- __android_log_print(
305
- ANDROID_LOG_ERROR,
306
- "FFmpegFileWriter",
307
- "Failed to allocate audio frame buffer, outputLength: %d, format: %d, sample_rate: %d, channels: %d",
308
- outputLength,
309
- encoderCtx_->sample_fmt,
310
- encoderCtx_->sample_rate,
311
- encoderCtx_->ch_layout.nb_channels);
312
-
313
- return false;
314
- }
315
-
316
- const uint8_t *inputData[1] = {reinterpret_cast<const uint8_t *>(data)};
317
-
318
- int convertedSamples = swr_convert(
319
- resampleCtx_.get(), frame_->data, outputLength, inputData, numFrames);
320
-
321
- if (convertedSamples < 0) {
322
- __android_log_print(
323
- ANDROID_LOG_ERROR,
324
- "FFmpegFileWriter",
325
- "Failed to convert audio samples for file: %s",
326
- filePath_.c_str());
327
- av_frame_unref(frame_.get());
328
- return false;
329
- }
330
-
331
- int fifoWrittenFrameCount = av_audio_fifo_write(
332
- audioFifo_.get(), (void **)frame_->data, convertedSamples);
333
-
334
- if (fifoWrittenFrameCount < convertedSamples) {
335
- __android_log_print(
336
- ANDROID_LOG_ERROR,
337
- "FFmpegFileWriter",
338
- "Failed to write audio samples to FIFO");
339
- av_frame_unref(frame_.get());
340
- return false;
341
- }
342
-
343
- av_frame_unref(frame_.get());
344
- const int frameSize =
345
- encoderCtx_->frame_size > 0 ? encoderCtx_->frame_size : 512;
346
-
347
- while (av_audio_fifo_size(audioFifo_.get()) >= frameSize) {
348
- frame_->nb_samples = frameSize;
349
- av_channel_layout_copy(&frame_->ch_layout, &encoderCtx_->ch_layout);
350
- frame_->format = encoderCtx_->sample_fmt;
351
- frame_->sample_rate = encoderCtx_->sample_rate;
352
-
353
- if (av_frame_get_buffer(frame_.get(), 0) < 0) {
354
- __android_log_print(
355
- ANDROID_LOG_ERROR,
356
- "FFmpegFileWriter",
357
- "Failed to allocate audio frame buffer");
358
- return false;
359
- }
360
-
361
- int fifoReadFrameCount =
362
- av_audio_fifo_read(audioFifo_.get(), (void **)frame_->data, frameSize);
363
-
364
- if (fifoReadFrameCount != frameSize) {
365
- __android_log_print(
366
- ANDROID_LOG_ERROR,
367
- "FFmpegFileWriter",
368
- "Failed to read audio samples from FIFO");
369
- return false;
370
- }
371
-
372
- frame_->pts = nextPts_;
373
- nextPts_ += frameSize;
374
-
375
- if (avcodec_send_frame(encoderCtx_.get(), frame_.get()) < 0) {
376
- __android_log_print(
377
- ANDROID_LOG_ERROR,
378
- "FFmpegFileWriter",
379
- "Failed to send audio frame to encoder");
380
- av_frame_unref(frame_.get());
381
- return false;
382
- }
383
-
384
- while (avcodec_receive_packet(encoderCtx_.get(), packet_.get()) == 0) {
385
- av_packet_rescale_ts(
386
- packet_.get(),
387
- AVRational{1, encoderCtx_->sample_rate},
388
- stream_->time_base);
389
-
390
- packet_->stream_index = stream_->index;
391
-
392
- if (av_interleaved_write_frame(formatCtx_.get(), packet_.get()) < 0) {
393
- __android_log_print(
394
- ANDROID_LOG_ERROR,
395
- "FFmpegFileWriter",
396
- "Failed to write audio packet to file");
397
-
398
- av_packet_unref(packet_.get());
399
- av_frame_unref(frame_.get());
400
- return false;
401
- }
402
-
403
- av_packet_unref(packet_.get());
404
- }
405
-
406
- av_frame_unref(frame_.get());
407
- }
408
-
409
- framesWritten_.fetch_add(numFrames);
410
- return true;
411
- }
412
-
413
- bool FFmpegAudioFileWriter::initializeConverterIfNeeded() {
414
- return false;
415
- }
416
-
417
- bool FFmpegAudioFileWriter::initializeEncoder() {
418
- return false;
419
- }
420
-
421
- bool FFmpegAudioFileWriter::isFileOpen() {
422
- return isFileOpen_.load();
423
- }
424
-
425
- bool FFmpegAudioFileWriter::isConverterRequired() {
426
- return isConverterRequired_.load();
427
- }
428
-
429
- } // namespace audioapi
@@ -1,113 +0,0 @@
1
- #pragma once
2
-
3
- extern "C" {
4
- #include <libavutil/opt.h>
5
- #include <libavcodec/avcodec.h>
6
- #include <libavutil/audio_fifo.h>
7
- #include <libavformat/avformat.h>
8
- #include <libswresample/swresample.h>
9
- #include <libavutil/channel_layout.h>
10
- }
11
-
12
- #include <audioapi/android/core/utils/AndroidFileWriterBackend.h>
13
-
14
- #include <string>
15
- #include <memory>
16
- #include <tuple>
17
-
18
- namespace audioapi {
19
-
20
- class FFmpegAudioFileOptions;
21
-
22
- struct AVCodecContextDTOR {
23
- void operator()(AVCodecContext* ctx) const {
24
- if (ctx) {
25
- avcodec_free_context(&ctx);
26
- }
27
- }
28
- };
29
-
30
- struct AVFormatContextDTOR {
31
- void operator()(AVFormatContext* ctx) const {
32
- if (ctx) {
33
- avformat_free_context(ctx);
34
- }
35
- }
36
- };
37
-
38
- struct AVFrameDTOR {
39
- void operator()(AVFrame* frame) const {
40
- if (frame) {
41
- av_frame_free(&frame);
42
- }
43
- }
44
- };
45
-
46
- struct AVPacketDTOR {
47
- void operator()(AVPacket* packet) const {
48
- if (packet) {
49
- av_packet_free(&packet);
50
- }
51
- }
52
- };
53
-
54
- struct SwrContextDTOR {
55
- void operator()(SwrContext* ctx) const {
56
- if (ctx) {
57
- swr_free(&ctx);
58
- }
59
- }
60
- };
61
-
62
- struct AVAudioFifoDTOR {
63
- void operator()(AVAudioFifo* fifo) const {
64
- if (fifo) {
65
- av_audio_fifo_free(fifo);
66
- }
67
- }
68
- };
69
-
70
- using AVCodecContextPtr = std::unique_ptr<AVCodecContext, AVCodecContextDTOR>;
71
- using AVFormatContextPtr = std::unique_ptr<AVFormatContext, AVFormatContextDTOR>;
72
- using AVFramePtr = std::unique_ptr<AVFrame, AVFrameDTOR>;
73
- using AVPacketPtr = std::unique_ptr<AVPacket, AVPacketDTOR>;
74
- using SwrContextPtr = std::unique_ptr<SwrContext, SwrContextDTOR>;
75
- using AVAudioFifoPtr = std::unique_ptr<AVAudioFifo, AVAudioFifoDTOR>;
76
-
77
- class FFmpegAudioFileWriter : public AndroidFileWriterBackend {
78
- public:
79
- FFmpegAudioFileWriter(
80
- float sampleRate,
81
- size_t channelCount,
82
- size_t bitRate,
83
- size_t androidFlags);
84
- ~FFmpegAudioFileWriter() override;
85
-
86
- std::string openFile(int32_t streamSampleRate, int32_t streamChannelCount, int32_t streamMaxBufferSize) override;
87
- std::tuple<double, double> closeFile() override;
88
-
89
- bool writeAudioData(void *data, int numFrames) override;
90
-
91
- private:
92
- std::shared_ptr<FFmpegAudioFileOptions> fileOptions_;
93
-
94
- std::atomic<bool> isFileOpen_{false};
95
- std::atomic<bool> isConverterRequired_{false};
96
-
97
- AVCodecContextPtr encoderCtx_{nullptr};
98
- AVFormatContextPtr formatCtx_{nullptr};
99
- SwrContextPtr resampleCtx_{nullptr};
100
- AVPacketPtr packet_{nullptr};
101
- AVFramePtr frame_{nullptr};
102
- AVStream* stream_{nullptr};
103
- AVAudioFifoPtr audioFifo_{nullptr};
104
- int64_t nextPts_;
105
-
106
- bool initializeConverterIfNeeded();
107
- bool initializeEncoder();
108
-
109
- bool isFileOpen();
110
- bool isConverterRequired();
111
- };
112
-
113
- } // namespace audioapi
@@ -1,47 +0,0 @@
1
-
2
- #include <audioapi/android/core/utils/FileUtils.h>
3
- #include <audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h>
4
-
5
- namespace audioapi {
6
-
7
- MiniAudioFileOptions::MiniAudioFileOptions(
8
- float sampleRate,
9
- size_t channelCount,
10
- size_t bitRate,
11
- size_t flags)
12
- : sampleRate_(sampleRate), channelCount_(channelCount), flags_(flags) {};
13
-
14
- ma_encoding_format MiniAudioFileOptions::getFormat() const {
15
- return ma_encoding_format_wav;
16
- }
17
-
18
- std::string MiniAudioFileOptions::getFilePath(
19
- const std::string &baseFileName) const {
20
- return android::fileutils::getFilePath(
21
- android::fileutils::directoryFromFlags(flags_), baseFileName, "wav");
22
- }
23
-
24
- float MiniAudioFileOptions::getSampleRate() const {
25
- return sampleRate_;
26
- }
27
-
28
- size_t MiniAudioFileOptions::getChannelCount() const {
29
- return channelCount_;
30
- }
31
-
32
- ma_format MiniAudioFileOptions::getDataFormat() const {
33
- android::fileutils::BitDepth bitDepth =
34
- android::fileutils::bitDepthFromFlags(flags_);
35
- switch (bitDepth) {
36
- case android::fileutils::BitDepth::BIT_16:
37
- return ma_format_s16;
38
- case android::fileutils::BitDepth::BIT_24:
39
- return ma_format_s24;
40
- case android::fileutils::BitDepth::BIT_32:
41
- return ma_format_f32;
42
- default:
43
- return ma_format_f32;
44
- }
45
- }
46
-
47
- } // namespace audioapi
@@ -1,28 +0,0 @@
1
- #pragma once
2
-
3
- #include <audioapi/libs/miniaudio/miniaudio.h>
4
- #include <cstddef>
5
- #include <cstdint>
6
- #include <string>
7
-
8
- namespace audioapi {
9
-
10
- class MiniAudioFileOptions {
11
- public:
12
- MiniAudioFileOptions(float sampleRate, size_t channelCount, size_t bitRate, size_t flags);
13
- ~MiniAudioFileOptions() = default;
14
-
15
- ma_encoding_format getFormat() const;
16
- std::string getFilePath(const std::string &baseFileName) const;
17
-
18
- float getSampleRate() const;
19
- size_t getChannelCount() const;
20
- ma_format getDataFormat() const;
21
-
22
- private:
23
- float sampleRate_;
24
- size_t channelCount_;
25
- size_t flags_;
26
- };
27
-
28
- } // namespace audioapi