osmux: Allow the user to alloc msgbs used to provide generated RTP packets

This is useful for users of the API which need to keep forwarding the
msgb to lower layers which may need prepending a new header to the msgb,
like osmo-bts with l1sap.

Related: SYS#5987
Change-Id: I632654221826340423e1e97b0f8ed9a2baf6c6c3
This commit is contained in:
Pau Espin 2022-08-31 18:37:01 +02:00
parent 3b0991e80f
commit 95d57c1803
2 changed files with 27 additions and 4 deletions

View File

@ -75,6 +75,8 @@ struct osmux_in_handle {
#define OSMUX_MAX_CONCURRENT_CALLS 8
typedef struct msgb *(*rtp_msgb_alloc_cb_t)(void *rtp_msgb_alloc_priv_data,
unsigned int msg_len);
/* one per OSmux circuit_id, ie. one per RTP flow. */
struct osmux_out_handle {
uint16_t rtp_seq;
@ -86,6 +88,8 @@ struct osmux_out_handle {
struct llist_head list;
void (*tx_cb)(struct msgb *msg, void *data); /* Used defined rtp tx callback */
void *data; /* User defined opaque data structure */
rtp_msgb_alloc_cb_t rtp_msgb_alloc_cb; /* User defined msgb alloc function for generated RTP pkts */
void *rtp_msgb_alloc_cb_data; /* Opaque data pointer set by user and passed in rtp_msgb_alloc_cb() */
};
static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
@ -113,6 +117,7 @@ void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint
void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc);
void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type);
void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, rtp_msgb_alloc_cb_t cb, void *cb_data);
int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
void osmux_xfrm_output_flush(struct osmux_out_handle *h);
struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);

View File

@ -127,11 +127,15 @@ osmux_rebuild_rtp(struct osmux_out_handle *h, struct osmux_hdr *osmuxh,
struct rtp_hdr *rtph;
struct amr_hdr *amrh;
struct timespec delta = { .tv_sec = 0, .tv_nsec = DELTA_RTP_MSG*1000 };
unsigned int msg_len = sizeof(struct rtp_hdr) +
sizeof(struct amr_hdr) +
payload_len;
out_msg = msgb_alloc(sizeof(struct rtp_hdr) +
sizeof(struct amr_hdr) +
osmo_amr_bytes(osmuxh->amr_ft),
"OSMUX test");
if (h->rtp_msgb_alloc_cb) {
out_msg = h->rtp_msgb_alloc_cb(h->rtp_msgb_alloc_cb_data, msg_len);
} else {
out_msg = msgb_alloc(msg_len, "osmux-rtp");
}
if (out_msg == NULL)
return NULL;
@ -932,6 +936,20 @@ void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h,
h->data = data;
}
/*! \brief Set callback to call when an RTP packet to be generated is to be allocated
* \param[in] h the osmux out handle handling a specific CID
* \param[in] cb User defined msgb alloc function for generated RTP pkts
* \param[in] cb_data Opaque data pointer set by user and passed in \ref cb
* \return msgb structure to be used to fill in generated RTP pkt content
*/
void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h,
rtp_msgb_alloc_cb_t cb,
void *cb_data)
{
h->rtp_msgb_alloc_cb = cb;
h->rtp_msgb_alloc_cb_data = cb_data;
}
/*! \brief Set SSRC of generated RTP packets from Osmux frames
* \param[in] h the osmux out handle handling a specific CID
* \param[in] rtp_ssrc the RTP SSRC to set