On 08/25/2010 11:49 AM, [email protected] wrote:
From: Alexander Larsson<[email protected]>

VLC sends silence when paused (bug #28817), which causes a lot of
unnecessary network traffic. We detect such silence and shut
down the clients audio stream (even though the audio is still active
in the server), re-enabling it when we get non-silent data again.
---

  __visible__ void spice_server_playback_put_samples(SpicePlaybackInstance 
*sin, uint32_t *samples)
  {
      SndChannel *channel = sin->st->worker.connection;
      PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, 
PlaybackChannel, base);
      AudioFrame *frame;
+    uint32_t mm_time;

      if (!channel)
          return;
      ASSERT(playback_channel->base.active);

+    frame = SPICE_CONTAINEROF(samples, AudioFrame, samples);
+
+    mm_time = reds_get_mm_time();
+    red_dispatcher_set_mm_time(mm_time);
+
+    if (frame_is_silent(frame)) {
+        if (channel->client_silent) {
+            snd_playback_free_frame(playback_channel, frame);
+            return;
+        }
+        channel->silent_count++;
+        if (channel->silent_count>  SPICE_INTERFACE_PLAYBACK_FREQ / 
FRAME_SIZE) {
+            /* After 1 sec of silence we stop the audio */
+            channel->client_silent = TRUE;
+            if (playback_channel->pending_frame) {
+                snd_playback_free_frame(playback_channel, 
playback_channel->pending_frame);
+                playback_channel->pending_frame = NULL;
+            }
+            snd_playback_free_frame(playback_channel, frame);
+            snd_playback_send_stop(playback_channel);
+
+            return;
+        }
+    } else {
+        if (channel->client_silent) {
+            snd_playback_send_start(playback_channel);
+            channel->client_silent = FALSE;

you shouldn't call snd_playback_send_start/stop here, but rather use the channel's "pipe" (channel->command). Otherwise, you might corrupt the currently sent data or the order of messages.
_______________________________________________
Spice-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/spice-devel

Reply via email to