Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Macros | Enumerations | Functions
fixedjitterbuf.h File Reference

Jitterbuffering algorithm. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fixed_jb_conf
 
struct  fixed_jb_frame
 

Macros

#define FIXED_JB_RESYNCH_THRESHOLD_DEFAULT   1000
 
#define FIXED_JB_SIZE_DEFAULT   200
 

Enumerations

enum  { FIXED_JB_OK , FIXED_JB_DROP , FIXED_JB_INTERP , FIXED_JB_NOFRAME }
 

Functions

void fixed_jb_destroy (struct fixed_jb *jb)
 
int fixed_jb_get (struct fixed_jb *jb, struct fixed_jb_frame *frame, long now, long interpl)
 
int fixed_jb_is_late (struct fixed_jb *jb, long ts)
 Checks if the given time stamp is late. More...
 
struct fixed_jbfixed_jb_new (struct fixed_jb_conf *conf)
 
long fixed_jb_next (struct fixed_jb *jb)
 
int fixed_jb_put (struct fixed_jb *jb, void *data, long ms, long ts, long now)
 
int fixed_jb_put_first (struct fixed_jb *jb, void *data, long ms, long ts, long now)
 
int fixed_jb_remove (struct fixed_jb *jb, struct fixed_jb_frame *frameout)
 
void fixed_jb_set_force_resynch (struct fixed_jb *jb)
 

Detailed Description

Jitterbuffering algorithm.

Definition in file fixedjitterbuf.h.

Macro Definition Documentation

◆ FIXED_JB_RESYNCH_THRESHOLD_DEFAULT

#define FIXED_JB_RESYNCH_THRESHOLD_DEFAULT   1000

Definition at line 45 of file fixedjitterbuf.h.

◆ FIXED_JB_SIZE_DEFAULT

#define FIXED_JB_SIZE_DEFAULT   200

Definition at line 44 of file fixedjitterbuf.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FIXED_JB_OK 
FIXED_JB_DROP 
FIXED_JB_INTERP 
FIXED_JB_NOFRAME 

Definition at line 35 of file fixedjitterbuf.h.

35 {
40};
@ FIXED_JB_INTERP
@ FIXED_JB_OK
@ FIXED_JB_NOFRAME
@ FIXED_JB_DROP

Function Documentation

◆ fixed_jb_destroy()

void fixed_jb_destroy ( struct fixed_jb jb)

Definition at line 127 of file fixedjitterbuf.c.

128{
129 /* jitterbuf MUST be empty before it can be destroyed */
130 ASSERT(jb->frames == NULL);
131
132 ast_free(jb);
133}
#define ast_free(a)
Definition: astmm.h:180
#define ASSERT(a)
#define NULL
Definition: resample.c:96
struct fixed_jb_frame * frames

References ASSERT, ast_free, fixed_jb::frames, and NULL.

Referenced by jb_destroy_fixed().

◆ fixed_jb_get()

int fixed_jb_get ( struct fixed_jb jb,
struct fixed_jb_frame frame,
long  now,
long  interpl 
)

Definition at line 291 of file fixedjitterbuf.c.

292{
293 ASSERT(now >= 0);
294 ASSERT(interpl >= 2);
295
296 if (now < jb->next_delivery) {
297 /* too early for the next frame */
298 return FIXED_JB_NOFRAME;
299 }
300
301 /* Is the jb empty? */
302 if (!jb->frames) {
303 /* should interpolate a frame */
304 /* update next */
305 jb->next_delivery += interpl;
306
307 return FIXED_JB_INTERP;
308 }
309
310 /* Isn't it too late for the first frame available in the jb? */
311 if (now > jb->frames->delivery + jb->frames->ms) {
312 /* yes - should drop this frame and update next to point the next frame (get_jb_head() does it) */
313 get_jb_head(jb, frame);
314
315 return FIXED_JB_DROP;
316 }
317
318 /* isn't it too early to play the first frame available? */
319 if (now < jb->frames->delivery) {
320 /* yes - should interpolate one frame */
321 /* update next */
322 jb->next_delivery += interpl;
323
324 return FIXED_JB_INTERP;
325 }
326
327 /* we have a frame for playing now (get_jb_head() updates next) */
328 get_jb_head(jb, frame);
329
330 return FIXED_JB_OK;
331}
static void get_jb_head(struct fixed_jb *jb, struct fixed_jb_frame *frame)
static int frames
Definition: parser.c:51
long next_delivery

References ASSERT, fixed_jb_frame::delivery, FIXED_JB_DROP, FIXED_JB_INTERP, FIXED_JB_NOFRAME, FIXED_JB_OK, frames, fixed_jb::frames, get_jb_head(), fixed_jb_frame::ms, and fixed_jb::next_delivery.

Referenced by jb_get_fixed().

◆ fixed_jb_is_late()

int fixed_jb_is_late ( struct fixed_jb jb,
long  ts 
)

Checks if the given time stamp is late.

Definition at line 350 of file fixedjitterbuf.c.

351{
352 return jb->rxcore + jb->delay + ts < jb->next_delivery;
353}

References fixed_jb::delay, fixed_jb::next_delivery, fixed_jb::rxcore, and fixed_jb_frame::ts.

Referenced by jb_is_late_fixed().

◆ fixed_jb_new()

struct fixed_jb * fixed_jb_new ( struct fixed_jb_conf conf)

Definition at line 100 of file fixedjitterbuf.c.

101{
102 struct fixed_jb *jb;
103
104 if (!(jb = ast_calloc(1, sizeof(*jb))))
105 return NULL;
106
107 /* First copy our config */
108 memcpy(&jb->conf, conf, sizeof(struct fixed_jb_conf));
109
110 /* we don't need the passed config anymore - continue working with the saved one */
111 conf = &jb->conf;
112
113 /* validate the configuration */
114 if (conf->jbsize < 1)
115 conf->jbsize = FIXED_JB_SIZE_DEFAULT;
116
117 if (conf->resync_threshold < 1)
118 conf->resync_threshold = FIXED_JB_RESYNCH_THRESHOLD_DEFAULT;
119
120 /* Set the constant delay to the jitterbuf */
121 jb->delay = conf->jbsize;
122
123 return jb;
124}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define FIXED_JB_SIZE_DEFAULT
#define FIXED_JB_RESYNCH_THRESHOLD_DEFAULT
All configuration options for http media cache.
private fixed_jb structure
struct fixed_jb_conf conf

References ast_calloc, fixed_jb::conf, fixed_jb::delay, FIXED_JB_RESYNCH_THRESHOLD_DEFAULT, FIXED_JB_SIZE_DEFAULT, and NULL.

Referenced by jb_create_fixed().

◆ fixed_jb_next()

long fixed_jb_next ( struct fixed_jb jb)

Definition at line 334 of file fixedjitterbuf.c.

335{
336 return jb->next_delivery;
337}

References fixed_jb::next_delivery.

Referenced by jb_next_fixed().

◆ fixed_jb_put()

int fixed_jb_put ( struct fixed_jb jb,
void *  data,
long  ms,
long  ts,
long  now 
)

Definition at line 197 of file fixedjitterbuf.c.

198{
199 struct fixed_jb_frame *frame, *next, *newframe;
200 long delivery;
201
202 /* debug check the validity of the input params */
203 ASSERT(data != NULL);
204 /* do not allow frames shorter than 2 ms */
205 ASSERT(ms >= 2);
206 ASSERT(ts >= 0);
207 ASSERT(now >= 0);
208
209 delivery = jb->rxcore + jb->delay + ts;
210
211 /* check if the new frame is not too late */
212 if (delivery < jb->next_delivery) {
213 /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
214 the force resynch flag was not set. */
215 return resynch_jb(jb, data, ms, ts, now);
216 }
217
218 /* what if the delivery time is bigger than next + delay? Seems like a frame for the future.
219 However, allow more resync_threshold ms in advance */
220 if (delivery > jb->next_delivery + jb->delay + jb->conf.resync_threshold) {
221 /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
222 the force resynch flag was not set. */
223 return resynch_jb(jb, data, ms, ts, now);
224 }
225
226 /* find the right place in the frames list, sorted by delivery time */
227 frame = jb->tail;
228 while (frame && frame->delivery > delivery) {
229 frame = frame->prev;
230 }
231
232 /* Check if the new delivery time is not covered already by the chosen frame */
233 if (frame && (frame->delivery == delivery ||
234 delivery < frame->delivery + frame->ms ||
235 (frame->next && delivery + ms > frame->next->delivery)))
236 {
237 /* TODO: Should we check for resynch here? Be careful to do not allow threshold smaller than
238 the size of the jb */
239
240 /* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
241 the force resynch flag was not set. */
242 return resynch_jb(jb, data, ms, ts, now);
243 }
244
245 /* Reset the force resynch flag */
246 jb->force_resynch = 0;
247
248 /* Get a new frame */
249 newframe = alloc_jb_frame(jb);
250 newframe->data = data;
251 newframe->ts = ts;
252 newframe->ms = ms;
253 newframe->delivery = delivery;
254
255 /* and insert it right on place */
256 if (frame) {
257 next = frame->next;
258 frame->next = newframe;
259 if (next) {
260 newframe->next = next;
261 next->prev = newframe;
262 } else {
263 /* insert after the last frame - should update tail */
264 jb->tail = newframe;
265 newframe->next = NULL;
266 }
267 newframe->prev = frame;
268
269 return FIXED_JB_OK;
270 } else if (!jb->frames) {
271 /* the frame list is empty or thats just the first frame ever */
272 /* tail should also be NULL is that case */
273 ASSERT(jb->tail == NULL);
274 jb->frames = jb->tail = newframe;
275 newframe->next = NULL;
276 newframe->prev = NULL;
277
278 return FIXED_JB_OK;
279 } else {
280 /* insert on a first position - should update frames head */
281 newframe->next = jb->frames;
282 newframe->prev = NULL;
283 jb->frames->prev = newframe;
284 jb->frames = newframe;
285
286 return FIXED_JB_OK;
287 }
288}
static struct fixed_jb_frame * alloc_jb_frame(struct fixed_jb *jb)
static int resynch_jb(struct fixed_jb *jb, void *data, long ms, long ts, long now)
struct fixed_jb_frame * prev
struct fixed_jb_frame * next
struct fixed_jb_frame * tail
int force_resynch

References alloc_jb_frame(), ASSERT, fixed_jb::conf, fixed_jb_frame::data, fixed_jb::delay, fixed_jb_frame::delivery, FIXED_JB_OK, fixed_jb::force_resynch, fixed_jb::frames, fixed_jb_frame::ms, fixed_jb_frame::next, fixed_jb::next_delivery, NULL, fixed_jb_frame::prev, fixed_jb_conf::resync_threshold, resynch_jb(), fixed_jb::rxcore, fixed_jb::tail, and fixed_jb_frame::ts.

Referenced by fixed_jb_put_first(), jb_put_fixed(), and resynch_jb().

◆ fixed_jb_put_first()

int fixed_jb_put_first ( struct fixed_jb jb,
void *  data,
long  ms,
long  ts,
long  now 
)

Definition at line 185 of file fixedjitterbuf.c.

186{
187 /* this is our first frame - set the base of the receivers time */
188 jb->rxcore = now - ts;
189
190 /* init next for a first time - it should be the time the first frame should be played */
191 jb->next_delivery = now + jb->delay;
192
193 /* put the frame */
194 return fixed_jb_put(jb, data, ms, ts, now);
195}
int fixed_jb_put(struct fixed_jb *jb, void *data, long ms, long ts, long now)

References fixed_jb_frame::data, fixed_jb::delay, fixed_jb_put(), fixed_jb_frame::ms, fixed_jb::next_delivery, fixed_jb::rxcore, and fixed_jb_frame::ts.

Referenced by jb_put_first_fixed(), and resynch_jb().

◆ fixed_jb_remove()

int fixed_jb_remove ( struct fixed_jb jb,
struct fixed_jb_frame frameout 
)

Definition at line 340 of file fixedjitterbuf.c.

341{
342 if (!jb->frames)
343 return FIXED_JB_NOFRAME;
344
345 get_jb_head(jb, frameout);
346
347 return FIXED_JB_OK;
348}

References FIXED_JB_NOFRAME, FIXED_JB_OK, fixed_jb::frames, and get_jb_head().

Referenced by jb_empty_and_reset_fixed(), and jb_remove_fixed().

◆ fixed_jb_set_force_resynch()

void fixed_jb_set_force_resynch ( struct fixed_jb jb)

Definition at line 179 of file fixedjitterbuf.c.

180{
181 jb->force_resynch = 1;
182}

References fixed_jb::force_resynch.

Referenced by jb_force_resynch_fixed().