2 The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3 Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ortp/event.h"
21 #include "ortp/ortp.h"
23 RtpEndpoint *rtp_endpoint_new(struct sockaddr *addr, socklen_t addrlen){
24 RtpEndpoint *ep=ortp_new(RtpEndpoint,1);
25 if (sizeof(ep->addr)<addrlen){
27 ortp_fatal("Bad socklen_t size !");
30 memcpy(&ep->addr,addr,addrlen);
35 void rtp_endpoint_destroy(RtpEndpoint *ep){
39 RtpEndpoint *rtp_endpoint_dup(const RtpEndpoint *ep){
40 return rtp_endpoint_new((struct sockaddr*)&ep->addr,ep->addrlen);
43 OrtpEvent * ortp_event_new(unsigned long type){
44 const int size=sizeof(OrtpEventType)+sizeof(OrtpEventData);
45 mblk_t *m=allocb(size,0);
46 memset(m->b_wptr,0,size);
47 *((OrtpEventType*)m->b_wptr)=type;
51 OrtpEvent *ortp_event_dup(OrtpEvent *ev){
53 OrtpEvent *nev=dupb(ev);
55 OrtpEvent *nev = ortp_event_new(ortp_event_get_type(ev));
56 OrtpEventData * ed = ortp_event_get_data(ev);
57 OrtpEventData * edv = ortp_event_get_data(nev);
59 if (ed->ep) edv->ep = rtp_endpoint_dup(ed->ep);
60 if (ed->packet) edv->packet = copymsg(ed->packet);
61 edv->info.telephone_event = ed->info.telephone_event;
66 OrtpEventType ortp_event_get_type(const OrtpEvent *ev){
67 return ((OrtpEventType*)ev->b_rptr)[0];
70 OrtpEventData * ortp_event_get_data(OrtpEvent *ev){
71 return (OrtpEventData*)(ev->b_rptr+sizeof(OrtpEventType));
74 void ortp_event_destroy(OrtpEvent *ev){
75 OrtpEventData *d=ortp_event_get_data(ev);
76 if (ev->b_datap->db_ref==1){
77 if (d->packet) freemsg(d->packet);
78 if (d->ep) rtp_endpoint_destroy(d->ep);
83 OrtpEvQueue * ortp_ev_queue_new(){
84 OrtpEvQueue *q=ortp_new(OrtpEvQueue,1);
86 ortp_mutex_init(&q->mutex,NULL);
90 void ortp_ev_queue_flush(OrtpEvQueue * qp){
92 while((ev=ortp_ev_queue_get(qp))!=NULL){
93 ortp_event_destroy(ev);
97 OrtpEvent * ortp_ev_queue_get(OrtpEvQueue *q){
99 ortp_mutex_lock(&q->mutex);
101 ortp_mutex_unlock(&q->mutex);
105 void ortp_ev_queue_destroy(OrtpEvQueue * qp){
106 ortp_ev_queue_flush(qp);
107 ortp_mutex_destroy(&qp->mutex);
111 void ortp_ev_queue_put(OrtpEvQueue *q, OrtpEvent *ev){
112 ortp_mutex_lock(&q->mutex);
114 ortp_mutex_unlock(&q->mutex);