blob: 5b350ce2bb4a28b9bdf472ad87dab98ce5231484 [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 Welteddfaca42011-09-07 11:52:43 +020024
Harald Weltefcb1fe82011-09-07 11:51:52 +020025/*! \brief Flag to indicate the socket is in polling-only mode */
Harald Welte9b737df2011-09-07 00:59:11 +020026#define OSMO_RTP_F_POLL 0x0001
27
Harald Weltefcb1fe82011-09-07 11:51:52 +020028/*! \brief A structure representing one RTP socket */
Harald Welte41d0d842011-09-03 15:33:24 +020029struct osmo_rtp_socket {
30 /*! \biref list header for global list of sockets */
31 struct llist_head list;
32
33 /*! \brief libortp RTP session pointer */
34 struct _RtpSession *sess;
35 /*! \brief Osmo file descriptor for RTP socket FD */
36 struct osmo_fd rtp_bfd;
37 /*! \brief Osmo file descriptor for RTCP socket FD */
38 struct osmo_fd rtcp_bfd;
39
40 /*! \brief callback for incoming data */
41 void (*rx_cb)(struct osmo_rtp_socket *rs, const uint8_t *payload,
42 unsigned int payload_len);
43
Harald Weltefcb1fe82011-09-07 11:51:52 +020044 /*! \brief Receive user timestamp, to be incremented by user */
Harald Welte41d0d842011-09-03 15:33:24 +020045 uint32_t rx_user_ts;
46
Harald Weltefcb1fe82011-09-07 11:51:52 +020047 /*! \brief Transmit timestamp, incremented by library */
Harald Welte41d0d842011-09-03 15:33:24 +020048 uint32_t tx_timestamp;
49
Harald Weltefcb1fe82011-09-07 11:51:52 +020050 /*! \brief Flags like OSMO_RTP_F_POLL */
Harald Welte9b737df2011-09-07 00:59:11 +020051 unsigned int flags;
52
Harald Welte41d0d842011-09-03 15:33:24 +020053 void *priv;
54};
55
56void osmo_rtp_init(void *ctx);
Harald Welte9b737df2011-09-07 00:59:11 +020057struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int flags);
Harald Welte41d0d842011-09-03 15:33:24 +020058int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port);
59int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port);
60int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type);
61int osmo_rtp_socket_free(struct osmo_rtp_socket *rs);
62int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload,
63 unsigned int payload_len, unsigned int duration);
Harald Welte9b737df2011-09-07 00:59:11 +020064int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs);
Harald Welte41d0d842011-09-03 15:33:24 +020065
66int osmo_rtp_get_bound_ip_port(struct osmo_rtp_socket *rs,
67 uint32_t *ip, int *port);
68int osmo_rtp_get_bound_addr(struct osmo_rtp_socket *rs,
69 const char **addr, int *port);
70
71#endif /* _OSMO_ORTP_H */