[Spice-devel] [PATCH spice 06/10] server/snd_worker: support SpiceDataHeaderNoSub for sound channel

Yonit Halperin yhalperi at redhat.com
Wed Dec 28 09:15:15 PST 2011


Sound channels need special support since they still don't use
red_channel for sending & receiving.
---
 server/red_channel.c |    8 ++++++++
 server/snd_worker.c  |   36 +++++++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/server/red_channel.c b/server/red_channel.c
index 7772355..43262ae 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -582,6 +582,7 @@ RedChannel *red_channel_create_dummy(int size, uint32_t type, uint32_t id)
     client_cbs.migrate = red_channel_client_default_migrate;
 
     red_channel_register_client_cbs(channel, &client_cbs);
+    red_channel_set_common_cap(channel, SPICE_COMMON_CAP_HEADER_NO_SUB);
 
     channel->thread_id = pthread_self();
 
@@ -1116,6 +1117,13 @@ RedChannelClient *red_channel_client_create_dummy(int size,
     rcc->client = client;
     rcc->channel = channel;
     red_channel_client_set_remote_caps(rcc, num_common_caps, common_caps, num_caps, caps);
+    if (red_channel_client_test_remote_common_cap(rcc, SPICE_COMMON_CAP_HEADER_NO_SUB)) {
+        rcc->header_size = sizeof(SpiceDataHeaderNoSub);
+        rcc->is_header_with_sub = FALSE;
+    } else {
+        rcc->header_size = sizeof(SpiceDataHeader);
+        rcc->is_header_with_sub = TRUE;
+    }
     red_channel_add_client(channel, rcc);
     return rcc;
 }
diff --git a/server/snd_worker.c b/server/snd_worker.c
index 048da34..8fc8c22 100644
--- a/server/snd_worker.c
+++ b/server/snd_worker.c
@@ -417,6 +417,8 @@ static int snd_record_handle_message(SndChannel *channel, size_t size, uint32_t
 static void snd_receive(void* data)
 {
     SndChannel *channel = (SndChannel*)data;
+    uint32_t header_size = channel->channel_client->header_size;
+
     if (!channel) {
         return;
     }
@@ -449,13 +451,13 @@ static void snd_receive(void* data)
             channel->recive_data.now += n;
             for (;;) {
                 SpiceDataHeader *header = channel->recive_data.message;
-                uint8_t *data = (uint8_t *)(header+1);
+                uint8_t *data = (uint8_t *)header + header_size;
                 size_t parsed_size;
                 uint8_t *parsed;
                 message_destructor_t parsed_free;
 
                 n = channel->recive_data.now - (uint8_t *)header;
-                if (n < sizeof(SpiceDataHeader) || n < sizeof(SpiceDataHeader) + header->size) {
+                if (n < header_size || n < header_size + header->size) {
                     break;
                 }
                 parsed = channel->parser((void *)data, data + header->size, header->type,
@@ -472,7 +474,7 @@ static void snd_receive(void* data)
                 }
                 parsed_free(parsed);
                 channel->recive_data.message = (SpiceDataHeader *)((uint8_t *)header +
-                                                                 sizeof(SpiceDataHeader) +
+                                                                 header_size +
                                                                  header->size);
             }
             if (channel->recive_data.now == (uint8_t *)channel->recive_data.message) {
@@ -507,13 +509,18 @@ static inline int snd_reset_send_data(SndChannel *channel, uint16_t verb)
 
     spice_marshaller_reset(channel->send_data.marshaller);
     channel->send_data.header = (SpiceDataHeader *)
-        spice_marshaller_reserve_space(channel->send_data.marshaller, sizeof(SpiceDataHeader));
-    spice_marshaller_set_base(channel->send_data.marshaller, sizeof(SpiceDataHeader));
+        spice_marshaller_reserve_space(channel->send_data.marshaller,
+                                       channel->channel_client->header_size);
+    spice_marshaller_set_base(channel->send_data.marshaller,
+                              channel->channel_client->header_size);
     channel->send_data.pos = 0;
-    channel->send_data.header->sub_list = 0;
     channel->send_data.header->size = 0;
     channel->send_data.header->type = verb;
     channel->send_data.header->serial = ++channel->send_data.serial;
+    if (channel->channel_client->is_header_with_sub) {
+        channel->send_data.header->sub_list = 0;
+    }
+
     return TRUE;
 }
 
@@ -521,7 +528,8 @@ static int snd_begin_send_message(SndChannel *channel)
 {
     spice_marshaller_flush(channel->send_data.marshaller);
     channel->send_data.size = spice_marshaller_get_total_size(channel->send_data.marshaller);
-    channel->send_data.header->size = channel->send_data.size - sizeof(SpiceDataHeader);
+    channel->send_data.header->size = channel->send_data.size -
+        channel->channel_client->header_size;
     channel->send_data.header = NULL; /* avoid writing to this until we have a new message */
     return snd_send_data(channel);
 }
@@ -711,6 +719,7 @@ static int snd_record_send_migrate(RecordChannel *record_channel)
     SpiceMsgMigrate migrate;
     SpiceDataHeader *header;
     RecordMigrateData *data;
+    uint32_t header_size = channel->channel_client->header_size;
 
     if (!snd_reset_send_data(channel, SPICE_MSG_MIGRATE)) {
         return FALSE;
@@ -720,11 +729,13 @@ static int snd_record_send_migrate(RecordChannel *record_channel)
     spice_marshall_msg_migrate(channel->send_data.marshaller, &migrate);
 
     header = (SpiceDataHeader *)spice_marshaller_reserve_space(channel->send_data.marshaller,
-                                                               sizeof(SpiceDataHeader));
+                                                               header_size);
     header->type = SPICE_MSG_MIGRATE_DATA;
     header->size = sizeof(RecordMigrateData);
     header->serial = ++channel->send_data.serial;
-    header->sub_list = 0;
+    if (channel->channel_client->is_header_with_sub) {
+        header->sub_list = 0;
+    }
 
     data = (RecordMigrateData *)spice_marshaller_reserve_space(channel->send_data.marshaller,
                                                                sizeof(RecordMigrateData));
@@ -735,7 +746,7 @@ static int snd_record_send_migrate(RecordChannel *record_channel)
     data->mode_time = record_channel->mode_time;
 
     channel->send_data.size = spice_marshaller_get_total_size(channel->send_data.marshaller);
-    channel->send_data.header->size = channel->send_data.size - sizeof(SpiceDataHeader) - sizeof(SpiceDataHeader) - sizeof(*data);
+    channel->send_data.header->size = channel->send_data.size - header_size - header_size - sizeof(*data);
 
     return snd_send_data(channel);
 }
@@ -876,6 +887,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
                                  snd_channel_handle_message_proc handle_message,
                                  snd_channel_on_message_done_proc on_message_done,
                                  snd_channel_cleanup_channel_proc cleanup,
+                                 uint32_t *common_caps, int num_common_caps,
                                  uint32_t *caps, int num_caps)
 {
     SndChannel *channel;
@@ -938,7 +950,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
     channel->channel_client = red_channel_client_create_dummy(sizeof(RedChannelClient),
                                                               worker->base_channel,
                                                               client,
-                                                              0, NULL,
+                                                              num_common_caps, common_caps,
                                                               num_caps, caps);
     return channel;
 
@@ -1159,6 +1171,7 @@ static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsSt
                                                               snd_playback_handle_message,
                                                               snd_playback_on_message_done,
                                                               snd_playback_cleanup,
+                                                              common_caps, num_common_caps,
                                                               caps, num_caps))) {
         goto error_2;
     }
@@ -1367,6 +1380,7 @@ static void snd_set_record_peer(RedChannel *channel, RedClient *client, RedsStre
                                                           snd_record_handle_message,
                                                           snd_record_on_message_done,
                                                           snd_record_cleanup,
+                                                          common_caps, num_common_caps,
                                                           caps, num_caps))) {
         goto error_2;
     }
-- 
1.7.6.4



More information about the Spice-devel mailing list