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];
}
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)

View File

@ -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