Skip to content

Commit 78432fb

Browse files
committed
Also run the EventLoop for OfflineAudioContext
1 parent 75096f1 commit 78432fb

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

src/context/concrete_base.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct ConcreteBaseAudioContextInner {
108108
/// Stores the event handlers
109109
event_loop: EventLoop,
110110
/// Sender for events that will be handled by the EventLoop
111-
event_send: Option<Sender<EventDispatch>>,
111+
event_send: Sender<EventDispatch>,
112112
}
113113

114114
impl BaseAudioContext for ConcreteBaseAudioContext {
@@ -126,15 +126,12 @@ impl ConcreteBaseAudioContext {
126126
state: Arc<AtomicU8>,
127127
frames_played: Arc<AtomicU64>,
128128
render_channel: Sender<ControlMessage>,
129-
event_channel: Option<(Sender<EventDispatch>, Receiver<EventDispatch>)>,
129+
event_channel: (Sender<EventDispatch>, Receiver<EventDispatch>),
130130
offline: bool,
131131
node_id_consumer: llq::Consumer<AudioNodeId>,
132132
) -> Self {
133133
let event_loop = EventLoop::new();
134-
let (event_send, event_recv) = match event_channel {
135-
None => (None, None),
136-
Some((send, recv)) => (Some(send), Some(recv)),
137-
};
134+
let (event_send, event_recv) = event_channel;
138135

139136
let audio_node_id_provider = AudioNodeIdProvider::new(node_id_consumer);
140137

@@ -220,11 +217,7 @@ impl ConcreteBaseAudioContext {
220217
}
221218

222219
// Boot the event loop thread that handles the events spawned by the render thread
223-
// (we don't do this for offline rendering because it makes little sense, the graph cannot
224-
// be mutated once rendering has started anyway)
225-
if let Some(event_channel) = event_recv {
226-
event_loop.run(event_channel);
227-
}
220+
event_loop.run(event_recv);
228221

229222
base
230223
}
@@ -288,10 +281,7 @@ impl ConcreteBaseAudioContext {
288281
}
289282

290283
pub(crate) fn send_event(&self, msg: EventDispatch) -> Result<(), SendError<EventDispatch>> {
291-
match self.inner.event_send.as_ref() {
292-
Some(s) => s.send(msg),
293-
None => Err(SendError(msg)),
294-
}
284+
self.inner.event_send.send(msg)
295285
}
296286

297287
pub(crate) fn lock_control_msg_sender(&self) -> RwLockWriteGuard<'_, Sender<ControlMessage>> {

src/context/offline.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ impl OfflineAudioContext {
100100
let state = Arc::new(AtomicU8::new(AudioContextState::Suspended as u8));
101101
let state_clone = Arc::clone(&state);
102102

103+
// Communication channel for events from the render thread to the control thread.
104+
// Use an unbounded channel because we do not require real-time safety.
105+
let event_channel = crossbeam_channel::unbounded();
106+
103107
// setup the render 'thread', which will run inside the control thread
104108
let renderer = RenderThread::new(
105109
sample_rate,
@@ -116,7 +120,7 @@ impl OfflineAudioContext {
116120
state,
117121
frames_played,
118122
sender,
119-
None,
123+
event_channel,
120124
true,
121125
node_id_consumer,
122126
);

src/context/online.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl AudioContext {
209209
state,
210210
frames_played,
211211
ctrl_msg_send,
212-
Some((event_send, event_recv)),
212+
(event_send, event_recv),
213213
false,
214214
node_id_consumer,
215215
);

0 commit comments

Comments
 (0)