Fri Jul 24 00:40:56 2009

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

Generated on Fri Jul 24 00:40:56 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7