osmux: add osmux_tx_sched to reconstruct the timing of RTP messages
This function schedules the transmission of a RTP message that was obtained from one osmux batch. It takes the time (in microseconds) after which the message should be transmitted.
This commit is contained in:
parent
d3c21b3cad
commit
8ba490fd96
|
@ -65,4 +65,6 @@ void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
|
||||||
struct msgb *osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h);
|
struct msgb *osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h);
|
||||||
struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
|
struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
|
||||||
|
|
||||||
|
void osmux_tx_sched(struct msgb *msg, struct timeval *when, void (*tx_cb)(struct msgb *msg, void *data), void *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
42
src/osmux.c
42
src/osmux.c
|
@ -14,6 +14,7 @@
|
||||||
#include <osmocom/core/msgb.h>
|
#include <osmocom/core/msgb.h>
|
||||||
#include <osmocom/core/timer.h>
|
#include <osmocom/core/timer.h>
|
||||||
#include <osmocom/core/select.h>
|
#include <osmocom/core/select.h>
|
||||||
|
#include <osmocom/core/talloc.h>
|
||||||
|
|
||||||
#include <osmocom/netif/amr.h>
|
#include <osmocom/netif/amr.h>
|
||||||
#include <osmocom/netif/rtp.h>
|
#include <osmocom/netif/rtp.h>
|
||||||
|
@ -218,3 +219,44 @@ void osmux_xfrm_input_init(struct osmux_in_handle *h)
|
||||||
batch.timer.cb = osmux_batch_timer_expired;
|
batch.timer.cb = osmux_batch_timer_expired;
|
||||||
batch.timer.data = h;
|
batch.timer.data = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct osmux_tx_handle {
|
||||||
|
struct osmo_timer_list timer;
|
||||||
|
struct msgb *msg;
|
||||||
|
void (*tx_cb)(struct msgb *msg, void *data);
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void osmux_tx_cb(void *data)
|
||||||
|
{
|
||||||
|
struct osmux_tx_handle *h = data;
|
||||||
|
|
||||||
|
h->tx_cb(h->msg, h->data);
|
||||||
|
|
||||||
|
talloc_free(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void osmux_tx_sched(struct msgb *msg, struct timeval *when,
|
||||||
|
void (*tx_cb)(struct msgb *msg, void *data), void *data)
|
||||||
|
{
|
||||||
|
struct osmux_tx_handle *h;
|
||||||
|
|
||||||
|
/* send it now */
|
||||||
|
if (when->tv_sec == 0 && when->tv_usec == 0) {
|
||||||
|
tx_cb(msg, data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ... otherwise schedule transmission */
|
||||||
|
h = talloc_zero(NULL, struct osmux_tx_handle);
|
||||||
|
if (h == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
h->msg = msg;
|
||||||
|
h->tx_cb = tx_cb;
|
||||||
|
h->data = data;
|
||||||
|
h->timer.cb = osmux_tx_cb;
|
||||||
|
h->timer.data = h;
|
||||||
|
|
||||||
|
osmo_timer_schedule(&h->timer, when->tv_sec, when->tv_usec);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue