#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
+#include "asterisk/utils.h"
static char *app = "Skel";
static char *synopsis =
AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
});
+static void *dogballs(void *shit)
+{
+ ast_log(LOG_NOTICE, "Oh GOD!! I am a thread magician!!\n");
+ return NULL;
+}
static int app_exec(struct ast_channel *chan, void *data)
{
- int res = 0;
- struct ast_flags flags;
+ int i;
struct ast_module_user *u;
- char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(dummy);
- AST_APP_ARG(options);
- );
-
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n", app);
- return -1;
- }
+ pthread_t thread;
u = ast_module_user_add(chan);
/* Do our thing here */
- /* We need to make a copy of the input string if we are going to modify it! */
+ for (i = 0; i < 100; ++i) {
+ ast_pthread_create(&thread, NULL, dogballs, NULL);
+ }
+/*
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (ast_test_flag(&flags, OPTION_C))
ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
-
+*/
ast_module_user_remove(u);
- return res;
+ return 0;
}
static int unload_module(void)
typedef int (*jb_remove_impl)(void *jb, struct ast_frame **fout);
/*! \brief Force resynch */
typedef void (*jb_force_resynch_impl)(void *jb);
-
+/*! \brief Empty and reset jb */
+typedef void (*jb_empty_and_reset_impl)(void *jb);
/*!
* \brief Jitterbuffer implementation private struct.
jb_next_impl next;
jb_remove_impl remove;
jb_force_resynch_impl force_resync;
+ jb_empty_and_reset_impl empty_and_reset;
};
/* Implementation functions */
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);
+static void jb_empty_and_reset_fixed(void *jb);
/* adaptive */
static void * jb_create_adaptive(struct ast_jb_conf *general_config, long resynch_threshold);
static void jb_destroy_adaptive(void *jb);
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);
+static void jb_empty_and_reset_adaptive(void *jb);
/* Available jb implementations */
static struct ast_jb_impl avail_impl[] =
.get = jb_get_fixed,
.next = jb_next_fixed,
.remove = jb_remove_fixed,
- .force_resync = jb_force_resynch_fixed
+ .force_resync = jb_force_resynch_fixed,
+ .empty_and_reset = jb_empty_and_reset_fixed,
},
{
.name = "adaptive",
.get = jb_get_adaptive,
.next = jb_next_adaptive,
.remove = jb_remove_adaptive,
- .force_resync = jb_force_resynch_adaptive
+ .force_resync = jb_force_resynch_adaptive,
+ .empty_and_reset = jb_empty_and_reset_adaptive,
}
};
}
ast_set_flag(jb0, JB_TIMEBASE_INITIALIZED);
}
-
+
if (!c0_jb_created) {
jb_choose_impl(c0);
}
memcpy(conf, &chan->jb.conf, sizeof(*conf));
}
+void ast_jb_empty_and_reset(struct ast_channel *c0, struct ast_channel *c1)
+{
+ 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);
+ 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);
+ }
+}
/* Implementation functions */
/* fixed */
-
static void * jb_create_fixed(struct ast_jb_conf *general_config, long resynch_threshold)
{
struct fixed_jb_conf conf;
-
+
conf.jbsize = general_config->max_size;
conf.resync_threshold = resynch_threshold;
-
+
return fixed_jb_new(&conf);
}
-
static void jb_destroy_fixed(void *jb)
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
fixed_jb_set_force_resynch(fixedjb);
}
+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);
+ }
+}
/* adaptive */
static void jb_force_resynch_adaptive(void *jb)
{
}
+
+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);
+}