[Spice-commits] 2 commits - server/sound.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Thu Dec 1 16:26:45 UTC 2016


 server/sound.c |  892 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 446 insertions(+), 446 deletions(-)

New commits:
commit 4867b9e76a358384c136eb1b54a34a5afe30118a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Wed Nov 23 11:27:19 2016 +0000

    sound: Rename {Record,Playback}Channel to *ChannelClient
    
    Make easier to understand that they refer to client and not
    all channel.
    
    Specifically:
    - RecordChannel -> RecordChannelClient
    - PlaybackChannel -> PlaybackChannelClient
    - playback_channel -> playback_client
    - record_channel -> record_client
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/sound.c b/server/sound.c
index 2d6b40f..1ac3505 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -116,17 +116,17 @@ struct SndChannelClient {
     snd_channel_cleanup_channel_proc cleanup;
 };
 
-typedef struct PlaybackChannel PlaybackChannel;
+typedef struct PlaybackChannelClient PlaybackChannelClient;
 
 typedef struct AudioFrame AudioFrame;
 struct AudioFrame {
     uint32_t time;
     uint32_t samples[SND_CODEC_MAX_FRAME_SIZE];
-    PlaybackChannel *channel;
+    PlaybackChannelClient *client;
     AudioFrame *next;
 };
 
-struct PlaybackChannel {
+struct PlaybackChannelClient {
     SndChannelClient base;
     AudioFrame frames[3];
     AudioFrame *free_frames;
@@ -163,7 +163,7 @@ struct SpiceRecordState {
     struct SndWorker worker;
 };
 
-typedef struct RecordChannel {
+typedef struct RecordChannelClient {
     SndChannelClient base;
     uint32_t samples[RECORD_SAMPLES_SIZE];
     uint32_t write_pos;
@@ -173,7 +173,7 @@ typedef struct RecordChannel {
     uint32_t start_time;
     SndCodec codec;
     uint8_t  decode_buf[SND_CODEC_MAX_FRAME_BYTES];
-} RecordChannel;
+} RecordChannelClient;
 
 /* A list of all Spice{Playback,Record}State objects */
 static SndWorker *workers;
@@ -233,20 +233,20 @@ static void snd_disconnect_channel(SndChannelClient *client)
     worker->connection = NULL;
 }
 
-static void snd_playback_free_frame(PlaybackChannel *playback_channel, AudioFrame *frame)
+static void snd_playback_free_frame(PlaybackChannelClient *playback_client, AudioFrame *frame)
 {
-    frame->channel = playback_channel;
-    frame->next = playback_channel->free_frames;
-    playback_channel->free_frames = frame;
+    frame->client = playback_client;
+    frame->next = playback_client->free_frames;
+    playback_client->free_frames = frame;
 }
 
 static void snd_playback_on_message_done(SndChannelClient *client)
 {
-    PlaybackChannel *playback_channel = (PlaybackChannel *)client;
-    if (playback_channel->in_progress) {
-        snd_playback_free_frame(playback_channel, playback_channel->in_progress);
-        playback_channel->in_progress = NULL;
-        if (playback_channel->pending_frame) {
+    PlaybackChannelClient *playback_client = (PlaybackChannelClient *)client;
+    if (playback_client->in_progress) {
+        snd_playback_free_frame(playback_client, playback_client->in_progress);
+        playback_client->in_progress = NULL;
+        if (playback_client->pending_frame) {
             client->command |= SND_PLAYBACK_PCM_MASK;
         }
     }
@@ -311,7 +311,7 @@ static int snd_send_data(SndChannelClient *client)
     return TRUE;
 }
 
-static int snd_record_handle_write(RecordChannel *record_channel, size_t size, void *message)
+static int snd_record_handle_write(RecordChannelClient *record_client, size_t size, void *message)
 {
     SpiceMsgcRecordPacket *packet;
     uint32_t write_pos;
@@ -319,39 +319,39 @@ static int snd_record_handle_write(RecordChannel *record_channel, size_t size, v
     uint32_t len;
     uint32_t now;
 
-    if (!record_channel) {
+    if (!record_client) {
         return FALSE;
     }
 
     packet = (SpiceMsgcRecordPacket *)message;
 
-    if (record_channel->mode == SPICE_AUDIO_DATA_MODE_RAW) {
+    if (record_client->mode == SPICE_AUDIO_DATA_MODE_RAW) {
         data = (uint32_t *)packet->data;
         size = packet->data_size >> 2;
         size = MIN(size, RECORD_SAMPLES_SIZE);
      } else {
         int decode_size;
-        decode_size = sizeof(record_channel->decode_buf);
-        if (snd_codec_decode(record_channel->codec, packet->data, packet->data_size,
-                    record_channel->decode_buf, &decode_size) != SND_CODEC_OK)
+        decode_size = sizeof(record_client->decode_buf);
+        if (snd_codec_decode(record_client->codec, packet->data, packet->data_size,
+                    record_client->decode_buf, &decode_size) != SND_CODEC_OK)
             return FALSE;
-        data = (uint32_t *) record_channel->decode_buf;
+        data = (uint32_t *) record_client->decode_buf;
         size = decode_size >> 2;
     }
 
-    write_pos = record_channel->write_pos % RECORD_SAMPLES_SIZE;
-    record_channel->write_pos += size;
+    write_pos = record_client->write_pos % RECORD_SAMPLES_SIZE;
+    record_client->write_pos += size;
     len = RECORD_SAMPLES_SIZE - write_pos;
     now = MIN(len, size);
     size -= now;
-    memcpy(record_channel->samples + write_pos, data, now << 2);
+    memcpy(record_client->samples + write_pos, data, now << 2);
 
     if (size) {
-        memcpy(record_channel->samples, data + now, size << 2);
+        memcpy(record_client->samples, data + now, size << 2);
     }
 
-    if (record_channel->write_pos - record_channel->read_pos > RECORD_SAMPLES_SIZE) {
-        record_channel->read_pos = record_channel->write_pos - RECORD_SAMPLES_SIZE;
+    if (record_client->write_pos - record_client->read_pos > RECORD_SAMPLES_SIZE) {
+        record_client->read_pos = record_client->write_pos - RECORD_SAMPLES_SIZE;
     }
     return TRUE;
 }
@@ -374,41 +374,41 @@ static int snd_playback_handle_message(SndChannelClient *client, size_t size, ui
 
 static int snd_record_handle_message(SndChannelClient *client, size_t size, uint32_t type, void *message)
 {
-    RecordChannel *record_channel = (RecordChannel *)client;
+    RecordChannelClient *record_client = (RecordChannelClient *)client;
 
     if (!client) {
         return FALSE;
     }
     switch (type) {
     case SPICE_MSGC_RECORD_DATA:
-        return snd_record_handle_write((RecordChannel *)client, size, message);
+        return snd_record_handle_write((RecordChannelClient *)client, size, message);
     case SPICE_MSGC_RECORD_MODE: {
         SpiceMsgcRecordMode *mode = (SpiceMsgcRecordMode *)message;
         SndWorker *worker = client->worker;
-        record_channel->mode_time = mode->time;
+        record_client->mode_time = mode->time;
         if (mode->mode != SPICE_AUDIO_DATA_MODE_RAW) {
             if (snd_codec_is_capable(mode->mode, worker->frequency)) {
-                if (snd_codec_create(&record_channel->codec, mode->mode, worker->frequency,
+                if (snd_codec_create(&record_client->codec, mode->mode, worker->frequency,
                                      SND_CODEC_DECODE) == SND_CODEC_OK) {
-                    record_channel->mode = mode->mode;
+                    record_client->mode = mode->mode;
                 } else {
                     spice_printerr("create decoder failed");
                     return FALSE;
                 }
             }
             else {
-                spice_printerr("unsupported mode %d", record_channel->mode);
+                spice_printerr("unsupported mode %d", record_client->mode);
                 return FALSE;
             }
         }
         else
-            record_channel->mode = mode->mode;
+            record_client->mode = mode->mode;
         break;
     }
 
     case SPICE_MSGC_RECORD_START_MARK: {
         SpiceMsgcRecordStartMark *mark = (SpiceMsgcRecordStartMark *)message;
-        record_channel->start_time = mark->time;
+        record_client->start_time = mark->time;
         break;
     }
     case SPICE_MSGC_DISCONNECTING:
@@ -562,9 +562,9 @@ static int snd_channel_send_migrate(SndChannelClient *client)
     return snd_begin_send_message(client);
 }
 
-static int snd_playback_send_migrate(PlaybackChannel *channel)
+static int snd_playback_send_migrate(PlaybackChannelClient *client)
 {
-    return snd_channel_send_migrate(&channel->base);
+    return snd_channel_send_migrate(&client->base);
 }
 
 static int snd_send_volume(SndChannelClient *client, uint32_t cap, int msg)
@@ -591,9 +591,9 @@ static int snd_send_volume(SndChannelClient *client, uint32_t cap, int msg)
     return snd_begin_send_message(client);
 }
 
-static int snd_playback_send_volume(PlaybackChannel *playback_channel)
+static int snd_playback_send_volume(PlaybackChannelClient *playback_client)
 {
-    return snd_send_volume(&playback_channel->base, SPICE_PLAYBACK_CAP_VOLUME,
+    return snd_send_volume(&playback_client->base, SPICE_PLAYBACK_CAP_VOLUME,
                            SPICE_MSG_PLAYBACK_VOLUME);
 }
 
@@ -615,29 +615,29 @@ static int snd_send_mute(SndChannelClient *client, uint32_t cap, int msg)
     return snd_begin_send_message(client);
 }
 
-static int snd_playback_send_mute(PlaybackChannel *playback_channel)
+static int snd_playback_send_mute(PlaybackChannelClient *playback_client)
 {
-    return snd_send_mute(&playback_channel->base, SPICE_PLAYBACK_CAP_VOLUME,
+    return snd_send_mute(&playback_client->base, SPICE_PLAYBACK_CAP_VOLUME,
                          SPICE_MSG_PLAYBACK_MUTE);
 }
 
-static int snd_playback_send_latency(PlaybackChannel *playback_channel)
+static int snd_playback_send_latency(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = &playback_channel->base;
+    SndChannelClient *client = &playback_client->base;
     SpiceMsgPlaybackLatency latency_msg;
 
-    spice_debug("latency %u", playback_channel->latency);
+    spice_debug("latency %u", playback_client->latency);
     if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_LATENCY)) {
         return FALSE;
     }
-    latency_msg.latency_ms = playback_channel->latency;
+    latency_msg.latency_ms = playback_client->latency;
     spice_marshall_msg_playback_latency(client->send_data.marshaller, &latency_msg);
 
     return snd_begin_send_message(client);
 }
-static int snd_playback_send_start(PlaybackChannel *playback_channel)
+static int snd_playback_send_start(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = (SndChannelClient *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_client;
     SpiceMsgPlaybackStart start;
 
     if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_START)) {
@@ -654,9 +654,9 @@ static int snd_playback_send_start(PlaybackChannel *playback_channel)
     return snd_begin_send_message(client);
 }
 
-static int snd_playback_send_stop(PlaybackChannel *playback_channel)
+static int snd_playback_send_stop(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = (SndChannelClient *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_client;
 
     if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_STOP)) {
         return FALSE;
@@ -665,20 +665,20 @@ static int snd_playback_send_stop(PlaybackChannel *playback_channel)
     return snd_begin_send_message(client);
 }
 
-static int snd_playback_send_ctl(PlaybackChannel *playback_channel)
+static int snd_playback_send_ctl(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = (SndChannelClient *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_client;
 
     if ((client->client_active = client->active)) {
-        return snd_playback_send_start(playback_channel);
+        return snd_playback_send_start(playback_client);
     } else {
-        return snd_playback_send_stop(playback_channel);
+        return snd_playback_send_stop(playback_client);
     }
 }
 
-static int snd_record_send_start(RecordChannel *record_channel)
+static int snd_record_send_start(RecordChannelClient *record_client)
 {
-    SndChannelClient *client = (SndChannelClient *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_client;
     SpiceMsgRecordStart start;
 
     if (!snd_reset_send_data(client, SPICE_MSG_RECORD_START)) {
@@ -694,9 +694,9 @@ static int snd_record_send_start(RecordChannel *record_channel)
     return snd_begin_send_message(client);
 }
 
-static int snd_record_send_stop(RecordChannel *record_channel)
+static int snd_record_send_stop(RecordChannelClient *record_client)
 {
-    SndChannelClient *client = (SndChannelClient *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_client;
 
     if (!snd_reset_send_data(client, SPICE_MSG_RECORD_STOP)) {
         return FALSE;
@@ -705,41 +705,41 @@ static int snd_record_send_stop(RecordChannel *record_channel)
     return snd_begin_send_message(client);
 }
 
-static int snd_record_send_ctl(RecordChannel *record_channel)
+static int snd_record_send_ctl(RecordChannelClient *record_client)
 {
-    SndChannelClient *client = (SndChannelClient *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_client;
 
     if ((client->client_active = client->active)) {
-        return snd_record_send_start(record_channel);
+        return snd_record_send_start(record_client);
     } else {
-        return snd_record_send_stop(record_channel);
+        return snd_record_send_stop(record_client);
     }
 }
 
-static int snd_record_send_volume(RecordChannel *record_channel)
+static int snd_record_send_volume(RecordChannelClient *record_client)
 {
-    return snd_send_volume(&record_channel->base, SPICE_RECORD_CAP_VOLUME,
+    return snd_send_volume(&record_client->base, SPICE_RECORD_CAP_VOLUME,
                            SPICE_MSG_RECORD_VOLUME);
 }
 
-static int snd_record_send_mute(RecordChannel *record_channel)
+static int snd_record_send_mute(RecordChannelClient *record_client)
 {
-    return snd_send_mute(&record_channel->base, SPICE_RECORD_CAP_VOLUME,
+    return snd_send_mute(&record_client->base, SPICE_RECORD_CAP_VOLUME,
                          SPICE_MSG_RECORD_MUTE);
 }
 
-static int snd_record_send_migrate(RecordChannel *record_channel)
+static int snd_record_send_migrate(RecordChannelClient *record_client)
 {
     /* No need for migration data: if recording has started before migration,
      * the client receives RECORD_STOP from the src before the migration completion
      * notification (when the vm is stopped).
      * Afterwards, when the vm starts on the dest, the client receives RECORD_START. */
-    return snd_channel_send_migrate(&record_channel->base);
+    return snd_channel_send_migrate(&record_client->base);
 }
 
-static int snd_playback_send_write(PlaybackChannel *playback_channel)
+static int snd_playback_send_write(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = (SndChannelClient *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_client;
     AudioFrame *frame;
     SpiceMsgPlaybackPacket msg;
 
@@ -747,41 +747,41 @@ static int snd_playback_send_write(PlaybackChannel *playback_channel)
         return FALSE;
     }
 
-    frame = playback_channel->in_progress;
+    frame = playback_client->in_progress;
     msg.time = frame->time;
 
     spice_marshall_msg_playback_data(client->send_data.marshaller, &msg);
 
-    if (playback_channel->mode == SPICE_AUDIO_DATA_MODE_RAW) {
+    if (playback_client->mode == SPICE_AUDIO_DATA_MODE_RAW) {
         spice_marshaller_add_ref(client->send_data.marshaller,
                                  (uint8_t *)frame->samples,
-                                 snd_codec_frame_size(playback_channel->codec) * sizeof(frame->samples[0]));
+                                 snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]));
     }
     else {
-        int n = sizeof(playback_channel->encode_buf);
-        if (snd_codec_encode(playback_channel->codec, (uint8_t *) frame->samples,
-                                    snd_codec_frame_size(playback_channel->codec) * sizeof(frame->samples[0]),
-                                    playback_channel->encode_buf, &n) != SND_CODEC_OK) {
+        int n = sizeof(playback_client->encode_buf);
+        if (snd_codec_encode(playback_client->codec, (uint8_t *) frame->samples,
+                                    snd_codec_frame_size(playback_client->codec) * sizeof(frame->samples[0]),
+                                    playback_client->encode_buf, &n) != SND_CODEC_OK) {
             spice_printerr("encode failed");
             snd_disconnect_channel(client);
             return FALSE;
         }
-        spice_marshaller_add_ref(client->send_data.marshaller, playback_channel->encode_buf, n);
+        spice_marshaller_add_ref(client->send_data.marshaller, playback_client->encode_buf, n);
     }
 
     return snd_begin_send_message(client);
 }
 
-static int playback_send_mode(PlaybackChannel *playback_channel)
+static int playback_send_mode(PlaybackChannelClient *playback_client)
 {
-    SndChannelClient *client = (SndChannelClient *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_client;
     SpiceMsgPlaybackMode mode;
 
     if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_MODE)) {
         return FALSE;
     }
     mode.time = reds_get_mm_time();
-    mode.mode = playback_channel->mode;
+    mode.mode = playback_client->mode;
     spice_marshall_msg_playback_mode(client->send_data.marshaller, &mode);
 
     return snd_begin_send_message(client);
@@ -789,51 +789,51 @@ static int playback_send_mode(PlaybackChannel *playback_channel)
 
 static void snd_playback_send(void* data)
 {
-    PlaybackChannel *playback_channel = (PlaybackChannel*)data;
-    SndChannelClient *client = (SndChannelClient*)playback_channel;
+    PlaybackChannelClient *playback_client = (PlaybackChannelClient*)data;
+    SndChannelClient *client = (SndChannelClient*)playback_client;
 
-    if (!playback_channel || !snd_send_data(data)) {
+    if (!playback_client || !snd_send_data(data)) {
         return;
     }
 
     while (client->command) {
         if (client->command & SND_PLAYBACK_MODE_MASK) {
-            if (!playback_send_mode(playback_channel)) {
+            if (!playback_send_mode(playback_client)) {
                 return;
             }
             client->command &= ~SND_PLAYBACK_MODE_MASK;
         }
         if (client->command & SND_PLAYBACK_PCM_MASK) {
-            spice_assert(!playback_channel->in_progress && playback_channel->pending_frame);
-            playback_channel->in_progress = playback_channel->pending_frame;
-            playback_channel->pending_frame = NULL;
+            spice_assert(!playback_client->in_progress && playback_client->pending_frame);
+            playback_client->in_progress = playback_client->pending_frame;
+            playback_client->pending_frame = NULL;
             client->command &= ~SND_PLAYBACK_PCM_MASK;
-            if (!snd_playback_send_write(playback_channel)) {
+            if (!snd_playback_send_write(playback_client)) {
                 spice_printerr("snd_send_playback_write failed");
                 return;
             }
         }
         if (client->command & SND_CTRL_MASK) {
-            if (!snd_playback_send_ctl(playback_channel)) {
+            if (!snd_playback_send_ctl(playback_client)) {
                 return;
             }
             client->command &= ~SND_CTRL_MASK;
         }
         if (client->command & SND_VOLUME_MASK) {
-            if (!snd_playback_send_volume(playback_channel) ||
-                !snd_playback_send_mute(playback_channel)) {
+            if (!snd_playback_send_volume(playback_client) ||
+                !snd_playback_send_mute(playback_client)) {
                 return;
             }
             client->command &= ~SND_VOLUME_MASK;
         }
         if (client->command & SND_MIGRATE_MASK) {
-            if (!snd_playback_send_migrate(playback_channel)) {
+            if (!snd_playback_send_migrate(playback_client)) {
                 return;
             }
             client->command &= ~SND_MIGRATE_MASK;
         }
         if (client->command & SND_PLAYBACK_LATENCY_MASK) {
-            if (!snd_playback_send_latency(playback_channel)) {
+            if (!snd_playback_send_latency(playback_client)) {
                 return;
             }
             client->command &= ~SND_PLAYBACK_LATENCY_MASK;
@@ -843,29 +843,29 @@ static void snd_playback_send(void* data)
 
 static void snd_record_send(void* data)
 {
-    RecordChannel *record_channel = (RecordChannel*)data;
-    SndChannelClient *client = (SndChannelClient*)record_channel;
+    RecordChannelClient *record_client = (RecordChannelClient*)data;
+    SndChannelClient *client = (SndChannelClient*)record_client;
 
-    if (!record_channel || !snd_send_data(data)) {
+    if (!record_client || !snd_send_data(data)) {
         return;
     }
 
     while (client->command) {
         if (client->command & SND_CTRL_MASK) {
-            if (!snd_record_send_ctl(record_channel)) {
+            if (!snd_record_send_ctl(record_client)) {
                 return;
             }
             client->command &= ~SND_CTRL_MASK;
         }
         if (client->command & SND_VOLUME_MASK) {
-            if (!snd_record_send_volume(record_channel) ||
-                !snd_record_send_mute(record_channel)) {
+            if (!snd_record_send_volume(record_client) ||
+                !snd_record_send_mute(record_client)) {
                 return;
             }
             client->command &= ~SND_VOLUME_MASK;
         }
         if (client->command & SND_MIGRATE_MASK) {
-            if (!snd_record_send_migrate(record_channel)) {
+            if (!snd_record_send_migrate(record_client)) {
                 return;
             }
             client->command &= ~SND_MIGRATE_MASK;
@@ -1000,7 +1000,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannelClient *client = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
+    PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
 
     st->volume_nchannels = nchannels;
     free(st->volume);
@@ -1009,21 +1009,21 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
     if (!client || nchannels == 0)
         return;
 
-    snd_playback_send_volume(playback_channel);
+    snd_playback_send_volume(playback_client);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *sin, uint8_t mute)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannelClient *client = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
+    PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
 
     st->mute = mute;
 
     if (!client)
         return;
 
-    snd_playback_send_mute(playback_channel);
+    snd_playback_send_mute(playback_client);
 }
 
 static void snd_playback_start(SndWorker *worker)
@@ -1052,26 +1052,26 @@ SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
 SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
 {
     SndChannelClient *client = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
+    PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
 
     sin->st->worker.active = 0;
     if (!client)
         return;
-    spice_assert(playback_channel->base.active);
+    spice_assert(playback_client->base.active);
     reds_enable_mm_time(snd_channel_get_server(client));
-    playback_channel->base.active = FALSE;
-    if (playback_channel->base.client_active) {
-        snd_set_command(&playback_channel->base, SND_CTRL_MASK);
-        snd_playback_send(&playback_channel->base);
+    playback_client->base.active = FALSE;
+    if (playback_client->base.client_active) {
+        snd_set_command(&playback_client->base, SND_CTRL_MASK);
+        snd_playback_send(&playback_client->base);
     } else {
-        playback_channel->base.command &= ~SND_CTRL_MASK;
-        playback_channel->base.command &= ~SND_PLAYBACK_PCM_MASK;
-
-        if (playback_channel->pending_frame) {
-            spice_assert(!playback_channel->in_progress);
-            snd_playback_free_frame(playback_channel,
-                                    playback_channel->pending_frame);
-            playback_channel->pending_frame = NULL;
+        playback_client->base.command &= ~SND_CTRL_MASK;
+        playback_client->base.command &= ~SND_PLAYBACK_PCM_MASK;
+
+        if (playback_client->pending_frame) {
+            spice_assert(!playback_client->in_progress);
+            snd_playback_free_frame(playback_client,
+                                    playback_client->pending_frame);
+            playback_client->pending_frame = NULL;
         }
     }
 }
@@ -1080,44 +1080,44 @@ SPICE_GNUC_VISIBLE void spice_server_playback_get_buffer(SpicePlaybackInstance *
                                                          uint32_t **frame, uint32_t *num_samples)
 {
     SndChannelClient *client = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
+    PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
 
-    if (!client || !playback_channel->free_frames) {
+    if (!client || !playback_client->free_frames) {
         *frame = NULL;
         *num_samples = 0;
         return;
     }
-    spice_assert(playback_channel->base.active);
+    spice_assert(playback_client->base.active);
     snd_channel_ref(client);
 
-    *frame = playback_channel->free_frames->samples;
-    playback_channel->free_frames = playback_channel->free_frames->next;
-    *num_samples = snd_codec_frame_size(playback_channel->codec);
+    *frame = playback_client->free_frames->samples;
+    playback_client->free_frames = playback_client->free_frames->next;
+    *num_samples = snd_codec_frame_size(playback_client->codec);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_playback_put_samples(SpicePlaybackInstance *sin, uint32_t *samples)
 {
-    PlaybackChannel *playback_channel;
+    PlaybackChannelClient *playback_client;
     AudioFrame *frame;
 
     frame = SPICE_CONTAINEROF(samples, AudioFrame, samples[0]);
-    playback_channel = frame->channel;
-    spice_assert(playback_channel);
-    if (!snd_channel_unref(&playback_channel->base) ||
-        sin->st->worker.connection != &playback_channel->base) {
+    playback_client = frame->client;
+    spice_assert(playback_client);
+    if (!snd_channel_unref(&playback_client->base) ||
+        sin->st->worker.connection != &playback_client->base) {
         /* lost last reference, client has been destroyed previously */
         spice_info("audio samples belong to a disconnected client");
         return;
     }
-    spice_assert(playback_channel->base.active);
+    spice_assert(playback_client->base.active);
 
-    if (playback_channel->pending_frame) {
-        snd_playback_free_frame(playback_channel, playback_channel->pending_frame);
+    if (playback_client->pending_frame) {
+        snd_playback_free_frame(playback_client, playback_client->pending_frame);
     }
     frame->time = reds_get_mm_time();
-    playback_channel->pending_frame = frame;
-    snd_set_command(&playback_channel->base, SND_PLAYBACK_PCM_MASK);
-    snd_playback_send(&playback_channel->base);
+    playback_client->pending_frame = frame;
+    snd_set_command(&playback_client->base, SND_PLAYBACK_PCM_MASK);
+    snd_playback_send(&playback_client->base);
 }
 
 void snd_set_playback_latency(RedClient *client, uint32_t latency)
@@ -1132,7 +1132,7 @@ void snd_set_playback_latency(RedClient *client, uint32_t latency)
 
             if (red_channel_client_test_remote_cap(now->connection->channel_client,
                 SPICE_PLAYBACK_CAP_LATENCY)) {
-                PlaybackChannel* playback = (PlaybackChannel*)now->connection;
+                PlaybackChannelClient* playback = (PlaybackChannelClient*)now->connection;
 
                 playback->latency = latency;
                 snd_set_command(now->connection, SND_PLAYBACK_LATENCY_MASK);
@@ -1180,13 +1180,13 @@ static void on_new_playback_channel(SndWorker *worker, SndChannelClient *snd_cha
 
 static void snd_playback_cleanup(SndChannelClient *client)
 {
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
+    PlaybackChannelClient *playback_client = SPICE_CONTAINEROF(client, PlaybackChannelClient, base);
 
-    if (playback_channel->base.active) {
+    if (playback_client->base.active) {
         reds_enable_mm_time(snd_channel_get_server(client));
     }
 
-    snd_codec_destroy(&playback_channel->codec);
+    snd_codec_destroy(&playback_client->codec);
 }
 
 static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
@@ -1194,48 +1194,48 @@ static void snd_set_playback_peer(RedChannel *channel, RedClient *client, RedsSt
                                   int num_caps, uint32_t *caps)
 {
     SndWorker *worker = g_object_get_data(G_OBJECT(channel), "sound-worker");
-    PlaybackChannel *playback_channel;
+    PlaybackChannelClient *playback_client;
 
     snd_disconnect_channel(worker->connection);
 
-    if (!(playback_channel = (PlaybackChannel *)__new_channel(worker,
-                                                              sizeof(*playback_channel),
-                                                              SPICE_CHANNEL_PLAYBACK,
-                                                              client,
-                                                              stream,
-                                                              migration,
-                                                              snd_playback_send,
-                                                              snd_playback_handle_message,
-                                                              snd_playback_on_message_done,
-                                                              snd_playback_cleanup,
-                                                              common_caps, num_common_caps,
-                                                              caps, num_caps))) {
+    if (!(playback_client = (PlaybackChannelClient *)__new_channel(worker,
+                                                                   sizeof(*playback_client),
+                                                                   SPICE_CHANNEL_PLAYBACK,
+                                                                   client,
+                                                                   stream,
+                                                                   migration,
+                                                                   snd_playback_send,
+                                                                   snd_playback_handle_message,
+                                                                   snd_playback_on_message_done,
+                                                                   snd_playback_cleanup,
+                                                                   common_caps, num_common_caps,
+                                                                   caps, num_caps))) {
         return;
     }
-    snd_playback_free_frame(playback_channel, &playback_channel->frames[0]);
-    snd_playback_free_frame(playback_channel, &playback_channel->frames[1]);
-    snd_playback_free_frame(playback_channel, &playback_channel->frames[2]);
+    snd_playback_free_frame(playback_client, &playback_client->frames[0]);
+    snd_playback_free_frame(playback_client, &playback_client->frames[1]);
+    snd_playback_free_frame(playback_client, &playback_client->frames[2]);
 
-    int client_can_celt = red_channel_client_test_remote_cap(playback_channel->base.channel_client,
+    int client_can_celt = red_channel_client_test_remote_cap(playback_client->base.channel_client,
                                           SPICE_PLAYBACK_CAP_CELT_0_5_1);
-    int client_can_opus = red_channel_client_test_remote_cap(playback_channel->base.channel_client,
+    int client_can_opus = red_channel_client_test_remote_cap(playback_client->base.channel_client,
                                           SPICE_PLAYBACK_CAP_OPUS);
     int playback_compression =
         reds_config_get_playback_compression(red_channel_get_server(channel));
     int desired_mode = snd_desired_audio_mode(playback_compression, worker->frequency,
                                               client_can_celt, client_can_opus);
-    playback_channel->mode = SPICE_AUDIO_DATA_MODE_RAW;
+    playback_client->mode = SPICE_AUDIO_DATA_MODE_RAW;
     if (desired_mode != SPICE_AUDIO_DATA_MODE_RAW) {
-        if (snd_codec_create(&playback_channel->codec, desired_mode, worker->frequency,
+        if (snd_codec_create(&playback_client->codec, desired_mode, worker->frequency,
                              SND_CODEC_ENCODE) == SND_CODEC_OK) {
-            playback_channel->mode = desired_mode;
+            playback_client->mode = desired_mode;
         } else {
             spice_printerr("create encoder failed");
         }
     }
 
     if (!red_client_during_migrate_at_target(client)) {
-        on_new_playback_channel(worker, &playback_channel->base);
+        on_new_playback_channel(worker, &playback_client->base);
     }
 
     if (worker->active) {
@@ -1267,7 +1267,7 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannelClient *client = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
 
     st->volume_nchannels = nchannels;
     free(st->volume);
@@ -1276,34 +1276,34 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
     if (!client || nchannels == 0)
         return;
 
-    snd_record_send_volume(record_channel);
+    snd_record_send_volume(record_client);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, uint8_t mute)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannelClient *client = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
 
     st->mute = mute;
 
     if (!client)
         return;
 
-    snd_record_send_mute(record_channel);
+    snd_record_send_mute(record_client);
 }
 
 static void snd_record_start(SndWorker *worker)
 {
     SndChannelClient *client = worker->connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
 
     worker->active = 1;
     if (!client)
         return;
     spice_assert(!client->active);
-    record_channel->read_pos = record_channel->write_pos = 0;   //todo: improve by
-                                                                //stream generation
+    record_client->read_pos = record_client->write_pos = 0;   //todo: improve by
+                                                              //stream generation
     client->active = TRUE;
     if (!client->client_active) {
         snd_set_command(client, SND_CTRL_MASK);
@@ -1321,18 +1321,18 @@ SPICE_GNUC_VISIBLE void spice_server_record_start(SpiceRecordInstance *sin)
 SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
 {
     SndChannelClient *client = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
 
     sin->st->worker.active = 0;
     if (!client)
         return;
-    spice_assert(record_channel->base.active);
-    record_channel->base.active = FALSE;
-    if (record_channel->base.client_active) {
-        snd_set_command(&record_channel->base, SND_CTRL_MASK);
-        snd_record_send(&record_channel->base);
+    spice_assert(record_client->base.active);
+    record_client->base.active = FALSE;
+    if (record_client->base.client_active) {
+        snd_set_command(&record_client->base, SND_CTRL_MASK);
+        snd_record_send(&record_client->base);
     } else {
-        record_channel->base.command &= ~SND_CTRL_MASK;
+        record_client->base.command &= ~SND_CTRL_MASK;
     }
 }
 
@@ -1340,36 +1340,36 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance
                                                             uint32_t *samples, uint32_t bufsize)
 {
     SndChannelClient *client = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
     uint32_t read_pos;
     uint32_t now;
     uint32_t len;
 
     if (!client)
         return 0;
-    spice_assert(record_channel->base.active);
+    spice_assert(record_client->base.active);
 
-    if (record_channel->write_pos < RECORD_SAMPLES_SIZE / 2) {
+    if (record_client->write_pos < RECORD_SAMPLES_SIZE / 2) {
         return 0;
     }
 
-    len = MIN(record_channel->write_pos - record_channel->read_pos, bufsize);
+    len = MIN(record_client->write_pos - record_client->read_pos, bufsize);
 
     if (len < bufsize) {
-        SndWorker *worker = record_channel->base.worker;
-        snd_receive(&record_channel->base);
+        SndWorker *worker = record_client->base.worker;
+        snd_receive(&record_client->base);
         if (!worker->connection) {
             return 0;
         }
-        len = MIN(record_channel->write_pos - record_channel->read_pos, bufsize);
+        len = MIN(record_client->write_pos - record_client->read_pos, bufsize);
     }
 
-    read_pos = record_channel->read_pos % RECORD_SAMPLES_SIZE;
-    record_channel->read_pos += len;
+    read_pos = record_client->read_pos % RECORD_SAMPLES_SIZE;
+    record_client->read_pos += len;
     now = MIN(len, RECORD_SAMPLES_SIZE - read_pos);
-    memcpy(samples, &record_channel->samples[read_pos], now * 4);
+    memcpy(samples, &record_client->samples[read_pos], now * 4);
     if (now < len) {
-        memcpy(samples + now, record_channel->samples, (len - now) * 4);
+        memcpy(samples + now, record_client->samples, (len - now) * 4);
     }
     return len;
 }
@@ -1431,8 +1431,8 @@ static void on_new_record_channel(SndWorker *worker, SndChannelClient *snd_chann
 
 static void snd_record_cleanup(SndChannelClient *client)
 {
-    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
-    snd_codec_destroy(&record_channel->codec);
+    RecordChannelClient *record_client = SPICE_CONTAINEROF(client, RecordChannelClient, base);
+    snd_codec_destroy(&record_client->codec);
 }
 
 static void snd_set_record_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
@@ -1440,28 +1440,28 @@ static void snd_set_record_peer(RedChannel *channel, RedClient *client, RedsStre
                                 int num_caps, uint32_t *caps)
 {
     SndWorker *worker = g_object_get_data(G_OBJECT(channel), "sound-worker");
-    RecordChannel *record_channel;
+    RecordChannelClient *record_client;
 
     snd_disconnect_channel(worker->connection);
 
-    if (!(record_channel = (RecordChannel *)__new_channel(worker,
-                                                          sizeof(*record_channel),
-                                                          SPICE_CHANNEL_RECORD,
-                                                          client,
-                                                          stream,
-                                                          migration,
-                                                          snd_record_send,
-                                                          snd_record_handle_message,
-                                                          snd_record_on_message_done,
-                                                          snd_record_cleanup,
-                                                          common_caps, num_common_caps,
-                                                          caps, num_caps))) {
+    if (!(record_client = (RecordChannelClient *)__new_channel(worker,
+                                                               sizeof(*record_client),
+                                                               SPICE_CHANNEL_RECORD,
+                                                               client,
+                                                               stream,
+                                                               migration,
+                                                               snd_record_send,
+                                                               snd_record_handle_message,
+                                                               snd_record_on_message_done,
+                                                               snd_record_cleanup,
+                                                               common_caps, num_common_caps,
+                                                               caps, num_caps))) {
         return;
     }
 
-    record_channel->mode = SPICE_AUDIO_DATA_MODE_RAW;
+    record_client->mode = SPICE_AUDIO_DATA_MODE_RAW;
 
-    on_new_record_channel(worker, &record_channel->base);
+    on_new_record_channel(worker, &record_client->base);
     if (worker->active) {
         snd_record_start(worker);
     }
@@ -1605,7 +1605,7 @@ void snd_set_playback_compression(int on)
         uint32_t type;
         g_object_get(now->base_channel, "channel-type", &type, NULL);
         if (type == SPICE_CHANNEL_PLAYBACK && now->connection) {
-            PlaybackChannel* playback = (PlaybackChannel*)now->connection;
+            PlaybackChannelClient* playback = (PlaybackChannelClient*)now->connection;
             int client_can_celt = red_channel_client_test_remote_cap(playback->base.channel_client,
                                     SPICE_PLAYBACK_CAP_CELT_0_5_1);
             int client_can_opus = red_channel_client_test_remote_cap(playback->base.channel_client,
commit 9ba847c2dace4c281eb46d43ed9dfc2fdfcb7e66
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue Nov 29 11:59:49 2016 +0000

    sound: Rename SndChannel to SndChannelClient
    
    SndWorker has been historically based on RedChannel, initial git commit
    has:
    struct SndWorker {
         Channel base;
         ...
    };
    
    SndChannel, contrary to what its name may imply is more focused on
    marshalling/sending of sound data, which is the responsibility of
    RedChannelClient for the other SPICE channels.
    
    This commit and following ones make the naming of these 2 types more
    consistent with how the rest of the code is structured.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/sound.c b/server/sound.c
index beab473..2d6b40f 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -73,16 +73,16 @@ enum PlaybackCommand {
 #define SND_PLAYBACK_PCM_MASK (1 << SND_PLAYBACK_PCM)
 #define SND_PLAYBACK_LATENCY_MASK ( 1 << SND_PLAYBACK_LATENCY)
 
-typedef struct SndChannel SndChannel;
+typedef struct SndChannelClient SndChannelClient;
 typedef void (*snd_channel_send_messages_proc)(void *in_channel);
-typedef int (*snd_channel_handle_message_proc)(SndChannel *channel, size_t size, uint32_t type, void *message);
-typedef void (*snd_channel_on_message_done_proc)(SndChannel *channel);
-typedef void (*snd_channel_cleanup_channel_proc)(SndChannel *channel);
+typedef int (*snd_channel_handle_message_proc)(SndChannelClient *client, size_t size, uint32_t type, void *message);
+typedef void (*snd_channel_on_message_done_proc)(SndChannelClient *client);
+typedef void (*snd_channel_cleanup_channel_proc)(SndChannelClient *client);
 
 typedef struct SndWorker SndWorker;
 
-/* Connects an audio channel to a Spice client */
-struct SndChannel {
+/* Connects an audio client to a Spice client */
+struct SndChannelClient {
     RedsStream *stream;
     SndWorker *worker;
     spice_parse_channel_func_t parser;
@@ -127,7 +127,7 @@ struct AudioFrame {
 };
 
 struct PlaybackChannel {
-    SndChannel base;
+    SndChannelClient base;
     AudioFrame frames[3];
     AudioFrame *free_frames;
     AudioFrame *in_progress;   /* Frame being sent to the client */
@@ -147,7 +147,7 @@ typedef struct SpiceVolumeState {
 /* Base class for SpicePlaybackState and SpiceRecordState */
 struct SndWorker {
     RedChannel *base_channel;
-    SndChannel *connection; /* Only one client is supported */
+    SndChannelClient *connection; /* Only one client is supported */
     SndWorker *next; /* For the global SndWorker list */
 
     int active;
@@ -164,7 +164,7 @@ struct SpiceRecordState {
 };
 
 typedef struct RecordChannel {
-    SndChannel base;
+    SndChannelClient base;
     uint32_t samples[RECORD_SAMPLES_SIZE];
     uint32_t write_pos;
     uint32_t read_pos;
@@ -178,58 +178,58 @@ typedef struct RecordChannel {
 /* A list of all Spice{Playback,Record}State objects */
 static SndWorker *workers;
 
-static void snd_receive(SndChannel *channel);
+static void snd_receive(SndChannelClient *client);
 static void snd_playback_start(SndWorker *worker);
 static void snd_record_start(SndWorker *worker);
 
-static SndChannel *snd_channel_ref(SndChannel *channel)
+static SndChannelClient *snd_channel_ref(SndChannelClient *client)
 {
-    channel->refs++;
-    return channel;
+    client->refs++;
+    return client;
 }
 
-static SndChannel *snd_channel_unref(SndChannel *channel)
+static SndChannelClient *snd_channel_unref(SndChannelClient *client)
 {
-    if (!--channel->refs) {
-        spice_printerr("SndChannel=%p freed", channel);
-        free(channel);
+    if (!--client->refs) {
+        spice_printerr("SndChannelClient=%p freed", client);
+        free(client);
         return NULL;
     }
-    return channel;
+    return client;
 }
 
-static RedsState* snd_channel_get_server(SndChannel *channel)
+static RedsState* snd_channel_get_server(SndChannelClient *client)
 {
-    g_return_val_if_fail(channel != NULL, NULL);
-    return red_channel_get_server(channel->worker->base_channel);
+    g_return_val_if_fail(client != NULL, NULL);
+    return red_channel_get_server(client->worker->base_channel);
 }
 
-static void snd_disconnect_channel(SndChannel *channel)
+static void snd_disconnect_channel(SndChannelClient *client)
 {
     SndWorker *worker;
     RedsState *reds;
     RedChannel *red_channel;
     uint32_t type;
 
-    if (!channel || !channel->stream) {
+    if (!client || !client->stream) {
         spice_debug("not connected");
         return;
     }
-    red_channel = red_channel_client_get_channel(channel->channel_client);
-    reds = snd_channel_get_server(channel);
+    red_channel = red_channel_client_get_channel(client->channel_client);
+    reds = snd_channel_get_server(client);
     g_object_get(red_channel, "channel-type", &type, NULL);
-    spice_debug("SndChannel=%p rcc=%p type=%d",
-                 channel, channel->channel_client, type);
-    worker = channel->worker;
-    channel->cleanup(channel);
+    spice_debug("SndChannelClient=%p rcc=%p type=%d",
+                 client, client->channel_client, type);
+    worker = client->worker;
+    client->cleanup(client);
     red_channel_client_disconnect(worker->connection->channel_client);
     worker->connection->channel_client = NULL;
-    reds_core_watch_remove(reds, channel->stream->watch);
-    channel->stream->watch = NULL;
-    reds_stream_free(channel->stream);
-    channel->stream = NULL;
-    spice_marshaller_destroy(channel->send_data.marshaller);
-    snd_channel_unref(channel);
+    reds_core_watch_remove(reds, client->stream->watch);
+    client->stream->watch = NULL;
+    reds_stream_free(client->stream);
+    client->stream = NULL;
+    spice_marshaller_destroy(client->send_data.marshaller);
+    snd_channel_unref(client);
     worker->connection = NULL;
 }
 
@@ -240,73 +240,73 @@ static void snd_playback_free_frame(PlaybackChannel *playback_channel, AudioFram
     playback_channel->free_frames = frame;
 }
 
-static void snd_playback_on_message_done(SndChannel *channel)
+static void snd_playback_on_message_done(SndChannelClient *client)
 {
-    PlaybackChannel *playback_channel = (PlaybackChannel *)channel;
+    PlaybackChannel *playback_channel = (PlaybackChannel *)client;
     if (playback_channel->in_progress) {
         snd_playback_free_frame(playback_channel, playback_channel->in_progress);
         playback_channel->in_progress = NULL;
         if (playback_channel->pending_frame) {
-            channel->command |= SND_PLAYBACK_PCM_MASK;
+            client->command |= SND_PLAYBACK_PCM_MASK;
         }
     }
 }
 
-static void snd_record_on_message_done(SndChannel *channel)
+static void snd_record_on_message_done(SndChannelClient *client)
 {
 }
 
-static int snd_send_data(SndChannel *channel)
+static int snd_send_data(SndChannelClient *client)
 {
     uint32_t n;
 
-    if (!channel) {
+    if (!client) {
         return FALSE;
     }
 
-    if (!(n = channel->send_data.size - channel->send_data.pos)) {
+    if (!(n = client->send_data.size - client->send_data.pos)) {
         return TRUE;
     }
 
-    RedsState *reds = snd_channel_get_server(channel);
+    RedsState *reds = snd_channel_get_server(client);
     for (;;) {
         struct iovec vec[IOV_MAX];
         int vec_size;
 
         if (!n) {
-            channel->on_message_done(channel);
+            client->on_message_done(client);
 
-            if (channel->blocked) {
-                channel->blocked = FALSE;
-                reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ);
+            if (client->blocked) {
+                client->blocked = FALSE;
+                reds_core_watch_update_mask(reds, client->stream->watch, SPICE_WATCH_EVENT_READ);
             }
             break;
         }
 
-        vec_size = spice_marshaller_fill_iovec(channel->send_data.marshaller,
-                                               vec, IOV_MAX, channel->send_data.pos);
-        n = reds_stream_writev(channel->stream, vec, vec_size);
+        vec_size = spice_marshaller_fill_iovec(client->send_data.marshaller,
+                                               vec, IOV_MAX, client->send_data.pos);
+        n = reds_stream_writev(client->stream, vec, vec_size);
         if (n == -1) {
             switch (errno) {
             case EAGAIN:
-                channel->blocked = TRUE;
-                reds_core_watch_update_mask(reds, channel->stream->watch, SPICE_WATCH_EVENT_READ |
+                client->blocked = TRUE;
+                reds_core_watch_update_mask(reds, client->stream->watch, SPICE_WATCH_EVENT_READ |
                                                                  SPICE_WATCH_EVENT_WRITE);
                 return FALSE;
             case EINTR:
                 break;
             case EPIPE:
-                snd_disconnect_channel(channel);
+                snd_disconnect_channel(client);
                 return FALSE;
             default:
                 spice_printerr("%s", strerror(errno));
-                snd_disconnect_channel(channel);
+                snd_disconnect_channel(client);
                 return FALSE;
             }
         } else {
-            channel->send_data.pos += n;
+            client->send_data.pos += n;
         }
-        n = channel->send_data.size - channel->send_data.pos;
+        n = client->send_data.size - client->send_data.pos;
     }
     return TRUE;
 }
@@ -356,9 +356,9 @@ static int snd_record_handle_write(RecordChannel *record_channel, size_t size, v
     return TRUE;
 }
 
-static int snd_playback_handle_message(SndChannel *channel, size_t size, uint32_t type, void *message)
+static int snd_playback_handle_message(SndChannelClient *client, size_t size, uint32_t type, void *message)
 {
-    if (!channel) {
+    if (!client) {
         return FALSE;
     }
 
@@ -372,19 +372,19 @@ static int snd_playback_handle_message(SndChannel *channel, size_t size, uint32_
     return TRUE;
 }
 
-static int snd_record_handle_message(SndChannel *channel, size_t size, uint32_t type, void *message)
+static int snd_record_handle_message(SndChannelClient *client, size_t size, uint32_t type, void *message)
 {
-    RecordChannel *record_channel = (RecordChannel *)channel;
+    RecordChannel *record_channel = (RecordChannel *)client;
 
-    if (!channel) {
+    if (!client) {
         return FALSE;
     }
     switch (type) {
     case SPICE_MSGC_RECORD_DATA:
-        return snd_record_handle_write((RecordChannel *)channel, size, message);
+        return snd_record_handle_write((RecordChannel *)client, size, message);
     case SPICE_MSGC_RECORD_MODE: {
         SpiceMsgcRecordMode *mode = (SpiceMsgcRecordMode *)message;
-        SndWorker *worker = channel->worker;
+        SndWorker *worker = client->worker;
         record_channel->mode_time = mode->time;
         if (mode->mode != SPICE_AUDIO_DATA_MODE_RAW) {
             if (snd_codec_is_capable(mode->mode, worker->frequency)) {
@@ -420,24 +420,24 @@ static int snd_record_handle_message(SndChannel *channel, size_t size, uint32_t
     return TRUE;
 }
 
-static void snd_receive(SndChannel *channel)
+static void snd_receive(SndChannelClient *client)
 {
     SpiceDataHeaderOpaque *header;
 
-    if (!channel) {
+    if (!client) {
         return;
     }
 
-    header = &channel->channel_client->incoming.header;
+    header = &client->channel_client->incoming.header;
 
     for (;;) {
         ssize_t n;
-        n = channel->receive_data.end - channel->receive_data.now;
+        n = client->receive_data.end - client->receive_data.now;
         spice_warn_if_fail(n > 0);
-        n = reds_stream_read(channel->stream, channel->receive_data.now, n);
+        n = reds_stream_read(client->stream, client->receive_data.now, n);
         if (n <= 0) {
             if (n == 0) {
-                snd_disconnect_channel(channel);
+                snd_disconnect_channel(client);
                 return;
             }
             spice_assert(n == -1);
@@ -447,54 +447,54 @@ static void snd_receive(SndChannel *channel)
             case EINTR:
                 break;
             case EPIPE:
-                snd_disconnect_channel(channel);
+                snd_disconnect_channel(client);
                 return;
             default:
                 spice_printerr("%s", strerror(errno));
-                snd_disconnect_channel(channel);
+                snd_disconnect_channel(client);
                 return;
             }
         } else {
-            channel->receive_data.now += n;
+            client->receive_data.now += n;
             for (;;) {
-                uint8_t *msg_start = channel->receive_data.message_start;
+                uint8_t *msg_start = client->receive_data.message_start;
                 uint8_t *data = msg_start + header->header_size;
                 size_t parsed_size;
                 uint8_t *parsed;
                 message_destructor_t parsed_free;
 
                 header->data = msg_start;
-                n = channel->receive_data.now - msg_start;
+                n = client->receive_data.now - msg_start;
 
                 if (n < header->header_size ||
                     n < header->header_size + header->get_msg_size(header)) {
                     break;
                 }
-                parsed = channel->parser((void *)data, data + header->get_msg_size(header),
+                parsed = client->parser((void *)data, data + header->get_msg_size(header),
                                          header->get_msg_type(header),
                                          SPICE_VERSION_MINOR, &parsed_size, &parsed_free);
                 if (parsed == NULL) {
                     spice_printerr("failed to parse message type %d", header->get_msg_type(header));
-                    snd_disconnect_channel(channel);
+                    snd_disconnect_channel(client);
                     return;
                 }
-                if (!channel->handle_message(channel, parsed_size,
+                if (!client->handle_message(client, parsed_size,
                                              header->get_msg_type(header), parsed)) {
                     free(parsed);
-                    snd_disconnect_channel(channel);
+                    snd_disconnect_channel(client);
                     return;
                 }
                 parsed_free(parsed);
-                channel->receive_data.message_start = msg_start + header->header_size +
+                client->receive_data.message_start = msg_start + header->header_size +
                                                      header->get_msg_size(header);
             }
-            if (channel->receive_data.now == channel->receive_data.message_start) {
-                channel->receive_data.now = channel->receive_data.buf;
-                channel->receive_data.message_start = channel->receive_data.buf;
-            } else if (channel->receive_data.now == channel->receive_data.end) {
-                memcpy(channel->receive_data.buf, channel->receive_data.message_start, n);
-                channel->receive_data.now = channel->receive_data.buf + n;
-                channel->receive_data.message_start = channel->receive_data.buf;
+            if (client->receive_data.now == client->receive_data.message_start) {
+                client->receive_data.now = client->receive_data.buf;
+                client->receive_data.message_start = client->receive_data.buf;
+            } else if (client->receive_data.now == client->receive_data.end) {
+                memcpy(client->receive_data.buf, client->receive_data.message_start, n);
+                client->receive_data.now = client->receive_data.buf + n;
+                client->receive_data.message_start = client->receive_data.buf;
             }
         }
     }
@@ -502,64 +502,64 @@ static void snd_receive(SndChannel *channel)
 
 static void snd_event(int fd, int event, void *data)
 {
-    SndChannel *channel = data;
+    SndChannelClient *client = data;
 
     if (event & SPICE_WATCH_EVENT_READ) {
-        snd_receive(channel);
+        snd_receive(client);
     }
     if (event & SPICE_WATCH_EVENT_WRITE) {
-        channel->send_messages(channel);
+        client->send_messages(client);
     }
 }
 
-static inline int snd_reset_send_data(SndChannel *channel, uint16_t verb)
+static inline int snd_reset_send_data(SndChannelClient *client, uint16_t verb)
 {
     SpiceDataHeaderOpaque *header;
 
-    if (!channel) {
+    if (!client) {
         return FALSE;
     }
 
-    header = &channel->channel_client->priv->send_data.header;
-    spice_marshaller_reset(channel->send_data.marshaller);
-    header->data = spice_marshaller_reserve_space(channel->send_data.marshaller,
+    header = &client->channel_client->priv->send_data.header;
+    spice_marshaller_reset(client->send_data.marshaller);
+    header->data = spice_marshaller_reserve_space(client->send_data.marshaller,
                                                   header->header_size);
-    spice_marshaller_set_base(channel->send_data.marshaller,
+    spice_marshaller_set_base(client->send_data.marshaller,
                               header->header_size);
-    channel->send_data.pos = 0;
+    client->send_data.pos = 0;
     header->set_msg_size(header, 0);
     header->set_msg_type(header, verb);
-    channel->send_data.serial++;
-    if (!channel->channel_client->priv->is_mini_header) {
-        header->set_msg_serial(header, channel->send_data.serial);
+    client->send_data.serial++;
+    if (!client->channel_client->priv->is_mini_header) {
+        header->set_msg_serial(header, client->send_data.serial);
         header->set_msg_sub_list(header, 0);
     }
 
     return TRUE;
 }
 
-static int snd_begin_send_message(SndChannel *channel)
+static int snd_begin_send_message(SndChannelClient *client)
 {
-    SpiceDataHeaderOpaque *header = &channel->channel_client->priv->send_data.header;
+    SpiceDataHeaderOpaque *header = &client->channel_client->priv->send_data.header;
 
-    spice_marshaller_flush(channel->send_data.marshaller);
-    channel->send_data.size = spice_marshaller_get_total_size(channel->send_data.marshaller);
-    header->set_msg_size(header, channel->send_data.size - header->header_size);
-    return snd_send_data(channel);
+    spice_marshaller_flush(client->send_data.marshaller);
+    client->send_data.size = spice_marshaller_get_total_size(client->send_data.marshaller);
+    header->set_msg_size(header, client->send_data.size - header->header_size);
+    return snd_send_data(client);
 }
 
-static int snd_channel_send_migrate(SndChannel *channel)
+static int snd_channel_send_migrate(SndChannelClient *client)
 {
     SpiceMsgMigrate migrate;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_MIGRATE)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_MIGRATE)) {
         return FALSE;
     }
     spice_debug(NULL);
     migrate.flags = 0;
-    spice_marshall_msg_migrate(channel->send_data.marshaller, &migrate);
+    spice_marshall_msg_migrate(client->send_data.marshaller, &migrate);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_playback_send_migrate(PlaybackChannel *channel)
@@ -567,28 +567,28 @@ static int snd_playback_send_migrate(PlaybackChannel *channel)
     return snd_channel_send_migrate(&channel->base);
 }
 
-static int snd_send_volume(SndChannel *channel, uint32_t cap, int msg)
+static int snd_send_volume(SndChannelClient *client, uint32_t cap, int msg)
 {
     SpiceMsgAudioVolume *vol;
     uint8_t c;
-    SpiceVolumeState *st = &channel->worker->volume;
+    SpiceVolumeState *st = &client->worker->volume;
 
-    if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+    if (!red_channel_client_test_remote_cap(client->channel_client, cap)) {
         return TRUE;
     }
 
     vol = alloca(sizeof (SpiceMsgAudioVolume) +
                  st->volume_nchannels * sizeof (uint16_t));
-    if (!snd_reset_send_data(channel, msg)) {
+    if (!snd_reset_send_data(client, msg)) {
         return FALSE;
     }
     vol->nchannels = st->volume_nchannels;
     for (c = 0; c < st->volume_nchannels; ++c) {
         vol->volume[c] = st->volume[c];
     }
-    spice_marshall_SpiceMsgAudioVolume(channel->send_data.marshaller, vol);
+    spice_marshall_SpiceMsgAudioVolume(client->send_data.marshaller, vol);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_playback_send_volume(PlaybackChannel *playback_channel)
@@ -597,22 +597,22 @@ static int snd_playback_send_volume(PlaybackChannel *playback_channel)
                            SPICE_MSG_PLAYBACK_VOLUME);
 }
 
-static int snd_send_mute(SndChannel *channel, uint32_t cap, int msg)
+static int snd_send_mute(SndChannelClient *client, uint32_t cap, int msg)
 {
     SpiceMsgAudioMute mute;
-    SpiceVolumeState *st = &channel->worker->volume;
+    SpiceVolumeState *st = &client->worker->volume;
 
-    if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+    if (!red_channel_client_test_remote_cap(client->channel_client, cap)) {
         return TRUE;
     }
 
-    if (!snd_reset_send_data(channel, msg)) {
+    if (!snd_reset_send_data(client, msg)) {
         return FALSE;
     }
     mute.mute = st->mute;
-    spice_marshall_SpiceMsgAudioMute(channel->send_data.marshaller, &mute);
+    spice_marshall_SpiceMsgAudioMute(client->send_data.marshaller, &mute);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_playback_send_mute(PlaybackChannel *playback_channel)
@@ -623,53 +623,53 @@ static int snd_playback_send_mute(PlaybackChannel *playback_channel)
 
 static int snd_playback_send_latency(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = &playback_channel->base;
+    SndChannelClient *client = &playback_channel->base;
     SpiceMsgPlaybackLatency latency_msg;
 
     spice_debug("latency %u", playback_channel->latency);
-    if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_LATENCY)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_LATENCY)) {
         return FALSE;
     }
     latency_msg.latency_ms = playback_channel->latency;
-    spice_marshall_msg_playback_latency(channel->send_data.marshaller, &latency_msg);
+    spice_marshall_msg_playback_latency(client->send_data.marshaller, &latency_msg);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 static int snd_playback_send_start(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = (SndChannel *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_channel;
     SpiceMsgPlaybackStart start;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_START)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_START)) {
         return FALSE;
     }
 
     start.channels = SPICE_INTERFACE_PLAYBACK_CHAN;
-    start.frequency = channel->worker->frequency;
+    start.frequency = client->worker->frequency;
     spice_assert(SPICE_INTERFACE_PLAYBACK_FMT == SPICE_INTERFACE_AUDIO_FMT_S16);
     start.format = SPICE_AUDIO_FMT_S16;
     start.time = reds_get_mm_time();
-    spice_marshall_msg_playback_start(channel->send_data.marshaller, &start);
+    spice_marshall_msg_playback_start(client->send_data.marshaller, &start);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_playback_send_stop(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = (SndChannel *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_channel;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_STOP)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_STOP)) {
         return FALSE;
     }
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_playback_send_ctl(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = (SndChannel *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_channel;
 
-    if ((channel->client_active = channel->active)) {
+    if ((client->client_active = client->active)) {
         return snd_playback_send_start(playback_channel);
     } else {
         return snd_playback_send_stop(playback_channel);
@@ -678,38 +678,38 @@ static int snd_playback_send_ctl(PlaybackChannel *playback_channel)
 
 static int snd_record_send_start(RecordChannel *record_channel)
 {
-    SndChannel *channel = (SndChannel *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_channel;
     SpiceMsgRecordStart start;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_RECORD_START)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_RECORD_START)) {
         return FALSE;
     }
 
     start.channels = SPICE_INTERFACE_RECORD_CHAN;
-    start.frequency = channel->worker->frequency;
+    start.frequency = client->worker->frequency;
     spice_assert(SPICE_INTERFACE_RECORD_FMT == SPICE_INTERFACE_AUDIO_FMT_S16);
     start.format = SPICE_AUDIO_FMT_S16;
-    spice_marshall_msg_record_start(channel->send_data.marshaller, &start);
+    spice_marshall_msg_record_start(client->send_data.marshaller, &start);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_record_send_stop(RecordChannel *record_channel)
 {
-    SndChannel *channel = (SndChannel *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_channel;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_RECORD_STOP)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_RECORD_STOP)) {
         return FALSE;
     }
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int snd_record_send_ctl(RecordChannel *record_channel)
 {
-    SndChannel *channel = (SndChannel *)record_channel;
+    SndChannelClient *client = (SndChannelClient *)record_channel;
 
-    if ((channel->client_active = channel->active)) {
+    if ((client->client_active = client->active)) {
         return snd_record_send_start(record_channel);
     } else {
         return snd_record_send_stop(record_channel);
@@ -739,21 +739,21 @@ static int snd_record_send_migrate(RecordChannel *record_channel)
 
 static int snd_playback_send_write(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = (SndChannel *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_channel;
     AudioFrame *frame;
     SpiceMsgPlaybackPacket msg;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_DATA)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_DATA)) {
         return FALSE;
     }
 
     frame = playback_channel->in_progress;
     msg.time = frame->time;
 
-    spice_marshall_msg_playback_data(channel->send_data.marshaller, &msg);
+    spice_marshall_msg_playback_data(client->send_data.marshaller, &msg);
 
     if (playback_channel->mode == SPICE_AUDIO_DATA_MODE_RAW) {
-        spice_marshaller_add_ref(channel->send_data.marshaller,
+        spice_marshaller_add_ref(client->send_data.marshaller,
                                  (uint8_t *)frame->samples,
                                  snd_codec_frame_size(playback_channel->codec) * sizeof(frame->samples[0]));
     }
@@ -763,80 +763,80 @@ static int snd_playback_send_write(PlaybackChannel *playback_channel)
                                     snd_codec_frame_size(playback_channel->codec) * sizeof(frame->samples[0]),
                                     playback_channel->encode_buf, &n) != SND_CODEC_OK) {
             spice_printerr("encode failed");
-            snd_disconnect_channel(channel);
+            snd_disconnect_channel(client);
             return FALSE;
         }
-        spice_marshaller_add_ref(channel->send_data.marshaller, playback_channel->encode_buf, n);
+        spice_marshaller_add_ref(client->send_data.marshaller, playback_channel->encode_buf, n);
     }
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static int playback_send_mode(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = (SndChannel *)playback_channel;
+    SndChannelClient *client = (SndChannelClient *)playback_channel;
     SpiceMsgPlaybackMode mode;
 
-    if (!snd_reset_send_data(channel, SPICE_MSG_PLAYBACK_MODE)) {
+    if (!snd_reset_send_data(client, SPICE_MSG_PLAYBACK_MODE)) {
         return FALSE;
     }
     mode.time = reds_get_mm_time();
     mode.mode = playback_channel->mode;
-    spice_marshall_msg_playback_mode(channel->send_data.marshaller, &mode);
+    spice_marshall_msg_playback_mode(client->send_data.marshaller, &mode);
 
-    return snd_begin_send_message(channel);
+    return snd_begin_send_message(client);
 }
 
 static void snd_playback_send(void* data)
 {
     PlaybackChannel *playback_channel = (PlaybackChannel*)data;
-    SndChannel *channel = (SndChannel*)playback_channel;
+    SndChannelClient *client = (SndChannelClient*)playback_channel;
 
     if (!playback_channel || !snd_send_data(data)) {
         return;
     }
 
-    while (channel->command) {
-        if (channel->command & SND_PLAYBACK_MODE_MASK) {
+    while (client->command) {
+        if (client->command & SND_PLAYBACK_MODE_MASK) {
             if (!playback_send_mode(playback_channel)) {
                 return;
             }
-            channel->command &= ~SND_PLAYBACK_MODE_MASK;
+            client->command &= ~SND_PLAYBACK_MODE_MASK;
         }
-        if (channel->command & SND_PLAYBACK_PCM_MASK) {
+        if (client->command & SND_PLAYBACK_PCM_MASK) {
             spice_assert(!playback_channel->in_progress && playback_channel->pending_frame);
             playback_channel->in_progress = playback_channel->pending_frame;
             playback_channel->pending_frame = NULL;
-            channel->command &= ~SND_PLAYBACK_PCM_MASK;
+            client->command &= ~SND_PLAYBACK_PCM_MASK;
             if (!snd_playback_send_write(playback_channel)) {
                 spice_printerr("snd_send_playback_write failed");
                 return;
             }
         }
-        if (channel->command & SND_CTRL_MASK) {
+        if (client->command & SND_CTRL_MASK) {
             if (!snd_playback_send_ctl(playback_channel)) {
                 return;
             }
-            channel->command &= ~SND_CTRL_MASK;
+            client->command &= ~SND_CTRL_MASK;
         }
-        if (channel->command & SND_VOLUME_MASK) {
+        if (client->command & SND_VOLUME_MASK) {
             if (!snd_playback_send_volume(playback_channel) ||
                 !snd_playback_send_mute(playback_channel)) {
                 return;
             }
-            channel->command &= ~SND_VOLUME_MASK;
+            client->command &= ~SND_VOLUME_MASK;
         }
-        if (channel->command & SND_MIGRATE_MASK) {
+        if (client->command & SND_MIGRATE_MASK) {
             if (!snd_playback_send_migrate(playback_channel)) {
                 return;
             }
-            channel->command &= ~SND_MIGRATE_MASK;
+            client->command &= ~SND_MIGRATE_MASK;
         }
-        if (channel->command & SND_PLAYBACK_LATENCY_MASK) {
+        if (client->command & SND_PLAYBACK_LATENCY_MASK) {
             if (!snd_playback_send_latency(playback_channel)) {
                 return;
             }
-            channel->command &= ~SND_PLAYBACK_LATENCY_MASK;
+            client->command &= ~SND_PLAYBACK_LATENCY_MASK;
         }
     }
 }
@@ -844,54 +844,54 @@ static void snd_playback_send(void* data)
 static void snd_record_send(void* data)
 {
     RecordChannel *record_channel = (RecordChannel*)data;
-    SndChannel *channel = (SndChannel*)record_channel;
+    SndChannelClient *client = (SndChannelClient*)record_channel;
 
     if (!record_channel || !snd_send_data(data)) {
         return;
     }
 
-    while (channel->command) {
-        if (channel->command & SND_CTRL_MASK) {
+    while (client->command) {
+        if (client->command & SND_CTRL_MASK) {
             if (!snd_record_send_ctl(record_channel)) {
                 return;
             }
-            channel->command &= ~SND_CTRL_MASK;
+            client->command &= ~SND_CTRL_MASK;
         }
-        if (channel->command & SND_VOLUME_MASK) {
+        if (client->command & SND_VOLUME_MASK) {
             if (!snd_record_send_volume(record_channel) ||
                 !snd_record_send_mute(record_channel)) {
                 return;
             }
-            channel->command &= ~SND_VOLUME_MASK;
+            client->command &= ~SND_VOLUME_MASK;
         }
-        if (channel->command & SND_MIGRATE_MASK) {
+        if (client->command & SND_MIGRATE_MASK) {
             if (!snd_record_send_migrate(record_channel)) {
                 return;
             }
-            channel->command &= ~SND_MIGRATE_MASK;
+            client->command &= ~SND_MIGRATE_MASK;
         }
     }
 }
 
-static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_id,
-                                 RedClient *client,
-                                 RedsStream *stream,
-                                 int migrate,
-                                 snd_channel_send_messages_proc send_messages,
-                                 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)
+static SndChannelClient *__new_channel(SndWorker *worker, int size, uint32_t channel_id,
+                                       RedClient *red_client,
+                                       RedsStream *stream,
+                                       int migrate,
+                                       snd_channel_send_messages_proc send_messages,
+                                       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;
+    SndChannelClient *client;
     int delay_val;
     int flags;
 #ifdef SO_PRIORITY
     int priority;
 #endif
     int tos;
-    MainChannelClient *mcc = red_client_get_main(client);
+    MainChannelClient *mcc = red_client_get_main(red_client);
     RedsState *reds = red_channel_get_server(worker->base_channel);
 
     spice_assert(stream);
@@ -929,39 +929,39 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
         goto error1;
     }
 
-    spice_assert(size >= sizeof(*channel));
-    channel = spice_malloc0(size);
-    channel->refs = 1;
-    channel->parser = spice_get_client_channel_parser(channel_id, NULL);
-    channel->stream = stream;
-    channel->worker = worker;
-    channel->receive_data.message_start = channel->receive_data.buf;
-    channel->receive_data.now = channel->receive_data.buf;
-    channel->receive_data.end = channel->receive_data.buf + sizeof(channel->receive_data.buf);
-    channel->send_data.marshaller = spice_marshaller_new();
+    spice_assert(size >= sizeof(*client));
+    client = spice_malloc0(size);
+    client->refs = 1;
+    client->parser = spice_get_client_channel_parser(channel_id, NULL);
+    client->stream = stream;
+    client->worker = worker;
+    client->receive_data.message_start = client->receive_data.buf;
+    client->receive_data.now = client->receive_data.buf;
+    client->receive_data.end = client->receive_data.buf + sizeof(client->receive_data.buf);
+    client->send_data.marshaller = spice_marshaller_new();
 
     stream->watch = reds_core_watch_add(reds, stream->socket, SPICE_WATCH_EVENT_READ,
-                                        snd_event, channel);
+                                        snd_event, client);
     if (stream->watch == NULL) {
         spice_printerr("watch_add failed, %s", strerror(errno));
         goto error2;
     }
 
-    channel->send_messages = send_messages;
-    channel->handle_message = handle_message;
-    channel->on_message_done = on_message_done;
-    channel->cleanup = cleanup;
+    client->send_messages = send_messages;
+    client->handle_message = handle_message;
+    client->on_message_done = on_message_done;
+    client->cleanup = cleanup;
 
-    channel->channel_client =
-        dummy_channel_client_create(worker->base_channel, client,
+    client->channel_client =
+        dummy_channel_client_create(worker->base_channel, red_client,
                                     num_common_caps, common_caps, num_caps, caps);
-    if (!channel->channel_client) {
+    if (!client->channel_client) {
         goto error2;
     }
-    return channel;
+    return client;
 
 error2:
-    free(channel);
+    free(client);
 
 error1:
     reds_stream_free(stream);
@@ -986,12 +986,12 @@ static void snd_disconnect_channel_client(RedChannelClient *rcc)
     }
 }
 
-static void snd_set_command(SndChannel *channel, uint32_t command)
+static void snd_set_command(SndChannelClient *client, uint32_t command)
 {
-    if (!channel) {
+    if (!client) {
         return;
     }
-    channel->command |= command;
+    client->command |= command;
 }
 
 SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *sin,
@@ -999,14 +999,14 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
                                                   uint16_t *volume)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
-    SndChannel *channel = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
 
     st->volume_nchannels = nchannels;
     free(st->volume);
     st->volume = spice_memdup(volume, sizeof(uint16_t) * nchannels);
 
-    if (!channel || nchannels == 0)
+    if (!client || nchannels == 0)
         return;
 
     snd_playback_send_volume(playback_channel);
@@ -1015,12 +1015,12 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
 SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *sin, uint8_t mute)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
-    SndChannel *channel = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
 
     st->mute = mute;
 
-    if (!channel)
+    if (!client)
         return;
 
     snd_playback_send_mute(playback_channel);
@@ -1028,19 +1028,19 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *si
 
 static void snd_playback_start(SndWorker *worker)
 {
-    SndChannel *channel = worker->connection;
+    SndChannelClient *client = worker->connection;
 
     worker->active = 1;
-    if (!channel)
+    if (!client)
         return;
-    spice_assert(!channel->active);
-    reds_disable_mm_time(snd_channel_get_server(channel));
-    channel->active = TRUE;
-    if (!channel->client_active) {
-        snd_set_command(channel, SND_CTRL_MASK);
-        snd_playback_send(channel);
+    spice_assert(!client->active);
+    reds_disable_mm_time(snd_channel_get_server(client));
+    client->active = TRUE;
+    if (!client->client_active) {
+        snd_set_command(client, SND_CTRL_MASK);
+        snd_playback_send(client);
     } else {
-        channel->command &= ~SND_CTRL_MASK;
+        client->command &= ~SND_CTRL_MASK;
     }
 }
 
@@ -1051,14 +1051,14 @@ SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
 
 SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
 {
-    SndChannel *channel = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
 
     sin->st->worker.active = 0;
-    if (!channel)
+    if (!client)
         return;
     spice_assert(playback_channel->base.active);
-    reds_enable_mm_time(snd_channel_get_server(channel));
+    reds_enable_mm_time(snd_channel_get_server(client));
     playback_channel->base.active = FALSE;
     if (playback_channel->base.client_active) {
         snd_set_command(&playback_channel->base, SND_CTRL_MASK);
@@ -1079,16 +1079,16 @@ SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
 SPICE_GNUC_VISIBLE void spice_server_playback_get_buffer(SpicePlaybackInstance *sin,
                                                          uint32_t **frame, uint32_t *num_samples)
 {
-    SndChannel *channel = sin->st->worker.connection;
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
 
-    if (!channel || !playback_channel->free_frames) {
+    if (!client || !playback_channel->free_frames) {
         *frame = NULL;
         *num_samples = 0;
         return;
     }
     spice_assert(playback_channel->base.active);
-    snd_channel_ref(channel);
+    snd_channel_ref(client);
 
     *frame = playback_channel->free_frames->samples;
     playback_channel->free_frames = playback_channel->free_frames->next;
@@ -1105,8 +1105,8 @@ SPICE_GNUC_VISIBLE void spice_server_playback_put_samples(SpicePlaybackInstance
     spice_assert(playback_channel);
     if (!snd_channel_unref(&playback_channel->base) ||
         sin->st->worker.connection != &playback_channel->base) {
-        /* lost last reference, channel has been destroyed previously */
-        spice_info("audio samples belong to a disconnected channel");
+        /* lost last reference, client has been destroyed previously */
+        spice_info("audio samples belong to a disconnected client");
         return;
     }
     spice_assert(playback_channel->base.active);
@@ -1159,7 +1159,7 @@ static int snd_desired_audio_mode(int playback_compression, int frequency,
     return SPICE_AUDIO_DATA_MODE_RAW;
 }
 
-static void on_new_playback_channel(SndWorker *worker, SndChannel *snd_channel)
+static void on_new_playback_channel(SndWorker *worker, SndChannelClient *snd_channel)
 {
     RedsState *reds = red_channel_get_server(worker->base_channel);
 
@@ -1178,12 +1178,12 @@ static void on_new_playback_channel(SndWorker *worker, SndChannel *snd_channel)
     }
 }
 
-static void snd_playback_cleanup(SndChannel *channel)
+static void snd_playback_cleanup(SndChannelClient *client)
 {
-    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+    PlaybackChannel *playback_channel = SPICE_CONTAINEROF(client, PlaybackChannel, base);
 
     if (playback_channel->base.active) {
-        reds_enable_mm_time(snd_channel_get_server(channel));
+        reds_enable_mm_time(snd_channel_get_server(client));
     }
 
     snd_codec_destroy(&playback_channel->codec);
@@ -1266,14 +1266,14 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
                                                 uint16_t *volume)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
-    SndChannel *channel = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
 
     st->volume_nchannels = nchannels;
     free(st->volume);
     st->volume = spice_memdup(volume, sizeof(uint16_t) * nchannels);
 
-    if (!channel || nchannels == 0)
+    if (!client || nchannels == 0)
         return;
 
     snd_record_send_volume(record_channel);
@@ -1282,12 +1282,12 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
 SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, uint8_t mute)
 {
     SpiceVolumeState *st = &sin->st->worker.volume;
-    SndChannel *channel = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
 
     st->mute = mute;
 
-    if (!channel)
+    if (!client)
         return;
 
     snd_record_send_mute(record_channel);
@@ -1295,21 +1295,21 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, u
 
 static void snd_record_start(SndWorker *worker)
 {
-    SndChannel *channel = worker->connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    SndChannelClient *client = worker->connection;
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
 
     worker->active = 1;
-    if (!channel)
+    if (!client)
         return;
-    spice_assert(!channel->active);
+    spice_assert(!client->active);
     record_channel->read_pos = record_channel->write_pos = 0;   //todo: improve by
                                                                 //stream generation
-    channel->active = TRUE;
-    if (!channel->client_active) {
-        snd_set_command(channel, SND_CTRL_MASK);
-        snd_record_send(channel);
+    client->active = TRUE;
+    if (!client->client_active) {
+        snd_set_command(client, SND_CTRL_MASK);
+        snd_record_send(client);
     } else {
-        channel->command &= ~SND_CTRL_MASK;
+        client->command &= ~SND_CTRL_MASK;
     }
 }
 
@@ -1320,11 +1320,11 @@ SPICE_GNUC_VISIBLE void spice_server_record_start(SpiceRecordInstance *sin)
 
 SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
 {
-    SndChannel *channel = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
 
     sin->st->worker.active = 0;
-    if (!channel)
+    if (!client)
         return;
     spice_assert(record_channel->base.active);
     record_channel->base.active = FALSE;
@@ -1339,13 +1339,13 @@ SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
 SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance *sin,
                                                             uint32_t *samples, uint32_t bufsize)
 {
-    SndChannel *channel = sin->st->worker.connection;
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    SndChannelClient *client = sin->st->worker.connection;
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
     uint32_t read_pos;
     uint32_t now;
     uint32_t len;
 
-    if (!channel)
+    if (!client)
         return 0;
     spice_assert(record_channel->base.active);
 
@@ -1374,11 +1374,11 @@ SPICE_GNUC_VISIBLE uint32_t spice_server_record_get_samples(SpiceRecordInstance
     return len;
 }
 
-static uint32_t snd_get_best_rate(SndChannel *channel, uint32_t cap_opus)
+static uint32_t snd_get_best_rate(SndChannelClient *client, uint32_t cap_opus)
 {
     int client_can_opus = TRUE;
-    if (channel) {
-        client_can_opus = red_channel_client_test_remote_cap(channel->channel_client, cap_opus);
+    if (client) {
+        client_can_opus = red_channel_client_test_remote_cap(client->channel_client, cap_opus);
     }
 
     if (client_can_opus && snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_OPUS, SND_CODEC_ANY_FREQUENCY))
@@ -1416,7 +1416,7 @@ SPICE_GNUC_VISIBLE void spice_server_set_record_rate(SpiceRecordInstance *sin, u
     snd_set_rate(&sin->st->worker, frequency, SPICE_RECORD_CAP_OPUS);
 }
 
-static void on_new_record_channel(SndWorker *worker, SndChannel *snd_channel)
+static void on_new_record_channel(SndWorker *worker, SndChannelClient *snd_channel)
 {
     spice_assert(snd_channel);
 
@@ -1429,9 +1429,9 @@ static void on_new_record_channel(SndWorker *worker, SndChannel *snd_channel)
     }
 }
 
-static void snd_record_cleanup(SndChannel *channel)
+static void snd_record_cleanup(SndChannelClient *client)
 {
-    RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
+    RecordChannel *record_channel = SPICE_CONTAINEROF(client, RecordChannel, base);
     snd_codec_destroy(&record_channel->codec);
 }
 


More information about the Spice-commits mailing list