Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 1 | #ifndef _OSMO_ORTP_H |
| 2 | #define _OSMO_ORTP_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | #include <osmocom/core/linuxlist.h> |
| 7 | #include <osmocom/core/select.h> |
| 8 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 9 | /* we cannot include ortp/ortp.h here, as they also use 'struct msgb' */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 10 | struct _RtpSession; |
| 11 | |
Harald Welte | ddfaca4 | 2011-09-07 11:52:43 +0200 | [diff] [blame] | 12 | /*! \brief default duration of a 20ms GSM codec frame */ |
| 13 | #define GSM_RTP_DURATION 160 |
| 14 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 15 | /*! \brief standard payload type for GSM Full Rate (FR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 16 | #define RTP_PT_GSM_FULL 3 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 17 | /*! \brief Osmocom pseudo-static paylaod type for Half Rate (HR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 18 | #define RTP_PT_GSM_HALF 96 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 19 | /*! \brief Osmocom pseudo-static paylaod type for Enhanced Full Rate (EFR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 20 | #define RTP_PT_GSM_EFR 97 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 21 | /*! \brief Osmocom pseudo-static paylaod type for Adaptive Multi Rate (AMR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 22 | #define RTP_PT_AMR 98 |
| 23 | |
Harald Welte | 65a5089 | 2011-09-08 14:42:58 +0200 | [diff] [blame] | 24 | /*! \brief Parameter to osmo_rtp_socket_param_set() */ |
| 25 | enum osmo_rtp_param { |
| 26 | OSMO_RTP_P_JITBUF = 1, |
| 27 | OSMO_RTP_P_JIT_ADAP, |
| 28 | }; |
Harald Welte | ddfaca4 | 2011-09-07 11:52:43 +0200 | [diff] [blame] | 29 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 30 | /*! \brief Flag to indicate the socket is in polling-only mode */ |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 31 | #define OSMO_RTP_F_POLL 0x0001 |
| 32 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 33 | /*! \brief A structure representing one RTP socket */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 34 | struct osmo_rtp_socket { |
| 35 | /*! \biref list header for global list of sockets */ |
| 36 | struct llist_head list; |
| 37 | |
| 38 | /*! \brief libortp RTP session pointer */ |
| 39 | struct _RtpSession *sess; |
| 40 | /*! \brief Osmo file descriptor for RTP socket FD */ |
| 41 | struct osmo_fd rtp_bfd; |
| 42 | /*! \brief Osmo file descriptor for RTCP socket FD */ |
| 43 | struct osmo_fd rtcp_bfd; |
| 44 | |
| 45 | /*! \brief callback for incoming data */ |
| 46 | void (*rx_cb)(struct osmo_rtp_socket *rs, const uint8_t *payload, |
| 47 | unsigned int payload_len); |
| 48 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 49 | /*! \brief Receive user timestamp, to be incremented by user */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 50 | uint32_t rx_user_ts; |
| 51 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 52 | /*! \brief Transmit timestamp, incremented by library */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 53 | uint32_t tx_timestamp; |
| 54 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 55 | /*! \brief Flags like OSMO_RTP_F_POLL */ |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 56 | unsigned int flags; |
| 57 | |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 58 | void *priv; |
| 59 | }; |
| 60 | |
| 61 | void osmo_rtp_init(void *ctx); |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 62 | struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int flags); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 63 | int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port); |
| 64 | int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port); |
| 65 | int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type); |
| 66 | int osmo_rtp_socket_free(struct osmo_rtp_socket *rs); |
| 67 | int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload, |
| 68 | unsigned int payload_len, unsigned int duration); |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 69 | int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 70 | |
| 71 | int osmo_rtp_get_bound_ip_port(struct osmo_rtp_socket *rs, |
| 72 | uint32_t *ip, int *port); |
| 73 | int osmo_rtp_get_bound_addr(struct osmo_rtp_socket *rs, |
| 74 | const char **addr, int *port); |
Harald Welte | 65a5089 | 2011-09-08 14:42:58 +0200 | [diff] [blame] | 75 | int osmo_rtp_socket_set_param(struct osmo_rtp_socket *rs, |
| 76 | enum osmo_rtp_param param, int val); |
| 77 | |
| 78 | void osmo_rtp_socket_log_stats(struct osmo_rtp_socket *rs, |
| 79 | int subsys, int level, |
| 80 | const char *pfx); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 81 | |
Holger Hans Peter Freyther | fe01908 | 2015-09-21 10:52:52 +0200 | [diff] [blame] | 82 | void osmo_rtp_socket_stats(struct osmo_rtp_socket *rs, |
| 83 | uint32_t *sent_packets, uint32_t *sent_octets, |
| 84 | uint32_t *recv_packets, uint32_t *recv_octets, |
| 85 | uint32_t *recv_lost, uint32_t *last_jitter); |
| 86 | |
| 87 | |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 88 | #endif /* _OSMO_ORTP_H */ |