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> |
Max | 73b9bc7 | 2016-05-18 15:52:37 +0200 | [diff] [blame] | 5 | #include <stdbool.h> |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 6 | |
| 7 | #include <osmocom/core/linuxlist.h> |
| 8 | #include <osmocom/core/select.h> |
| 9 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 10 | /* 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] | 11 | struct _RtpSession; |
| 12 | |
Harald Welte | ddfaca4 | 2011-09-07 11:52:43 +0200 | [diff] [blame] | 13 | /*! \brief default duration of a 20ms GSM codec frame */ |
| 14 | #define GSM_RTP_DURATION 160 |
| 15 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 16 | /*! \brief standard payload type for GSM Full Rate (FR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 17 | #define RTP_PT_GSM_FULL 3 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 18 | /*! \brief Osmocom pseudo-static paylaod type for Half Rate (HR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 19 | #define RTP_PT_GSM_HALF 96 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 20 | /*! \brief Osmocom pseudo-static paylaod type for Enhanced Full Rate (EFR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 21 | #define RTP_PT_GSM_EFR 97 |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 22 | /*! \brief Osmocom pseudo-static paylaod type for Adaptive Multi Rate (AMR) */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 23 | #define RTP_PT_AMR 98 |
| 24 | |
Max | c42c2ca | 2016-06-06 10:09:06 +0200 | [diff] [blame] | 25 | #define GSM_VOICE_SAMPLE_RATE_HZ 8000 |
| 26 | #define GSM_VOICE_SAMPLES_PER_MS (GSM_VOICE_SAMPLE_RATE_HZ / 1000) |
| 27 | #define GSM_VOICE_MULTIFRAME 26 |
| 28 | #define GSM_RTP_FRAME_DURATION_MS 20 |
| 29 | #define GSM_SAMPLES_PER_RTP_FRAME (GSM_RTP_FRAME_DURATION_MS * GSM_VOICE_SAMPLES_PER_MS) |
| 30 | #define GSM_TDMA_FRAME_MS (120 / GSM_VOICE_MULTIFRAME) |
Max | c1cf14c | 2016-06-07 18:40:01 +0200 | [diff] [blame] | 31 | #define GSM_MS_TO_SAMPLES(ms) ((ms) * GSM_VOICE_SAMPLES_PER_MS) |
| 32 | #define GSM_FN_TO_MS(fn) ((fn) * GSM_TDMA_FRAME_MS) |
Max | c42c2ca | 2016-06-06 10:09:06 +0200 | [diff] [blame] | 33 | |
Harald Welte | 65a5089 | 2011-09-08 14:42:58 +0200 | [diff] [blame] | 34 | /*! \brief Parameter to osmo_rtp_socket_param_set() */ |
| 35 | enum osmo_rtp_param { |
| 36 | OSMO_RTP_P_JITBUF = 1, |
| 37 | OSMO_RTP_P_JIT_ADAP, |
| 38 | }; |
Harald Welte | ddfaca4 | 2011-09-07 11:52:43 +0200 | [diff] [blame] | 39 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 40 | /*! \brief Flag to indicate the socket is in polling-only mode */ |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 41 | #define OSMO_RTP_F_POLL 0x0001 |
Max | e54d7bc | 2016-04-29 12:39:33 +0200 | [diff] [blame] | 42 | #define OSMO_RTP_F_DISABLED 0x0002 |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 43 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 44 | /*! \brief A structure representing one RTP socket */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 45 | struct osmo_rtp_socket { |
| 46 | /*! \biref list header for global list of sockets */ |
| 47 | struct llist_head list; |
| 48 | |
| 49 | /*! \brief libortp RTP session pointer */ |
| 50 | struct _RtpSession *sess; |
| 51 | /*! \brief Osmo file descriptor for RTP socket FD */ |
| 52 | struct osmo_fd rtp_bfd; |
| 53 | /*! \brief Osmo file descriptor for RTCP socket FD */ |
| 54 | struct osmo_fd rtcp_bfd; |
| 55 | |
| 56 | /*! \brief callback for incoming data */ |
| 57 | void (*rx_cb)(struct osmo_rtp_socket *rs, const uint8_t *payload, |
Max | 02ceea8 | 2016-10-21 19:31:46 +0200 | [diff] [blame] | 58 | unsigned int payload_len, uint16_t seq_number, |
| 59 | uint32_t timestamp, bool marker); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 60 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 61 | /*! \brief Receive user timestamp, to be incremented by user */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 62 | uint32_t rx_user_ts; |
| 63 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 64 | /*! \brief Transmit timestamp, incremented by library */ |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 65 | uint32_t tx_timestamp; |
| 66 | |
Harald Welte | fcb1fe8 | 2011-09-07 11:51:52 +0200 | [diff] [blame] | 67 | /*! \brief Flags like OSMO_RTP_F_POLL */ |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 68 | unsigned int flags; |
| 69 | |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 70 | void *priv; |
| 71 | }; |
| 72 | |
| 73 | void osmo_rtp_init(void *ctx); |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 74 | 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] | 75 | int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port); |
| 76 | int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port); |
| 77 | int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type); |
| 78 | int osmo_rtp_socket_free(struct osmo_rtp_socket *rs); |
Pau Espin Pedrol | 524923a | 2017-06-28 15:31:46 +0200 | [diff] [blame] | 79 | int osmo_rtp_skipped_frame(struct osmo_rtp_socket *rs, unsigned int duration); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 80 | int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload, |
| 81 | unsigned int payload_len, unsigned int duration); |
Max | 73b9bc7 | 2016-05-18 15:52:37 +0200 | [diff] [blame] | 82 | int osmo_rtp_send_frame_ext(struct osmo_rtp_socket *rs, const uint8_t *payload, |
| 83 | unsigned int payload_len, unsigned int duration, |
| 84 | bool marker); |
Harald Welte | 9b737df | 2011-09-07 00:59:11 +0200 | [diff] [blame] | 85 | int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 86 | |
| 87 | int osmo_rtp_get_bound_ip_port(struct osmo_rtp_socket *rs, |
| 88 | uint32_t *ip, int *port); |
| 89 | int osmo_rtp_get_bound_addr(struct osmo_rtp_socket *rs, |
| 90 | const char **addr, int *port); |
Harald Welte | 65a5089 | 2011-09-08 14:42:58 +0200 | [diff] [blame] | 91 | int osmo_rtp_socket_set_param(struct osmo_rtp_socket *rs, |
| 92 | enum osmo_rtp_param param, int val); |
| 93 | |
| 94 | void osmo_rtp_socket_log_stats(struct osmo_rtp_socket *rs, |
| 95 | int subsys, int level, |
| 96 | const char *pfx); |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 97 | |
Holger Hans Peter Freyther | fe01908 | 2015-09-21 10:52:52 +0200 | [diff] [blame] | 98 | void osmo_rtp_socket_stats(struct osmo_rtp_socket *rs, |
| 99 | uint32_t *sent_packets, uint32_t *sent_octets, |
| 100 | uint32_t *recv_packets, uint32_t *recv_octets, |
| 101 | uint32_t *recv_lost, uint32_t *last_jitter); |
| 102 | |
Harald Welte | d1dd22c | 2017-12-03 10:00:16 +0100 | [diff] [blame] | 103 | void osmo_rtp_set_source_desc(struct osmo_rtp_socket *rs, const char *cname, |
| 104 | const char *name, const char *email, const char *phone, |
| 105 | const char *loc, const char *tool, const char *note); |
Holger Hans Peter Freyther | fe01908 | 2015-09-21 10:52:52 +0200 | [diff] [blame] | 106 | |
Harald Welte | 41d0d84 | 2011-09-03 15:33:24 +0200 | [diff] [blame] | 107 | #endif /* _OSMO_ORTP_H */ |