Transfer only larger sound buffers

This commit is contained in:
simon.kagstrom 2009-04-11 11:50:10 +00:00
parent 852c6d546a
commit 7c216605bc
2 changed files with 14 additions and 3 deletions

View File

@ -132,6 +132,9 @@ size_t Network::EncodeSoundRLE(struct NetworkUpdate *dst,
volume = buffer[i]; volume = buffer[i];
} }
len++; len++;
/* Abort if the encoding becomes larger than the raw encoding */
if (len >= buf_len)
return buf_len + 2;
} }
if (len != 0) if (len != 0)
{ {
@ -406,10 +409,16 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t
out = this->EncodeSoundRLE(dst, buf, len); out = this->EncodeSoundRLE(dst, buf, len);
if (out > len) if (out > len)
out = this->EncodeSoundRaw(dst, buf, len); out = this->EncodeSoundRaw(dst, buf, len);
return out; 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() void Network::EncodeSound()
{ {
NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud; NetworkUpdate *dst = (NetworkUpdate *)this->cur_ud;
@ -418,7 +427,7 @@ void Network::EncodeSound()
/* Nothing to encode? */ /* Nothing to encode? */
if (!Network::is_master || if (!Network::is_master ||
Network::sample_head == Network::sample_tail) this->GetSoundBufferSize() < NETWORK_SOUND_BUF_SIZE / 2)
return; return;
if (Network::sample_tail > Network::sample_head) if (Network::sample_tail > Network::sample_head)

View File

@ -15,7 +15,7 @@
#define FRODO_NETWORK_MAGIC 0x1976 #define FRODO_NETWORK_MAGIC 0x1976
#define NETWORK_UPDATE_SIZE (256 * 1024) #define NETWORK_UPDATE_SIZE (256 * 1024)
#define NETWORK_SOUND_BUF_SIZE 1024 #define NETWORK_SOUND_BUF_SIZE 4096
typedef enum typedef enum
{ {
/* Connection-related messages */ /* Connection-related messages */
@ -216,6 +216,8 @@ protected:
size_t EncodeSoundRaw(struct NetworkUpdate *dst, size_t EncodeSoundRaw(struct NetworkUpdate *dst,
Uint8 *buffer, size_t len); Uint8 *buffer, size_t len);
size_t GetSoundBufferSize();
/** Encode part of a screen into @a dst in a single sweep /** Encode part of a screen into @a dst in a single sweep
* *
* @param dst the destination update structure * @param dst the destination update structure