Mon Jun 27 16:50:53 2011

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/frame_defs.h"
00035 #include "asterisk/endian.h"
00036 #include "asterisk/linkedlists.h"
00037 
00038 struct ast_codec_pref {
00039    char order[sizeof(format_t) * 8];
00040    char framing[sizeof(format_t) * 8];
00041 };
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 and character by character (real time text)
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  * \arg \b CONNECTED_LINE  Connected line has changed
00091  * \arg \b REDIRECTING     Call redirecting information has changed.
00092  */
00093 
00094 /*!
00095  * \brief Frame types 
00096  *
00097  * \note It is important that the values of each frame type are never changed,
00098  *       because it will break backwards compatability with older versions.
00099  *       This is because these constants are transmitted directly over IAX2.
00100  */
00101 enum ast_frame_type {
00102    /*! DTMF end event, subclass is the digit */
00103    AST_FRAME_DTMF_END = 1,
00104    /*! Voice data, subclass is AST_FORMAT_* */
00105    AST_FRAME_VOICE,
00106    /*! Video frame, maybe?? :) */
00107    AST_FRAME_VIDEO,
00108    /*! A control frame, subclass is AST_CONTROL_* */
00109    AST_FRAME_CONTROL,
00110    /*! An empty, useless frame */
00111    AST_FRAME_NULL,
00112    /*! Inter Asterisk Exchange private frame type */
00113    AST_FRAME_IAX,
00114    /*! Text messages */
00115    AST_FRAME_TEXT,
00116    /*! Image Frames */
00117    AST_FRAME_IMAGE,
00118    /*! HTML Frame */
00119    AST_FRAME_HTML,
00120    /*! Comfort Noise frame (subclass is level of CNG in -dBov), 
00121        body may include zero or more 8-bit quantization coefficients */
00122    AST_FRAME_CNG,
00123    /*! Modem-over-IP data streams */
00124    AST_FRAME_MODEM,  
00125    /*! DTMF begin event, subclass is the digit */
00126    AST_FRAME_DTMF_BEGIN,
00127 };
00128 #define AST_FRAME_DTMF AST_FRAME_DTMF_END
00129 
00130 enum {
00131    /*! This frame contains valid timing information */
00132    AST_FRFLAG_HAS_TIMING_INFO = (1 << 0),
00133 };
00134 
00135 union ast_frame_subclass {
00136    int integer;
00137    format_t codec;
00138 };
00139 
00140 /*! \brief Data structure associated with a single frame of data
00141  */
00142 struct ast_frame {
00143    /*! Kind of frame */
00144    enum ast_frame_type frametype;            
00145    /*! Subclass, frame dependent */
00146    union ast_frame_subclass subclass;
00147    /*! Length of data */
00148    int datalen;            
00149    /*! Number of samples in this frame */
00150    int samples;            
00151    /*! Was the data malloc'd?  i.e. should we free it when we discard the frame? */
00152    int mallocd;            
00153    /*! The number of bytes allocated for a malloc'd frame header */
00154    size_t mallocd_hdr_len;
00155    /*! How many bytes exist _before_ "data" that can be used if needed */
00156    int offset;          
00157    /*! Optional source of frame for debugging */
00158    const char *src;           
00159    /*! Pointer to actual data */
00160    union { void *ptr; uint32_t uint32; char pad[8]; } data;
00161    /*! Global delivery time */      
00162    struct timeval delivery;
00163    /*! For placing in a linked list */
00164    AST_LIST_ENTRY(ast_frame) frame_list;
00165    /*! Misc. frame flags */
00166    unsigned int flags;
00167    /*! Timestamp in milliseconds */
00168    long ts;
00169    /*! Length in milliseconds */
00170    long len;
00171    /*! Sequence number */
00172    int seqno;
00173 };
00174 
00175 /*!
00176  * Set the various field of a frame to point to a buffer.
00177  * Typically you set the base address of the buffer, the offset as
00178  * AST_FRIENDLY_OFFSET, and the datalen as the amount of bytes queued.
00179  * The remaining things (to be done manually) is set the number of
00180  * samples, which cannot be derived from the datalen unless you know
00181  * the number of bits per sample.
00182  */
00183 #define  AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen) \
00184    {              \
00185    (fr)->data.ptr = (char *)_base + (_ofs);  \
00186    (fr)->offset = (_ofs);        \
00187    (fr)->datalen = (_datalen);      \
00188    }
00189 
00190 /*! Queueing a null frame is fairly common, so we declare a global null frame object
00191     for this purpose instead of having to declare one on the stack */
00192 extern struct ast_frame ast_null_frame;
00193 
00194 /*! \brief Offset into a frame's data buffer.
00195  *
00196  * By providing some "empty" space prior to the actual data of an ast_frame,
00197  * this gives any consumer of the frame ample space to prepend other necessary
00198  * information without having to create a new buffer.
00199  *
00200  * As an example, RTP can use the data from an ast_frame and simply prepend the
00201  * RTP header information into the space provided by AST_FRIENDLY_OFFSET instead
00202  * of having to create a new buffer with the necessary space allocated.
00203  */
00204 #define AST_FRIENDLY_OFFSET   64 
00205 #define AST_MIN_OFFSET     32 /*! Make sure we keep at least this much handy */
00206 
00207 /*! Need the header be free'd? */
00208 #define AST_MALLOCD_HDR    (1 << 0)
00209 /*! Need the data be free'd? */
00210 #define AST_MALLOCD_DATA   (1 << 1)
00211 /*! Need the source be free'd? (haha!) */
00212 #define AST_MALLOCD_SRC    (1 << 2)
00213 
00214 /* MODEM subclasses */
00215 /*! T.38 Fax-over-IP */
00216 #define AST_MODEM_T38      1
00217 /*! V.150 Modem-over-IP */
00218 #define AST_MODEM_V150     2
00219 
00220 /* HTML subclasses */
00221 /*! Sending a URL */
00222 #define AST_HTML_URL    1
00223 /*! Data frame */
00224 #define AST_HTML_DATA      2
00225 /*! Beginning frame */
00226 #define AST_HTML_BEGIN     4
00227 /*! End frame */
00228 #define AST_HTML_END    8
00229 /*! Load is complete */
00230 #define AST_HTML_LDCOMPLETE   16
00231 /*! Peer is unable to support HTML */
00232 #define AST_HTML_NOSUPPORT 17
00233 /*! Send URL, and track */
00234 #define AST_HTML_LINKURL   18
00235 /*! No more HTML linkage */
00236 #define AST_HTML_UNLINK    19
00237 /*! Reject link request */
00238 #define AST_HTML_LINKREJECT   20
00239 
00240 /* Data formats for capabilities and frames alike */
00241 /*! G.723.1 compression */
00242 #define AST_FORMAT_G723_1     (1ULL << 0)
00243 /*! GSM compression */
00244 #define AST_FORMAT_GSM        (1ULL << 1)
00245 /*! Raw mu-law data (G.711) */
00246 #define AST_FORMAT_ULAW       (1ULL << 2)
00247 /*! Raw A-law data (G.711) */
00248 #define AST_FORMAT_ALAW       (1ULL << 3)
00249 /*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
00250 #define AST_FORMAT_G726_AAL2  (1ULL << 4)
00251 /*! ADPCM (IMA) */
00252 #define AST_FORMAT_ADPCM      (1ULL << 5)
00253 /*! Raw 16-bit Signed Linear (8000 Hz) PCM */
00254 #define AST_FORMAT_SLINEAR    (1ULL << 6)
00255 /*! LPC10, 180 samples/frame */
00256 #define AST_FORMAT_LPC10      (1ULL << 7)
00257 /*! G.729A audio */
00258 #define AST_FORMAT_G729A      (1ULL << 8)
00259 /*! SpeeX Free Compression */
00260 #define AST_FORMAT_SPEEX      (1ULL << 9)
00261 /*! iLBC Free Compression */
00262 #define AST_FORMAT_ILBC       (1ULL << 10)
00263 /*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
00264 #define AST_FORMAT_G726       (1ULL << 11)
00265 /*! G.722 */
00266 #define AST_FORMAT_G722       (1ULL << 12)
00267 /*! G.722.1 (also known as Siren7, 32kbps assumed) */
00268 #define AST_FORMAT_SIREN7     (1ULL << 13)
00269 /*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
00270 #define AST_FORMAT_SIREN14    (1ULL << 14)
00271 /*! Raw 16-bit Signed Linear (16000 Hz) PCM */
00272 #define AST_FORMAT_SLINEAR16  (1ULL << 15)
00273 /*! Maximum audio mask */
00274 #define AST_FORMAT_AUDIO_MASK 0xFFFF0000FFFFULL
00275 /*! JPEG Images */
00276 #define AST_FORMAT_JPEG       (1ULL << 16)
00277 /*! PNG Images */
00278 #define AST_FORMAT_PNG        (1ULL << 17)
00279 /*! H.261 Video */
00280 #define AST_FORMAT_H261       (1ULL << 18)
00281 /*! H.263 Video */
00282 #define AST_FORMAT_H263       (1ULL << 19)
00283 /*! H.263+ Video */
00284 #define AST_FORMAT_H263_PLUS  (1ULL << 20)
00285 /*! H.264 Video */
00286 #define AST_FORMAT_H264       (1ULL << 21)
00287 /*! MPEG4 Video */
00288 #define AST_FORMAT_MP4_VIDEO  (1ULL << 22)
00289 #define AST_FORMAT_VIDEO_MASK ((((1ULL << 25)-1) & ~(AST_FORMAT_AUDIO_MASK)) | 0x7FFF000000000000ULL)
00290 /*! T.140 RED Text format RFC 4103 */
00291 #define AST_FORMAT_T140RED    (1ULL << 26)
00292 /*! T.140 Text format - ITU T.140, RFC 4103 */
00293 #define AST_FORMAT_T140       (1ULL << 27)
00294 /*! Maximum text mask */
00295 #define AST_FORMAT_MAX_TEXT   (1ULL << 28)
00296 #define AST_FORMAT_TEXT_MASK  (((1ULL << 30)-1) & ~(AST_FORMAT_AUDIO_MASK) & ~(AST_FORMAT_VIDEO_MASK))
00297 /*! G.719 (64 kbps assumed) */
00298 #define AST_FORMAT_G719       (1ULL << 32)
00299 /*! SpeeX Wideband (16kHz) Free Compression */
00300 #define AST_FORMAT_SPEEX16    (1ULL << 33)
00301 /*! Raw mu-law data (G.711) */
00302 #define AST_FORMAT_TESTLAW    (1ULL << 47)
00303 /*! Reserved bit - do not use */
00304 #define AST_FORMAT_RESERVED   (1ULL << 63)
00305 
00306 enum ast_control_frame_type {
00307    AST_CONTROL_HANGUP = 1,    /*!< Other end has hungup */
00308    AST_CONTROL_RING = 2,      /*!< Local ring */
00309    AST_CONTROL_RINGING = 3,   /*!< Remote end is ringing */
00310    AST_CONTROL_ANSWER = 4,    /*!< Remote end has answered */
00311    AST_CONTROL_BUSY = 5,      /*!< Remote end is busy */
00312    AST_CONTROL_TAKEOFFHOOK = 6,  /*!< Make it go off hook */
00313    AST_CONTROL_OFFHOOK = 7,   /*!< Line is off hook */
00314    AST_CONTROL_CONGESTION = 8,   /*!< Congestion (circuits busy) */
00315    AST_CONTROL_FLASH = 9,     /*!< Flash hook */
00316    AST_CONTROL_WINK = 10,     /*!< Wink */
00317    AST_CONTROL_OPTION = 11,   /*!< Set a low-level option */
00318    AST_CONTROL_RADIO_KEY = 12,   /*!< Key Radio */
00319    AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */
00320    AST_CONTROL_PROGRESS = 14, /*!< Indicate PROGRESS */
00321    AST_CONTROL_PROCEEDING = 15,  /*!< Indicate CALL PROCEEDING */
00322    AST_CONTROL_HOLD = 16,     /*!< Indicate call is placed on hold */
00323    AST_CONTROL_UNHOLD = 17,   /*!< Indicate call is left from hold */
00324    AST_CONTROL_VIDUPDATE = 18,   /*!< Indicate video frame update */
00325    _XXX_AST_CONTROL_T38 = 19, /*!< T38 state change request/notification \deprecated This is no longer supported. Use AST_CONTROL_T38_PARAMETERS instead. */
00326    AST_CONTROL_SRCUPDATE = 20,     /*!< Indicate source of media has changed */
00327    AST_CONTROL_TRANSFER = 21,      /*!< Indicate status of a transfer request */
00328    AST_CONTROL_CONNECTED_LINE = 22,/*!< Indicate connected line has changed */
00329    AST_CONTROL_REDIRECTING = 23,    /*!< Indicate redirecting id has changed */
00330    AST_CONTROL_T38_PARAMETERS = 24, /*! T38 state change request/notification with parameters */
00331    AST_CONTROL_CC = 25, /*!< Indication that Call completion service is possible */
00332    AST_CONTROL_SRCCHANGE = 26,  /*!< Media source has changed and requires a new RTP SSRC */
00333    AST_CONTROL_READ_ACTION = 27, /*!< Tell ast_read to take a specific action */
00334    AST_CONTROL_AOC = 28,           /*!< Advice of Charge with encoded generic AOC payload */
00335    AST_CONTROL_END_OF_Q = 29,    /*!< Indicate that this position was the end of the channel queue for a softhangup. */
00336 };
00337 
00338 enum ast_frame_read_action {
00339    AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO,
00340 };
00341 
00342 struct ast_control_read_action_payload {
00343    /* An indicator to ast_read of what action to
00344     * take with the frame;
00345     */
00346    enum ast_frame_read_action action;
00347    /* The size of the frame's payload
00348     */
00349    size_t payload_size;
00350    /* A payload for the frame.
00351     */
00352    unsigned char payload[0];
00353 };
00354 
00355 enum ast_control_t38 {
00356    AST_T38_REQUEST_NEGOTIATE = 1,   /*!< Request T38 on a channel (voice to fax) */
00357    AST_T38_REQUEST_TERMINATE, /*!< Terminate T38 on a channel (fax to voice) */
00358    AST_T38_NEGOTIATED,     /*!< T38 negotiated (fax mode) */
00359    AST_T38_TERMINATED,     /*!< T38 terminated (back to voice) */
00360    AST_T38_REFUSED,     /*!< T38 refused for some reason (usually rejected by remote end) */
00361    AST_T38_REQUEST_PARMS,     /*!< request far end T.38 parameters for a channel in 'negotiating' state */
00362 };
00363 
00364 enum ast_control_t38_rate {
00365    AST_T38_RATE_2400 = 0,
00366    AST_T38_RATE_4800,
00367    AST_T38_RATE_7200,
00368    AST_T38_RATE_9600,
00369    AST_T38_RATE_12000,
00370    AST_T38_RATE_14400,
00371 };
00372 
00373 enum ast_control_t38_rate_management {
00374    AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF = 0,
00375    AST_T38_RATE_MANAGEMENT_LOCAL_TCF,
00376 };
00377 
00378 struct ast_control_t38_parameters {
00379    enum ast_control_t38 request_response;       /*!< Request or response of the T38 control frame */
00380    unsigned int version;               /*!< Supported T.38 version */
00381    unsigned int max_ifp;               /*!< Maximum IFP size supported */
00382    enum ast_control_t38_rate rate;           /*!< Maximum fax rate supported */
00383    enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
00384    unsigned int fill_bit_removal:1;       /*!< Set if fill bit removal can be used */
00385    unsigned int transcoding_mmr:1;           /*!< Set if MMR transcoding can be used */
00386    unsigned int transcoding_jbig:1;       /*!< Set if JBIG transcoding can be used */
00387 };
00388 
00389 enum ast_control_transfer {
00390    AST_TRANSFER_SUCCESS = 0, /*!< Transfer request on the channel worked */
00391    AST_TRANSFER_FAILED,      /*!< Transfer request on the channel failed */
00392 };
00393 
00394 #define AST_SMOOTHER_FLAG_G729      (1 << 0)
00395 #define AST_SMOOTHER_FLAG_BE     (1 << 1)
00396 
00397 /* Option identifiers and flags */
00398 #define AST_OPTION_FLAG_REQUEST     0
00399 #define AST_OPTION_FLAG_ACCEPT      1
00400 #define AST_OPTION_FLAG_REJECT      2
00401 #define AST_OPTION_FLAG_QUERY    4
00402 #define AST_OPTION_FLAG_ANSWER      5
00403 #define AST_OPTION_FLAG_WTF      6
00404 
00405 /*! Verify touchtones by muting audio transmission 
00406  * (and reception) and verify the tone is still present
00407  * Option data is a single signed char value 0 or 1 */
00408 #define AST_OPTION_TONE_VERIFY      1     
00409 
00410 /*! Put a compatible channel into TDD (TTY for the hearing-impared) mode
00411  * Option data is a single signed char value 0 or 1 */
00412 #define  AST_OPTION_TDD       2
00413 
00414 /*! Relax the parameters for DTMF reception (mainly for radio use)
00415  * Option data is a single signed char value 0 or 1 */
00416 #define  AST_OPTION_RELAXDTMF    3
00417 
00418 /*! Set (or clear) Audio (Not-Clear) Mode
00419  * Option data is a single signed char value 0 or 1 */
00420 #define  AST_OPTION_AUDIO_MODE      4
00421 
00422 /*! Set channel transmit gain 
00423  * Option data is a single signed char representing number of decibels (dB)
00424  * to set gain to (on top of any gain specified in channel driver) */
00425 #define AST_OPTION_TXGAIN     5
00426 
00427 /*! Set channel receive gain
00428  * Option data is a single signed char representing number of decibels (dB)
00429  * to set gain to (on top of any gain specified in channel driver) */
00430 #define AST_OPTION_RXGAIN     6
00431 
00432 /* set channel into "Operator Services" mode 
00433  * Option data is a struct oprmode
00434  *
00435  * \note This option should never be sent over the network */
00436 #define  AST_OPTION_OPRMODE      7
00437 
00438 /*! Explicitly enable or disable echo cancelation for the given channel
00439  * Option data is a single signed char value 0 or 1
00440  *
00441  * \note This option appears to be unused in the code. It is handled, but never
00442  * set or queried. */
00443 #define  AST_OPTION_ECHOCAN      8
00444 
00445 /*! \brief Handle channel write data
00446  * If a channel needs to process the data from a func_channel write operation
00447  * after func_channel_write executes, it can define the setoption callback
00448  * and process this option. A pointer to an ast_chan_write_info_t will be passed.
00449  *
00450  * \note This option should never be passed over the network. */
00451 #define AST_OPTION_CHANNEL_WRITE 9
00452 
00453 /* !
00454  * Read-only. Allows query current status of T38 on the channel.
00455  * data: ast_t38state
00456  */
00457 #define AST_OPTION_T38_STATE     10
00458 
00459 /*! Request that the channel driver deliver frames in a specific format
00460  * Option data is a format_t */
00461 #define AST_OPTION_FORMAT_READ          11
00462 
00463 /*! Request that the channel driver be prepared to accept frames in a specific format
00464  * Option data is a format_t */
00465 #define AST_OPTION_FORMAT_WRITE         12
00466 
00467 /*! Request that the channel driver make two channels of the same tech type compatible if possible
00468  * Option data is an ast_channel
00469  *
00470  * \note This option should never be passed over the network */
00471 #define AST_OPTION_MAKE_COMPATIBLE      13
00472 
00473 /*! Get or set the digit detection state of the channel
00474  * Option data is a single signed char value 0 or 1 */
00475 #define AST_OPTION_DIGIT_DETECT     14
00476 
00477 /*! Get or set the fax tone detection state of the channel
00478  * Option data is a single signed char value 0 or 1 */
00479 #define AST_OPTION_FAX_DETECT    15
00480 
00481 /*! Get the device name from the channel (Read only)
00482  * Option data is a character buffer of suitable length */
00483 #define AST_OPTION_DEVICE_NAME      16
00484 
00485 /*! Get the CC agent type from the channel (Read only) 
00486  * Option data is a character buffer of suitable length */
00487 #define AST_OPTION_CC_AGENT_TYPE    17
00488 
00489 /*! Get or set the security options on a channel
00490  * Option data is an integer value of 0 or 1 */
00491 #define AST_OPTION_SECURE_SIGNALING        18
00492 #define AST_OPTION_SECURE_MEDIA            19
00493 
00494 struct oprmode {
00495    struct ast_channel *peer;
00496    int mode;
00497 } ;
00498 
00499 struct ast_option_header {
00500    /* Always keep in network byte order */
00501 #if __BYTE_ORDER == __BIG_ENDIAN
00502         uint16_t flag:3;
00503         uint16_t option:13;
00504 #else
00505 #if __BYTE_ORDER == __LITTLE_ENDIAN
00506         uint16_t option:13;
00507         uint16_t flag:3;
00508 #else
00509 #error Byte order not defined
00510 #endif
00511 #endif
00512       uint8_t data[0];
00513 };
00514 
00515 
00516 /*! \brief Definition of supported media formats (codecs) */
00517 struct ast_format_list {
00518    format_t bits; /*!< bitmask value */
00519    char *name; /*!< short name */
00520    int samplespersecond; /*!< Number of samples per second (8000/16000) */
00521    char *desc; /*!< Description */
00522    int fr_len; /*!< Single frame length in bytes */
00523    int min_ms; /*!< Min value */
00524    int max_ms; /*!< Max value */
00525    int inc_ms; /*!< Increment */
00526    int def_ms; /*!< Default value */
00527    unsigned int flags;  /*!< Smoother flags */
00528    int cur_ms; /*!< Current value */
00529 };
00530 
00531 
00532 /*! \brief  Requests a frame to be allocated 
00533  * 
00534  * \param source 
00535  * Request a frame be allocated.  source is an optional source of the frame, 
00536  * len is the requested length, or "0" if the caller will supply the buffer 
00537  */
00538 #if 0 /* Unimplemented */
00539 struct ast_frame *ast_fralloc(char *source, int len);
00540 #endif
00541 
00542 /*!  
00543  * \brief Frees a frame or list of frames
00544  * 
00545  * \param fr Frame to free, or head of list to free
00546  * \param cache Whether to consider this frame for frame caching
00547  */
00548 void ast_frame_free(struct ast_frame *fr, int cache);
00549 
00550 #define ast_frfree(fr) ast_frame_free(fr, 1)
00551 
00552 /*! \brief Makes a frame independent of any static storage
00553  * \param fr frame to act upon
00554  * Take a frame, and if it's not been malloc'd, make a malloc'd copy
00555  * and if the data hasn't been malloced then make the
00556  * data malloc'd.  If you need to store frames, say for queueing, then
00557  * you should call this function.
00558  * \return Returns a frame on success, NULL on error
00559  * \note This function may modify the frame passed to it, so you must
00560  * not assume the frame will be intact after the isolated frame has
00561  * been produced. In other words, calling this function on a frame
00562  * should be the last operation you do with that frame before freeing
00563  * it (or exiting the block, if the frame is on the stack.)
00564  */
00565 struct ast_frame *ast_frisolate(struct ast_frame *fr);
00566 
00567 /*! \brief Copies a frame 
00568  * \param fr frame to copy
00569  * Duplicates a frame -- should only rarely be used, typically frisolate is good enough
00570  * \return Returns a frame on success, NULL on error
00571  */
00572 struct ast_frame *ast_frdup(const struct ast_frame *fr);
00573 
00574 void ast_swapcopy_samples(void *dst, const void *src, int samples);
00575 
00576 /* Helpers for byteswapping native samples to/from 
00577    little-endian and big-endian. */
00578 #if __BYTE_ORDER == __LITTLE_ENDIAN
00579 #define ast_frame_byteswap_le(fr) do { ; } while(0)
00580 #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)
00581 #else
00582 #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)
00583 #define ast_frame_byteswap_be(fr) do { ; } while(0)
00584 #endif
00585 
00586 
00587 /*! \brief Get the name of a format
00588  * \param format id of format
00589  * \return A static string containing the name of the format or "unknown" if unknown.
00590  */
00591 char* ast_getformatname(format_t format);
00592 
00593 /*! \brief Get the names of a set of formats
00594  * \param buf a buffer for the output string
00595  * \param size size of buf (bytes)
00596  * \param format the format (combined IDs of codecs)
00597  * Prints a list of readable codec names corresponding to "format".
00598  * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)"
00599  * \return The return value is buf.
00600  */
00601 char* ast_getformatname_multiple(char *buf, size_t size, format_t format);
00602 
00603 /*!
00604  * \brief Gets a format from a name.
00605  * \param name string of format
00606  * \return This returns the form of the format in binary on success, 0 on error.
00607  */
00608 format_t ast_getformatbyname(const char *name);
00609 
00610 /*! \brief Get a name from a format 
00611  * Gets a name from a format
00612  * \param codec codec number (1,2,4,8,16,etc.)
00613  * \return This returns a static string identifying the format on success, 0 on error.
00614  */
00615 char *ast_codec2str(format_t codec);
00616 
00617 /*! \name AST_Smoother 
00618 */
00619 /*@{ */
00620 /*! \page ast_smooth The AST Frame Smoother
00621 The ast_smoother interface was designed specifically
00622 to take frames of variant sizes and produce frames of a single expected
00623 size, precisely what you want to do.
00624 
00625 The basic interface is:
00626 
00627 - Initialize with ast_smoother_new()
00628 - Queue input frames with ast_smoother_feed()
00629 - Get output frames with ast_smoother_read()
00630 - when you're done, free the structure with ast_smoother_free()
00631 - Also see ast_smoother_test_flag(), ast_smoother_set_flags(), ast_smoother_get_flags(), ast_smoother_reset()
00632 */
00633 struct ast_smoother;
00634 
00635 struct ast_smoother *ast_smoother_new(int bytes);
00636 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
00637 int ast_smoother_get_flags(struct ast_smoother *smoother);
00638 int ast_smoother_test_flag(struct ast_smoother *s, int flag);
00639 void ast_smoother_free(struct ast_smoother *s);
00640 void ast_smoother_reset(struct ast_smoother *s, int bytes);
00641 
00642 /*!
00643  * \brief Reconfigure an existing smoother to output a different number of bytes per frame
00644  * \param s the smoother to reconfigure
00645  * \param bytes the desired number of bytes per output frame
00646  * \return nothing
00647  *
00648  */
00649 void ast_smoother_reconfigure(struct ast_smoother *s, int bytes);
00650 
00651 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
00652 struct ast_frame *ast_smoother_read(struct ast_smoother *s);
00653 #define ast_smoother_feed(s,f) __ast_smoother_feed(s, f, 0)
00654 #if __BYTE_ORDER == __LITTLE_ENDIAN
00655 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 1)
00656 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 0)
00657 #else
00658 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 0)
00659 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1)
00660 #endif
00661 /*@} Doxygen marker */
00662 
00663 const struct ast_format_list *ast_get_format_list_index(int index);
00664 const struct ast_format_list *ast_get_format_list(size_t *size);
00665 void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix);
00666 
00667 /*! \page AudioCodecPref Audio Codec Preferences
00668 
00669    In order to negotiate audio codecs in the order they are configured
00670    in <channel>.conf for a device, we set up codec preference lists
00671    in addition to the codec capabilities setting. The capabilities
00672    setting is a bitmask of audio and video codecs with no internal
00673    order. This will reflect the offer given to the other side, where
00674    the prefered codecs will be added to the top of the list in the
00675    order indicated by the "allow" lines in the device configuration.
00676    
00677    Video codecs are not included in the preference lists since they
00678    can't be transcoded and we just have to pick whatever is supported
00679 */
00680 
00681 /*! 
00682  *\brief Initialize an audio codec preference to "no preference".
00683  * \arg \ref AudioCodecPref 
00684 */
00685 void ast_codec_pref_init(struct ast_codec_pref *pref);
00686 
00687 /*! 
00688  * \brief Codec located at a particular place in the preference index.
00689  * \arg \ref AudioCodecPref 
00690 */
00691 format_t ast_codec_pref_index(struct ast_codec_pref *pref, int index);
00692 
00693 /*! \brief Remove audio a codec from a preference list */
00694 void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format);
00695 
00696 /*! \brief Append a audio codec to a preference list, removing it first if it was already there 
00697 */
00698 int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format);
00699 
00700 /*! \brief Prepend an audio codec to a preference list, removing it first if it was already there 
00701 */
00702 void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing);
00703 
00704 /*! \brief Select the best audio format according to preference list from supplied options. 
00705    If "find_best" is non-zero then if nothing is found, the "Best" format of 
00706    the format list is selected, otherwise 0 is returned. */
00707 format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best);
00708 
00709 /*! \brief Set packet size for codec
00710 */
00711 int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems);
00712 
00713 /*! \brief Get packet size for codec
00714 */
00715 struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format);
00716 
00717 /*! \brief Parse an "allow" or "deny" line in a channel or device configuration 
00718         and update the capabilities mask and pref if provided.
00719    Video codecs are not added to codec preference lists, since we can not transcode
00720    \return Returns number of errors encountered during parsing
00721  */
00722 int ast_parse_allow_disallow(struct ast_codec_pref *pref, format_t *mask, const char *list, int allowing);
00723 
00724 /*! \brief Dump audio codec preference list into a string */
00725 int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size);
00726 
00727 /*! \brief Shift an audio codec preference list up or down 65 bytes so that it becomes an ASCII string
00728  * \note Due to a misunderstanding in how codec preferences are stored, this
00729  * list starts at 'B', not 'A'.  For backwards compatibility reasons, this
00730  * cannot change.
00731  * \param pref A codec preference list structure
00732  * \param buf A string denoting codec preference, appropriate for use in line transmission
00733  * \param size Size of \a buf
00734  * \param right Boolean:  if 0, convert from \a buf to \a pref; if 1, convert from \a pref to \a buf.
00735  */
00736 void ast_codec_pref_convert(struct ast_codec_pref *pref, char *buf, size_t size, int right);
00737 
00738 /*! \brief Returns the number of samples contained in the frame */
00739 int ast_codec_get_samples(struct ast_frame *f);
00740 
00741 /*! \brief Returns the number of bytes for the number of samples of the given format */
00742 int ast_codec_get_len(format_t format, int samples);
00743 
00744 /*! \brief Appends a frame to the end of a list of frames, truncating the maximum length of the list */
00745 struct ast_frame *ast_frame_enqueue(struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe);
00746 
00747 
00748 /*! \brief Gets duration in ms of interpolation frame for a format */
00749 static inline int ast_codec_interp_len(format_t format) 
00750 { 
00751    return (format == AST_FORMAT_ILBC) ? 30 : 20;
00752 }
00753 
00754 /*!
00755   \brief Adjusts the volume of the audio samples contained in a frame.
00756   \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR)
00757   \param adjustment The number of dB to adjust up or down.
00758   \return 0 for success, non-zero for an error
00759  */
00760 int ast_frame_adjust_volume(struct ast_frame *f, int adjustment);
00761 
00762 /*!
00763   \brief Sums two frames of audio samples.
00764   \param f1 The first frame (which will contain the result)
00765   \param f2 The second frame
00766   \return 0 for success, non-zero for an error
00767 
00768   The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples,
00769   and must contain the same number of samples.
00770  */
00771 int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2);
00772 
00773 /*!
00774  * \brief Get the sample rate for a given format.
00775  */
00776 static force_inline int ast_format_rate(format_t format)
00777 {
00778    switch (format) {
00779    case AST_FORMAT_G722:
00780    case AST_FORMAT_SLINEAR16:
00781    case AST_FORMAT_SIREN7:
00782    case AST_FORMAT_SPEEX16:
00783       return 16000;
00784    case AST_FORMAT_SIREN14:
00785       return 32000;
00786    case AST_FORMAT_G719:
00787       return 48000;
00788    default:
00789       return 8000;
00790    }
00791 }
00792 
00793 /*!
00794  * \brief Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR 
00795  */
00796 int ast_frame_clear(struct ast_frame *frame);
00797 
00798 #if defined(__cplusplus) || defined(c_plusplus)
00799 }
00800 #endif
00801 
00802 #endif /* _ASTERISK_FRAME_H */

Generated on Mon Jun 27 16:50:53 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7