34 #include <ortp/port.h>
39 #include <ortp/rtcp.h>
40 #include <ortp/str_utils.h>
41 #include <ortp/rtpsignaltable.h>
42 #include <ortp/event.h>
45 #define ORTP_AVPF_FEATURE_NONE 0
46 #define ORTP_AVPF_FEATURE_TMMBR (1 << 0)
72 int adapt_jitt_comp_ts;
80 uint64_t cum_jitter_buffer_size;
81 unsigned int cum_jitter_buffer_count;
114 int (*t_sendto)(
struct _RtpTransport *t,
mblk_t *msg ,
int flags,
const struct sockaddr *to, socklen_t tolen);
115 int (*t_recvfrom)(
struct _RtpTransport *t,
mblk_t *msg,
int flags,
struct sockaddr *from, socklen_t *fromlen);
116 void (*t_close)(
struct _RtpTransport *transport,
void *userData);
125 OrtpNetworkSimulatorInvalid=-1,
130 }OrtpNetworkSimulatorMode;
154 struct timeval last_check;
155 uint64_t last_jitter_event;
156 int consecutive_drops;
158 int drop_by_congestion;
162 ortp_thread_t thread;
163 bool_t in_jitter_event;
164 bool_t thread_started;
172 uint32_t T_max_fb_delay;
173 uint32_t T_rr_interval;
174 uint32_t T_rr_current_interval;
181 bool_t tmmbr_scheduled;
182 bool_t tmmbn_scheduled;
185 #define ORTP_RTCP_XR_UNAVAILABLE_PARAMETER 127
189 OrtpRtcpXrSilencePlc,
190 OrtpRtcpXrEnhancedPlc
191 } OrtpRtcpXrPlcStatus;
193 typedef OrtpRtcpXrPlcStatus (*OrtpRtcpXrPlcCallback)(
unsigned long userdata);
194 typedef int (*OrtpRtcpXrSignalLevelCallback)(
unsigned long userdata);
195 typedef int (*OrtpRtcpXrNoiseLevelCallback)(
unsigned long userdata);
196 typedef float (*OrtpRtcpXrAverageQualityIndicatorCallback)(
unsigned long userdata);
199 OrtpRtcpXrPlcCallback plc;
200 OrtpRtcpXrSignalLevelCallback signal_level;
201 OrtpRtcpXrNoiseLevelCallback noise_level;
202 OrtpRtcpXrAverageQualityIndicatorCallback average_qi;
203 OrtpRtcpXrAverageQualityIndicatorCallback average_lq_qi;
204 unsigned long userdata;
208 OrtpRtcpXrRcvrRttNone,
209 OrtpRtcpXrRcvrRttAll,
210 OrtpRtcpXrRcvrRttSender
211 } OrtpRtcpXrRcvrRttMode;
214 OrtpRtcpXrStatSummaryLoss = (1 << 7),
215 OrtpRtcpXrStatSummaryDup = (1 << 6),
216 OrtpRtcpXrStatSummaryJitt = (1 << 5),
217 OrtpRtcpXrStatSummaryTTL = (1 << 3),
218 OrtpRtcpXrStatSummaryHL = (1 << 4)
219 } OrtpRtcpXrStatSummaryFlag;
223 bool_t stat_summary_enabled;
224 bool_t voip_metrics_enabled;
225 OrtpRtcpXrRcvrRttMode rcvr_rtt_mode;
226 int rcvr_rtt_max_size;
227 OrtpRtcpXrStatSummaryFlag stat_summary_flags;
231 uint32_t last_rcvr_rtt_ts;
232 struct timeval last_rcvr_rtt_time;
233 uint16_t rcv_seq_at_last_stat_summary;
234 uint32_t rcv_since_last_stat_summary;
235 uint32_t dup_since_last_stat_summary;
236 uint32_t min_jitter_since_last_stat_summary;
237 uint32_t max_jitter_since_last_stat_summary;
238 double olds_jitter_since_last_stat_summary;
239 double oldm_jitter_since_last_stat_summary;
240 double news_jitter_since_last_stat_summary;
241 double newm_jitter_since_last_stat_summary;
242 int64_t last_jitter_diff_since_last_stat_summary;
243 double olds_ttl_or_hl_since_last_stat_summary;
244 double oldm_ttl_or_hl_since_last_stat_summary;
245 double news_ttl_or_hl_since_last_stat_summary;
246 double newm_ttl_or_hl_since_last_stat_summary;
247 uint8_t min_ttl_or_hl_since_last_stat_summary;
248 uint8_t max_ttl_or_hl_since_last_stat_summary;
249 uint32_t first_rcv_seq;
250 uint32_t last_rcv_seq;
252 uint32_t discarded_count;
261 struct sockaddr_storage addr;
266 ortp_socket_t socket;
269 socklen_t rem_addrlen;
270 struct sockaddr_storage rem_addr;
271 socklen_t loc_addrlen;
272 struct sockaddr_storage loc_addr;
275 struct timeval send_bw_start;
276 struct timeval recv_bw_start;
277 unsigned int sent_bytes;
278 unsigned int recv_bytes;
281 OList *aux_destinations;
293 unsigned long QoSFlowID;
295 uint32_t snd_time_offset;
296 uint32_t snd_ts_offset;
297 uint32_t snd_rand_offset;
298 uint32_t snd_last_ts;
299 uint32_t rcv_time_offset;
300 uint32_t rcv_ts_offset;
301 uint32_t rcv_query_ts_offset;
302 uint32_t rcv_last_ts;
303 uint16_t rcv_last_seq;
305 uint32_t rcv_last_app_ts;
306 uint32_t rcv_last_ret_ts;
307 uint32_t hwrcv_extseq;
308 uint32_t hwrcv_seq_at_last_SR;
309 uint32_t hwrcv_since_last_SR;
310 uint32_t last_rcv_SR_ts;
311 struct timeval last_rcv_SR_time;
313 uint32_t last_rtcp_packet_count;
314 uint32_t sent_payload_bytes;
320 int ssrc_changed_thres;
332 bool_t rtcp_xr_dlrr_to_send;
333 uint8_t rtcp_fb_fir_seq_nr;
334 uint32_t last_rtcp_fb_pli_snt;
358 unsigned int inc_ssrc_candidate;
359 int inc_same_ssrc_count;
362 int target_upload_bandwidth;
370 struct _OList *signal_tables;
381 int multicast_loopback;
382 float duplication_ratio;
383 float duplication_left ;
386 struct timeval last_recv_time;
393 int64_t lost_packets_test_vector;
394 unsigned int interarrival_jitter_test_vector;
395 unsigned int delay_test_vector;
399 bool_t symmetric_rtp;
415 ORTP_PUBLIC
const char *ortp_network_simulator_mode_to_string(OrtpNetworkSimulatorMode mode);
416 ORTP_PUBLIC OrtpNetworkSimulatorMode ortp_network_simulator_mode_from_string(
const char *str);
420 ORTP_PUBLIC
RtpSession *rtp_session_new(
int mode);
421 ORTP_PUBLIC
void rtp_session_set_scheduling_mode(
RtpSession *session,
int yesno);
422 ORTP_PUBLIC
void rtp_session_set_blocking_mode(
RtpSession *session,
int yesno);
429 ORTP_PUBLIC
int rtp_session_signal_connect(
RtpSession *session,
const char *signal_name, RtpCallback cb,
void *user_data);
430 ORTP_PUBLIC
int rtp_session_signal_disconnect_by_callback(
RtpSession *session,
const char *signal_name, RtpCallback cb);
431 ORTP_PUBLIC
void rtp_session_set_ssrc(
RtpSession *session, uint32_t ssrc);
432 ORTP_PUBLIC uint32_t rtp_session_get_send_ssrc(
RtpSession* session);
433 ORTP_PUBLIC uint32_t rtp_session_get_recv_ssrc(
RtpSession *session);
434 ORTP_PUBLIC
void rtp_session_set_seq_number(
RtpSession *session, uint16_t seq);
435 ORTP_PUBLIC uint16_t rtp_session_get_seq_number(
RtpSession *session);
436 ORTP_PUBLIC uint32_t rtp_session_get_rcv_ext_seq_number(
RtpSession *session);
437 ORTP_PUBLIC
int rtp_session_get_cum_loss(
RtpSession *session);
438 ORTP_PUBLIC
void rtp_session_set_duplication_ratio(
RtpSession *session,
float ratio);
440 ORTP_PUBLIC
void rtp_session_enable_jitter_buffer(
RtpSession *session , bool_t enabled);
441 ORTP_PUBLIC bool_t rtp_session_jitter_buffer_enabled(
const RtpSession *session);
446 ORTP_PUBLIC
void rtp_session_set_jitter_compensation(
RtpSession *session,
int milisec);
447 ORTP_PUBLIC
void rtp_session_enable_adaptive_jitter_compensation(
RtpSession *session, bool_t val);
448 ORTP_PUBLIC bool_t rtp_session_adaptive_jitter_compensation_enabled(
RtpSession *session);
450 ORTP_PUBLIC
void rtp_session_set_time_jump_limit(
RtpSession *session,
int miliseconds);
451 ORTP_PUBLIC
int rtp_session_join_multicast_group(
RtpSession *session,
const char *ip);
452 ORTP_PUBLIC
int rtp_session_set_local_addr(
RtpSession *session,
const char *addr,
int rtp_port,
int rtcp_port);
453 ORTP_PUBLIC
int rtp_session_get_local_port(
const RtpSession *session);
454 ORTP_PUBLIC
int rtp_session_get_local_rtcp_port(
const RtpSession *session);
457 rtp_session_set_remote_addr_full (
RtpSession * session,
const char * rtp_addr,
int rtp_port,
const char * rtcp_addr,
int rtcp_port);
459 ORTP_PUBLIC
int rtp_session_set_remote_addr_and_port (
RtpSession * session,
const char * addr,
int rtp_port,
int rtcp_port);
460 ORTP_PUBLIC
int rtp_session_set_remote_addr(
RtpSession *session,
const char *addr,
int port);
461 ORTP_PUBLIC
int rtp_session_add_aux_remote_addr_full(
RtpSession * session,
const char * rtp_addr,
int rtp_port,
const char * rtcp_addr,
int rtcp_port);
462 ORTP_PUBLIC
void rtp_session_clear_aux_remote_addr(
RtpSession * session);
465 ORTP_PUBLIC
void rtp_session_set_sockets(
RtpSession *session,
int rtpfd,
int rtcpfd);
469 ORTP_PUBLIC ortp_socket_t rtp_session_get_rtp_socket(
const RtpSession *session);
470 ORTP_PUBLIC ortp_socket_t rtp_session_get_rtcp_socket(
const RtpSession *session);
474 ORTP_PUBLIC
int rtp_session_set_dscp(
RtpSession *session,
int dscp);
475 ORTP_PUBLIC
int rtp_session_get_dscp(
const RtpSession *session);
479 ORTP_PUBLIC
int rtp_session_set_pktinfo(
RtpSession *session,
int activate);
482 ORTP_PUBLIC
int rtp_session_set_multicast_ttl(
RtpSession *session,
int ttl);
483 ORTP_PUBLIC
int rtp_session_get_multicast_ttl(
RtpSession *session);
485 ORTP_PUBLIC
int rtp_session_set_multicast_loopback(
RtpSession *session,
int yesno);
486 ORTP_PUBLIC
int rtp_session_get_multicast_loopback(
RtpSession *session);
490 ORTP_PUBLIC
int rtp_session_set_send_payload_type(
RtpSession *session,
int paytype);
491 ORTP_PUBLIC
int rtp_session_get_send_payload_type(
const RtpSession *session);
493 ORTP_PUBLIC
int rtp_session_get_recv_payload_type(
const RtpSession *session);
494 ORTP_PUBLIC
int rtp_session_set_recv_payload_type(
RtpSession *session,
int pt);
496 ORTP_PUBLIC
int rtp_session_set_payload_type(
RtpSession *session,
int pt);
498 ORTP_PUBLIC
void rtp_session_set_symmetric_rtp (
RtpSession * session, bool_t yesno);
500 ORTP_PUBLIC bool_t rtp_session_get_symmetric_rtp (
const RtpSession * session);
502 ORTP_PUBLIC
void rtp_session_set_connected_mode(
RtpSession *session, bool_t yesno);
504 ORTP_PUBLIC
void rtp_session_enable_rtcp(
RtpSession *session, bool_t yesno);
506 ORTP_PUBLIC
void rtp_session_set_rtcp_report_interval(
RtpSession *session,
int value_ms);
508 ORTP_PUBLIC
void rtp_session_set_target_upload_bandwidth(
RtpSession *session,
int target_bandwidth);
513 ORTP_PUBLIC
void rtp_session_set_ssrc_changed_threshold(
RtpSession *session,
int numpackets);
516 ORTP_PUBLIC
mblk_t * rtp_session_recvm_with_ts (
RtpSession * session, uint32_t user_ts);
517 ORTP_PUBLIC
mblk_t * rtp_session_create_packet(
RtpSession *session,
int header_size,
const uint8_t *payload,
int payload_size);
518 ORTP_PUBLIC
mblk_t * rtp_session_create_packet_raw(
const uint8_t *packet,
int packet_size);
519 ORTP_PUBLIC
mblk_t * rtp_session_create_packet_with_data(
RtpSession *session, uint8_t *payload,
int payload_size,
void (*freefn)(
void*));
520 ORTP_PUBLIC
mblk_t * rtp_session_create_packet_in_place(
RtpSession *session,uint8_t *buffer,
int size,
void (*freefn)(
void*) );
521 ORTP_PUBLIC
int rtp_session_sendm_with_ts (
RtpSession * session,
mblk_t *mp, uint32_t userts);
523 ORTP_PUBLIC
int rtp_session_recv_with_ts(
RtpSession *session, uint8_t *buffer,
int len, uint32_t ts,
int *have_more);
524 ORTP_PUBLIC
int rtp_session_send_with_ts(
RtpSession *session,
const uint8_t *buffer,
int len, uint32_t userts);
532 ORTP_PUBLIC
float rtp_session_compute_send_bandwidth(
RtpSession *session);
533 ORTP_PUBLIC
float rtp_session_compute_recv_bandwidth(
RtpSession *session);
534 ORTP_PUBLIC
float rtp_session_get_send_bandwidth(
RtpSession *session);
535 ORTP_PUBLIC
float rtp_session_get_recv_bandwidth(
RtpSession *session);
536 ORTP_PUBLIC
float rtp_session_get_rtp_send_bandwidth(
RtpSession *session);
537 ORTP_PUBLIC
float rtp_session_get_rtp_recv_bandwidth(
RtpSession *session);
538 ORTP_PUBLIC
float rtp_session_get_rtcp_send_bandwidth(
RtpSession *session);
539 ORTP_PUBLIC
float rtp_session_get_rtcp_recv_bandwidth(
RtpSession *session);
541 ORTP_PUBLIC
void rtp_session_send_rtcp_APP(
RtpSession *session, uint8_t subtype,
const char *name,
const uint8_t *data,
int datalen);
543 ORTP_PUBLIC uint32_t rtp_session_get_current_send_ts(
RtpSession *session);
544 ORTP_PUBLIC uint32_t rtp_session_get_current_recv_ts(
RtpSession *session);
545 ORTP_PUBLIC
void rtp_session_flush_sockets(
RtpSession *session);
546 ORTP_PUBLIC
void rtp_session_release_sockets(
RtpSession *session);
547 ORTP_PUBLIC
void rtp_session_resync(
RtpSession *session);
548 ORTP_PUBLIC
void rtp_session_reset(
RtpSession *session);
549 ORTP_PUBLIC
void rtp_session_destroy(
RtpSession *session);
553 ORTP_PUBLIC
void rtp_session_reset_stats(
RtpSession *session);
555 ORTP_PUBLIC
void rtp_session_set_data(
RtpSession *session,
void *data);
556 ORTP_PUBLIC
void *rtp_session_get_data(
const RtpSession *session);
558 ORTP_PUBLIC
void rtp_session_set_recv_buf_size(
RtpSession *session,
int bufsize);
559 ORTP_PUBLIC
void rtp_session_set_rtp_socket_send_buffer_size(
RtpSession * session,
unsigned int size);
560 ORTP_PUBLIC
void rtp_session_set_rtp_socket_recv_buffer_size(
RtpSession * session,
unsigned int size);
563 ORTP_PUBLIC uint32_t rtp_session_ts_to_time(
RtpSession *session,uint32_t timestamp);
564 ORTP_PUBLIC uint32_t rtp_session_time_to_ts(
RtpSession *session,
int millisecs);
568 ORTP_PUBLIC
void rtp_session_make_time_distorsion(
RtpSession *session,
int milisec);
571 ORTP_PUBLIC
void rtp_session_set_source_description(
RtpSession *session,
const char *cname,
572 const char *name,
const char *email,
const char *phone,
573 const char *loc,
const char *tool,
const char *note);
574 ORTP_PUBLIC
void rtp_session_add_contributing_source(
RtpSession *session, uint32_t csrc,
575 const char *cname,
const char *name,
const char *email,
const char *phone,
576 const char *loc,
const char *tool,
const char *note);
578 #define rtp_session_remove_contributing_sources rtp_session_remove_contributing_source
579 ORTP_PUBLIC
void rtp_session_remove_contributing_source(
RtpSession *session, uint32_t csrc);
580 ORTP_PUBLIC
mblk_t* rtp_session_create_rtcp_sdes_packet(
RtpSession *session, bool_t full);
582 ORTP_PUBLIC
void rtp_session_get_last_recv_time(
RtpSession *session,
struct timeval *tv);
583 ORTP_PUBLIC
int rtp_session_bye(
RtpSession *session,
const char *reason);
585 ORTP_PUBLIC
int rtp_session_get_last_send_error_code(
RtpSession *session);
586 ORTP_PUBLIC
void rtp_session_clear_send_error_code(
RtpSession *session);
587 ORTP_PUBLIC
int rtp_session_get_last_recv_error_code(
RtpSession *session);
588 ORTP_PUBLIC
void rtp_session_clear_recv_error_code(
RtpSession *session);
591 ORTP_PUBLIC
float rtp_session_get_round_trip_propagation(
RtpSession *session);
596 ORTP_PUBLIC
void rtp_session_rtcp_set_lost_packet_value(
RtpSession *session,
const int64_t value );
597 ORTP_PUBLIC
void rtp_session_rtcp_set_jitter_value(
RtpSession *session,
const unsigned int value );
598 ORTP_PUBLIC
void rtp_session_rtcp_set_delay_value(
RtpSession *session,
const unsigned int value );
599 ORTP_PUBLIC
mblk_t * rtp_session_pick_with_cseq (
RtpSession * session,
const uint16_t sequence_number);
602 ORTP_PUBLIC
void rtp_session_send_rtcp_xr_rcvr_rtt(
RtpSession *session);
603 ORTP_PUBLIC
void rtp_session_send_rtcp_xr_dlrr(
RtpSession *session);
604 ORTP_PUBLIC
void rtp_session_send_rtcp_xr_stat_summary(
RtpSession *session);
605 ORTP_PUBLIC
void rtp_session_send_rtcp_xr_voip_metrics(
RtpSession *session);
608 ORTP_PUBLIC bool_t rtp_session_avpf_enabled(
RtpSession *session);
609 ORTP_PUBLIC bool_t rtp_session_avpf_payload_type_feature_enabled(
RtpSession *session,
unsigned char feature);
610 ORTP_PUBLIC bool_t rtp_session_avpf_feature_enabled(
RtpSession *session,
unsigned char feature);
611 ORTP_PUBLIC
void rtp_session_enable_avpf_feature(
RtpSession *session,
unsigned char feature, bool_t enable);
612 ORTP_PUBLIC uint16_t rtp_session_get_avpf_rr_interval(
RtpSession *session);
613 ORTP_PUBLIC bool_t rtp_session_rtcp_psfb_scheduled(
RtpSession *session, rtcp_psfb_type_t type);
614 ORTP_PUBLIC bool_t rtp_session_rtcp_rtpfb_scheduled(
RtpSession *session, rtcp_rtpfb_type_t type);
615 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_pli(
RtpSession *session);
616 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_fir(
RtpSession *session);
617 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_sli(
RtpSession *session, uint16_t first, uint16_t number, uint8_t picture_id);
618 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_rpsi(
RtpSession *session, uint8_t *bit_string, uint16_t bit_string_len);
619 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_tmmbr(
RtpSession *session, uint64_t mxtbr);
620 ORTP_PUBLIC
void rtp_session_send_rtcp_fb_tmmbn(
RtpSession *session);
624 ORTP_PUBLIC
void rtp_session_init(
RtpSession *session,
int mode);
625 #define rtp_session_set_flag(session,flag) (session)->flags|=(flag)
626 #define rtp_session_unset_flag(session,flag) (session)->flags&=~(flag)
627 ORTP_PUBLIC
void rtp_session_uninit(
RtpSession *session);
630 ORTP_PUBLIC
void rtp_session_set_reuseaddr(
RtpSession *session, bool_t yes);
662 ORTP_PUBLIC
void meta_rtp_transport_destroy(
RtpTransport *tp);