2006-05-31 18:09:52 +00:00
|
|
|
/*
|
|
|
|
* abstract_jb: common implementation-independent jitterbuffer stuff
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005, Attractel OOD
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* Slav Klenov <slav@securax.org>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
2006-06-14 14:12:56 +00:00
|
|
|
*
|
|
|
|
* A license has been granted to Digium (via disclaimer) for the use of
|
|
|
|
* this code.
|
2006-05-31 18:09:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Common implementation-independent jitterbuffer stuff.
|
2009-03-04 20:48:42 +00:00
|
|
|
*
|
2006-05-31 18:09:52 +00:00
|
|
|
* \author Slav Klenov <slav@securax.org>
|
2008-01-22 08:58:46 +00:00
|
|
|
*
|
|
|
|
*
|
2006-05-31 18:09:52 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
#include "asterisk/frame.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/term.h"
|
|
|
|
#include "asterisk/utils.h"
|
2013-05-21 18:00:22 +00:00
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/timing.h"
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
#include "asterisk/abstract_jb.h"
|
2006-06-01 14:07:03 +00:00
|
|
|
#include "fixedjitterbuf.h"
|
2006-05-31 18:09:52 +00:00
|
|
|
#include "jitterbuf.h"
|
|
|
|
|
|
|
|
/*! Internal jb flags */
|
|
|
|
enum {
|
|
|
|
JB_USE = (1 << 0),
|
|
|
|
JB_TIMEBASE_INITIALIZED = (1 << 1),
|
|
|
|
JB_CREATED = (1 << 2)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation functions */
|
2006-06-01 14:07:03 +00:00
|
|
|
/* fixed */
|
2012-07-23 21:15:26 +00:00
|
|
|
static void *jb_create_fixed(struct ast_jb_conf *general_config);
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_destroy_fixed(void *jb);
|
|
|
|
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_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl);
|
|
|
|
static long jb_next_fixed(void *jb);
|
|
|
|
static int jb_remove_fixed(void *jb, struct ast_frame **fout);
|
|
|
|
static void jb_force_resynch_fixed(void *jb);
|
2008-08-06 00:30:53 +00:00
|
|
|
static void jb_empty_and_reset_fixed(void *jb);
|
2006-06-01 14:07:03 +00:00
|
|
|
/* adaptive */
|
2012-07-23 21:15:26 +00:00
|
|
|
static void * jb_create_adaptive(struct ast_jb_conf *general_config);
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_destroy_adaptive(void *jb);
|
|
|
|
static int jb_put_first_adaptive(void *jb, struct ast_frame *fin, long now);
|
|
|
|
static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now);
|
|
|
|
static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl);
|
|
|
|
static long jb_next_adaptive(void *jb);
|
|
|
|
static int jb_remove_adaptive(void *jb, struct ast_frame **fout);
|
|
|
|
static void jb_force_resynch_adaptive(void *jb);
|
2008-08-06 00:30:53 +00:00
|
|
|
static void jb_empty_and_reset_adaptive(void *jb);
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
/* Available jb implementations */
|
2009-05-21 21:13:09 +00:00
|
|
|
static const struct ast_jb_impl avail_impl[] = {
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
|
|
|
.name = "fixed",
|
2011-04-20 20:52:15 +00:00
|
|
|
.type = AST_JB_FIXED,
|
2006-06-01 14:07:03 +00:00
|
|
|
.create = jb_create_fixed,
|
|
|
|
.destroy = jb_destroy_fixed,
|
|
|
|
.put_first = jb_put_first_fixed,
|
|
|
|
.put = jb_put_fixed,
|
|
|
|
.get = jb_get_fixed,
|
|
|
|
.next = jb_next_fixed,
|
|
|
|
.remove = jb_remove_fixed,
|
2008-08-06 00:30:53 +00:00
|
|
|
.force_resync = jb_force_resynch_fixed,
|
|
|
|
.empty_and_reset = jb_empty_and_reset_fixed,
|
2006-05-31 18:09:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "adaptive",
|
2011-04-20 20:52:15 +00:00
|
|
|
.type = AST_JB_ADAPTIVE,
|
2006-06-01 14:07:03 +00:00
|
|
|
.create = jb_create_adaptive,
|
|
|
|
.destroy = jb_destroy_adaptive,
|
|
|
|
.put_first = jb_put_first_adaptive,
|
|
|
|
.put = jb_put_adaptive,
|
|
|
|
.get = jb_get_adaptive,
|
|
|
|
.next = jb_next_adaptive,
|
|
|
|
.remove = jb_remove_adaptive,
|
2008-08-06 00:30:53 +00:00
|
|
|
.force_resync = jb_force_resynch_adaptive,
|
|
|
|
.empty_and_reset = jb_empty_and_reset_adaptive,
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int default_impl = 0;
|
|
|
|
|
|
|
|
/* Translations between impl and abstract return codes */
|
2009-05-21 21:13:09 +00:00
|
|
|
static const int fixed_to_abstract_code[] =
|
2011-04-20 20:52:15 +00:00
|
|
|
{AST_JB_IMPL_OK, AST_JB_IMPL_DROP, AST_JB_IMPL_INTERP, AST_JB_IMPL_NOFRAME};
|
2009-05-21 21:13:09 +00:00
|
|
|
static const int adaptive_to_abstract_code[] =
|
2011-04-20 20:52:15 +00:00
|
|
|
{AST_JB_IMPL_OK, AST_JB_IMPL_NOFRAME, AST_JB_IMPL_NOFRAME, AST_JB_IMPL_INTERP, AST_JB_IMPL_DROP, AST_JB_IMPL_OK};
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
/* JB_GET actions (used only for the frames log) */
|
2009-05-21 21:13:09 +00:00
|
|
|
static const char * const jb_get_actions[] = {"Delivered", "Dropped", "Interpolated", "No"};
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
/*! \brief Macros for the frame log files */
|
|
|
|
#define jb_framelog(...) do { \
|
|
|
|
if (jb->logfile) { \
|
|
|
|
fprintf(jb->logfile, __VA_ARGS__); \
|
|
|
|
fflush(jb->logfile); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
/* Internal utility functions */
|
|
|
|
static void jb_choose_impl(struct ast_channel *chan);
|
|
|
|
static void jb_get_and_deliver(struct ast_channel *chan);
|
|
|
|
static int create_jb(struct ast_channel *chan, struct ast_frame *first_frame);
|
|
|
|
static long get_now(struct ast_jb *jb, struct timeval *tv);
|
|
|
|
|
|
|
|
|
|
|
|
/* Interface ast jb functions impl */
|
|
|
|
|
|
|
|
|
|
|
|
static void jb_choose_impl(struct ast_channel *chan)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb = ast_channel_jb(chan);
|
2006-05-31 18:09:52 +00:00
|
|
|
struct ast_jb_conf *jbconf = &jb->conf;
|
2009-05-21 21:13:09 +00:00
|
|
|
const struct ast_jb_impl *test_impl;
|
2008-07-11 18:09:35 +00:00
|
|
|
int i, avail_impl_count = ARRAY_LEN(avail_impl);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
jb->impl = &avail_impl[default_impl];
|
2009-03-04 20:48:42 +00:00
|
|
|
|
|
|
|
if (ast_strlen_zero(jbconf->impl)) {
|
2006-05-31 18:09:52 +00:00
|
|
|
return;
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
for (i = 0; i < avail_impl_count; i++) {
|
|
|
|
test_impl = &avail_impl[i];
|
|
|
|
if (!strcasecmp(jbconf->impl, test_impl->name)) {
|
|
|
|
jb->impl = test_impl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb0 = ast_channel_jb(c0);
|
|
|
|
struct ast_jb *jb1 = ast_channel_jb(c1);
|
2006-05-31 18:09:52 +00:00
|
|
|
struct ast_jb_conf *conf0 = &jb0->conf;
|
|
|
|
struct ast_jb_conf *conf1 = &jb1->conf;
|
2012-02-20 23:43:27 +00:00
|
|
|
int c0_wants_jitter = ast_channel_tech(c0)->properties & AST_CHAN_TP_WANTSJITTER;
|
|
|
|
int c0_creates_jitter = ast_channel_tech(c0)->properties & AST_CHAN_TP_CREATESJITTER;
|
2006-05-31 18:09:52 +00:00
|
|
|
int c0_jb_enabled = ast_test_flag(conf0, AST_JB_ENABLED);
|
|
|
|
int c0_force_jb = ast_test_flag(conf0, AST_JB_FORCED);
|
|
|
|
int c0_jb_timebase_initialized = ast_test_flag(jb0, JB_TIMEBASE_INITIALIZED);
|
|
|
|
int c0_jb_created = ast_test_flag(jb0, JB_CREATED);
|
2012-02-20 23:43:27 +00:00
|
|
|
int c1_wants_jitter = ast_channel_tech(c1)->properties & AST_CHAN_TP_WANTSJITTER;
|
|
|
|
int c1_creates_jitter = ast_channel_tech(c1)->properties & AST_CHAN_TP_CREATESJITTER;
|
2006-05-31 18:09:52 +00:00
|
|
|
int c1_jb_enabled = ast_test_flag(conf1, AST_JB_ENABLED);
|
|
|
|
int c1_force_jb = ast_test_flag(conf1, AST_JB_FORCED);
|
|
|
|
int c1_jb_timebase_initialized = ast_test_flag(jb1, JB_TIMEBASE_INITIALIZED);
|
|
|
|
int c1_jb_created = ast_test_flag(jb1, JB_CREATED);
|
|
|
|
int inuse = 0;
|
|
|
|
|
|
|
|
/* Determine whether audio going to c0 needs a jitter buffer */
|
|
|
|
if (((!c0_wants_jitter && c1_creates_jitter) || (c0_force_jb && c1_creates_jitter)) && c0_jb_enabled) {
|
|
|
|
ast_set_flag(jb0, JB_USE);
|
|
|
|
if (!c0_jb_timebase_initialized) {
|
|
|
|
if (c1_jb_timebase_initialized) {
|
|
|
|
memcpy(&jb0->timebase, &jb1->timebase, sizeof(struct timeval));
|
|
|
|
} else {
|
|
|
|
gettimeofday(&jb0->timebase, NULL);
|
|
|
|
}
|
|
|
|
ast_set_flag(jb0, JB_TIMEBASE_INITIALIZED);
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (!c0_jb_created) {
|
|
|
|
jb_choose_impl(c0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inuse = 1;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* Determine whether audio going to c1 needs a jitter buffer */
|
|
|
|
if (((!c1_wants_jitter && c0_creates_jitter) || (c1_force_jb && c0_creates_jitter)) && c1_jb_enabled) {
|
|
|
|
ast_set_flag(jb1, JB_USE);
|
|
|
|
if (!c1_jb_timebase_initialized) {
|
|
|
|
if (c0_jb_timebase_initialized) {
|
|
|
|
memcpy(&jb1->timebase, &jb0->timebase, sizeof(struct timeval));
|
|
|
|
} else {
|
|
|
|
gettimeofday(&jb1->timebase, NULL);
|
|
|
|
}
|
|
|
|
ast_set_flag(jb1, JB_TIMEBASE_INITIALIZED);
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (!c1_jb_created) {
|
|
|
|
jb_choose_impl(c1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inuse = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb0 = ast_channel_jb(c0);
|
|
|
|
struct ast_jb *jb1 = ast_channel_jb(c1);
|
2006-05-31 18:09:52 +00:00
|
|
|
int c0_use_jb = ast_test_flag(jb0, JB_USE);
|
|
|
|
int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
|
|
|
|
int c1_use_jb = ast_test_flag(jb1, JB_USE);
|
|
|
|
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
|
|
|
|
int wait, wait0, wait1;
|
|
|
|
struct timeval tv_now;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (time_left == 0) {
|
|
|
|
/* No time left - the bridge will be retried */
|
|
|
|
/* TODO: Test disable this */
|
|
|
|
/*return 0;*/
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (time_left < 0) {
|
|
|
|
time_left = INT_MAX;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
gettimeofday(&tv_now, NULL);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
wait0 = (c0_use_jb && c0_jb_is_created) ? jb0->next - get_now(jb0, &tv_now) : time_left;
|
|
|
|
wait1 = (c1_use_jb && c1_jb_is_created) ? jb1->next - get_now(jb1, &tv_now) : time_left;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
wait = wait0 < wait1 ? wait0 : wait1;
|
|
|
|
wait = wait < time_left ? wait : time_left;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (wait == INT_MAX) {
|
|
|
|
wait = -1;
|
|
|
|
} else if (wait < 1) {
|
|
|
|
/* don't let wait=0, because this can cause the pbx thread to loop without any sleeping at all */
|
|
|
|
wait = 1;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
return wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ast_jb_put(struct ast_channel *chan, struct ast_frame *f)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb = ast_channel_jb(chan);
|
2009-05-21 21:13:09 +00:00
|
|
|
const struct ast_jb_impl *jbimpl = jb->impl;
|
2006-05-31 18:09:52 +00:00
|
|
|
void *jbobj = jb->jbobj;
|
|
|
|
struct ast_frame *frr;
|
|
|
|
long now = 0;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (!ast_test_flag(jb, JB_USE))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (f->frametype != AST_FRAME_VOICE) {
|
|
|
|
if (f->frametype == AST_FRAME_DTMF && ast_test_flag(jb, JB_CREATED)) {
|
|
|
|
jb_framelog("JB_PUT {now=%ld}: Received DTMF frame. Force resynching jb...\n", now);
|
|
|
|
jbimpl->force_resync(jbobj);
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We consider an enabled jitterbuffer should receive frames with valid timing info. */
|
Merged revisions 98943 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed. Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code. The reason this
happens is that the channel might get masqueraded during this time. During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way. (This one is
for you, paravoid!)
It changes an int in ast_frame to be used as flag bits. The 1 bit is still used
to indicate that the frame contains timing information. Also, a second flag has
been added to indicate that the frame came from a translator. When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed. At this point, the flag gets
cleared. Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack. But, it does fix the issue, and I was not able
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-01-15 23:31:53 +00:00
|
|
|
if (!ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO) || f->len < 2 || f->ts < 0) {
|
2007-11-28 15:38:03 +00:00
|
|
|
ast_log(LOG_WARNING, "%s received frame with invalid timing info: "
|
2014-05-09 22:49:26 +00:00
|
|
|
"has_timing_info=%u, len=%ld, ts=%ld, src=%s\n",
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_channel_name(chan), ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO), f->len, f->ts, f->src);
|
2006-05-31 18:09:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-08-29 20:50:36 +00:00
|
|
|
frr = ast_frdup(f);
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
if (!frr) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_ERROR, "Failed to isolate frame for the jitterbuffer on channel '%s'\n", ast_channel_name(chan));
|
2006-05-31 18:09:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ast_test_flag(jb, JB_CREATED)) {
|
|
|
|
if (create_jb(chan, frr)) {
|
|
|
|
ast_frfree(frr);
|
|
|
|
/* Disable the jitterbuffer */
|
|
|
|
ast_clear_flag(jb, JB_USE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_set_flag(jb, JB_CREATED);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
now = get_now(jb, NULL);
|
2011-04-20 20:52:15 +00:00
|
|
|
if (jbimpl->put(jbobj, frr, now) != AST_JB_IMPL_OK) {
|
2006-05-31 18:09:52 +00:00
|
|
|
jb_framelog("JB_PUT {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len);
|
|
|
|
ast_frfree(frr);
|
|
|
|
/*return -1;*/
|
2009-03-04 20:48:42 +00:00
|
|
|
/* TODO: Check this fix - should return 0 here, because the dropped frame shouldn't
|
2006-05-31 18:09:52 +00:00
|
|
|
be delivered at all */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
jb->next = jbimpl->next(jbobj);
|
|
|
|
|
|
|
|
jb_framelog("JB_PUT {now=%ld}: Queued frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb0 = ast_channel_jb(c0);
|
|
|
|
struct ast_jb *jb1 = ast_channel_jb(c1);
|
2006-05-31 18:09:52 +00:00
|
|
|
int c0_use_jb = ast_test_flag(jb0, JB_USE);
|
|
|
|
int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
|
|
|
|
int c1_use_jb = ast_test_flag(jb1, JB_USE);
|
|
|
|
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (c0_use_jb && c0_jb_is_created)
|
|
|
|
jb_get_and_deliver(c0);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (c1_use_jb && c1_jb_is_created)
|
|
|
|
jb_get_and_deliver(c1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void jb_get_and_deliver(struct ast_channel *chan)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb = ast_channel_jb(chan);
|
2009-05-21 21:13:09 +00:00
|
|
|
const struct ast_jb_impl *jbimpl = jb->impl;
|
2006-05-31 18:09:52 +00:00
|
|
|
void *jbobj = jb->jbobj;
|
2009-11-06 16:42:23 +00:00
|
|
|
struct ast_frame *f, finterp = { .frametype = AST_FRAME_VOICE, };
|
2006-05-31 18:09:52 +00:00
|
|
|
long now;
|
|
|
|
int interpolation_len, res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
now = get_now(jb, NULL);
|
|
|
|
jb->next = jbimpl->next(jbobj);
|
|
|
|
if (now < jb->next) {
|
|
|
|
jb_framelog("\tJB_GET {now=%ld}: now < next=%ld\n", now, jb->next);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
while (now >= jb->next) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
interpolation_len = ast_format_get_default_ms(jb->last_format);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
res = jbimpl->get(jbobj, &f, now, interpolation_len);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2007-01-23 00:11:32 +00:00
|
|
|
switch (res) {
|
2011-04-20 20:52:15 +00:00
|
|
|
case AST_JB_IMPL_OK:
|
2006-05-31 18:09:52 +00:00
|
|
|
/* deliver the frame */
|
|
|
|
ast_write(chan, f);
|
2011-04-20 20:52:15 +00:00
|
|
|
case AST_JB_IMPL_DROP:
|
2006-05-31 18:09:52 +00:00
|
|
|
jb_framelog("\tJB_GET {now=%ld}: %s frame with ts=%ld and len=%ld\n",
|
|
|
|
now, jb_get_actions[res], f->ts, f->len);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_replace(jb->last_format, f->subclass.format);
|
2006-05-31 18:09:52 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
2011-04-20 20:52:15 +00:00
|
|
|
case AST_JB_IMPL_INTERP:
|
2006-05-31 18:09:52 +00:00
|
|
|
/* interpolate a frame */
|
|
|
|
f = &finterp;
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
f->subclass.format = jb->last_format;
|
2006-05-31 18:09:52 +00:00
|
|
|
f->samples = interpolation_len * 8;
|
|
|
|
f->src = "JB interpolation";
|
|
|
|
f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000));
|
|
|
|
f->offset = AST_FRIENDLY_OFFSET;
|
|
|
|
/* deliver the interpolated frame */
|
|
|
|
ast_write(chan, f);
|
|
|
|
jb_framelog("\tJB_GET {now=%ld}: Interpolated frame with len=%d\n", now, interpolation_len);
|
|
|
|
break;
|
2011-04-20 20:52:15 +00:00
|
|
|
case AST_JB_IMPL_NOFRAME:
|
2006-05-31 18:09:52 +00:00
|
|
|
ast_log(LOG_WARNING,
|
2011-04-20 20:52:15 +00:00
|
|
|
"AST_JB_IMPL_NOFRAME is returned from the %s jb when now=%ld >= next=%ld, jbnext=%ld!\n",
|
2006-05-31 18:09:52 +00:00
|
|
|
jbimpl->name, now, jb->next, jbimpl->next(jbobj));
|
|
|
|
jb_framelog("\tJB_GET {now=%ld}: No frame for now!?\n", now);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
ast_log(LOG_ERROR, "This should never happen!\n");
|
2008-06-11 18:19:24 +00:00
|
|
|
ast_assert("JB type unknown" == NULL);
|
2006-05-31 18:09:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
jb->next = jbimpl->next(jbobj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb = ast_channel_jb(chan);
|
2006-05-31 18:09:52 +00:00
|
|
|
struct ast_jb_conf *jbconf = &jb->conf;
|
2009-05-21 21:13:09 +00:00
|
|
|
const struct ast_jb_impl *jbimpl = jb->impl;
|
2006-05-31 18:09:52 +00:00
|
|
|
void *jbobj;
|
|
|
|
long now;
|
|
|
|
char logfile_pathname[20 + AST_JB_IMPL_NAME_SIZE + 2*AST_CHANNEL_NAME + 1];
|
|
|
|
char name1[AST_CHANNEL_NAME], name2[AST_CHANNEL_NAME], *tmp;
|
|
|
|
int res;
|
|
|
|
|
2012-07-23 21:15:26 +00:00
|
|
|
jbobj = jb->jbobj = jbimpl->create(jbconf);
|
2006-05-31 18:09:52 +00:00
|
|
|
if (!jbobj) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to create jitterbuffer on channel '%s'\n", ast_channel_name(chan));
|
2006-05-31 18:09:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
now = get_now(jb, NULL);
|
|
|
|
res = jbimpl->put_first(jbobj, frr, now);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* The result of putting the first frame should not differ from OK. However, its possible
|
2006-06-01 14:07:03 +00:00
|
|
|
some implementations (i.e. adaptive's when resynch_threshold is specified) to drop it. */
|
2011-04-20 20:52:15 +00:00
|
|
|
if (res != AST_JB_IMPL_OK) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to put first frame in the jitterbuffer on channel '%s'\n", ast_channel_name(chan));
|
2006-05-31 18:09:52 +00:00
|
|
|
/*
|
|
|
|
jbimpl->destroy(jbobj);
|
|
|
|
return -1;
|
|
|
|
*/
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* Init next */
|
|
|
|
jb->next = jbimpl->next(jbobj);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* Init last format for a first time. */
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
jb->last_format = ao2_bump(frr->subclass.format);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* Create a frame log file */
|
|
|
|
if (ast_test_flag(jbconf, AST_JB_LOG)) {
|
2013-07-30 21:43:29 +00:00
|
|
|
RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(chan), ast_channel_cleanup);
|
2009-01-22 21:25:46 +00:00
|
|
|
char safe_logfile[30] = "/tmp/logfile-XXXXXX";
|
|
|
|
int safe_fd;
|
2013-07-30 21:43:29 +00:00
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
snprintf(name2, sizeof(name2), "%s", ast_channel_name(chan));
|
2013-09-18 20:04:14 +00:00
|
|
|
while ((tmp = strchr(name2, '/'))) {
|
2006-05-31 18:09:52 +00:00
|
|
|
*tmp = '#';
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
|
|
|
|
2008-06-11 18:19:24 +00:00
|
|
|
/* We should always have bridged chan if a jitterbuffer is in use */
|
|
|
|
ast_assert(bridged != NULL);
|
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
snprintf(name1, sizeof(name1), "%s", ast_channel_name(bridged));
|
2013-09-18 20:04:14 +00:00
|
|
|
while ((tmp = strchr(name1, '/'))) {
|
2006-05-31 18:09:52 +00:00
|
|
|
*tmp = '#';
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
2009-01-22 21:25:46 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
snprintf(logfile_pathname, sizeof(logfile_pathname),
|
|
|
|
"/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
|
2010-03-10 18:25:18 +00:00
|
|
|
unlink(logfile_pathname);
|
|
|
|
safe_fd = mkstemp(safe_logfile);
|
|
|
|
if (safe_fd < 0 || link(safe_logfile, logfile_pathname) || unlink(safe_logfile) || !(jb->logfile = fdopen(safe_fd, "w+b"))) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s': %s\n", logfile_pathname, strerror(errno));
|
2009-01-22 21:25:46 +00:00
|
|
|
jb->logfile = NULL;
|
|
|
|
if (safe_fd > -1) {
|
|
|
|
close(safe_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 20:52:15 +00:00
|
|
|
if (res == AST_JB_IMPL_OK) {
|
2006-05-31 18:09:52 +00:00
|
|
|
jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
|
|
|
|
now, frr->ts, frr->len);
|
2009-03-04 20:48:42 +00:00
|
|
|
} else {
|
2006-05-31 18:09:52 +00:00
|
|
|
jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n",
|
|
|
|
now, frr->ts, frr->len);
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s jitterbuffer created on channel %s\n", jbimpl->name, ast_channel_name(chan));
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* Free the frame if it has not been queued in the jb */
|
2011-04-20 20:52:15 +00:00
|
|
|
if (res != AST_JB_IMPL_OK) {
|
2006-05-31 18:09:52 +00:00
|
|
|
ast_frfree(frr);
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ast_jb_destroy(struct ast_channel *chan)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb = ast_channel_jb(chan);
|
2009-05-21 21:13:09 +00:00
|
|
|
const struct ast_jb_impl *jbimpl = jb->impl;
|
2006-05-31 18:09:52 +00:00
|
|
|
void *jbobj = jb->jbobj;
|
|
|
|
struct ast_frame *f;
|
|
|
|
|
|
|
|
if (jb->logfile) {
|
|
|
|
fclose(jb->logfile);
|
|
|
|
jb->logfile = NULL;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_cleanup(jb->last_format);
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (ast_test_flag(jb, JB_CREATED)) {
|
|
|
|
/* Remove and free all frames still queued in jb */
|
2011-04-20 20:52:15 +00:00
|
|
|
while (jbimpl->remove(jbobj, &f) == AST_JB_IMPL_OK) {
|
2006-05-31 18:09:52 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
jbimpl->destroy(jbobj);
|
|
|
|
jb->jbobj = NULL;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
ast_clear_flag(jb, JB_CREATED);
|
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, ast_channel_name(chan));
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-10 19:35:50 +00:00
|
|
|
static long get_now(struct ast_jb *jb, struct timeval *when)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
|
2008-08-10 19:35:50 +00:00
|
|
|
if (!when) {
|
|
|
|
when = &now;
|
|
|
|
gettimeofday(when, NULL);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 19:35:50 +00:00
|
|
|
return ast_tvdiff_ms(*when, jb->timebase);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-14 13:18:40 +00:00
|
|
|
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
|
|
|
int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1;
|
2007-11-14 13:18:40 +00:00
|
|
|
const char *name;
|
2006-05-31 18:09:52 +00:00
|
|
|
int tmp;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
|
|
|
if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen)) {
|
2006-05-31 18:09:52 +00:00
|
|
|
return -1;
|
2009-03-04 20:48:42 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
name = varname + prefixlen;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
if (!strcasecmp(name, AST_JB_CONF_ENABLE)) {
|
|
|
|
ast_set2_flag(conf, ast_true(value), AST_JB_ENABLED);
|
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_FORCE)) {
|
|
|
|
ast_set2_flag(conf, ast_true(value), AST_JB_FORCED);
|
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_MAX_SIZE)) {
|
|
|
|
if ((tmp = atoi(value)) > 0)
|
|
|
|
conf->max_size = tmp;
|
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_RESYNCH_THRESHOLD)) {
|
|
|
|
if ((tmp = atoi(value)) > 0)
|
|
|
|
conf->resync_threshold = tmp;
|
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_IMPL)) {
|
|
|
|
if (!ast_strlen_zero(value))
|
|
|
|
snprintf(conf->impl, sizeof(conf->impl), "%s", value);
|
2010-03-02 19:08:38 +00:00
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_TARGET_EXTRA)) {
|
|
|
|
if (sscanf(value, "%30d", &tmp) == 1) {
|
|
|
|
conf->target_extra = tmp;
|
|
|
|
}
|
2006-05-31 18:09:52 +00:00
|
|
|
} else if (!strcasecmp(name, AST_JB_CONF_LOG)) {
|
|
|
|
ast_set2_flag(conf, ast_true(value), AST_JB_LOG);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-21 18:00:22 +00:00
|
|
|
void ast_jb_enable_for_channel(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_jb_conf conf = ast_channel_jb(chan)->conf;
|
|
|
|
if (ast_test_flag(&conf, AST_JB_ENABLED)) {
|
|
|
|
ast_jb_create_framehook(chan, &conf, 1);
|
|
|
|
}
|
|
|
|
}
|
2006-05-31 18:09:52 +00:00
|
|
|
|
2006-06-23 16:49:12 +00:00
|
|
|
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
memcpy(&ast_channel_jb(chan)->conf, conf, sizeof(*conf));
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-23 16:49:12 +00:00
|
|
|
void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
memcpy(conf, &ast_channel_jb((struct ast_channel *) chan)->conf, sizeof(*conf));
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 00:30:53 +00:00
|
|
|
void ast_jb_empty_and_reset(struct ast_channel *c0, struct ast_channel *c1)
|
|
|
|
{
|
2012-02-29 16:52:47 +00:00
|
|
|
struct ast_jb *jb0 = ast_channel_jb(c0);
|
|
|
|
struct ast_jb *jb1 = ast_channel_jb(c1);
|
2008-08-06 00:30:53 +00:00
|
|
|
int c0_use_jb = ast_test_flag(jb0, JB_USE);
|
|
|
|
int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
|
|
|
|
int c1_use_jb = ast_test_flag(jb1, JB_USE);
|
|
|
|
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
|
|
|
|
|
|
|
|
if (c0_use_jb && c0_jb_is_created && jb0->impl->empty_and_reset) {
|
|
|
|
jb0->impl->empty_and_reset(jb0->jbobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c1_use_jb && c1_jb_is_created && jb1->impl->empty_and_reset) {
|
|
|
|
jb1->impl->empty_and_reset(jb1->jbobj);
|
|
|
|
}
|
|
|
|
}
|
2006-05-31 18:09:52 +00:00
|
|
|
|
|
|
|
/* Implementation functions */
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
/* fixed */
|
2012-07-23 21:15:26 +00:00
|
|
|
static void * jb_create_fixed(struct ast_jb_conf *general_config)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb_conf conf;
|
2008-08-06 00:30:53 +00:00
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
conf.jbsize = general_config->max_size;
|
2012-07-23 21:15:26 +00:00
|
|
|
conf.resync_threshold = general_config->resync_threshold;
|
2008-08-06 00:30:53 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_jb_new(&conf);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_destroy_fixed(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2012-07-23 21:15:26 +00:00
|
|
|
/* Ensure the fixed jb is empty - otherwise it will raise an ASSERT */
|
|
|
|
jb_empty_and_reset_fixed(jb);
|
|
|
|
|
2006-05-31 18:09:52 +00:00
|
|
|
/* destroy the jb */
|
2006-06-01 14:07:03 +00:00
|
|
|
fixed_jb_destroy(fixedjb);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_put_first_fixed(void *jb, struct ast_frame *fin, long now)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = fixed_jb_put_first(fixedjb, fin, fin->len, fin->ts, now);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_put_fixed(void *jb, struct ast_frame *fin, long now)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = fixed_jb_put(fixedjb, fin, fin->len, fin->ts, now);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_get_fixed(void *jb, struct ast_frame **fout, long now, long interpl)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2014-11-02 07:40:57 +00:00
|
|
|
struct fixed_jb_frame frame = { .data = &ast_null_frame };
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = fixed_jb_get(fixedjb, &frame, now, interpl);
|
2006-05-31 18:09:52 +00:00
|
|
|
*fout = frame.data;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static long jb_next_fixed(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_jb_next(fixedjb);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_remove_fixed(void *jb, struct ast_frame **fout)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
|
|
|
struct fixed_jb_frame frame;
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = fixed_jb_remove(fixedjb, &frame);
|
2006-05-31 18:09:52 +00:00
|
|
|
*fout = frame.data;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return fixed_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_force_resynch_fixed(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
fixed_jb_set_force_resynch(fixedjb);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 00:30:53 +00:00
|
|
|
static void jb_empty_and_reset_fixed(void *jb)
|
|
|
|
{
|
|
|
|
struct fixed_jb *fixedjb = jb;
|
|
|
|
struct fixed_jb_frame f;
|
|
|
|
|
|
|
|
while (fixed_jb_remove(fixedjb, &f) == FIXED_JB_OK) {
|
|
|
|
ast_frfree(f.data);
|
|
|
|
}
|
|
|
|
}
|
2006-05-31 18:09:52 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
/* adaptive */
|
2006-05-31 18:09:52 +00:00
|
|
|
|
2012-07-23 21:15:26 +00:00
|
|
|
static void *jb_create_adaptive(struct ast_jb_conf *general_config)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
|
|
|
jb_conf jbconf;
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb;
|
2006-05-31 18:09:52 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
adaptivejb = jb_new();
|
|
|
|
if (adaptivejb) {
|
2006-05-31 18:09:52 +00:00
|
|
|
jbconf.max_jitterbuf = general_config->max_size;
|
|
|
|
jbconf.resync_threshold = general_config->resync_threshold;
|
|
|
|
jbconf.max_contig_interp = 10;
|
2010-03-02 19:08:38 +00:00
|
|
|
jbconf.target_extra = general_config->target_extra;
|
2006-06-01 14:07:03 +00:00
|
|
|
jb_setconf(adaptivejb, &jbconf);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return adaptivejb;
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_destroy_adaptive(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb = (jitterbuf *) jb;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
jb_destroy(adaptivejb);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_put_first_adaptive(void *jb, struct ast_frame *fin, long now)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
return jb_put_adaptive(jb, fin, now);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_put_adaptive(void *jb, struct ast_frame *fin, long now)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb = (jitterbuf *) jb;
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = jb_put(adaptivejb, fin, JB_TYPE_VOICE, fin->len, fin->ts, now);
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return adaptive_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_get_adaptive(void *jb, struct ast_frame **fout, long now, long interpl)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb = (jitterbuf *) jb;
|
2014-11-02 07:40:57 +00:00
|
|
|
jb_frame frame = { .data = &ast_null_frame };
|
2006-05-31 18:09:52 +00:00
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = jb_get(adaptivejb, &frame, now, interpl);
|
2006-05-31 18:09:52 +00:00
|
|
|
*fout = frame.data;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return adaptive_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static long jb_next_adaptive(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb = (jitterbuf *) jb;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return jb_next(adaptivejb);
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static int jb_remove_adaptive(void *jb, struct ast_frame **fout)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
2006-06-01 14:07:03 +00:00
|
|
|
jitterbuf *adaptivejb = (jitterbuf *) jb;
|
2006-05-31 18:09:52 +00:00
|
|
|
jb_frame frame;
|
|
|
|
int res;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
res = jb_getall(adaptivejb, &frame);
|
2006-05-31 18:09:52 +00:00
|
|
|
*fout = frame.data;
|
2009-03-04 20:48:42 +00:00
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
return adaptive_to_abstract_code[res];
|
2006-05-31 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 14:07:03 +00:00
|
|
|
static void jb_force_resynch_adaptive(void *jb)
|
2006-05-31 18:09:52 +00:00
|
|
|
{
|
|
|
|
}
|
2008-08-06 00:30:53 +00:00
|
|
|
|
|
|
|
static void jb_empty_and_reset_adaptive(void *jb)
|
|
|
|
{
|
|
|
|
jitterbuf *adaptivejb = jb;
|
|
|
|
jb_frame f;
|
|
|
|
|
|
|
|
while (jb_getall(adaptivejb, &f) == JB_OK) {
|
|
|
|
ast_frfree(f.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
jb_reset(adaptivejb);
|
|
|
|
}
|
2011-04-20 20:52:15 +00:00
|
|
|
|
|
|
|
const struct ast_jb_impl *ast_jb_get_impl(enum ast_jb_type type)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_LEN(avail_impl); i++) {
|
|
|
|
if (avail_impl[i].type == type) {
|
|
|
|
return &avail_impl[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-05-21 18:00:22 +00:00
|
|
|
|
|
|
|
#define DEFAULT_TIMER_INTERVAL 20
|
|
|
|
#define DEFAULT_SIZE 200
|
|
|
|
#define DEFAULT_TARGET_EXTRA 40
|
|
|
|
#define DEFAULT_RESYNC 1000
|
|
|
|
#define DEFAULT_TYPE AST_JB_FIXED
|
|
|
|
|
|
|
|
struct jb_framedata {
|
|
|
|
const struct ast_jb_impl *jb_impl;
|
|
|
|
struct ast_jb_conf jb_conf;
|
|
|
|
struct timeval start_tv;
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
struct ast_format *last_format;
|
2013-05-21 18:00:22 +00:00
|
|
|
struct ast_timer *timer;
|
|
|
|
int timer_interval; /* ms between deliveries */
|
|
|
|
int timer_fd;
|
|
|
|
int first;
|
|
|
|
void *jb_obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void jb_framedata_destroy(struct jb_framedata *framedata)
|
|
|
|
{
|
|
|
|
if (framedata->timer) {
|
|
|
|
ast_timer_close(framedata->timer);
|
|
|
|
framedata->timer = NULL;
|
|
|
|
}
|
|
|
|
if (framedata->jb_impl && framedata->jb_obj) {
|
|
|
|
struct ast_frame *f;
|
|
|
|
while (framedata->jb_impl->remove(framedata->jb_obj, &f) == AST_JB_IMPL_OK) {
|
|
|
|
ast_frfree(f);
|
|
|
|
}
|
|
|
|
framedata->jb_impl->destroy(framedata->jb_obj);
|
|
|
|
framedata->jb_obj = NULL;
|
|
|
|
}
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_cleanup(framedata->last_format);
|
2013-05-21 18:00:22 +00:00
|
|
|
ast_free(framedata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_jb_conf_default(struct ast_jb_conf *conf)
|
|
|
|
{
|
|
|
|
conf->max_size = DEFAULT_SIZE;
|
|
|
|
conf->resync_threshold = DEFAULT_RESYNC;
|
|
|
|
ast_copy_string(conf->impl, "fixed", sizeof(conf->impl));
|
|
|
|
conf->target_extra = DEFAULT_TARGET_EXTRA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void datastore_destroy_cb(void *data) {
|
2014-09-26 15:43:04 +00:00
|
|
|
ast_free(data);
|
2013-05-21 18:00:22 +00:00
|
|
|
ast_debug(1, "JITTERBUFFER datastore destroyed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ast_datastore_info jb_datastore = {
|
|
|
|
.type = "jitterbuffer",
|
|
|
|
.destroy = datastore_destroy_cb
|
|
|
|
};
|
|
|
|
|
|
|
|
static void hook_destroy_cb(void *framedata)
|
|
|
|
{
|
|
|
|
ast_debug(1, "JITTERBUFFER hook destroyed\n");
|
|
|
|
jb_framedata_destroy((struct jb_framedata *) framedata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
|
|
|
|
{
|
|
|
|
struct jb_framedata *framedata = data;
|
|
|
|
struct timeval now_tv;
|
|
|
|
unsigned long now;
|
|
|
|
int putframe = 0; /* signifies if audio frame was placed into the buffer or not */
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case AST_FRAMEHOOK_EVENT_READ:
|
|
|
|
break;
|
|
|
|
case AST_FRAMEHOOK_EVENT_ATTACHED:
|
|
|
|
case AST_FRAMEHOOK_EVENT_DETACHED:
|
|
|
|
case AST_FRAMEHOOK_EVENT_WRITE:
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_channel_fdno(chan) == AST_JITTERBUFFER_FD && framedata->timer) {
|
|
|
|
if (ast_timer_ack(framedata->timer, 1) < 0) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to acknowledge timer in jitter buffer\n");
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame) {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
now_tv = ast_tvnow();
|
|
|
|
now = ast_tvdiff_ms(now_tv, framedata->start_tv);
|
|
|
|
|
|
|
|
if (frame->frametype == AST_FRAME_VOICE) {
|
|
|
|
int res;
|
|
|
|
struct ast_frame *jbframe;
|
|
|
|
|
|
|
|
if (!ast_test_flag(frame, AST_FRFLAG_HAS_TIMING_INFO) || frame->len < 2 || frame->ts < 0) {
|
|
|
|
/* only frames with timing info can enter the jitterbuffer */
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
jbframe = ast_frisolate(frame);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_replace(framedata->last_format, frame->subclass.format);
|
2013-05-21 18:00:22 +00:00
|
|
|
|
|
|
|
if (frame->len && (frame->len != framedata->timer_interval)) {
|
|
|
|
framedata->timer_interval = frame->len;
|
|
|
|
ast_timer_set_rate(framedata->timer, 1000 / framedata->timer_interval);
|
|
|
|
}
|
|
|
|
if (!framedata->first) {
|
|
|
|
framedata->first = 1;
|
|
|
|
res = framedata->jb_impl->put_first(framedata->jb_obj, jbframe, now);
|
|
|
|
} else {
|
|
|
|
res = framedata->jb_impl->put(framedata->jb_obj, jbframe, now);
|
|
|
|
}
|
2014-11-02 07:40:57 +00:00
|
|
|
|
2013-05-21 18:00:22 +00:00
|
|
|
if (res == AST_JB_IMPL_OK) {
|
2014-11-02 07:40:57 +00:00
|
|
|
if (jbframe != frame) {
|
|
|
|
ast_frfree(frame);
|
|
|
|
}
|
2013-05-21 18:00:22 +00:00
|
|
|
frame = &ast_null_frame;
|
2014-11-02 07:40:57 +00:00
|
|
|
} else if (jbframe != frame) {
|
|
|
|
ast_frfree(jbframe);
|
2013-05-21 18:00:22 +00:00
|
|
|
}
|
|
|
|
putframe = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->frametype == AST_FRAME_NULL) {
|
|
|
|
int res;
|
|
|
|
long next = framedata->jb_impl->next(framedata->jb_obj);
|
|
|
|
|
|
|
|
/* If now is earlier than the next expected output frame
|
|
|
|
* from the jitterbuffer we may choose to pass on retrieving
|
|
|
|
* a frame during this read iteration. The only exception
|
|
|
|
* to this rule is when an audio frame is placed into the buffer
|
|
|
|
* and the time for the next frame to come out of the buffer is
|
|
|
|
* at least within the timer_interval of the next output frame. By
|
|
|
|
* doing this we are able to feed off the timing of the input frames
|
|
|
|
* and only rely on our jitterbuffer timer when frames are dropped.
|
|
|
|
* During testing, this hybrid form of timing gave more reliable results. */
|
|
|
|
if (now < next) {
|
|
|
|
long int diff = next - now;
|
|
|
|
if (!putframe) {
|
|
|
|
return frame;
|
|
|
|
} else if (diff >= framedata->timer_interval) {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-02 07:40:57 +00:00
|
|
|
ast_frfree(frame);
|
|
|
|
frame = &ast_null_frame;
|
2013-05-21 18:00:22 +00:00
|
|
|
res = framedata->jb_impl->get(framedata->jb_obj, &frame, now, framedata->timer_interval);
|
|
|
|
switch (res) {
|
|
|
|
case AST_JB_IMPL_OK:
|
|
|
|
/* got it, and pass it through */
|
|
|
|
break;
|
|
|
|
case AST_JB_IMPL_DROP:
|
|
|
|
ast_frfree(frame);
|
|
|
|
frame = &ast_null_frame;
|
|
|
|
break;
|
|
|
|
case AST_JB_IMPL_INTERP:
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (framedata->last_format) {
|
2013-05-21 18:00:22 +00:00
|
|
|
struct ast_frame tmp = { 0, };
|
2014-11-02 07:40:57 +00:00
|
|
|
|
2013-05-21 18:00:22 +00:00
|
|
|
tmp.frametype = AST_FRAME_VOICE;
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
tmp.subclass.format = framedata->last_format;
|
2013-05-21 18:00:22 +00:00
|
|
|
/* example: 8000hz / (1000 / 20ms) = 160 samples */
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
tmp.samples = ast_format_get_sample_rate(framedata->last_format) / (1000 / framedata->timer_interval);
|
2013-05-21 18:00:22 +00:00
|
|
|
tmp.delivery = ast_tvadd(framedata->start_tv, ast_samp2tv(next, 1000));
|
|
|
|
tmp.offset = AST_FRIENDLY_OFFSET;
|
|
|
|
tmp.src = "func_jitterbuffer interpolation";
|
2014-11-02 07:40:57 +00:00
|
|
|
ast_frfree(frame);
|
2013-05-21 18:00:22 +00:00
|
|
|
frame = ast_frdup(&tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else fall through */
|
|
|
|
case AST_JB_IMPL_NOFRAME:
|
2014-11-02 07:40:57 +00:00
|
|
|
ast_frfree(frame);
|
2013-05-21 18:00:22 +00:00
|
|
|
frame = &ast_null_frame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->frametype == AST_FRAME_CONTROL) {
|
|
|
|
switch(frame->subclass.integer) {
|
2013-08-22 17:34:46 +00:00
|
|
|
case AST_CONTROL_HOLD:
|
|
|
|
case AST_CONTROL_UNHOLD:
|
|
|
|
case AST_CONTROL_T38_PARAMETERS:
|
2013-05-21 18:00:22 +00:00
|
|
|
case AST_CONTROL_SRCUPDATE:
|
|
|
|
case AST_CONTROL_SRCCHANGE:
|
|
|
|
framedata->jb_impl->force_resync(framedata->jb_obj);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set defaults */
|
|
|
|
static int jb_framedata_init(struct jb_framedata *framedata, struct ast_jb_conf *jb_conf)
|
|
|
|
{
|
|
|
|
int jb_impl_type = DEFAULT_TYPE;
|
|
|
|
/* Initialize defaults */
|
|
|
|
framedata->timer_fd = -1;
|
|
|
|
memcpy(&framedata->jb_conf, jb_conf, sizeof(*jb_conf));
|
|
|
|
|
|
|
|
/* Figure out implementation type from the configuration implementation string */
|
|
|
|
if (!ast_strlen_zero(jb_conf->impl)) {
|
|
|
|
if (!strcasecmp(jb_conf->impl, "fixed")) {
|
|
|
|
jb_impl_type = AST_JB_FIXED;
|
|
|
|
} else if (!strcasecmp(jb_conf->impl, "adaptive")) {
|
|
|
|
jb_impl_type = AST_JB_ADAPTIVE;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unknown Jitterbuffer type %s. Failed to create jitterbuffer.\n", jb_conf->impl);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(framedata->jb_impl = ast_jb_get_impl(jb_impl_type))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(framedata->timer = ast_timer_open())) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
framedata->timer_fd = ast_timer_fd(framedata->timer);
|
|
|
|
framedata->timer_interval = DEFAULT_TIMER_INTERVAL;
|
|
|
|
ast_timer_set_rate(framedata->timer, 1000 / framedata->timer_interval);
|
|
|
|
framedata->start_tv = ast_tvnow();
|
|
|
|
|
|
|
|
framedata->jb_obj = framedata->jb_impl->create(&framedata->jb_conf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ast_jb_create_framehook(struct ast_channel *chan, struct ast_jb_conf *jb_conf, int prefer_existing)
|
|
|
|
{
|
|
|
|
struct jb_framedata *framedata;
|
|
|
|
struct ast_datastore *datastore = NULL;
|
|
|
|
struct ast_framehook_interface interface = {
|
|
|
|
.version = AST_FRAMEHOOK_INTERFACE_VERSION,
|
|
|
|
.event_cb = hook_event_cb,
|
|
|
|
.destroy_cb = hook_destroy_cb,
|
|
|
|
};
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
/* If disabled, strip any existing jitterbuffer and don't replace it. */
|
|
|
|
if (!strcasecmp(jb_conf->impl, "disabled")) {
|
|
|
|
int *id;
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
if ((datastore = ast_channel_datastore_find(chan, &jb_datastore, NULL))) {
|
|
|
|
id = datastore->data;
|
|
|
|
ast_framehook_detach(chan, *id);
|
|
|
|
ast_channel_datastore_remove(chan, datastore);
|
2014-07-28 18:58:43 +00:00
|
|
|
ast_datastore_free(datastore);
|
2013-05-21 18:00:22 +00:00
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jb_framedata_init(framedata, jb_conf)) {
|
|
|
|
jb_framedata_destroy(framedata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface.data = framedata;
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
i = ast_framehook_attach(chan, &interface);
|
|
|
|
if (i >= 0) {
|
|
|
|
int *id;
|
|
|
|
if ((datastore = ast_channel_datastore_find(chan, &jb_datastore, NULL))) {
|
|
|
|
/* There is already a jitterbuffer on the channel. */
|
|
|
|
if (prefer_existing) {
|
|
|
|
/* We prefer the existing jitterbuffer, so remove the new one and keep the old one. */
|
|
|
|
ast_framehook_detach(chan, i);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* We prefer the new jitterbuffer, so strip the old one. */
|
|
|
|
id = datastore->data;
|
|
|
|
ast_framehook_detach(chan, *id);
|
|
|
|
ast_channel_datastore_remove(chan, datastore);
|
2014-07-28 18:58:43 +00:00
|
|
|
ast_datastore_free(datastore);
|
2013-05-21 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(datastore = ast_datastore_alloc(&jb_datastore, NULL))) {
|
|
|
|
ast_framehook_detach(chan, i);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(id = ast_calloc(1, sizeof(int)))) {
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
ast_framehook_detach(chan, i);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
|
|
|
|
datastore->data = id;
|
|
|
|
ast_channel_datastore_add(chan, datastore);
|
|
|
|
|
|
|
|
ast_channel_set_fd(chan, AST_JITTERBUFFER_FD, framedata->timer_fd);
|
|
|
|
} else {
|
|
|
|
jb_framedata_destroy(framedata);
|
|
|
|
framedata = NULL;
|
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
}
|