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

Frediano Ziglio fziglio at kemper.freedesktop.org
Sat Nov 12 09:40:47 UTC 2016


 server/sound.c |  116 +++++++++++++++++++++++----------------------------------
 1 file changed, 47 insertions(+), 69 deletions(-)

New commits:
commit eef0e07a0f7635a2bfbf1dea4e2542a9e7b34388
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Nov 11 17:58:57 2016 +0000

    sound: Peep hole optimisation
    
    Reduce SpiceVolumeState structure size on 64 architectures
    swapping the order of two fields.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/sound.c b/server/sound.c
index 8849f94..a21eebc 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -148,8 +148,8 @@ struct PlaybackChannel {
 };
 
 typedef struct SpiceVolumeState {
-    uint8_t volume_nchannels;
     uint16_t *volume;
+    uint8_t volume_nchannels;
     int mute;
 } SpiceVolumeState;
 
commit 4e9a274c049b16cd900f0b4e2f2c64b7379ed106
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Nov 11 14:18:14 2016 +0000

    sound: Minor simplification due to volume move
    
    Reuse more code in snd_send_volume and snd_send_mute.
    Reduce conversions in on_new_playback_channel and
    on_new_record_channel.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/sound.c b/server/sound.c
index 385a908..8849f94 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -576,10 +576,15 @@ static int snd_playback_send_migrate(PlaybackChannel *channel)
     return snd_channel_send_migrate(&channel->base);
 }
 
-static int snd_send_volume(SndChannel *channel, SpiceVolumeState *st, int msg)
+static int snd_send_volume(SndChannel *channel, uint32_t cap, int msg)
 {
     SpiceMsgAudioVolume *vol;
     uint8_t c;
+    SpiceVolumeState *st = &channel->worker->volume;
+
+    if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+        return TRUE;
+    }
 
     vol = alloca(sizeof (SpiceMsgAudioVolume) +
                  st->volume_nchannels * sizeof (uint16_t));
@@ -597,20 +602,18 @@ static int snd_send_volume(SndChannel *channel, SpiceVolumeState *st, int msg)
 
 static int snd_playback_send_volume(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = &playback_channel->base;
-    SpicePlaybackState *st = SPICE_CONTAINEROF(channel->worker, SpicePlaybackState, worker);
-
-    if (!red_channel_client_test_remote_cap(channel->channel_client,
-                                            SPICE_PLAYBACK_CAP_VOLUME)) {
-        return TRUE;
-    }
-
-    return snd_send_volume(channel, &st->worker.volume, SPICE_MSG_PLAYBACK_VOLUME);
+    return snd_send_volume(&playback_channel->base, SPICE_PLAYBACK_CAP_VOLUME,
+                           SPICE_MSG_PLAYBACK_VOLUME);
 }
 
-static int snd_send_mute(SndChannel *channel, SpiceVolumeState *st, int msg)
+static int snd_send_mute(SndChannel *channel, uint32_t cap, int msg)
 {
     SpiceMsgAudioMute mute;
+    SpiceVolumeState *st = &channel->worker->volume;
+
+    if (!red_channel_client_test_remote_cap(channel->channel_client, cap)) {
+        return TRUE;
+    }
 
     if (!snd_reset_send_data(channel, msg)) {
         return FALSE;
@@ -623,15 +626,8 @@ static int snd_send_mute(SndChannel *channel, SpiceVolumeState *st, int msg)
 
 static int snd_playback_send_mute(PlaybackChannel *playback_channel)
 {
-    SndChannel *channel = &playback_channel->base;
-    SpicePlaybackState *st = SPICE_CONTAINEROF(channel->worker, SpicePlaybackState, worker);
-
-    if (!red_channel_client_test_remote_cap(channel->channel_client,
-                                            SPICE_PLAYBACK_CAP_VOLUME)) {
-        return TRUE;
-    }
-
-    return snd_send_mute(channel, &st->worker.volume, SPICE_MSG_PLAYBACK_MUTE);
+    return snd_send_mute(&playback_channel->base, SPICE_PLAYBACK_CAP_VOLUME,
+                         SPICE_MSG_PLAYBACK_MUTE);
 }
 
 static int snd_playback_send_latency(PlaybackChannel *playback_channel)
@@ -733,28 +729,14 @@ static int snd_record_send_ctl(RecordChannel *record_channel)
 
 static int snd_record_send_volume(RecordChannel *record_channel)
 {
-    SndChannel *channel = &record_channel->base;
-    SpiceRecordState *st = SPICE_CONTAINEROF(channel->worker, SpiceRecordState, worker);
-
-    if (!red_channel_client_test_remote_cap(channel->channel_client,
-                                            SPICE_RECORD_CAP_VOLUME)) {
-        return TRUE;
-    }
-
-    return snd_send_volume(channel, &st->worker.volume, SPICE_MSG_RECORD_VOLUME);
+    return snd_send_volume(&record_channel->base, SPICE_RECORD_CAP_VOLUME,
+                           SPICE_MSG_RECORD_VOLUME);
 }
 
 static int snd_record_send_mute(RecordChannel *record_channel)
 {
-    SndChannel *channel = &record_channel->base;
-    SpiceRecordState *st = SPICE_CONTAINEROF(channel->worker, SpiceRecordState, worker);
-
-    if (!red_channel_client_test_remote_cap(channel->channel_client,
-                                            SPICE_RECORD_CAP_VOLUME)) {
-        return TRUE;
-    }
-
-    return snd_send_mute(channel, &st->worker.volume, SPICE_MSG_RECORD_MUTE);
+    return snd_send_mute(&record_channel->base, SPICE_RECORD_CAP_VOLUME,
+                         SPICE_MSG_RECORD_MUTE);
 }
 
 static int snd_record_send_migrate(RecordChannel *record_channel)
@@ -1187,20 +1169,18 @@ static int snd_desired_audio_mode(int playback_compression, int frequency,
 static void on_new_playback_channel(SndWorker *worker)
 {
     RedsState *reds = red_channel_get_server(worker->base_channel);
-    PlaybackChannel *playback_channel =
-        SPICE_CONTAINEROF(worker->connection, PlaybackChannel, base);
-    SpicePlaybackState *st = SPICE_CONTAINEROF(worker, SpicePlaybackState, worker);
+    SndChannel *snd_channel = worker->connection;
 
-    spice_assert(playback_channel);
+    spice_assert(snd_channel);
 
-    snd_set_command((SndChannel *)playback_channel, SND_PLAYBACK_MODE_MASK);
-    if (playback_channel->base.active) {
-        snd_set_command((SndChannel *)playback_channel, SND_PLAYBACK_CTRL_MASK);
+    snd_set_command(snd_channel, SND_PLAYBACK_MODE_MASK);
+    if (snd_channel->active) {
+        snd_set_command(snd_channel, SND_PLAYBACK_CTRL_MASK);
     }
-    if (st->worker.volume.volume_nchannels) {
-        snd_set_command((SndChannel *)playback_channel, SND_PLAYBACK_VOLUME_MASK);
+    if (worker->volume.volume_nchannels) {
+        snd_set_command(snd_channel, SND_PLAYBACK_VOLUME_MASK);
     }
-    if (playback_channel->base.active) {
+    if (snd_channel->active) {
         reds_disable_mm_time(reds);
     }
 }
@@ -1447,16 +1427,15 @@ SPICE_GNUC_VISIBLE void spice_server_set_record_rate(SpiceRecordInstance *sin, u
 
 static void on_new_record_channel(SndWorker *worker)
 {
-    RecordChannel *record_channel = (RecordChannel *)worker->connection;
-    SpiceRecordState *st = SPICE_CONTAINEROF(worker, SpiceRecordState, worker);
+    SndChannel *snd_channel = worker->connection;
 
-    spice_assert(record_channel);
+    spice_assert(snd_channel);
 
-    if (st->worker.volume.volume_nchannels) {
-        snd_set_command((SndChannel *)record_channel, SND_RECORD_VOLUME_MASK);
+    if (worker->volume.volume_nchannels) {
+        snd_set_command(snd_channel, SND_RECORD_VOLUME_MASK);
     }
-    if (record_channel->base.active) {
-        snd_set_command((SndChannel *)record_channel, SND_RECORD_CTRL_MASK);
+    if (snd_channel->active) {
+        snd_set_command(snd_channel, SND_RECORD_CTRL_MASK);
     }
 }
 
commit c3aece7601ae4bf07dc6addd5353288adda1ffd1
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Nov 11 13:45:13 2016 +0000

    sound: Move volume field to SndWorker
    
    This field is common to SpicePlaybackState and SpiceRecordState
    which are based on SndWorker.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/sound.c b/server/sound.c
index be9ad5f..385a908 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -147,6 +147,12 @@ struct PlaybackChannel {
     uint8_t  encode_buf[SND_CODEC_MAX_COMPRESSED_BYTES];
 };
 
+typedef struct SpiceVolumeState {
+    uint8_t volume_nchannels;
+    uint16_t *volume;
+    int mute;
+} SpiceVolumeState;
+
 /* Base class for SpicePlaybackState and SpiceRecordState */
 struct SndWorker {
     RedChannel *base_channel;
@@ -154,25 +160,18 @@ struct SndWorker {
     SndWorker *next; /* For the global SndWorker list */
 
     int active;
+    SpiceVolumeState volume;
 };
 
-typedef struct SpiceVolumeState {
-    uint8_t volume_nchannels;
-    uint16_t *volume;
-    int mute;
-} SpiceVolumeState;
-
 struct SpicePlaybackState {
     struct SndWorker worker;
     SpicePlaybackInstance *sin;
-    SpiceVolumeState volume;
     uint32_t frequency;
 };
 
 struct SpiceRecordState {
     struct SndWorker worker;
     SpiceRecordInstance *sin;
-    SpiceVolumeState volume;
     uint32_t frequency;
 };
 
@@ -606,7 +605,7 @@ static int snd_playback_send_volume(PlaybackChannel *playback_channel)
         return TRUE;
     }
 
-    return snd_send_volume(channel, &st->volume, SPICE_MSG_PLAYBACK_VOLUME);
+    return snd_send_volume(channel, &st->worker.volume, SPICE_MSG_PLAYBACK_VOLUME);
 }
 
 static int snd_send_mute(SndChannel *channel, SpiceVolumeState *st, int msg)
@@ -632,7 +631,7 @@ static int snd_playback_send_mute(PlaybackChannel *playback_channel)
         return TRUE;
     }
 
-    return snd_send_mute(channel, &st->volume, SPICE_MSG_PLAYBACK_MUTE);
+    return snd_send_mute(channel, &st->worker.volume, SPICE_MSG_PLAYBACK_MUTE);
 }
 
 static int snd_playback_send_latency(PlaybackChannel *playback_channel)
@@ -742,7 +741,7 @@ static int snd_record_send_volume(RecordChannel *record_channel)
         return TRUE;
     }
 
-    return snd_send_volume(channel, &st->volume, SPICE_MSG_RECORD_VOLUME);
+    return snd_send_volume(channel, &st->worker.volume, SPICE_MSG_RECORD_VOLUME);
 }
 
 static int snd_record_send_mute(RecordChannel *record_channel)
@@ -755,7 +754,7 @@ static int snd_record_send_mute(RecordChannel *record_channel)
         return TRUE;
     }
 
-    return snd_send_mute(channel, &st->volume, SPICE_MSG_RECORD_MUTE);
+    return snd_send_mute(channel, &st->worker.volume, SPICE_MSG_RECORD_MUTE);
 }
 
 static int snd_record_send_migrate(RecordChannel *record_channel)
@@ -1028,7 +1027,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
                                                   uint8_t nchannels,
                                                   uint16_t *volume)
 {
-    SpiceVolumeState *st = &sin->st->volume;
+    SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannel *channel = sin->st->worker.connection;
     PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
 
@@ -1044,7 +1043,7 @@ 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->volume;
+    SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannel *channel = sin->st->worker.connection;
     PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
 
@@ -1198,7 +1197,7 @@ static void on_new_playback_channel(SndWorker *worker)
     if (playback_channel->base.active) {
         snd_set_command((SndChannel *)playback_channel, SND_PLAYBACK_CTRL_MASK);
     }
-    if (st->volume.volume_nchannels) {
+    if (st->worker.volume.volume_nchannels) {
         snd_set_command((SndChannel *)playback_channel, SND_PLAYBACK_VOLUME_MASK);
     }
     if (playback_channel->base.active) {
@@ -1294,7 +1293,7 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
                                                 uint8_t nchannels,
                                                 uint16_t *volume)
 {
-    SpiceVolumeState *st = &sin->st->volume;
+    SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannel *channel = sin->st->worker.connection;
     RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
 
@@ -1310,7 +1309,7 @@ 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->volume;
+    SpiceVolumeState *st = &sin->st->worker.volume;
     SndChannel *channel = sin->st->worker.connection;
     RecordChannel *record_channel = SPICE_CONTAINEROF(channel, RecordChannel, base);
 
@@ -1453,7 +1452,7 @@ static void on_new_record_channel(SndWorker *worker)
 
     spice_assert(record_channel);
 
-    if (st->volume.volume_nchannels) {
+    if (st->worker.volume.volume_nchannels) {
         snd_set_command((SndChannel *)record_channel, SND_RECORD_VOLUME_MASK);
     }
     if (record_channel->base.active) {
@@ -1612,7 +1611,7 @@ static void snd_detach_common(SndWorker *worker)
 
 static void spice_playback_state_free(SpicePlaybackState *st)
 {
-    free(st->volume.volume);
+    free(st->worker.volume.volume);
     free(st);
 }
 
@@ -1624,7 +1623,7 @@ void snd_detach_playback(SpicePlaybackInstance *sin)
 
 static void spice_record_state_free(SpiceRecordState *st)
 {
-    free(st->volume.volume);
+    free(st->worker.volume.volume);
     free(st);
 }
 


More information about the Spice-commits mailing list