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

Generated on Fri Oct 31 07:05:06 2003 for Asterisk by doxygen 1.3.4