Properly play a holdtime message if the announce-holdtime option is
[asterisk-bristuff.git] / include / asterisk / audiohook.h
blob5f79d83b0e53a7d86f0d2e1a09869d25ce20dd73
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2007, Digium, Inc.
6 * Joshua Colp <jcolp@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
20 * \brief Audiohooks Architecture
23 #ifndef _ASTERISK_AUDIOHOOK_H
24 #define _ASTERISK_AUDIOHOOK_H
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
30 #include "asterisk/slinfactory.h"
32 enum ast_audiohook_type {
33 AST_AUDIOHOOK_TYPE_SPY = 0, /*!< Audiohook wants to receive audio */
34 AST_AUDIOHOOK_TYPE_WHISPER, /*!< Audiohook wants to provide audio to be mixed with existing audio */
35 AST_AUDIOHOOK_TYPE_MANIPULATE, /*!< Audiohook wants to manipulate the audio */
38 enum ast_audiohook_status {
39 AST_AUDIOHOOK_STATUS_NEW = 0, /*!< Audiohook was just created, not in use yet */
40 AST_AUDIOHOOK_STATUS_RUNNING, /*!< Audiohook is running on a channel */
41 AST_AUDIOHOOK_STATUS_SHUTDOWN, /*!< Audiohook is being shutdown */
42 AST_AUDIOHOOK_STATUS_DONE, /*!< Audiohook has shutdown and is not running on a channel any longer */
45 enum ast_audiohook_direction {
46 AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
47 AST_AUDIOHOOK_DIRECTION_WRITE, /*!< Writing audio out */
48 AST_AUDIOHOOK_DIRECTION_BOTH, /*!< Both reading audio in and writing audio out */
51 enum ast_audiohook_flags {
52 AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0), /*!< When audiohook should be triggered to do something */
53 AST_AUDIOHOOK_TRIGGER_READ = (1 << 0), /*!< Audiohook wants to be triggered when reading audio in */
54 AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
55 AST_AUDIOHOOK_WANTS_DTMF = (1 << 1), /*!< Audiohook also wants to receive DTMF frames */
56 AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 2), /*!< Audiohook wants to be triggered when both sides have combined audio available */
59 struct ast_audiohook;
61 /*! \brief Callback function for manipulate audiohook type
62 * \param audiohook Audiohook structure
63 * \param chan Channel
64 * \param frame Frame of audio to manipulate
65 * \param direction Direction frame came from
66 * \return Returns 0 on success, -1 on failure
67 * \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
68 * via it's own method. An example would be datastores.
70 typedef int (*ast_audiohook_manipulate_callback)(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction);
72 struct ast_audiohook_options {
73 int read_volume; /*!< Volume adjustment on frames read from the channel the hook is on */
74 int write_volume; /*!< Volume adjustment on frames written to the channel the hook is on */
77 struct ast_audiohook {
78 ast_mutex_t lock; /*!< Lock that protects the audiohook structure */
79 ast_cond_t trigger; /*!< Trigger condition (if enabled) */
80 enum ast_audiohook_type type; /*!< Type of audiohook */
81 enum ast_audiohook_status status; /*!< Status of the audiohook */
82 const char *source; /*!< Who this audiohook ultimately belongs to */
83 unsigned int flags; /*!< Flags on the audiohook */
84 struct ast_slinfactory read_factory; /*!< Factory where frames read from the channel, or read from the whisper source will go through */
85 struct ast_slinfactory write_factory; /*!< Factory where frames written to the channel will go through */
86 struct timeval read_time; /*!< Last time read factory was fed */
87 struct timeval write_time; /*!< Last time write factory was fed */
88 int format; /*!< Format translation path is setup as */
89 struct ast_trans_pvt *trans_pvt; /*!< Translation path for reading frames */
90 ast_audiohook_manipulate_callback manipulate_callback; /*!< Manipulation callback */
91 struct ast_audiohook_options options; /*!< Applicable options */
92 AST_LIST_ENTRY(ast_audiohook) list; /*!< Linked list information */
95 struct ast_audiohook_list;
97 /*! \brief Initialize an audiohook structure
98 * \param audiohook Audiohook structure
99 * \param type Type of audiohook to initialize this as
100 * \param source Who is initializing this audiohook
101 * \return Returns 0 on success, -1 on failure
103 int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source);
105 /*! \brief Destroys an audiohook structure
106 * \param audiohook Audiohook structure
107 * \return Returns 0 on success, -1 on failure
109 int ast_audiohook_destroy(struct ast_audiohook *audiohook);
111 /*! \brief Writes a frame into the audiohook structure
112 * \param audiohook Audiohook structure
113 * \param direction Direction the audio frame came from
114 * \param frame Frame to write in
115 * \return Returns 0 on success, -1 on failure
117 int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame);
119 /*! \brief Reads a frame in from the audiohook structure
120 * \param audiohook Audiohook structure
121 * \param samples Number of samples wanted
122 * \param direction Direction the audio frame came from
123 * \param format Format of frame remote side wants back
124 * \return Returns frame on success, NULL on failure
126 struct ast_frame *ast_audiohook_read_frame(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, int format);
128 /*! \brief Attach audiohook to channel
129 * \param chan Channel
130 * \param audiohook Audiohook structure
131 * \return Returns 0 on success, -1 on failure
133 int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook);
135 /*! \brief Detach audiohook from channel
136 * \param audiohook Audiohook structure
137 * \return Returns 0 on success, -1 on failure
139 int ast_audiohook_detach(struct ast_audiohook *audiohook);
141 /*! \brief Detach audiohooks from list and destroy said list
142 * \param audiohook_list List of audiohooks
143 * \return Returns 0 on success, -1 on failure
145 int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list);
147 /*! \brief Detach specified source audiohook from channel
148 * \param chan Channel to detach from
149 * \param source Name of source to detach
150 * \return Returns 0 on success, -1 on failure
152 int ast_audiohook_detach_source(struct ast_channel *chan, const char *source);
154 /*! \brief Pass a frame off to be handled by the audiohook core
155 * \param chan Channel that the list is coming off of
156 * \param audiohook_list List of audiohooks
157 * \param direction Direction frame is coming in from
158 * \param frame The frame itself
159 * \return Return frame on success, NULL on failure
161 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);
163 /*! \brief Wait for audiohook trigger to be triggered
164 * \param audiohook Audiohook to wait on
166 void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook);
168 /*! \brief Lock an audiohook
169 * \param ah Audiohook structure
171 #define ast_audiohook_lock(ah) ast_mutex_lock(&(ah)->lock)
173 /*! \brief Unlock an audiohook
174 * \param ah Audiohook structure
176 #define ast_audiohook_unlock(ah) ast_mutex_unlock(&(ah)->lock)
178 #if defined(__cplusplus) || defined(c_plusplus)
180 #endif
182 #endif /* _ASTERISK_AUDIOHOOK_H */