summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois Gouget <fgouget@codeweavers.com>2016-03-18 15:32:17 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2016-03-24 14:46:58 +0100
commit5f5b502ecdae7fb4e37e9285be9ee7a2107aff28 (patch)
tree4a242e9520262b88b801f096520013699d5c22e3
parent5671929aecb742e7aaee4f4caf5e00cff344769a (diff)
spiceqxl_audio: Only start the playback channel when fifos are present
This lets the client free the audio resources when they are not needed. This matches QEMU's behavior. As a side benefit it stops the client's mm-time from being stuck (due to the audio backend's delay updates being applied to the mm-time of the last audio message, that is the channel's creation) when no audio application is running. Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
-rw-r--r--src/spiceqxl_audio.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/spiceqxl_audio.c b/src/spiceqxl_audio.c
index 5fd76c8..8d187b7 100644
--- a/src/spiceqxl_audio.c
+++ b/src/spiceqxl_audio.c
@@ -63,6 +63,7 @@ struct fifo_data {
struct audio_data {
struct fifo_data fifos[MAX_FIFOS];
+ int active;
uint32_t *spice_buffer;
int spice_buffer_bytes;
int period_bytes;
@@ -247,7 +248,6 @@ static int process_fifos(qxl_screen_t *qxl, struct audio_data *data, int maxlen)
return TRUE;
}
-
/* a helper for read_from_fifos() */
static void condense_fifos(qxl_screen_t *qxl)
{
@@ -278,6 +278,12 @@ static void read_from_fifos(int fd, int event, void *opaque)
struct audio_data *data = qxl->playback_opaque;
int i;
int maxlen = 0;
+
+ if (data->wall_timer_live) {
+ qxl->core->timer_cancel(data->wall_timer);
+ data->wall_timer_live = 0;
+ }
+
for (i = 0; i < data->fifo_count; i++) {
struct fifo_data *f = &data->fifos[i];
@@ -319,17 +325,24 @@ static void read_from_fifos(int fd, int event, void *opaque)
condense_fifos(qxl);
}
+ if (maxlen && !data->active) {
+ spice_server_playback_start(&qxl->playback_sin);
+ data->active = 1;
+ }
+
if (!process_fifos(qxl, data, maxlen)) {
- if (! data->wall_timer_live) {
- qxl->core->timer_start(data->wall_timer, PERIOD_MS);
- data->wall_timer_live = 1;
- }
- } else {
+ /* There is still some fifo data to process */
+ qxl->core->timer_start(data->wall_timer, PERIOD_MS);
+ data->wall_timer_live = 1;
+
+ } else if (data->fifo_count) {
+ /* All the fifo data was processed. Wait for more */
start_watching(qxl);
- if (data->wall_timer_live) {
- qxl->core->timer_cancel(data->wall_timer);
- }
- data->wall_timer_live = 0;
+
+ } else if (data->active) {
+ /* There is no open fifo anymore */
+ spice_server_playback_stop(&qxl->playback_sin);
+ data->active = 0;
}
}
@@ -459,8 +472,6 @@ static void audio_initialize (qxl_screen_t *qxl)
data->fifos[i].size = data->period_bytes * READ_BUFFER_PERIODS;
data->fifos[i].buffer = calloc(1, data->fifos[i].size);
}
-
- spice_server_playback_start(&qxl->playback_sin);
}