summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/core_unreal.c2
-rw-r--r--res/ari/resource_bridges.c4
-rw-r--r--res/res_rtp_asterisk.c15
-rw-r--r--res/res_stasis.c15
-rw-r--r--res/res_stasis_recording.c18
-rw-r--r--res/stasis/control.c39
-rw-r--r--res/stasis/control.h8
7 files changed, 59 insertions, 42 deletions
diff --git a/main/core_unreal.c b/main/core_unreal.c
index 028e371f6..fc311ec5d 100644
--- a/main/core_unreal.c
+++ b/main/core_unreal.c
@@ -808,9 +808,11 @@ int ast_unreal_channel_push_to_bridge(struct ast_channel *ast, struct ast_bridge
return -1;
}
+ /* The bridge thread now controls the chan ref from the ast_unreal_pvt */
ao2_lock(p);
ast_set_flag(p, AST_UNREAL_CARETAKER_THREAD);
ao2_unlock(p);
+
ast_channel_unref(chan);
return 0;
diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c
index ad37053f7..127933ae4 100644
--- a/res/ari/resource_bridges.c
+++ b/res/ari/resource_bridges.c
@@ -527,9 +527,7 @@ static enum play_found_result ari_bridges_play_found(const char *args_media,
control = stasis_app_control_find_by_channel(play_channel);
if (!control) {
- ast_ari_response_error(
- response, 500, "Internal Error", "Failed to get control snapshot");
- return PLAY_FOUND_FAILURE;
+ return PLAY_FOUND_CHANNEL_UNAVAILABLE;
}
ao2_lock(control);
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 4c6ee185f..029aff01b 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -2252,7 +2252,6 @@ static int __rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t siz
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
struct ast_srtp *srtp = ast_rtp_instance_get_srtp(instance);
int res;
- int hdrlen = 12;
*ice = 0;
@@ -2260,9 +2259,6 @@ static int __rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t siz
return -1;
}
- rtp->txcount++;
- rtp->txoctetcount += (len - hdrlen);
-
#ifdef HAVE_PJPROJECT
if (rtp->ice) {
pj_thread_register_check();
@@ -2289,7 +2285,16 @@ static int rtcp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size
static int rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct ast_sockaddr *sa, int *ice)
{
- return __rtp_sendto(instance, buf, size, flags, sa, 0, ice, 1);
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ int hdrlen = 12;
+ int res;
+
+ if ((res = __rtp_sendto(instance, buf, size, flags, sa, 0, ice, 1)) > 0) {
+ rtp->txcount++;
+ rtp->txoctetcount += (res - hdrlen);
+ }
+
+ return res;
}
static int rtp_get_rate(struct ast_format *format)
diff --git a/res/res_stasis.c b/res/res_stasis.c
index 94b037e69..5dabc7f73 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -1188,10 +1188,11 @@ void stasis_app_channel_set_stasis_end_published(struct ast_channel *chan)
struct ast_datastore *datastore;
datastore = ast_datastore_alloc(&set_end_published_info, NULL);
-
- ast_channel_lock(chan);
- ast_channel_datastore_add(chan, datastore);
- ast_channel_unlock(chan);
+ if (datastore) {
+ ast_channel_lock(chan);
+ ast_channel_datastore_add(chan, datastore);
+ ast_channel_unlock(chan);
+ }
}
int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan)
@@ -1211,12 +1212,11 @@ static void remove_stasis_end_published(struct ast_channel *chan)
ast_channel_lock(chan);
datastore = ast_channel_datastore_find(chan, &set_end_published_info, NULL);
- ast_channel_unlock(chan);
-
if (datastore) {
ast_channel_datastore_remove(chan, datastore);
ast_datastore_free(datastore);
}
+ ast_channel_unlock(chan);
}
/*! /brief Stasis dialplan application callback */
@@ -1371,6 +1371,9 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
remove_stasis_end_published(chan);
}
+ /* Stop any lingering silence generator */
+ control_silence_stop_now(control);
+
/* There's an off chance that app is ready for cleanup. Go ahead
* and clean up, just in case
*/
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index 392d92c8e..05b97bf69 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -265,7 +265,13 @@ static enum stasis_app_control_channel_result check_rule_recording(
return STASIS_APP_CHANNEL_RECORDING;
}
-struct stasis_app_control_rule rule_recording = {
+/*
+ * XXX This only works because there is one and only one rule in
+ * the system so it can be added to any number of channels
+ * without issue. However, as soon as there is another rule then
+ * watch out for weirdness because of cross linked lists.
+ */
+static struct stasis_app_control_rule rule_recording = {
.check_rule = check_rule_recording
};
@@ -465,15 +471,7 @@ const char *stasis_app_recording_get_name(
struct stasis_app_recording *stasis_app_recording_find_by_name(const char *name)
{
- RAII_VAR(struct stasis_app_recording *, recording, NULL, ao2_cleanup);
-
- recording = ao2_find(recordings, name, OBJ_KEY);
- if (recording == NULL) {
- return NULL;
- }
-
- ao2_ref(recording, +1);
- return recording;
+ return ao2_find(recordings, name, OBJ_KEY);
}
struct ast_json *stasis_app_recording_to_json(
diff --git a/res/stasis/control.c b/res/stasis/control.c
index ebb7e0194..00385a09f 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -87,21 +87,19 @@ static void control_dtor(void *obj)
{
struct stasis_app_control *control = obj;
- AST_LIST_HEAD_DESTROY(&control->add_rules);
- AST_LIST_HEAD_DESTROY(&control->remove_rules);
+ ao2_cleanup(control->command_queue);
- /* We may have a lingering silence generator; free it */
- ast_channel_stop_silence_generator(control->channel, control->silgen);
- control->silgen = NULL;
+ ast_channel_cleanup(control->channel);
+ ao2_cleanup(control->app);
- ao2_cleanup(control->command_queue);
ast_cond_destroy(&control->wait_cond);
- ao2_cleanup(control->app);
+ AST_LIST_HEAD_DESTROY(&control->add_rules);
+ AST_LIST_HEAD_DESTROY(&control->remove_rules);
}
struct stasis_app_control *control_create(struct ast_channel *channel, struct stasis_app *app)
{
- RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ struct stasis_app_control *control;
int res;
control = ao2_alloc(sizeof(*control), control_dtor);
@@ -109,28 +107,29 @@ struct stasis_app_control *control_create(struct ast_channel *channel, struct st
return NULL;
}
- control->app = ao2_bump(app);
+ AST_LIST_HEAD_INIT(&control->add_rules);
+ AST_LIST_HEAD_INIT(&control->remove_rules);
res = ast_cond_init(&control->wait_cond, NULL);
if (res != 0) {
ast_log(LOG_ERROR, "Error initializing ast_cond_t: %s\n",
strerror(errno));
+ ao2_ref(control, -1);
return NULL;
}
+ control->app = ao2_bump(app);
+
+ ast_channel_ref(channel);
+ control->channel = channel;
+
control->command_queue = ao2_container_alloc_list(
AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
-
if (!control->command_queue) {
+ ao2_ref(control, -1);
return NULL;
}
- control->channel = channel;
-
- AST_LIST_HEAD_INIT(&control->add_rules);
- AST_LIST_HEAD_INIT(&control->remove_rules);
-
- ao2_ref(control, +1);
return control;
}
@@ -785,8 +784,7 @@ void stasis_app_control_silence_start(struct stasis_app_control *control)
stasis_app_send_command_async(control, app_control_silence_start, NULL, NULL);
}
-static int app_control_silence_stop(struct stasis_app_control *control,
- struct ast_channel *chan, void *data)
+void control_silence_stop_now(struct stasis_app_control *control)
{
if (control->silgen) {
ast_debug(3, "%s: Stopping silence generator\n",
@@ -795,7 +793,12 @@ static int app_control_silence_stop(struct stasis_app_control *control,
control->channel, control->silgen);
control->silgen = NULL;
}
+}
+static int app_control_silence_stop(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ control_silence_stop_now(control);
return 0;
}
diff --git a/res/stasis/control.h b/res/stasis/control.h
index a139f82e4..d053a35f7 100644
--- a/res/stasis/control.h
+++ b/res/stasis/control.h
@@ -108,5 +108,13 @@ int control_add_channel_to_bridge(
struct stasis_app_control *control,
struct ast_channel *chan, void *obj);
+/*!
+ * \brief Stop playing silence to a channel right now.
+ * \since 13.9.0
+ *
+ * \param control The control for chan
+ */
+void control_silence_stop_now(struct stasis_app_control *control);
+
#endif /* _ASTERISK_RES_STASIS_CONTROL_H */