[gtk-vnc] Batch up incoming audio samples for upto 100ms
- From: Daniel P. Berrange <dberrange src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-vnc] Batch up incoming audio samples for upto 100ms
- Date: Fri, 9 Dec 2011 17:41:54 +0000 (UTC)
commit 4e1598416527e85bf4b7eae33aaebf2f4e7964f8
Author: Daniel P. Berrange <berrange redhat com>
Date: Fri Dec 9 16:27:14 2011 +0000
Batch up incoming audio samples for upto 100ms
The length of samples received from the guest can be very
small (as little as 1 sample). If this is dispatched directly
to the audio sink this can cause excessive CPU consumption
and context switching. Batch up incoming data for upto 100ms
until dispatching it
src/vncconnection.c | 46 +++++++++++++++++++++++++++++++++++++++-------
1 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index aea507e..ebfcc27 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -2857,6 +2857,26 @@ static gboolean vnc_connection_framebuffer_update(VncConnection *conn, gint32 et
}
+static gboolean vnc_connection_audio_timer(gpointer opaque)
+{
+ VncConnection *conn = opaque;
+ VncConnectionPrivate *priv = conn->priv;
+
+ priv->audio_timer = 0;
+ if (!priv->audio_sample)
+ return FALSE;
+
+ VNC_DEBUG("Audio tick %u\n", priv->audio_sample->length);
+
+ if (priv->audio)
+ vnc_audio_playback_data(priv->audio, priv->audio_sample);
+
+ vnc_audio_sample_free(priv->audio_sample);
+ priv->audio_sample = NULL;
+ return FALSE;
+}
+
+
struct audio_action_data
{
VncConnection *conn;
@@ -3046,16 +3066,28 @@ static gboolean vnc_connection_server_message(VncConnection *conn)
priv->has_error = TRUE;
break;
}
- priv->audio_sample = vnc_audio_sample_new(n_length);
+ if (priv->audio_sample &&
+ ((priv->audio_sample->capacity - priv->audio_sample->length) < n_length)) {
+ g_source_remove(priv->audio_timer);
+ fprintf(stderr, "%u %u %u\n",
+ priv->audio_sample->capacity,
+ priv->audio_sample->length,
+ n_length);
+ vnc_connection_audio_action(conn, 2);
+ vnc_audio_sample_free(priv->audio_sample);
+ priv->audio_sample = NULL;
+ }
+ if (!priv->audio_sample) {
+ priv->audio_sample = vnc_audio_sample_new(1024*1024);
+ priv->audio_timer = g_timeout_add(50,
+ vnc_connection_audio_timer,
+ conn);
+ }
+
vnc_connection_read(conn,
- priv->audio_sample->data,
+ priv->audio_sample->data + priv->audio_sample->length,
n_length);
priv->audio_sample->length += n_length;
-
- vnc_connection_audio_action(conn, 2);
-
- vnc_audio_sample_free(priv->audio_sample);
- priv->audio_sample = NULL;
break;
case 1:
if (priv->audio)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]