www.pudn.com > RTP通用开发库(for Linux).rar > event.h
/*------------------------------------------------------------------------- * event.h - BIT_SET, SET_BIT, UNSET_BIT *------------------------------------------------------------------------- */ #ifndef EVENT_H #define EVENT_H #include#include #include #include #include /* event types; comment describes data included in event */ #define EVENT_RTP_HEAD 0 /* none */ #define EVENT_RTP 1 /* none */ #define EVENT_RTCP_SR 2 /* SR packet (inc RTCP hdr) */ #define EVENT_RTCP_RR 3 /* RR packet (inc RTCP hdr) */ #define EVENT_RTCP_BYE 4 /* reason string */ #define EVENT_RTCP_APP 5 /* APP Packet (inc RTCP hdr) */ #define EVENT_RTCP_SDES_CHUNK 6 /* chunk (inc SSRC) */ /* SDES item events are sent only when the item value changes */ #define EVENT_RTCP_SDES_CNAME 7 /* none */ #define EVENT_RTCP_SDES_NAME 8 /* none */ #define EVENT_RTCP_SDES_EMAIL 9 /* none */ #define EVENT_RTCP_SDES_PHONE 10 /* none */ #define EVENT_RTCP_SDES_LOC 11 /* none */ #define EVENT_RTCP_SDES_TOOL 12 /* none */ #define EVENT_RTCP_SDES_NOTE 13 /* none */ #define EVENT_RTCP_SDES_PRIV 14 /* none */ #define EVENT_PARTICIPANT_TIMEOUT 15 /* none */ #define EVENT_PARTICIPANT_ENCODING 16 /* none */ #define EVENT_PARTICIPANT_NEW 17 /* none */ #define EVENT_PARTICIPANT_SEQGAP 18 /* none */ #define EVENT_PARTICIPANT_SYNC 19 /* sstm_clky adjustment */ #define EVENT_COLLISION 20 /* none */ #define EVENT_NOBUFS 21 /* none */ #define EVENT_TYPES 22 #define EVENT_VECTOR_SZ ((EVENT_TYPES / 8) + (EVENT_TYPES % 8 != 0 ? 1 : 0)) #define BIT_SET(pchar, bit) ((pchar[bit / 8] & (1 << (7 - (bit % 8)))) != 0) #define SET_BIT(pchar, bit) (pchar[bit / 8] |= 1 << (7 - (bit % 8))) #define UNSET_BIT(pchar, bit) (pchar[bit / 8] &= ~(1 << (7 - (bit % 8)))) /* structure for an event */ struct event { int ev_type; /* type of event */ ssrc_t ev_ssrc; /* SSRC to which event pertains */ struct timespec ev_time; /* localtime event generated */ struct event *ev_next; /* pointer to next event in q */ int ev_datalen; /* length of data */ char ev_data[1]; /* beginning of data */ }; #define EVENT_QUEUE_HT_SZ 11 #define EVENT_DEFAULTBPBUFSZ 1024 #define EVENT_DEFAULTBPBUFCOUNT 32 /* structure for an event queue */ struct eventqueue { char eq_wantall[EVENT_VECTOR_SZ]; /* bitvect for events wanted from any SSRC */ struct event *eq_eventtail; /* newest event in queue */ struct event *eq_eventhead; /* oldest event in queue */ pthread_mutex_t eq_eventqueuemutex; /* mutex to lock queue */ sem_t eq_eventsem; /* semaphore to impl blocking */ int eq_eventblock; /* true if nextevent should block */ struct ht *eq_ssrcs; /* hashtable ssrc -> bitvector */ struct bufpool eq_bpool; }; /* Event API calls */ int eventqnext(struct eventqueue *, struct event *, int); int eventqpost(struct eventqueue *, int, ssrc_t, void *, int); int eventqinit(struct eventqueue *, int, bool, int, int); int eventqfilterssrc(struct eventqueue *, int, ssrc_t, bool); int eventqfilterall(struct eventqueue *, int, bool); int eventqdestroy(struct eventqueue *); int eventqclear(struct eventqueue *); /* Internal calls */ bool eventqwant(struct eventqueue *, int, ssrc_t); int eventqenqueue(struct eventqueue *, struct event *); struct event *eventqdequeue(struct eventqueue *); #endif