Sat Feb 11 06:33:15 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/time.h>
00033 
00034 #include "asterisk/format_pref.h"
00035 #include "asterisk/format.h"
00036 #include "asterisk/endian.h"
00037 #include "asterisk/linkedlists.h"
00038 
00039 /*!
00040  * \page Def_Frame AST Multimedia and signalling frames
00041  * \section Def_AstFrame What is an ast_frame ?
00042  * A frame of data read used to communicate between 
00043  * between channels and applications.
00044  * Frames are divided into frame types and subclasses.
00045  *
00046  * \par Frame types 
00047  * \arg \b VOICE:  Voice data, subclass is codec (AST_FORMAT_*)
00048  * \arg \b VIDEO:  Video data, subclass is codec (AST_FORMAT_*)
00049  * \arg \b DTMF:   A DTMF digit, subclass is the digit
00050  * \arg \b IMAGE:  Image transport, mostly used in IAX
00051  * \arg \b TEXT:   Text messages and character by character (real time text)
00052  * \arg \b HTML:   URL's and web pages
00053  * \arg \b MODEM:  Modulated data encodings, such as T.38 and V.150
00054  * \arg \b IAX:    Private frame type for the IAX protocol
00055  * \arg \b CNG:    Comfort noice frames
00056  * \arg \b CONTROL:A control frame, subclass defined as AST_CONTROL_
00057  * \arg \b NULL:   Empty, useless frame
00058  *
00059  * \par Files
00060  * \arg frame.h    Definitions
00061  * \arg frame.c    Function library
00062  * \arg \ref Def_Channel Asterisk channels
00063  * \section Def_ControlFrame Control Frames
00064  * Control frames send signalling information between channels
00065  * and devices. They are prefixed with AST_CONTROL_, like AST_CONTROL_FRAME_HANGUP
00066  * \arg \b HANGUP          The other end has hungup
00067  * \arg \b RING            Local ring
00068  * \arg \b RINGING         The other end is ringing
00069  * \arg \b ANSWER          The other end has answered
00070  * \arg \b BUSY            Remote end is busy
00071  * \arg \b TAKEOFFHOOK     Make it go off hook (what's "it" ? )
00072  * \arg \b OFFHOOK         Line is off hook
00073  * \arg \b CONGESTION      Congestion (circuit is busy, not available)
00074  * \arg \b FLASH           Other end sends flash hook
00075  * \arg \b WINK            Other end sends wink
00076  * \arg \b OPTION          Send low-level option
00077  * \arg \b RADIO_KEY       Key radio (see app_rpt.c)
00078  * \arg \b RADIO_UNKEY     Un-key radio (see app_rpt.c)
00079  * \arg \b PROGRESS        Other end indicates call progress
00080  * \arg \b PROCEEDING      Indicates proceeding
00081  * \arg \b HOLD            Call is placed on hold
00082  * \arg \b UNHOLD          Call is back from hold
00083  * \arg \b VIDUPDATE       Video update requested
00084  * \arg \b SRCUPDATE       The source of media has changed (RTP marker bit must change)
00085  * \arg \b SRCCHANGE       Media source has changed (RTP marker bit and SSRC must change)
00086  * \arg \b CONNECTED_LINE  Connected line has changed
00087  * \arg \b REDIRECTING     Call redirecting information has changed.
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 };
00130 
00131 union ast_frame_subclass {
00132    int integer;
00133    struct ast_format format;
00134 };
00135 
00136 /*! \brief Data structure associated with a single frame of data
00137  */
00138 struct ast_frame {
00139    /*! Kind of frame */
00140    enum ast_frame_type frametype;            
00141    /*! Subclass, frame dependent */
00142    union ast_frame_subclass subclass;
00143    /*! Length of data */
00144    int datalen;            
00145    /*! Number of samples in this frame */
00146    int samples;            
00147    /*! Was the data malloc'd?  i.e. should we free it when we discard the frame? */
00148    int mallocd;            
00149    /*! The number of bytes allocated for a malloc'd frame header */
00150    size_t mallocd_hdr_len;
00151    /*! How many bytes exist _before_ "data" that can be used if needed */
00152    int offset;          
00153    /*! Optional source of frame for debugging */
00154    const char *src;           
00155    /*! Pointer to actual data */
00156    union { void *ptr; uint32_t uint32; char pad[8]; } data;
00157    /*! Global delivery time */      
00158    struct timeval delivery;
00159    /*! For placing in a linked list */
00160    AST_LIST_ENTRY(ast_frame) frame_list;
00161    /*! Misc. frame flags */
00162    unsigned int flags;
00163    /*! Timestamp in milliseconds */
00164    long ts;
00165    /*! Length in milliseconds */
00166    long len;
00167    /*! Sequence number */
00168    int seqno;
00169 };
00170 
00171 /*!
00172  * Set the various field of a frame to point to a buffer.
00173  * Typically you set the base address of the buffer, the offset as
00174  * AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued.
00175  * The remaining things (to be done manually) is set the number of
00176  * samples, which cannot be derived from the datalen unless you know
00177  * the number of bits per sample.
00178  */
00179 #define  AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen) \
00180    {              \
00181    (fr)->data.ptr = (char *)_base + (_ofs);  \
00182    (fr)->offset = (_ofs);        \
00183    (fr)->datalen = (_datalen);      \
00184    }
00185 
00186 /*! Queueing a null frame is fairly common, so we declare a global null frame object
00187     for this purpose instead of having to declare one on the stack */
00188 extern struct ast_frame ast_null_frame;
00189 
00190 /*! \brief Offset into a frame's data buffer.
00191  *
00192  * By providing some "empty" space prior to the actual data of an ast_frame,
00193  * this gives any consumer of the frame ample space to prepend other necessary
00194  * information without having to create a new buffer.
00195  *
00196  * As an example, RTP can use the data from an ast_frame and simply prepend the
00197  * RTP header information into the space provided by AST_FRIENDLY_OFFSET instead
00198  * of having to create a new buffer with the necessary space allocated.
00199  */
00200 #define AST_FRIENDLY_OFFSET   64 
00201 #define AST_MIN_OFFSET     32 /*! Make sure we keep at least this much handy */
00202 
00203 /*! Need the header be free'd? */
00204 #define AST_MALLOCD_HDR    (1 << 0)
00205 /*! Need the data be free'd? */
00206 #define AST_MALLOCD_DATA   (1 << 1)
00207 /*! Need the source be free'd? (haha!) */
00208 #define AST_MALLOCD_SRC    (1 << 2)
00209 
00210 /* MODEM subclasses */
00211 /*! T.38 Fax-over-IP */
00212 #define AST_MODEM_T38      1
00213 /*! V.150 Modem-over-IP */
00214 #define AST_MODEM_V150     2
00215 
00216 /* HTML subclasses */
00217 /*! Sending a URL */
00218 #define AST_HTML_URL    1
00219 /*! Data frame */
00220 #define AST_HTML_DATA      2
00221 /*! Beginning frame */
00222 #define AST_HTML_BEGIN     4
00223 /*! End frame */
00224 #define AST_HTML_END    8
00225 /*! Load is complete */
00226 #define AST_HTML_LDCOMPLETE   16
00227 /*! Peer is unable to support HTML */
00228 #define AST_HTML_NOSUPPORT 17
00229 /*! Send URL, and track */
00230 #define AST_HTML_LINKURL   18
00231 /*! No more HTML linkage */
00232 #define AST_HTML_UNLINK    19
00233 /*! Reject link request */
00234 #define AST_HTML_LINKREJECT   20
00235 
00236 enum ast_control_frame_type {
00237    AST_CONTROL_HANGUP = 1,       /*!< Other end has hungup */
00238    AST_CONTROL_RING = 2,         /*!< Local ring */
00239    AST_CONTROL_RINGING = 3,      /*!< Remote end is ringing */
00240    AST_CONTROL_ANSWER = 4,       /*!< Remote end has answered */
00241    AST_CONTROL_BUSY = 5,         /*!< Remote end is busy */
00242    AST_CONTROL_TAKEOFFHOOK = 6,  /*!< Make it go off hook */
00243    AST_CONTROL_OFFHOOK = 7,      /*!< Line is off hook */
00244    AST_CONTROL_CONGESTION = 8,      /*!< Congestion (circuits busy) */
00245    AST_CONTROL_FLASH = 9,        /*!< Flash hook */
00246    AST_CONTROL_WINK = 10,        /*!< Wink */
00247    AST_CONTROL_OPTION = 11,      /*!< Set a low-level option */
00248    AST_CONTROL_RADIO_KEY = 12,      /*!< Key Radio */
00249    AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */
00250    AST_CONTROL_PROGRESS = 14,    /*!< Indicate PROGRESS */
00251    AST_CONTROL_PROCEEDING = 15,  /*!< Indicate CALL PROCEEDING */
00252    AST_CONTROL_HOLD = 16,        /*!< Indicate call is placed on hold */
00253    AST_CONTROL_UNHOLD = 17,      /*!< Indicate call is left from hold */
00254    AST_CONTROL_VIDUPDATE = 18,      /*!< Indicate video frame update */
00255    _XXX_AST_CONTROL_T38 = 19,    /*!< T38 state change request/notification \deprecated This is no longer supported. Use AST_CONTROL_T38_PARAMETERS instead. */
00256    AST_CONTROL_SRCUPDATE = 20,      /*!< Indicate source of media has changed */
00257    AST_CONTROL_TRANSFER = 21,    /*!< Indicate status of a transfer request */
00258    AST_CONTROL_CONNECTED_LINE = 22,/*!< Indicate connected line has changed */
00259    AST_CONTROL_REDIRECTING = 23, /*!< Indicate redirecting id has changed */
00260    AST_CONTROL_T38_PARAMETERS = 24,/*!< T38 state change request/notification with parameters */
00261    AST_CONTROL_CC = 25,       /*!< Indication that Call completion service is possible */
00262    AST_CONTROL_SRCCHANGE = 26,      /*!< Media source has changed and requires a new RTP SSRC */
00263    AST_CONTROL_READ_ACTION = 27, /*!< Tell ast_read to take a specific action */
00264    AST_CONTROL_AOC = 28,         /*!< Advice of Charge with encoded generic AOC payload */
00265    AST_CONTROL_END_OF_Q = 29,    /*!< Indicate that this position was the end of the channel queue for a softhangup. */
00266    AST_CONTROL_INCOMPLETE = 30,  /*!< Indication that the extension dialed is incomplete */
00267    AST_CONTROL_MCID = 31,        /*!< Indicate that the caller is being malicious. */
00268    AST_CONTROL_UPDATE_RTP_PEER = 32, /*!< Interrupt the bridge and have it update the peer */
00269 };
00270 
00271 enum ast_frame_read_action {
00272    AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO,
00273 };
00274 
00275 struct ast_control_read_action_payload {
00276    /* An indicator to ast_read of what action to
00277     * take with the frame;
00278     */
00279    enum ast_frame_read_action action;
00280    /* The size of the frame's payload
00281     */
00282    size_t payload_size;
00283    /* A payload for the frame.
00284     */
00285    unsigned char payload[0];
00286 };
00287 
00288 enum ast_control_t38 {
00289    AST_T38_REQUEST_NEGOTIATE = 1,   /*!< Request T38 on a channel (voice to fax) */
00290    AST_T38_REQUEST_TERMINATE, /*!< Terminate T38 on a channel (fax to voice) */
00291    AST_T38_NEGOTIATED,     /*!< T38 negotiated (fax mode) */
00292    AST_T38_TERMINATED,     /*!< T38 terminated (back to voice) */
00293    AST_T38_REFUSED,     /*!< T38 refused for some reason (usually rejected by remote end) */
00294    AST_T38_REQUEST_PARMS,     /*!< request far end T.38 parameters for a channel in 'negotiating' state */
00295 };
00296 
00297 enum ast_control_t38_rate {
00298    AST_T38_RATE_2400 = 0,
00299    AST_T38_RATE_4800,
00300    AST_T38_RATE_7200,
00301    AST_T38_RATE_9600,
00302    AST_T38_RATE_12000,
00303    AST_T38_RATE_14400,
00304 };
00305 
00306 enum ast_control_t38_rate_management {
00307    AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF = 0,
00308    AST_T38_RATE_MANAGEMENT_LOCAL_TCF,
00309 };
00310 
00311 struct ast_control_t38_parameters {
00312    enum ast_control_t38 request_response;       /*!< Request or response of the T38 control frame */
00313    unsigned int version;               /*!< Supported T.38 version */
00314    unsigned int max_ifp;               /*!< Maximum IFP size supported */
00315    enum ast_control_t38_rate rate;           /*!< Maximum fax rate supported */
00316    enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
00317    unsigned int fill_bit_removal:1;       /*!< Set if fill bit removal can be used */
00318    unsigned int transcoding_mmr:1;           /*!< Set if MMR transcoding can be used */
00319    unsigned int transcoding_jbig:1;       /*!< Set if JBIG transcoding can be used */
00320 };
00321 
00322 enum ast_control_transfer {
00323    AST_TRANSFER_SUCCESS = 0, /*!< Transfer request on the channel worked */
00324    AST_TRANSFER_FAILED,      /*!< Transfer request on the channel failed */
00325 };
00326 
00327 #define AST_SMOOTHER_FLAG_G729      (1 << 0)
00328 #define AST_SMOOTHER_FLAG_BE     (1 << 1)
00329 
00330 /* Option identifiers and flags */
00331 #define AST_OPTION_FLAG_REQUEST     0
00332 #define AST_OPTION_FLAG_ACCEPT      1
00333 #define AST_OPTION_FLAG_REJECT      2
00334 #define AST_OPTION_FLAG_QUERY    4
00335 #define AST_OPTION_FLAG_ANSWER      5
00336 #define AST_OPTION_FLAG_WTF      6
00337 
00338 /*! Verify touchtones by muting audio transmission 
00339  * (and reception) and verify the tone is still present
00340  * Option data is a single signed char value 0 or 1 */
00341 #define AST_OPTION_TONE_VERIFY      1     
00342 
00343 /*! Put a compatible channel into TDD (TTY for the hearing-impared) mode
00344  * Option data is a single signed char value 0 or 1 */
00345 #define  AST_OPTION_TDD       2
00346 
00347 /*! Relax the parameters for DTMF reception (mainly for radio use)
00348  * Option data is a single signed char value 0 or 1 */
00349 #define  AST_OPTION_RELAXDTMF    3
00350 
00351 /*! Set (or clear) Audio (Not-Clear) Mode
00352  * Option data is a single signed char value 0 or 1 */
00353 #define  AST_OPTION_AUDIO_MODE      4
00354 
00355 /*! Set channel transmit gain 
00356  * Option data is a single signed char representing number of decibels (dB)
00357  * to set gain to (on top of any gain specified in channel driver) */
00358 #define AST_OPTION_TXGAIN     5
00359 
00360 /*! Set channel receive gain
00361  * Option data is a single signed char representing number of decibels (dB)
00362  * to set gain to (on top of any gain specified in channel driver) */
00363 #define AST_OPTION_RXGAIN     6
00364 
00365 /* set channel into "Operator Services" mode 
00366  * Option data is a struct oprmode
00367  *
00368  * \note This option should never be sent over the network */
00369 #define  AST_OPTION_OPRMODE      7
00370 
00371 /*! Explicitly enable or disable echo cancelation for the given channel
00372  * Option data is a single signed char value 0 or 1
00373  *
00374  * \note This option appears to be unused in the code. It is handled, but never
00375  * set or queried. */
00376 #define  AST_OPTION_ECHOCAN      8
00377 
00378 /*! \brief Handle channel write data
00379  * If a channel needs to process the data from a func_channel write operation
00380  * after func_channel_write executes, it can define the setoption callback
00381  * and process this option. A pointer to an ast_chan_write_info_t will be passed.
00382  *
00383  * \note This option should never be passed over the network. */
00384 #define AST_OPTION_CHANNEL_WRITE 9
00385 
00386 /* !
00387  * Read-only. Allows query current status of T38 on the channel.
00388  * data: ast_t38state
00389  */
00390 #define AST_OPTION_T38_STATE     10
00391 
00392 /*! Request that the channel driver deliver frames in a specific format
00393  * Option data is a format_t */
00394 #define AST_OPTION_FORMAT_READ          11
00395 
00396 /*! Request that the channel driver be prepared to accept frames in a specific format
00397  * Option data is a format_t */
00398 #define AST_OPTION_FORMAT_WRITE         12
00399 
00400 /*! Request that the channel driver make two channels of the same tech type compatible if possible
00401  * Option data is an ast_channel
00402  *
00403  * \note This option should never be passed over the network */
00404 #define AST_OPTION_MAKE_COMPATIBLE      13
00405 
00406 /*! Get or set the digit detection state of the channel
00407  * Option data is a single signed char value 0 or 1 */
00408 #define AST_OPTION_DIGIT_DETECT     14
00409 
00410 /*! Get or set the fax tone detection state of the channel
00411  * Option data is a single signed char value 0 or 1 */
00412 #define AST_OPTION_FAX_DETECT    15
00413 
00414 /*! Get the device name from the channel (Read only)
00415  * Option data is a character buffer of suitable length */
00416 #define AST_OPTION_DEVICE_NAME      16
00417 
00418 /*! Get the CC agent type from the channel (Read only) 
00419  * Option data is a character buffer of suitable length */
00420 #define AST_OPTION_CC_AGENT_TYPE    17
00421 
00422 /*! Get or set the security options on a channel
00423  * Option data is an integer value of 0 or 1 */
00424 #define AST_OPTION_SECURE_SIGNALING        18
00425 #define AST_OPTION_SECURE_MEDIA            19
00426 
00427 struct oprmode {
00428    struct ast_channel *peer;
00429    int mode;
00430 } ;
00431 
00432 struct ast_option_header {
00433    /* Always keep in network byte order */
00434 #if __BYTE_ORDER == __BIG_ENDIAN
00435         uint16_t flag:3;
00436         uint16_t option:13;
00437 #else
00438 #if __BYTE_ORDER == __LITTLE_ENDIAN
00439         uint16_t option:13;
00440         uint16_t flag:3;
00441 #else
00442 #error Byte order not defined
00443 #endif
00444 #endif
00445       uint8_t data[0];
00446 };
00447 
00448 /*! \brief  Requests a frame to be allocated 
00449  * 
00450  * \param source 
00451  * Request a frame be allocated.  source is an optional source of the frame, 
00452  * len is the requested length, or "0" if the caller will supply the buffer 
00453  */
00454 #if 0 /* Unimplemented */
00455 struct ast_frame *ast_fralloc(char *source, int len);
00456 #endif
00457 
00458 /*!  
00459  * \brief Frees a frame or list of frames
00460  * 
00461  * \param fr Frame to free, or head of list to free
00462  * \param cache Whether to consider this frame for frame caching
00463  */
00464 void ast_frame_free(struct ast_frame *fr, int cache);
00465 
00466 #define ast_frfree(fr) ast_frame_free(fr, 1)
00467 
00468 /*! \brief Makes a frame independent of any static storage
00469  * \param fr frame to act upon
00470  * Take a frame, and if it's not been malloc'd, make a malloc'd copy
00471  * and if the data hasn't been malloced then make the
00472  * data malloc'd.  If you need to store frames, say for queueing, then
00473  * you should call this function.
00474  * \return Returns a frame on success, NULL on error
00475  * \note This function may modify the frame passed to it, so you must
00476  * not assume the frame will be intact after the isolated frame has
00477  * been produced. In other words, calling this function on a frame
00478  * should be the last operation you do with that frame before freeing
00479  * it (or exiting the block, if the frame is on the stack.)
00480  */
00481 struct ast_frame *ast_frisolate(struct ast_frame *fr);
00482 
00483 /*! \brief Copies a frame 
00484  * \param fr frame to copy
00485  * Duplicates a frame -- should only rarely be used, typically frisolate is good enough
00486  * \return Returns a frame on success, NULL on error
00487  */
00488 struct ast_frame *ast_frdup(const struct ast_frame *fr);
00489 
00490 void ast_swapcopy_samples(void *dst, const void *src, int samples);
00491 
00492 /* Helpers for byteswapping native samples to/from 
00493    little-endian and big-endian. */
00494 #if __BYTE_ORDER == __LITTLE_ENDIAN
00495 #define ast_frame_byteswap_le(fr) do { ; } while(0)
00496 #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)
00497 #else
00498 #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)
00499 #define ast_frame_byteswap_be(fr) do { ; } while(0)
00500 #endif
00501 
00502 /*! \brief Parse an "allow" or "deny" line in a channel or device configuration
00503         and update the capabilities and pref if provided.
00504    Video codecs are not added to codec preference lists, since we can not transcode
00505    \return Returns number of errors encountered during parsing
00506  */
00507 int ast_parse_allow_disallow(struct ast_codec_pref *pref, struct ast_format_cap *cap, const char *list, int allowing);
00508 
00509 /*! \name AST_Smoother 
00510 */
00511 /*@{ */
00512 /*! \page ast_smooth The AST Frame Smoother
00513 The ast_smoother interface was designed specifically
00514 to take frames of variant sizes and produce frames of a single expected
00515 size, precisely what you want to do.
00516 
00517 The basic interface is:
00518 
00519 - Initialize with ast_smoother_new()
00520 - Queue input frames with ast_smoother_feed()
00521 - Get output frames with ast_smoother_read()
00522 - when you're done, free the structure with ast_smoother_free()
00523 - Also see ast_smoother_test_flag(), ast_smoother_set_flags(), ast_smoother_get_flags(), ast_smoother_reset()
00524 */
00525 struct ast_smoother;
00526 
00527 struct ast_smoother *ast_smoother_new(int bytes);
00528 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
00529 int ast_smoother_get_flags(struct ast_smoother *smoother);
00530 int ast_smoother_test_flag(struct ast_smoother *s, int flag);
00531 void ast_smoother_free(struct ast_smoother *s);
00532 void ast_smoother_reset(struct ast_smoother *s, int bytes);
00533 
00534 /*!
00535  * \brief Reconfigure an existing smoother to output a different number of bytes per frame
00536  * \param s the smoother to reconfigure
00537  * \param bytes the desired number of bytes per output frame
00538  * \return nothing
00539  *
00540  */
00541 void ast_smoother_reconfigure(struct ast_smoother *s, int bytes);
00542 
00543 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
00544 struct ast_frame *ast_smoother_read(struct ast_smoother *s);
00545 #define ast_smoother_feed(s,f) __ast_smoother_feed(s, f, 0)
00546 #if __BYTE_ORDER == __LITTLE_ENDIAN
00547 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 1)
00548 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 0)
00549 #else
00550 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 0)
00551 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1)
00552 #endif
00553 /*@} Doxygen marker */
00554 
00555 void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix);
00556 
00557 /*! \brief Returns the number of samples contained in the frame */
00558 int ast_codec_get_samples(struct ast_frame *f);
00559 
00560 /*! \brief Returns the number of bytes for the number of samples of the given format */
00561 int ast_codec_get_len(struct ast_format *format, int samples);
00562 
00563 /*! \brief Appends a frame to the end of a list of frames, truncating the maximum length of the list */
00564 struct ast_frame *ast_frame_enqueue(struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe);
00565 
00566 
00567 /*! \brief Gets duration in ms of interpolation frame for a format */
00568 static inline int ast_codec_interp_len(struct ast_format *format)
00569 { 
00570    return (format->id == AST_FORMAT_ILBC) ? 30 : 20;
00571 }
00572 
00573 /*!
00574   \brief Adjusts the volume of the audio samples contained in a frame.
00575   \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
00576   \param adjustment The number of dB to adjust up or down.
00577   \return 0 for success, non-zero for an error
00578  */
00579 int ast_frame_adjust_volume(struct ast_frame *f, int adjustment);
00580 
00581 /*!
00582   \brief Sums two frames of audio samples.
00583   \param f1 The first frame (which will contain the result)
00584   \param f2 The second frame
00585   \return 0 for success, non-zero for an error
00586 
00587   The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples,
00588   and must contain the same number of samples.
00589  */
00590 int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
00591 
00592 /*!
00593  * \brief Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR 
00594  */
00595 int ast_frame_clear(struct ast_frame *frame);
00596 
00597 #if defined(__cplusplus) || defined(c_plusplus)
00598 }
00599 #endif
00600 
00601 #endif /* _ASTERISK_FRAME_H */

Generated on Sat Feb 11 06:33:15 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6