diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index 9f530c50dab8cb5e4a7063481ac4a519ab34dcb0..3777c48e9f43cb2d8c4e9ac404d03f93b8037f7f 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -498,21 +498,10 @@ static struct ast_generator spygen = { static int start_spying(struct ast_autochan *autochan, const char *spychan_name, struct ast_audiohook *audiohook) { - int res = 0; - ast_log(LOG_NOTICE, "Attaching %s to %s\n", spychan_name, ast_channel_name(autochan->chan)); ast_set_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC | AST_AUDIOHOOK_SMALL_QUEUE); - res = ast_audiohook_attach(autochan->chan, audiohook); - - if (!res) { - ast_channel_lock(autochan->chan); - if (ast_channel_is_bridged(autochan->chan)) { - ast_channel_set_unbridged_nolock(autochan->chan, 1); - } - ast_channel_unlock(autochan->chan); - } - return res; + return ast_audiohook_attach(autochan->chan, audiohook); } static void change_spy_mode(const char digit, struct ast_flags *flags) diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c index 4b3da07c028e2b377926ab71a610c91745800836..a993580b3892035f4d779b50d6482c44964cc160 100644 --- a/apps/app_mixmonitor.c +++ b/apps/app_mixmonitor.c @@ -451,22 +451,11 @@ static void destroy_monitor_audiohook(struct mixmonitor *mixmonitor) static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook) { - int res = 0; - - if (!chan) + if (!chan) { return -1; - - ast_audiohook_attach(chan, audiohook); - - if (!res) { - ast_channel_lock(chan); - if (ast_channel_is_bridged(chan)) { - ast_channel_set_unbridged_nolock(chan, 1); - } - ast_channel_unlock(chan); } - return res; + return ast_audiohook_attach(chan, audiohook); } /*! @@ -1149,7 +1138,8 @@ static int stop_mixmonitor_full(struct ast_channel *chan, const char *data) ast_channel_lock(chan); - datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, args.mixmonid); + datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, + S_OR(args.mixmonid, NULL)); if (!datastore) { ast_channel_unlock(chan); return -1; diff --git a/main/audiohook.c b/main/audiohook.c index 33dad38f9040433768841be86cf2f7896ef573ab..1c0f2c7ab41caf616cd00467c946f7b9f7531b89 100644 --- a/main/audiohook.c +++ b/main/audiohook.c @@ -483,6 +483,10 @@ int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audioho /* Change status over to running since it is now attached */ ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_RUNNING); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } + ast_channel_unlock(chan); return 0; @@ -713,6 +717,10 @@ int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audioho audiohook_list_set_samplerate_compatibility(ast_channel_audiohooks(chan)); ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } + ast_channel_unlock(chan); return 0; @@ -738,6 +746,9 @@ static struct ast_frame *dtmf_audiohook_write_list(struct ast_channel *chan, str ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE); ast_audiohook_unlock(audiohook); audiohook->manipulate_callback(audiohook, NULL, NULL, 0); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } continue; } if (ast_test_flag(audiohook, AST_AUDIOHOOK_WANTS_DTMF)) { @@ -863,6 +874,9 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st removed = 1; ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE); ast_audiohook_unlock(audiohook); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } continue; } audiohook_set_internal_rate(audiohook, audiohook_list->list_internal_samp_rate, 1); @@ -884,6 +898,9 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st removed = 1; ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE); ast_audiohook_unlock(audiohook); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } continue; } audiohook_set_internal_rate(audiohook, audiohook_list->list_internal_samp_rate, 1); @@ -914,6 +931,9 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st ast_audiohook_unlock(audiohook); /* We basically drop all of our links to the manipulate audiohook and prod it to do it's own destructive things */ audiohook->manipulate_callback(audiohook, chan, NULL, direction); + if (ast_channel_is_bridged(chan)) { + ast_channel_set_unbridged_nolock(chan, 1); + } continue; } audiohook_set_internal_rate(audiohook, audiohook_list->list_internal_samp_rate, 1); diff --git a/main/framehook.c b/main/framehook.c index 8df3a31a4d935d4a6d42892a2cd74ec0bac92630..44bb8684345d0b1c109ea67c03089fff829812da 100644 --- a/main/framehook.c +++ b/main/framehook.c @@ -94,7 +94,7 @@ static struct ast_frame *framehook_list_push_event(struct ast_framehook_list *fr } skip_size = sizeof(int) * framehooks->count; - skip = alloca(skip_size); + skip = ast_alloca(skip_size); memset(skip, 0, skip_size); do { @@ -198,7 +198,7 @@ int ast_framehook_detach(struct ast_channel *chan, int id) } AST_LIST_TRAVERSE_SAFE_END; - if (ast_channel_is_bridged(chan)) { + if (!res && ast_channel_is_bridged(chan)) { ast_channel_set_unbridged_nolock(chan, 1); } @@ -246,9 +246,11 @@ void ast_framehook_list_fixup(struct ast_channel *old_chan, struct ast_channel * return; } - AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_channel_framehooks(old_chan)->list, framehook, list) { - AST_LIST_REMOVE_CURRENT(list); - + if (!AST_LIST_EMPTY(&ast_channel_framehooks(old_chan)->list) + && ast_channel_is_bridged(old_chan)) { + ast_channel_set_unbridged_nolock(old_chan, 1); + } + while ((framehook = AST_LIST_REMOVE_HEAD(&ast_channel_framehooks(old_chan)->list, list))) { /* If inheritance is not allowed for this framehook, just destroy it. */ if (framehook->i.disable_inheritance) { framehook_detach(framehook, FRAMEHOOK_DETACH_DESTROY); @@ -257,7 +259,6 @@ void ast_framehook_list_fixup(struct ast_channel *old_chan, struct ast_channel * /* Otherwise move it to the other channel and perform any fixups set by the framehook interface */ moved_framehook_id = ast_framehook_attach(new_chan, &framehook->i); - if (moved_framehook_id < 0) { ast_log(LOG_WARNING, "Failed framehook copy during masquerade. Expect loss of features.\n"); framehook_detach(framehook, FRAMEHOOK_DETACH_DESTROY); @@ -270,7 +271,6 @@ void ast_framehook_list_fixup(struct ast_channel *old_chan, struct ast_channel * framehook_detach(framehook, FRAMEHOOK_DETACH_PRESERVE); } } - AST_LIST_TRAVERSE_SAFE_END; } int ast_framehook_list_is_empty(struct ast_framehook_list *framehooks)