/* * CallWeaver -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * Mark Spencer * * See http://www.callweaver.org for more information about * the CallWeaver project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. */ /*! \file * \brief Translate via the use of pseudo channels */ #ifndef _CALLWEAVER_TRANSLATE_H #define _CALLWEAVER_TRANSLATE_H #define MAX_FORMAT 32 #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif #include "callweaver/object.h" #include "callweaver/registry.h" #include "callweaver/module.h" #include "callweaver/frame.h" typedef struct cw_translator cw_translator_t; extern CW_API_PUBLIC const struct cw_object_isa cw_object_isa_translator; extern CW_API_PUBLIC struct cw_registry translator_registry; #define cw_translator_register(ptr) ({ \ const typeof(ptr) __ptr = (ptr); \ /* We know 0 refs means not initialized because we know how objs work \ * internally and we know that registration only happens while the \ * module lock is held. \ */ \ if (!cw_object_refs(__ptr)) \ cw_object_init_obj(&__ptr->obj, &cw_object_isa_translator, CW_OBJECT_CURRENT_MODULE, 0); \ __ptr->reg_entry = cw_registry_add(&translator_registry, 0, &__ptr->obj); \ 0; \ }) #define cw_translator_unregister(ptr) ({ \ const typeof(ptr) __ptr = (ptr); \ if (__ptr->reg_entry) \ cw_registry_del(&translator_registry, __ptr->reg_entry); \ 0; \ }) struct cw_trans_pvt; extern int cw_translator_init(void); /*! Chooses the best translation path */ /*! * Given a list of sources, and a designed destination format, which should I choose? Returns 0 on success, -1 if no path could be found. Modifies dests and srcs in place */ extern CW_API_PUBLIC int cw_translator_best_choice(int *dsts, int *srcs); /*!Builds a translator path */ /*! * \param dest destination format * \param source source format * Build a path (possibly NULL) from source to dest * Returns cw_trans_pvt on success, NULL on failure * */ extern CW_API_PUBLIC struct cw_trans_pvt *cw_translator_build_path(int dest, int dest_rate, int source, int source_rate); /*! Frees a translator path */ /*! * \param tr translator path to get rid of * Frees the given translator path structure */ extern CW_API_PUBLIC void cw_translator_free_path(struct cw_trans_pvt *tr); /*! translates one or more frames */ /*! * \param tr translator structure to use for translation * \param f frame to translate * \param consume Whether or not to free the original frame * Apply an input frame into the translator and receive zero or one output frames. Consume * determines whether the original frame should be freed * Returns an cw_frame of the new translation format on success, NULL on failure */ extern CW_API_PUBLIC struct cw_frame *cw_translate(struct cw_trans_pvt *tr, struct cw_frame *f, int consume); #if defined(__cplusplus) || defined(c_plusplus) } #endif #endif /* _CALLWEAVER_TRANSLATE_H */