Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

frame.h

Go to the documentation of this file.
00001 /* 00002 * Asterisk -- A telephony toolkit for Linux. 00003 * 00004 * Asterisk internal frame definitions. 00005 * 00006 * Copyright (C) 1999, Mark Spencer 00007 * 00008 * Mark Spencer <markster@linux-support.net> 00009 * 00010 * This program is free software, distributed under the terms of 00011 * the GNU Lesser General Public License. Other components of 00012 * Asterisk are distributed under The GNU General Public License 00013 * only. 00014 */ 00015 00016 #ifndef _ASTERISK_FRAME_H 00017 #define _ASTERISK_FRAME_H 00018 00019 #if defined(__cplusplus) || defined(c_plusplus) 00020 extern "C" { 00021 #endif 00022 00023 #include <sys/types.h> 00024 #include <sys/time.h> 00025 00026 /* 00027 * Autodetect system endianess 00028 */ 00029 #ifndef __BYTE_ORDER 00030 #ifdef __linux__ 00031 #include <endian.h> 00032 #elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) 00033 #if defined(__OpenBSD__) 00034 #include <machine/types.h> 00035 #endif /* __OpenBSD__ */ 00036 #include <machine/endian.h> 00037 #define __BYTE_ORDER BYTE_ORDER 00038 #define __LITTLE_ENDIAN LITTLE_ENDIAN 00039 #define __BIG_ENDIAN BIG_ENDIAN 00040 #else 00041 #ifdef __LITTLE_ENDIAN__ 00042 #define __BYTE_ORDER __LITTLE_ENDIAN 00043 #endif /* __LITTLE_ENDIAN */ 00044 00045 #if defined(i386) || defined(__i386__) 00046 #define __BYTE_ORDER __LITTLE_ENDIAN 00047 #endif /* defined i386 */ 00048 00049 #if defined(sun) && defined(unix) && defined(sparc) 00050 #define __BYTE_ORDER __BIG_ENDIAN 00051 #endif /* sun unix sparc */ 00052 00053 #endif /* linux */ 00054 00055 #endif /* __BYTE_ORDER */ 00056 00057 #ifndef __BYTE_ORDER 00058 #error Need to know endianess 00059 #endif /* __BYTE_ORDER */ 00060 00061 //! Data structure associated with a single frame of data 00062 /* A frame of data read used to communicate between 00063 between channels and applications */ 00064 struct ast_frame { 00065 /*! Kind of frame */ 00066 int frametype; 00067 /*! Subclass, frame dependent */ 00068 int subclass; 00069 /*! Length of data */ 00070 int datalen; 00071 /*! Number of 8khz samples in this frame */ 00072 int samples; 00073 /*! Was the data malloc'd? i.e. should we free it when we discard the frame? */ 00074 int mallocd; 00075 /*! How far into "data" the data really starts */ 00076 int offset; 00077 /*! Optional source of frame for debugging */ 00078 char *src; 00079 /*! Pointer to actual data */ 00080 void *data; 00081 /*! Global delivery time */ 00082 struct timeval delivery; 00083 /*! Next/Prev for linking stand alone frames */ 00084 struct ast_frame *prev; 00085 /*! Next/Prev for linking stand alone frames */ 00086 struct ast_frame *next; 00087 /* Unused except if debugging is turned on, but left 00088 in the struct so that it can be turned on without 00089 requiring a recompile of the whole thing */ 00090 }; 00091 00092 struct ast_frame_chain { 00093 /* XXX Should ast_frame chain's be just prt of frames, i.e. should they just link? XXX */ 00094 struct ast_frame *fr; 00095 struct ast_frame_chain *next; 00096 }; 00097 00098 #define AST_FRIENDLY_OFFSET 64 /*! It's polite for a a new frame to 00099 have this number of bytes for additional 00100 headers. */ 00101 #define AST_MIN_OFFSET 32 /*! Make sure we keep at least this much handy */ 00102 00103 /*! Need the header be free'd? */ 00104 #define AST_MALLOCD_HDR (1 << 0) 00105 /*! Need the data be free'd? */ 00106 #define AST_MALLOCD_DATA (1 << 1) 00107 /*! Need the source be free'd? (haha!) */ 00108 #define AST_MALLOCD_SRC (1 << 2) 00109 00110 /* Frame types */ 00111 /*! A DTMF digit, subclass is the digit */ 00112 #define AST_FRAME_DTMF 1 00113 /*! Voice data, subclass is AST_FORMAT_* */ 00114 #define AST_FRAME_VOICE 2 00115 /*! Video frame, maybe?? :) */ 00116 #define AST_FRAME_VIDEO 3 00117 /*! A control frame, subclass is AST_CONTROL_* */ 00118 #define AST_FRAME_CONTROL 4 00119 /*! An empty, useless frame */ 00120 #define AST_FRAME_NULL 5 00121 /*! Inter Aterisk Exchange private frame type */ 00122 #define AST_FRAME_IAX 6 00123 /*! Text messages */ 00124 #define AST_FRAME_TEXT 7 00125 /*! Image Frames */ 00126 #define AST_FRAME_IMAGE 8 00127 /*! HTML Frame */ 00128 #define AST_FRAME_HTML 9 00129 00130 /* HTML subclasses */ 00131 /*! Sending a URL */ 00132 #define AST_HTML_URL 1 00133 /*! Data frame */ 00134 #define AST_HTML_DATA 2 00135 /*! Beginning frame */ 00136 #define AST_HTML_BEGIN 4 00137 /*! End frame */ 00138 #define AST_HTML_END 8 00139 /*! Load is complete */ 00140 #define AST_HTML_LDCOMPLETE 16 00141 /*! Peer is unable to support HTML */ 00142 #define AST_HTML_NOSUPPORT 17 00143 /*! Send URL, and track */ 00144 #define AST_HTML_LINKURL 18 00145 /*! No more HTML linkage */ 00146 #define AST_HTML_UNLINK 19 00147 /*! Reject link request */ 00148 #define AST_HTML_LINKREJECT 20 00149 00150 /* Data formats for capabilities and frames alike */ 00151 /*! G.723.1 compression */ 00152 #define AST_FORMAT_G723_1 (1 << 0) 00153 /*! GSM compression */ 00154 #define AST_FORMAT_GSM (1 << 1) 00155 /*! Raw mu-law data (G.711) */ 00156 #define AST_FORMAT_ULAW (1 << 2) 00157 /*! Raw A-law data (G.711) */ 00158 #define AST_FORMAT_ALAW (1 << 3) 00159 /*! ADPCM (G.726, 32kbps) */ 00160 #define AST_FORMAT_G726 (1 << 4) 00161 /*! ADPCM (IMA) */ 00162 #define AST_FORMAT_ADPCM (1 << 5) 00163 /*! Raw 16-bit Signed Linear (8000 Hz) PCM */ 00164 #define AST_FORMAT_SLINEAR (1 << 6) 00165 /*! LPC10, 180 samples/frame */ 00166 #define AST_FORMAT_LPC10 (1 << 7) 00167 /*! G.729A audio */ 00168 #define AST_FORMAT_G729A (1 << 8) 00169 /*! SpeeX Free Compression */ 00170 #define AST_FORMAT_SPEEX (1 << 9) 00171 /*! iLBC Free Compression */ 00172 #define AST_FORMAT_ILBC (1 << 10) 00173 /*! Maximum audio format */ 00174 #define AST_FORMAT_MAX_AUDIO (1 << 15) 00175 /*! JPEG Images */ 00176 #define AST_FORMAT_JPEG (1 << 16) 00177 /*! PNG Images */ 00178 #define AST_FORMAT_PNG (1 << 17) 00179 /*! H.261 Video */ 00180 #define AST_FORMAT_H261 (1 << 18) 00181 /*! H.263 Video */ 00182 #define AST_FORMAT_H263 (1 << 19) 00183 /*! Max one */ 00184 #define AST_FORMAT_MAX_VIDEO (1 << 24) 00185 00186 /* Control frame types */ 00187 /*! Other end has hungup */ 00188 #define AST_CONTROL_HANGUP 1 00189 /*! Local ring */ 00190 #define AST_CONTROL_RING 2 00191 /*! Remote end is ringing */ 00192 #define AST_CONTROL_RINGING 3 00193 /*! Remote end has answered */ 00194 #define AST_CONTROL_ANSWER 4 00195 /*! Remote end is busy */ 00196 #define AST_CONTROL_BUSY 5 00197 /*! Make it go off hook */ 00198 #define AST_CONTROL_TAKEOFFHOOK 6 00199 /*! Line is off hook */ 00200 #define AST_CONTROL_OFFHOOK 7 00201 /*! Congestion (circuits busy) */ 00202 #define AST_CONTROL_CONGESTION 8 00203 /*! Flash hook */ 00204 #define AST_CONTROL_FLASH 9 00205 /*! Wink */ 00206 #define AST_CONTROL_WINK 10 00207 /*! Set a low-level option */ 00208 #define AST_CONTROL_OPTION 11 00209 /*! Key Radio */ 00210 #define AST_CONTROL_RADIO_KEY 12 00211 /*! Un-Key Radio */ 00212 #define AST_CONTROL_RADIO_UNKEY 13 00213 /*! Indicate CALL_PROCEEDING or PROGRESS */ 00214 #define AST_CONTROL_PROGRESS 14 00215 00216 #define AST_SMOOTHER_FLAG_G729 (1 << 0) 00217 00218 /* Option identifiers and flags */ 00219 #define AST_OPTION_FLAG_REQUEST 0 00220 #define AST_OPTION_FLAG_ACCEPT 1 00221 #define AST_OPTION_FLAG_REJECT 2 00222 #define AST_OPTION_FLAG_QUERY 4 00223 #define AST_OPTION_FLAG_ANSWER 5 00224 #define AST_OPTION_FLAG_WTF 6 00225 00226 /* Verify touchtones by muting audio transmission 00227 (and reception) and verify the tone is still present */ 00228 #define AST_OPTION_TONE_VERIFY 1 00229 00230 /* Put a compatible channel into TDD (TTY for the hearing-impared) mode */ 00231 #define AST_OPTION_TDD 2 00232 00233 /* Relax the parameters for DTMF reception (mainly for radio use) */ 00234 #define AST_OPTION_RELAXDTMF 3 00235 00236 /* Set (or clear) Audio (Not-Clear) Mode */ 00237 #define AST_OPTION_AUDIO_MODE 4 00238 00239 struct ast_option_header { 00240 /* Always keep in network byte order */ 00241 #if __BYTE_ORDER == __BIG_ENDIAN 00242 u_int16_t flag:3; 00243 u_int16_t option:13; 00244 #else 00245 #if __BYTE_ORDER == __LITTLE_ENDIAN 00246 u_int16_t option:13; 00247 u_int16_t flag:3; 00248 #else 00249 #error Byte order not defined 00250 #endif 00251 #endif 00252 u_int8_t data[0]; 00253 }; 00254 00255 // Requests a frame to be allocated 00256 /* 00257 * \param source 00258 * Request a frame be allocated. source is an optional source of the frame, 00259 * len is the requested length, or "0" if the caller will supply the buffer 00260 */ 00261 #if 0 /* Unimplemented */ 00262 struct ast_frame *ast_fralloc(char *source, int len); 00263 #endif 00264 00265 //! Frees a frame 00266 /*! 00267 * \param fr Frame to free 00268 * Free a frame, and the memory it used if applicable 00269 * no return. 00270 */ 00271 void ast_frfree(struct ast_frame *fr); 00272 00273 //! Copies a frame 00274 /*! 00275 * \param fr frame to act upon 00276 * Take a frame, and if it's not been malloc'd, make a malloc'd copy 00277 * and if the data hasn't been malloced then make the 00278 * data malloc'd. If you need to store frames, say for queueing, then 00279 * you should call this function. 00280 * Returns a frame on success, NULL on error 00281 */ 00282 struct ast_frame *ast_frisolate(struct ast_frame *fr); 00283 00284 //! Copies a frame 00285 /*! 00286 * \param fr frame to copy 00287 * Dupliates a frame -- should only rarely be used, typically frisolate is good enough 00288 * Returns a frame on success, NULL on error 00289 */ 00290 struct ast_frame *ast_frdup(struct ast_frame *fr); 00291 00292 //! Chains a frame -- unimplemented 00293 #if 0 /* unimplemented */ 00294 void ast_frchain(struct ast_frame_chain *fc); 00295 #endif 00296 00297 //! Reads a frame from an fd 00298 /*! 00299 * \param fd an opened fd to read from 00300 * Read a frame from a stream or packet fd, as written by fd_write 00301 * returns a frame on success, NULL on error 00302 */ 00303 struct ast_frame *ast_fr_fdread(int fd); 00304 00305 //! Writes a frame to an fd 00306 /*! 00307 * \param fd Which fd to write to 00308 * \param frame frame to write to the fd 00309 * Write a frame to an fd 00310 * Returns 0 on success, -1 on failure 00311 */ 00312 int ast_fr_fdwrite(int fd, struct ast_frame *frame); 00313 00314 //! Sends a hangup to an fd 00315 /*! 00316 * \param fd fd to write to 00317 * Send a hangup (NULL equivalent) on an fd 00318 * Returns 0 on success, -1 on failure 00319 */ 00320 int ast_fr_fdhangup(int fd); 00321 00322 //! Get the name of a format 00323 /*! 00324 * \param format id of format 00325 * \return A static string containing the name of the format or "UNKN" if unknown. 00326 */ 00327 extern char* ast_getformatname(int format); 00328 00329 //! Get the names of a set of formats 00330 /*! 00331 * \param buf a buffer for the output string 00332 * \param n size of buf (bytes) 00333 * \param format the format (combined IDs of codecs) 00334 * Prints a list of readable codec names corresponding to "format". 00335 * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602(GSM|SPEEX|ILBC)" 00336 * \return The return value is buf. 00337 */ 00338 extern char* ast_getformatname_multiple(char *buf, unsigned n, int format); 00339 00340 00341 /*! 00342 * \param name string of format 00343 * Gets a format from a name. 00344 * This returns the form of the format in binary on success, 0 on error. 00345 */ 00346 extern int ast_getformatbyname(char *name); 00347 00348 //! Get a name from a format 00349 /*! 00350 * \param codec codec number (1,2,4,8,16,etc.) 00351 * Gets a name from a format 00352 * This returns a static string identifying the format on success, 0 on error. 00353 */ 00354 extern char *ast_codec2str(int codec); 00355 00356 //! Pick the best codec 00357 /* Choose the best codec... Uhhh... Yah. */ 00358 extern int ast_best_codec(int fmts); 00359 00360 struct ast_smoother; 00361 00362 extern struct ast_smoother *ast_smoother_new(int bytes); 00363 extern void ast_smoother_set_flags(struct ast_smoother *smoother, int flags); 00364 extern int ast_smoother_get_flags(struct ast_smoother *smoother); 00365 extern void ast_smoother_free(struct ast_smoother *s); 00366 extern void ast_smoother_reset(struct ast_smoother *s, int bytes); 00367 extern int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f); 00368 extern struct ast_frame *ast_smoother_read(struct ast_smoother *s); 00369 00370 extern void ast_frame_dump(char *name, struct ast_frame *f, char *prefix); 00371 00372 #if defined(__cplusplus) || defined(c_plusplus) 00373 } 00374 #endif 00375 00376 00377 #endif

Generated on Sat Jun 12 16:40:58 2004 for Asterisk by doxygen 1.3.7