From 461c584982c1862036dad985838fb069a9870a5f Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 20 May 2006 13:01:07 +0000 Subject: Set media thread in siprtp samples to highest priority to make RTCP jitter calculation as accurate as possible git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@460 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/samples/siprtp.c | 54 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'pjsip-apps') diff --git a/pjsip-apps/src/samples/siprtp.c b/pjsip-apps/src/samples/siprtp.c index 46d6cba0..e2891abc 100644 --- a/pjsip-apps/src/samples/siprtp.c +++ b/pjsip-apps/src/samples/siprtp.c @@ -80,7 +80,7 @@ static const char *USAGE = #define THIS_FILE "siprtp.c" #define MAX_CALLS 1024 -#define RTP_START_PORT 44100 +#define RTP_START_PORT 4000 /* Codec descriptor: */ @@ -367,12 +367,6 @@ static void destroy_sip() pjsip_endpt_destroy(app.sip_endpt); app.sip_endpt = NULL; } - - if (app.pool) { - pj_pool_release(app.pool); - app.pool = NULL; - pj_caching_pool_destroy(&app.cp); - } } @@ -430,11 +424,10 @@ static pj_status_t init_media() * to current port number. */ retry = 0; - do { + status = -1; + for (retry=0; status!=PJ_SUCCESS && retry<100; ++retry,rtp_port+=2) { struct media_stream *m = &app.call[i].media[0]; - ++retry; - rtp_port += 2; m->port = rtp_port; /* Create and bind RTP socket */ @@ -465,7 +458,7 @@ static pj_status_t init_media() continue; } - } while (status != PJ_SUCCESS && retry < 100); + } if (status != PJ_SUCCESS) goto on_error; @@ -868,7 +861,7 @@ static pj_status_t init_options(int argc, char *argv[]) app.max_calls = 1; app.thread_count = 1; app.sip_port = 5060; - app.rtp_start_port = 4000; + app.rtp_start_port = RTP_START_PORT; app.local_addr = ip_addr; app.log_level = 5; app.app_log_level = 3; @@ -1061,6 +1054,18 @@ static pj_status_t create_sdp( pj_pool_t *pool, } +#if defined(PJ_WIN32) && PJ_WIN32 != 0 +#include +static void boost_priority(void) +{ + SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); +} + +#else +# define boost_priority() +#endif + /* * Media thread * @@ -1074,6 +1079,11 @@ static int media_thread(void *arg) unsigned msec_interval; pj_timestamp freq, next_rtp, next_rtcp; + + /* Boost thread priority if necessary */ + boost_priority(); + + msec_interval = strm->samples_per_frame * 1000 / strm->clock_rate; pj_get_timestamp_freq(&freq); @@ -1116,6 +1126,11 @@ static int media_thread(void *arg) rc = pj_sock_select(FD_SETSIZE, &set, NULL, NULL, &timeout); + if (rc < 0) { + pj_thread_sleep(10); + continue; + } + if (rc > 0 && PJ_FD_ISSET(strm->rtp_sock, &set)) { /* @@ -1131,6 +1146,7 @@ static int media_thread(void *arg) status = pj_sock_recv(strm->rtp_sock, packet, &size, 0); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "RTP recv() error", status); + pj_thread_sleep(10); continue; } @@ -1163,9 +1179,10 @@ static int media_thread(void *arg) size = sizeof(packet); status = pj_sock_recv( strm->rtcp_sock, packet, &size, 0); - if (status != PJ_SUCCESS) + if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Error receiving RTCP packet", status); - else + pj_thread_sleep(10); + } else pjmedia_rtcp_rx_rtcp(&strm->rtcp, packet, size); } @@ -1704,8 +1721,15 @@ int main(int argc, char *argv[]) /* Shutting down... */ - destroy_media(); destroy_sip(); + destroy_media(); + + if (app.pool) { + pj_pool_release(app.pool); + app.pool = NULL; + pj_caching_pool_destroy(&app.cp); + } + app_logging_shutdown(); -- cgit v1.2.3