summaryrefslogtreecommitdiff
path: root/res/res_stasis_playback.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2014-03-17 17:22:12 +0000
committerMark Michelson <mmichelson@digium.com>2014-03-17 17:22:12 +0000
commitd44aefeef476d744f2915d47c3fdc9b138cdd584 (patch)
tree59aa013e9a8c0fb7ab1607e2e98076dd88a60f1b /res/res_stasis_playback.c
parent1900bae7b6cec9479ba0e89aed31d02aa71f3133 (diff)
Fix stuck channel in ARI through the introduction of synchronous bridge actions.
Playing back a file to a channel in an ARI bridge would attempt to wait until the playback concluded before returning. The method used involved signaling the waiting thread in the ARI custom playback function. The problem with this is that there were some corner cases that were not accounted for: * If a bridge channel could not be found, then we never would attempt the playback but would still attempt to wait for the playback to complete. * If the bridge playfile action failed to queue, we would still attempt to wait for the playback to complete. * If the bridge playfile action were queued but some circumstance caused the playback not to occur (the bridge dies, the channel is removed from the bridge), then we would never be notified. The solution to this is to move the waiting logic into the bridge code. A new bridge API function is added to queue a synchronous action on a bridge. The waiting thread is notified when the queued frame has been freed, either due to an error occurring or due to successful playback. As a failsafe, the waiting thread has a 10 minute timeout just in case there is a frame leak somewhere. Review: https://reviewboard.asterisk.org/r/3338 ........ Merged revisions 410673 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410684 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_stasis_playback.c')
-rw-r--r--res/res_stasis_playback.c46
1 files changed, 4 insertions, 42 deletions
diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index ee4a20bcc..299cb4483 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -78,14 +78,10 @@ struct stasis_app_playback {
long offsetms;
/*! Number of milliseconds to skip for forward/reverse operations */
int skipms;
- /*! Condition for waiting on done to be set */
- ast_cond_t done_cond;
/*! Number of milliseconds of media that has been played */
long playedms;
/*! Current playback state */
enum stasis_app_playback_state state;
- /*! Set when playback has been completed */
- unsigned int done:1;
/*! Set when the playback can be controlled */
unsigned int controllable:1;
};
@@ -121,7 +117,6 @@ static void playback_dtor(void *obj)
struct stasis_app_playback *playback = obj;
ast_string_field_free_memory(playback);
- ast_cond_destroy(&playback->done_cond);
}
static struct stasis_app_playback *playback_create(
@@ -129,7 +124,6 @@ static struct stasis_app_playback *playback_create(
{
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
char uuid[AST_UUID_STR_LEN];
- int res;
if (!control) {
return NULL;
@@ -140,13 +134,6 @@ static struct stasis_app_playback *playback_create(
return NULL;
}
- res = ast_cond_init(&playback->done_cond, NULL);
- if (res != 0) {
- ast_log(LOG_ERROR, "Error creating done condition: %s\n",
- strerror(errno));
- return NULL;
- }
-
if (!ast_strlen_zero(id)) {
ast_string_field_set(playback, id, id);
} else {
@@ -266,21 +253,9 @@ static void playback_final_update(struct stasis_app_playback *playback,
playback_publish(playback);
}
-/*!
- * \brief RAII_VAR function to mark a playback as done when leaving scope.
- */
-static void mark_as_done(struct stasis_app_playback *playback)
-{
- SCOPED_AO2LOCK(lock, playback);
- playback->done = 1;
- ast_cond_broadcast(&playback->done_cond);
-}
-
static void play_on_channel(struct stasis_app_playback *playback,
struct ast_channel *chan)
{
- RAII_VAR(struct stasis_app_playback *, mark_when_done, playback,
- mark_as_done);
int res;
long offsetms;
@@ -399,7 +374,6 @@ static int play_uri(struct stasis_app_control *control,
RAII_VAR(struct stasis_app_playback *, playback, NULL,
remove_from_playbacks);
struct ast_bridge *bridge;
- int res;
playback = data;
@@ -413,28 +387,16 @@ static int play_uri(struct stasis_app_control *control,
/* Queue up playback on the bridge */
ast_bridge_lock(bridge);
- bridge_chan = bridge_find_channel(bridge, chan);
+ bridge_chan = ao2_bump(bridge_find_channel(bridge, chan));
+ ast_bridge_unlock(bridge);
if (bridge_chan) {
- ast_bridge_channel_queue_playfile(
+ ast_bridge_channel_queue_playfile_sync(
bridge_chan,
play_on_channel_in_bridge,
playback->id,
NULL); /* moh_class */
}
- ast_bridge_unlock(bridge);
-
- /* Wait for playback to complete */
- ao2_lock(playback);
- while (!playback->done) {
- res = ast_cond_wait(&playback->done_cond,
- ao2_object_get_lockaddr(playback));
- if (res != 0) {
- ast_log(LOG_ERROR,
- "Error waiting for playback to complete: %s\n",
- strerror(errno));
- }
- }
- ao2_unlock(playback);
+ ao2_cleanup(bridge_chan);
} else {
play_on_channel(playback, chan);
}