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 /*! 00237 * \brief Internal control frame subtype field values. 00238 * 00239 * \warning 00240 * IAX2 sends these values out over the wire. To prevent future 00241 * incompatibilities, pick the next value in the enum from whatever 00242 * is on the current trunk. If you lose the merge race you need to 00243 * fix the previous branches to match what is on trunk. In addition 00244 * you need to change chan_iax2 to explicitly allow the control 00245 * frame over the wire if it makes sense for the frame to be passed 00246 * to another Asterisk instance. 00247 */ 00248 enum ast_control_frame_type { 00249 AST_CONTROL_HANGUP = 1, /*!< Other end has hungup */ 00250 AST_CONTROL_RING = 2, /*!< Local ring */ 00251 AST_CONTROL_RINGING = 3, /*!< Remote end is ringing */ 00252 AST_CONTROL_ANSWER = 4, /*!< Remote end has answered */ 00253 AST_CONTROL_BUSY = 5, /*!< Remote end is busy */ 00254 AST_CONTROL_TAKEOFFHOOK = 6, /*!< Make it go off hook */ 00255 AST_CONTROL_OFFHOOK = 7, /*!< Line is off hook */ 00256 AST_CONTROL_CONGESTION = 8, /*!< Congestion (circuits busy) */ 00257 AST_CONTROL_FLASH = 9, /*!< Flash hook */ 00258 AST_CONTROL_WINK = 10, /*!< Wink */ 00259 AST_CONTROL_OPTION = 11, /*!< Set a low-level option */ 00260 AST_CONTROL_RADIO_KEY = 12, /*!< Key Radio */ 00261 AST_CONTROL_RADIO_UNKEY = 13, /*!< Un-Key Radio */ 00262 AST_CONTROL_PROGRESS = 14, /*!< Indicate PROGRESS */ 00263 AST_CONTROL_PROCEEDING = 15, /*!< Indicate CALL PROCEEDING */ 00264 AST_CONTROL_HOLD = 16, /*!< Indicate call is placed on hold */ 00265 AST_CONTROL_UNHOLD = 17, /*!< Indicate call is left from hold */ 00266 AST_CONTROL_VIDUPDATE = 18, /*!< Indicate video frame update */ 00267 _XXX_AST_CONTROL_T38 = 19, /*!< T38 state change request/notification \deprecated This is no longer supported. Use AST_CONTROL_T38_PARAMETERS instead. */ 00268 AST_CONTROL_SRCUPDATE = 20, /*!< Indicate source of media has changed */ 00269 AST_CONTROL_TRANSFER = 21, /*!< Indicate status of a transfer request */ 00270 AST_CONTROL_CONNECTED_LINE = 22,/*!< Indicate connected line has changed */ 00271 AST_CONTROL_REDIRECTING = 23, /*!< Indicate redirecting id has changed */ 00272 AST_CONTROL_T38_PARAMETERS = 24,/*!< T38 state change request/notification with parameters */ 00273 AST_CONTROL_CC = 25, /*!< Indication that Call completion service is possible */ 00274 AST_CONTROL_SRCCHANGE = 26, /*!< Media source has changed and requires a new RTP SSRC */ 00275 AST_CONTROL_READ_ACTION = 27, /*!< Tell ast_read to take a specific action */ 00276 AST_CONTROL_AOC = 28, /*!< Advice of Charge with encoded generic AOC payload */ 00277 AST_CONTROL_END_OF_Q = 29, /*!< Indicate that this position was the end of the channel queue for a softhangup. */ 00278 AST_CONTROL_INCOMPLETE = 30, /*!< Indication that the extension dialed is incomplete */ 00279 AST_CONTROL_MCID = 31, /*!< Indicate that the caller is being malicious. */ 00280 AST_CONTROL_UPDATE_RTP_PEER = 32, /*!< Interrupt the bridge and have it update the peer */ 00281 AST_CONTROL_PVT_CAUSE_CODE = 33, /*!< Contains an update to the protocol-specific cause-code stored for branching dials */ 00282 00283 /* 00284 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 00285 * 00286 * IAX2 sends these values out over the wire. To prevent future 00287 * incompatibilities, pick the next value in the enum from whatever 00288 * is on the current trunk. If you lose the merge race you need to 00289 * fix the previous branches to match what is on trunk. In addition 00290 * you need to change chan_iax2 to explicitly allow the control 00291 * frame over the wire if it makes sense for the frame to be passed 00292 * to another Asterisk instance. 00293 * 00294 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 00295 */ 00296 }; 00297 00298 enum ast_frame_read_action { 00299 AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO, 00300 }; 00301 00302 struct ast_control_read_action_payload { 00303 /* An indicator to ast_read of what action to 00304 * take with the frame; 00305 */ 00306 enum ast_frame_read_action action; 00307 /* The size of the frame's payload 00308 */ 00309 size_t payload_size; 00310 /* A payload for the frame. 00311 */ 00312 unsigned char payload[0]; 00313 }; 00314 00315 enum ast_control_t38 { 00316 AST_T38_REQUEST_NEGOTIATE = 1, /*!< Request T38 on a channel (voice to fax) */ 00317 AST_T38_REQUEST_TERMINATE, /*!< Terminate T38 on a channel (fax to voice) */ 00318 AST_T38_NEGOTIATED, /*!< T38 negotiated (fax mode) */ 00319 AST_T38_TERMINATED, /*!< T38 terminated (back to voice) */ 00320 AST_T38_REFUSED, /*!< T38 refused for some reason (usually rejected by remote end) */ 00321 AST_T38_REQUEST_PARMS, /*!< request far end T.38 parameters for a channel in 'negotiating' state */ 00322 }; 00323 00324 enum ast_control_t38_rate { 00325 AST_T38_RATE_2400 = 1, 00326 AST_T38_RATE_4800, 00327 AST_T38_RATE_7200, 00328 AST_T38_RATE_9600, 00329 AST_T38_RATE_12000, 00330 /* Set to 0 so it's taken as default when unspecified. 00331 * See ITU-T T.38 Implementors' Guide (11 May 2012), 00332 * Table H.2: if the T38MaxBitRate attribute is omitted 00333 * it should use a default of 14400. */ 00334 AST_T38_RATE_14400 = 0, 00335 }; 00336 00337 enum ast_control_t38_rate_management { 00338 AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF = 0, 00339 AST_T38_RATE_MANAGEMENT_LOCAL_TCF, 00340 }; 00341 00342 struct ast_control_t38_parameters { 00343 enum ast_control_t38 request_response; /*!< Request or response of the T38 control frame */ 00344 unsigned int version; /*!< Supported T.38 version */ 00345 unsigned int max_ifp; /*!< Maximum IFP size supported */ 00346 enum ast_control_t38_rate rate; /*!< Maximum fax rate supported */ 00347 enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */ 00348 unsigned int fill_bit_removal:1; /*!< Set if fill bit removal can be used */ 00349 unsigned int transcoding_mmr:1; /*!< Set if MMR transcoding can be used */ 00350 unsigned int transcoding_jbig:1; /*!< Set if JBIG transcoding can be used */ 00351 }; 00352 00353 enum ast_control_transfer { 00354 AST_TRANSFER_SUCCESS = 0, /*!< Transfer request on the channel worked */ 00355 AST_TRANSFER_FAILED, /*!< Transfer request on the channel failed */ 00356 }; 00357 00358 struct ast_control_pvt_cause_code { 00359 char chan_name[AST_CHANNEL_NAME]; /*!< Name of the channel that originated the cause information */ 00360 unsigned int emulate_sip_cause:1; /*!< Indicates whether this should be used to emulate SIP_CAUSE support */ 00361 int ast_cause; /*!< Asterisk cause code associated with this message */ 00362 char code[1]; /*!< Tech-specific cause code information, beginning with the name of the tech */ 00363 }; 00364 00365 #define AST_SMOOTHER_FLAG_G729 (1 << 0) 00366 #define AST_SMOOTHER_FLAG_BE (1 << 1) 00367 00368 /* Option identifiers and flags */ 00369 #define AST_OPTION_FLAG_REQUEST 0 00370 #define AST_OPTION_FLAG_ACCEPT 1 00371 #define AST_OPTION_FLAG_REJECT 2 00372 #define AST_OPTION_FLAG_QUERY 4 00373 #define AST_OPTION_FLAG_ANSWER 5 00374 #define AST_OPTION_FLAG_WTF 6 00375 00376 /*! Verify touchtones by muting audio transmission 00377 * (and reception) and verify the tone is still present 00378 * Option data is a single signed char value 0 or 1 */ 00379 #define AST_OPTION_TONE_VERIFY 1 00380 00381 /*! Put a compatible channel into TDD (TTY for the hearing-impared) mode 00382 * Option data is a single signed char value 0 or 1 */ 00383 #define AST_OPTION_TDD 2 00384 00385 /*! Relax the parameters for DTMF reception (mainly for radio use) 00386 * Option data is a single signed char value 0 or 1 */ 00387 #define AST_OPTION_RELAXDTMF 3 00388 00389 /*! Set (or clear) Audio (Not-Clear) Mode 00390 * Option data is a single signed char value 0 or 1 */ 00391 #define AST_OPTION_AUDIO_MODE 4 00392 00393 /*! Set channel transmit gain 00394 * Option data is a single signed char representing number of decibels (dB) 00395 * to set gain to (on top of any gain specified in channel driver) */ 00396 #define AST_OPTION_TXGAIN 5 00397 00398 /*! Set channel receive gain 00399 * Option data is a single signed char representing number of decibels (dB) 00400 * to set gain to (on top of any gain specified in channel driver) */ 00401 #define AST_OPTION_RXGAIN 6 00402 00403 /* set channel into "Operator Services" mode 00404 * Option data is a struct oprmode 00405 * 00406 * \note This option should never be sent over the network */ 00407 #define AST_OPTION_OPRMODE 7 00408 00409 /*! Explicitly enable or disable echo cancelation for the given channel 00410 * Option data is a single signed char value 0 or 1 00411 * 00412 * \note This option appears to be unused in the code. It is handled, but never 00413 * set or queried. */ 00414 #define AST_OPTION_ECHOCAN 8 00415 00416 /*! \brief Handle channel write data 00417 * If a channel needs to process the data from a func_channel write operation 00418 * after func_channel_write executes, it can define the setoption callback 00419 * and process this option. A pointer to an ast_chan_write_info_t will be passed. 00420 * 00421 * \note This option should never be passed over the network. */ 00422 #define AST_OPTION_CHANNEL_WRITE 9 00423 00424 /* ! 00425 * Read-only. Allows query current status of T38 on the channel. 00426 * data: ast_t38state 00427 */ 00428 #define AST_OPTION_T38_STATE 10 00429 00430 /*! Request that the channel driver deliver frames in a specific format 00431 * Option data is a format_t */ 00432 #define AST_OPTION_FORMAT_READ 11 00433 00434 /*! Request that the channel driver be prepared to accept frames in a specific format 00435 * Option data is a format_t */ 00436 #define AST_OPTION_FORMAT_WRITE 12 00437 00438 /*! Request that the channel driver make two channels of the same tech type compatible if possible 00439 * Option data is an ast_channel 00440 * 00441 * \note This option should never be passed over the network */ 00442 #define AST_OPTION_MAKE_COMPATIBLE 13 00443 00444 /*! Get or set the digit detection state of the channel 00445 * Option data is a single signed char value 0 or 1 */ 00446 #define AST_OPTION_DIGIT_DETECT 14 00447 00448 /*! Get or set the fax tone detection state of the channel 00449 * Option data is a single signed char value 0 or 1 */ 00450 #define AST_OPTION_FAX_DETECT 15 00451 00452 /*! Get the device name from the channel (Read only) 00453 * Option data is a character buffer of suitable length */ 00454 #define AST_OPTION_DEVICE_NAME 16 00455 00456 /*! Get the CC agent type from the channel (Read only) 00457 * Option data is a character buffer of suitable length */ 00458 #define AST_OPTION_CC_AGENT_TYPE 17 00459 00460 /*! Get or set the security options on a channel 00461 * Option data is an integer value of 0 or 1 */ 00462 #define AST_OPTION_SECURE_SIGNALING 18 00463 #define AST_OPTION_SECURE_MEDIA 19 00464 00465 struct oprmode { 00466 struct ast_channel *peer; 00467 int mode; 00468 } ; 00469 00470 struct ast_option_header { 00471 /* Always keep in network byte order */ 00472 #if __BYTE_ORDER == __BIG_ENDIAN 00473 uint16_t flag:3; 00474 uint16_t option:13; 00475 #else 00476 #if __BYTE_ORDER == __LITTLE_ENDIAN 00477 uint16_t option:13; 00478 uint16_t flag:3; 00479 #else 00480 #error Byte order not defined 00481 #endif 00482 #endif 00483 uint8_t data[0]; 00484 }; 00485 00486 /*! \brief Requests a frame to be allocated 00487 * 00488 * \param source 00489 * Request a frame be allocated. source is an optional source of the frame, 00490 * len is the requested length, or "0" if the caller will supply the buffer 00491 */ 00492 #if 0 /* Unimplemented */ 00493 struct ast_frame *ast_fralloc(char *source, int len); 00494 #endif 00495 00496 /*! 00497 * \brief Frees a frame or list of frames 00498 * 00499 * \param fr Frame to free, or head of list to free 00500 * \param cache Whether to consider this frame for frame caching 00501 */ 00502 void ast_frame_free(struct ast_frame *fr, int cache); 00503 00504 #define ast_frfree(fr) ast_frame_free(fr, 1) 00505 00506 /*! \brief Makes a frame independent of any static storage 00507 * \param fr frame to act upon 00508 * Take a frame, and if it's not been malloc'd, make a malloc'd copy 00509 * and if the data hasn't been malloced then make the 00510 * data malloc'd. If you need to store frames, say for queueing, then 00511 * you should call this function. 00512 * \return Returns a frame on success, NULL on error 00513 * \note This function may modify the frame passed to it, so you must 00514 * not assume the frame will be intact after the isolated frame has 00515 * been produced. In other words, calling this function on a frame 00516 * should be the last operation you do with that frame before freeing 00517 * it (or exiting the block, if the frame is on the stack.) 00518 */ 00519 struct ast_frame *ast_frisolate(struct ast_frame *fr); 00520 00521 /*! \brief Copies a frame 00522 * \param fr frame to copy 00523 * Duplicates a frame -- should only rarely be used, typically frisolate is good enough 00524 * \return Returns a frame on success, NULL on error 00525 */ 00526 struct ast_frame *ast_frdup(const struct ast_frame *fr); 00527 00528 void ast_swapcopy_samples(void *dst, const void *src, int samples); 00529 00530 /* Helpers for byteswapping native samples to/from 00531 little-endian and big-endian. */ 00532 #if __BYTE_ORDER == __LITTLE_ENDIAN 00533 #define ast_frame_byteswap_le(fr) do { ; } while(0) 00534 #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) 00535 #else 00536 #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) 00537 #define ast_frame_byteswap_be(fr) do { ; } while(0) 00538 #endif 00539 00540 /*! \brief Parse an "allow" or "deny" line in a channel or device configuration 00541 and update the capabilities and pref if provided. 00542 Video codecs are not added to codec preference lists, since we can not transcode 00543 \return Returns number of errors encountered during parsing 00544 */ 00545 int ast_parse_allow_disallow(struct ast_codec_pref *pref, struct ast_format_cap *cap, const char *list, int allowing); 00546 00547 /*! \name AST_Smoother 00548 */ 00549 /*@{ */ 00550 /*! \page ast_smooth The AST Frame Smoother 00551 The ast_smoother interface was designed specifically 00552 to take frames of variant sizes and produce frames of a single expected 00553 size, precisely what you want to do. 00554 00555 The basic interface is: 00556 00557 - Initialize with ast_smoother_new() 00558 - Queue input frames with ast_smoother_feed() 00559 - Get output frames with ast_smoother_read() 00560 - when you're done, free the structure with ast_smoother_free() 00561 - Also see ast_smoother_test_flag(), ast_smoother_set_flags(), ast_smoother_get_flags(), ast_smoother_reset() 00562 */ 00563 struct ast_smoother; 00564 00565 struct ast_smoother *ast_smoother_new(int bytes); 00566 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags); 00567 int ast_smoother_get_flags(struct ast_smoother *smoother); 00568 int ast_smoother_test_flag(struct ast_smoother *s, int flag); 00569 void ast_smoother_free(struct ast_smoother *s); 00570 void ast_smoother_reset(struct ast_smoother *s, int bytes); 00571 00572 /*! 00573 * \brief Reconfigure an existing smoother to output a different number of bytes per frame 00574 * \param s the smoother to reconfigure 00575 * \param bytes the desired number of bytes per output frame 00576 * \return nothing 00577 * 00578 */ 00579 void ast_smoother_reconfigure(struct ast_smoother *s, int bytes); 00580 00581 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap); 00582 struct ast_frame *ast_smoother_read(struct ast_smoother *s); 00583 #define ast_smoother_feed(s,f) __ast_smoother_feed(s, f, 0) 00584 #if __BYTE_ORDER == __LITTLE_ENDIAN 00585 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 1) 00586 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 0) 00587 #else 00588 #define ast_smoother_feed_be(s,f) __ast_smoother_feed(s, f, 0) 00589 #define ast_smoother_feed_le(s,f) __ast_smoother_feed(s, f, 1) 00590 #endif 00591 /*@} Doxygen marker */ 00592 00593 void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix); 00594 00595 /*! \brief Returns the number of samples contained in the frame */ 00596 int ast_codec_get_samples(struct ast_frame *f); 00597 00598 /*! \brief Returns the number of bytes for the number of samples of the given format */ 00599 int ast_codec_get_len(struct ast_format *format, int samples); 00600 00601 /*! \brief Appends a frame to the end of a list of frames, truncating the maximum length of the list */ 00602 struct ast_frame *ast_frame_enqueue(struct ast_frame *head, struct ast_frame *f, int maxlen, int dupe); 00603 00604 00605 /*! \brief Gets duration in ms of interpolation frame for a format */ 00606 static inline int ast_codec_interp_len(struct ast_format *format) 00607 { 00608 return (format->id == AST_FORMAT_ILBC) ? 30 : 20; 00609 } 00610 00611 /*! 00612 \brief Adjusts the volume of the audio samples contained in a frame. 00613 \param f The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR) 00614 \param adjustment The number of dB to adjust up or down. 00615 \return 0 for success, non-zero for an error 00616 */ 00617 int ast_frame_adjust_volume(struct ast_frame *f, int adjustment); 00618 00619 /*! 00620 \brief Sums two frames of audio samples. 00621 \param f1 The first frame (which will contain the result) 00622 \param f2 The second frame 00623 \return 0 for success, non-zero for an error 00624 00625 The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples, 00626 and must contain the same number of samples. 00627 */ 00628 int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2); 00629 00630 /*! 00631 * \brief Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR 00632 */ 00633 int ast_frame_clear(struct ast_frame *frame); 00634 00635 /*! 00636 * \brief Copy the discription of a frame's subclass into the provided string 00637 * 00638 * \param f The frame to get the information from 00639 * \param subclass Buffer to fill with subclass information 00640 * \param slen Length of subclass buffer 00641 * \param moreinfo Buffer to fill with additional information 00642 * \param mlen Length of moreinfo buffer 00643 * \since 11 00644 */ 00645 void ast_frame_subclass2str(struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen); 00646 00647 /*! 00648 * \brief Copy the discription of a frame type into the provided string 00649 * 00650 * \param frame_type The frame type to be described 00651 * \param ftype Buffer to fill with frame type description 00652 * \param len Length of subclass buffer 00653 * \since 11 00654 */ 00655 void ast_frame_type2str(enum ast_frame_type frame_type, char *ftype, size_t len); 00656 00657 #if defined(__cplusplus) || defined(c_plusplus) 00658 } 00659 #endif 00660 00661 #endif /* _ASTERISK_FRAME_H */