aboutsummaryrefslogtreecommitdiffstats
path: root/abstract_jb.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-06-22 17:05:17 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-06-22 17:05:17 +0000
commit75865d5802e68f217cb6d5b27e205948a935883e (patch)
tree09e0da9c9e65e62322d7b473d2f44a59feef1bbb /abstract_jb.c
parentf3f7a9e1aaee38f18bc703bef74d441b3069eb41 (diff)
- dynamically allocate the ast_jb structure that is on the channel structure
so that channels not using a jitterbuffer don't waste as much memory - ensure that the channel drivers that use jitterbuffers can handle a failure from configuring a jitterbuffer on a new channel because of a memory allocation error - On passing through these channel drivers, configure the jitterbuffer before starting the PBX thread instead of afterwards. If the pbx fails to start for whatever reason, this would have caused a crash. - Also on passing, move the increase of the usecount to after all of the possible failure conditions in the function - fix a place where ast_update_use_count() was not called - ensure that the owner channel pointer of the channel pvt strcutures is set to NULL in failure conditions git-svn-id: http://svn.digium.com/svn/asterisk/trunk@35553 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'abstract_jb.c')
-rw-r--r--abstract_jb.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/abstract_jb.c b/abstract_jb.c
index 1525d81b0..e9ab1ad9c 100644
--- a/abstract_jb.c
+++ b/abstract_jb.c
@@ -176,7 +176,7 @@ static long get_now(struct ast_jb *jb, struct timeval *tv);
static void jb_choose_impl(struct ast_channel *chan)
{
- struct ast_jb *jb = &chan->jb;
+ struct ast_jb *jb = chan->jb;
struct ast_jb_conf *jbconf = &jb->conf;
struct ast_jb_impl *test_impl;
int i, avail_impl_count = sizeof(avail_impl) / sizeof(avail_impl[0]);
@@ -197,8 +197,8 @@ static void jb_choose_impl(struct ast_channel *chan)
int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1)
{
- struct ast_jb *jb0 = &c0->jb;
- struct ast_jb *jb1 = &c1->jb;
+ struct ast_jb *jb0 = c0->jb;
+ struct ast_jb *jb1 = c1->jb;
struct ast_jb_conf *conf0 = &jb0->conf;
struct ast_jb_conf *conf1 = &jb1->conf;
int c0_wants_jitter = c0->tech->properties & AST_CHAN_TP_WANTSJITTER;
@@ -258,8 +258,8 @@ int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1)
int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left)
{
- struct ast_jb *jb0 = &c0->jb;
- struct ast_jb *jb1 = &c1->jb;
+ struct ast_jb *jb0 = c0->jb;
+ struct ast_jb *jb1 = c1->jb;
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);
@@ -298,7 +298,7 @@ int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, in
int ast_jb_put(struct ast_channel *chan, struct ast_frame *f)
{
- struct ast_jb *jb = &chan->jb;
+ struct ast_jb *jb = chan->jb;
struct ast_jb_impl *jbimpl = jb->impl;
void *jbobj = jb->jbobj;
struct ast_frame *frr;
@@ -366,8 +366,8 @@ int ast_jb_put(struct ast_channel *chan, struct ast_frame *f)
void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1)
{
- struct ast_jb *jb0 = &c0->jb;
- struct ast_jb *jb1 = &c1->jb;
+ struct ast_jb *jb0 = c0->jb;
+ struct ast_jb *jb1 = c1->jb;
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);
@@ -383,7 +383,7 @@ void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1)
static void jb_get_and_deliver(struct ast_channel *chan)
{
- struct ast_jb *jb = &chan->jb;
+ struct ast_jb *jb = chan->jb;
struct ast_jb_impl *jbimpl = jb->impl;
void *jbobj = jb->jbobj;
struct ast_frame *f, finterp;
@@ -447,7 +447,7 @@ static void jb_get_and_deliver(struct ast_channel *chan)
static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
{
- struct ast_jb *jb = &chan->jb;
+ struct ast_jb *jb = chan->jb;
struct ast_jb_conf *jbconf = &jb->conf;
struct ast_jb_impl *jbimpl = jb->impl;
void *jbobj;
@@ -527,7 +527,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr)
void ast_jb_destroy(struct ast_channel *chan)
{
- struct ast_jb *jb = &chan->jb;
+ struct ast_jb *jb = chan->jb;
struct ast_jb_impl *jbimpl = jb->impl;
void *jbobj = jb->jbobj;
struct ast_frame *f;
@@ -551,6 +551,8 @@ void ast_jb_destroy(struct ast_channel *chan)
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, chan->name);
}
+
+ free(jb);
}
@@ -601,15 +603,25 @@ int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value)
}
-void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
+int ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
{
- memcpy(&chan->jb.conf, conf, sizeof(*conf));
+ if (!(chan->jb = ast_calloc(1, sizeof(*chan->jb))))
+ return -1;
+
+ memcpy(&chan->jb->conf, conf, sizeof(*conf));
+
+ return 0;
}
-void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf)
+int ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf)
{
- memcpy(conf, &chan->jb.conf, sizeof(*conf));
+ if (!chan->jb)
+ return -1;
+
+ memcpy(conf, &chan->jb->conf, sizeof(*conf));
+
+ return 0;
}