blob: cec0d2e88e422031000602fda0c4a72c422728a5 [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>
Max73b9bc72016-05-18 15:52:37 +02005#include <stdbool.h>
Harald Welte41d0d842011-09-03 15:33:24 +02006
7#include <osmocom/core/linuxlist.h>
8#include <osmocom/core/select.h>
9
Harald Weltefcb1fe82011-09-07 11:51:52 +020010/* we cannot include ortp/ortp.h here, as they also use 'struct msgb' */
Harald Welte41d0d842011-09-03 15:33:24 +020011struct _RtpSession;
12
Harald Welteddfaca42011-09-07 11:52:43 +020013/*! \brief default duration of a 20ms GSM codec frame */
14#define GSM_RTP_DURATION 160
15
Harald Weltefcb1fe82011-09-07 11:51:52 +020016/*! \brief standard payload type for GSM Full Rate (FR) */
Harald Welte41d0d842011-09-03 15:33:24 +020017#define RTP_PT_GSM_FULL 3
Harald Weltefcb1fe82011-09-07 11:51:52 +020018/*! \brief Osmocom pseudo-static paylaod type for Half Rate (HR) */
Harald Welte41d0d842011-09-03 15:33:24 +020019#define RTP_PT_GSM_HALF 96
Harald Weltefcb1fe82011-09-07 11:51:52 +020020/*! \brief Osmocom pseudo-static paylaod type for Enhanced Full Rate (EFR) */
Harald Welte41d0d842011-09-03 15:33:24 +020021#define RTP_PT_GSM_EFR 97
Harald Weltefcb1fe82011-09-07 11:51:52 +020022/*! \brief Osmocom pseudo-static paylaod type for Adaptive Multi Rate (AMR) */
Harald Welte41d0d842011-09-03 15:33:24 +020023#define RTP_PT_AMR 98
24
Harald Welte65a50892011-09-08 14:42:58 +020025/*! \brief Parameter to osmo_rtp_socket_param_set() */
26enum osmo_rtp_param {
27 OSMO_RTP_P_JITBUF = 1,
28 OSMO_RTP_P_JIT_ADAP,
29};
Harald Welteddfaca42011-09-07 11:52:43 +020030
Harald Weltefcb1fe82011-09-07 11:51:52 +020031/*! \brief Flag to indicate the socket is in polling-only mode */
Harald Welte9b737df2011-09-07 00:59:11 +020032#define OSMO_RTP_F_POLL 0x0001
Maxe54d7bc2016-04-29 12:39:33 +020033#define OSMO_RTP_F_DISABLED 0x0002
Harald Welte9b737df2011-09-07 00:59:11 +020034
Harald Weltefcb1fe82011-09-07 11:51:52 +020035/*! \brief A structure representing one RTP socket */
Harald Welte41d0d842011-09-03 15:33:24 +020036struct osmo_rtp_socket {
37 /*! \biref list header for global list of sockets */
38 struct llist_head list;
39
40 /*! \brief libortp RTP session pointer */
41 struct _RtpSession *sess;
42 /*! \brief Osmo file descriptor for RTP socket FD */
43 struct osmo_fd rtp_bfd;
44 /*! \brief Osmo file descriptor for RTCP socket FD */
45 struct osmo_fd rtcp_bfd;
46
47 /*! \brief callback for incoming data */
48 void (*rx_cb)(struct osmo_rtp_socket *rs, const uint8_t *payload,
49 unsigned int payload_len);
50
Harald Weltefcb1fe82011-09-07 11:51:52 +020051 /*! \brief Receive user timestamp, to be incremented by user */
Harald Welte41d0d842011-09-03 15:33:24 +020052 uint32_t rx_user_ts;
53
Harald Weltefcb1fe82011-09-07 11:51:52 +020054 /*! \brief Transmit timestamp, incremented by library */
Harald Welte41d0d842011-09-03 15:33:24 +020055 uint32_t tx_timestamp;
56
Harald Weltefcb1fe82011-09-07 11:51:52 +020057 /*! \brief Flags like OSMO_RTP_F_POLL */
Harald Welte9b737df2011-09-07 00:59:11 +020058 unsigned int flags;
59
Harald Welte41d0d842011-09-03 15:33:24 +020060 void *priv;
61};
62
63void osmo_rtp_init(void *ctx);
Harald Welte9b737df2011-09-07 00:59:11 +020064struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int flags);
Harald Welte41d0d842011-09-03 15:33:24 +020065int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port);
66int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port);
67int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type);
68int osmo_rtp_socket_free(struct osmo_rtp_socket *rs);
69int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload,
70 unsigned int payload_len, unsigned int duration);
Max73b9bc72016-05-18 15:52:37 +020071int osmo_rtp_send_frame_ext(struct osmo_rtp_socket *rs, const uint8_t *payload,
72 unsigned int payload_len, unsigned int duration,
73 bool marker);
Harald Welte9b737df2011-09-07 00:59:11 +020074int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs);
Harald Welte41d0d842011-09-03 15:33:24 +020075
76int osmo_rtp_get_bound_ip_port(struct osmo_rtp_socket *rs,
77 uint32_t *ip, int *port);
78int osmo_rtp_get_bound_addr(struct osmo_rtp_socket *rs,
79 const char **addr, int *port);
Harald Welte65a50892011-09-08 14:42:58 +020080int osmo_rtp_socket_set_param(struct osmo_rtp_socket *rs,
81 enum osmo_rtp_param param, int val);
82
83void osmo_rtp_socket_log_stats(struct osmo_rtp_socket *rs,
84 int subsys, int level,
85 const char *pfx);
Harald Welte41d0d842011-09-03 15:33:24 +020086
Holger Hans Peter Freytherfe019082015-09-21 10:52:52 +020087void osmo_rtp_socket_stats(struct osmo_rtp_socket *rs,
88 uint32_t *sent_packets, uint32_t *sent_octets,
89 uint32_t *recv_packets, uint32_t *recv_octets,
90 uint32_t *recv_lost, uint32_t *last_jitter);
91
92
Harald Welte41d0d842011-09-03 15:33:24 +020093#endif /* _OSMO_ORTP_H */