mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-06 13:07:21 +00:00
Correct timestamp calculations when RTP sample rates over 8kHz are used.
While testing some endpoints that support 16kHz and 32kHz sample rates, some log messages were generated due to calc_rxstamp() computing timestamps in a way that produced odd results, so this patch sanitizes the result of the computations. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@224670 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
23
main/rtp.c
23
main/rtp.c
@@ -1045,6 +1045,18 @@ struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sanitize_tv(struct timeval *tv)
|
||||||
|
{
|
||||||
|
while (tv->tv_usec < 0) {
|
||||||
|
tv->tv_usec += 1000000;
|
||||||
|
tv->tv_sec -= 1;
|
||||||
|
}
|
||||||
|
while (tv->tv_usec >= 1000000) {
|
||||||
|
tv->tv_usec -= 1000000;
|
||||||
|
tv->tv_sec += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
|
static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
@@ -1064,21 +1076,14 @@ static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int t
|
|||||||
rtp->rxcore.tv_usec -= (timestamp % rate) * 125;
|
rtp->rxcore.tv_usec -= (timestamp % rate) * 125;
|
||||||
/* Round to 0.1ms for nice, pretty timestamps */
|
/* Round to 0.1ms for nice, pretty timestamps */
|
||||||
rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100;
|
rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100;
|
||||||
if (rtp->rxcore.tv_usec < 0) {
|
sanitize_tv(&rtp->rxcore);
|
||||||
/* Adjust appropriately if necessary */
|
|
||||||
rtp->rxcore.tv_usec += 1000000;
|
|
||||||
rtp->rxcore.tv_sec -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&now,NULL);
|
gettimeofday(&now,NULL);
|
||||||
/* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */
|
/* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */
|
||||||
tv->tv_sec = rtp->rxcore.tv_sec + timestamp / rate;
|
tv->tv_sec = rtp->rxcore.tv_sec + timestamp / rate;
|
||||||
tv->tv_usec = rtp->rxcore.tv_usec + (timestamp % rate) * 125;
|
tv->tv_usec = rtp->rxcore.tv_usec + (timestamp % rate) * 125;
|
||||||
if (tv->tv_usec >= 1000000) {
|
sanitize_tv(tv);
|
||||||
tv->tv_usec -= 1000000;
|
|
||||||
tv->tv_sec += 1;
|
|
||||||
}
|
|
||||||
prog = (double)((timestamp-rtp->seedrxts)/(float)(rate));
|
prog = (double)((timestamp-rtp->seedrxts)/(float)(rate));
|
||||||
dtv = (double)rtp->drxcore + (double)(prog);
|
dtv = (double)rtp->drxcore + (double)(prog);
|
||||||
current_time = (double)now.tv_sec + (double)now.tv_usec/1000000;
|
current_time = (double)now.tv_sec + (double)now.tv_usec/1000000;
|
||||||
|
Reference in New Issue
Block a user