Channel negotiation drops buffer swaps when several graph changes land in one render quantum
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp, react-native
- Ambito
- audio-video-rtc, backend
Direzione di ricerca
Start in common/cpp/audioapi/core/utils/graph/HostGraph.cpp, especially buildNegotiatedBufferIfNeeded, then inspect HostGraph::Node and initialization in addNode. Add the described reproductions to common/cpp/test/src/graph/GraphTest.cpp and run the graph tests; done means the batched channel changes leave the destination at the expected channel count.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
While a context is rendering, HostGraph can leave a node with the wrong channel count. Stereo
content then plays mono, and a StereoPannerNode or PannerNode placed after it no longer pans.
On a device it is intermittent: it depends on whether an audio callback runs between the JS calls.
buildNegotiatedBufferIfNeeded (common/cpp/audioapi/core/utils/graph/HostGraph.cpp) runs on the
JS thread. It skips the swap when the node's live buffer already has the computed channel count.
Swaps queued earlier in the same batch have not reached the audio thread yet. So when a node goes
2 → 1 → 2 within one batch, the second negotiation sees the live 2 and queues nothing, and the
queued swap to 1 is applied last. Offline before startRendering(), or in a suspended context, the
producer drains its own events, so the live buffer is current and the bug does not show.
A common JS pattern that should hit it (inferred from reading the code; the C++ test below is the
verified reproduction):
// In one JS task, while the context is running:
const source = ctx.createBufferSource();
source.connect(gain); // no buffer yet: 1 output channel, gain -> 1 is queued
source.buffer = stereoBuffer; // 2 output channels: gain's live buffer still has 2, nothing is queued
source.start(); // gain stays mono
Another one: a mono source and a StereoPannerNode connected to the same gain in one task. This is
what Howler's sound.stereo(pan) does: the gain stays mono and the panned output collapses to the
center.
Steps to reproduce
Add this to common/cpp/test/src/graph/GraphTest.cpp. There is no processEvents() between the two
changes, as on a running context where both apply in the same render quantum:
TEST_F(GraphTest, ComputedNumberOfChannels_MaxMode_BatchedChangesBackToLiveWidth) {
auto *mono = addChannelCountNode(*graph, {.channelCount = 1, .mode = ChannelCountMode::EXPLICIT});
auto *stereo = addChannelCountNode(*graph, {.channelCount = 2, .mode = ChannelCountMode::EXPLICIT});
auto *dest = addChannelCountNode(*graph, {.channelCount = 2, .mode = ChannelCountMode::MAX});
graph->processEvents();
ASSERT_TRUE(graph->addEdge(mono, dest).is_ok());
ASSERT_TRUE(graph->addEdge(stereo, dest).is_ok());
graph->processEvents();
EXPECT_EQ(channelsOf(dest), 2u); // fails on main: 1
}
The same happens with addEdge(mono, dest) followed by removeEdge(mono, dest) (expected 2, got
1), and with a source whose output channel number changes from 1 to 2 after addEdge, followed by
renegotiateNodeChannels (expected 2, got 1). All three fail on main (b8491e1).
Proposed fix
Record on HostGraph::Node the channel count of the last swap queued for the audio thread,
initialized in addNode (AudioGraph does not know the node yet, so reading its buffer there is
safe), and compare against it instead of the live buffer. With this change the three cases pass, and
so do the smoke suite (460 tests) and the graph category (659 tests). I can open a PR with the fix
and the tests.
Snack or a link to a repository
no React Native app. We embed the C++ engine in a custom iOS runtime; the reproduction is the GraphTest case above.
React Native Audio API version
1.0.0
React Native version
0.75.3
Platforms
iOS
JavaScript runtime
Hermes
Workflow
None
Architecture
None
Build type
None
Device
Real device
Device model
No response
Acknowledgements
Yes
- Lingua principale
- C++
- Stelle
- 848
- Fork
- 94
- Merge medio
- 4g 20m
- PR unite (30g)
- 31
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-native-audio-api
-
android bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
software-mansion/react-native-audio-api#1273 · 5 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
software-mansion/react-native-audio-api#1238 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
software-mansion/react-native-audio-api#1340 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
software-mansion/react-native-audio-api#1339 ·
I maintainer di solito rispondono entro 2 giorni
-
bug ios pkg:audio-api
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
software-mansion/react-native-audio-api#1298 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di software-mansion/react-native-audio-api
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
FriendsofECCE/ECCE#336 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bitcoin-core/gui-qml#1030 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
tesseract-robotics/tesseract#1384 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NVIDIA/nccl-extensions#26 ·