[Spice-devel] [PATCH v4 10/14] sound: Reduce message buffer

Frediano Ziglio fziglio at redhat.com
Thu Dec 1 11:23:50 UTC 2016


Sound messages are not that big.
This limit RecordChannelClient to 64K so the entire
structure can be a GObject (which are currently limited
to 64K).

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/sound.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/server/sound.c b/server/sound.c
index 00eab67..0606fa0 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -98,7 +98,9 @@ struct SndChannelClient {
 
     uint32_t command;
 
-    uint8_t receive_buf[SND_RECEIVE_BUF_SIZE];
+    /* we don't expect very big messages so don't allocate too much
+     * bytes, data will be cached in RecordChannelClient::samples */
+    uint8_t receive_buf[SND_CODEC_MAX_FRAME_BYTES + 64];
     RedPipeItem persistent_pipe_item;
 
     snd_channel_on_message_done_proc on_message_done;
@@ -785,8 +787,10 @@ static uint8_t*
 snd_channel_client_alloc_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size)
 {
     SndChannelClient *client = SND_CHANNEL_CLIENT(rcc);
-    // TODO isn't too much the buffer ?? return NULL ??
-    spice_assert(size < sizeof(client->receive_buf));
+    // If message is to big allocate one, this should never happen
+    if (size > sizeof(client->receive_buf)) {
+        return spice_malloc(size);
+    }
     return client->receive_buf;
 }
 
@@ -794,6 +798,10 @@ static void
 snd_channel_client_release_recv_buf(RedChannelClient *rcc, uint16_t type, uint32_t size,
                                     uint8_t *msg)
 {
+    SndChannelClient *client = SND_CHANNEL_CLIENT(rcc);
+    if (msg != client->receive_buf) {
+        free(msg);
+    }
 }
 
 // TODO remove and just use red_channel_client_disconnect ??
-- 
git-series 0.9.1


More information about the Spice-devel mailing list