www.pudn.com > streamrtp.rar > rtcpcyclethreadfcn.c
/*------------------------------------------------------------------------- * rtcpcyclethreadfcn.c - rtcpcyclethreadfcn *------------------------------------------------------------------------- */ #include#include #include #include #include #include #include /*------------------------------------------------------------------------- * rtcpcyclethreadfcn - loop and invoke rtcpcycle at appropriate interval. *------------------------------------------------------------------------- */ void rtcpcyclethreadfcn(struct session *psn) { double time; /* * Initialize by setting signal handler, then signal condition to * indicate that initialization is complete. This code prevents * rtpctl from sending a SIGTERM *before* the handler is installed. */ pthread_mutex_lock(&psn->sn_rtcpcyclethrmutex); signal(SIGTERM, nullfcn); psn->sn_rtcpcyclethrstat = THR_RUNNING; pthread_cond_signal(&psn->sn_cond); pthread_mutex_unlock(&psn->sn_rtcpcyclethrmutex); /* * Compute initial interval to wait before * generating a receiver report. */ time = rtcpinitinterval(psn); while(TRUE) { usleep((unsigned int) (time * 1000000)); /* * Check if SIGTERM has been received. * If so, return. */ pthread_mutex_lock(&psn->sn_rtcpcyclethrmutex); if (psn->sn_rtcpcyclethrstat == THR_TERMINATE) { psn->sn_rtcpcyclethrstat = THR_NOTRUNNING; pthread_cond_signal(&psn->sn_cond); pthread_mutex_unlock(&psn->sn_rtcpcyclethrmutex); return; } pthread_mutex_unlock(&psn->sn_rtcpcyclethrmutex); time = rtcpcycle(psn); } }