summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/aoc.c5
-rw-r--r--main/asterisk.c52
-rw-r--r--main/audiohook.c4
-rw-r--r--main/frame.c29
-rw-r--r--main/plc.c2
-rw-r--r--main/sdp_state.c15
-rw-r--r--main/sorcery.c30
-rw-r--r--main/stasis_bridges.c8
8 files changed, 95 insertions, 50 deletions
diff --git a/main/aoc.c b/main/aoc.c
index 451b21973..3487948df 100644
--- a/main/aoc.c
+++ b/main/aoc.c
@@ -1860,7 +1860,10 @@ static void aoc_publish_blob(struct ast_channel *chan, struct stasis_message_typ
msg = stasis_message_create(msg_type, aoc_event);
ao2_ref(aoc_event, -1);
- stasis_publish(ast_manager_get_topic(), msg);
+ if (msg) {
+ stasis_publish(ast_manager_get_topic(), msg);
+ ao2_ref(msg, -1);
+ }
}
static struct ast_manager_event_blob *aoc_to_ami(struct stasis_message *message,
diff --git a/main/asterisk.c b/main/asterisk.c
index d55594983..77046f272 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -607,6 +607,9 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c
ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled");
ast_cli(a->fd, " Generic PLC: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled");
ast_cli(a->fd, " Min DTMF duration:: %u\n", option_dtmfminduration);
+#if !defined(LOW_MEMORY)
+ ast_cli(a->fd, " Cache media frames: %s\n", ast_opt_cache_media_frames ? "Enabled" : "Disabled");
+#endif
ast_cli(a->fd, " RTP use dynamic payloads: %u\n", ast_option_rtpusedynamic);
if (ast_option_rtpptdynamic == AST_RTP_PT_LAST_REASSIGN) {
@@ -1761,15 +1764,13 @@ static struct sigaction urg_handler = {
static void _hup_handler(int num)
{
- int a = 0, save_errno = errno;
+ int save_errno = errno;
printf("Received HUP signal -- Reloading configs\n");
if (restartnow)
execvp(_argv[0], _argv);
sig_flags.need_reload = 1;
- if (sig_alert_pipe[1] != -1) {
- if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) {
- fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
- }
+ if (ast_alertpipe_write(sig_alert_pipe)) {
+ fprintf(stderr, "hup_handler: write() failed: %s\n", strerror(errno));
}
errno = save_errno;
}
@@ -2169,10 +2170,7 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart)
close(ast_consock);
if (!ast_opt_remote)
unlink(ast_config_AST_PID);
- if (sig_alert_pipe[0])
- close(sig_alert_pipe[0]);
- if (sig_alert_pipe[1])
- close(sig_alert_pipe[1]);
+ ast_alertpipe_close(sig_alert_pipe);
printf("%s", term_quit());
if (restart) {
int i;
@@ -2208,12 +2206,9 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart)
static void __quit_handler(int num)
{
- int a = 0;
sig_flags.need_quit = 1;
- if (sig_alert_pipe[1] != -1) {
- if (write(sig_alert_pipe[1], &a, sizeof(a)) < 0) {
- fprintf(stderr, "quit_handler: write() failed: %s\n", strerror(errno));
- }
+ if (ast_alertpipe_write(sig_alert_pipe)) {
+ fprintf(stderr, "quit_handler: write() failed: %s\n", strerror(errno));
}
/* There is no need to restore the signal handler here, since the app
* is going to exit */
@@ -2466,16 +2461,6 @@ static char *handle_version(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
return CLI_SUCCESS;
}
-#if 0
-static int handle_quit(int fd, int argc, char *argv[])
-{
- if (argc != 1)
- return RESULT_SHOWUSAGE;
- quit_handler(0, SHUTDOWN_NORMAL, 0);
- return RESULT_SUCCESS;
-}
-#endif
-
static char *handle_stop_now(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
switch (cmd) {
@@ -3665,7 +3650,6 @@ static void ast_readconfig(void)
ast_copy_string(cfg_paths.agi_dir, v->value, sizeof(cfg_paths.agi_dir));
} else if (!strcasecmp(v->name, "astrundir")) {
snprintf(cfg_paths.pid_path, sizeof(cfg_paths.pid_path), "%s/%s", v->value, "asterisk.pid");
- snprintf(cfg_paths.socket_path, sizeof(cfg_paths.socket_path), "%s/%s", v->value, ast_config_AST_CTL);
ast_copy_string(cfg_paths.run_dir, v->value, sizeof(cfg_paths.run_dir));
} else if (!strcasecmp(v->name, "astmoddir")) {
ast_copy_string(cfg_paths.module_dir, v->value, sizeof(cfg_paths.module_dir));
@@ -3674,6 +3658,10 @@ static void ast_readconfig(void)
}
}
+ /* Combine astrundir and astctl settings. */
+ snprintf(cfg_paths.socket_path, sizeof(cfg_paths.socket_path), "%s/%s",
+ ast_config_AST_RUN_DIR, ast_config_AST_CTL);
+
for (v = ast_variable_browse(cfg, "options"); v; v = v->next) {
/* verbose level (-v at startup) */
if (!strcasecmp(v->name, "verbose")) {
@@ -3724,6 +3712,11 @@ static void ast_readconfig(void)
/* Cache recorded sound files to another directory during recording */
} else if (!strcasecmp(v->name, "cache_record_files")) {
ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CACHE_RECORD_FILES);
+#if !defined(LOW_MEMORY)
+ /* Cache media frames for performance */
+ } else if (!strcasecmp(v->name, "cache_media_frames")) {
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CACHE_MEDIA_FRAMES);
+#endif
/* Specify cache directory */
} else if (!strcasecmp(v->name, "record_cache_dir")) {
ast_copy_string(record_cache_dir, v->value, AST_CACHE_DIR_LEN);
@@ -3887,7 +3880,7 @@ static void *monitor_sig_flags(void *unused)
{
for (;;) {
struct pollfd p = { sig_alert_pipe[0], POLLIN, 0 };
- int a;
+
ast_poll(&p, 1, -1);
if (sig_flags.need_reload) {
sig_flags.need_reload = 0;
@@ -3902,8 +3895,7 @@ static void *monitor_sig_flags(void *unused)
quit_handler(0, SHUTDOWN_NORMAL, 0);
}
}
- if (read(sig_alert_pipe[0], &a, sizeof(a)) != sizeof(a)) {
- }
+ ast_alertpipe_read(sig_alert_pipe);
}
return NULL;
@@ -4710,9 +4702,7 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
consolethread = pthread_self();
}
- if (pipe(sig_alert_pipe)) {
- sig_alert_pipe[0] = sig_alert_pipe[1] = -1;
- }
+ ast_alertpipe_init(sig_alert_pipe);
ast_process_pending_reloads();
diff --git a/main/audiohook.c b/main/audiohook.c
index 2cba2de6e..04a379fef 100644
--- a/main/audiohook.c
+++ b/main/audiohook.c
@@ -950,7 +950,9 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st
* rely on actual media being present to do things.
*/
if (!middle_frame->data.ptr) {
- ast_frfree(middle_frame);
+ if (middle_frame != start_frame) {
+ ast_frfree(middle_frame);
+ }
return start_frame;
}
diff --git a/main/frame.c b/main/frame.c
index c24cc8f78..dd47f42d0 100644
--- a/main/frame.c
+++ b/main/frame.c
@@ -120,14 +120,18 @@ static void __frame_free(struct ast_frame *fr, int cache)
return;
#if !defined(LOW_MEMORY)
- if (cache && fr->mallocd == AST_MALLOCD_HDR) {
+ if (fr->mallocd == AST_MALLOCD_HDR
+ && cache
+ && ast_opt_cache_media_frames) {
/* Cool, only the header is malloc'd, let's just cache those for now
* to keep things simple... */
struct ast_frame_cache *frames;
- if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames))) &&
- (frames->size < FRAME_CACHE_MAX_SIZE)) {
- if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) ||
- (fr->frametype == AST_FRAME_IMAGE)) {
+
+ frames = ast_threadstorage_get(&frame_cache, sizeof(*frames));
+ if (frames && frames->size < FRAME_CACHE_MAX_SIZE) {
+ if (fr->frametype == AST_FRAME_VOICE
+ || fr->frametype == AST_FRAME_VIDEO
+ || fr->frametype == AST_FRAME_IMAGE) {
ao2_cleanup(fr->subclass.format);
}
@@ -147,8 +151,9 @@ static void __frame_free(struct ast_frame *fr, int cache)
ast_free((void *) fr->src);
}
if (fr->mallocd & AST_MALLOCD_HDR) {
- if ((fr->frametype == AST_FRAME_VOICE) || (fr->frametype == AST_FRAME_VIDEO) ||
- (fr->frametype == AST_FRAME_IMAGE)) {
+ if (fr->frametype == AST_FRAME_VOICE
+ || fr->frametype == AST_FRAME_VIDEO
+ || fr->frametype == AST_FRAME_IMAGE) {
ao2_cleanup(fr->subclass.format);
}
@@ -163,18 +168,16 @@ void ast_frame_free(struct ast_frame *frame, int cache)
{
struct ast_frame *next;
- for (next = AST_LIST_NEXT(frame, frame_list);
- frame;
- frame = next, next = frame ? AST_LIST_NEXT(frame, frame_list) : NULL) {
+ while (frame) {
+ next = AST_LIST_NEXT(frame, frame_list);
__frame_free(frame, cache);
+ frame = next;
}
}
void ast_frame_dtor(struct ast_frame *f)
{
- if (f) {
- ast_frfree(f);
- }
+ ast_frfree(f);
}
/*!
diff --git a/main/plc.c b/main/plc.c
index b649357dc..739f7276d 100644
--- a/main/plc.c
+++ b/main/plc.c
@@ -96,7 +96,7 @@ static void normalise_history(plc_state_t *s)
if (s->buf_ptr == 0)
return;
memcpy(tmp, s->history, sizeof(int16_t)*s->buf_ptr);
- memcpy(s->history, s->history + s->buf_ptr, sizeof(int16_t) * (PLC_HISTORY_LEN - s->buf_ptr));
+ memmove(s->history, s->history + s->buf_ptr, sizeof(int16_t) * (PLC_HISTORY_LEN - s->buf_ptr));
memcpy(s->history + PLC_HISTORY_LEN - s->buf_ptr, tmp, sizeof(int16_t) * s->buf_ptr);
s->buf_ptr = 0;
}
diff --git a/main/sdp_state.c b/main/sdp_state.c
index a77d96da5..2b75cc2a1 100644
--- a/main/sdp_state.c
+++ b/main/sdp_state.c
@@ -1255,7 +1255,10 @@ static int sdp_merge_streams_match(
return -1;
}
idx = AST_VECTOR_GET(current_vect, current_idx);
- ast_stream_topology_set_stream(merged_topology, idx, merged_stream);
+ if (ast_stream_topology_set_stream(merged_topology, idx, merged_stream)) {
+ ast_stream_free(merged_stream);
+ return -1;
+ }
/*
* The current_stream cannot be considered a backfill_candidate
@@ -1400,7 +1403,10 @@ static struct ast_stream_topology *merge_local_topologies(
if (!merged_stream) {
goto fail;
}
- ast_stream_topology_set_stream(merged_topology, idx, merged_stream);
+ if (ast_stream_topology_set_stream(merged_topology, idx, merged_stream)) {
+ ast_stream_free(merged_stream);
+ goto fail;
+ }
}
/* Backfill new update stream slots into pre-existing declined current stream slots */
@@ -1438,7 +1444,10 @@ static struct ast_stream_topology *merge_local_topologies(
}
/* Add the new stream into the backfill stream slot. */
- ast_stream_topology_set_stream(merged_topology, current_idx, merged_stream);
+ if (ast_stream_topology_set_stream(merged_topology, current_idx, merged_stream)) {
+ ast_stream_free(merged_stream);
+ goto fail;
+ }
backfill_candidate[current_idx] = 0;
}
diff --git a/main/sorcery.c b/main/sorcery.c
index 01b77918d..51b55c5a2 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -2036,6 +2036,36 @@ struct ao2_container *ast_sorcery_retrieve_by_regex(const struct ast_sorcery *so
return objects;
}
+struct ao2_container *ast_sorcery_retrieve_by_prefix(const struct ast_sorcery *sorcery, const char *type, const char *prefix, const size_t prefix_len)
+{
+ RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
+ struct ao2_container *objects;
+ int i;
+
+ if (!object_type || !(objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) {
+ return NULL;
+ }
+
+ AST_VECTOR_RW_RDLOCK(&object_type->wizards);
+ for (i = 0; i < AST_VECTOR_SIZE(&object_type->wizards); i++) {
+ struct ast_sorcery_object_wizard *wizard =
+ AST_VECTOR_GET(&object_type->wizards, i);
+
+ if (!wizard->wizard->callbacks.retrieve_prefix) {
+ continue;
+ }
+
+ wizard->wizard->callbacks.retrieve_prefix(sorcery, wizard->data, object_type->name, objects, prefix, prefix_len);
+
+ if (wizard->caching && ao2_container_count(objects)) {
+ break;
+ }
+ }
+ AST_VECTOR_RW_UNLOCK(&object_type->wizards);
+
+ return objects;
+}
+
/*! \brief Internal function which returns if the wizard has created the object */
static int sorcery_wizard_create(const struct ast_sorcery_object_wizard *object_wizard, const struct sorcery_details *details)
{
diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c
index 7f53bfe2d..d197e4d2d 100644
--- a/main/stasis_bridges.c
+++ b/main/stasis_bridges.c
@@ -868,6 +868,8 @@ static struct ast_json *attended_transfer_to_json(struct stasis_message *msg,
if (transfer_msg->transferee) {
json_transferee = ast_channel_snapshot_to_json(transfer_msg->transferee, sanitize);
if (!json_transferee) {
+ ast_json_unref(json_transferer2);
+ ast_json_unref(json_transferer1);
return NULL;
}
}
@@ -875,6 +877,9 @@ static struct ast_json *attended_transfer_to_json(struct stasis_message *msg,
if (transfer_msg->target) {
json_target = ast_channel_snapshot_to_json(transfer_msg->target, sanitize);
if (!json_target) {
+ ast_json_unref(json_transferee);
+ ast_json_unref(json_transferer2);
+ ast_json_unref(json_transferer1);
return NULL;
}
}
@@ -887,9 +892,12 @@ static struct ast_json *attended_transfer_to_json(struct stasis_message *msg,
"result", result_strs[transfer_msg->result],
"is_external", ast_json_boolean(transfer_msg->is_external));
if (!out) {
+ ast_json_unref(json_target);
+ ast_json_unref(json_transferee);
return NULL;
}
if (json_transferee && ast_json_object_set(out, "transferee", json_transferee)) {
+ ast_json_unref(json_target);
return NULL;
}
if (json_target && ast_json_object_set(out, "transfer_target", json_target)) {