[client] audio: move the memory copy into the pull function

This commit is contained in:
Geoffrey McRae 2022-01-19 10:29:49 +11:00
parent 99536eaf9d
commit 15f76339c8
4 changed files with 18 additions and 11 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -25,8 +25,8 @@
#include <stdint.h>
#include <stddef.h>
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
{

View file

@ -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, &copy);
memcpy(dst, src, copy * audio.playback.stride);
dst += copy * audio.playback.stride;
fetched += copy;
}
}
else
frames = 0;