Commit 64407ca9 authored by Simon Morlat's avatar Simon Morlat

fix outbound controlled mode of network simulator

parent e19a11e0
......@@ -313,6 +313,7 @@ ORTP_PUBLIC char *ortp_strcat_vprintf(char *dst, const char *fmt, va_list ap);
ORTP_PUBLIC int ortp_file_exist(const char *pathname);
ORTP_PUBLIC void ortp_get_cur_time(ortpTimeSpec *ret);
void _ortp_get_cur_time(ortpTimeSpec *ret, bool_t realtime);
ORTP_PUBLIC uint64_t ortp_get_cur_time_ms(void);
ORTP_PUBLIC void ortp_sleep_ms(int ms);
ORTP_PUBLIC void ortp_sleep_until(const ortpTimeSpec *ts);
......
......@@ -102,7 +102,7 @@ static void * outboud_simulator_thread(void *ctx){
sleep_until.tv_sec=0;
sleep_until.tv_nsec=0;
rtp_session_schedule_outbound_network_simulator(session, &sleep_until);
if (sleep_until.tv_sec!=0 || sleep_until.tv_nsec!=0 ) ortp_sleep_until(&sleep_until);
if (sleep_until.tv_sec!=0) ortp_sleep_until(&sleep_until);
else ortp_sleep_ms(1);
}
return NULL;
......@@ -145,7 +145,7 @@ void rtp_session_enable_network_simulation(RtpSession *session, const OrtpNetwor
sim->params.max_buffer_size=sim->params.max_bandwidth;
ortp_message("Network simulation: Max buffer size not set for RTP session [%p], using [%i]",session,sim->params.max_buffer_size);
}
if (params->mode==OrtpNetworkSimulatorOutbound && !sim->thread_started){
if ((params->mode==OrtpNetworkSimulatorOutbound || params->mode==OrtpNetworkSimulatorOutboundControlled) && !sim->thread_started){
sim->thread_started=TRUE;
ortp_thread_create(&sim->thread, NULL, outboud_simulator_thread, session);
}
......@@ -394,7 +394,7 @@ static void rtp_session_schedule_outbound_network_simulator(RtpSession *session,
}
}else if (session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutboundControlled){
#if defined(ORTP_TIMESTAMP)
ortpTimeSpec current;
ortpTimeSpec current={0};
ortpTimeSpec packet_time;
mblk_t *todrop=NULL;
ortp_mutex_lock(&session->net_sim_ctx->mutex);
......@@ -404,7 +404,7 @@ static void rtp_session_schedule_outbound_network_simulator(RtpSession *session,
freemsg(todrop); /*free the last message while the mutex is not held*/
todrop=NULL;
}
ortp_get_cur_time(&current);
_ortp_get_cur_time(&current,TRUE);
packet_time.tv_sec=om->timestamp.tv_sec;
packet_time.tv_nsec=om->timestamp.tv_usec*1000LL;
if (om->timestamp.tv_sec==0 && om->timestamp.tv_usec==0){
......@@ -416,6 +416,7 @@ static void rtp_session_schedule_outbound_network_simulator(RtpSession *session,
}else {
/*no packet is to be sent yet; set the time at which we want to be called*/
*sleep_until=packet_time;
ortp_mutex_lock(&session->net_sim_ctx->mutex);
break;
}
ortp_mutex_lock(&session->net_sim_ctx->mutex);
......@@ -424,10 +425,12 @@ static void rtp_session_schedule_outbound_network_simulator(RtpSession *session,
ortp_mutex_unlock(&session->net_sim_ctx->mutex);
if (todrop) freemsg(todrop);
if (sleep_until->tv_sec==0){
/*no packet in the queue yet, schedule a wake up not too far*/
_ortp_get_cur_time(&current,TRUE);
/*no pending packet in the queue yet, schedule a wake up not too far*/
sleep_until->tv_sec=current.tv_sec;
sleep_until->tv_nsec=current.tv_nsec+1000000LL; /*in 1 ms*/
}
#else
ortp_mutex_lock(&session->net_sim_ctx->mutex);
while((om=getq(&session->net_sim_ctx->send_q))!=NULL){
......@@ -436,6 +439,7 @@ static void rtp_session_schedule_outbound_network_simulator(RtpSession *session,
ortp_error("Network simulator is in mode OrtpNetworkSimulatorOutboundControlled but oRTP wasn't compiled with --enable-ntp-timestamp.");
ortp_mutex_lock(&session->net_sim_ctx->mutex);
}
ortp_mutex_unlock(&session->net_sim_ctx->mutex);
#endif
}
}
......
......@@ -712,7 +712,7 @@ void ortp_shm_close(void *mem){
#include <sys/timeb.h>
#endif
void ortp_get_cur_time(ortpTimeSpec *ret){
void _ortp_get_cur_time(ortpTimeSpec *ret, bool_t realtime){
#if defined(_WIN32_WCE) || defined(WIN32)
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
DWORD timemillis;
......@@ -741,7 +741,7 @@ void ortp_get_cur_time(ortpTimeSpec *ret){
ret->tv_nsec = time_val.millitm * 1000000LL;
#else
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC,&ts)<0){
if (clock_gettime(realtime ? CLOCK_REALTIME : CLOCK_MONOTONIC,&ts)<0){
ortp_fatal("clock_gettime() doesn't work: %s",strerror(errno));
}
ret->tv_sec=ts.tv_sec;
......@@ -749,6 +749,11 @@ void ortp_get_cur_time(ortpTimeSpec *ret){
#endif
}
void ortp_get_cur_time(ortpTimeSpec *ret){
return _ortp_get_cur_time(ret, FALSE);
}
uint64_t ortp_get_cur_time_ms(void) {
ortpTimeSpec ts;
ortp_get_cur_time(&ts);
......@@ -767,8 +772,8 @@ void ortp_sleep_ms(int ms){
#endif
#else
struct timespec ts;
ts.tv_sec=0;
ts.tv_nsec=ms*1000000LL;
ts.tv_sec=ms/1000;
ts.tv_nsec=(ms%1000)*1000000LL;
nanosleep(&ts,NULL);
#endif
}
......@@ -783,7 +788,7 @@ void ortp_sleep_until(const ortpTimeSpec *ts){
#else
ortpTimeSpec current;
ortpTimeSpec diff;
ortp_get_cur_time(&current);
_ortp_get_cur_time(&current, TRUE);
diff.tv_sec=ts->tv_sec-current.tv_sec;
diff.tv_nsec=ts->tv_nsec-current.tv_nsec;
if (diff.tv_nsec<0){
......
......@@ -1025,7 +1025,8 @@ int _ortp_sendto(ortp_socket_t sockfd, mblk_t *m, int flags, const struct sockad
int _rtp_session_sendto(RtpSession *session, bool_t is_rtp, mblk_t *m, int flags, const struct sockaddr *destaddr, socklen_t destlen){
int ret;
if (session->net_sim_ctx && session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutbound){
if (session->net_sim_ctx && (session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutbound
|| session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutboundControlled)){
ret=msgdsize(m);
m=dupmsg(m);
memcpy(&m->net_addr,destaddr,destlen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment