oRTP  0.25.0
include/ortp/event.h
00001  /*
00002   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
00003   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #ifndef ortp_events_h
00021 #define ortp_events_h
00022 
00023 #include <ortp/str_utils.h>
00024 #include <ortp/rtcp.h>
00025 
00026 typedef mblk_t OrtpEvent;
00027 
00028 typedef unsigned long OrtpEventType;
00029 
00030 typedef enum {
00031         OrtpRTPSocket,
00032         OrtpRTCPSocket
00033 } OrtpSocketType;
00034 
00035 struct _OrtpEventData{
00036         mblk_t *packet; /* most events are associated to a received packet */
00037         struct sockaddr_storage source_addr;
00038         socklen_t source_addrlen;
00039         ortpTimeSpec ts;
00040         union {
00041                 int telephone_event;
00042                 int payload_type;
00043                 bool_t dtls_stream_encrypted;
00044                 bool_t zrtp_stream_encrypted;
00045                 struct _ZrtpSas{
00046                         char sas[32]; // up to 31 + null characters
00047                         bool_t verified;
00048                 } zrtp_sas;
00049                 OrtpSocketType socket_type;
00050                 bool_t ice_processing_successful;
00051                 uint64_t tmmbr_mxtbr;
00052                 uint32_t received_rtt_character;
00053         } info;
00054 };
00055 
00056 typedef struct _OrtpEventData OrtpEventData;
00057 
00058 
00059 
00060 #ifdef __cplusplus
00061 extern "C"{
00062 #endif
00063 
00064 ORTP_PUBLIC OrtpEvent * ortp_event_new(OrtpEventType tp);
00065 ORTP_PUBLIC OrtpEventType ortp_event_get_type(const OrtpEvent *ev);
00066 /* type is one of the following*/
00067 #define ORTP_EVENT_STUN_PACKET_RECEIVED         1
00068 #define ORTP_EVENT_PAYLOAD_TYPE_CHANGED         2
00069 #define ORTP_EVENT_TELEPHONE_EVENT              3
00070 #define ORTP_EVENT_RTCP_PACKET_RECEIVED         4 
00071 #define ORTP_EVENT_RTCP_PACKET_EMITTED          5 
00072 #define ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED      6
00073 #define ORTP_EVENT_ZRTP_SAS_READY               7
00074 #define ORTP_EVENT_ICE_CHECK_LIST_PROCESSING_FINISHED   8
00075 #define ORTP_EVENT_ICE_SESSION_PROCESSING_FINISHED      9
00076 #define ORTP_EVENT_ICE_GATHERING_FINISHED               10
00077 #define ORTP_EVENT_ICE_LOSING_PAIRS_COMPLETED           11
00078 #define ORTP_EVENT_ICE_RESTART_NEEDED                   12
00079 #define ORTP_EVENT_DTLS_ENCRYPTION_CHANGED              13
00080 #define ORTP_EVENT_TMMBR_RECEIVED               14
00081 #define ORTP_EVENT_RTT_CHARACTER_RECEIVED               15
00082 
00083 ORTP_PUBLIC OrtpEventData * ortp_event_get_data(OrtpEvent *ev);
00084 ORTP_PUBLIC void ortp_event_destroy(OrtpEvent *ev);
00085 ORTP_PUBLIC OrtpEvent *ortp_event_dup(OrtpEvent *ev);
00086 
00087 typedef struct OrtpEvQueue{
00088         queue_t q;
00089         ortp_mutex_t mutex;
00090 } OrtpEvQueue;
00091 
00092 ORTP_PUBLIC OrtpEvQueue * ortp_ev_queue_new(void);
00093 ORTP_PUBLIC void ortp_ev_queue_destroy(OrtpEvQueue *q);
00094 ORTP_PUBLIC OrtpEvent * ortp_ev_queue_get(OrtpEvQueue *q);
00095 ORTP_PUBLIC void ortp_ev_queue_flush(OrtpEvQueue * qp);
00096 
00097 struct _RtpSession;
00098 
00106 typedef void (*OrtpEvDispatcherCb)(const OrtpEventData *evd, void *user_data);
00107 typedef struct OrtpEvDispatcherData{
00108         OrtpEventType type;
00109         rtcp_type_t subtype;
00110         OrtpEvDispatcherCb on_found;
00111         void* user_data;
00112 } OrtpEvDispatcherData;
00113 
00114 typedef struct OrtpEvDispatcher{
00115         OrtpEvQueue *q;
00116         struct _RtpSession* session;
00117         OList *cbs;
00118 } OrtpEvDispatcher;
00119 
00129 ORTP_PUBLIC OrtpEvDispatcher * ortp_ev_dispatcher_new(struct _RtpSession* session);
00136 ORTP_PUBLIC void ortp_ev_dispatcher_destroy(OrtpEvDispatcher *d);
00144 ORTP_PUBLIC void ortp_ev_dispatcher_iterate(OrtpEvDispatcher *d);
00158 ORTP_PUBLIC void ortp_ev_dispatcher_connect(OrtpEvDispatcher *d
00159                                                                                         , OrtpEventType type
00160                                                                                         , rtcp_type_t subtype
00161                                                                                         , OrtpEvDispatcherCb on_receive
00162                                                                                         , void *user_data);
00163 
00167 void ortp_ev_dispatcher_disconnect(OrtpEvDispatcher *d
00168                                                                 , OrtpEventType type
00169                                                                 , rtcp_type_t subtype
00170                                                                 , OrtpEvDispatcherCb cb);
00171 
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 
00176 #endif
00177