[asterisk-commits] file: branch file/ah r59238 - in /team/file/ah: include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Mar 26 15:48:04 MST 2007


Author: file
Date: Mon Mar 26 17:48:03 2007
New Revision: 59238

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59238
Log:
Add hooks for the manipulate type. Note that an audiohook does not have any reference to a "private" structure for this. It is up to the manipulator to find it's own way to store it (like datastores).

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

Modified: team/file/ah/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/file/ah/include/asterisk/audiohook.h?view=diff&rev=59238&r1=59237&r2=59238
==============================================================================
--- team/file/ah/include/asterisk/audiohook.h (original)
+++ team/file/ah/include/asterisk/audiohook.h Mon Mar 26 17:48:03 2007
@@ -54,18 +54,31 @@
 	AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0),
 };
 
+struct ast_audiohook;
+
+/*! \brief Callback function for manipulate audiohook type
+ * \param audiohook Audiohook structure
+ * \param chan Channel
+ * \param frame Frame of audio to manipulate
+ * \return Returns 0 on success, -1 on failure
+ * \note An audiohook does not have any reference to a private data structure for manipulate types. It is up to the manipulate callback to store this data
+ *       via it's own method. An example would be datastores.
+ */
+typedef int (*ast_audiohook_manipulate_callback)(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame);
+
 struct ast_audiohook {
-	ast_mutex_t lock;                     /*!< Lock that protects the audiohook structure */
-	ast_cond_t trigger;                   /*!< Trigger condition (if enabled) */
-	enum ast_audiohook_type type;         /*!< Type of audiohook */
-	enum ast_audiohook_status status;     /*!< Status of the audiohook */
-	const char *source;                   /*!< Who this audiohook ultimately belongs to */
-	unsigned int flags;                   /*!< Flags on the audiohook */
-	struct ast_slinfactory read_factory;  /*!< Factory where frames read from the channel, or read from the whisper source will go through */
-	struct ast_slinfactory write_factory; /*!< Factory where frames written to the channel will go through */
-	int format;                           /*!< Format translation path is setup as */
-	struct ast_trans_pvt *trans_pvt;      /*!< Translation path for reading frames */
-	AST_LIST_ENTRY(ast_audiohook) list;   /*!< Linked list information */
+	ast_mutex_t lock;                                      /*!< Lock that protects the audiohook structure */
+	ast_cond_t trigger;                                    /*!< Trigger condition (if enabled) */
+	enum ast_audiohook_type type;                          /*!< Type of audiohook */
+	enum ast_audiohook_status status;                      /*!< Status of the audiohook */
+	const char *source;                                    /*!< Who this audiohook ultimately belongs to */
+	unsigned int flags;                                    /*!< Flags on the audiohook */
+	struct ast_slinfactory read_factory;                   /*!< Factory where frames read from the channel, or read from the whisper source will go through */
+	struct ast_slinfactory write_factory;                  /*!< Factory where frames written to the channel will go through */
+	int format;                                            /*!< Format translation path is setup as */
+	struct ast_trans_pvt *trans_pvt;                       /*!< Translation path for reading frames */
+	ast_audiohook_manipulate_callback manipulate_callback; /*!< Manipulation callback */
+	AST_LIST_ENTRY(ast_audiohook) list;                    /*!< Linked list information */
 };
 
 struct ast_audiohook_list;
@@ -121,12 +134,13 @@
 int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list);
 
 /*! \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
  * \param direction Direction frame is coming in from
  * \param frame The frame itself
  * \return Return frame on success, NULL on failure
  */
-struct ast_frame *ast_audiohook_write_list(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame);
+struct ast_frame *ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame);
 
 /*! \brief Wait for audiohook trigger to be triggered
  * \param audiohook Audiohook to wait on

Modified: team/file/ah/main/audiohook.c
URL: http://svn.digium.com/view/asterisk/team/file/ah/main/audiohook.c?view=diff&rev=59238&r1=59237&r2=59238
==============================================================================
--- team/file/ah/main/audiohook.c (original)
+++ team/file/ah/main/audiohook.c Mon Mar 26 17:48:03 2007
@@ -356,12 +356,13 @@
 }
 
 /*! \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
  * \param direction Direction frame is coming in from
  * \param frame The frame itself
  * \return Return frame on success, NULL on failure
  */
-struct ast_frame *ast_audiohook_write_list(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
+struct ast_frame *ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
 {
 	struct ast_audiohook_translate *in_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->in_translate[0] : &audiohook_list->in_translate[1]);
 	struct ast_audiohook_translate *out_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->out_translate[0] : &audiohook_list->out_translate[1]);
@@ -432,10 +433,13 @@
 			if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
 				AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
 				audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
-				ast_cond_signal(&audiohook->trigger);
 				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);
 				continue;
 			}
+			/* Feed in frame to manipulation */
+			audiohook->manipulate_callback(audiohook, chan, middle_frame);
 			ast_audiohook_unlock(audiohook);
 		}
 		AST_LIST_TRAVERSE_SAFE_END

Modified: team/file/ah/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/ah/main/channel.c?view=diff&rev=59238&r1=59237&r2=59238
==============================================================================
--- team/file/ah/main/channel.c (original)
+++ team/file/ah/main/channel.c Mon Mar 26 17:48:03 2007
@@ -1916,7 +1916,7 @@
 			} else {
 				/* Send frame to audiohooks if present */
 				if (chan->audiohooks)
-					f = ast_audiohook_write_list(chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
+					f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
 				if (chan->monitor && chan->monitor->read_stream ) {
 					/* XXX what does this do ? */
 #ifndef MONITOR_CONSTANT_DELAY
@@ -2308,7 +2308,7 @@
 
 		/* If audiohooks are present, write the frame out */
 		if (chan->audiohooks)
-			fr = ast_audiohook_write_list(chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
+			fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
 		
 		/* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
 		if (fr->subclass == chan->rawwriteformat)



More information about the asterisk-commits mailing list