fix: guard against NULL audio ports and defer channel activation until port registration succeeds
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -6,13 +6,6 @@
|
||||
|
||||
void channel_add(jack_client_t *client, int idx)
|
||||
{
|
||||
channels[idx].active = 1;
|
||||
atomic_store(&channels[idx].state, STATE_IDLE);
|
||||
channels[idx].prev_state = -1;
|
||||
channels[idx].loop_count = 0;
|
||||
channels[idx].record_pos = 0;
|
||||
channels[idx].playback_pos = 0;
|
||||
|
||||
char in_name[64], out_name[64];
|
||||
snprintf(in_name, sizeof(in_name), "channel%d_input", next_channel_id);
|
||||
snprintf(out_name, sizeof(out_name), "channel%d_output", next_channel_id);
|
||||
@@ -23,8 +16,20 @@ void channel_add(jack_client_t *client, int idx)
|
||||
channels[idx].audio_out = jack_port_register(client, out_name,
|
||||
JACK_DEFAULT_AUDIO_TYPE,
|
||||
JackPortIsOutput, 0);
|
||||
if (!channels[idx].audio_in || !channels[idx].audio_out)
|
||||
if (!channels[idx].audio_in || !channels[idx].audio_out) {
|
||||
fprintf(stderr, "Failed to register ports for channel %d\n", next_channel_id);
|
||||
/* Do NOT mark channel active – process loop will skip it */
|
||||
channels[idx].active = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
channels[idx].active = 1;
|
||||
atomic_store(&channels[idx].state, STATE_IDLE);
|
||||
channels[idx].prev_state = -1;
|
||||
channels[idx].loop_count = 0;
|
||||
channels[idx].record_pos = 0;
|
||||
channels[idx].playback_pos = 0;
|
||||
|
||||
next_channel_id++;
|
||||
channel_count++;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@ int process_callback(jack_nframes_t nframes, void *arg)
|
||||
for (int c = 0; c < MAX_CHANNELS; c++) {
|
||||
if (!channels[c].active) continue;
|
||||
|
||||
/* Guard against NULL ports (e.g. if port registration failed) */
|
||||
if (!channels[c].audio_in || !channels[c].audio_out) {
|
||||
fprintf(stderr, "WARN: channel %d has NULL audio port(s), skipping\n", c);
|
||||
continue;
|
||||
}
|
||||
|
||||
jack_default_audio_sample_t *in = (jack_default_audio_sample_t *)
|
||||
jack_port_get_buffer(channels[c].audio_in, nframes);
|
||||
jack_default_audio_sample_t *out = (jack_default_audio_sample_t *)
|
||||
|
||||
Reference in New Issue
Block a user