oRTP  0.24.0
rtpsession.h
Go to the documentation of this file.
1  /*
2  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
3  Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
4 
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.
9 
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.
14 
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
18 */
19 
30 #ifndef RTPSESSION_H
31 #define RTPSESSION_H
32 
33 
34 #include <ortp/port.h>
35 #include <ortp/rtp.h>
36 #include <ortp/payloadtype.h>
37 #include <ortp/rtpprofile.h>
38 #include <ortp/sessionset.h>
39 #include <ortp/rtcp.h>
40 #include <ortp/str_utils.h>
41 #include <ortp/rtpsignaltable.h>
42 #include <ortp/event.h>
43 
44 
45 
46 typedef enum {
47  RTP_SESSION_RECVONLY,
48  RTP_SESSION_SENDONLY,
49  RTP_SESSION_SENDRECV
50 } RtpSessionMode;
51 
52 
55 typedef struct _JBParameters{
56  int min_size;
57  int nom_size;
58  int max_size;
59  bool_t adaptive;
60  bool_t pad[3];
62 } JBParameters;
63 
64 typedef struct _JitterControl
65 {
66  unsigned int count;
67  int jitt_comp; /* the user jitt_comp in miliseconds*/
68  int jitt_comp_ts; /* the jitt_comp converted in rtp time (same unit as timestamp) */
69  int adapt_jitt_comp_ts;
70  int64_t slide;
71  int64_t prev_slide;
72  float jitter;
73  int olddiff;
74  float inter_jitter; /* interarrival jitter as defined in the RFC */
75  int corrective_step;
76  int corrective_slide;
77  uint64_t cum_jitter_buffer_size; /*in timestamp units*/
78  unsigned int cum_jitter_buffer_count; /*used for computation of jitter buffer size*/
79  int clock_rate;
80  bool_t adaptive;
81  bool_t enabled;
83 
84 typedef struct _WaitPoint
85 {
86  ortp_mutex_t lock;
87  ortp_cond_t cond;
88  uint32_t time;
89  bool_t wakeup;
90 } WaitPoint;
91 
92 typedef struct _RtpTransportModifier
93 {
94  void *data;
95  struct _RtpSession *session;//<back pointer to the owning session, set by oRTP
96  int (*t_process_on_send)(struct _RtpTransportModifier *t, mblk_t *msg);
97  int (*t_process_on_receive)(struct _RtpTransportModifier *t, mblk_t *msg);
98  void (*t_process_on_schedule)(struct _RtpTransportModifier *t); /*invoked each time rtp_session_recvm even is no message are available*/
103  void (*t_destroy)(struct _RtpTransportModifier *transport);
105 
106 typedef struct _RtpTransport
107 {
108  void *data;
109  struct _RtpSession *session;//<back pointer to the owning session, set by oRTP
110  ortp_socket_t (*t_getsocket)(struct _RtpTransport *t);
111  int (*t_sendto)(struct _RtpTransport *t, mblk_t *msg , int flags, const struct sockaddr *to, socklen_t tolen);
112  int (*t_recvfrom)(struct _RtpTransport *t, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen);
113  void (*t_close)(struct _RtpTransport *transport, void *userData);
118  void (*t_destroy)(struct _RtpTransport *transport);
119 } RtpTransport;
120 
122  OrtpNetworkSimulatorInvalid=-1,
127 }OrtpNetworkSimulatorMode;
128 
133  int enabled;
136  float loss_rate;
137  uint32_t latency;
141  OrtpNetworkSimulatorMode mode;
143 
146  int bit_budget;
147  int qsize;
148  queue_t q;/*queue used for simulating bandwidth limit*/
149  queue_t latency_q;
150  queue_t send_q; /*used only for OrtpNetworkSimulatorOutbound direction*/
151  struct timeval last_check;
152  uint64_t last_jitter_event;
153  int consecutive_drops;
154  int drops_to_ignore;
155  int drop_by_congestion;
156  int drop_by_loss;
157  int total_count; /*total number of packets gone through the simulator*/
158  ortp_mutex_t mutex;
159  ortp_thread_t thread;
160  bool_t in_jitter_event;
161  bool_t thread_started;
163 
164 typedef struct OrtpRtcpSendAlgorithm {
165  uint64_t tn; /* Time of the next scheduled RTCP RR transmission in milliseconds. */
166  uint64_t tp; /* Time of the last scheduled RTCP RR transmission in milliseconds. */
167  uint64_t t_rr_last; /* Time of the last regular RTCP packet sent in milliseconds. */
168  uint32_t T_rr; /* Interval for the scheduling of the next regular RTCP packet. */
169  uint32_t T_max_fb_delay; /* Interval within which a feeback message is considered to be useful to the sender. */
170  uint32_t T_rr_interval; /* Minimal interval to be used between regular RTCP packets. */
171  uint32_t T_rr_current_interval;
172  uint32_t Tmin; /* Minimal interval between RTCP packets. */
173  float avg_rtcp_size;
174  mblk_t *fb_packets;
175  bool_t initialized; /* Whether the RTCP send algorithm is fully initialized. */
176  bool_t initial;
177  bool_t allow_early;
179 
180 #define ORTP_RTCP_XR_UNAVAILABLE_PARAMETER 127
181 
182 typedef enum {
183  OrtpRtcpXrNoPlc,
184  OrtpRtcpXrSilencePlc,
185  OrtpRtcpXrEnhancedPlc
186 } OrtpRtcpXrPlcStatus;
187 
188 typedef OrtpRtcpXrPlcStatus (*OrtpRtcpXrPlcCallback)(unsigned long userdata);
189 typedef int (*OrtpRtcpXrSignalLevelCallback)(unsigned long userdata);
190 typedef int (*OrtpRtcpXrNoiseLevelCallback)(unsigned long userdata);
191 typedef float (*OrtpRtcpXrAverageQualityIndicatorCallback)(unsigned long userdata);
192 
193 typedef struct OrtpRtcpXrMediaCallbacks {
194  OrtpRtcpXrPlcCallback plc;
195  OrtpRtcpXrSignalLevelCallback signal_level;
196  OrtpRtcpXrNoiseLevelCallback noise_level;
197  OrtpRtcpXrAverageQualityIndicatorCallback average_qi;
198  OrtpRtcpXrAverageQualityIndicatorCallback average_lq_qi;
199  unsigned long userdata;
201 
202 typedef enum {
203  OrtpRtcpXrRcvrRttNone,
204  OrtpRtcpXrRcvrRttAll,
205  OrtpRtcpXrRcvrRttSender
206 } OrtpRtcpXrRcvrRttMode;
207 
208 typedef enum {
209  OrtpRtcpXrStatSummaryLoss = (1 << 7),
210  OrtpRtcpXrStatSummaryDup = (1 << 6),
211  OrtpRtcpXrStatSummaryJitt = (1 << 5),
212  OrtpRtcpXrStatSummaryTTL = (1 << 3),
213  OrtpRtcpXrStatSummaryHL = (1 << 4)
214 } OrtpRtcpXrStatSummaryFlag;
215 
216 typedef struct OrtpRtcpXrConfiguration {
217  bool_t enabled;
218  bool_t stat_summary_enabled;
219  bool_t voip_metrics_enabled;
220  OrtpRtcpXrRcvrRttMode rcvr_rtt_mode;
221  int rcvr_rtt_max_size;
222  OrtpRtcpXrStatSummaryFlag stat_summary_flags;
224 
225 typedef struct OrtpRtcpXrStats {
226  uint32_t last_rcvr_rtt_ts; /* NTP timestamp (middle 32 bits) of last received XR rcvr-rtt */
227  struct timeval last_rcvr_rtt_time; /* Time at which last XR rcvr-rtt was received */
228  uint16_t rcv_seq_at_last_stat_summary; /* Received sequence number at last XR stat-summary sent */
229  uint32_t rcv_since_last_stat_summary; /* The number of packets received since last XR stat-summary was sent */
230  uint32_t dup_since_last_stat_summary; /* The number of duplicate packets received since last XR stat-summary was sent */
231  uint32_t min_jitter_since_last_stat_summary; /* The minimum value of jitter since last XR stat-summary was sent */
232  uint32_t max_jitter_since_last_stat_summary; /* The maximum value of jitter since last XR stat-summary was sent */
233  double olds_jitter_since_last_stat_summary;
234  double oldm_jitter_since_last_stat_summary;
235  double news_jitter_since_last_stat_summary;
236  double newm_jitter_since_last_stat_summary;
237  int64_t last_jitter_diff_since_last_stat_summary;
238  double olds_ttl_or_hl_since_last_stat_summary;
239  double oldm_ttl_or_hl_since_last_stat_summary;
240  double news_ttl_or_hl_since_last_stat_summary;
241  double newm_ttl_or_hl_since_last_stat_summary;
242  uint8_t min_ttl_or_hl_since_last_stat_summary; /* The minimum value of TTL/HL since last XR stat-summary was sent */
243  uint8_t max_ttl_or_hl_since_last_stat_summary; /* The maximum value of TTL/HL since last XR stat-summary was sent */
244  uint32_t first_rcv_seq;
245  uint32_t last_rcv_seq;
246  uint32_t rcv_count;
247  uint32_t discarded_count;
249 
250 typedef struct _OrtpAddress{
251  struct sockaddr_storage addr;
252  socklen_t len;
253 }OrtpAddress;
254 
255 typedef struct _OrtpStream {
256  ortp_socket_t socket;
257  int sockfamily;
258  int loc_port;
259  socklen_t rem_addrlen;
260  struct sockaddr_storage rem_addr;
261  socklen_t loc_addrlen;
262  struct sockaddr_storage loc_addr;
263  struct _RtpTransport *tr;
264  mblk_t *cached_mp;
265  struct timeval send_bw_start; /* used for bandwidth estimation */
266  struct timeval recv_bw_start; /* used for bandwidth estimation */
267  unsigned int sent_bytes; /* used for bandwidth estimation */
268  unsigned int recv_bytes; /* used for bandwidth estimation */
269  float upload_bw;
270  float download_bw;
271  OList *aux_destinations; /*list of OrtpAddress */
272 } OrtpStream;
273 
274 typedef struct _RtpStream
275 {
276  OrtpStream gs;
277  int max_rq_size;
278  int time_jump;
279  uint32_t ts_jump;
280  queue_t rq;
281  queue_t tev_rq;
282  void *QoSHandle;
283  unsigned long QoSFlowID;
284  JitterControl jittctl;
285  uint32_t snd_time_offset;/*the scheduler time when the application send its first timestamp*/
286  uint32_t snd_ts_offset; /* the first application timestamp sent by the application */
287  uint32_t snd_rand_offset; /* a random number added to the user offset to make the stream timestamp*/
288  uint32_t snd_last_ts; /* the last stream timestamp sended */
289  uint32_t rcv_time_offset; /*the scheduler time when the application ask for its first timestamp*/
290  uint32_t rcv_ts_offset; /* the first stream timestamp */
291  uint32_t rcv_query_ts_offset; /* the first user timestamp asked by the application */
292  uint32_t rcv_last_ts; /* the last stream timestamp got by the application */
293  uint16_t rcv_last_seq; /* the last stream sequence number got by the application*/
294  uint16_t pad;
295  uint32_t rcv_last_app_ts; /* the last application timestamp asked by the application */
296  uint32_t rcv_last_ret_ts; /* the timestamp of the last sample returned (only for continuous audio)*/
297  uint32_t hwrcv_extseq; /* last received on socket extended sequence number */
298  uint32_t hwrcv_seq_at_last_SR;
299  uint32_t hwrcv_since_last_SR;
300  uint32_t last_rcv_SR_ts; /* NTP timestamp (middle 32 bits) of last received SR */
301  struct timeval last_rcv_SR_time; /* time at which last SR was received */
302  uint16_t snd_seq; /* send sequence number */
303  uint32_t last_rtcp_packet_count; /*the sender's octet count in the last sent RTCP SR*/
304  uint32_t sent_payload_bytes; /*used for RTCP sender reports*/
305  rtp_stats_t stats;
306  int recv_errno;
307  int send_errno;
308  int snd_socket_size;
309  int rcv_socket_size;
310  int ssrc_changed_thres;
312 }RtpStream;
313 
314 typedef struct _RtcpStream
315 {
316  OrtpStream gs;
317  OrtpRtcpSendAlgorithm send_algo;
318  OrtpRtcpXrConfiguration xr_conf;
319  OrtpRtcpXrMediaCallbacks xr_media_callbacks;
320  bool_t enabled; /*tells whether we can send RTCP packets */
321  bool_t rtcp_xr_dlrr_to_send;
322  uint8_t rtcp_fb_fir_seq_nr; /* The FIR command sequence number */
323  uint32_t last_rtcp_fb_pli_snt;
324 } RtcpStream;
325 
326 typedef struct _RtpSession RtpSession;
327 
328 
338 {
339  RtpSession *next; /* next RtpSession, when the session are enqueued by the scheduler */
340  int mask_pos; /* the position in the scheduler mask of RtpSession : do not move this field: it is part of the ABI since the session_set macros use it*/
341  struct {
342  RtpProfile *profile;
343  int pt;
344  unsigned int ssrc;
345  WaitPoint wp;
346  } snd,rcv;
347  unsigned int inc_ssrc_candidate;
348  int inc_same_ssrc_count;
349  int hw_recv_pt; /* recv payload type before jitter buffer */
350  int recv_buf_size;
351  int target_upload_bandwidth; /* Target upload bandwidth at nework layer (with IP and UDP headers) in bits/s */
352  RtpSignalTable on_ssrc_changed;
353  RtpSignalTable on_payload_type_changed;
354  RtpSignalTable on_telephone_event_packet;
355  RtpSignalTable on_telephone_event;
356  RtpSignalTable on_timestamp_jump;
357  RtpSignalTable on_network_error;
358  RtpSignalTable on_rtcp_bye;
359  struct _OList *signal_tables;
360  struct _OList *eventqs;
361  msgb_allocator_t allocator;
362  RtpStream rtp;
363  RtcpStream rtcp;
364  OrtpRtcpXrStats rtcp_xr_stats;
365  RtpSessionMode mode;
366  struct _RtpScheduler *sched;
367  uint32_t flags;
368  int dscp;
369  int multicast_ttl;
370  int multicast_loopback;
371  float duplication_ratio; /* Number of times a packet should be duplicated */
372  float duplication_left ; /* Remainder of the duplication ratio */
373  void * user_data;
374  /* FIXME: Should be a table for all session participants. */
375  struct timeval last_recv_time; /* Time of receiving the RTP/RTCP packet. */
376  mblk_t *pending;
377  /* telephony events extension */
378  mblk_t *current_tev; /* the pending telephony events */
379  mblk_t *minimal_sdes;
380  mblk_t *full_sdes;
381  queue_t contributing_sources;
382  int64_t lost_packets_test_vector;
383  unsigned int interarrival_jitter_test_vector;
384  unsigned int delay_test_vector;
385  float rtt;/*last round trip delay calculated*/
386  int cum_loss;
387  OrtpNetworkSimulatorCtx *net_sim_ctx;
388  bool_t symmetric_rtp;
389  bool_t permissive; /*use the permissive algorithm*/
390  bool_t use_connect; /* use connect() on the socket */
391  bool_t ssrc_set;
392  bool_t reuseaddr; /*setsockopt SO_REUSEADDR */
393 };
394 
395 
396 
397 
398 #ifdef __cplusplus
399 extern "C"
400 {
401 #endif
402 
403 ORTP_PUBLIC const char *ortp_network_simulator_mode_to_string(OrtpNetworkSimulatorMode mode);
404 ORTP_PUBLIC OrtpNetworkSimulatorMode ortp_network_simulator_mode_from_string(const char *str);
405 
406 
407 /* public API */
408 ORTP_PUBLIC RtpSession *rtp_session_new(int mode);
409 ORTP_PUBLIC void rtp_session_set_scheduling_mode(RtpSession *session, int yesno);
410 ORTP_PUBLIC void rtp_session_set_blocking_mode(RtpSession *session, int yesno);
411 ORTP_PUBLIC void rtp_session_set_profile(RtpSession *session, RtpProfile *profile);
412 ORTP_PUBLIC void rtp_session_set_send_profile(RtpSession *session,RtpProfile *profile);
413 ORTP_PUBLIC void rtp_session_set_recv_profile(RtpSession *session,RtpProfile *profile);
414 ORTP_PUBLIC RtpProfile *rtp_session_get_profile(RtpSession *session);
415 ORTP_PUBLIC RtpProfile *rtp_session_get_send_profile(RtpSession *session);
416 ORTP_PUBLIC RtpProfile *rtp_session_get_recv_profile(RtpSession *session);
417 ORTP_PUBLIC int rtp_session_signal_connect(RtpSession *session,const char *signal_name, RtpCallback cb, void *user_data);
418 ORTP_PUBLIC int rtp_session_signal_disconnect_by_callback(RtpSession *session,const char *signal_name, RtpCallback cb);
419 ORTP_PUBLIC void rtp_session_set_ssrc(RtpSession *session, uint32_t ssrc);
420 ORTP_PUBLIC uint32_t rtp_session_get_send_ssrc(RtpSession* session);
421 ORTP_PUBLIC uint32_t rtp_session_get_recv_ssrc(RtpSession *session);
422 ORTP_PUBLIC void rtp_session_set_seq_number(RtpSession *session, uint16_t seq);
423 ORTP_PUBLIC uint16_t rtp_session_get_seq_number(RtpSession *session);
424 ORTP_PUBLIC uint32_t rtp_session_get_rcv_ext_seq_number(RtpSession *session);
425 ORTP_PUBLIC int rtp_session_get_cum_loss(RtpSession *session);
426 ORTP_PUBLIC void rtp_session_set_duplication_ratio(RtpSession *session, float ratio);
427 
428 ORTP_PUBLIC void rtp_session_enable_jitter_buffer(RtpSession *session , bool_t enabled);
429 ORTP_PUBLIC bool_t rtp_session_jitter_buffer_enabled(const RtpSession *session);
430 ORTP_PUBLIC void rtp_session_set_jitter_buffer_params(RtpSession *session, const JBParameters *par);
431 ORTP_PUBLIC void rtp_session_get_jitter_buffer_params(RtpSession *session, JBParameters *par);
432 
433 /*deprecated jitter control functions*/
434 ORTP_PUBLIC void rtp_session_set_jitter_compensation(RtpSession *session, int milisec);
435 ORTP_PUBLIC void rtp_session_enable_adaptive_jitter_compensation(RtpSession *session, bool_t val);
436 ORTP_PUBLIC bool_t rtp_session_adaptive_jitter_compensation_enabled(RtpSession *session);
437 
438 ORTP_PUBLIC void rtp_session_set_time_jump_limit(RtpSession *session, int miliseconds);
439 ORTP_PUBLIC int rtp_session_join_multicast_group(RtpSession *session, const char *ip);
440 ORTP_PUBLIC int rtp_session_set_local_addr(RtpSession *session,const char *addr, int rtp_port, int rtcp_port);
441 ORTP_PUBLIC int rtp_session_get_local_port(const RtpSession *session);
442 ORTP_PUBLIC int rtp_session_get_local_rtcp_port(const RtpSession *session);
443 
444 ORTP_PUBLIC int
445 rtp_session_set_remote_addr_full (RtpSession * session, const char * rtp_addr, int rtp_port, const char * rtcp_addr, int rtcp_port);
446 /*same as previous function, old name:*/
447 ORTP_PUBLIC int rtp_session_set_remote_addr_and_port (RtpSession * session, const char * addr, int rtp_port, int rtcp_port);
448 ORTP_PUBLIC int rtp_session_set_remote_addr(RtpSession *session,const char *addr, int port);
449 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);
450 ORTP_PUBLIC void rtp_session_clear_aux_remote_addr(RtpSession * session);
451 /* alternatively to the set_remote_addr() and set_local_addr(), an application can give
452 a valid socket (potentially connect()ed )to be used by the RtpSession */
453 ORTP_PUBLIC void rtp_session_set_sockets(RtpSession *session, int rtpfd, int rtcpfd);
454 
455 ORTP_PUBLIC void rtp_session_get_transports(const RtpSession *session, RtpTransport **rtptr, RtpTransport **rtcptr);
456 /*those methods are provided for people who wants to send non-RTP messages using the RTP/RTCP sockets */
457 ORTP_PUBLIC ortp_socket_t rtp_session_get_rtp_socket(const RtpSession *session);
458 ORTP_PUBLIC ortp_socket_t rtp_session_get_rtcp_socket(const RtpSession *session);
459 
460 
461 /* QOS / DSCP */
462 ORTP_PUBLIC int rtp_session_set_dscp(RtpSession *session, int dscp);
463 ORTP_PUBLIC int rtp_session_get_dscp(const RtpSession *session);
464 
465 
466 /* Packet info */
467 ORTP_PUBLIC int rtp_session_set_pktinfo(RtpSession *session, int activate);
468 
469 /* Multicast methods */
470 ORTP_PUBLIC int rtp_session_set_multicast_ttl(RtpSession *session, int ttl);
471 ORTP_PUBLIC int rtp_session_get_multicast_ttl(RtpSession *session);
472 
473 ORTP_PUBLIC int rtp_session_set_multicast_loopback(RtpSession *session, int yesno);
474 ORTP_PUBLIC int rtp_session_get_multicast_loopback(RtpSession *session);
475 
476 
477 
478 ORTP_PUBLIC int rtp_session_set_send_payload_type(RtpSession *session, int paytype);
479 ORTP_PUBLIC int rtp_session_get_send_payload_type(const RtpSession *session);
480 
481 ORTP_PUBLIC int rtp_session_get_recv_payload_type(const RtpSession *session);
482 ORTP_PUBLIC int rtp_session_set_recv_payload_type(RtpSession *session, int pt);
483 
484 ORTP_PUBLIC int rtp_session_set_payload_type(RtpSession *session, int pt);
485 
486 ORTP_PUBLIC void rtp_session_set_symmetric_rtp (RtpSession * session, bool_t yesno);
487 
488 ORTP_PUBLIC void rtp_session_set_connected_mode(RtpSession *session, bool_t yesno);
489 
490 ORTP_PUBLIC void rtp_session_enable_rtcp(RtpSession *session, bool_t yesno);
491 
492 ORTP_PUBLIC void rtp_session_set_rtcp_report_interval(RtpSession *session, int value_ms);
493 
494 ORTP_PUBLIC void rtp_session_set_target_upload_bandwidth(RtpSession *session, int target_bandwidth);
495 
496 ORTP_PUBLIC void rtp_session_configure_rtcp_xr(RtpSession *session, const OrtpRtcpXrConfiguration *config);
497 ORTP_PUBLIC void rtp_session_set_rtcp_xr_media_callbacks(RtpSession *session, const OrtpRtcpXrMediaCallbacks *cbs);
498 
499 ORTP_PUBLIC void rtp_session_set_ssrc_changed_threshold(RtpSession *session, int numpackets);
500 
501 /*low level recv and send functions */
502 ORTP_PUBLIC mblk_t * rtp_session_recvm_with_ts (RtpSession * session, uint32_t user_ts);
503 ORTP_PUBLIC mblk_t * rtp_session_create_packet(RtpSession *session,int header_size, const uint8_t *payload, int payload_size);
504 ORTP_PUBLIC mblk_t * rtp_session_create_packet_raw(const uint8_t *packet, int packet_size);
505 ORTP_PUBLIC mblk_t * rtp_session_create_packet_with_data(RtpSession *session, uint8_t *payload, int payload_size, void (*freefn)(void*));
506 ORTP_PUBLIC mblk_t * rtp_session_create_packet_in_place(RtpSession *session,uint8_t *buffer, int size, void (*freefn)(void*) );
507 ORTP_PUBLIC int rtp_session_sendm_with_ts (RtpSession * session, mblk_t *mp, uint32_t userts);
508 /* high level recv and send functions */
509 ORTP_PUBLIC int rtp_session_recv_with_ts(RtpSession *session, uint8_t *buffer, int len, uint32_t ts, int *have_more);
510 ORTP_PUBLIC int rtp_session_send_with_ts(RtpSession *session, const uint8_t *buffer, int len, uint32_t userts);
511 
512 /* event API*/
513 ORTP_PUBLIC void rtp_session_register_event_queue(RtpSession *session, OrtpEvQueue *q);
514 ORTP_PUBLIC void rtp_session_unregister_event_queue(RtpSession *session, OrtpEvQueue *q);
515 
516 
517 /* IP bandwidth usage estimation functions, returning bits/s*/
518 ORTP_PUBLIC float rtp_session_compute_send_bandwidth(RtpSession *session);
519 ORTP_PUBLIC float rtp_session_compute_recv_bandwidth(RtpSession *session);
520 ORTP_PUBLIC float rtp_session_get_send_bandwidth(RtpSession *session);
521 ORTP_PUBLIC float rtp_session_get_recv_bandwidth(RtpSession *session);
522 ORTP_PUBLIC float rtp_session_get_rtp_send_bandwidth(RtpSession *session);
523 ORTP_PUBLIC float rtp_session_get_rtp_recv_bandwidth(RtpSession *session);
524 ORTP_PUBLIC float rtp_session_get_rtcp_send_bandwidth(RtpSession *session);
525 ORTP_PUBLIC float rtp_session_get_rtcp_recv_bandwidth(RtpSession *session);
526 
527 ORTP_PUBLIC void rtp_session_send_rtcp_APP(RtpSession *session, uint8_t subtype, const char *name, const uint8_t *data, int datalen);
528 
529 ORTP_PUBLIC uint32_t rtp_session_get_current_send_ts(RtpSession *session);
530 ORTP_PUBLIC uint32_t rtp_session_get_current_recv_ts(RtpSession *session);
531 ORTP_PUBLIC void rtp_session_flush_sockets(RtpSession *session);
532 ORTP_PUBLIC void rtp_session_release_sockets(RtpSession *session);
533 ORTP_PUBLIC void rtp_session_resync(RtpSession *session);
534 ORTP_PUBLIC void rtp_session_reset(RtpSession *session);
535 ORTP_PUBLIC void rtp_session_destroy(RtpSession *session);
536 
537 ORTP_PUBLIC const rtp_stats_t * rtp_session_get_stats(const RtpSession *session);
538 ORTP_PUBLIC const jitter_stats_t * rtp_session_get_jitter_stats( const RtpSession *session );
539 ORTP_PUBLIC void rtp_session_reset_stats(RtpSession *session);
540 
541 ORTP_PUBLIC void rtp_session_set_data(RtpSession *session, void *data);
542 ORTP_PUBLIC void *rtp_session_get_data(const RtpSession *session);
543 
544 ORTP_PUBLIC void rtp_session_set_recv_buf_size(RtpSession *session, int bufsize);
545 ORTP_PUBLIC void rtp_session_set_rtp_socket_send_buffer_size(RtpSession * session, unsigned int size);
546 ORTP_PUBLIC void rtp_session_set_rtp_socket_recv_buffer_size(RtpSession * session, unsigned int size);
547 
548 /* in use with the scheduler to convert a timestamp in scheduler time unit (ms) */
549 ORTP_PUBLIC uint32_t rtp_session_ts_to_time(RtpSession *session,uint32_t timestamp);
550 ORTP_PUBLIC uint32_t rtp_session_time_to_ts(RtpSession *session, int millisecs);
551 /* this function aims at simulating senders with "imprecise" clocks, resulting in
552 rtp packets sent with timestamp uncorrelated with the system clock .
553 This is only availlable to sessions working with the oRTP scheduler */
554 ORTP_PUBLIC void rtp_session_make_time_distorsion(RtpSession *session, int milisec);
555 
556 /*RTCP functions */
557 ORTP_PUBLIC void rtp_session_set_source_description(RtpSession *session, const char *cname,
558  const char *name, const char *email, const char *phone,
559  const char *loc, const char *tool, const char *note);
560 ORTP_PUBLIC void rtp_session_add_contributing_source(RtpSession *session, uint32_t csrc,
561  const char *cname, const char *name, const char *email, const char *phone,
562  const char *loc, const char *tool, const char *note);
563 /* DEPRECATED: Use rtp_session_remove_contributing_source instead of rtp_session_remove_contributing_sources */
564 #define rtp_session_remove_contributing_sources rtp_session_remove_contributing_source
565 ORTP_PUBLIC void rtp_session_remove_contributing_source(RtpSession *session, uint32_t csrc);
566 ORTP_PUBLIC mblk_t* rtp_session_create_rtcp_sdes_packet(RtpSession *session, bool_t full);
567 
568 ORTP_PUBLIC void rtp_session_get_last_recv_time(RtpSession *session, struct timeval *tv);
569 ORTP_PUBLIC int rtp_session_bye(RtpSession *session, const char *reason);
570 
571 ORTP_PUBLIC int rtp_session_get_last_send_error_code(RtpSession *session);
572 ORTP_PUBLIC void rtp_session_clear_send_error_code(RtpSession *session);
573 ORTP_PUBLIC int rtp_session_get_last_recv_error_code(RtpSession *session);
574 ORTP_PUBLIC void rtp_session_clear_recv_error_code(RtpSession *session);
575 
576 
577 ORTP_PUBLIC float rtp_session_get_round_trip_propagation(RtpSession *session);
578 
579 
580 ORTP_PUBLIC void rtp_session_enable_network_simulation(RtpSession *session, const OrtpNetworkSimulatorParams *params);
581 
582 ORTP_PUBLIC void rtp_session_rtcp_set_lost_packet_value( RtpSession *session, const int64_t value );
583 ORTP_PUBLIC void rtp_session_rtcp_set_jitter_value(RtpSession *session, const unsigned int value );
584 ORTP_PUBLIC void rtp_session_rtcp_set_delay_value(RtpSession *session, const unsigned int value );
585 ORTP_PUBLIC mblk_t * rtp_session_pick_with_cseq (RtpSession * session, const uint16_t sequence_number);
586 
587 
588 ORTP_PUBLIC void rtp_session_send_rtcp_xr_rcvr_rtt(RtpSession *session);
589 ORTP_PUBLIC void rtp_session_send_rtcp_xr_dlrr(RtpSession *session);
590 ORTP_PUBLIC void rtp_session_send_rtcp_xr_stat_summary(RtpSession *session);
591 ORTP_PUBLIC void rtp_session_send_rtcp_xr_voip_metrics(RtpSession *session);
592 
593 
594 ORTP_PUBLIC bool_t rtp_session_avpf_enabled(RtpSession *session);
595 ORTP_PUBLIC bool_t rtp_session_avpf_feature_enabled(RtpSession *session, unsigned char feature);
596 ORTP_PUBLIC uint16_t rtp_session_get_avpf_rr_interval(RtpSession *session);
597 ORTP_PUBLIC void rtp_session_send_rtcp_fb_pli(RtpSession *session);
598 ORTP_PUBLIC void rtp_session_send_rtcp_fb_fir(RtpSession *session);
599 ORTP_PUBLIC void rtp_session_send_rtcp_fb_sli(RtpSession *session, uint16_t first, uint16_t number, uint8_t picture_id);
600 ORTP_PUBLIC void rtp_session_send_rtcp_fb_rpsi(RtpSession *session, uint8_t *bit_string, uint16_t bit_string_len);
601 
602 
603 /*private */
604 ORTP_PUBLIC void rtp_session_init(RtpSession *session, int mode);
605 #define rtp_session_set_flag(session,flag) (session)->flags|=(flag)
606 #define rtp_session_unset_flag(session,flag) (session)->flags&=~(flag)
607 ORTP_PUBLIC void rtp_session_uninit(RtpSession *session);
608 ORTP_PUBLIC void rtp_session_dispatch_event(RtpSession *session, OrtpEvent *ev);
609 
610 ORTP_PUBLIC void rtp_session_set_reuseaddr(RtpSession *session, bool_t yes);
611 
612 
613 ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags);
625 ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet_to(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags,const struct sockaddr *to, socklen_t tolen) ;
626 
633 ORTP_PUBLIC RtpTransport* meta_rtp_transport_get_endpoint(const RtpTransport *transport);
640 ORTP_PUBLIC void meta_rtp_transport_set_endpoint(RtpTransport *transport,RtpTransport *endpoint);
641 
642 ORTP_PUBLIC void meta_rtp_transport_destroy(RtpTransport *tp);
643 ORTP_PUBLIC void meta_rtp_transport_append_modifier(RtpTransport *tp,RtpTransportModifier *tpm);
644 #ifdef __cplusplus
645 }
646 #endif
647 
648 #endif
ORTP_PUBLIC int rtp_session_set_payload_type(RtpSession *session, int pt)
Definition: rtpsession.c:750
ORTP_PUBLIC RtpProfile * rtp_session_get_send_profile(RtpSession *session)
Definition: rtpsession.c:483
ORTP_PUBLIC mblk_t * rtp_session_create_packet_with_data(RtpSession *session, uint8_t *payload, int payload_size, void(*freefn)(void *))
Definition: rtpsession.c:831
Definition: rtpsession.h:314
Definition: rtpsession.h:225
Definition: rtpsession.h:216
ORTP_PUBLIC void rtp_session_rtcp_set_delay_value(RtpSession *session, const unsigned int value)
For test purpose only, simulates a constant RTT (Round Trip Time) value by setting the LSR field with...
Definition: rtpsession.c:1660
ORTP_PUBLIC void rtp_session_set_connected_mode(RtpSession *session, bool_t yesno)
Definition: rtpsession.c:1715
ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet_to(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg, int flags, const struct sockaddr *to, socklen_t tolen)
Definition: rtpsession.c:2075
ORTP_PUBLIC int rtp_session_get_multicast_ttl(RtpSession *session)
Definition: rtpsession_inet.c:510
ORTP_PUBLIC void rtp_session_rtcp_set_jitter_value(RtpSession *session, const unsigned int value)
For test purpose only, sets a constant interarrival_jitter value within all RTCP output packets...
Definition: rtpsession.c:1634
Definition: rtpsession.h:132
ORTP_PUBLIC mblk_t * rtp_session_create_packet_raw(const uint8_t *packet, int packet_size)
Definition: rtpsession.c:804
ORTP_PUBLIC uint32_t rtp_session_get_rcv_ext_seq_number(RtpSession *session)
Definition: rtpsession.c:623
int max_packets
Definition: rtpsession.h:61
ORTP_PUBLIC int rtp_session_get_dscp(const RtpSession *session)
Definition: rtpsession_inet.c:712
Definition of payload types.
ORTP_PUBLIC int rtp_session_set_remote_addr_full(RtpSession *session, const char *rtp_addr, int rtp_port, const char *rtcp_addr, int rtcp_port)
Definition: rtpsession_inet.c:769
ORTP_PUBLIC uint32_t rtp_session_get_recv_ssrc(RtpSession *session)
Definition: rtpsession.c:663
Definition: rtpsession.h:337
ORTP_PUBLIC void rtp_session_flush_sockets(RtpSession *session)
Definition: rtpsession_inet.c:979
Definition: str_utils.h:49
Definition: rtpsession.h:250
ORTP_PUBLIC RtpProfile * rtp_session_get_recv_profile(RtpSession *session)
Definition: rtpsession.c:493
ORTP_PUBLIC uint16_t rtp_session_get_seq_number(RtpSession *session)
Definition: rtpsession.c:616
ORTP_PUBLIC void rtp_session_set_recv_buf_size(RtpSession *session, int bufsize)
Definition: rtpsession.c:505
ORTP_PUBLIC RtpSession * rtp_session_new(int mode)
Definition: rtpsession.c:318
ORTP_PUBLIC mblk_t * rtp_session_recvm_with_ts(RtpSession *session, uint32_t user_ts)
Definition: rtpsession.c:1083
ORTP_PUBLIC int rtp_session_set_multicast_loopback(RtpSession *session, int yesno)
Definition: rtpsession_inet.c:526
_OrtpNetworkSimulatorMode
Definition: rtpsession.h:121
Definition: rtpsession.h:274
ORTP_PUBLIC int rtp_session_set_local_addr(RtpSession *session, const char *addr, int rtp_port, int rtcp_port)
Definition: rtpsession_inet.c:339
ORTP_PUBLIC const jitter_stats_t * rtp_session_get_jitter_stats(const RtpSession *session)
Definition: rtpsession.c:1611
ORTP_PUBLIC int rtp_session_set_multicast_ttl(RtpSession *session, int ttl)
Definition: rtpsession_inet.c:459
Definition: rtpsession.h:84
int min_size
Definition: rtpsession.h:56
ORTP_PUBLIC void rtp_session_destroy(RtpSession *session)
Definition: rtpsession.c:1828
Definition: rtpsession.h:164
Definition: rtpsession.h:193
Definition: rtpsignaltable.h:27
ORTP_PUBLIC void rtp_session_set_blocking_mode(RtpSession *session, int yesno)
Definition: rtpsession.c:380
Definition: str_utils.h:78
ORTP_PUBLIC float rtp_session_get_send_bandwidth(RtpSession *session)
Definition: rtpsession.c:1771
ORTP_PUBLIC int rtp_session_get_local_port(const RtpSession *session)
Definition: rtpsession_inet.c:728
ORTP_PUBLIC void rtp_session_get_last_recv_time(RtpSession *session, struct timeval *tv)
Definition: rtpsession.c:1919
float max_bandwidth
Definition: rtpsession.h:134
ORTP_PUBLIC int rtp_session_get_cum_loss(RtpSession *session)
Definition: rtpsession.c:630
ORTP_PUBLIC void rtp_session_set_rtp_socket_recv_buffer_size(RtpSession *session, unsigned int size)
Definition: rtpsession.c:521
struct _JBParameters JBParameters
Definition: rtp.h:79
int max_size
Definition: rtpsession.h:58
ORTP_PUBLIC int rtp_session_get_multicast_loopback(RtpSession *session)
Definition: rtpsession_inet.c:582
ORTP_PUBLIC int rtp_session_signal_connect(RtpSession *session, const char *signal_name, RtpCallback cb, void *user_data)
Definition: rtpsession.c:559
ORTP_PUBLIC uint32_t rtp_session_get_send_ssrc(RtpSession *session)
Definition: rtpsession.c:653
ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg, int flags)
Definition: rtpsession.c:2053
Definition: rtpsession.h:124
ORTP_PUBLIC void rtp_session_set_time_jump_limit(RtpSession *session, int miliseconds)
Definition: rtpsession.c:1374
Definition: event.h:82
Definition: rtpsession.h:144
ORTP_PUBLIC int rtp_session_recv_with_ts(RtpSession *session, uint8_t *buffer, int len, uint32_t ts, int *have_more)
Definition: rtpsession.c:1273
Definition: utils.h:33
ORTP_PUBLIC void rtp_session_set_ssrc_changed_threshold(RtpSession *session, int numpackets)
Definition: rtpsession.c:1541
Definition: rtpsession.h:106
ORTP_PUBLIC mblk_t * rtp_session_pick_with_cseq(RtpSession *session, const uint16_t sequence_number)
Definition: rtpsession.c:1040
ORTP_PUBLIC void rtp_session_set_recv_profile(RtpSession *session, RtpProfile *profile)
Definition: rtpsession.c:459
float consecutive_loss_probability
Definition: rtpsession.h:138
Definition: rtp.h:63
ORTP_PUBLIC void rtp_session_reset(RtpSession *session)
Definition: rtpsession.c:1575
ORTP_PUBLIC float rtp_session_get_recv_bandwidth(RtpSession *session)
Definition: rtpsession.c:1763
ORTP_PUBLIC int rtp_session_set_pktinfo(RtpSession *session, int activate)
Definition: rtpsession_inet.c:399
ORTP_PUBLIC void rtp_session_set_seq_number(RtpSession *session, uint16_t seq)
Definition: rtpsession.c:604
ORTP_PUBLIC int rtp_session_send_with_ts(RtpSession *session, const uint8_t *buffer, int len, uint32_t userts)
Definition: rtpsession.c:1003
OrtpNetworkSimulatorMode mode
Definition: rtpsession.h:141
int max_buffer_size
Definition: rtpsession.h:135
Definition: rtpsession.h:255
ORTP_PUBLIC int rtp_session_set_recv_payload_type(RtpSession *session, int pt)
Definition: rtpsession.c:720
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)
Definition: rtpsession_inet.c:930
ORTP_PUBLIC RtpTransport * meta_rtp_transport_get_endpoint(const RtpTransport *transport)
Definition: rtpsession.c:2199
float jitter_strength
Definition: rtpsession.h:140
ORTP_PUBLIC mblk_t * rtp_session_create_packet_in_place(RtpSession *session, uint8_t *buffer, int size, void(*freefn)(void *))
Definition: rtpsession.c:863
ORTP_PUBLIC void rtp_session_set_send_profile(RtpSession *session, RtpProfile *profile)
Definition: rtpsession.c:441
Definition: rtpsession.h:55
ORTP_PUBLIC void rtp_session_set_source_description(RtpSession *session, const char *cname, const char *name, const char *email, const char *phone, const char *loc, const char *tool, const char *note)
Definition: rtcp.c:128
int nom_size
Definition: rtpsession.h:57
Definition: rtpsession.h:125
ORTP_PUBLIC void rtp_session_set_data(RtpSession *session, void *data)
Definition: rtpsession.c:1675
Definition: str_utils.h:152
ORTP_PUBLIC void rtp_session_set_symmetric_rtp(RtpSession *session, bool_t yesno)
Definition: rtpsession.c:1697
void(* t_destroy)(struct _RtpTransport *transport)
Definition: rtpsession.h:118
Definition: scheduler.h:28
ORTP_PUBLIC void rtp_session_set_rtp_socket_send_buffer_size(RtpSession *session, unsigned int size)
Definition: rtpsession.c:513
ORTP_PUBLIC void rtp_session_set_profile(RtpSession *session, RtpProfile *profile)
Definition: rtpsession.c:399
ORTP_PUBLIC void rtp_session_enable_rtcp(RtpSession *session, bool_t yesno)
Definition: rtpsession.c:414
ORTP_PUBLIC RtpProfile * rtp_session_get_profile(RtpSession *session)
Definition: rtpsession.c:472
ORTP_PUBLIC const rtp_stats_t * rtp_session_get_stats(const RtpSession *session)
Definition: rtpsession.c:1604
ORTP_PUBLIC uint32_t rtp_session_get_current_recv_ts(RtpSession *session)
Definition: rtpsession.c:1347
ORTP_PUBLIC int rtp_session_set_send_payload_type(RtpSession *session, int paytype)
Definition: rtpsession.c:693
Sending and receiving multiple streams together with only one thread.
ORTP_PUBLIC void meta_rtp_transport_set_endpoint(RtpTransport *transport, RtpTransport *endpoint)
Definition: rtpsession.c:2203
ORTP_PUBLIC void rtp_session_release_sockets(RtpSession *session)
Definition: rtpsession.c:1385
ORTP_PUBLIC void rtp_session_rtcp_set_lost_packet_value(RtpSession *session, const int64_t value)
For test purpose only, sets a constant lost packet value within all RTCP output packets. .
Definition: rtpsession.c:1622
float jitter_burst_density
Definition: rtpsession.h:139
ORTP_PUBLIC int rtp_session_signal_disconnect_by_callback(RtpSession *session, const char *signal_name, RtpCallback cb)
Definition: rtpsession.c:583
int enabled
Definition: rtpsession.h:133
ORTP_PUBLIC void rtp_session_set_ssrc(RtpSession *session, uint32_t ssrc)
Definition: rtpsession.c:642
ORTP_PUBLIC int rtp_session_get_recv_payload_type(const RtpSession *session)
Definition: rtpsession.c:737
ORTP_PUBLIC float rtp_session_get_round_trip_propagation(RtpSession *session)
Definition: rtpsession.c:1818
Using and creating standart and custom RTP profiles.
ORTP_PUBLIC int rtp_session_get_send_payload_type(const RtpSession *session)
Definition: rtpsession.c:704
Definition: rtpprofile.h:41
ORTP_PUBLIC int rtp_session_set_dscp(RtpSession *session, int dscp)
Definition: rtpsession_inet.c:597
Definition: rtpsession.h:64
Definition: rtpsession.h:123
float loss_rate
Definition: rtpsession.h:136
Definition: rtpsession.h:92
ORTP_PUBLIC mblk_t * rtp_session_create_packet(RtpSession *session, int header_size, const uint8_t *payload, int payload_size)
Definition: rtpsession.c:782
void(* t_destroy)(struct _RtpTransportModifier *transport)
Definition: rtpsession.h:103
ORTP_PUBLIC int rtp_session_bye(RtpSession *session, const char *reason)
Definition: rtcp.c:627
ORTP_PUBLIC void rtp_session_set_scheduling_mode(RtpSession *session, int yesno)
Definition: rtpsession.c:345
ORTP_PUBLIC void rtp_session_set_jitter_compensation(RtpSession *session, int milisec)
Definition: jitterctl.c:164
ORTP_PUBLIC int rtp_session_set_remote_addr(RtpSession *session, const char *addr, int port)
Definition: rtpsession_inet.c:749
ORTP_PUBLIC int rtp_session_sendm_with_ts(RtpSession *session, mblk_t *mp, uint32_t userts)
Definition: rtpsession.c:983
uint32_t latency
Definition: rtpsession.h:137
ORTP_PUBLIC void * rtp_session_get_data(const RtpSession *session)
Definition: rtpsession.c:1683
ORTP_PUBLIC void rtp_session_register_event_queue(RtpSession *session, OrtpEvQueue *q)
Definition: rtpsession.c:1424
ORTP_PUBLIC void rtp_session_resync(RtpSession *session)
Definition: rtpsession.c:1551
ORTP_PUBLIC uint32_t rtp_session_get_current_send_ts(RtpSession *session)
Definition: rtpsession.c:1321
ORTP_PUBLIC void rtp_session_set_rtcp_report_interval(RtpSession *session, int value_ms)
Definition: rtpsession.c:422
struct _OrtpNetworkSimulatorParams OrtpNetworkSimulatorParams