Author: rmudgett
Date: Fri Oct  3 14:36:09 2014
New Revision: 424506

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=424506
Log:
audiohooks: Reevaluate the bridge technology when an audiohook is added or 
removed.

Adding a mixmonitor to a channel causes the bridge to change technologies
from native to simple_bridge so the call can be recorded.  However, when
the mixmonitor is stopped the bridge does not switch back to the native
technology.

* Added unbridge requests to reevaluate the bridge when a channel
audiohook is removed.

* Moved the unbridge request into ast_audiohook_attach() ensure that the
bridge reevaluates whenever an audiohook is attached.  This simplified the
mixmonitor and chan_spy start code as well.

* Added defensive code to stop_mixmonitor_full() in case additional
arguments are ever added to the StopMixMonitor application.

* Made ast_framehook_detach() not do an unbridge request if the framehook
does not exist.

* Made ast_framehook_list_fixup() do an unbridge request if there are any
framehooks.  Also simplified the loop.

ASTERISK-24195 #close
Reported by: Jonathan Rose

Review: https://reviewboard.asterisk.org/r/4046/

Modified:
    branches/12/apps/app_chanspy.c
    branches/12/apps/app_mixmonitor.c
    branches/12/main/audiohook.c
    branches/12/main/framehook.c

Modified: branches/12/apps/app_chanspy.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/12/apps/app_chanspy.c?view=diff&rev=424506&r1=424505&r2=424506
==============================================================================
--- branches/12/apps/app_chanspy.c (original)
+++ branches/12/apps/app_chanspy.c Fri Oct  3 14:36:09 2014
@@ -494,21 +494,10 @@
 
 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)

Modified: branches/12/apps/app_mixmonitor.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/12/apps/app_mixmonitor.c?view=diff&rev=424506&r1=424505&r2=424506
==============================================================================
--- branches/12/apps/app_mixmonitor.c (original)
+++ branches/12/apps/app_mixmonitor.c Fri Oct  3 14:36:09 2014
@@ -411,22 +411,11 @@
 
 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);
 }
 
 /*!
@@ -1077,7 +1066,8 @@
 
        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;

Modified: branches/12/main/audiohook.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/12/main/audiohook.c?view=diff&rev=424506&r1=424505&r2=424506
==============================================================================
--- branches/12/main/audiohook.c (original)
+++ branches/12/main/audiohook.c Fri Oct  3 14:36:09 2014
@@ -469,6 +469,10 @@
        /* 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;
@@ -689,6 +693,10 @@
 
        
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);
 
@@ -715,6 +723,9 @@
                        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))
@@ -840,6 +851,9 @@
                        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);
@@ -861,6 +875,9 @@
                                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);
@@ -890,6 +907,9 @@
                                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);

Modified: branches/12/main/framehook.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/12/main/framehook.c?view=diff&rev=424506&r1=424505&r2=424506
==============================================================================
--- branches/12/main/framehook.c (original)
+++ branches/12/main/framehook.c Fri Oct  3 14:36:09 2014
@@ -94,7 +94,7 @@
        }
 
        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 @@
        }
        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 @@
                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 @@
 
                /* 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 @@
                        framehook_detach(framehook, FRAMEHOOK_DETACH_PRESERVE);
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END;
 }
 
 int ast_framehook_list_is_empty(struct ast_framehook_list *framehooks)


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to