From 7c216605bc274d33d802bdfd85131dddd6d7a912 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 11 Apr 2009 11:50:10 +0000 Subject: [PATCH] Transfer only larger sound buffers --- Src/Network.cpp | 13 +++++++++++-- Src/Network.h | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Src/Network.cpp b/Src/Network.cpp index 3c4f7c4..4b552db 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -132,6 +132,9 @@ size_t Network::EncodeSoundRLE(struct NetworkUpdate *dst, volume = buffer[i]; } len++; + /* Abort if the encoding becomes larger than the raw encoding */ + if (len >= buf_len) + return buf_len + 2; } if (len != 0) { @@ -406,10 +409,16 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t out = this->EncodeSoundRLE(dst, buf, len); if (out > len) out = this->EncodeSoundRaw(dst, buf, len); - return out; } +size_t Network::GetSoundBufferSize() +{ + if (Network::sample_tail > Network::sample_head) + return NETWORK_SOUND_BUF_SIZE - Network::sample_tail + Network::sample_head; + return Network::sample_head- Network::sample_tail; +} + void Network::EncodeSound() { NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud; @@ -418,7 +427,7 @@ void Network::EncodeSound() /* Nothing to encode? */ if (!Network::is_master || - Network::sample_head == Network::sample_tail) + this->GetSoundBufferSize() < NETWORK_SOUND_BUF_SIZE / 2) return; if (Network::sample_tail > Network::sample_head) diff --git a/Src/Network.h b/Src/Network.h index 416de0e..3ff9910 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -15,7 +15,7 @@ #define FRODO_NETWORK_MAGIC 0x1976 #define NETWORK_UPDATE_SIZE (256 * 1024) -#define NETWORK_SOUND_BUF_SIZE 1024 +#define NETWORK_SOUND_BUF_SIZE 4096 typedef enum { /* Connection-related messages */ @@ -216,6 +216,8 @@ protected: size_t EncodeSoundRaw(struct NetworkUpdate *dst, Uint8 *buffer, size_t len); + size_t GetSoundBufferSize(); + /** Encode part of a screen into @a dst in a single sweep * * @param dst the destination update structure