Fri Jun 19 12:09:24 2009

Asterisk developer's documentation


abstract_jb.h

Go to the documentation of this file.
00001 /*
00002  * abstract_jb: common implementation-independent jitterbuffer stuff
00003  *
00004  * Copyright (C) 2005, Attractel OOD
00005  *
00006  * Contributors:
00007  * Slav Klenov <slav@securax.org>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  *
00019  * A license has been granted to Digium (via disclaimer) for the use of
00020  * this code.
00021  */
00022 
00023 /*! \file
00024  *
00025  * \brief Common implementation-independent jitterbuffer stuff.
00026  * 
00027  * \author Slav Klenov <slav@securax.org>
00028  */
00029 
00030 #ifndef _ABSTRACT_JB_H_
00031 #define _ABSTRACT_JB_H_
00032 
00033 #include <sys/time.h>
00034 
00035 #if defined(__cplusplus) || defined(c_plusplus)
00036 extern "C" {
00037 #endif
00038 
00039 struct ast_frame;
00040 
00041 /* Configuration flags */
00042 enum {
00043    AST_JB_ENABLED = (1 << 0),
00044    AST_JB_FORCED =  (1 << 1),
00045    AST_JB_LOG =     (1 << 2)
00046 };
00047 
00048 #define AST_JB_IMPL_NAME_SIZE 12
00049 
00050 /*!
00051  * \brief General jitterbuffer configuration.
00052  */
00053 struct ast_jb_conf
00054 {
00055    /*! \brief Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags. */
00056    unsigned int flags;
00057    /*! \brief Max size of the jitterbuffer implementation. */
00058    long max_size;
00059    /*! \brief Resynchronization threshold of the jitterbuffer implementation. */
00060    long resync_threshold;
00061    /*! \brief Name of the jitterbuffer implementation to be used. */
00062    char impl[AST_JB_IMPL_NAME_SIZE];
00063 };
00064 
00065 
00066 /* Jitterbuffer configuration property names */
00067 #define AST_JB_CONF_PREFIX "jb"
00068 #define AST_JB_CONF_ENABLE "enable"
00069 #define AST_JB_CONF_FORCE "force"
00070 #define AST_JB_CONF_MAX_SIZE "maxsize"
00071 #define AST_JB_CONF_RESYNCH_THRESHOLD "resyncthreshold"
00072 #define AST_JB_CONF_IMPL "impl"
00073 #define AST_JB_CONF_LOG "log"
00074 
00075 
00076 struct ast_jb_impl;
00077 
00078 
00079 /*!
00080  * \brief General jitterbuffer state.
00081  */
00082 struct ast_jb
00083 {
00084    /*! \brief Jitterbuffer configuration. */
00085    struct ast_jb_conf conf;
00086    /*! \brief Jitterbuffer implementation to be used. */
00087    struct ast_jb_impl *impl;
00088    /*! \brief Jitterbuffer object, passed to the implementation. */
00089    void *jbobj;
00090    /*! \brief The time the jitterbuffer was created. */
00091    struct timeval timebase;
00092    /*! \brief The time the next frame should be played. */
00093    long next;
00094    /*! \brief Voice format of the last frame in. */
00095    int last_format;
00096    /*! \brief File for frame timestamp tracing. */
00097    FILE *logfile;
00098    /*! \brief Jitterbuffer internal state flags. */
00099    unsigned int flags;
00100 };
00101 
00102 
00103 /*!
00104  * \brief Checks the need of a jb use in a generic bridge.
00105  * \param c0 first bridged channel.
00106  * \param c1 second bridged channel.
00107  *
00108  * Called from ast_generic_bridge() when two channels are entering in a bridge.
00109  * The function checks the need of a jitterbuffer, depending on both channel's
00110  * configuration and technology properties. As a result, this function sets
00111  * appropriate internal jb flags to the channels, determining further behaviour
00112  * of the bridged jitterbuffers.
00113  *
00114  * \retval zero if there are no jitter buffers in use
00115  * \retval non-zero if there are
00116  */
00117 int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1);
00118 
00119 
00120 /*!
00121  * \brief Calculates the time, left to the closest delivery moment in a bridge.
00122  * \param c0 first bridged channel.
00123  * \param c1 second bridged channel.
00124  * \param time_left bridge time limit, or -1 if not set.
00125  *
00126  * Called from ast_generic_bridge() to determine the maximum time to wait for
00127  * activity in ast_waitfor_n() call. If neihter of the channels is using jb,
00128  * this function returns the time limit passed.
00129  *
00130  * \return maximum time to wait.
00131  */
00132 int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left);
00133 
00134 
00135 /*!
00136  * \brief Puts a frame into a channel jitterbuffer.
00137  * \param chan channel.
00138  * \param f frame.
00139  *
00140  * Called from ast_generic_bridge() to put a frame into a channel's jitterbuffer.
00141  * The function will successfuly enqueue a frame if and only if:
00142  * 1. the channel is using a jitterbuffer (as determined by ast_jb_do_usecheck()),
00143  * 2. the frame's type is AST_FRAME_VOICE,
00144  * 3. the frame has timing info set and has length >= 2 ms,
00145  * 4. there is no some internal error happened (like failed memory allocation).
00146  * Frames, successfuly queued, should be delivered by the channel's jitterbuffer,
00147  * when their delivery time has came.
00148  * Frames, not successfuly queued, should be delivered immediately.
00149  * Dropped by the jb implementation frames are considered successfuly enqueued as
00150  * far as they should not be delivered at all.
00151  *
00152  * \retval 0 if the frame was queued
00153  * \retval -1 if not
00154  */
00155 int ast_jb_put(struct ast_channel *chan, struct ast_frame *f);
00156 
00157 
00158 /*!
00159  * \brief Deliver the queued frames that should be delivered now for both channels.
00160  * \param c0 first bridged channel.
00161  * \param c1 second bridged channel.
00162  *
00163  * Called from ast_generic_bridge() to deliver any frames, that should be delivered
00164  * for the moment of invocation. Does nothing if neihter of the channels is using jb
00165  * or has any frames currently queued in. The function delivers frames usig ast_write()
00166  * each of the channels.
00167  */
00168 void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1);
00169 
00170 
00171 /*!
00172  * \brief Destroys jitterbuffer on a channel.
00173  * \param chan channel.
00174  *
00175  * Called from ast_channel_free() when a channel is destroyed.
00176  */
00177 void ast_jb_destroy(struct ast_channel *chan);
00178 
00179 
00180 /*!
00181  * \brief Sets jitterbuffer configuration property.
00182  * \param conf configuration to store the property in.
00183  * \param varname property name.
00184  * \param value property value.
00185  *
00186  * Called from a channel driver to build a jitterbuffer configuration tipically when
00187  * reading a configuration file. It is not neccessary for a channel driver to know
00188  * each of the jb configuration property names. The jitterbuffer itself knows them.
00189  * The channel driver can pass each config var it reads through this function. It will
00190  * return 0 if the variable was consumed from the jb conf.
00191  *
00192  * \return zero if the property was set to the configuration, -1 if not.
00193  */
00194 int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value);
00195 
00196 
00197 /*!
00198  * \brief Configures a jitterbuffer on a channel.
00199  * \param chan channel to configure.
00200  * \param conf configuration to apply.
00201  *
00202  * Called from a channel driver when a channel is created and its jitterbuffer needs
00203  * to be configured.
00204  */
00205 void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf);
00206 
00207 
00208 /*!
00209  * \brief Copies a channel's jitterbuffer configuration.
00210  * \param chan channel.
00211  * \param conf destination.
00212  */
00213 void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf);
00214 
00215 /*!
00216  * \brief drops all frames from a jitterbuffer and resets it
00217  * \param c0 one channel of a bridge
00218  * \param c1 the other channel of the bridge
00219  */
00220 void ast_jb_empty_and_reset(struct ast_channel *c0, struct ast_channel *c1);
00221 
00222 #if defined(__cplusplus) || defined(c_plusplus)
00223 }
00224 #endif
00225 
00226 #endif /* _ABSTRACT_JB_H_ */

Generated on Fri Jun 19 12:09:24 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7