/* for high level telephony event callback */
void rtp_session_check_telephone_events(RtpSession *session, mblk_t *m0)
{
	telephone_event_t *events,*evbuf;
	int num,num2;
	int i;
	rtp_header_t *hdr;
	mblk_t *cur_tev;
	unsigned char *payload;
	int datasize;
	
	hdr=(rtp_header_t*)m0->b_rptr;
	
	datasize=rtp_get_payload(m0,&payload);

	num=datasize/sizeof(telephone_event_t);
	events=(telephone_event_t*)payload;
	
	
	if (hdr->markbit==1)
	{
		/* this is a start of new events. Store the event buffer for later use*/
		if (session->current_tev!=NULL) {
			freemsg(session->current_tev);
			session->current_tev=NULL;
		}
		session->current_tev=copymsg(m0);
		/* handle the case where the events are short enough to end within the packet that has the marker bit*/
		notify_events_ended(session,events,num);
	}
	/* whatever there is a markbit set or not, we parse the packet and compare it to previously received one */
	cur_tev=session->current_tev;
	if (cur_tev!=NULL)
	{
		/* first compare timestamp, they must be identical */
		if (((rtp_header_t*)cur_tev->b_rptr)->timestamp==
			((rtp_header_t*)m0->b_rptr)->timestamp)
		{
			datasize=rtp_get_payload(cur_tev,&payload);
			num2=datasize/sizeof(telephone_event_t);
			evbuf=(telephone_event_t*)payload;
			for (i=0;i<MIN(num,num2);i++)
			{
				if (events[i].E==1)
				{
					/* update events that have ended */
					if (evbuf[i].E==0){
						evbuf[i].E=1;
						/* this is a end of event, report it */
						notify_tev(session,&events[i]);
					}
				}
			}
		}
		else
		{
			/* timestamp are not identical: this is not the same events*/
			if (session->current_tev!=NULL) {
				freemsg(session->current_tev);
				session->current_tev=NULL;
			}
			session->current_tev=copymsg(m0);
			notify_events_ended(session,events,num);
		}
	}
	else
	{
		/* there is no pending events, but we did not received marked bit packet
		either the sending implementation is not compliant, either it has been lost, 
		we must deal with it anyway.*/
		session->current_tev=copymsg(m0);
		/* inform the application if there are tone ends */
		notify_events_ended(session,events,num);
	}
}
コード例 #2
0
/* for high level telephony event callback */
void rtp_session_check_telephone_events(RtpSession *session, mblk_t *m0)
{
	telephone_event_t *events,*evbuf;
	int num;
	int i;
	mblk_t *mp;
	rtp_header_t *hdr;
	mblk_t *cur_tev;
	
	hdr=(rtp_header_t*)m0->b_rptr;
	mp=m0->b_cont;
	
	num=(mp->b_wptr-mp->b_rptr)/sizeof(telephone_event_t);
	events=(telephone_event_t*)mp->b_rptr;
	
	
	if (hdr->markbit==1)
	{
		/* this is a start of new events. Store the event buffer for later use*/
		if (session->current_tev!=NULL) {
			freemsg(session->current_tev);
			session->current_tev=NULL;
		}
		session->current_tev=copymsg(m0);
		/* handle the case where the events are short enough to end within the packet that has the marker bit*/
		notify_events_ended(session,events,num);
	}
	/* whatever there is a markbit set or not, we parse the packet and compare it to previously received one */
	cur_tev=session->current_tev;
	if (cur_tev!=NULL)
	{
		/* first compare timestamp, they must be identical */
		if (((rtp_header_t*)cur_tev->b_rptr)->timestamp==
			((rtp_header_t*)m0->b_rptr)->timestamp)
		{
			evbuf=(telephone_event_t*)cur_tev->b_cont;
			for (i=0;i<num;i++)
			{
				if (events[i].E==1)
				{
					/* update events that have ended */
					if (evbuf[i].E==0){
						evbuf[i].E=1;
						/* this is a end of event, report it */
						rtp_signal_table_emit2(&session->on_telephone_event,(gpointer)(long)events[i].event);
					}
				}
			}
		}
		else
		{
			/* timestamp are not identical: this is not the same events*/
			if (session->current_tev!=NULL) {
				freemsg(session->current_tev);
				session->current_tev=NULL;
			}
			session->current_tev=dupmsg(m0);
		}
	}
	else
	{
		/* there is no pending events, but we did not received marked bit packet
		either the sending implementation is not compliant, either it has been lost, 
		we must deal with it anyway.*/
		session->current_tev=copymsg(m0);
		/* inform the application if there are tone ends */
		notify_events_ended(session,events,num);
	}
}