www.pudn.com > streamrtp.rar > rtprecvthreadfcn.c


/*-------------------------------------------------------------------------
 * rtprecvthreadfcn.c - rtprecvthreadfcn
 *-------------------------------------------------------------------------
 */

#include 
#include 
#include 
#include 
#include 

/*------------------------------------------------------------------------
 * rtprecvthreadfcn - loop to receive RTP packets.
 *------------------------------------------------------------------------
 */
void
rtprecvthreadfcn(struct session *psn)
{

	/*
	 * 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_rtpthrmutex);

	signal(SIGTERM, nullfcn);
	psn->sn_rtpthrstat = THR_RUNNING;
	pthread_cond_signal(&psn->sn_cond);

	pthread_mutex_unlock(&psn->sn_rtpthrmutex);

	while(TRUE) {

		rtprecv(psn);

		/*
		 * Check if a SIGTERM has been received.
		 * If so, return.
		 */
		pthread_mutex_lock(&psn->sn_rtpthrmutex);
		if (psn->sn_rtpthrstat == THR_TERMINATE) {
			psn->sn_rtpthrstat = THR_NOTRUNNING;
			pthread_cond_signal(&psn->sn_cond);
			pthread_mutex_unlock(&psn->sn_rtpthrmutex);
			return;
		}
		pthread_mutex_unlock(&psn->sn_rtpthrmutex);
	}
}