00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030 #ifndef RTPSESSION_H
00031 #define RTPSESSION_H
00032
00033
00034 #include <ortp/port.h>
00035 #include <ortp/rtp.h>
00036 #include <ortp/payloadtype.h>
00037 #include <ortp/sessionset.h>
00038 #include <ortp/rtcp.h>
00039 #include <ortp/str_utils.h>
00040 #include <ortp/rtpsignaltable.h>
00041 #include <ortp/event.h>
00042
00043
00044
00045 typedef enum {
00046 RTP_SESSION_RECVONLY,
00047 RTP_SESSION_SENDONLY,
00048 RTP_SESSION_SENDRECV
00049 } RtpSessionMode;
00050
00051
00054 typedef struct _JBParameters{
00055 int min_size;
00056 int nom_size;
00057 int max_size;
00058 bool_t adaptive;
00059 } JBParameters;
00060
00061 typedef struct _JitterControl
00062 {
00063 int jitt_comp;
00064 int jitt_comp_ts;
00065 int adapt_jitt_comp_ts;
00066 float slide;
00067 float jitter;
00068 int count;
00069 int olddiff;
00070 float inter_jitter;
00071 int corrective_step;
00072 int corrective_slide;
00073 bool_t adaptive;
00074 bool_t enabled;
00075 } JitterControl;
00076
00077 typedef struct _WaitPoint
00078 {
00079 ortp_mutex_t lock;
00080 ortp_cond_t cond;
00081 uint32_t time;
00082 bool_t wakeup;
00083 } WaitPoint;
00084
00085 typedef struct _RtpTransport
00086 {
00087 void *data;
00088 ortp_socket_t (*t_getsocket)(struct _RtpTransport *t);
00089 int (*t_sendto)(struct _RtpTransport *t, mblk_t *msg , int flags, const struct sockaddr *to, socklen_t tolen);
00090 int (*t_recvfrom)(struct _RtpTransport *t, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen);
00091 struct _RtpSession *session;
00092 } RtpTransport;
00093
00094
00095
00096 typedef struct _RtpStream
00097 {
00098 ortp_socket_t socket;
00099 struct _RtpTransport *tr;
00100 int sockfamily;
00101 int max_rq_size;
00102 int time_jump;
00103 uint32_t ts_jump;
00104 queue_t rq;
00105 queue_t tev_rq;
00106 mblk_t *cached_mp;
00107 int loc_port;
00108 #ifdef ORTP_INET6
00109 struct sockaddr_storage rem_addr;
00110 #else
00111 struct sockaddr_in rem_addr;
00112 #endif
00113 int rem_addrlen;
00114 JitterControl jittctl;
00115 uint32_t snd_time_offset;
00116 uint32_t snd_ts_offset;
00117 uint32_t snd_rand_offset;
00118 uint32_t snd_last_ts;
00119 uint32_t rcv_time_offset;
00120 uint32_t rcv_ts_offset;
00121 uint32_t rcv_query_ts_offset;
00122 uint32_t rcv_diff_ts;
00123 uint32_t hwrcv_diff_ts;
00124 uint32_t rcv_last_ts;
00125 uint32_t rcv_last_app_ts;
00126 uint32_t rcv_last_ret_ts;
00127 uint32_t hwrcv_extseq;
00128 uint32_t hwrcv_seq_at_last_SR;
00129 uint32_t hwrcv_since_last_SR;
00130 uint32_t last_rcv_SR_ts;
00131 struct timeval last_rcv_SR_time;
00132 uint16_t snd_seq;
00133 uint32_t last_rtcp_report_snt_r;
00134 uint32_t last_rtcp_report_snt_s;
00135 uint32_t rtcp_report_snt_interval;
00136 uint32_t last_rtcp_packet_count;
00137 unsigned int sent_bytes;
00138 struct timeval send_bw_start;
00139 unsigned int recv_bytes;
00140 struct timeval recv_bw_start;
00141 rtp_stats_t stats;
00142 int recv_errno;
00143 int send_errno;
00144 }RtpStream;
00145
00146 typedef struct _RtcpStream
00147 {
00148 ortp_socket_t socket;
00149 int sockfamily;
00150 struct _RtpTransport *tr;
00151
00152 mblk_t *cached_mp;
00153 #ifdef ORTP_INET6
00154 struct sockaddr_storage rem_addr;
00155 #else
00156 struct sockaddr_in rem_addr;
00157 #endif
00158 int rem_addrlen;
00159 bool_t enabled;
00160 } RtcpStream;
00161
00162 typedef struct _RtpSession RtpSession;
00163
00164
00173 struct _RtpSession
00174 {
00175 RtpSession *next;
00176 int mask_pos;
00177 struct {
00178 RtpProfile *profile;
00179 int pt;
00180 unsigned int ssrc;
00181 WaitPoint wp;
00182 int telephone_events_pt;
00183 } snd,rcv;
00184 unsigned int inc_ssrc_candidate;
00185 int inc_same_ssrc_count;
00186 int hw_recv_pt;
00187 int recv_buf_size;
00188 RtpSignalTable on_ssrc_changed;
00189 RtpSignalTable on_payload_type_changed;
00190 RtpSignalTable on_telephone_event_packet;
00191 RtpSignalTable on_telephone_event;
00192 RtpSignalTable on_timestamp_jump;
00193 RtpSignalTable on_network_error;
00194 RtpSignalTable on_rtcp_bye;
00195 struct _OList *signal_tables;
00196 struct _OList *eventqs;
00197 RtpStream rtp;
00198 RtcpStream rtcp;
00199 RtpSessionMode mode;
00200 struct _RtpScheduler *sched;
00201 uint32_t flags;
00202 int dscp;
00203 int multicast_ttl;
00204 int multicast_loopback;
00205 void * user_data;
00206
00207 struct timeval last_recv_time;
00208
00209
00210 mblk_t *current_tev;
00211 mblk_t *sd;
00212 queue_t contributing_sources;
00213 bool_t symmetric_rtp;
00214 bool_t permissive;
00215 bool_t use_connect;
00216 bool_t ssrc_set;
00217 };
00218
00219
00220
00221
00222 #ifdef __cplusplus
00223 extern "C"
00224 {
00225 #endif
00226
00227
00228 RtpSession *rtp_session_new(int mode);
00229 void rtp_session_set_scheduling_mode(RtpSession *session, int yesno);
00230 void rtp_session_set_blocking_mode(RtpSession *session, int yesno);
00231 void rtp_session_set_profile(RtpSession *session, RtpProfile *profile);
00232 void rtp_session_set_send_profile(RtpSession *session,RtpProfile *profile);
00233 void rtp_session_set_recv_profile(RtpSession *session,RtpProfile *profile);
00234 RtpProfile *rtp_session_get_profile(RtpSession *session);
00235 RtpProfile *rtp_session_get_send_profile(RtpSession *session);
00236 RtpProfile *rtp_session_get_recv_profile(RtpSession *session);
00237 int rtp_session_signal_connect(RtpSession *session,const char *signal_name, RtpCallback cb, unsigned long user_data);
00238 int rtp_session_signal_disconnect_by_callback(RtpSession *session,const char *signal_name, RtpCallback cb);
00239 void rtp_session_set_ssrc(RtpSession *session, uint32_t ssrc);
00240 void rtp_session_set_seq_number(RtpSession *session, uint16_t seq);
00241 uint16_t rtp_session_get_seq_number(RtpSession *session);
00242
00243 void rtp_session_enable_jitter_buffer(RtpSession *session , bool_t enabled);
00244 bool_t rtp_session_jitter_buffer_enabled(const RtpSession *session);
00245 void rtp_session_set_jitter_buffer_params(RtpSession *session, const JBParameters *par);
00246 void rtp_session_get_jitter_buffer_params(RtpSession *session, JBParameters *par);
00247
00248
00249 void rtp_session_set_jitter_compensation(RtpSession *session, int milisec);
00250 void rtp_session_enable_adaptive_jitter_compensation(RtpSession *session, bool_t val);
00251 bool_t rtp_session_adaptive_jitter_compensation_enabled(RtpSession *session);
00252
00253 void rtp_session_set_time_jump_limit(RtpSession *session, int miliseconds);
00254 int rtp_session_set_local_addr(RtpSession *session,const char *addr, int port);
00255 int rtp_session_get_local_port(const RtpSession *session);
00256 int rtp_session_set_remote_addr_and_port (RtpSession * session, const char * addr, int rtp_port, int rtcp_port);
00257 int rtp_session_set_remote_addr(RtpSession *session,const char *addr, int port);
00258
00259
00260 void rtp_session_set_sockets(RtpSession *session, int rtpfd, int rtcpfd);
00261 void rtp_session_set_transports(RtpSession *session, RtpTransport *rtptr, RtpTransport *rtcptr);
00262
00263
00264 ortp_socket_t rtp_session_get_rtp_socket(const RtpSession *session);
00265 ortp_socket_t rtp_session_get_rtcp_socket(const RtpSession *session);
00266
00267
00268
00269 int rtp_session_set_dscp(RtpSession *session, int dscp);
00270 int rtp_session_get_dscp(const RtpSession *session);
00271
00272
00273
00274 int rtp_session_set_multicast_ttl(RtpSession *session, int ttl);
00275 int rtp_session_get_multicast_ttl(RtpSession *session);
00276
00277 int rtp_session_set_multicast_loopback(RtpSession *session, int yesno);
00278 int rtp_session_get_multicast_loopback(RtpSession *session);
00279
00280
00281
00282 int rtp_session_set_send_payload_type(RtpSession *session, int paytype);
00283 int rtp_session_get_send_payload_type(const RtpSession *session);
00284
00285 int rtp_session_get_recv_payload_type(const RtpSession *session);
00286 int rtp_session_set_recv_payload_type(RtpSession *session, int pt);
00287
00288 int rtp_session_set_payload_type(RtpSession *session, int pt);
00289
00290 void rtp_session_set_symmetric_rtp (RtpSession * session, bool_t yesno);
00291
00292 void rtp_session_set_connected_mode(RtpSession *session, bool_t yesno);
00293
00294 void rtp_session_enable_rtcp(RtpSession *session, bool_t yesno);
00295
00296
00297 mblk_t * rtp_session_recvm_with_ts (RtpSession * session, uint32_t user_ts);
00298 mblk_t * rtp_session_create_packet(RtpSession *session,int header_size, const uint8_t *payload, int payload_size);
00299 mblk_t * rtp_session_create_packet_with_data(RtpSession *session, uint8_t *payload, int payload_size, void (*freefn)(void*));
00300 mblk_t * rtp_session_create_packet_in_place(RtpSession *session,uint8_t *buffer, int size, void (*freefn)(void*) );
00301 int rtp_session_sendm_with_ts (RtpSession * session, mblk_t *mp, uint32_t userts);
00302
00303 int rtp_session_recv_with_ts(RtpSession *session, uint8_t *buffer, int len, uint32_t ts, int *have_more);
00304 int rtp_session_send_with_ts(RtpSession *session, const uint8_t *buffer, int len, uint32_t userts);
00305
00306
00307 void rtp_session_register_event_queue(RtpSession *session, OrtpEvQueue *q);
00308 void rtp_session_unregister_event_queue(RtpSession *session, OrtpEvQueue *q);
00309
00310
00311
00312 float rtp_session_compute_send_bandwidth(RtpSession *session);
00313 float rtp_session_compute_recv_bandwidth(RtpSession *session);
00314
00315 void rtp_session_send_rtcp_APP(RtpSession *session, uint8_t subtype, const char *name, const uint8_t *data, int datalen);
00316
00317 uint32_t rtp_session_get_current_send_ts(RtpSession *session);
00318 uint32_t rtp_session_get_current_recv_ts(RtpSession *session);
00319 void rtp_session_flush_sockets(RtpSession *session);
00320 void rtp_session_release_sockets(RtpSession *session);
00321 void rtp_session_resync(RtpSession *session);
00322 void rtp_session_reset(RtpSession *session);
00323 void rtp_session_destroy(RtpSession *session);
00324
00325 const rtp_stats_t * rtp_session_get_stats(const RtpSession *session);
00326 void rtp_session_reset_stats(RtpSession *session);
00327
00328 void rtp_session_set_data(RtpSession *session, void *data);
00329 void *rtp_session_get_data(const RtpSession *session);
00330
00331 void rtp_session_set_recv_buf_size(RtpSession *session, int bufsize);
00332
00333
00334 uint32_t rtp_session_ts_to_time(RtpSession *session,uint32_t timestamp);
00335 uint32_t rtp_session_time_to_ts(RtpSession *session, int millisecs);
00336
00337
00338
00339 void rtp_session_make_time_distorsion(RtpSession *session, int milisec);
00340
00341
00342 void rtp_session_set_source_description(RtpSession *session, const char *cname,
00343 const char *name, const char *email, const char *phone,
00344 const char *loc, const char *tool, const char *note);
00345 void rtp_session_add_contributing_source(RtpSession *session, uint32_t csrc,
00346 const char *cname, const char *name, const char *email, const char *phone,
00347 const char *loc, const char *tool, const char *note);
00348 void rtp_session_remove_contributing_sources(RtpSession *session, uint32_t csrc);
00349 mblk_t* rtp_session_create_rtcp_sdes_packet(RtpSession *session);
00350
00351 void rtp_session_get_last_recv_time(RtpSession *session, struct timeval *tv);
00352 int rtp_session_bye(RtpSession *session, const char *reason);
00353
00354 int rtp_session_get_last_send_error_code(RtpSession *session);
00355 void rtp_session_clear_send_error_code(RtpSession *session);
00356 int rtp_session_get_last_recv_error_code(RtpSession *session);
00357 void rtp_session_clear_recv_error_code(RtpSession *session);
00358
00359
00360 void rtp_session_init(RtpSession *session, int mode);
00361 #define rtp_session_set_flag(session,flag) (session)->flags|=(flag)
00362 #define rtp_session_unset_flag(session,flag) (session)->flags&=~(flag)
00363 void rtp_session_uninit(RtpSession *session);
00364
00365 #ifdef __cplusplus
00366 }
00367 #endif
00368
00369 #endif