Skip to content

Commit eb813e1

Browse files
committed
updated to 0.3.1
1 parent 2027dab commit eb813e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2577
-464
lines changed

BlockingQueue.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
CBlockingQueue::CBlockingQueue(size_t capacity){
1010
this->capacity=capacity;
11+
overflowCallback=NULL;
1112
init_lock(lock);
1213
init_mutex(mutex);
1314
}
@@ -29,7 +30,12 @@ void CBlockingQueue::Put(void *thing){
2930
}
3031
queue.push_back(thing);
3132
while(queue.size()>capacity){
32-
queue.pop_front();
33+
if(overflowCallback){
34+
overflowCallback(queue.front());
35+
queue.pop_front();
36+
}else{
37+
abort();
38+
}
3339
}
3440
unlock_mutex(mutex);
3541
}
@@ -72,3 +78,7 @@ void CBlockingQueue::PrepareDealloc(){
7278
unlock_mutex(mutex);
7379
}
7480

81+
82+
void CBlockingQueue::SetOverflowCallback(void (*overflowCallback)(void *)){
83+
this->overflowCallback=overflowCallback;
84+
}

BlockingQueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ class CBlockingQueue{
2222
void* Get();
2323
unsigned int Size();
2424
void PrepareDealloc();
25+
void SetOverflowCallback(void (*overflowCallback)(void*));
2526

2627
private:
2728
void* GetInternal();
2829
list<void*> queue;
2930
size_t capacity;
3031
tgvoip_lock_t lock;
3132
tgvoip_mutex_t mutex;
33+
void (*overflowCallback)(void*);
3234
};
3335

3436

BufferInputStream.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <exception>
1111
#include <stdexcept>
1212

13-
CBufferInputStream::CBufferInputStream(char* data, size_t length){
13+
CBufferInputStream::CBufferInputStream(unsigned char* data, size_t length){
1414
this->buffer=data;
1515
this->length=length;
1616
offset=0;
@@ -22,7 +22,9 @@ CBufferInputStream::~CBufferInputStream(){
2222

2323

2424
void CBufferInputStream::Seek(size_t offset){
25-
assert(offset<=length);
25+
if(offset>length){
26+
throw std::out_of_range("Not enough bytes in buffer");
27+
}
2628
this->offset=offset;
2729
}
2830

@@ -88,7 +90,7 @@ int32_t CBufferInputStream::ReadTlLength(){
8890
return res;
8991
}
9092

91-
void CBufferInputStream::ReadBytes(char *to, size_t count){
93+
void CBufferInputStream::ReadBytes(unsigned char *to, size_t count){
9294
EnsureEnoughRemaining(count);
9395
memcpy(to, buffer+offset, count);
9496
offset+=count;

BufferInputStream.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class CBufferInputStream{
1414

1515
public:
16-
CBufferInputStream(char* data, size_t length);
16+
CBufferInputStream(unsigned char* data, size_t length);
1717
~CBufferInputStream();
1818
void Seek(size_t offset);
1919
size_t GetLength();
@@ -24,11 +24,11 @@ class CBufferInputStream{
2424
int32_t ReadInt32();
2525
int16_t ReadInt16();
2626
int32_t ReadTlLength();
27-
void ReadBytes(char* to, size_t count);
27+
void ReadBytes(unsigned char* to, size_t count);
2828

2929
private:
3030
void EnsureEnoughRemaining(size_t need);
31-
char* buffer;
31+
unsigned char* buffer;
3232
size_t length;
3333
size_t offset;
3434
};

BufferOutputStream.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string.h>
99

1010
CBufferOutputStream::CBufferOutputStream(size_t size){
11-
buffer=(char*) malloc(size);
11+
buffer=(unsigned char*) malloc(size);
1212
offset=0;
1313
this->size=size;
1414
}
@@ -24,40 +24,40 @@ void CBufferOutputStream::WriteByte(unsigned char byte){
2424

2525
void CBufferOutputStream::WriteInt32(int32_t i){
2626
this->ExpandBufferIfNeeded(4);
27-
buffer[offset+3]=(char)((i >> 24) & 0xFF);
28-
buffer[offset+2]=(char)((i >> 16) & 0xFF);
29-
buffer[offset+1]=(char)((i >> 8) & 0xFF);
30-
buffer[offset]=(char)(i & 0xFF);
27+
buffer[offset+3]=(unsigned char)((i >> 24) & 0xFF);
28+
buffer[offset+2]=(unsigned char)((i >> 16) & 0xFF);
29+
buffer[offset+1]=(unsigned char)((i >> 8) & 0xFF);
30+
buffer[offset]=(unsigned char)(i & 0xFF);
3131
offset+=4;
3232
}
3333

3434
void CBufferOutputStream::WriteInt64(int64_t i){
3535
this->ExpandBufferIfNeeded(8);
36-
buffer[offset+7]=(char)((i >> 56) & 0xFF);
37-
buffer[offset+6]=(char)((i >> 48) & 0xFF);
38-
buffer[offset+5]=(char)((i >> 40) & 0xFF);
39-
buffer[offset+4]=(char)((i >> 32) & 0xFF);
40-
buffer[offset+3]=(char)((i >> 24) & 0xFF);
41-
buffer[offset+2]=(char)((i >> 16) & 0xFF);
42-
buffer[offset+1]=(char)((i >> 8) & 0xFF);
43-
buffer[offset]=(char)(i & 0xFF);
36+
buffer[offset+7]=(unsigned char)((i >> 56) & 0xFF);
37+
buffer[offset+6]=(unsigned char)((i >> 48) & 0xFF);
38+
buffer[offset+5]=(unsigned char)((i >> 40) & 0xFF);
39+
buffer[offset+4]=(unsigned char)((i >> 32) & 0xFF);
40+
buffer[offset+3]=(unsigned char)((i >> 24) & 0xFF);
41+
buffer[offset+2]=(unsigned char)((i >> 16) & 0xFF);
42+
buffer[offset+1]=(unsigned char)((i >> 8) & 0xFF);
43+
buffer[offset]=(unsigned char)(i & 0xFF);
4444
offset+=8;
4545
}
4646

4747
void CBufferOutputStream::WriteInt16(int16_t i){
4848
this->ExpandBufferIfNeeded(2);
49-
buffer[offset+1]=(char)((i >> 8) & 0xFF);
50-
buffer[offset]=(char)(i & 0xFF);
49+
buffer[offset+1]=(unsigned char)((i >> 8) & 0xFF);
50+
buffer[offset]=(unsigned char)(i & 0xFF);
5151
offset+=2;
5252
}
5353

54-
void CBufferOutputStream::WriteBytes(char *bytes, size_t count){
54+
void CBufferOutputStream::WriteBytes(unsigned char *bytes, size_t count){
5555
this->ExpandBufferIfNeeded(count);
5656
memcpy(buffer+offset, bytes, count);
5757
offset+=count;
5858
}
5959

60-
char *CBufferOutputStream::GetBuffer(){
60+
unsigned char *CBufferOutputStream::GetBuffer(){
6161
return buffer;
6262
}
6363

@@ -68,10 +68,10 @@ size_t CBufferOutputStream::GetLength(){
6868
void CBufferOutputStream::ExpandBufferIfNeeded(size_t need){
6969
if(offset+need>size){
7070
if(need<1024){
71-
buffer=(char *) realloc(buffer, size+1024);
71+
buffer=(unsigned char *) realloc(buffer, size+1024);
7272
size+=1024;
7373
}else{
74-
buffer=(char *) realloc(buffer, size+need);
74+
buffer=(unsigned char *) realloc(buffer, size+need);
7575
size+=need;
7676
}
7777
}

BufferOutputStream.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class CBufferOutputStream{
1818
void WriteInt64(int64_t i);
1919
void WriteInt32(int32_t i);
2020
void WriteInt16(int16_t i);
21-
void WriteBytes(char* bytes, size_t count);
22-
char* GetBuffer();
21+
void WriteBytes(unsigned char* bytes, size_t count);
22+
unsigned char* GetBuffer();
2323
size_t GetLength();
2424
void Reset();
2525

2626
private:
2727
void ExpandBufferIfNeeded(size_t need);
28-
char* buffer;
28+
unsigned char* buffer;
2929
size_t size;
3030
size_t offset;
3131
};

CongestionControl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "CongestionControl.h"
88
#include "VoIPController.h"
99
#include "logging.h"
10+
#include "VoIPServerConfig.h"
1011
#include <math.h>
1112
#include <assert.h>
1213

@@ -26,7 +27,7 @@ CCongestionControl::CCongestionControl(){
2627
stateTransitionTime=0;
2728
inflightDataSize=0;
2829
lossCount=0;
29-
cwnd=1024;
30+
cwnd=(size_t) CVoIPServerConfig::GetSharedInstance()->GetInt("audio_congestion_window", 1024);
3031
init_mutex(mutex);
3132
}
3233

CongestionControl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class CCongestionControl{
5555
double stateTransitionTime;
5656
int tmpRttCount;
5757
char rttHistorySize;
58-
char rttHistoryTop;
59-
char inflightHistoryTop;
58+
unsigned int rttHistoryTop;
59+
unsigned int inflightHistoryTop;
6060
uint32_t lastSentSeq;
6161
uint32_t tickCount;
6262
size_t inflightDataSize;

0 commit comments

Comments
 (0)