2 * abstract_jb: common implementation-independent jitterbuffer stuff
4 * Copyright (C) 2005, Attractel OOD
7 * Slav Klenov <slav@securax.org>
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
19 * A license has been granted to Digium (via disclaimer) for the use of
25 * \brief Common implementation-independent jitterbuffer stuff.
27 * \author Slav Klenov <slav@securax.org>
30 #ifndef _ABSTRACT_JB_H_
31 #define _ABSTRACT_JB_H_
36 #if defined(__cplusplus) || defined(c_plusplus)
44 /* Configuration flags */
46 AST_JB_ENABLED = (1 << 0),
47 AST_JB_FORCED = (1 << 1),
51 #define AST_JB_IMPL_NAME_SIZE 12
54 * \brief General jitterbuffer configuration.
58 /*! \brief Combination of the AST_JB_ENABLED, AST_JB_FORCED and AST_JB_LOG flags. */
60 /*! \brief Max size of the jitterbuffer implementation. */
62 /*! \brief Resynchronization threshold of the jitterbuffer implementation. */
63 long resync_threshold;
64 /*! \brief Name of the jitterbuffer implementation to be used. */
65 char impl[AST_JB_IMPL_NAME_SIZE];
69 /* Jitterbuffer configuration property names */
70 #define AST_JB_CONF_PREFIX "jb"
71 #define AST_JB_CONF_ENABLE "enable"
72 #define AST_JB_CONF_FORCE "force"
73 #define AST_JB_CONF_MAX_SIZE "maxsize"
74 #define AST_JB_CONF_RESYNCH_THRESHOLD "resyncthreshold"
75 #define AST_JB_CONF_IMPL "impl"
76 #define AST_JB_CONF_LOG "log"
83 * \brief General jitterbuffer state.
87 /*! \brief Jitterbuffer configuration. */
88 struct ast_jb_conf conf;
89 /*! \brief Jitterbuffer implementation to be used. */
90 struct ast_jb_impl *impl;
91 /*! \brief Jitterbuffer object, passed to the implementation. */
93 /*! \brief The time the jitterbuffer was created. */
94 struct timeval timebase;
95 /*! \brief The time the next frame should be played. */
97 /*! \brief Voice format of the last frame in. */
99 /*! \brief File for frame timestamp tracing. */
101 /*! \brief Jitterbuffer internal state flags. */
107 * \brief Checks the need of a jb use in a generic bridge.
108 * \param c0 first bridged channel.
109 * \param c1 second bridged channel.
111 * Called from ast_generic_bridge() when two channels are entering in a bridge.
112 * The function checks the need of a jitterbuffer, depending on both channel's
113 * configuration and technology properties. As a result, this function sets
114 * appropriate internal jb flags to the channels, determining further behaviour
115 * of the bridged jitterbuffers.
117 * \return zero if there are no jitter buffers in use, non-zero if there are
119 int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1);
123 * \brief Calculates the time, left to the closest delivery moment in a bridge.
124 * \param c0 first bridged channel.
125 * \param c1 second bridged channel.
126 * \param time_left bridge time limit, or -1 if not set.
128 * Called from ast_generic_bridge() to determine the maximum time to wait for
129 * activity in ast_waitfor_n() call. If neihter of the channels is using jb,
130 * this function returns the time limit passed.
132 * \return maximum time to wait.
134 int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left);
138 * \brief Puts a frame into a channel jitterbuffer.
139 * \param chan channel.
142 * Called from ast_generic_bridge() to put a frame into a channel's jitterbuffer.
143 * The function will successfuly enqueue a frame if and only if:
144 * 1. the channel is using a jitterbuffer (as determined by ast_jb_do_usecheck()),
145 * 2. the frame's type is AST_FRAME_VOICE,
146 * 3. the frame has timing info set and has length >= 2 ms,
147 * 4. there is no some internal error happened (like failed memory allocation).
148 * Frames, successfuly queued, should be delivered by the channel's jitterbuffer,
149 * when their delivery time has came.
150 * Frames, not successfuly queued, should be delivered immediately.
151 * Dropped by the jb implementation frames are considered successfuly enqueued as
152 * far as they should not be delivered at all.
154 * \return zero if the frame was queued, -1 if not.
156 int ast_jb_put(struct ast_channel *chan, struct ast_frame *f);
160 * \brief Deliver the queued frames that should be delivered now for both channels.
161 * \param c0 first bridged channel.
162 * \param c1 second bridged channel.
164 * Called from ast_generic_bridge() to deliver any frames, that should be delivered
165 * for the moment of invocation. Does nothing if neihter of the channels is using jb
166 * or has any frames currently queued in. The function delivers frames usig ast_write()
167 * each of the channels.
169 void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1);
173 * \brief Destroys jitterbuffer on a channel.
174 * \param chan channel.
176 * Called from ast_channel_free() when a channel is destroyed.
178 void ast_jb_destroy(struct ast_channel *chan);
182 * \brief Sets jitterbuffer configuration property.
183 * \param conf configuration to store the property in.
184 * \param varname property name.
185 * \param value property value.
187 * Called from a channel driver to build a jitterbuffer configuration tipically when
188 * reading a configuration file. It is not neccessary for a channel driver to know
189 * each of the jb configuration property names. The jitterbuffer itself knows them.
190 * The channel driver can pass each config var it reads through this function. It will
191 * return 0 if the variable was consumed from the jb conf.
193 * \return zero if the property was set to the configuration, -1 if not.
195 int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value);
199 * \brief Configures a jitterbuffer on a channel.
200 * \param chan channel to configure.
201 * \param conf configuration to apply.
203 * Called from a channel driver when a channel is created and its jitterbuffer needs
206 void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf);
210 * \brief Copies a channel's jitterbuffer configuration.
211 * \param chan channel.
212 * \param conf destination.
214 void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf);
217 #if defined(__cplusplus) || defined(c_plusplus)
221 #endif /* _ABSTRACT_JB_H_ */