[Spice-devel,v3,13/17] sound: Reduce message buffer

Submitted by Frediano Ziglio on Nov. 29, 2016, 2:57 p.m.

Details

Message ID a756f207aa5354309bc3e741a6702c86b09e6eee.1480431431.git-series.fziglio@redhat.com
State Accepted
Headers show
Series "Remove DummyChannel* objects" ( rev: 4 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Nov. 29, 2016, 2:57 p.m.
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@redhat.com>
---
 server/sound.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/sound.c b/server/sound.c
index 4906122..bd8812b 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 ??