Wed Jan 8 2020 09:49:52

Asterisk developer's documentation


abstract_jb.c File Reference

Common implementation-independent jitterbuffer stuff. More...

#include "asterisk.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/abstract_jb.h"
#include "fixedjitterbuf.h"
#include "jitterbuf.h"

Go to the source code of this file.

Data Structures

struct  ast_jb_impl
 Jitterbuffer implementation private struct. More...
 

Macros

#define jb_framelog(...)
 Macros for the frame log files. More...
 

Typedefs

typedef void *(* jb_create_impl )(struct ast_jb_conf *general_config, long resynch_threshold)
 Create. More...
 
typedef void(* jb_destroy_impl )(void *jb)
 Destroy. More...
 
typedef void(* jb_empty_and_reset_impl )(void *jb)
 Empty and reset jb. More...
 
typedef void(* jb_force_resynch_impl )(void *jb)
 Force resynch. More...
 
typedef int(* jb_get_impl )(void *jb, struct ast_frame **fout, long now, long interpl)
 Get frame for now. More...
 
typedef long(* jb_next_impl )(void *jb)
 Get next. More...
 
typedef int(* jb_put_first_impl )(void *jb, struct ast_frame *fin, long now)
 Put first frame. More...
 
typedef int(* jb_put_impl )(void *jb, struct ast_frame *fin, long now)
 Put frame. More...
 
typedef int(* jb_remove_impl )(void *jb, struct ast_frame **fout)
 Remove first frame. More...
 

Enumerations

enum  { JB_USE = (1 << 0), JB_TIMEBASE_INITIALIZED = (1 << 1), JB_CREATED = (1 << 2) }
 
enum  { JB_IMPL_OK, JB_IMPL_DROP, JB_IMPL_INTERP, JB_IMPL_NOFRAME }
 

Functions

void ast_jb_configure (struct ast_channel *chan, const struct ast_jb_conf *conf)
 Configures a jitterbuffer on a channel. More...
 
void ast_jb_destroy (struct ast_channel *chan)
 Destroys jitterbuffer on a channel. More...
 
int ast_jb_do_usecheck (struct ast_channel *c0, struct ast_channel *c1)
 Checks the need of a jb use in a generic bridge. More...
 
void ast_jb_empty_and_reset (struct ast_channel *c0, struct ast_channel *c1)
 drops all frames from a jitterbuffer and resets it More...
 
void ast_jb_get_and_deliver (struct ast_channel *c0, struct ast_channel *c1)
 Deliver the queued frames that should be delivered now for both channels. More...
 
void ast_jb_get_config (const struct ast_channel *chan, struct ast_jb_conf *conf)
 Copies a channel's jitterbuffer configuration. More...
 
int ast_jb_get_when_to_wakeup (struct ast_channel *c0, struct ast_channel *c1, int time_left)
 Calculates the time, left to the closest delivery moment in a bridge. More...
 
int ast_jb_put (struct ast_channel *chan, struct ast_frame *f)
 Puts a frame into a channel jitterbuffer. More...
 
int ast_jb_read_conf (struct ast_jb_conf *conf, const char *varname, const char *value)
 Sets jitterbuffer configuration property. More...
 
static int create_jb (struct ast_channel *chan, struct ast_frame *first_frame)
 
static long get_now (struct ast_jb *jb, struct timeval *tv)
 
static void jb_choose_impl (struct ast_channel *chan)
 
static void * jb_create_adaptive (struct ast_jb_conf *general_config, long resynch_threshold)
 
static void * jb_create_fixed (struct ast_jb_conf *general_config, long resynch_threshold)
 
static void jb_destroy_adaptive (void *jb)
 
static void jb_destroy_fixed (void *jb)
 
static void jb_empty_and_reset_adaptive (void *jb)
 
static void jb_empty_and_reset_fixed (void *jb)
 
static void jb_force_resynch_adaptive (void *jb)
 
static void jb_force_resynch_fixed (void *jb)
 
static int jb_get_adaptive (void *jb, struct ast_frame **fout, long now, long interpl)
 
static void jb_get_and_deliver (struct ast_channel *chan)
 
static int jb_get_fixed (void *jb, struct ast_frame **fout, long now, long interpl)
 
static long jb_next_adaptive (void *jb)
 
static long jb_next_fixed (void *jb)
 
static int jb_put_adaptive (void *jb, struct ast_frame *fin, long now)
 
static int jb_put_first_adaptive (void *jb, struct ast_frame *fin, long now)
 
static int jb_put_first_fixed (void *jb, struct ast_frame *fin, long now)
 
static int jb_put_fixed (void *jb, struct ast_frame *fin, long now)
 
static int jb_remove_adaptive (void *jb, struct ast_frame **fout)
 
static int jb_remove_fixed (void *jb, struct ast_frame **fout)
 

Variables

static const int adaptive_to_abstract_code []
 
static struct ast_jb_impl avail_impl []
 
static int default_impl = 0
 
static const int fixed_to_abstract_code []
 
static const char *const jb_get_actions [] = {"Delivered", "Dropped", "Interpolated", "No"}
 

Detailed Description

Common implementation-independent jitterbuffer stuff.

Author
Slav Klenov slav@.nosp@m.secu.nosp@m.rax.o.nosp@m.rg

Definition in file abstract_jb.c.

Macro Definition Documentation

#define jb_framelog (   ...)

Macros for the frame log files.

Definition at line 165 of file abstract_jb.c.

Referenced by ast_jb_put(), create_jb(), and jb_get_and_deliver().

Typedef Documentation

typedef void*(* jb_create_impl)(struct ast_jb_conf *general_config, long resynch_threshold)

Create.

Definition at line 59 of file abstract_jb.c.

typedef void(* jb_destroy_impl)(void *jb)

Destroy.

Definition at line 61 of file abstract_jb.c.

typedef void(* jb_empty_and_reset_impl)(void *jb)

Empty and reset jb.

Definition at line 75 of file abstract_jb.c.

typedef void(* jb_force_resynch_impl)(void *jb)

Force resynch.

Definition at line 73 of file abstract_jb.c.

typedef int(* jb_get_impl)(void *jb, struct ast_frame **fout, long now, long interpl)

Get frame for now.

Definition at line 67 of file abstract_jb.c.

typedef long(* jb_next_impl)(void *jb)

Get next.

Definition at line 69 of file abstract_jb.c.

typedef int(* jb_put_first_impl)(void *jb, struct ast_frame *fin, long now)

Put first frame.

Definition at line 63 of file abstract_jb.c.

typedef int(* jb_put_impl)(void *jb, struct ast_frame *fin, long now)

Put frame.

Definition at line 65 of file abstract_jb.c.

typedef int(* jb_remove_impl)(void *jb, struct ast_frame **fout)

Remove first frame.

Definition at line 71 of file abstract_jb.c.

Enumeration Type Documentation

anonymous enum

Internal jb flags

Enumerator
JB_USE 
JB_TIMEBASE_INITIALIZED 
JB_CREATED 

Definition at line 50 of file abstract_jb.c.

50  {
51  JB_USE = (1 << 0),
52  JB_TIMEBASE_INITIALIZED = (1 << 1),
53  JB_CREATED = (1 << 2)
54 };
anonymous enum

Abstract return codes

Enumerator
JB_IMPL_OK 
JB_IMPL_DROP 
JB_IMPL_INTERP 
JB_IMPL_NOFRAME 

Definition at line 148 of file abstract_jb.c.

Function Documentation

void ast_jb_configure ( struct ast_channel chan,
const struct ast_jb_conf conf 
)

Configures a jitterbuffer on a channel.

Parameters
chanchannel to configure.
confconfiguration to apply.

Called from a channel driver when a channel is created and its jitterbuffer needs to be configured.

Definition at line 616 of file abstract_jb.c.

References ast_jb::conf, and ast_channel::jb.

Referenced by __oh323_rtp_create(), __oh323_update_info(), alsa_new(), console_new(), dahdi_new(), gtalk_new(), jingle_new(), local_new(), mgcp_new(), misdn_new(), oss_new(), sip_new(), skinny_new(), and unistim_new().

617 {
618  memcpy(&chan->jb.conf, conf, sizeof(*conf));
619 }
struct ast_jb_conf conf
Jitterbuffer configuration.
Definition: abstract_jb.h:90
struct ast_jb jb
Definition: channel.h:821
void ast_jb_destroy ( struct ast_channel chan)

Destroys jitterbuffer on a channel.

Parameters
chanchannel.

Called from ast_channel_free() when a channel is destroyed.

Definition at line 536 of file abstract_jb.c.

References ast_clear_flag, ast_frfree, ast_test_flag, ast_verb, ast_jb_impl::destroy, f, ast_jb::impl, ast_channel::jb, JB_CREATED, JB_IMPL_OK, ast_jb::jbobj, ast_jb::logfile, ast_jb_impl::name, ast_channel::name, and ast_jb_impl::remove.

Referenced by ast_channel_destructor().

537 {
538  struct ast_jb *jb = &chan->jb;
539  const struct ast_jb_impl *jbimpl = jb->impl;
540  void *jbobj = jb->jbobj;
541  struct ast_frame *f;
542 
543  if (jb->logfile) {
544  fclose(jb->logfile);
545  jb->logfile = NULL;
546  }
547 
548  if (ast_test_flag(jb, JB_CREATED)) {
549  /* Remove and free all frames still queued in jb */
550  while (jbimpl->remove(jbobj, &f) == JB_IMPL_OK) {
551  ast_frfree(f);
552  }
553 
554  jbimpl->destroy(jbobj);
555  jb->jbobj = NULL;
556 
558 
559  ast_verb(3, "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, chan->name);
560  }
561 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
jb_destroy_impl destroy
Definition: abstract_jb.c:84
jb_remove_impl remove
Definition: abstract_jb.c:89
#define ast_verb(level,...)
Definition: logger.h:243
void * jbobj
Jitterbuffer object, passed to the implementation.
Definition: abstract_jb.h:94
const ast_string_field name
Definition: channel.h:787
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
FILE * logfile
File for frame timestamp tracing.
Definition: abstract_jb.h:102
static struct ast_format f[]
Definition: format_g726.c:181
#define ast_clear_flag(p, flag)
Definition: utils.h:77
char name[AST_JB_IMPL_NAME_SIZE]
Definition: abstract_jb.c:82
Data structure associated with a single frame of data.
Definition: frame.h:142
#define ast_frfree(fr)
Definition: frame.h:583
Jitterbuffer implementation private struct.
Definition: abstract_jb.c:80
int ast_jb_do_usecheck ( struct ast_channel c0,
struct ast_channel c1 
)

Checks the need of a jb use in a generic bridge.

Parameters
c0first bridged channel.
c1second bridged channel.

Called from ast_generic_bridge() when two channels are entering in a bridge. The function checks the need of a jitterbuffer, depending on both channel's configuration and technology properties. As a result, this function sets appropriate internal jb flags to the channels, determining further behaviour of the bridged jitterbuffers.

Return values
zeroif there are no jitter buffers in use
non-zeroif there are

Definition at line 205 of file abstract_jb.c.

References AST_CHAN_TP_CREATESJITTER, AST_CHAN_TP_WANTSJITTER, AST_JB_ENABLED, AST_JB_FORCED, ast_set_flag, ast_test_flag, ast_jb::conf, ast_channel::jb, jb_choose_impl(), JB_CREATED, JB_TIMEBASE_INITIALIZED, JB_USE, ast_channel_tech::properties, ast_channel::tech, and ast_jb::timebase.

Referenced by ast_generic_bridge().

206 {
207  struct ast_jb *jb0 = &c0->jb;
208  struct ast_jb *jb1 = &c1->jb;
209  struct ast_jb_conf *conf0 = &jb0->conf;
210  struct ast_jb_conf *conf1 = &jb1->conf;
211  int c0_wants_jitter = c0->tech->properties & AST_CHAN_TP_WANTSJITTER;
212  int c0_creates_jitter = c0->tech->properties & AST_CHAN_TP_CREATESJITTER;
213  int c0_jb_enabled = ast_test_flag(conf0, AST_JB_ENABLED);
214  int c0_force_jb = ast_test_flag(conf0, AST_JB_FORCED);
215  int c0_jb_timebase_initialized = ast_test_flag(jb0, JB_TIMEBASE_INITIALIZED);
216  int c0_jb_created = ast_test_flag(jb0, JB_CREATED);
217  int c1_wants_jitter = c1->tech->properties & AST_CHAN_TP_WANTSJITTER;
218  int c1_creates_jitter = c1->tech->properties & AST_CHAN_TP_CREATESJITTER;
219  int c1_jb_enabled = ast_test_flag(conf1, AST_JB_ENABLED);
220  int c1_force_jb = ast_test_flag(conf1, AST_JB_FORCED);
221  int c1_jb_timebase_initialized = ast_test_flag(jb1, JB_TIMEBASE_INITIALIZED);
222  int c1_jb_created = ast_test_flag(jb1, JB_CREATED);
223  int inuse = 0;
224 
225  /* Determine whether audio going to c0 needs a jitter buffer */
226  if (((!c0_wants_jitter && c1_creates_jitter) || (c0_force_jb && c1_creates_jitter)) && c0_jb_enabled) {
227  ast_set_flag(jb0, JB_USE);
228  if (!c0_jb_timebase_initialized) {
229  if (c1_jb_timebase_initialized) {
230  memcpy(&jb0->timebase, &jb1->timebase, sizeof(struct timeval));
231  } else {
232  gettimeofday(&jb0->timebase, NULL);
233  }
235  }
236 
237  if (!c0_jb_created) {
238  jb_choose_impl(c0);
239  }
240 
241  inuse = 1;
242  }
243 
244  /* Determine whether audio going to c1 needs a jitter buffer */
245  if (((!c1_wants_jitter && c0_creates_jitter) || (c1_force_jb && c0_creates_jitter)) && c1_jb_enabled) {
246  ast_set_flag(jb1, JB_USE);
247  if (!c1_jb_timebase_initialized) {
248  if (c0_jb_timebase_initialized) {
249  memcpy(&jb1->timebase, &jb0->timebase, sizeof(struct timeval));
250  } else {
251  gettimeofday(&jb1->timebase, NULL);
252  }
254  }
255 
256  if (!c1_jb_created) {
257  jb_choose_impl(c1);
258  }
259 
260  inuse = 1;
261  }
262 
263  return inuse;
264 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_jb_conf conf
Jitterbuffer configuration.
Definition: abstract_jb.h:90
static void jb_choose_impl(struct ast_channel *chan)
Definition: abstract_jb.c:183
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
Channels have this property if they can create jitter; i.e. most VoIP channels.
Definition: channel.h:888
Channels have this property if they can accept input with jitter; i.e. most VoIP channels.
Definition: channel.h:883
struct timeval timebase
The time the jitterbuffer was created.
Definition: abstract_jb.h:96
struct ast_channel_tech * tech
Definition: channel.h:743
General jitterbuffer configuration.
Definition: abstract_jb.h:55
void ast_jb_empty_and_reset ( struct ast_channel c0,
struct ast_channel c1 
)

drops all frames from a jitterbuffer and resets it

Parameters
c0one channel of a bridge
c1the other channel of the bridge

Definition at line 627 of file abstract_jb.c.

References ast_test_flag, ast_jb_impl::empty_and_reset, ast_jb::impl, ast_channel::jb, JB_CREATED, JB_USE, and ast_jb::jbobj.

Referenced by ast_generic_bridge().

628 {
629  struct ast_jb *jb0 = &c0->jb;
630  struct ast_jb *jb1 = &c1->jb;
631  int c0_use_jb = ast_test_flag(jb0, JB_USE);
632  int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
633  int c1_use_jb = ast_test_flag(jb1, JB_USE);
634  int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
635 
636  if (c0_use_jb && c0_jb_is_created && jb0->impl->empty_and_reset) {
637  jb0->impl->empty_and_reset(jb0->jbobj);
638  }
639 
640  if (c1_use_jb && c1_jb_is_created && jb1->impl->empty_and_reset) {
641  jb1->impl->empty_and_reset(jb1->jbobj);
642  }
643 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
void * jbobj
Jitterbuffer object, passed to the implementation.
Definition: abstract_jb.h:94
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
jb_empty_and_reset_impl empty_and_reset
Definition: abstract_jb.c:91
void ast_jb_get_and_deliver ( struct ast_channel c0,
struct ast_channel c1 
)

Deliver the queued frames that should be delivered now for both channels.

Parameters
c0first bridged channel.
c1second bridged channel.

Called from ast_generic_bridge() to deliver any frames, that should be delivered for the moment of invocation. Does nothing if neihter of the channels is using jb or has any frames currently queued in. The function delivers frames usig ast_write() each of the channels.

Definition at line 371 of file abstract_jb.c.

References ast_test_flag, ast_channel::jb, JB_CREATED, jb_get_and_deliver(), and JB_USE.

Referenced by ast_generic_bridge().

372 {
373  struct ast_jb *jb0 = &c0->jb;
374  struct ast_jb *jb1 = &c1->jb;
375  int c0_use_jb = ast_test_flag(jb0, JB_USE);
376  int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
377  int c1_use_jb = ast_test_flag(jb1, JB_USE);
378  int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
379 
380  if (c0_use_jb && c0_jb_is_created)
381  jb_get_and_deliver(c0);
382 
383  if (c1_use_jb && c1_jb_is_created)
384  jb_get_and_deliver(c1);
385 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
static void jb_get_and_deliver(struct ast_channel *chan)
Definition: abstract_jb.c:388
void ast_jb_get_config ( const struct ast_channel chan,
struct ast_jb_conf conf 
)

Copies a channel's jitterbuffer configuration.

Parameters
chanchannel.
confdestination.

Definition at line 622 of file abstract_jb.c.

References ast_jb::conf, and ast_channel::jb.

623 {
624  memcpy(conf, &chan->jb.conf, sizeof(*conf));
625 }
struct ast_jb_conf conf
Jitterbuffer configuration.
Definition: abstract_jb.h:90
struct ast_jb jb
Definition: channel.h:821
int ast_jb_get_when_to_wakeup ( struct ast_channel c0,
struct ast_channel c1,
int  time_left 
)

Calculates the time, left to the closest delivery moment in a bridge.

Parameters
c0first bridged channel.
c1second bridged channel.
time_leftbridge time limit, or -1 if not set.

Called from ast_generic_bridge() to determine the maximum time to wait for activity in ast_waitfor_n() call. If neihter of the channels is using jb, this function returns the time limit passed.

Returns
maximum time to wait.

Definition at line 266 of file abstract_jb.c.

References ast_test_flag, get_now(), ast_channel::jb, JB_CREATED, JB_USE, and ast_jb::next.

Referenced by ast_generic_bridge().

267 {
268  struct ast_jb *jb0 = &c0->jb;
269  struct ast_jb *jb1 = &c1->jb;
270  int c0_use_jb = ast_test_flag(jb0, JB_USE);
271  int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
272  int c1_use_jb = ast_test_flag(jb1, JB_USE);
273  int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
274  int wait, wait0, wait1;
275  struct timeval tv_now;
276 
277  if (time_left == 0) {
278  /* No time left - the bridge will be retried */
279  /* TODO: Test disable this */
280  /*return 0;*/
281  }
282 
283  if (time_left < 0) {
284  time_left = INT_MAX;
285  }
286 
287  gettimeofday(&tv_now, NULL);
288 
289  wait0 = (c0_use_jb && c0_jb_is_created) ? jb0->next - get_now(jb0, &tv_now) : time_left;
290  wait1 = (c1_use_jb && c1_jb_is_created) ? jb1->next - get_now(jb1, &tv_now) : time_left;
291 
292  wait = wait0 < wait1 ? wait0 : wait1;
293  wait = wait < time_left ? wait : time_left;
294 
295  if (wait == INT_MAX) {
296  wait = -1;
297  } else if (wait < 1) {
298  /* don't let wait=0, because this can cause the pbx thread to loop without any sleeping at all */
299  wait = 1;
300  }
301 
302  return wait;
303 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
static long get_now(struct ast_jb *jb, struct timeval *tv)
Definition: abstract_jb.c:564
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
long next
The time the next frame should be played.
Definition: abstract_jb.h:98
int ast_jb_put ( struct ast_channel chan,
struct ast_frame f 
)

Puts a frame into a channel jitterbuffer.

Parameters
chanchannel.
fframe.

Called from ast_generic_bridge() to put a frame into a channel's jitterbuffer. The function will successfuly enqueue a frame if and only if:

  1. the channel is using a jitterbuffer (as determined by ast_jb_do_usecheck()),
  2. the frame's type is AST_FRAME_VOICE,
  3. the frame has timing info set and has length >= 2 ms,
  4. there is no some internal error happened (like failed memory allocation). Frames, successfuly queued, should be delivered by the channel's jitterbuffer, when their delivery time has came. Frames, not successfuly queued, should be delivered immediately. Dropped by the jb implementation frames are considered successfuly enqueued as far as they should not be delivered at all.
Return values
0if the frame was queued
-1if not

Definition at line 306 of file abstract_jb.c.

References ast_clear_flag, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frdup(), AST_FRFLAG_HAS_TIMING_INFO, ast_frfree, ast_log(), ast_set_flag, ast_test_flag, create_jb(), ast_jb_impl::force_resync, ast_frame::frametype, get_now(), ast_jb::impl, ast_channel::jb, JB_CREATED, jb_framelog, JB_IMPL_OK, JB_USE, ast_jb::jbobj, ast_frame::len, LOG_ERROR, LOG_WARNING, ast_channel::name, ast_jb_impl::next, ast_jb::next, ast_jb_impl::put, ast_frame::src, and ast_frame::ts.

Referenced by ast_generic_bridge().

307 {
308  struct ast_jb *jb = &chan->jb;
309  const struct ast_jb_impl *jbimpl = jb->impl;
310  void *jbobj = jb->jbobj;
311  struct ast_frame *frr;
312  long now = 0;
313 
314  if (!ast_test_flag(jb, JB_USE))
315  return -1;
316 
317  if (f->frametype != AST_FRAME_VOICE) {
318  if (f->frametype == AST_FRAME_DTMF && ast_test_flag(jb, JB_CREATED)) {
319  jb_framelog("JB_PUT {now=%ld}: Received DTMF frame. Force resynching jb...\n", now);
320  jbimpl->force_resync(jbobj);
321  }
322 
323  return -1;
324  }
325 
326  /* We consider an enabled jitterbuffer should receive frames with valid timing info. */
327  if (!ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO) || f->len < 2 || f->ts < 0) {
328  ast_log(LOG_WARNING, "%s received frame with invalid timing info: "
329  "has_timing_info=%u, len=%ld, ts=%ld, src=%s\n",
330  chan->name, ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO), f->len, f->ts, f->src);
331  return -1;
332  }
333 
334  frr = ast_frdup(f);
335 
336  if (!frr) {
337  ast_log(LOG_ERROR, "Failed to isolate frame for the jitterbuffer on channel '%s'\n", chan->name);
338  return -1;
339  }
340 
341  if (!ast_test_flag(jb, JB_CREATED)) {
342  if (create_jb(chan, frr)) {
343  ast_frfree(frr);
344  /* Disable the jitterbuffer */
345  ast_clear_flag(jb, JB_USE);
346  return -1;
347  }
348 
350  return 0;
351  } else {
352  now = get_now(jb, NULL);
353  if (jbimpl->put(jbobj, frr, now) != JB_IMPL_OK) {
354  jb_framelog("JB_PUT {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len);
355  ast_frfree(frr);
356  /*return -1;*/
357  /* TODO: Check this fix - should return 0 here, because the dropped frame shouldn't
358  be delivered at all */
359  return 0;
360  }
361 
362  jb->next = jbimpl->next(jbobj);
363 
364  jb_framelog("JB_PUT {now=%ld}: Queued frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len);
365 
366  return 0;
367  }
368 }
jb_next_impl next
Definition: abstract_jb.c:88
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define LOG_WARNING
Definition: logger.h:144
#define AST_FRAME_DTMF
Definition: frame.h:128
static int create_jb(struct ast_channel *chan, struct ast_frame *first_frame)
Definition: abstract_jb.c:449
long ts
Definition: frame.h:168
static long get_now(struct ast_jb *jb, struct timeval *tv)
Definition: abstract_jb.c:564
#define jb_framelog(...)
Macros for the frame log files.
Definition: abstract_jb.c:165
jb_put_impl put
Definition: abstract_jb.c:86
const char * src
Definition: frame.h:158
jb_force_resynch_impl force_resync
Definition: abstract_jb.c:90
void * jbobj
Jitterbuffer object, passed to the implementation.
Definition: abstract_jb.h:94
#define LOG_ERROR
Definition: logger.h:155
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
#define ast_clear_flag(p, flag)
Definition: utils.h:77
Data structure associated with a single frame of data.
Definition: frame.h:142
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_frfree(fr)
Definition: frame.h:583
Jitterbuffer implementation private struct.
Definition: abstract_jb.c:80
long len
Definition: frame.h:170
struct ast_frame * ast_frdup(const struct ast_frame *fr)
Copies a frame.
Definition: frame.c:474
long next
The time the next frame should be played.
Definition: abstract_jb.h:98
int ast_jb_read_conf ( struct ast_jb_conf conf,
const char *  varname,
const char *  value 
)

Sets jitterbuffer configuration property.

Parameters
confconfiguration to store the property in.
varnameproperty name.
valueproperty value.

Called from a channel driver to build a jitterbuffer configuration typically when reading a configuration file. It is not necessary for a channel driver to know each of the jb configuration property names. The jitterbuffer itself knows them. The channel driver can pass each config var it reads through this function. It will return 0 if the variable was consumed from the jb conf.

Returns
zero if the property was set to the configuration, -1 if not.

Definition at line 577 of file abstract_jb.c.

References AST_JB_CONF_ENABLE, AST_JB_CONF_FORCE, AST_JB_CONF_IMPL, AST_JB_CONF_LOG, AST_JB_CONF_MAX_SIZE, AST_JB_CONF_PREFIX, AST_JB_CONF_RESYNCH_THRESHOLD, AST_JB_CONF_TARGET_EXTRA, AST_JB_ENABLED, AST_JB_FORCED, AST_JB_LOG, ast_set2_flag, ast_strlen_zero(), ast_true(), ast_jb_conf::impl, ast_jb_conf::max_size, name, ast_jb_conf::resync_threshold, and ast_jb_conf::target_extra.

Referenced by _build_general_config(), config_parse_variables(), gtalk_load_config(), jingle_load_config(), load_module(), process_dahdi(), reload_config(), and store_config_core().

578 {
579  int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1;
580  const char *name;
581  int tmp;
582 
583  if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen)) {
584  return -1;
585  }
586 
587  name = varname + prefixlen;
588 
589  if (!strcasecmp(name, AST_JB_CONF_ENABLE)) {
591  } else if (!strcasecmp(name, AST_JB_CONF_FORCE)) {
593  } else if (!strcasecmp(name, AST_JB_CONF_MAX_SIZE)) {
594  if ((tmp = atoi(value)) > 0)
595  conf->max_size = tmp;
596  } else if (!strcasecmp(name, AST_JB_CONF_RESYNCH_THRESHOLD)) {
597  if ((tmp = atoi(value)) > 0)
598  conf->resync_threshold = tmp;
599  } else if (!strcasecmp(name, AST_JB_CONF_IMPL)) {
600  if (!ast_strlen_zero(value))
601  snprintf(conf->impl, sizeof(conf->impl), "%s", value);
602  } else if (!strcasecmp(name, AST_JB_CONF_TARGET_EXTRA)) {
603  if (sscanf(value, "%30d", &tmp) == 1) {
604  conf->target_extra = tmp;
605  }
606  } else if (!strcasecmp(name, AST_JB_CONF_LOG)) {
608  } else {
609  return -1;
610  }
611 
612  return 0;
613 }
#define AST_JB_CONF_IMPL
Definition: abstract_jb.h:77
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define AST_JB_CONF_ENABLE
Definition: abstract_jb.h:72
#define AST_JB_CONF_LOG
Definition: abstract_jb.h:78
int value
Definition: syslog.c:39
long resync_threshold
Resynchronization threshold of the jitterbuffer implementation.
Definition: abstract_jb.h:62
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_JB_CONF_PREFIX
Definition: abstract_jb.h:71
long target_extra
amount of additional jitterbuffer adjustment
Definition: abstract_jb.h:66
#define AST_JB_CONF_TARGET_EXTRA
Definition: abstract_jb.h:76
char impl[AST_JB_IMPL_NAME_SIZE]
Name of the jitterbuffer implementation to be used.
Definition: abstract_jb.h:64
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
#define AST_JB_CONF_FORCE
Definition: abstract_jb.h:73
static const char name[]
#define AST_JB_CONF_MAX_SIZE
Definition: abstract_jb.h:74
#define AST_JB_CONF_RESYNCH_THRESHOLD
Definition: abstract_jb.h:75
long max_size
Max size of the jitterbuffer implementation.
Definition: abstract_jb.h:60
static int create_jb ( struct ast_channel chan,
struct ast_frame first_frame 
)
static

Definition at line 449 of file abstract_jb.c.

References ast_assert, ast_bridged_channel(), AST_CHANNEL_NAME, ast_frfree, AST_JB_IMPL_NAME_SIZE, AST_JB_LOG, ast_log(), ast_test_flag, ast_verb, ast_frame_subclass::codec, ast_jb::conf, ast_jb_impl::create, errno, get_now(), ast_jb::impl, ast_channel::jb, jb_framelog, JB_IMPL_OK, ast_jb::jbobj, ast_jb::last_format, ast_frame::len, LOG_ERROR, LOG_WARNING, ast_jb::logfile, ast_jb_impl::name, ast_channel::name, ast_jb_impl::next, ast_jb::next, ast_jb_impl::put_first, ast_jb_conf::resync_threshold, ast_frame::subclass, and ast_frame::ts.

Referenced by ast_jb_put().

450 {
451  struct ast_jb *jb = &chan->jb;
452  struct ast_jb_conf *jbconf = &jb->conf;
453  const struct ast_jb_impl *jbimpl = jb->impl;
454  void *jbobj;
455  struct ast_channel *bridged;
456  long now;
457  char logfile_pathname[20 + AST_JB_IMPL_NAME_SIZE + 2*AST_CHANNEL_NAME + 1];
458  char name1[AST_CHANNEL_NAME], name2[AST_CHANNEL_NAME], *tmp;
459  int res;
460 
461  jbobj = jb->jbobj = jbimpl->create(jbconf, jbconf->resync_threshold);
462  if (!jbobj) {
463  ast_log(LOG_WARNING, "Failed to create jitterbuffer on channel '%s'\n", chan->name);
464  return -1;
465  }
466 
467  now = get_now(jb, NULL);
468  res = jbimpl->put_first(jbobj, frr, now);
469 
470  /* The result of putting the first frame should not differ from OK. However, its possible
471  some implementations (i.e. adaptive's when resynch_threshold is specified) to drop it. */
472  if (res != JB_IMPL_OK) {
473  ast_log(LOG_WARNING, "Failed to put first frame in the jitterbuffer on channel '%s'\n", chan->name);
474  /*
475  jbimpl->destroy(jbobj);
476  return -1;
477  */
478  }
479 
480  /* Init next */
481  jb->next = jbimpl->next(jbobj);
482 
483  /* Init last format for a first time. */
484  jb->last_format = frr->subclass.codec;
485 
486  /* Create a frame log file */
487  if (ast_test_flag(jbconf, AST_JB_LOG)) {
488  char safe_logfile[30] = "/tmp/logfile-XXXXXX";
489  int safe_fd;
490  snprintf(name2, sizeof(name2), "%s", chan->name);
491  while ((tmp = strchr(name2, '/'))) {
492  *tmp = '#';
493  }
494 
495  bridged = ast_bridged_channel(chan);
496  /* We should always have bridged chan if a jitterbuffer is in use */
497  ast_assert(bridged != NULL);
498 
499  snprintf(name1, sizeof(name1), "%s", bridged->name);
500  while ((tmp = strchr(name1, '/'))) {
501  *tmp = '#';
502  }
503 
504  snprintf(logfile_pathname, sizeof(logfile_pathname),
505  "/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
506  unlink(logfile_pathname);
507  safe_fd = mkstemp(safe_logfile);
508  if (safe_fd < 0 || link(safe_logfile, logfile_pathname) || unlink(safe_logfile) || !(jb->logfile = fdopen(safe_fd, "w+b"))) {
509  ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s': %s\n", logfile_pathname, strerror(errno));
510  jb->logfile = NULL;
511  if (safe_fd > -1) {
512  close(safe_fd);
513  }
514  }
515 
516  if (res == JB_IMPL_OK) {
517  jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
518  now, frr->ts, frr->len);
519  } else {
520  jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n",
521  now, frr->ts, frr->len);
522  }
523  }
524 
525  ast_verb(3, "%s jitterbuffer created on channel %s\n", jbimpl->name, chan->name);
526 
527  /* Free the frame if it has not been queued in the jb */
528  if (res != JB_IMPL_OK) {
529  ast_frfree(frr);
530  }
531 
532  return 0;
533 }
Main Channel structure associated with a channel.
Definition: channel.h:742
jb_next_impl next
Definition: abstract_jb.c:88
jb_create_impl create
Definition: abstract_jb.c:83
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:144
#define ast_assert(a)
Definition: utils.h:738
static long get_now(struct ast_jb *jb, struct timeval *tv)
Definition: abstract_jb.c:564
struct ast_jb_conf conf
Jitterbuffer configuration.
Definition: abstract_jb.h:90
#define AST_JB_IMPL_NAME_SIZE
Definition: abstract_jb.h:50
#define ast_verb(level,...)
Definition: logger.h:243
long resync_threshold
Resynchronization threshold of the jitterbuffer implementation.
Definition: abstract_jb.h:62
#define jb_framelog(...)
Macros for the frame log files.
Definition: abstract_jb.c:165
void * jbobj
Jitterbuffer object, passed to the implementation.
Definition: abstract_jb.h:94
#define LOG_ERROR
Definition: logger.h:155
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
jb_put_first_impl put_first
Definition: abstract_jb.c:85
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
int errno
#define AST_CHANNEL_NAME
Definition: channel.h:137
struct ast_jb jb
Definition: channel.h:821
FILE * logfile
File for frame timestamp tracing.
Definition: abstract_jb.h:102
format_t last_format
Voice format of the last frame in.
Definition: abstract_jb.h:100
char name[AST_JB_IMPL_NAME_SIZE]
Definition: abstract_jb.c:82
#define ast_frfree(fr)
Definition: frame.h:583
Jitterbuffer implementation private struct.
Definition: abstract_jb.c:80
General jitterbuffer configuration.
Definition: abstract_jb.h:55
long next
The time the next frame should be played.
Definition: abstract_jb.h:98
static long get_now ( struct ast_jb jb,
struct timeval *  tv 
)
static

Definition at line 564 of file abstract_jb.c.

References ast_tvdiff_ms(), and ast_jb::timebase.

Referenced by ast_jb_get_when_to_wakeup(), ast_jb_put(), create_jb(), and jb_get_and_deliver().

565 {
566  struct timeval now;
567 
568  if (!when) {
569  when = &now;
570  gettimeofday(when, NULL);
571  }
572 
573  return ast_tvdiff_ms(*when, jb->timebase);
574 }
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
struct timeval timebase
The time the jitterbuffer was created.
Definition: abstract_jb.h:96
static void jb_choose_impl ( struct ast_channel chan)
static

Definition at line 183 of file abstract_jb.c.

References ARRAY_LEN, ast_strlen_zero(), ast_jb::conf, default_impl, ast_jb_conf::impl, ast_jb::impl, ast_channel::jb, and ast_jb_impl::name.

Referenced by ast_jb_do_usecheck().

184 {
185  struct ast_jb *jb = &chan->jb;
186  struct ast_jb_conf *jbconf = &jb->conf;
187  const struct ast_jb_impl *test_impl;
188  int i, avail_impl_count = ARRAY_LEN(avail_impl);
189 
190  jb->impl = &avail_impl[default_impl];
191 
192  if (ast_strlen_zero(jbconf->impl)) {
193  return;
194  }
195 
196  for (i = 0; i < avail_impl_count; i++) {
197  test_impl = &avail_impl[i];
198  if (!strcasecmp(jbconf->impl, test_impl->name)) {
199  jb->impl = test_impl;
200  return;
201  }
202  }
203 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_jb_conf conf
Jitterbuffer configuration.
Definition: abstract_jb.h:90
static struct ast_jb_impl avail_impl[]
Definition: abstract_jb.c:117
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char impl[AST_JB_IMPL_NAME_SIZE]
Name of the jitterbuffer implementation to be used.
Definition: abstract_jb.h:64
static int default_impl
Definition: abstract_jb.c:144
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
char name[AST_JB_IMPL_NAME_SIZE]
Definition: abstract_jb.c:82
Jitterbuffer implementation private struct.
Definition: abstract_jb.c:80
General jitterbuffer configuration.
Definition: abstract_jb.h:55
static void * jb_create_adaptive ( struct ast_jb_conf general_config,
long  resynch_threshold 
)
static

Definition at line 742 of file abstract_jb.c.

References jb_new(), jb_setconf(), jb_conf::max_contig_interp, jb_conf::max_jitterbuf, ast_jb_conf::max_size, ast_jb_conf::resync_threshold, jb_conf::resync_threshold, ast_jb_conf::target_extra, and jb_conf::target_extra.

743 {
744  jb_conf jbconf;
745  jitterbuf *adaptivejb;
746 
747  adaptivejb = jb_new();
748  if (adaptivejb) {
749  jbconf.max_jitterbuf = general_config->max_size;
750  jbconf.resync_threshold = general_config->resync_threshold;
751  jbconf.max_contig_interp = 10;
752  jbconf.target_extra = general_config->target_extra;
753  jb_setconf(adaptivejb, &jbconf);
754  }
755 
756  return adaptivejb;
757 }
long max_jitterbuf
Definition: jitterbuf.h:67
jitterbuf * jb_new(void)
new jitterbuf
Definition: jitterbuf.c:88
long resync_threshold
Resynchronization threshold of the jitterbuffer implementation.
Definition: abstract_jb.h:62
long resync_threshold
Definition: jitterbuf.h:68
long target_extra
amount of additional jitterbuffer adjustment
Definition: abstract_jb.h:66
long target_extra
Definition: jitterbuf.h:70
enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
set jitterbuf conf
Definition: jitterbuf.c:827
long max_size
Max size of the jitterbuffer implementation.
Definition: abstract_jb.h:60
long max_contig_interp
Definition: jitterbuf.h:69
static void * jb_create_fixed ( struct ast_jb_conf general_config,
long  resynch_threshold 
)
static

Definition at line 648 of file abstract_jb.c.

References fixed_jb_new(), fixed_jb_conf::jbsize, ast_jb_conf::max_size, and fixed_jb_conf::resync_threshold.

649 {
650  struct fixed_jb_conf conf;
651 
652  conf.jbsize = general_config->max_size;
653  conf.resync_threshold = resynch_threshold;
654 
655  return fixed_jb_new(&conf);
656 }
struct fixed_jb * fixed_jb_new(struct fixed_jb_conf *conf)
long max_size
Max size of the jitterbuffer implementation.
Definition: abstract_jb.h:60
static void jb_destroy_adaptive ( void *  jb)
static

Definition at line 760 of file abstract_jb.c.

References jb_destroy().

761 {
762  jitterbuf *adaptivejb = (jitterbuf *) jb;
763 
764  jb_destroy(adaptivejb);
765 }
void jb_destroy(jitterbuf *jb)
destroy jitterbuf
Definition: jitterbuf.c:101
static void jb_destroy_fixed ( void *  jb)
static

Definition at line 658 of file abstract_jb.c.

References fixed_jb_destroy().

659 {
660  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
661 
662  /* destroy the jb */
663  fixed_jb_destroy(fixedjb);
664 }
private fixed_jb structure
void fixed_jb_destroy(struct fixed_jb *jb)
static void jb_empty_and_reset_adaptive ( void *  jb)
static

Definition at line 828 of file abstract_jb.c.

References ast_frfree, jb_frame::data, f, jb_getall(), JB_OK, and jb_reset().

829 {
830  jitterbuf *adaptivejb = jb;
831  jb_frame f;
832 
833  while (jb_getall(adaptivejb, &f) == JB_OK) {
834  ast_frfree(f.data);
835  }
836 
837  jb_reset(adaptivejb);
838 }
void * data
Definition: jitterbuf.h:100
static struct ast_format f[]
Definition: format_g726.c:181
#define ast_frfree(fr)
Definition: frame.h:583
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
unconditionally get frames from jitterbuf until empty
Definition: jitterbuf.c:803
void jb_reset(jitterbuf *jb)
reset jitterbuf
Definition: jitterbuf.c:74
static void jb_empty_and_reset_fixed ( void *  jb)
static

Definition at line 730 of file abstract_jb.c.

References ast_frfree, fixed_jb_frame::data, FIXED_JB_OK, and fixed_jb_remove().

731 {
732  struct fixed_jb *fixedjb = jb;
733  struct fixed_jb_frame f;
734 
735  while (fixed_jb_remove(fixedjb, &f) == FIXED_JB_OK) {
736  ast_frfree(f.data);
737  }
738 }
private fixed_jb structure
int fixed_jb_remove(struct fixed_jb *jb, struct fixed_jb_frame *frameout)
static struct ast_format f[]
Definition: format_g726.c:181
#define ast_frfree(fr)
Definition: frame.h:583
static void jb_force_resynch_adaptive ( void *  jb)
static

Definition at line 824 of file abstract_jb.c.

825 {
826 }
static void jb_force_resynch_fixed ( void *  jb)
static

Definition at line 723 of file abstract_jb.c.

References fixed_jb_set_force_resynch().

724 {
725  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
726 
728 }
private fixed_jb structure
void fixed_jb_set_force_resynch(struct fixed_jb *jb)
static int jb_get_adaptive ( void *  jb,
struct ast_frame **  fout,
long  now,
long  interpl 
)
static

Definition at line 790 of file abstract_jb.c.

References jb_frame::data, and jb_get().

791 {
792  jitterbuf *adaptivejb = (jitterbuf *) jb;
793  jb_frame frame;
794  int res;
795 
796  res = jb_get(adaptivejb, &frame, now, interpl);
797  *fout = frame.data;
798 
799  return adaptive_to_abstract_code[res];
800 }
enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frame, long now, long interpl)
get a frame for time now (receiver&#39;s time) return value is one of JB_OK: You&#39;ve got frame! JB_DROP: H...
Definition: jitterbuf.c:787
void * data
Definition: jitterbuf.h:100
static const int adaptive_to_abstract_code[]
Definition: abstract_jb.c:158
static void jb_get_and_deliver ( struct ast_channel chan)
static

Definition at line 388 of file abstract_jb.c.

References ast_assert, ast_codec_interp_len(), AST_FRAME_VOICE, ast_frfree, AST_FRIENDLY_OFFSET, ast_log(), ast_samp2tv(), ast_tvadd(), ast_write(), ast_frame_subclass::codec, ast_frame::delivery, f, ast_jb_impl::get, get_now(), ast_jb::impl, ast_channel::jb, jb_framelog, JB_IMPL_DROP, JB_IMPL_INTERP, JB_IMPL_NOFRAME, JB_IMPL_OK, ast_jb::jbobj, ast_jb::last_format, ast_frame::len, LOG_ERROR, LOG_WARNING, ast_jb_impl::name, ast_jb_impl::next, ast_jb::next, ast_frame::next, ast_frame::offset, ast_frame::samples, ast_frame::src, ast_frame::subclass, ast_jb::timebase, and ast_frame::ts.

Referenced by ast_jb_get_and_deliver().

389 {
390  struct ast_jb *jb = &chan->jb;
391  const struct ast_jb_impl *jbimpl = jb->impl;
392  void *jbobj = jb->jbobj;
393  struct ast_frame *f, finterp = { .frametype = AST_FRAME_VOICE, };
394  long now;
395  int interpolation_len, res;
396 
397  now = get_now(jb, NULL);
398  jb->next = jbimpl->next(jbobj);
399  if (now < jb->next) {
400  jb_framelog("\tJB_GET {now=%ld}: now < next=%ld\n", now, jb->next);
401  return;
402  }
403 
404  while (now >= jb->next) {
405  interpolation_len = ast_codec_interp_len(jb->last_format);
406 
407  res = jbimpl->get(jbobj, &f, now, interpolation_len);
408 
409  switch (res) {
410  case JB_IMPL_OK:
411  /* deliver the frame */
412  ast_write(chan, f);
413  /* Fall through intentionally */
414  case JB_IMPL_DROP:
415  jb_framelog("\tJB_GET {now=%ld}: %s frame with ts=%ld and len=%ld\n",
416  now, jb_get_actions[res], f->ts, f->len);
417  jb->last_format = f->subclass.codec;
418  ast_frfree(f);
419  break;
420  case JB_IMPL_INTERP:
421  /* interpolate a frame */
422  f = &finterp;
423  f->subclass.codec = jb->last_format;
424  f->samples = interpolation_len * 8;
425  f->src = "JB interpolation";
426  f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000));
428  /* deliver the interpolated frame */
429  ast_write(chan, f);
430  jb_framelog("\tJB_GET {now=%ld}: Interpolated frame with len=%d\n", now, interpolation_len);
431  break;
432  case JB_IMPL_NOFRAME:
434  "JB_IMPL_NOFRAME is returned from the %s jb when now=%ld >= next=%ld, jbnext=%ld!\n",
435  jbimpl->name, now, jb->next, jbimpl->next(jbobj));
436  jb_framelog("\tJB_GET {now=%ld}: No frame for now!?\n", now);
437  return;
438  default:
439  ast_log(LOG_ERROR, "This should never happen!\n");
440  ast_assert("JB type unknown" == NULL);
441  break;
442  }
443 
444  jb->next = jbimpl->next(jbobj);
445  }
446 }
union ast_frame_subclass subclass
Definition: frame.h:146
int offset
Definition: frame.h:156
jb_next_impl next
Definition: abstract_jb.c:88
static int ast_codec_interp_len(format_t format)
Gets duration in ms of interpolation frame for a format.
Definition: frame.h:782
#define LOG_WARNING
Definition: logger.h:144
long ts
Definition: frame.h:168
jb_get_impl get
Definition: abstract_jb.c:87
static const char *const jb_get_actions[]
Definition: abstract_jb.c:162
#define ast_assert(a)
Definition: utils.h:738
static long get_now(struct ast_jb *jb, struct timeval *tv)
Definition: abstract_jb.c:564
format_t codec
Definition: frame.h:137
#define jb_framelog(...)
Macros for the frame log files.
Definition: abstract_jb.c:165
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
const char * src
Definition: frame.h:158
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:191
void * jbobj
Jitterbuffer object, passed to the implementation.
Definition: abstract_jb.h:94
#define LOG_ERROR
Definition: logger.h:155
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: utils.c:1587
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
Definition: abstract_jb.h:92
General jitterbuffer state.
Definition: abstract_jb.h:87
struct ast_jb jb
Definition: channel.h:821
static struct ast_format f[]
Definition: format_g726.c:181
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:4916
format_t last_format
Voice format of the last frame in.
Definition: abstract_jb.h:100
struct timeval delivery
Definition: frame.h:162
char name[AST_JB_IMPL_NAME_SIZE]
Definition: abstract_jb.c:82
struct ast_frame * next
Definition: frame.h:164
Data structure associated with a single frame of data.
Definition: frame.h:142
#define ast_frfree(fr)
Definition: frame.h:583
struct timeval timebase
The time the jitterbuffer was created.
Definition: abstract_jb.h:96
Jitterbuffer implementation private struct.
Definition: abstract_jb.c:80
long len
Definition: frame.h:170
int samples
Definition: frame.h:150
long next
The time the next frame should be played.
Definition: abstract_jb.h:98
static int jb_get_fixed ( void *  jb,
struct ast_frame **  fout,
long  now,
long  interpl 
)
static

Definition at line 689 of file abstract_jb.c.

References fixed_jb_frame::data, and fixed_jb_get().

690 {
691  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
692  struct fixed_jb_frame frame;
693  int res;
694 
695  res = fixed_jb_get(fixedjb, &frame, now, interpl);
696  *fout = frame.data;
697 
698  return fixed_to_abstract_code[res];
699 }
private fixed_jb structure
int fixed_jb_get(struct fixed_jb *jb, struct fixed_jb_frame *frame, long now, long interpl)
static const int fixed_to_abstract_code[]
Definition: abstract_jb.c:156
union ast_frame::@172 data
static long jb_next_adaptive ( void *  jb)
static

Definition at line 803 of file abstract_jb.c.

References jb_next().

804 {
805  jitterbuf *adaptivejb = (jitterbuf *) jb;
806 
807  return jb_next(adaptivejb);
808 }
long jb_next(jitterbuf *jb)
when is the next frame due out, in receiver&#39;s time (0=EMPTY) This value may change as frames are adde...
Definition: jitterbuf.c:769
static long jb_next_fixed ( void *  jb)
static

Definition at line 702 of file abstract_jb.c.

References fixed_jb_next().

703 {
704  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
705 
706  return fixed_jb_next(fixedjb);
707 }
private fixed_jb structure
long fixed_jb_next(struct fixed_jb *jb)
static int jb_put_adaptive ( void *  jb,
struct ast_frame fin,
long  now 
)
static

Definition at line 779 of file abstract_jb.c.

References jb_put(), JB_TYPE_VOICE, ast_frame::len, and ast_frame::ts.

Referenced by jb_put_first_adaptive().

780 {
781  jitterbuf *adaptivejb = (jitterbuf *) jb;
782  int res;
783 
784  res = jb_put(adaptivejb, fin, JB_TYPE_VOICE, fin->len, fin->ts, now);
785 
786  return adaptive_to_abstract_code[res];
787 }
enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now)
queue a frame
Definition: jitterbuf.c:527
long ts
Definition: frame.h:168
static const int adaptive_to_abstract_code[]
Definition: abstract_jb.c:158
long len
Definition: frame.h:170
static int jb_put_first_adaptive ( void *  jb,
struct ast_frame fin,
long  now 
)
static

Definition at line 768 of file abstract_jb.c.

References jitterbuf::info, jb_put_adaptive(), jb_info::resync_offset, and ast_frame::ts.

769 {
770  jitterbuf *adaptivejb = (jitterbuf *) jb;
771 
772  /* Initialize the offset to that of the first frame's timestamp */
773  adaptivejb->info.resync_offset = fin->ts;
774 
775  return jb_put_adaptive(jb, fin, now);
776 }
long ts
Definition: frame.h:168
jb_info info
Definition: jitterbuf.h:108
long resync_offset
Definition: jitterbuf.h:95
static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now)
Definition: abstract_jb.c:779
static int jb_put_first_fixed ( void *  jb,
struct ast_frame fin,
long  now 
)
static

Definition at line 667 of file abstract_jb.c.

References fixed_jb_put_first(), ast_frame::len, and ast_frame::ts.

668 {
669  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
670  int res;
671 
672  res = fixed_jb_put_first(fixedjb, fin, fin->len, fin->ts, now);
673 
674  return fixed_to_abstract_code[res];
675 }
private fixed_jb structure
long ts
Definition: frame.h:168
static const int fixed_to_abstract_code[]
Definition: abstract_jb.c:156
int fixed_jb_put_first(struct fixed_jb *jb, void *data, long ms, long ts, long now)
long len
Definition: frame.h:170
static int jb_put_fixed ( void *  jb,
struct ast_frame fin,
long  now 
)
static

Definition at line 678 of file abstract_jb.c.

References fixed_jb_put(), ast_frame::len, and ast_frame::ts.

679 {
680  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
681  int res;
682 
683  res = fixed_jb_put(fixedjb, fin, fin->len, fin->ts, now);
684 
685  return fixed_to_abstract_code[res];
686 }
private fixed_jb structure
long ts
Definition: frame.h:168
static const int fixed_to_abstract_code[]
Definition: abstract_jb.c:156
int fixed_jb_put(struct fixed_jb *jb, void *data, long ms, long ts, long now)
long len
Definition: frame.h:170
static int jb_remove_adaptive ( void *  jb,
struct ast_frame **  fout 
)
static

Definition at line 811 of file abstract_jb.c.

References jb_frame::data, and jb_getall().

812 {
813  jitterbuf *adaptivejb = (jitterbuf *) jb;
814  jb_frame frame;
815  int res;
816 
817  res = jb_getall(adaptivejb, &frame);
818  *fout = frame.data;
819 
820  return adaptive_to_abstract_code[res];
821 }
void * data
Definition: jitterbuf.h:100
static const int adaptive_to_abstract_code[]
Definition: abstract_jb.c:158
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
unconditionally get frames from jitterbuf until empty
Definition: jitterbuf.c:803
static int jb_remove_fixed ( void *  jb,
struct ast_frame **  fout 
)
static

Definition at line 710 of file abstract_jb.c.

References fixed_jb_frame::data, and fixed_jb_remove().

711 {
712  struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
713  struct fixed_jb_frame frame;
714  int res;
715 
716  res = fixed_jb_remove(fixedjb, &frame);
717  *fout = frame.data;
718 
719  return fixed_to_abstract_code[res];
720 }
private fixed_jb structure
int fixed_jb_remove(struct fixed_jb *jb, struct fixed_jb_frame *frameout)
static const int fixed_to_abstract_code[]
Definition: abstract_jb.c:156
union ast_frame::@172 data

Variable Documentation

const int adaptive_to_abstract_code[]
static
struct ast_jb_impl avail_impl[]
static

Definition at line 117 of file abstract_jb.c.

int default_impl = 0
static

Definition at line 144 of file abstract_jb.c.

Referenced by jb_choose_impl().

const int fixed_to_abstract_code[]
static
const char* const jb_get_actions[] = {"Delivered", "Dropped", "Interpolated", "No"}
static

Definition at line 162 of file abstract_jb.c.