diff --git a/client/audiodevs/PipeWire/pipewire.c b/client/audiodevs/PipeWire/pipewire.c index 40ec88fe..738edc4b 100644 --- a/client/audiodevs/PipeWire/pipewire.c +++ b/client/audiodevs/PipeWire/pipewire.c @@ -106,8 +106,7 @@ static void pipewire_onPlaybackProcess(void * userdata) if (pw.playback.rateMatch && pw.playback.rateMatch->size > 0) frames = min(frames, pw.playback.rateMatch->size); - uint8_t * data; - frames = pw.playback.pullFn(&data, frames); + frames = pw.playback.pullFn(dst, frames); if (!frames) { if (pw.playback.state == STREAM_STATE_FLUSHING) @@ -123,8 +122,6 @@ static void pipewire_onPlaybackProcess(void * userdata) return; } - memcpy(dst, data, frames * pw.playback.stride); - sbuf->datas[0].chunk->offset = 0; sbuf->datas[0].chunk->stride = pw.playback.stride; sbuf->datas[0].chunk->size = frames * pw.playback.stride; diff --git a/client/audiodevs/PulseAudio/pulseaudio.c b/client/audiodevs/PulseAudio/pulseaudio.c index d435cb2c..c313ba46 100644 --- a/client/audiodevs/PulseAudio/pulseaudio.c +++ b/client/audiodevs/PulseAudio/pulseaudio.c @@ -220,14 +220,13 @@ static void pulseaudio_free(void) static void pulseaudio_write_cb(pa_stream * p, size_t nbytes, void * userdata) { - uint8_t * dst, * src; + uint8_t * dst; pa_stream_begin_write(p, (void **)&dst, &nbytes); int frames = nbytes / pa.sinkStride; - frames = pa.sinkPullFn(&src, frames); + frames = pa.sinkPullFn(dst, frames); - memcpy(dst, src, frames * pa.sinkStride); pa_stream_write(p, dst, frames * pa.sinkStride, NULL, 0, PA_SEEK_RELATIVE); } diff --git a/client/include/interface/audiodev.h b/client/include/interface/audiodev.h index 5acc7796..92952f77 100644 --- a/client/include/interface/audiodev.h +++ b/client/include/interface/audiodev.h @@ -25,8 +25,8 @@ #include #include -typedef int (*LG_AudioPullFn)(uint8_t ** data, int frames); -typedef void (*LG_AudioPushFn)(uint8_t * data, int frames); +typedef int (*LG_AudioPullFn)(uint8_t * dst, int frames); +typedef void (*LG_AudioPushFn)(uint8_t * src, int frames); struct LG_AudioDevOps { diff --git a/client/src/audio.c b/client/src/audio.c index 03314bfa..89eb390a 100644 --- a/client/src/audio.c +++ b/client/src/audio.c @@ -131,10 +131,21 @@ void playbackStopNL(void) } } -static int playbackPullFrames(uint8_t ** data, int frames) +static int playbackPullFrames(uint8_t * dst, int frames) { if (audio.playback.buffer) - *data = ringbuffer_consume(audio.playback.buffer, &frames); + { + frames = min(frames, ringbuffer_getCount(audio.playback.buffer)); + for(int fetched = 0; fetched < frames; ) + { + int copy = frames - fetched; + uint8_t * src = ringbuffer_consume(audio.playback.buffer, ©); + + memcpy(dst, src, copy * audio.playback.stride); + dst += copy * audio.playback.stride; + fetched += copy; + } + } else frames = 0;