Wed Jan 8 2020 09:49:52

Asterisk developer's documentation


abstract_jb.h File Reference

Common implementation-independent jitterbuffer stuff. More...

#include <sys/time.h>
#include "asterisk/frame_defs.h"

Go to the source code of this file.

Data Structures

struct  ast_jb
 General jitterbuffer state. More...
 
struct  ast_jb_conf
 General jitterbuffer configuration. More...
 

Macros

#define AST_JB_CONF_ENABLE   "enable"
 
#define AST_JB_CONF_FORCE   "force"
 
#define AST_JB_CONF_IMPL   "impl"
 
#define AST_JB_CONF_LOG   "log"
 
#define AST_JB_CONF_MAX_SIZE   "maxsize"
 
#define AST_JB_CONF_PREFIX   "jb"
 
#define AST_JB_CONF_RESYNCH_THRESHOLD   "resyncthreshold"
 
#define AST_JB_CONF_TARGET_EXTRA   "targetextra"
 
#define AST_JB_IMPL_NAME_SIZE   12
 

Enumerations

enum  { AST_JB_ENABLED = (1 << 0), AST_JB_FORCED = (1 << 1), AST_JB_LOG = (1 << 2) }
 

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...
 

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.h.

Macro Definition Documentation

#define AST_JB_CONF_ENABLE   "enable"

Definition at line 72 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_FORCE   "force"

Definition at line 73 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_IMPL   "impl"

Definition at line 77 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_LOG   "log"

Definition at line 78 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_MAX_SIZE   "maxsize"

Definition at line 74 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_PREFIX   "jb"

Definition at line 71 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_RESYNCH_THRESHOLD   "resyncthreshold"

Definition at line 75 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_CONF_TARGET_EXTRA   "targetextra"

Definition at line 76 of file abstract_jb.h.

Referenced by ast_jb_read_conf().

#define AST_JB_IMPL_NAME_SIZE   12

Definition at line 50 of file abstract_jb.h.

Referenced by create_jb().

Enumeration Type Documentation

anonymous enum
Enumerator
AST_JB_ENABLED 
AST_JB_FORCED 
AST_JB_LOG 

Definition at line 44 of file abstract_jb.h.

44  {
45  AST_JB_ENABLED = (1 << 0),
46  AST_JB_FORCED = (1 << 1),
47  AST_JB_LOG = (1 << 2)
48 };

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