Thu Oct 11 06:42:07 2012

Asterisk developer's documentation


frame.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 internal frame definitions.
00021  * \arg For an explanation of frames, see \ref Def_Frame
00022  * \arg Frames are send of Asterisk channels, see \ref Def_Channel
00023  */
00024 
00025 #ifndef _ASTERISK_FRAME_H
00026 #define _ASTERISK_FRAME_H
00027 
00028 #if defined(__cplusplus) || defined(c_plusplus)
00029 extern "C" {
00030 #endif
00031 
00032 #include <sys/types.h>
00033 #include <sys/time.h>
00034 
00035 #include "asterisk/compiler.h"
00036 #include "asterisk/endian.h"
00037 #include "asterisk/linkedlists.h"
00038 
00039 struct ast_codec_pref {
00040    char order[32];
00041    char framing[32];
00042 };
00043 
00044 /*! \page Def_Frame AST Multimedia and signalling frames
00045    \section Def_AstFrame What is an ast_frame ?
00046    A frame of data read used to communicate between 
00047    between channels and applications.
00048    Frames are divided into frame types and subclasses.
00049 
00050    \par Frame types 
00051    \arg \b VOICE: Voice data, subclass is codec (AST_FORMAT_*)
00052    \arg \b VIDEO: Video data, subclass is codec (AST_FORMAT_*)
00053    \arg \b DTMF:  A DTMF digit, subclass is the digit
00054    \arg \b IMAGE: Image transport, mostly used in IAX
00055    \arg \b TEXT:  Text messages
00056    \arg \b HTML:  URL's and web pages
00057    \arg \b MODEM: Modulated data encodings, such as T.38 and V.150
00058    \arg \b IAX:   Private frame type for the IAX protocol
00059    \arg \b CNG:   Comfort noice frames
00060    \arg \b CONTROL:  A control frame, subclass defined as AST_CONTROL_
00061    \arg \b NULL:  Empty, useless frame
00062 
00063    \par Files
00064    \arg frame.h   Definitions
00065    \arg frame.c   Function library
00066    \arg \ref Def_Channel Asterisk channels
00067    \section Def_ControlFrame Control Frames
00068    Control frames send signalling information between channels
00069    and devices. They are prefixed with AST_CONTROL_, like AST_CONTROL_FRAME_HANGUP
00070    \arg \b HANGUP The other end has hungup
00071    \arg \b RING   Local ring
00072    \arg \b RINGING   The other end is ringing
00073    \arg \b ANSWER The other end has answered
00074    \arg \b BUSY   Remote end is busy
00075    \arg \b TAKEOFFHOOK  Make it go off hook (what's "it" ? )
00076    \arg \b OFFHOOK   Line is off hook
00077    \arg \b CONGESTION   Congestion (circuit is busy, not available)
00078    \arg \b FLASH  Other end sends flash hook
00079    \arg \b WINK   Other end sends wink
00080    \arg \b OPTION Send low-level option
00081    \arg \b RADIO_KEY Key radio (see app_rpt.c)
00082    \arg \b RADIO_UNKEY  Un-key radio (see app_rpt.c)
00083    \arg \b PROGRESS  Other end indicates call progress
00084    \arg \b PROCEEDING   Indicates proceeding
00085    \arg \b HOLD   Call is placed on hold
00086    \arg \b UNHOLD Call is back from hold
00087    \arg \b VIDUPDATE Video update requested
00088    \arg \b SRCUPDATE The source of media has changed (RTP marker bit must change)
00089    \arg \b SRCCHANGE Media source has changed (RTP marker bit and SSRC must change)
00090 
00091 */
00092 
00093 /*!
00094  * \brief Frame types 
00095  *
00096  * \note It is important that the values of each frame type are never changed,
00097  *       because it will break backwards compatability with older versions.
00098  */
00099 enum ast_frame_type {
00100    /*! DTMF end event, subclass is the digit */
00101    AST_FRAME_DTMF_END = 1,
00102    /*! Voice data, subclass is AST_FORMAT_* */
00103    AST_FRAME_VOICE,
00104    /*! Video frame, maybe?? :) */
00105    AST_FRAME_VIDEO,
00106    /*! A control frame, subclass is AST_CONTROL_* */
00107    AST_FRAME_CONTROL,
00108    /*! An empty, useless frame */
00109    AST_FRAME_NULL,
00110    /*! Inter Asterisk Exchange private frame type */
00111    AST_FRAME_IAX,
00112    /*! Text messages */
00113    AST_FRAME_TEXT,
00114    /*! Image Frames */
00115    AST_FRAME_IMAGE,
00116    /*! HTML Frame */
00117    AST_FRAME_HTML,
00118    /*! Comfort Noise frame (subclass is level of CNG in -dBov), 
00119        body may include zero or more 8-bit quantization coefficients */
00120    AST_FRAME_CNG,
00121    /*! Modem-over-IP data streams */
00122    AST_FRAME_MODEM,  
00123    /*! DTMF begin event, subclass is the digit */
00124    AST_FRAME_DTMF_BEGIN,
00125 };
00126 #define AST_FRAME_DTMF AST_FRAME_DTMF_END
00127 
00128 enum {
00129    /*! This frame contains valid timing information */
00130    AST_FRFLAG_HAS_TIMING_INFO = (1 << 0),
00131 };
00132 
00133 /*! \brief Data structure associated with a single frame of data
00134  */
00135 struct ast_frame {
00136    /*! Kind of frame */
00137    enum ast_frame_type frametype;            
00138    /*! Subclass, frame dependent */
00139    int subclass;           
00140    /*! Length of data */
00141    int datalen;            
00142    /*! Number of samples in this frame */
00143    int samples;            
00144    /*! Was the data malloc'd?  i.e. should we free it when we discard the frame? */
00145    int mallocd;            
00146    /*! The number of bytes allocated for a malloc'd frame header */
00147    size_t mallocd_hdr_len;
00148    /*! How many bytes exist _before_ "data" that can be used if needed */
00149    int offset;          
00150    /*! Optional source of frame for debugging */
00151    const char *src;           
00152    /*! Pointer to actual data */
00153    void *data;    
00154    /*! Global delivery time */      
00155    struct timeval delivery;
00156    /*! For placing in a linked list */
00157    AST_LIST_ENTRY(ast_frame) frame_list;
00158    /*! Misc. frame flags */
00159    unsigned int flags;
00160    /*! Timestamp in milliseconds */
00161    long ts;
00162    /*! Length in milliseconds */
00163    long len;
00164    /*! Sequence number */
00165    int seqno;
00166 };
00167 
00168 /*!
00169  * Set the various field of a frame to point to a buffer.
00170  * Typically you set the base address of the buffer, the offset as
00171  * AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued.
00172  * The remaining things (to be done manually) is set the number of
00173  * samples, which cannot be derived from the datalen unless you know
00174  * the number of bits per sample.
00175  */
00176 #define  AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen) \
00177    {              \
00178    (fr)->data = (char *)_base + (_ofs);   \
00179    (fr)->offset = (_ofs);        \
00180    (fr)->datalen = (_datalen);      \
00181    }
00182 
00183 /*! Queueing a null frame is fairly common, so we declare a global null frame object
00184     for this purpose instead of having to declare one on the stack */
00185 extern struct ast_frame ast_null_frame;
00186 
00187 #define AST_FRIENDLY_OFFSET   64 /*! It's polite for a a new frame to
00188                  have this number of bytes for additional
00189                  headers.  */
00190 #define AST_MIN_OFFSET     32 /*! Make sure we keep at least this much handy */
00191 
00192 /*! Need the header be free'd? */
00193 #define AST_MALLOCD_HDR    (1 << 0)
00194 /*! Need the data be free'd? */
00195 #define AST_MALLOCD_DATA   (1 << 1)
00196 /*! Need the source be free'd? (haha!) */
00197 #define AST_MALLOCD_SRC    (1 << 2)
00198 
00199 /* MODEM subclasses */
00200 /*! T.38 Fax-over-IP */
00201 #define AST_MODEM_T38      1
00202 /*! V.150 Modem-over-IP */
00203 #define AST_MODEM_V150     2
00204 
00205 /* HTML subclasses */
00206 /*! Sending a URL */
00207 #define AST_HTML_URL    1
00208 /*! Data frame */
00209 #define AST_HTML_DATA      2
00210 /*! Beginning frame */
00211 #define AST_HTML_BEGIN     4
00212 /*! End frame */
00213 #define AST_HTML_END    8
00214 /*! Load is complete */
00215 #define AST_HTML_LDCOMPLETE   16
00216 /*! Peer is unable to support HTML */
00217 #define AST_HTML_NOSUPPORT 17
00218 /*! Send URL, and track */
00219 #define AST_HTML_LINKURL   18
00220 /*! No more HTML linkage */
00221 #define AST_HTML_UNLINK    19
00222 /*! Reject link request */
00223 #define AST_HTML_LINKREJECT   20
00224 
00225 /* Data formats for capabilities and frames alike */
00226 /*! G.723.1 compression */
00227 #define AST_FORMAT_G723_1  (1 << 0)
00228 /*! GSM compression */
00229 #define AST_FORMAT_GSM     (1 << 1)
00230 /*! Raw mu-law data (G.711) */
00231 #define AST_FORMAT_ULAW    (1 << 2)
00232 /*! Raw A-law data (G.711) */
00233 #define AST_FORMAT_ALAW    (1 << 3)
00234 /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
00235 #define AST_FORMAT_G726_AAL2  (1 << 4)
00236 /*! ADPCM (IMA) */
00237 #define AST_FORMAT_ADPCM   (1 << 5)
00238 /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
00239 #define AST_FORMAT_SLINEAR (1 << 6)
00240 /*! LPC10, 180 samples/frame */
00241 #define AST_FORMAT_LPC10   (1 << 7)
00242 /*! G.729A audio */
00243 #define AST_FORMAT_G729A   (1 << 8)
00244 /*! SpeeX Free Compression */
00245 #define AST_FORMAT_SPEEX   (1 << 9)
00246 /*! iLBC Free Compression */
00247 #define AST_FORMAT_ILBC    (1 << 10)
00248 /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
00249 #define AST_FORMAT_G726    (1 << 11)
00250 /*! G.722 */
00251 #define AST_FORMAT_G722    (1 << 12)
00252 /*! Unsupported audio bits */
00253 #define AST_FORMAT_AUDIO_UNDEFINED  ((1 << 13) | (1 << 14) | (1 << 15))
00254 /*! Maximum audio format */
00255 #define AST_FORMAT_MAX_AUDIO  (1 << 15)
00256 /*! Maximum audio mask */
00257 #define AST_FORMAT_AUDIO_MASK   ((1 << 16)-1)
00258 /*! JPEG Images */
00259 #define AST_FORMAT_JPEG    (1 << 16)
00260 /*! PNG Images */
00261 #define AST_FORMAT_PNG     (1 << 17)
00262 /*! H.261 Video */
00263 #define AST_FORMAT_H261    (1 << 18)
00264 /*! H.263 Video */
00265 #define AST_FORMAT_H263    (1 << 19)
00266 /*! H.263+ Video */
00267 #define AST_FORMAT_H263_PLUS  (1 << 20)
00268 /*! H.264 Video */
00269 #define AST_FORMAT_H264    (1 << 21)
00270 /*! Maximum video format */
00271 #define AST_FORMAT_MAX_VIDEO  (1 << 24)
00272 #define AST_FORMAT_VIDEO_MASK   (((1 << 25)-1) & ~(AST_FORMAT_AUDIO_MASK))
00273 
00274 enum ast_control_frame_type {
00275    AST_CONTROL_HANGUP = 1,    /*!< Other end has hungup */
00276    AST_CONTROL_RING = 2,      /*!< Local ring */
00277    AST_CONTROL_RINGING = 3,   /*!< Remote end is ringing */
00278    AST_CONTROL_ANSWER = 4,    /*!< Remote end has answered */
00279    AST_CONTROL_BUSY = 5,      /*!< Remote end is busy */
00280    AST_CONTROL_TAKEOFFHOOK = 6,  /*!< Make it go off hook */
00281    AST_CONTROL_OFFHOOK = 7,   /*!< Line is off hook */
00282    AST_CONTROL_CONGESTION = 8,   /*!< Congestion (circuits busy) */
00283    AST_CONTROL_FLASH = 9,     /*!< Flash hook */
00284    AST_CONTROL_WINK = 10,     /*!< Wink */
00285    AST_CONTROL_OPTION = 11,   /*!< Set a low-level option */
00286    AST_CONTROL_RADIO_KEY = 12,   /*!< Key Radio */
00287    AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */
00288    AST_CONTROL_PROGRESS = 14, /*!< Indicate PROGRESS */
00289    AST_CONTROL_PROCEEDING = 15,  /*!< Indicate CALL PROCEEDING */
00290    AST_CONTROL_HOLD = 16,     /*!< Indicate call is placed on hold */
00291    AST_CONTROL_UNHOLD = 17,   /*!< Indicate call is left from hold */
00292    AST_CONTROL_VIDUPDATE = 18,   /*!< Indicate video frame update */
00293    AST_CONTROL_SRCUPDATE = 20,     /*!< Indicate source of media has changed */
00294    AST_CONTROL_SRCCHANGE = 21,     /*!< Media has changed and requires a new RTP SSRC */
00295    AST_CONTROL_END_OF_Q = 22,    /*!< Indicate that this position was the end of the channel queue for a softhangup. */
00296 };
00297 
00298 #define AST_SMOOTHER_FLAG_G729      (1 << 0)
00299 #define AST_SMOOTHER_FLAG_BE     (1 << 1)
00300 
00301 /* Option identifiers and flags */
00302 #define AST_OPTION_FLAG_REQUEST     0
00303 #define AST_OPTION_FLAG_ACCEPT      1
00304 #define AST_OPTION_FLAG_REJECT      2
00305 #define AST_OPTION_FLAG_QUERY    4
00306 #define AST_OPTION_FLAG_ANSWER      5
00307 #define AST_OPTION_FLAG_WTF      6
00308 
00309 /*! Verify touchtones by muting audio transmission 
00310    (and reception) and verify the tone is still present */
00311 #define AST_OPTION_TONE_VERIFY      1     
00312 
00313 /*! Put a compatible channel into TDD (TTY for the hearing-impared) mode */
00314 #define  AST_OPTION_TDD       2
00315 
00316 /*! Relax the parameters for DTMF reception (mainly for radio use) */
00317 #define  AST_OPTION_RELAXDTMF    3
00318 
00319 /*! Set (or clear) Audio (Not-Clear) Mode */
00320 #define  AST_OPTION_AUDIO_MODE      4
00321 
00322 /*! Set channel transmit gain 
00323  * Option data is a single signed char
00324    representing number of decibels (dB)
00325    to set gain to (on top of any gain
00326    specified in channel driver)
00327 */
00328 #define AST_OPTION_TXGAIN     5
00329 
00330 /*! Set channel receive gain
00331  * Option data is a single signed char
00332    representing number of decibels (dB)
00333    to set gain to (on top of any gain
00334    specified in channel driver)
00335 */
00336 #define AST_OPTION_RXGAIN     6
00337 
00338 /* set channel into "Operator Services" mode */
00339 #define  AST_OPTION_OPRMODE      7
00340 
00341 /*! Explicitly enable or disable echo cancelation for the given channel */
00342 #define  AST_OPTION_ECHOCAN      8
00343 
00344 /*! \brief Handle channel write data
00345  * If a channel needs to process the data from a func_channel write operation
00346  * after func_channel_write executes, it can define the setoption callback
00347  * and process this option. A pointer to an ast_chan_write_info_t will be passed.
00348  * */
00349 #define AST_OPTION_CHANNEL_WRITE 9
00350 
00351 struct oprmode {
00352    struct ast_channel *peer;
00353    int mode;
00354 } ;
00355 
00356 struct ast_option_header {
00357    /* Always keep in network byte order */
00358 #if __BYTE_ORDER == __BIG_ENDIAN
00359         uint16_t flag:3;
00360         uint16_t option:13;
00361 #else
00362 #if __BYTE_ORDER == __LITTLE_ENDIAN
00363         uint16_t option:13;
00364         uint16_t flag:3;
00365 #else
00366 #error Byte order not defined
00367 #endif
00368 #endif
00369       uint8_t data[0];
00370 };
00371 
00372 
00373 /*! \brief Definition of supported media formats (codecs) */
00374 struct ast_format_list {
00375    int visible;   /*!< Can we see this entry */
00376    int bits;   /*!< bitmask value */
00377    char *name; /*!< short name */
00378    char *desc; /*!< Description */
00379    int fr_len; /*!< Single frame length in bytes */
00380    int min_ms; /*!< Min value */
00381    int max_ms; /*!< Max value */
00382    int inc_ms; /*!< Increment */
00383    int def_ms; /*!< Default value */
00384    unsigned int flags;  /*!< Smoother flags */
00385    int cur_ms; /*!< Current value */
00386 };
00387 
00388 
00389 /*! \brief  Requests a frame to be allocated 
00390  * 
00391  * \param source 
00392  * Request a frame be allocated.  source is an optional source of the frame, 
00393  * len is the requested length, or "0" if the caller will supply the buffer 
00394  */
00395 #if 0 /* Unimplemented */
00396 struct ast_frame *ast_fralloc(char *source, int len);
00397 #endif
00398 
00399 /*!  
00400  * \brief Frees a frame or list of frames
00401  * 
00402  * \param fr Frame to free, or head of list to free
00403  * \param cache Whether to consider this frame for frame caching
00404  */
00405 void ast_frame_free(struct ast_frame *fr, int cache);
00406 
00407 #define ast_frfree(fr) ast_frame_free(fr, 1)
00408 
00409 /*! \brief Makes a frame independent of any static storage
00410  * \param fr frame to act upon
00411  * Take a frame, and if it's not been malloc'd, make a malloc'd copy
00412  * and if the data hasn't been malloced then make the
00413  * data malloc'd.  If you need to store frames, say for queueing, then
00414  * you should call this function.
00415  * \return Returns a frame on success, NULL on error
00416  * \note This function may modify the frame passed to it, so you must
00417  * not assume the frame will be intact after the isolated frame has
00418  * been produced. In other words, calling this function on a frame
00419  * should be the last operation you do with that frame before freeing
00420  * it (or exiting the block, if the frame is on the stack.)
00421  */
00422 struct ast_frame *ast_frisolate(struct ast_frame *fr);
00423 
00424 /*! \brief Copies a frame 
00425  * \param fr frame to copy
00426  * Duplicates a frame -- should only rarely be used, typically frisolate is good enough
00427  * \return Returns a frame on success, NULL on error
00428  */
00429 struct ast_frame *ast_frdup(const struct ast_frame *fr);
00430 
00431 void ast_swapcopy_samples(void *dst, const void *src, int samples);
00432 
00433 /* Helpers for byteswapping native samples to/from 
00434    little-endian and big-endian. */
00435 #if __BYTE_ORDER == __LITTLE_ENDIAN
00436 #define ast_frame_byteswap_le(fr) do { ; } while(0)
00437 #define ast_frame_byteswap_be(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
00438 #else
00439 #define ast_frame_byteswap_le(fr) do { struct ast_frame *__f = (fr); ast_swapcopy_samples(__f->data, __f->data, __f->samples); } while(0)
00440 #define ast_frame_byteswap_be(fr) do { ; } while(0)
00441 #endif
00442 
00443 
00444 /*! \brief Get the name of a format
00445  * \param format id of format
00446  * \return A static string containing the name of the format or "unknown" if unknown.
00447  */
00448 char* ast_getformatname(int format);
00449 
00450 /*! \brief Get the names of a set of formats
00451  * \param buf a buffer for the output string
00452  * \param size size of buf (bytes)
00453  * \param format the format (combined IDs of codecs)
00454  * Prints a list of readable codec names corresponding to "format".
00455  * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
00456  * \return The return value is buf.
00457  */
00458 char* ast_getformatname_multiple(char *buf, size_t size, int format);
00459 
00460 /*!
00461  * \brief Gets a format from a name.
00462  * \param name string of format
00463  * \return This returns the form of the format in binary on success, 0 on error.
00464  */
00465 int ast_getformatbyname(const char *name);
00466 
00467 /*! \brief Get a name from a format 
00468  * Gets a name from a format
00469  * \param codec codec number (1,2,4,8,16,etc.)
00470  * \return This returns a static string identifying the format on success, 0 on error.
00471  */
00472 char *ast_codec2str(int codec);
00473 
00474 struct ast_smoother;
00475 
00476 struct ast_format_list *ast_get_format_list_index(int index);
00477 struct ast_format_list *ast_get_format_list(size_t *size);
00478 struct ast_smoother *ast_smoother_new(int bytes);
00479 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
00480 int ast_smoother_get_flags(struct ast_smoother *smoother);
00481 int ast_smoother_test_flag(struct ast_smoother *s, int flag);
00482 void ast_smoother_free(struct ast_smoother *s);
00483 void ast_smoother_reset(struct ast_smoother *s, int bytes);
00484 
00485 /*!
00486  * \brief Reconfigure an existing smoother to output a different number of bytes per frame
00487  * \param s the smoother to reconfigure
00488  * \param bytes the desired number of bytes per output frame
00489  * \return nothing
00490  *
00491  */
00492 void ast_smoother_reconfigure(struct ast_smoother *s, int bytes);
00493 
00494 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
00495 struct ast_frame *ast_smoother_read(struct ast_smoother *s);
00496 #define ast_smoother_feed(s,f) __ast_smoother_feed(s, f, 0)
00497 #if __BYTE_ORDER == __LITTLE_ENDIAN
00498 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 1)
00499 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 0)
00500 #else
00501 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 0)
00502 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1)
00503 #endif
00504 
00505 void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix);
00506 
00507 /*! \page AudioCodecPref Audio Codec Preferences
00508    In order to negotiate audio codecs in the order they are configured
00509    in <channel>.conf for a device, we set up codec preference lists
00510    in addition to the codec capabilities setting. The capabilities
00511    setting is a bitmask of audio and video codecs with no internal
00512    order. This will reflect the offer given to the other side, where
00513    the prefered codecs will be added to the top of the list in the
00514    order indicated by the "allow" lines in the device configuration.
00515    
00516    Video codecs are not included in the preference lists since they
00517    can't be transcoded and we just have to pick whatever is supported
00518 */
00519 
00520 /*! \brief Initialize an audio codec preference to "no preference" See \ref AudioCodecPref */
00521 void ast_codec_pref_init(struct ast_codec_pref *pref);
00522 
00523 /*! \brief Codec located at a particular place in the preference index See \ref AudioCodecPref */
00524 int ast_codec_pref_index(struct ast_codec_pref *pref, int index);
00525 
00526 /*! \brief Remove audio a codec from a preference list */
00527 void ast_codec_pref_remove(struct ast_codec_pref *pref, int format);
00528 
00529 /*! \brief Append a audio codec to a preference list, removing it first if it was already there 
00530 */
00531 int ast_codec_pref_append(struct ast_codec_pref *pref, int format);
00532 
00533 /*! \brief Prepend an audio codec to a preference list, removing it first if it was already there 
00534 */
00535 void ast_codec_pref_prepend(struct ast_codec_pref *pref, int format, int only_if_existing);
00536 
00537 /*! \brief Select the best audio format according to preference list from supplied options. 
00538    If "find_best" is non-zero then if nothing is found, the "Best" format of 
00539    the format list is selected, otherwise 0 is returned. */
00540 int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best);
00541 
00542 /*! \brief Set packet size for codec
00543 */
00544 int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems);
00545 
00546 /*! \brief Get packet size for codec
00547 */
00548 struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, int format);
00549 
00550 /*! \brief Parse an "allow" or "deny" line in a channel or device configuration 
00551         and update the capabilities mask and pref if provided.
00552    Video codecs are not added to codec preference lists, since we can not transcode
00553  */
00554 void ast_parse_allow_disallow(struct ast_codec_pref *pref, int *mask, const char *list, int allowing);
00555 
00556 /*! \brief Dump audio codec preference list into a string */
00557 int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size);
00558 
00559 /*! \brief Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string
00560  * \note Due to a misunderstanding in how codec preferences are stored, this
00561  * list starts at 'B', not 'A'.  For backwards compatibility reasons, this
00562  * cannot change.
00563  * \param pref A codec preference list structure
00564  * \param buf A string denoting codec preference, appropriate for use in line transmission
00565  * \param size Size of \a buf
00566  * \param right Boolean:  if 0, convert from \a buf to \a pref; if 1, convert from \a pref to \a buf.
00567  */
00568 void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right);
00569 
00570 /*! \brief Returns the number of samples contained in the frame */
00571 int ast_codec_get_samples(struct ast_frame *f);
00572 
00573 /*! \brief Returns the number of bytes for the number of samples of the given format */
00574 int ast_codec_get_len(int format, int samples);
00575 
00576 /*! \brief Appends a frame to the end of a list of frames, truncating the maximum length of the list */
00577 struct ast_frame *ast_frame_enqueue(struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe);
00578 
00579 
00580 /*! \brief Gets duration in ms of interpolation frame for a format */
00581 static inline int ast_codec_interp_len(int format) 
00582 { 
00583    return (format == AST_FORMAT_ILBC) ? 30 : 20;
00584 }
00585 
00586 /*!
00587   \brief Adjusts the volume of the audio samples contained in a frame.
00588   \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
00589   \param adjustment The number of dB to adjust up or down.
00590   \return 0 for success, non-zero for an error
00591  */
00592 int ast_frame_adjust_volume(struct ast_frame *f, int adjustment);
00593 
00594 /*!
00595   \brief Sums two frames of audio samples.
00596   \param f1 The first frame (which will contain the result)
00597   \param f2 The second frame
00598   \return 0 for success, non-zero for an error
00599 
00600   The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples,
00601   and must contain the same number of samples.
00602  */
00603 int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
00604 
00605 /*!
00606  * \brief Get the sample rate for a given format.
00607  */
00608 static force_inline int ast_format_rate(int format)
00609 {
00610    if (format == AST_FORMAT_G722)
00611       return 16000;
00612 
00613    return 8000;
00614 }
00615 
00616 #if defined(__cplusplus) || defined(c_plusplus)
00617 }
00618 #endif
00619 
00620 #endif /* _ASTERISK_FRAME_H */

Generated on Thu Oct 11 06:42:07 2012 for Asterisk - the Open Source PBX by  doxygen 1.5.6