blob: c02cca85c28a9bd35d79e4c28c8df61c23671421 [file] [log] [blame]
Harald Welte41d0d842011-09-03 15:33:24 +02001#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 Weltefcb1fe82011-09-07 11:51:52 +02009/* we cannot include ortp/ortp.h here, as they also use 'struct msgb' */
Harald Welte41d0d842011-09-03 15:33:24 +020010struct _RtpSession;
11
Harald Welteddfaca42011-09-07 11:52:43 +020012/*! \brief default duration of a 20ms GSM codec frame */
13#define GSM_RTP_DURATION 160
14
Harald Weltefcb1fe82011-09-07 11:51:52 +020015/*! \brief standard payload type for GSM Full Rate (FR) */
Harald Welte41d0d842011-09-03 15:33:24 +020016#define RTP_PT_GSM_FULL 3
Harald Weltefcb1fe82011-09-07 11:51:52 +020017/*! \brief Osmocom pseudo-static paylaod type for Half Rate (HR) */
Harald Welte41d0d842011-09-03 15:33:24 +020018#define RTP_PT_GSM_HALF 96
Harald Weltefcb1fe82011-09-07 11:51:52 +020019/*! \brief Osmocom pseudo-static paylaod type for Enhanced Full Rate (EFR) */
Harald Welte41d0d842011-09-03 15:33:24 +020020#define RTP_PT_GSM_EFR 97
Harald Weltefcb1fe82011-09-07 11:51:52 +020021/*! \brief Osmocom pseudo-static paylaod type for Adaptive Multi Rate (AMR) */
Harald Welte41d0d842011-09-03 15:33:24 +020022#define RTP_PT_AMR 98
23
Harald Welte65a50892011-09-08 14:42:58 +020024/*! \brief Parameter to osmo_rtp_socket_param_set() */
25enum osmo_rtp_param {
26 OSMO_RTP_P_JITBUF = 1,
27 OSMO_RTP_P_JIT_ADAP,
28};
Harald Welteddfaca42011-09-07 11:52:43 +020029
Harald Weltefcb1fe82011-09-07 11:51:52 +020030/*! \brief Flag to indicate the socket is in polling-only mode */
Harald Welte9b737df2011-09-07 00:59:11 +020031#define OSMO_RTP_F_POLL 0x0001
32
Harald Weltefcb1fe82011-09-07 11:51:52 +020033/*! \brief A structure representing one RTP socket */
Harald Welte41d0d842011-09-03 15:33:24 +020034struct 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 Weltefcb1fe82011-09-07 11:51:52 +020049 /*! \brief Receive user timestamp, to be incremented by user */
Harald Welte41d0d842011-09-03 15:33:24 +020050 uint32_t rx_user_ts;
51
Harald Weltefcb1fe82011-09-07 11:51:52 +020052 /*! \brief Transmit timestamp, incremented by library */
Harald Welte41d0d842011-09-03 15:33:24 +020053 uint32_t tx_timestamp;
54
Harald Weltefcb1fe82011-09-07 11:51:52 +020055 /*! \brief Flags like OSMO_RTP_F_POLL */
Harald Welte9b737df2011-09-07 00:59:11 +020056 unsigned int flags;
57
Harald Welte41d0d842011-09-03 15:33:24 +020058 void *priv;
59};
60
61void osmo_rtp_init(void *ctx);
Harald Welte9b737df2011-09-07 00:59:11 +020062struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int flags);
Harald Welte41d0d842011-09-03 15:33:24 +020063int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port);
64int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port);
65int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type);
66int osmo_rtp_socket_free(struct osmo_rtp_socket *rs);
67int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload,
68 unsigned int payload_len, unsigned int duration);
Harald Welte9b737df2011-09-07 00:59:11 +020069int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs);
Harald Welte41d0d842011-09-03 15:33:24 +020070
71int osmo_rtp_get_bound_ip_port(struct osmo_rtp_socket *rs,
72 uint32_t *ip, int *port);
73int osmo_rtp_get_bound_addr(struct osmo_rtp_socket *rs,
74 const char **addr, int *port);
Harald Welte65a50892011-09-08 14:42:58 +020075int osmo_rtp_socket_set_param(struct osmo_rtp_socket *rs,
76 enum osmo_rtp_param param, int val);
77
78void osmo_rtp_socket_log_stats(struct osmo_rtp_socket *rs,
79 int subsys, int level,
80 const char *pfx);
Harald Welte41d0d842011-09-03 15:33:24 +020081
Holger Hans Peter Freytherfe019082015-09-21 10:52:52 +020082void 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 Welte41d0d842011-09-03 15:33:24 +020088#endif /* _OSMO_ORTP_H */