[asterisk-commits] file: branch file/audiohooks r78558 - in /team/file/audiohooks: include/aster...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 7 18:56:58 CDT 2007


Author: file
Date: Tue Aug  7 18:56:58 2007
New Revision: 78558

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78558
Log:
Add ability to stop an audiohook based on the source name.

Modified:
    team/file/audiohooks/include/asterisk/audiohook.h
    team/file/audiohooks/main/audiohook.c

Modified: team/file/audiohooks/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/file/audiohooks/include/asterisk/audiohook.h?view=diff&rev=78558&r1=78557&r2=78558
==============================================================================
--- team/file/audiohooks/include/asterisk/audiohook.h (original)
+++ team/file/audiohooks/include/asterisk/audiohook.h Tue Aug  7 18:56:58 2007
@@ -141,6 +141,13 @@
  */
 int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list);
 
+/*! \brief Detach specified source audiohook from channel
+ * \param chan Channel to detach from
+ * \param source Name of source to detach
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_audiohook_detach_source(struct ast_channel *chan, const char *source);
+
 /*! \brief Pass a frame off to be handled by the audiohook core
  * \param chan Channel that the list is coming off of
  * \param audiohook_list List of audiohooks

Modified: team/file/audiohooks/main/audiohook.c
URL: http://svn.digium.com/view/asterisk/team/file/audiohooks/main/audiohook.c?view=diff&rev=78558&r1=78557&r2=78558
==============================================================================
--- team/file/audiohooks/main/audiohook.c (original)
+++ team/file/audiohooks/main/audiohook.c Tue Aug  7 18:56:58 2007
@@ -64,8 +64,9 @@
  */
 int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source)
 {
-	/* Need to keep the type */
+	/* Need to keep the type and source */
 	audiohook->type = type;
+	audiohook->source = source;
 
 	/* Initialize lock that protects our audiohook */
 	ast_mutex_init(&audiohook->lock);
@@ -383,6 +384,58 @@
 	free(audiohook_list);
 
 	return 0;
+}
+
+static struct ast_audiohook *find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
+{
+	struct ast_audiohook *audiohook = NULL;
+
+	AST_LIST_TRAVERSE(&audiohook_list->spy_list, audiohook, list) {
+		if (!strcasecmp(audiohook->source, source))
+			return audiohook;
+	}
+
+	AST_LIST_TRAVERSE(&audiohook_list->whisper_list, audiohook, list) {
+		if (!strcasecmp(audiohook->source, source))
+			return audiohook;
+	}
+
+	AST_LIST_TRAVERSE(&audiohook_list->manipulate_list, audiohook, list) {
+		if (!strcasecmp(audiohook->source, source))
+			return audiohook;
+	}
+
+	return NULL;
+}
+
+/*! \brief Detach specified source audiohook from channel
+ * \param chan Channel to detach from
+ * \param source Name of source to detach
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_audiohook_detach_source(struct ast_channel *chan, const char *source)
+{
+	struct ast_audiohook *audiohook = NULL;
+
+	ast_channel_lock(chan);
+
+	/* Ensure the channel has audiohooks on it */
+	if (!chan->audiohooks) {
+		ast_channel_unlock(chan);
+		return -1;
+	}
+
+	audiohook = find_audiohook_by_source(chan->audiohooks, source);
+
+	ast_channel_unlock(chan);
+
+	if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
+		audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
+		while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
+			ast_audiohook_trigger_wait(audiohook);
+	}
+
+	return (audiohook ? 0 : -1);
 }
 
 /*! \brief Pass a DTMF frame off to be handled by the audiohook core




More information about the asterisk-commits mailing list