Skip to content

Commit 2952e5e

Browse files
refactor: cleanup
1 parent 43a7395 commit 2952e5e

19 files changed

Lines changed: 72 additions & 100 deletions

apps/fabric-example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ EXTERNAL SOURCES:
25142514

25152515
SPEC CHECKSUMS:
25162516
FBLazyVector: e97c19a5a442429d1988f182a1940fb08df514da
2517-
hermes-engine: 471e81260adadffc041e40c5eea01333addabb53
2517+
hermes-engine: ca0c1d4fe0200e05fedd8d7c0c283b54cd461436
25182518
RCTDeprecation: af44b104091a34482596cd9bd7e8d90c4e9b4bd7
25192519
RCTRequired: bb77b070f75f53398ce43c0aaaa58337cebe2bf6
25202520
RCTSwiftUI: afc0a0a635860da1040a0b894bfd529da06d7810
@@ -2523,7 +2523,7 @@ SPEC CHECKSUMS:
25232523
React: 1ba7d364ade7d883a1ec055bfc3606f35fdee17b
25242524
React-callinvoker: bc2a26f8d84fb01f003fc6de6c9337b64715f95b
25252525
React-Core: 7840d3a80b43a95c5e80ef75146bd70925ebab0f
2526-
React-Core-prebuilt: 6586031f606ff8ab466cac9e8284053a91342881
2526+
React-Core-prebuilt: e44365cf4785c3aa56ababc9ab204fe8bc6b17d0
25272527
React-CoreModules: 2eb010400b63b89e53a324ffb3c112e4c7c3ce42
25282528
React-cxxreact: a558e92199d26f145afa9e62c4233cf8e7950efe
25292529
React-debug: 755200a6e7f5e6e0a40ff8d215493d43cce285fc
@@ -2587,7 +2587,7 @@ SPEC CHECKSUMS:
25872587
ReactAppDependencyProvider: e96e93b493d8d86eeaee3e590ba0be53f6abe46f
25882588
ReactCodegen: f66521b131699d6af0790f10653933b3f1f79a6f
25892589
ReactCommon: 07572bf9e687c8a52fbe4a3641e9e3a1a477c78e
2590-
ReactNativeDependencies: a5d71d95f2654107eb45e6ece04caba36beac2bd
2590+
ReactNativeDependencies: 3467a1fea6f7a524df13b30430bebcc254d9aee2
25912591
RNAudioAPI: fa5c075d2fcdb1ad9a695754b38f07c8c3074396
25922592
RNGestureHandler: 07de6f059e0ee5744ae9a56feb07ee345338cc31
25932593
RNReanimated: d75c81956bf7531fe08ba4390149002ab8bdd127

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ AudioParamHostObject::AudioParamHostObject(
4444
}
4545

4646
AudioParamHostObject::~AudioParamHostObject() {
47-
if (graph_ && bridgeNode_) {
48-
// Remove outgoing edges (bridge → owner)
49-
(void)graph_->removeAllEdges(bridgeNode_);
47+
if (graph_ && bridgeNode_ != nullptr) {
5048
// Remove the bridge node itself
5149
(void)graph_->removeNode(bridgeNode_);
5250
bridgeNode_ = nullptr;

packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class AudioParam {
6666
/// @note Audio Thread only
6767
void cancelAndHoldAtTime(double cancelTime);
6868

69-
template <
70-
typename F,
71-
typename = std::enable_if_t<std::is_invocable_r_v<void, std::decay_t<F>, BaseAudioContext &>>>
69+
template <typename F>
7270
bool scheduleAudioEvent(F &&event) noexcept {
7371
if (std::shared_ptr<BaseAudioContext> context = context_.lock()) {
7472
return context->scheduleAudioEvent(std::forward<F>(event));
@@ -86,13 +84,6 @@ class AudioParam {
8684
return inputBuffer_;
8785
}
8886

89-
/// @brief Called when a BridgeNode connected to this param is being destroyed.
90-
/// Clears the input buffer so the param no longer relies on stale bridge data.
91-
/// @note Audio Thread only
92-
void onBridgeDetached() {
93-
inputBuffer_->zero();
94-
}
95-
9687
/// @note Audio Thread only
9788
std::shared_ptr<DSPAudioBuffer> processARateParam(int framesToProcess, double time);
9889

packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class BaseAudioContext : public std::enable_shared_from_this<BaseAudioContext> {
5050
std::shared_ptr<utils::graph::Graph> getGraph() const;
5151
std::shared_ptr<IAudioEventHandlerRegistry> getAudioEventHandlerRegistry() const;
5252
const RuntimeRegistry &getRuntimeRegistry() const;
53-
utils::DisposerImpl<utils::graph::Graph::kDisposerPayloadSize> *getDisposer() const;
53+
utils::DisposerImpl<DISPOSER_PAYLOAD_SIZE> *getDisposer() const;
5454

5555
/// @brief Assigns the audio destination node to the context.
5656
/// @param destination The audio destination node to be associated with the context.
@@ -92,7 +92,7 @@ class BaseAudioContext : public std::enable_shared_from_this<BaseAudioContext> {
9292
static constexpr size_t AUDIO_SCHEDULER_CAPACITY = 1024;
9393
CrossThreadEventScheduler<BaseAudioContext> audioEventScheduler_;
9494

95-
std::unique_ptr<utils::DisposerImpl<utils::graph::Graph::kDisposerPayloadSize>> disposer_;
95+
std::unique_ptr<utils::DisposerImpl<DISPOSER_PAYLOAD_SIZE>> disposer_;
9696
std::shared_ptr<utils::graph::Graph> graph_;
9797

9898
[[nodiscard]] virtual bool isDriverRunning() const = 0;

packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class StereoPannerNode : public AudioNode {
1818
const StereoPannerOptions &options);
1919

2020
[[nodiscard]] std::shared_ptr<AudioParam> getPanParam() const;
21-
22-
std::shared_ptr<DSPAudioBuffer> getOutputBuffer() const override;
21+
[[nodiscard]] std::shared_ptr<DSPAudioBuffer> getOutputBuffer() const override;
2322

2423
protected:
2524
void processNode(int framesToProcess) override;

packages/react-native-audio-api/common/cpp/audioapi/core/utils/Constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ inline constexpr size_t PROMISE_VENDOR_THREAD_POOL_WORKER_COUNT = 4;
3636
inline constexpr size_t PROMISE_VENDOR_THREAD_POOL_LOAD_BALANCER_QUEUE_SIZE = 32;
3737
inline constexpr size_t PROMISE_VENDOR_THREAD_POOL_WORKER_QUEUE_SIZE = 32;
3838

39+
// Disposer payload size (= sizeof(std::vector<T>))
40+
inline constexpr size_t DISPOSER_PAYLOAD_SIZE = 24;
41+
3942
// Cache line size
4043
#ifdef __cpp_lib_hardware_interference_size
4144
using std::hardware_constructive_interference_size;

packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph/AudioGraph.hpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <audioapi/core/utils/Constants.h>
4+
#include <audioapi/core/utils/Disposer.hpp>
35
#include <audioapi/core/utils/graph/InputPool.hpp>
46
#include <audioapi/core/utils/graph/NodeHandle.hpp>
57

@@ -223,8 +225,6 @@ inline void AudioGraph::process() {
223225
if (node.orphaned && InputPool::isEmpty(node.input_head) &&
224226
node.handle->audioNode->canBeDestructed()) {
225227
node.will_be_deleted = true;
226-
// Call beforeDestruction while node is still valid (before move/compaction)
227-
node.handle->audioNode->beforeDestruction();
228228
}
229229
}
230230

@@ -242,8 +242,9 @@ inline void AudioGraph::process() {
242242
// Must happen BEFORE shifting nodes, because shifting invalidates source
243243
// positions that later nodes' inputs may still reference.
244244
for (std::uint32_t e = 0; e < n; e++) {
245-
if (nodes[e].will_be_deleted)
245+
if (nodes[e].will_be_deleted) {
246246
continue;
247+
}
247248
for (auto &inp : pool_.mutableView(nodes[e].input_head)) {
248249
inp = static_cast<std::uint32_t>(nodes[inp].after_compaction_ind);
249250
}
@@ -252,8 +253,9 @@ inline void AudioGraph::process() {
252253
// ── Pass 2b: compact — shift kept nodes left ───────────────────────────
253254
std::uint32_t b = 0;
254255
for (std::uint32_t e = 0; e < n; e++) {
255-
if (nodes[e].will_be_deleted)
256+
if (nodes[e].will_be_deleted) {
256257
continue;
258+
}
257259
if (b != e) {
258260
nodes[b] = std::move(nodes[e]);
259261
nodes[e].input_head = InputPool::kNull; // prevent double-free in truncation
@@ -283,13 +285,15 @@ inline void AudioGraph::process() {
283285

284286
inline void AudioGraph::kahn_toposort() {
285287
const auto n = static_cast<std::uint32_t>(nodes.size());
286-
if (n <= 1)
288+
if (n <= 1) {
287289
return;
290+
}
288291

289292
// Phase 1: compute out-degree
290293
for (const auto &nd : nodes) {
291-
for (std::uint32_t inp : pool_.view(nd.input_head))
294+
for (std::uint32_t inp : pool_.view(nd.input_head)) {
292295
nodes[inp].topo_out_degree++;
296+
}
293297
}
294298

295299
// Phase 2: reverse Kahn BFS — sinks first, sources last in dequeue order.
@@ -306,8 +310,9 @@ inline void AudioGraph::kahn_toposort() {
306310
};
307311

308312
for (std::uint32_t i = 0; i < n; i++) {
309-
if (nodes[i].topo_out_degree == 0)
313+
if (nodes[i].topo_out_degree == 0) {
310314
enq(i);
315+
}
311316
}
312317

313318
std::uint32_t write = n;
@@ -317,15 +322,17 @@ inline void AudioGraph::kahn_toposort() {
317322
nodes[idx].after_compaction_ind = static_cast<std::int32_t>(--write);
318323

319324
for (std::uint32_t inp : pool_.view(nodes[idx].input_head)) {
320-
if (--nodes[inp].topo_out_degree == 0)
325+
if (--nodes[inp].topo_out_degree == 0) {
321326
enq(inp);
327+
}
322328
}
323329
}
324330

325331
// Phase 3: remap input indices to new positions (before nodes move)
326332
for (auto &nd : nodes) {
327-
for (std::uint32_t &inp : pool_.mutableView(nd.input_head))
333+
for (std::uint32_t &inp : pool_.mutableView(nd.input_head)) {
328334
inp = static_cast<std::uint32_t>(nodes[inp].after_compaction_ind);
335+
}
329336
}
330337

331338
// Phase 4: apply permutation in place via cycle sort
@@ -338,8 +345,9 @@ inline void AudioGraph::kahn_toposort() {
338345

339346
// Phase 5: update handle indices & reset scratch
340347
for (std::uint32_t i = 0; i < n; i++) {
341-
if (nodes[i].handle)
348+
if (nodes[i].handle) {
342349
nodes[i].handle->index = i;
350+
}
343351
nodes[i].after_compaction_ind = -1;
344352
}
345353
}

packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph/BridgeNode.cpp

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph/BridgeNode.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <audioapi/core/AudioParam.h>
34
#include <audioapi/core/types/ChannelInterpretation.h>
45
#include <audioapi/core/utils/graph/GraphObject.hpp>
56
#include <audioapi/utils/AudioBuffer.hpp>
@@ -34,8 +35,6 @@ class BridgeNode final : public GraphObject {
3435
public:
3536
explicit BridgeNode(AudioParam *param) : param_(param) {}
3637

37-
void beforeDestruction() override;
38-
3938
[[nodiscard]] bool isProcessable() const override {
4039
return true;
4140
}
@@ -55,7 +54,20 @@ class BridgeNode final : public GraphObject {
5554
}
5655

5756
protected:
58-
void processInputs(const std::vector<const DSPAudioBuffer *> &inputs, int numFrames) override;
57+
void processInputs(const std::vector<const DSPAudioBuffer *> &inputs, int numFrames) override {
58+
// Skip processing if param is null (e.g., in tests)
59+
if (param_ == nullptr) {
60+
return;
61+
}
62+
63+
// Get AudioParam's input buffer and fill it with mixed inputs
64+
auto inputBuffer = param_->getInputBuffer();
65+
inputBuffer->zero();
66+
67+
for (const DSPAudioBuffer *input : inputs) {
68+
inputBuffer->sum(*input, ChannelInterpretation::SPEAKERS);
69+
}
70+
}
5971

6072
private:
6173
AudioParam *param_;

packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph/Graph.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class Graph {
4949
using HNode = HostGraph::Node;
5050

5151
public:
52-
static constexpr size_t kDisposerPayloadSize = HostGraph::kDisposerPayloadSize;
5352
using ResultError = HostGraph::ResultError;
5453
using Res = Result<NoneType, ResultError>;
5554

56-
Graph(size_t eventQueueCapacity, Disposer<kDisposerPayloadSize> *disposer) : disposer_(disposer) {
55+
Graph(size_t eventQueueCapacity, Disposer<audioapi::DISPOSER_PAYLOAD_SIZE> *disposer)
56+
: disposer_(disposer) {
5757
using namespace audioapi::channels::spsc;
5858

5959
auto [es, er] = channel<AGEvent, OverflowStrategy::WAIT_ON_FULL, WaitStrategy::BUSY_LOOP>(
@@ -64,7 +64,7 @@ class Graph {
6464

6565
Graph(
6666
size_t eventQueueCapacity,
67-
Disposer<kDisposerPayloadSize> *disposer,
67+
Disposer<audioapi::DISPOSER_PAYLOAD_SIZE> *disposer,
6868
std::uint32_t initialNodeCapacity,
6969
std::uint32_t initialEdgeCapacity)
7070
: Graph(eventQueueCapacity, disposer) {
@@ -190,7 +190,7 @@ class Graph {
190190

191191
// ── Disposer — destroys old pool buffers off the audio thread ───────────
192192

193-
Disposer<kDisposerPayloadSize> *disposer_;
193+
Disposer<audioapi::DISPOSER_PAYLOAD_SIZE> *disposer_;
194194

195195
// ── Main-thread tracking for pre-growth ─────────────────────────────────
196196

@@ -209,13 +209,14 @@ class Graph {
209209
if (edges > poolCapacity_ / 2) {
210210
std::uint32_t newCap = std::max(static_cast<std::uint32_t>(edges * 2), std::uint32_t{64});
211211
auto buf = std::make_unique<InputPool::Slot[]>(newCap);
212-
eventSender_.send([buf = std::move(buf), newCap](
213-
AudioGraph &graph, Disposer<kDisposerPayloadSize> &disposer) mutable {
214-
auto *old = graph.pool().adoptBuffer(buf.release(), newCap);
215-
if (old) {
216-
disposer.dispose(OwnedSlotBuffer(old));
217-
}
218-
});
212+
eventSender_.send(
213+
[buf = std::move(buf), newCap](
214+
AudioGraph &graph, Disposer<audioapi::DISPOSER_PAYLOAD_SIZE> &disposer) mutable {
215+
auto *old = graph.pool().adoptBuffer(buf.release(), newCap);
216+
if (old) {
217+
disposer.dispose(OwnedSlotBuffer(old));
218+
}
219+
});
219220
poolCapacity_ = newCap;
220221
}
221222
}

0 commit comments

Comments
 (0)