mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-07 05:25:12 +00:00
2.0-alpha4
This commit is contained in:
@@ -40,15 +40,22 @@ JitterBuffer::JitterBuffer(MediaStreamItf *out, uint32_t step):bufferPool(JITTER
|
||||
}
|
||||
lossesToReset=(uint32_t) ServerConfig::GetSharedInstance()->GetInt("jitter_losses_to_reset", 20);
|
||||
resyncThreshold=ServerConfig::GetSharedInstance()->GetDouble("jitter_resync_threshold", 1.0);
|
||||
//dump=fopen("/sdcard/tgvoip_jitter_dump.txt", "a");
|
||||
//fprintf(dump, "==================================\n");
|
||||
#ifdef TGVOIP_DUMP_JITTER_STATS
|
||||
#ifdef TGVOIP_JITTER_DUMP_FILE
|
||||
dump=fopen(TGVOIP_JITTER_DUMP_FILE, "w");
|
||||
#elif defined(__ANDROID__)
|
||||
dump=fopen("/sdcard/tgvoip_jitter_dump.txt", "w");
|
||||
#else
|
||||
dump=fopen("tgvoip_jitter_dump.txt", "w");
|
||||
#endif
|
||||
tgvoip_log_file_write_header(dump);
|
||||
fprintf(dump, "PTS\tRTS\tNumInBuf\tAJitter\tADelay\tTDelay\n");
|
||||
#endif
|
||||
Reset();
|
||||
init_mutex(mutex);
|
||||
}
|
||||
|
||||
JitterBuffer::~JitterBuffer(){
|
||||
Reset();
|
||||
free_mutex(mutex);
|
||||
}
|
||||
|
||||
void JitterBuffer::SetMinPacketCount(uint32_t count){
|
||||
@@ -76,9 +83,9 @@ void JitterBuffer::HandleInput(unsigned char *data, size_t len, uint32_t timesta
|
||||
pkt.size=len;
|
||||
pkt.buffer=data;
|
||||
pkt.timestamp=timestamp;
|
||||
lock_mutex(mutex);
|
||||
mutex.Lock();
|
||||
PutInternal(&pkt);
|
||||
unlock_mutex(mutex);
|
||||
mutex.Unlock();
|
||||
//LOGV("in, ts=%d", timestamp);
|
||||
}
|
||||
|
||||
@@ -106,12 +113,12 @@ void JitterBuffer::Reset(){
|
||||
}
|
||||
|
||||
|
||||
size_t JitterBuffer::HandleOutput(unsigned char *buffer, size_t len, int offsetInSteps, int* playbackScaledDuration){
|
||||
size_t JitterBuffer::HandleOutput(unsigned char *buffer, size_t len, int offsetInSteps, bool advance, int* playbackScaledDuration){
|
||||
jitter_packet_t pkt;
|
||||
pkt.buffer=buffer;
|
||||
pkt.size=len;
|
||||
lock_mutex(mutex);
|
||||
int result=GetInternal(&pkt, offsetInSteps);
|
||||
MutexGuard m(mutex);
|
||||
int result=GetInternal(&pkt, offsetInSteps, advance);
|
||||
if(playbackScaledDuration){
|
||||
if(outstandingDelayChange!=0){
|
||||
if(outstandingDelayChange<0){
|
||||
@@ -121,12 +128,14 @@ size_t JitterBuffer::HandleOutput(unsigned char *buffer, size_t len, int offsetI
|
||||
*playbackScaledDuration=80;
|
||||
outstandingDelayChange-=20;
|
||||
}
|
||||
LOGV("outstanding delay change: %d", outstandingDelayChange);
|
||||
//LOGV("outstanding delay change: %d", outstandingDelayChange);
|
||||
}else if(advance && GetCurrentDelay()==0){
|
||||
//LOGV("stretching packet because the next one is late");
|
||||
*playbackScaledDuration=80;
|
||||
}else{
|
||||
*playbackScaledDuration=60;
|
||||
}
|
||||
}
|
||||
unlock_mutex(mutex);
|
||||
if(result==JR_OK){
|
||||
return pkt.size;
|
||||
}else{
|
||||
@@ -135,7 +144,7 @@ size_t JitterBuffer::HandleOutput(unsigned char *buffer, size_t len, int offsetI
|
||||
}
|
||||
|
||||
|
||||
int JitterBuffer::GetInternal(jitter_packet_t* pkt, int offset){
|
||||
int JitterBuffer::GetInternal(jitter_packet_t* pkt, int offset, bool advance){
|
||||
/*if(needBuffering && lastPutTimestamp<nextTimestamp){
|
||||
LOGV("jitter: don't have timestamp %lld, buffering", (long long int)nextTimestamp);
|
||||
Advance();
|
||||
@@ -172,9 +181,9 @@ int JitterBuffer::GetInternal(jitter_packet_t* pkt, int offset){
|
||||
return JR_OK;
|
||||
}
|
||||
|
||||
LOGW("jitter: found no packet for timestamp %lld (last put = %d, lost = %d)", (long long int)timestampToGet, lastPutTimestamp, lostCount);
|
||||
//LOGV("jitter: found no packet for timestamp %lld (last put = %d, lost = %d)", (long long int)timestampToGet, lastPutTimestamp, lostCount);
|
||||
|
||||
if(offset==0)
|
||||
if(advance)
|
||||
Advance();
|
||||
|
||||
if(!needBuffering){
|
||||
@@ -242,11 +251,11 @@ void JitterBuffer::PutInternal(jitter_packet_t* pkt){
|
||||
}
|
||||
|
||||
if(pkt->timestamp<nextTimestamp){
|
||||
LOGW("jitter: would drop packet with timestamp %d because it is late but not hopelessly", pkt->timestamp);
|
||||
//LOGW("jitter: would drop packet with timestamp %d because it is late but not hopelessly", pkt->timestamp);
|
||||
latePacketCount++;
|
||||
lostPackets--;
|
||||
}else if(pkt->timestamp<nextTimestamp-1){
|
||||
LOGW("jitter: dropping packet with timestamp %d because it is too late", pkt->timestamp);
|
||||
//LOGW("jitter: dropping packet with timestamp %d because it is too late", pkt->timestamp);
|
||||
latePacketCount++;
|
||||
return;
|
||||
}
|
||||
@@ -280,7 +289,9 @@ void JitterBuffer::PutInternal(jitter_packet_t* pkt){
|
||||
memcpy(slots[i].buffer, pkt->buffer, pkt->size);
|
||||
else
|
||||
LOGE("WTF!!");
|
||||
//fprintf(dump, "%f %d\n", time-prevRecvTime, GetCurrentDelay());
|
||||
#ifdef TGVOIP_DUMP_JITTER_STATS
|
||||
fprintf(dump, "%u\t%.03f\t%d\t%.03f\t%.03f\t%.03f\n", pkt->timestamp, time, GetCurrentDelay(), lastMeasuredJitter, lastMeasuredDelay, minDelay);
|
||||
#endif
|
||||
prevRecvTime=time;
|
||||
}
|
||||
|
||||
@@ -290,8 +301,8 @@ void JitterBuffer::Advance(){
|
||||
}
|
||||
|
||||
|
||||
int JitterBuffer::GetCurrentDelay(){
|
||||
int delay=0;
|
||||
unsigned int JitterBuffer::GetCurrentDelay(){
|
||||
unsigned int delay=0;
|
||||
int i;
|
||||
for(i=0;i<JITTER_SLOT_COUNT;i++){
|
||||
if(slots[i].buffer!=NULL)
|
||||
@@ -301,11 +312,9 @@ int JitterBuffer::GetCurrentDelay(){
|
||||
}
|
||||
|
||||
void JitterBuffer::Tick(){
|
||||
lock_mutex(mutex);
|
||||
MutexGuard m(mutex);
|
||||
int i;
|
||||
|
||||
int count=0;
|
||||
|
||||
memmove(&lateHistory[1], lateHistory, 63*sizeof(int));
|
||||
lateHistory[0]=latePacketCount;
|
||||
latePacketCount=0;
|
||||
@@ -329,26 +338,6 @@ void JitterBuffer::Tick(){
|
||||
if(avgLate16>=resyncThreshold){
|
||||
wasReset=true;
|
||||
}
|
||||
/*if(avgLate16>=0.3){
|
||||
if(dontIncMinDelay==0 && minDelay<15){
|
||||
minDelay++;
|
||||
if(GetCurrentDelay()<minDelay)
|
||||
nextTimestamp-=(minDelay-GetCurrentDelay());
|
||||
dontIncMinDelay=16;
|
||||
dontDecMinDelay+=128;
|
||||
}
|
||||
}else if(absolutelyNoLatePackets){
|
||||
if(dontDecMinDelay>0)
|
||||
dontDecMinDelay--;
|
||||
if(dontDecMinDelay==0 && minDelay>minMinDelay){
|
||||
minDelay--;
|
||||
dontDecMinDelay=64;
|
||||
dontIncMinDelay+=16;
|
||||
}
|
||||
}
|
||||
|
||||
if(dontIncMinDelay>0)
|
||||
dontIncMinDelay--;*/
|
||||
|
||||
if(absolutelyNoLatePackets){
|
||||
if(dontDecMinDelay>0)
|
||||
@@ -444,7 +433,6 @@ void JitterBuffer::Tick(){
|
||||
|
||||
tickCount++;
|
||||
|
||||
unlock_mutex(mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -468,10 +456,9 @@ void JitterBuffer::GetAverageLateCount(double *out){
|
||||
|
||||
|
||||
int JitterBuffer::GetAndResetLostPacketCount(){
|
||||
lock_mutex(mutex);
|
||||
MutexGuard m(mutex);
|
||||
int r=lostPackets;
|
||||
lostPackets=0;
|
||||
unlock_mutex(mutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user