libosmo-netif 1.5.1.5-89a1
Osmocom network interface library
jibuf.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5#include <time.h>
6
7#include <osmocom/core/timer.h>
8
17typedef void (*osmo_jibuf_dequeue_cb)(struct msgb *msg, void *data);
18
20struct osmo_jibuf {
21 void *talloc_ctx;
22 bool started;
23 struct osmo_timer_list timer;
24 struct llist_head msg_list; /* sorted by output ts */
25 uint32_t min_delay; /* in msec */
26 uint32_t max_delay; /* in msec */
27 uint32_t threshold_delay; /* in msec */
28
29 osmo_jibuf_dequeue_cb dequeue_cb;
30 void *dequeue_cb_data;
31
32 /* number of pkt drops since we last changed the buffer size */
33 uint32_t last_dropped;
34 uint32_t consecutive_drops;
35
36 uint32_t ref_rx_ts;
37 uint32_t ref_tx_ts;
38 uint16_t ref_tx_seq;
39
40 struct timeval last_enqueue_time;
41 struct timeval next_dequeue_time;
42
43 bool skew_enabled;
44 int32_t skew_us; /* src clock skew, in usec */
45
46 struct {
47 uint32_t total_enqueued;
48 uint64_t total_dropped;
49 } stats;
50};
51
52
53struct osmo_jibuf *osmo_jibuf_alloc(void *talloc_ctx);
54
55void osmo_jibuf_delete(struct osmo_jibuf *jb);
56
57int osmo_jibuf_enqueue(struct osmo_jibuf *jb, struct msgb *msg);
58
59bool osmo_jibuf_empty(struct osmo_jibuf *jb);
60
61void osmo_jibuf_set_min_delay(struct osmo_jibuf *jb, uint32_t min_delay);
62void osmo_jibuf_set_max_delay(struct osmo_jibuf *jb, uint32_t max_delay);
63
64void osmo_jibuf_enable_skew_compensation(struct osmo_jibuf *jb, bool enable);
65
66void osmo_jibuf_set_dequeue_cb(struct osmo_jibuf *jb, osmo_jibuf_dequeue_cb dequeue_cb, void* cb_data);
67
void osmo_jibuf_enable_skew_compensation(struct osmo_jibuf *jb, bool enable)
Toggle use of skew detection and compensation mechanism.
Definition: jibuf.c:450
struct osmo_jibuf * osmo_jibuf_alloc(void *talloc_ctx)
Allocate a new jitter buffer instance.
Definition: jibuf.c:299
void osmo_jibuf_set_dequeue_cb(struct osmo_jibuf *jb, osmo_jibuf_dequeue_cb dequeue_cb, void *cb_data)
Set dequeue callback for the jitter buffer.
Definition: jibuf.c:461
int osmo_jibuf_enqueue(struct osmo_jibuf *jb, struct msgb *msg)
Try to enqueue a packet into the jitter buffer.
Definition: jibuf.c:343
void osmo_jibuf_set_max_delay(struct osmo_jibuf *jb, uint32_t max_delay)
Set maximum buffer size for the jitter buffer.
Definition: jibuf.c:438
void osmo_jibuf_set_min_delay(struct osmo_jibuf *jb, uint32_t min_delay)
Set minimum buffer size for the jitter buffer.
Definition: jibuf.c:428
void osmo_jibuf_delete(struct osmo_jibuf *jb)
Destroy a previously allocated jitter buffer instance.
Definition: jibuf.c:321
bool osmo_jibuf_empty(struct osmo_jibuf *jb)
Check whether the jitter buffer instance has packets queued or not.
Definition: jibuf.c:419
A structure representing a single instance of a jitter buffer.
Definition: jibuf.h:20