Am 12.04.23 um 15:59 schrieb Dorinda Bassey: > Hi Volker, > > It seems that for some unknown reason using audio_pcm_info_clear_buf in > playback_process causes segmentation fault. Hence I moved the handling of > buffer underruns from the playback process to the qpw_write process because > that is the underlying cause of buffer underrun. >
Hi Dorinda, I guess you made a mistake somewhere if you see a segmentation fault. This patch for v10 works fine on my computer. diff --git a/audio/pwaudio.c b/audio/pwaudio.c index f9da86059f..0f272d6744 100644 --- a/audio/pwaudio.c +++ b/audio/pwaudio.c @@ -79,7 +79,7 @@ stream_destroy(void *data) static void playback_on_process(void *data) { - PWVoice *v = (PWVoice *) data; + PWVoice *v = data; void *p; struct pw_buffer *b; struct spa_buffer *buf; @@ -108,19 +108,28 @@ playback_on_process(void *data) n_bytes = SPA_MIN(req, buf->datas[0].maxsize); /* get no of available bytes to read data from buffer */ - avail = spa_ringbuffer_get_read_index(&v->ring, &index); + if (avail <= 0) { + PWVoiceOut *vo = container_of(data, PWVoiceOut, v); - if (avail < (int32_t) n_bytes) { - n_bytes = avail; - } + audio_pcm_info_clear_buf(&vo->hw.info, p, n_bytes / v->frame_size); + } else { + if ((uint32_t)avail < n_bytes) { + /* + * PipeWire immediately calls this callback again if we provide + * less than n_bytes. Then audio_pcm_info_clear_buf() fills the + * rest of the buffer with silence. + */ + n_bytes = avail; + } - spa_ringbuffer_read_data(&v->ring, - v->buffer, RINGBUFFER_SIZE, - index & RINGBUFFER_MASK, p, n_bytes); + spa_ringbuffer_read_data(&v->ring, + v->buffer, RINGBUFFER_SIZE, + index & RINGBUFFER_MASK, p, n_bytes); - index += n_bytes; - spa_ringbuffer_read_update(&v->ring, index); + index += n_bytes; + spa_ringbuffer_read_update(&v->ring, index); + } buf->datas[0].chunk->offset = 0; buf->datas[0].chunk->stride = v->frame_size; -- 2.35.3 With best regards, Volker