handle packetloss properly.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4382 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
2ed1053e66
commit
cb8e23709a
1 changed files with 41 additions and 38 deletions
|
@ -563,6 +563,33 @@ void S_Voip_Decode(unsigned int sender, unsigned int codec, unsigned int gen, un
|
||||||
s_voip.decseq[sender] = seq;
|
s_voip.decseq[sender] = seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//if there's packetloss, tell the decoder about the missing parts.
|
||||||
|
//no infinite loops please.
|
||||||
|
if ((unsigned)(seq - s_voip.decseq[sender]) > 10)
|
||||||
|
s_voip.decseq[sender] = seq - 10;
|
||||||
|
while(s_voip.decseq[sender] != seq)
|
||||||
|
{
|
||||||
|
if (decodesamps + s_voip.decframesize[sender] > sizeof(decodebuf)/sizeof(decodebuf[0]))
|
||||||
|
{
|
||||||
|
S_RawAudio(sender, (qbyte*)decodebuf, s_voip.decsamplerate[sender], decodesamps, 1, 2, cl_voip_play.value);
|
||||||
|
decodesamps = 0;
|
||||||
|
}
|
||||||
|
switch(codec)
|
||||||
|
{
|
||||||
|
case VOIP_SPEEX:
|
||||||
|
qspeex_decode_int(s_voip.decoder[sender], NULL, decodebuf + decodesamps);
|
||||||
|
decodesamps += s_voip.decframesize[sender];
|
||||||
|
break;
|
||||||
|
case VOIP_OPUS:
|
||||||
|
r = qopus_decode(s_voip.decoder[sender], NULL, 0, decodebuf + decodesamps, sizeof(decodebuf)/sizeof(decodebuf[0]) - decodesamps, false);
|
||||||
|
if (r > 0)
|
||||||
|
decodesamps += r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s_voip.decseq[sender]++;
|
||||||
|
}
|
||||||
|
|
||||||
while (bytes > 0)
|
while (bytes > 0)
|
||||||
{
|
{
|
||||||
if (decodesamps + s_voip.decframesize[sender] > sizeof(decodebuf)/sizeof(decodebuf[0]))
|
if (decodesamps + s_voip.decframesize[sender] > sizeof(decodebuf)/sizeof(decodebuf[0]))
|
||||||
|
@ -576,58 +603,34 @@ void S_Voip_Decode(unsigned int sender, unsigned int codec, unsigned int gen, un
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
break;
|
break;
|
||||||
case VOIP_SPEEX:
|
case VOIP_SPEEX:
|
||||||
if (s_voip.decseq[sender] != seq)
|
bytes--;
|
||||||
{
|
len = *start++;
|
||||||
//tell speex about missing packets
|
if (bytes < len)
|
||||||
qspeex_decode_int(s_voip.decoder[sender], NULL, decodebuf + decodesamps);
|
break;
|
||||||
drops++;
|
qspeex_bits_read_from(&s_voip.speex.decbits[sender], start, len);
|
||||||
s_voip.decseq[sender]++;
|
bytes -= len;
|
||||||
}
|
start += len;
|
||||||
else
|
qspeex_decode_int(s_voip.decoder[sender], &s_voip.speex.decbits[sender], decodebuf + decodesamps);
|
||||||
{
|
|
||||||
//yay, we got data
|
|
||||||
bytes--;
|
|
||||||
len = *start++;
|
|
||||||
if (bytes < len)
|
|
||||||
break;
|
|
||||||
qspeex_bits_read_from(&s_voip.speex.decbits[sender], start, len);
|
|
||||||
bytes -= len;
|
|
||||||
start += len;
|
|
||||||
qspeex_decode_int(s_voip.decoder[sender], &s_voip.speex.decbits[sender], decodebuf + decodesamps);
|
|
||||||
newseq++;
|
|
||||||
}
|
|
||||||
decodesamps += s_voip.decframesize[sender];
|
decodesamps += s_voip.decframesize[sender];
|
||||||
break;
|
break;
|
||||||
case VOIP_OPUS:
|
case VOIP_OPUS:
|
||||||
bytes--;
|
bytes--;
|
||||||
len = *start++;
|
len = *start++;
|
||||||
if (bytes < len)
|
if (bytes < len)
|
||||||
break;
|
break;
|
||||||
|
r = qopus_decode(s_voip.decoder[sender], start, len, decodebuf + decodesamps, sizeof(decodebuf)/sizeof(decodebuf[0]) - decodesamps, false);
|
||||||
// len = bytes;
|
|
||||||
|
|
||||||
if (s_voip.decseq[sender] != seq)
|
|
||||||
{
|
|
||||||
r = qopus_decode(s_voip.decoder[sender], NULL, len, decodebuf + decodesamps, sizeof(decodebuf)/sizeof(decodebuf[0]) - decodesamps, false);
|
|
||||||
drops++;
|
|
||||||
s_voip.decseq[sender]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = qopus_decode(s_voip.decoder[sender], start, len, decodebuf + decodesamps, sizeof(decodebuf)/sizeof(decodebuf[0]) - decodesamps, false);
|
|
||||||
newseq++;
|
|
||||||
}
|
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
decodesamps += r;
|
decodesamps += r;
|
||||||
|
else if (r < 0)
|
||||||
|
Con_Printf("Opus decoding error %i\n", r);
|
||||||
|
|
||||||
bytes -= len;
|
bytes -= len;
|
||||||
start += len;
|
start += len;
|
||||||
|
|
||||||
s_voip.decseq[sender] = seq + 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
s_voip.decseq[sender]++;
|
||||||
|
seq++;
|
||||||
}
|
}
|
||||||
s_voip.decseq[sender] += newseq;
|
|
||||||
|
|
||||||
if (drops)
|
if (drops)
|
||||||
Con_DPrintf("%i dropped audio frames\n", drops);
|
Con_DPrintf("%i dropped audio frames\n", drops);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue