Extract a repeated test into ast_channel_has_audio_frame_or_monitor().
authorRichard Mudgett <rmudgett@digium.com>
Fri, 19 Jul 2013 22:47:10 +0000 (22:47 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 19 Jul 2013 22:47:10 +0000 (22:47 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394825 65c4cc65-6c06-0410-ace0-fbb531ad65f3

bridges/bridge_native_rtp.c
include/asterisk/channel.h
main/bridging.c
main/channel.c

index 4436f70..924686b 100644 (file)
@@ -45,7 +45,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/bridging_technology.h"
 #include "asterisk/frame.h"
 #include "asterisk/rtp_engine.h"
-#include "asterisk/audiohook.h"
 
 /*! \brief Forward declarations for frame hook usage */
 static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
@@ -85,13 +84,7 @@ static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, struct a
 /*! \brief Internal helper function which checks whether the channels are compatible with our native bridging */
 static int native_rtp_bridge_capable(struct ast_channel *chan)
 {
-       if (ast_channel_monitor(chan) || (ast_channel_audiohooks(chan) &&
-               !ast_audiohook_write_list_empty(ast_channel_audiohooks(chan))) ||
-               !ast_framehook_list_contains_no_active(ast_channel_framehooks(chan))) {
-               return 0;
-       } else {
-               return 1;
-       }
+       return ast_channel_has_audio_frame_or_monitor(chan);
 }
 
 /*! \brief Internal helper function which gets all RTP information (glue and instances) relating to the given channels */
index b2b6e60..d8db470 100644 (file)
@@ -4336,6 +4336,16 @@ int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *
 const char *ast_channel_oldest_linkedid(const char *a, const char *b);
 
 /*!
+ * \brief Check if the channel has active audiohooks, active framehooks, or a monitor.
+ * \since 12.0.0
+ *
+ * \param chan The channel to check.
+ *
+ * \retval non-zero if channel has active audiohooks, framehooks, or monitor.
+ */
+int ast_channel_has_audio_frame_or_monitor(struct ast_channel *chan);
+
+/*!
  * \brief Removes the trailing identifiers from a channel name string
  * \since 12.0.0
  *
index 4304dfb..f833ccb 100644 (file)
@@ -63,7 +63,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/core_local.h"
 #include "asterisk/core_unreal.h"
 #include "asterisk/features_config.h"
-#include "asterisk/audiohook.h"
 
 /*! All bridges container. */
 static struct ao2_container *bridges;
@@ -4722,10 +4721,7 @@ static struct ast_bridge *optimize_lock_chan_stack(struct ast_channel *chan)
        if (!AST_LIST_EMPTY(ast_channel_readq(chan))) {
                return NULL;
        }
-       if (ast_channel_monitor(chan)
-               || (ast_channel_audiohooks(chan)
-                       && !ast_audiohook_write_list_empty(ast_channel_audiohooks(chan)))
-               || !ast_framehook_list_contains_no_active(ast_channel_framehooks(chan))) {
+       if (ast_channel_has_audio_frame_or_monitor(chan)) {
                /* Channel has an active monitor, audiohook, or framehook. */
                return NULL;
        }
@@ -4771,10 +4767,7 @@ static struct ast_bridge *optimize_lock_peer_stack(struct ast_channel *peer)
                ast_channel_unlock(peer);
                return NULL;
        }
-       if (ast_channel_monitor(peer)
-               || (ast_channel_audiohooks(peer)
-                       && !ast_audiohook_write_list_empty(ast_channel_audiohooks(peer)))
-               || !ast_framehook_list_contains_no_active(ast_channel_framehooks(peer))) {
+       if (ast_channel_has_audio_frame_or_monitor(peer)) {
                /* Peer has an active monitor, audiohook, or framehook. */
                ast_channel_unlock(peer);
                return NULL;
index fba59d4..f76d6a8 100644 (file)
@@ -2629,6 +2629,14 @@ void ast_set_hangupsource(struct ast_channel *chan, const char *source, int forc
        }
 }
 
+int ast_channel_has_audio_frame_or_monitor(struct ast_channel *chan)
+{
+       return ast_channel_monitor(chan)
+               || (ast_channel_audiohooks(chan)
+                       && !ast_audiohook_write_list_empty(ast_channel_audiohooks(chan)))
+               || !ast_framehook_list_contains_no_active(ast_channel_framehooks(chan));
+}
+
 static void destroy_hooks(struct ast_channel *chan)
 {
        if (ast_channel_audiohooks(chan)) {