[Spice-devel] [Xspice 2/2] spiceqxl_audio: Let the audio play when no client is connected
Francois Gouget
fgouget at codeweavers.com
Mon Mar 14 18:10:49 UTC 2016
Simply keep reading from the fifos in reasonably sized chunks.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
src/spiceqxl_audio.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/src/spiceqxl_audio.c b/src/spiceqxl_audio.c
index 1aebe8d..080a6f9 100644
--- a/src/spiceqxl_audio.c
+++ b/src/spiceqxl_audio.c
@@ -108,14 +108,18 @@ static inline void fifo_remove_data(struct fifo_data *f, unsigned char *dest, in
int remain = f->size - remove_from;
if (remain < len) {
- memcpy(dest, f->buffer + remove_from, remain);
- dest += remain;
+ if (dest) {
+ memcpy(dest, f->buffer + remove_from, remain);
+ dest += remain;
+ }
len -= remain;
f->len -= remain;
remove_from = 0;
}
- memcpy(dest, f->buffer + remove_from, len);
+ if (dest) {
+ memcpy(dest, f->buffer + remove_from, len);
+ }
f->len -= len;
}
@@ -153,7 +157,9 @@ static void mix_in_fifos(qxl_screen_t *qxl)
struct audio_data *data = qxl->playback_opaque;
struct fifo_data *f;
- memset(data->spice_buffer, 0, data->spice_buffer_bytes);
+ if (data->spice_buffer) {
+ memset(data->spice_buffer, 0, data->spice_buffer_bytes);
+ }
if (data->fifo_count == 0)
return;
@@ -165,8 +171,13 @@ static void mix_in_fifos(qxl_screen_t *qxl)
/* Extra fifos need to be mixed in */
for (i = 1; i < data->fifo_count; i++) {
f = &data->fifos[i];
- if (f->len > 0)
- mix_in_one_fifo(f, (int16_t *) data->spice_buffer, data->spice_buffer_bytes);
+ if (f->len > 0) {
+ if (data->spice_buffer) {
+ mix_in_one_fifo(f, (int16_t *) data->spice_buffer, data->spice_buffer_bytes);
+ } else {
+ fifo_remove_data(f, NULL, min(data->spice_buffer_bytes, f->len));
+ }
+ }
}
}
@@ -233,12 +244,11 @@ static void process_fifos(qxl_screen_t *qxl, struct audio_data *data, int maxlen
if (! data->spice_buffer) {
uint32_t chunk_frames;
spice_server_playback_get_buffer(&qxl->playback_sin, &data->spice_buffer, &chunk_frames);
- data->spice_buffer_bytes = chunk_frames * sizeof(int16_t) * SPICE_INTERFACE_PLAYBACK_CHAN;
+ data->spice_buffer_bytes = data->spice_buffer ?
+ chunk_frames * sizeof(int16_t) * SPICE_INTERFACE_PLAYBACK_CHAN :
+ data->period_bytes * READ_BUFFER_PERIODS;
}
- if (! data->spice_buffer)
- break;
-
if (! can_feed(data)) {
if (! data->wall_timer_live) {
qxl->core->timer_start(data->wall_timer, PERIOD_MS);
@@ -252,8 +262,10 @@ static void process_fifos(qxl_screen_t *qxl, struct audio_data *data, int maxlen
did_feed(data, data->spice_buffer_bytes);
maxlen -= data->spice_buffer_bytes;
- spice_server_playback_put_samples(&qxl->playback_sin, data->spice_buffer);
- data->spice_buffer = NULL;
+ if (data->spice_buffer) {
+ spice_server_playback_put_samples(&qxl->playback_sin, data->spice_buffer);
+ data->spice_buffer = NULL;
+ }
}
start_watching(qxl);
--
2.7.0
More information about the Spice-devel
mailing list