react-native-audio-api 0.11.0-nightly-95f9c99-20251215 → 0.11.0-nightly-dd83923-20251216
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.
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +382 -39
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +45 -18
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +33 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +170 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +46 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +0 -1
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.cpp +83 -0
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.h +22 -0
- package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +8 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +493 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +70 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/ptrs.hpp +56 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.cpp +114 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.h +34 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +296 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +40 -0
- package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +32 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +2 -0
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +7 -3
- package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +1 -0
- package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +18 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +1 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +2 -0
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +100 -80
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +3 -11
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +145 -16
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +21 -6
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +43 -60
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +53 -33
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +42 -14
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +12 -9
- package/common/cpp/audioapi/core/utils/AudioFileWriter.cpp +41 -0
- package/common/cpp/audioapi/core/utils/AudioFileWriter.h +44 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp +101 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.h +52 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.cpp +92 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.h +76 -0
- package/common/cpp/audioapi/utils/Result.hpp +323 -0
- package/common/cpp/audioapi/utils/UnitConversion.h +9 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +9 -14
- package/ios/audioapi/ios/core/IOSAudioPlayer.h +1 -1
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +7 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +39 -13
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +302 -26
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +7 -11
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +8 -9
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +70 -76
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +1 -0
- package/ios/audioapi/ios/core/utils/FileOptions.h +33 -0
- package/ios/audioapi/ios/core/utils/FileOptions.mm +195 -0
- package/ios/audioapi/ios/core/utils/IOSFileWriter.h +53 -0
- package/ios/audioapi/ios/core/utils/IOSFileWriter.mm +239 -0
- package/ios/audioapi/ios/core/utils/IOSRecorderCallback.h +47 -0
- package/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm +185 -0
- package/ios/audioapi/ios/system/AudioEngine.h +21 -16
- package/ios/audioapi/ios/system/AudioEngine.mm +138 -130
- package/ios/audioapi/ios/system/AudioSessionManager.h +19 -9
- package/ios/audioapi/ios/system/AudioSessionManager.mm +250 -215
- package/ios/audioapi/ios/system/NotificationManager.mm +24 -42
- package/lib/commonjs/api.js +82 -109
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +159 -13
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js +17 -14
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/commonjs/system/notification/RecordingNotificationManager.js +22 -19
- package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/commonjs/system/notification/SimpleNotificationManager.js +16 -13
- package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +1 -1
- package/lib/commonjs/types.js +39 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/filePresets.js +43 -0
- package/lib/commonjs/utils/filePresets.js.map +1 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +6 -3
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +6 -3
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/module/api.js +5 -4
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +159 -13
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/notification/PlaybackNotificationManager.js +17 -14
- package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/module/system/notification/RecordingNotificationManager.js +22 -19
- package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/module/system/notification/SimpleNotificationManager.js +16 -13
- package/lib/module/system/notification/SimpleNotificationManager.js.map +1 -1
- package/lib/module/types.js +38 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/filePresets.js +39 -0
- package/lib/module/utils/filePresets.js.map +1 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js +6 -3
- package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/module/web-system/notification/RecordingNotificationManager.js +6 -3
- package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/typescript/api.d.ts +5 -4
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +69 -7
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +36 -2
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +24 -4
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +4 -3
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +4 -3
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +3 -2
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +79 -3
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/filePresets.d.ts +9 -0
- package/lib/typescript/utils/filePresets.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +4 -3
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -1
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +4 -3
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/AudioAPIModule/globals.d.ts +1 -2
- package/src/api.ts +8 -29
- package/src/core/AudioRecorder.ts +195 -23
- package/src/events/types.ts +40 -2
- package/src/interfaces.ts +34 -5
- package/src/specs/NativeAudioAPIModule.ts +2 -2
- package/src/system/notification/PlaybackNotificationManager.ts +20 -16
- package/src/system/notification/RecordingNotificationManager.ts +26 -21
- package/src/system/notification/SimpleNotificationManager.ts +18 -13
- package/src/system/notification/types.ts +1 -0
- package/src/types.ts +89 -3
- package/src/utils/filePresets.ts +47 -0
- package/src/web-system/notification/PlaybackNotificationManager.ts +9 -5
- package/src/web-system/notification/RecordingNotificationManager.ts +9 -5
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <new>
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <type_traits>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
struct NoneType {};
|
|
11
|
+
inline constexpr NoneType None{};
|
|
12
|
+
|
|
13
|
+
/// @brief A Result type that can represent either a success (Ok) or an error (Err).
|
|
14
|
+
/// @tparam T value type for success
|
|
15
|
+
/// @tparam E error type for failure
|
|
16
|
+
/// @note Specializations for void T and/or void E are not provided. Use NoneType instead.
|
|
17
|
+
/// Design inspired by Rust's Result type.
|
|
18
|
+
/// https://doc.rust-lang.org/std/result/
|
|
19
|
+
///
|
|
20
|
+
/// @example
|
|
21
|
+
/// /// Creating an Ok Result and mapping its error:
|
|
22
|
+
/// Result<int, std::string> res = Result<int, int>::Err(404)
|
|
23
|
+
/// .map_err<std::string>([](auto code){
|
|
24
|
+
/// return "Error code: " + std::to_string(code);
|
|
25
|
+
/// });
|
|
26
|
+
///
|
|
27
|
+
template <typename T = NoneType, typename E = NoneType>
|
|
28
|
+
class Result {
|
|
29
|
+
struct OkTag {};
|
|
30
|
+
struct ErrTag {};
|
|
31
|
+
|
|
32
|
+
explicit Result(OkTag, const T &value) : ok_value(value), is_ok_(true) {}
|
|
33
|
+
explicit Result(OkTag, T &&value) : ok_value(std::move(value)), is_ok_(true) {}
|
|
34
|
+
explicit Result(ErrTag, const E &error) : err_value(error), is_ok_(false) {}
|
|
35
|
+
explicit Result(ErrTag, E &&error) : err_value(std::move(error)), is_ok_(false) {}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
Result(const Result<T, E> &other) {
|
|
39
|
+
is_ok_ = other.is_ok_;
|
|
40
|
+
if (is_ok_) {
|
|
41
|
+
new (&ok_value) T(other.ok_value);
|
|
42
|
+
} else {
|
|
43
|
+
new (&err_value) E(other.err_value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Result(Result<T, E> &&other) noexcept(
|
|
48
|
+
std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_constructible_v<E>) {
|
|
49
|
+
is_ok_ = other.is_ok_;
|
|
50
|
+
if (is_ok_) {
|
|
51
|
+
new (&ok_value) T(std::move(other.ok_value));
|
|
52
|
+
} else {
|
|
53
|
+
new (&err_value) E(std::move(other.err_value));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Result &operator=(const Result &other) {
|
|
58
|
+
if (this == &other)
|
|
59
|
+
return *this;
|
|
60
|
+
if (is_ok_ == other.is_ok_) {
|
|
61
|
+
if (is_ok_)
|
|
62
|
+
ok_value = other.ok_value;
|
|
63
|
+
else
|
|
64
|
+
err_value = other.err_value;
|
|
65
|
+
} else {
|
|
66
|
+
if (is_ok_) {
|
|
67
|
+
ok_value.~T();
|
|
68
|
+
new (&err_value) E(other.err_value);
|
|
69
|
+
is_ok_ = false;
|
|
70
|
+
} else {
|
|
71
|
+
err_value.~E();
|
|
72
|
+
new (&ok_value) T(other.ok_value);
|
|
73
|
+
is_ok_ = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return *this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Result &operator=(Result &&other) noexcept(
|
|
80
|
+
std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_assignable_v<E> &&
|
|
81
|
+
std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_constructible_v<E>) {
|
|
82
|
+
if (this == &other)
|
|
83
|
+
return *this;
|
|
84
|
+
if (is_ok_ == other.is_ok_) {
|
|
85
|
+
if (is_ok_)
|
|
86
|
+
ok_value = std::move(other.ok_value);
|
|
87
|
+
else
|
|
88
|
+
err_value = std::move(other.err_value);
|
|
89
|
+
} else {
|
|
90
|
+
if (is_ok_) {
|
|
91
|
+
ok_value.~T();
|
|
92
|
+
new (&err_value) E(std::move(other.err_value));
|
|
93
|
+
is_ok_ = false;
|
|
94
|
+
} else {
|
|
95
|
+
err_value.~E();
|
|
96
|
+
new (&ok_value) T(std::move(other.ok_value));
|
|
97
|
+
is_ok_ = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return *this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
~Result() {
|
|
104
|
+
if (is_ok_) {
|
|
105
|
+
ok_value.~T();
|
|
106
|
+
} else {
|
|
107
|
+
err_value.~E();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @brief Creates a success Result.
|
|
112
|
+
static Result<T, E> Ok(const T &value) {
|
|
113
|
+
return Result<T, E>(OkTag{}, value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// @brief Creates a success Result from an rvalue.
|
|
117
|
+
static Result<T, E> Ok(T &&value) {
|
|
118
|
+
return Result<T, E>(OkTag{}, std::move(value));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// @brief Creates an error Result.
|
|
122
|
+
static Result<T, E> Err(const E &error) {
|
|
123
|
+
return Result<T, E>(ErrTag{}, error);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/// @brief Creates an error Result from an rvalue.
|
|
127
|
+
static Result<T, E> Err(E &&error) {
|
|
128
|
+
return Result<T, E>(ErrTag{}, std::move(error));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// @brief Returns true if the result is Ok.
|
|
132
|
+
[[nodiscard]] bool is_ok() const {
|
|
133
|
+
return is_ok_;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// @brief Returns true if the result is Err.
|
|
137
|
+
[[nodiscard]] bool is_err() const {
|
|
138
|
+
return !is_ok_;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// @brief Returns the contained Ok value, consuming the Result.
|
|
142
|
+
/// @throws std::runtime_error if the value is an Err.
|
|
143
|
+
[[nodiscard]] T expect(const std::string &msg) && {
|
|
144
|
+
if (!is_ok_) {
|
|
145
|
+
throw std::runtime_error(msg);
|
|
146
|
+
}
|
|
147
|
+
return std::move(ok_value);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/// @brief Returns the contained Ok value.
|
|
151
|
+
/// @throws std::runtime_error if the value is an Err.
|
|
152
|
+
[[nodiscard]] const T &expect(const std::string &msg) const & {
|
|
153
|
+
if (!is_ok_) {
|
|
154
|
+
throw std::runtime_error(msg);
|
|
155
|
+
}
|
|
156
|
+
return ok_value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// @brief Returns the contained Ok value, consuming the Result.
|
|
160
|
+
/// @throws std::runtime_error if the value is an Err.
|
|
161
|
+
[[nodiscard]] T unwrap() && {
|
|
162
|
+
if (!is_ok_) {
|
|
163
|
+
throw std::runtime_error("Called unwrap on an Err value");
|
|
164
|
+
}
|
|
165
|
+
return std::move(ok_value);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// @brief Returns the contained Ok value.
|
|
169
|
+
/// @throws std::runtime_error if the value is an Err.
|
|
170
|
+
[[nodiscard]] const T &unwrap() const & {
|
|
171
|
+
if (!is_ok_) {
|
|
172
|
+
throw std::runtime_error("Called unwrap on an Err value");
|
|
173
|
+
}
|
|
174
|
+
return ok_value;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// @brief Returns the contained Ok value or a default. Consumes self.
|
|
178
|
+
[[nodiscard]] T unwrap_or(T &&default_value) && {
|
|
179
|
+
if (is_ok_) {
|
|
180
|
+
return std::move(ok_value);
|
|
181
|
+
}
|
|
182
|
+
return std::move(default_value);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// @brief Returns the contained Ok value or computes it from a closure. Consumes self.
|
|
186
|
+
[[nodiscard]] T unwrap_or_else(const std::function<T(E &&)> &func) && {
|
|
187
|
+
if (is_ok_) {
|
|
188
|
+
return std::move(ok_value);
|
|
189
|
+
}
|
|
190
|
+
return func(std::move(err_value));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/// @brief Returns the contained Ok value without checking. UB if Err.
|
|
194
|
+
[[nodiscard]] T unwrap_unchecked() && noexcept {
|
|
195
|
+
return std::move(ok_value);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// @brief Returns the contained Ok value without checking. UB if Err.
|
|
199
|
+
[[nodiscard]] const T &unwrap_unchecked() const & noexcept {
|
|
200
|
+
return ok_value;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/// @brief Returns the contained Err value, consuming the Result.
|
|
204
|
+
/// @throws std::runtime_error if the value is Ok.
|
|
205
|
+
[[nodiscard]] E unwrap_err() && {
|
|
206
|
+
if (is_ok_) {
|
|
207
|
+
throw std::runtime_error("Called unwrap_err on an Ok value");
|
|
208
|
+
}
|
|
209
|
+
return std::move(err_value);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/// @brief Returns the contained Err value.
|
|
213
|
+
/// @throws std::runtime_error if the value is Ok.
|
|
214
|
+
[[nodiscard]] const E &unwrap_err() const & {
|
|
215
|
+
if (is_ok_) {
|
|
216
|
+
throw std::runtime_error("Called unwrap_err on an Ok value");
|
|
217
|
+
}
|
|
218
|
+
return err_value;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// @brief Returns the contained Err value, consuming the Result.
|
|
222
|
+
/// @throws std::runtime_error if the value is Ok.
|
|
223
|
+
[[nodiscard]] E expect_err(const std::string &msg) && {
|
|
224
|
+
if (is_ok_) {
|
|
225
|
+
throw std::runtime_error(msg);
|
|
226
|
+
}
|
|
227
|
+
return std::move(err_value);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// @brief Returns the contained Err value.
|
|
231
|
+
/// @throws std::runtime_error if the value is Ok.
|
|
232
|
+
[[nodiscard]] const E &expect_err(const std::string &msg) const & {
|
|
233
|
+
if (is_ok_) {
|
|
234
|
+
throw std::runtime_error(msg);
|
|
235
|
+
}
|
|
236
|
+
return err_value;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// @brief Returns the contained Err value without checking. UB if Ok.
|
|
240
|
+
[[nodiscard]] E unwrap_err_unchecked() && noexcept {
|
|
241
|
+
return std::move(err_value);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/// @brief Returns the contained Err value without checking. UB if Ok.
|
|
245
|
+
[[nodiscard]] const E &unwrap_err_unchecked() const & noexcept {
|
|
246
|
+
return err_value;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// @brief Maps a Result<T, E> to Result<U, E> by applying a function to a contained Ok value.
|
|
250
|
+
template <typename F>
|
|
251
|
+
[[nodiscard]] auto map(F &&ok_func) && {
|
|
252
|
+
using U = std::invoke_result_t<F, T>;
|
|
253
|
+
using ResultType = Result<U, E>;
|
|
254
|
+
if (is_ok_) {
|
|
255
|
+
return ResultType::Ok(ok_func(std::move(ok_value)));
|
|
256
|
+
} else {
|
|
257
|
+
return ResultType::Err(std::move(err_value));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/// @brief Maps a Result<T, E> to Result<T, F> by applying a function to a contained Err value.
|
|
262
|
+
template <typename F>
|
|
263
|
+
[[nodiscard]] auto map_err(F &&err_func) && {
|
|
264
|
+
using U = std::invoke_result_t<F, E>;
|
|
265
|
+
using ResultType = Result<T, U>;
|
|
266
|
+
if (is_ok_) {
|
|
267
|
+
return ResultType::Ok(std::move(ok_value));
|
|
268
|
+
} else {
|
|
269
|
+
return ResultType::Err(err_func(std::move(err_value)));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// @brief Returns the provided default (if Err), or applies a function to the contained value (if Ok).
|
|
274
|
+
template <typename F, typename U>
|
|
275
|
+
[[nodiscard]] auto map_or(F &&ok_func, U &&default_value) && {
|
|
276
|
+
if (is_ok_) {
|
|
277
|
+
return ok_func(std::move(ok_value));
|
|
278
|
+
} else {
|
|
279
|
+
return std::forward<U>(default_value);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/// @brief Maps a Result<T, E> to U by applying fallback function default to a contained Err value, or function f to a contained Ok value.
|
|
284
|
+
template <typename FT, typename FE>
|
|
285
|
+
[[nodiscard]] auto map_or_else(FT &&ok_func, FE &&err_func) && {
|
|
286
|
+
if (is_ok_) {
|
|
287
|
+
return ok_func(std::move(ok_value));
|
|
288
|
+
} else {
|
|
289
|
+
return err_func(std::move(err_value));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/// @brief Calls the provided closure with the contained Ok value, if any, otherwise returns the Err value of self.
|
|
294
|
+
/// @tparam for Result<T,E> F is a closure that takes T and returns Result<TNew, E>
|
|
295
|
+
template <typename F>
|
|
296
|
+
[[nodiscard]] auto and_then(F &&ok_func) && {
|
|
297
|
+
using ResultType = std::invoke_result_t<F, T>;
|
|
298
|
+
if (is_ok_) {
|
|
299
|
+
return ok_func(std::move(ok_value));
|
|
300
|
+
} else {
|
|
301
|
+
return ResultType::Err(std::move(err_value));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/// @brief Calls the provided closure with the contained Err value, if any, otherwise returns the Ok value of self.
|
|
306
|
+
/// @tparam for Result<T,E> F is a closure that takes E and returns Result<T, ENew>
|
|
307
|
+
template <typename F>
|
|
308
|
+
[[nodiscard]] auto or_else(F &&err_func) && {
|
|
309
|
+
using ResultType = std::invoke_result_t<F, E>;
|
|
310
|
+
if (is_ok_) {
|
|
311
|
+
return ResultType::Ok(std::move(ok_value));
|
|
312
|
+
} else {
|
|
313
|
+
return err_func(std::move(err_value));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private:
|
|
318
|
+
union {
|
|
319
|
+
T ok_value;
|
|
320
|
+
E err_value;
|
|
321
|
+
};
|
|
322
|
+
bool is_ok_;
|
|
323
|
+
};
|
|
@@ -57,10 +57,15 @@ RCT_EXPORT_MODULE(AudioAPIModule);
|
|
|
57
57
|
[super invalidate];
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
- (dispatch_queue_t)methodQueue
|
|
61
|
+
{
|
|
62
|
+
return dispatch_queue_create("com.swmansion.audioapi.MainModuleQueue", DISPATCH_QUEUE_SERIAL);
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install)
|
|
61
66
|
{
|
|
62
67
|
self.audioSessionManager = [[AudioSessionManager alloc] init];
|
|
63
|
-
self.audioEngine = [[AudioEngine alloc]
|
|
68
|
+
self.audioEngine = [[AudioEngine alloc] init];
|
|
64
69
|
self.notificationManager = [[NotificationManager alloc] initWithAudioAPIModule:self];
|
|
65
70
|
self.notificationRegistry = [[NotificationRegistry alloc] initWithAudioAPIModule:self];
|
|
66
71
|
|
|
@@ -118,14 +123,9 @@ RCT_EXPORT_METHOD(
|
|
|
118
123
|
resolve reject : (RCTPromiseRejectBlock)reject)
|
|
119
124
|
{
|
|
120
125
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if ([self.audioSessionManager setActive:enabled]) {
|
|
125
|
-
resolve(@"true");
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
resolve(@"false");
|
|
126
|
+
auto success = [self.audioSessionManager setActive:enabled];
|
|
127
|
+
|
|
128
|
+
resolve(@(success));
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -334,9 +334,4 @@ RCT_EXPORT_METHOD(
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
- (dispatch_queue_t)methodQueue
|
|
338
|
-
{
|
|
339
|
-
return dispatch_queue_create("swmansion.audioapi.Queue", DISPATCH_QUEUE_SERIAL);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
337
|
@end
|
|
@@ -21,7 +21,7 @@ IOSAudioPlayer::IOSAudioPlayer(
|
|
|
21
21
|
while (processedFrames < numFrames) {
|
|
22
22
|
int framesToProcess = std::min(numFrames - processedFrames, RENDER_QUANTUM_SIZE);
|
|
23
23
|
|
|
24
|
-
if (isRunning_.load()) {
|
|
24
|
+
if (isRunning_.load(std::memory_order_acquire)) {
|
|
25
25
|
renderAudio_(audioBus_, framesToProcess);
|
|
26
26
|
} else {
|
|
27
27
|
audioBus_->zero();
|
|
@@ -57,13 +57,13 @@ bool IOSAudioPlayer::start()
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
bool success = [audioPlayer_ start];
|
|
60
|
-
isRunning_.store(success);
|
|
60
|
+
isRunning_.store(success, std::memory_order_release);
|
|
61
61
|
return success;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
void IOSAudioPlayer::stop()
|
|
65
65
|
{
|
|
66
|
-
isRunning_.store(false);
|
|
66
|
+
isRunning_.store(false, std::memory_order_release);
|
|
67
67
|
[audioPlayer_ stop];
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -74,13 +74,13 @@ bool IOSAudioPlayer::resume()
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
bool success = [audioPlayer_ resume];
|
|
77
|
-
isRunning_.store(success);
|
|
77
|
+
isRunning_.store(success, std::memory_order_release);
|
|
78
78
|
return success;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
void IOSAudioPlayer::suspend()
|
|
82
82
|
{
|
|
83
|
-
isRunning_.store(false);
|
|
83
|
+
isRunning_.store(false, std::memory_order_release);
|
|
84
84
|
[audioPlayer_ suspend];
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -88,7 +88,8 @@ bool IOSAudioPlayer::isRunning() const
|
|
|
88
88
|
{
|
|
89
89
|
AudioEngine *audioEngine = [AudioEngine sharedInstance];
|
|
90
90
|
|
|
91
|
-
return isRunning_.load() &&
|
|
91
|
+
return isRunning_.load(std::memory_order_acquire) &&
|
|
92
|
+
[audioEngine getState] == AudioEngineState::AudioEngineStateRunning;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
void IOSAudioPlayer::cleanup()
|
|
@@ -1,32 +1,58 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#ifdef __OBJC__ // when compiled as Objective-C
|
|
3
|
+
#ifdef __OBJC__ // when compiled as Objective-C
|
|
4
4
|
#import <NativeAudioRecorder.h>
|
|
5
|
-
#else
|
|
5
|
+
#else
|
|
6
|
+
typedef struct objc_object NSURL;
|
|
7
|
+
typedef struct objc_object AVAudioFile;
|
|
8
|
+
typedef struct objc_object AudioBufferList;
|
|
6
9
|
typedef struct objc_object NativeAudioRecorder;
|
|
7
10
|
#endif // __OBJC__
|
|
8
11
|
|
|
9
12
|
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
13
|
+
#include <audioapi/utils/Result.hpp>
|
|
14
|
+
|
|
15
|
+
#include <mutex>
|
|
10
16
|
|
|
11
17
|
namespace audioapi {
|
|
12
18
|
|
|
13
|
-
class
|
|
14
|
-
class
|
|
19
|
+
class FileWriter;
|
|
20
|
+
class RecorderCallback;
|
|
21
|
+
class RecorderAdapterNode;
|
|
22
|
+
class AudioFileProperties;
|
|
23
|
+
class AudioEventHandlerRegistry;
|
|
15
24
|
|
|
16
25
|
class IOSAudioRecorder : public AudioRecorder {
|
|
17
26
|
public:
|
|
18
|
-
IOSAudioRecorder(
|
|
19
|
-
float sampleRate,
|
|
20
|
-
int bufferLength,
|
|
21
|
-
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
22
|
-
|
|
27
|
+
IOSAudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
|
|
23
28
|
~IOSAudioRecorder() override;
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
Result<std::string, std::string> start() override;
|
|
31
|
+
Result<std::tuple<std::string, double, double>, std::string> stop() override;
|
|
32
|
+
|
|
33
|
+
Result<std::string, std::string> enableFileOutput(
|
|
34
|
+
std::shared_ptr<AudioFileProperties> properties) override;
|
|
35
|
+
void disableFileOutput() override;
|
|
36
|
+
|
|
37
|
+
void connect(const std::shared_ptr<RecorderAdapterNode> &node) override;
|
|
38
|
+
void disconnect() override;
|
|
39
|
+
|
|
40
|
+
void pause() override;
|
|
41
|
+
void resume() override;
|
|
42
|
+
|
|
43
|
+
bool isRecording() const override;
|
|
44
|
+
bool isPaused() const override;
|
|
45
|
+
bool isIdle() const override;
|
|
46
|
+
|
|
47
|
+
Result<NoneType, std::string> setOnAudioReadyCallback(
|
|
48
|
+
float sampleRate,
|
|
49
|
+
size_t bufferLength,
|
|
50
|
+
int channelCount,
|
|
51
|
+
uint64_t callbackId) override;
|
|
52
|
+
void clearOnAudioReadyCallback() override;
|
|
27
53
|
|
|
28
|
-
|
|
29
|
-
NativeAudioRecorder *
|
|
54
|
+
protected:
|
|
55
|
+
NativeAudioRecorder *nativeRecorder_;
|
|
30
56
|
};
|
|
31
57
|
|
|
32
58
|
} // namespace audioapi
|