Sat Mar 24 23:26:04 2007

Asterisk developer's documentation


chanspy.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Asterisk PBX channel spy definitions
00021  */
00022 
00023 #ifndef _ASTERISK_CHANSPY_H
00024 #define _ASTERISK_CHANSPY_H
00025 
00026 #if defined(__cplusplus) || defined(c_plusplus)
00027 extern "C" {
00028 #endif
00029 
00030 #include "asterisk/linkedlists.h"
00031 
00032 enum chanspy_states {
00033    CHANSPY_NEW = 0,     /*!< spy not yet operating */
00034    CHANSPY_RUNNING = 1,    /*!< normal operation, spy is still operating */
00035    CHANSPY_DONE = 2,    /*!< spy is stopped and already removed from channel */
00036    CHANSPY_STOP = 3,    /*!< spy requested to stop, still attached to channel */
00037 };
00038 
00039 enum chanspy_flags {
00040    CHANSPY_MIXAUDIO = (1 << 0),
00041    CHANSPY_READ_VOLADJUST = (1 << 1),
00042    CHANSPY_WRITE_VOLADJUST = (1 << 2),
00043    CHANSPY_FORMAT_AUDIO = (1 << 3),
00044    CHANSPY_TRIGGER_MODE = (3 << 4),
00045    CHANSPY_TRIGGER_READ = (1 << 4),
00046    CHANSPY_TRIGGER_WRITE = (2 << 4),
00047    CHANSPY_TRIGGER_NONE = (3 << 4),
00048    CHANSPY_TRIGGER_FLUSH = (1 << 6),
00049 };
00050 
00051 struct ast_channel_spy_queue {
00052    struct ast_frame *head;
00053    unsigned int samples;
00054    unsigned int format;
00055 };
00056 
00057 struct ast_channel_spy {
00058    AST_LIST_ENTRY(ast_channel_spy) list;
00059    ast_mutex_t lock;
00060    ast_cond_t trigger;
00061    struct ast_channel_spy_queue read_queue;
00062    struct ast_channel_spy_queue write_queue;
00063    unsigned int flags;
00064    enum chanspy_states status;
00065    const char *type;
00066    /* The volume adjustment values are very straightforward:
00067       positive values cause the samples to be multiplied by that amount
00068       negative values cause the samples to be divided by the absolute value of that amount
00069    */
00070    int read_vol_adjustment;
00071    int write_vol_adjustment;
00072 };
00073 
00074 /*!
00075   \brief Adds a spy to a channel, to begin receiving copies of the channel's audio frames.
00076   \param chan The channel to add the spy to.
00077   \param spy A pointer to ast_channel_spy structure describing how the spy is to be used.
00078   \return 0 for success, non-zero for failure
00079 
00080   Note: This function performs no locking; you must hold the channel's lock before
00081   calling this function.
00082  */
00083 int ast_channel_spy_add(struct ast_channel *chan, struct ast_channel_spy *spy);
00084 
00085 /*!
00086   \brief Remove a spy from a channel.
00087   \param chan The channel to remove the spy from
00088   \param spy The spy to be removed
00089   \return nothing
00090 
00091   Note: This function performs no locking; you must hold the channel's lock before
00092   calling this function.
00093  */
00094 void ast_channel_spy_remove(struct ast_channel *chan, struct ast_channel_spy *spy);
00095 
00096 /*!
00097   \brief Find all spies of a particular type on a channel and stop them.
00098   \param chan The channel to operate on
00099   \param type A character string identifying the type of spies to be stopped
00100   \return nothing
00101 
00102   Note: This function performs no locking; you must hold the channel's lock before
00103   calling this function.
00104  */
00105 void ast_channel_spy_stop_by_type(struct ast_channel *chan, const char *type);
00106 
00107 /*!
00108   \brief Read one (or more) frames of audio from a channel being spied upon.
00109   \param spy The spy to operate on
00110   \param samples The number of audio samples to read
00111   \return NULL for failure, one ast_frame pointer, or a chain of ast_frame pointers
00112 
00113   This function can return multiple frames if the spy structure needs to be 'flushed'
00114   due to mismatched queue lengths, or if the spy structure is configured to return
00115   unmixed audio (in which case each call to this function will return a frame of audio
00116   from each side of channel).
00117 
00118   Note: This function performs no locking; you must hold the spy's lock before calling
00119   this function. You must <b>not</b> hold the channel's lock at the same time.
00120  */
00121 struct ast_frame *ast_channel_spy_read_frame(struct ast_channel_spy *spy, unsigned int samples);
00122 
00123 /*!
00124   \brief Efficiently wait until audio is available for a spy, or an exception occurs.
00125   \param spy The spy to wait on
00126   \return nothing
00127 
00128   Note: The locking rules for this function are non-obvious... first, you must <b>not</b>
00129   hold the channel's lock when calling this function. Second, you must hold the spy's lock
00130   before making the function call; while the function runs the lock will be released, and
00131   when the trigger event occurs, the lock will be re-obtained. This means that when control
00132   returns to your code, you will again hold the spy's lock.
00133  */
00134 void ast_channel_spy_trigger_wait(struct ast_channel_spy *spy);
00135 
00136 #if defined(__cplusplus) || defined(c_plusplus)
00137 }
00138 #endif
00139 
00140 #endif /* _ASTERISK_CHANSPY_H */

Generated on Sat Mar 24 23:26:04 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6