Sat Mar 26 11:08:06 2011

Asterisk developer's documentation


res_fax.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2008-2009, Digium, Inc.
00005  *
00006  * Dwayne M. Hubbard <dhubbard@digium.com>
00007  * Kevin P. Fleming <kpfleming@digium.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 #ifndef _ASTERISK_RES_FAX_H
00021 #define _ASTERISK_RES_FAX_H
00022 
00023 #include <asterisk.h>
00024 #include <asterisk/lock.h>
00025 #include <asterisk/linkedlists.h>
00026 #include <asterisk/module.h>
00027 #include <asterisk/utils.h>
00028 #include <asterisk/options.h>
00029 #include <asterisk/frame.h>
00030 #include <asterisk/cli.h>
00031 #include <asterisk/stringfields.h>
00032 
00033 /*! \brief capabilities for res_fax to locate a fax technology module */
00034 enum ast_fax_capabilities {
00035    /*! SendFax is supported */
00036    AST_FAX_TECH_SEND      = (1 << 0),
00037    /*! ReceiveFax is supported */
00038    AST_FAX_TECH_RECEIVE   = (1 << 1),
00039    /*! Audio FAX session supported */
00040    AST_FAX_TECH_AUDIO     = (1 << 2),
00041    /*! T.38 FAX session supported */
00042    AST_FAX_TECH_T38       = (1 << 3),
00043    /*! sending mulitple documents supported */
00044    AST_FAX_TECH_MULTI_DOC = (1 << 4),
00045 };
00046 
00047 /*! \brief fax modem capabilities */
00048 enum ast_fax_modems {
00049    /*! V.17 */
00050    AST_FAX_MODEM_V17 = (1 << 0),
00051    /*! V.27 */
00052    AST_FAX_MODEM_V27 = (1 << 1),
00053    /*! V.29 */
00054    AST_FAX_MODEM_V29 = (1 << 2),
00055    /*! V.34 */
00056    AST_FAX_MODEM_V34 = (1 << 3),
00057 };
00058 
00059 /*! \brief current state of a fax session */
00060 enum ast_fax_state {
00061    /*! uninitialized state */
00062    AST_FAX_STATE_UNINITIALIZED = 0,
00063    /*! initialized state */
00064    AST_FAX_STATE_INITIALIZED,
00065    /*! fax resources open state */
00066    AST_FAX_STATE_OPEN,
00067    /*! fax session in progress */
00068    AST_FAX_STATE_ACTIVE,
00069    /*! fax session complete */
00070    AST_FAX_STATE_COMPLETE,
00071 };
00072 
00073 /*! \brief fax session options */
00074 enum ast_fax_optflag {
00075    /*! false/disable configuration override */
00076    AST_FAX_OPTFLAG_FALSE = 0,
00077    /*! true/enable configuration override */
00078    AST_FAX_OPTFLAG_TRUE,
00079    /*! use the configured default */
00080    AST_FAX_OPTFLAG_DEFAULT,
00081 };
00082 
00083 struct ast_fax_t38_parameters {
00084    unsigned int version;               /*!< Supported T.38 version */
00085    unsigned int max_ifp;               /*!< Maximum IFP size supported */
00086    enum ast_control_t38_rate rate;           /*!< Maximum fax rate supported */
00087    enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
00088    unsigned int fill_bit_removal:1;       /*!< Set if fill bit removal can be used */
00089    unsigned int transcoding_mmr:1;           /*!< Set if MMR transcoding can be used */
00090    unsigned int transcoding_jbig:1;       /*!< Set if JBIG transcoding can be used */
00091 };
00092 
00093 struct ast_fax_document {
00094    AST_LIST_ENTRY(ast_fax_document) next;
00095    char filename[0];
00096 };
00097 
00098 AST_LIST_HEAD_NOLOCK(ast_fax_documents, ast_fax_document);
00099 
00100 /*! \brief The data communicated between the high level applications and the generic fax function */
00101 struct ast_fax_session_details {
00102    /*! fax session capability requirements.  The caps field is used to select
00103     * the proper fax technology module before the session starts */
00104    enum ast_fax_capabilities caps;
00105    /*! modem requirement for the session */
00106    enum ast_fax_modems modems;
00107    /*! session id */
00108    unsigned int id;
00109    /*! document(s) to be sent/received */
00110    struct ast_fax_documents documents;
00111    AST_DECLARE_STRING_FIELDS(
00112       /*! resolution negotiated during the fax session.  This is stored in the
00113        * FAXRESOLUTION channel variable when the fax session completes */
00114       AST_STRING_FIELD(resolution);
00115       /*! transfer rate negotiated during the fax session.  This is stored in the
00116        * FAXBITRATE channel variable when the fax session completes */
00117       AST_STRING_FIELD(transfer_rate);
00118       /*! local station identification.  This is set from the LOCALSTATIONID
00119        * channel variable before the fax session starts */
00120       AST_STRING_FIELD(localstationid);
00121       /*! remote station identification.  This is stored in the REMOTESTATIONID
00122        * channel variable after the fax session completes */
00123       AST_STRING_FIELD(remotestationid);
00124       /*! headerinfo variable is set from the LOCALHEADERINFO channel variable
00125        * before the fax session starts */
00126       AST_STRING_FIELD(headerinfo);
00127       /*! the result of the fax session */
00128       AST_STRING_FIELD(result);
00129       /*! a more descriptive result string of the fax session */
00130       AST_STRING_FIELD(resultstr);
00131       /*! the error reason of the fax session */
00132       AST_STRING_FIELD(error);
00133    );
00134    /*! the number of pages sent/received during a fax session */
00135    unsigned int pages_transferred;
00136    /*! session details flags for options */
00137    union {
00138       /*! dontuse dummy variable - do not ever use */ 
00139       uint32_t dontuse;
00140       struct {
00141          /*! flag to send debug manager events */
00142          uint32_t debug:2;
00143          /*! flag indicating the use of Error Correction Mode (ECM) */
00144          uint32_t ecm:1;
00145          /*! flag indicating the sending of status manager events */
00146          uint32_t statusevents:2;
00147          /*! allow audio mode FAX on T.38-capable channels */
00148          uint32_t allow_audio:2;
00149          /*! indicating the session switched to T38 */
00150          uint32_t switch_to_t38:1;
00151          /*! flag indicating whether CED should be sent (for receive mode) */
00152          uint32_t send_ced:1;
00153          /*! flag indicating whether CNG should be sent (for send mode) */
00154          uint32_t send_cng:1;
00155          /*! send a T.38 reinvite */
00156          uint32_t request_t38:1;
00157       };
00158    } option;
00159    /*! override the minimum transmission rate with a channel variable */
00160    unsigned int minrate;
00161    /*! override the maximum transmission rate with a channel varialbe */
00162    unsigned int maxrate;
00163    /*! our T.38 session parameters, if any */
00164    struct ast_fax_t38_parameters our_t38_parameters;
00165    /*! the other endpoint's T.38 session parameters, if any */
00166    struct ast_fax_t38_parameters their_t38_parameters;
00167 };
00168 
00169 struct ast_fax_tech;
00170 struct ast_fax_debug_info;
00171    
00172 /*! \brief The data required to handle a fax session */
00173 struct ast_fax_session {
00174    /*! session id */
00175    unsigned int id;
00176    /*! session file descriptor */
00177    int fd;
00178    /*! fax session details structure */
00179    struct ast_fax_session_details *details;
00180    /*! fax frames received */
00181    unsigned long frames_received;
00182    /*! fax frames sent */
00183    unsigned long frames_sent;
00184    /*! the fax technology callbacks */
00185    const struct ast_fax_tech *tech;
00186    /*! private implementation pointer */
00187    void *tech_pvt;
00188    /*! fax state */
00189    enum ast_fax_state state;
00190    /*! name of the Asterisk channel using the fax session */
00191    char *channame;
00192    /*! unique ID of the Asterisk channel using the fax session */
00193    char *chan_uniqueid;
00194    /*! Asterisk channel using the fax session */
00195    struct ast_channel *chan;
00196    /*! fax debugging structure */
00197    struct ast_fax_debug_info *debug_info;
00198    /*! used to take variable-sized frames in and output frames of an expected size to the fax stack */
00199    struct ast_smoother *smoother;
00200 };
00201 
00202 struct ast_fax_tech_token;
00203 
00204 /*! \brief used to register a FAX technology module with res_fax */
00205 struct ast_fax_tech {
00206    /*! the type of fax session supported with this ast_fax_tech structure */
00207    const char * const type;
00208    /*! a short description of the fax technology */
00209    const char * const description;
00210    /*! version string of the technology module */
00211    const char * const version;
00212    /*! the ast_fax_capabilities supported by the fax technology */
00213    const enum ast_fax_capabilities caps;
00214    /*! module information for the fax technology */
00215    struct ast_module *module;
00216    /*! reserves a session for future use; returns a token */
00217    struct ast_fax_tech_token *(* const reserve_session)(struct ast_fax_session *);
00218    /*! releases an unused session token */
00219    void (* const release_token)(struct ast_fax_tech_token *);
00220    /*! creates a new fax session, optionally using a previously-reserved token */
00221    void *(* const new_session)(struct ast_fax_session *, struct ast_fax_tech_token *);
00222    /*! destroys an existing fax session */
00223    void (* const destroy_session)(struct ast_fax_session *);
00224    /*! sends an Asterisk frame to res_fax */
00225    struct ast_frame *(* const read)(struct ast_fax_session *);
00226    /*! writes an Asterisk frame to the fax session */
00227    int (* const write)(struct ast_fax_session *, const struct ast_frame *);
00228    /*! starts the fax session */
00229    int (* const start_session)(struct ast_fax_session *);
00230    /*! cancels a fax session */
00231    int (* const cancel_session)(struct ast_fax_session *);
00232    /*! initiates the generation of silence to the fax session */
00233    int (* const generate_silence)(struct ast_fax_session *);
00234    /*! switches an existing dual-mode session from audio to T.38 */
00235    int (* const switch_to_t38)(struct ast_fax_session *);
00236    /*! displays capabilities of the fax technology */
00237    char * (* const cli_show_capabilities)(int);
00238    /*! displays details about the fax session */
00239    char * (* const cli_show_session)(struct ast_fax_session *, int);
00240    /*! displays statistics from the fax technology module */
00241    char * (* const cli_show_stats)(int);
00242    /*! displays settings from the fax technology module */
00243    char * (* const cli_show_settings)(int);
00244 };
00245   
00246 /*! \brief register a fax technology */
00247 int ast_fax_tech_register(struct ast_fax_tech *tech);
00248 
00249 /*! \brief unregister a fax technology */
00250 void ast_fax_tech_unregister(struct ast_fax_tech *tech);
00251 
00252 /*! \brief get the minimum supported fax rate */
00253 unsigned int ast_fax_minrate(void);
00254 
00255 /*! \brief get the maxiumum supported fax rate */
00256 unsigned int ast_fax_maxrate(void);
00257 
00258 /*! \brief convert an ast_fax_state to a string */
00259 const char *ast_fax_state_to_str(enum ast_fax_state state);
00260 
00261 /*!
00262  * \brief Log message at FAX or recommended level
00263  *
00264  * The first four parameters can be represented with Asterisk's
00265  * LOG_* levels. In other words, this function may be called
00266  * like
00267  *
00268  * ast_fax_log(LOG_DEBUG, msg);
00269  */
00270 void ast_fax_log(int level, const char *file, const int line, const char *function, const char *msg);
00271 
00272 #endif

Generated on Sat Mar 26 11:08:07 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9