Asterisk - The Open Source Telephony Project
21.4.1
|
Translate via the use of pseudo channels. More...
#include "asterisk.h"
#include <sys/time.h>
#include <sys/resource.h>
#include <math.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/format.h"
#include "asterisk/linkedlists.h"
Go to the source code of this file.
Data Structures | |
struct | translator_path |
struct | translators |
the list of translators More... | |
Macros | |
#define | format_sample_rate_absdiff(fmt1, fmt2) |
#define | GROW_INDEX 16 |
#define | INIT_INDEX 32 |
#define | MAX_RECALC 1000 |
Functions | |
int | __ast_register_translator (struct ast_translator *t, struct ast_module *mod) |
register codec translator More... | |
static int | add_codec2index (struct ast_codec *codec) |
struct ast_frame * | ast_trans_frameout (struct ast_trans_pvt *pvt, int datalen, int samples) |
generic frameout routine. If samples and datalen are 0, take whatever is in pvt and reset them, otherwise take the values in the caller and leave alone the pvt values. More... | |
struct ast_frame * | ast_translate (struct ast_trans_pvt *path, struct ast_frame *f, int consume) |
do the actual translation More... | |
void | ast_translate_available_formats (struct ast_format_cap *dest, struct ast_format_cap *src, struct ast_format_cap *result) |
Find available formats. More... | |
int | ast_translate_init (void) |
Initialize the translation matrix and index to format conversion table. More... | |
unsigned int | ast_translate_path_steps (struct ast_format *dst_format, struct ast_format *src_format) |
Returns the number of steps required to convert from 'src' to 'dest'. More... | |
const char * | ast_translate_path_to_str (struct ast_trans_pvt *p, struct ast_str **str) |
Puts a string representation of the translation path into outbuf. More... | |
void | ast_translator_activate (struct ast_translator *t) |
Activate a previously deactivated translator. More... | |
int | ast_translator_best_choice (struct ast_format_cap *dst_cap, struct ast_format_cap *src_cap, struct ast_format **dst_fmt_out, struct ast_format **src_fmt_out) |
Calculate our best translator source format, given costs, and a desired destination. More... | |
struct ast_trans_pvt * | ast_translator_build_path (struct ast_format *dst, struct ast_format *src) |
Build a chain of translators based upon the given source and dest formats. More... | |
void | ast_translator_deactivate (struct ast_translator *t) |
Deactivate a translator. More... | |
void | ast_translator_free_path (struct ast_trans_pvt *p) |
Frees a translator path Frees the given translator path structure. More... | |
int | ast_unregister_translator (struct ast_translator *t) |
unregister codec translator More... | |
static void | check_translation_path (struct ast_format_cap *dest, struct ast_format_cap *src, struct ast_format_cap *result, struct ast_format *src_fmt, enum ast_media_type type) |
static int | codec2index (struct ast_codec *codec) |
static void | codec_append_name (const struct ast_codec *codec, struct ast_str **buf) |
static int | codec_to_index (unsigned int id) |
static char * | complete_trans_path_choice (const char *word) |
static struct ast_frame * | default_frameout (struct ast_trans_pvt *pvt) |
static void | destroy (struct ast_trans_pvt *pvt) |
static int | format2index (struct ast_format *format) |
static int | framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
framein wrapper, deals with bound checks. | |
static void | generate_computational_cost (struct ast_translator *t, int seconds) |
static struct ast_frame * | generate_interpolated_slin (struct ast_trans_pvt *p, struct ast_frame *f) |
static int | generate_table_cost (struct ast_codec *src, struct ast_codec *dst) |
static char * | handle_cli_core_show_translation (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | handle_cli_recalc (struct ast_cli_args *a) |
static char * | handle_show_translation_path (struct ast_cli_args *a, const char *codec_name, unsigned int sample_rate) |
static char * | handle_show_translation_table (struct ast_cli_args *a) |
static struct ast_codec * | index2codec (int index) |
static void | matrix_clear (void) |
static struct translator_path * | matrix_get (unsigned int x, unsigned int y) |
static void | matrix_rebuild (int samples) |
rebuild a translation matrix. More... | |
static int | matrix_resize (int init) |
static struct ast_trans_pvt * | newpvt (struct ast_translator *t, struct ast_format *explicit_dst) |
Allocate the descriptor, required outbuf space, and possibly desc. | |
static void | translate_shutdown (void) |
Variables | |
static unsigned int * | __indextable |
table for converting index to format values. More... | |
static struct translator_path ** | __matrix |
a matrix that, for any pair of supported formats, indicates the total cost of translation and the first step. The full path can be reconstructed iterating on the matrix until step->dstfmt == desired_format. More... | |
static struct ast_cli_entry | cli_translate [] |
static int | cur_max_index |
static int | index_size |
static ast_rwlock_t | tablelock |
static struct translators | translators = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
Translate via the use of pseudo channels.
Definition in file translate.c.
#define format_sample_rate_absdiff | ( | fmt1, | |
fmt2 | |||
) |
Calculate the absolute difference between sample rate of two formats.
Definition at line 1395 of file translate.c.
Referenced by ast_translator_best_choice().
#define MAX_RECALC 1000 |
max sample recalc
Definition at line 54 of file translate.c.
int __ast_register_translator | ( | struct ast_translator * | t, |
struct ast_module * | mod | ||
) |
register codec translator
Register a translator This registers a codec translator with asterisk.
Definition at line 1237 of file translate.c.
References ast_translator::active, ast_codec_get(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_translator::buf_size, ast_translator::comp_cost, ast_translator::dst_codec, ast_translator::dst_fmt_index, ast_translator::frameout, matrix_rebuild(), ast_translator::module, ast_codec::name, ast_translator::name, RAII_VAR, ast_codec::sample_rate, ast_translator::src_codec, ast_translator::src_fmt_index, ast_translator::table_cost, term_color(), and ast_codec::type.
struct ast_frame* ast_trans_frameout | ( | struct ast_trans_pvt * | pvt, |
int | datalen, | ||
int | samples | ||
) |
generic frameout routine. If samples and datalen are 0, take whatever is in pvt and reset them, otherwise take the values in the caller and leave alone the pvt values.
generic frameout function
Definition at line 439 of file translate.c.
References ast_frisolate, ast_trans_pvt::c, ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, ast_trans_pvt::f, ast_frame::samples, and ast_trans_pvt::samples.
Referenced by lintoadpcm_frameout(), lintocodec2_frameout(), lintogsm_frameout(), lintoilbc_frameout(), and lintospeex_frameout().
struct ast_frame* ast_translate | ( | struct ast_trans_pvt * | path, |
struct ast_frame * | f, | ||
int | consume | ||
) |
do the actual translation
translates one or more frames Apply an input frame into the translator and receive zero or one output frames. Consume determines whether the original frame should be freed. In case the frame type is AST_FRAME_RTCP, the frame is not translated but passed to the translator codecs via the feedback callback, and a pointer to ast_null_frame is returned after that.
Definition at line 566 of file translate.c.
References ast_debug, ast_format_get_sample_rate(), AST_FRAME_CNG, AST_FRAME_RTCP, AST_FRFLAG_HAS_TIMING_INFO, AST_LIST_NEXT, ast_null_frame, ast_samp2tv(), ast_tv(), ast_tvadd(), ast_tveq(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_frame::delivery, ast_translator::feedback, ast_frame_subclass::format, framein(), ast_frame::frametype, ast_frame::len, ast_trans_pvt::next, ast_frame::samples, ast_frame::seqno, ast_frame::subclass, and ast_frame::ts.
Referenced by __ast_read(), ast_slinfactory_feed(), ast_write_stream(), ast_writestream(), and fax_gateway_framehook().
void ast_translate_available_formats | ( | struct ast_format_cap * | dest, |
struct ast_format_cap * | src, | ||
struct ast_format_cap * | result | ||
) |
Find available formats.
dest | possible destination formats | |
src | source formats | |
[out] | result | capabilities structure to store available formats in returns the destination formats that are available in the source or translatable |
The result will include all formats from 'dest' that are either present in 'src' or translatable from a format present in 'src'.
Definition at line 1616 of file translate.c.
References ao2_ref, ast_format_cap_append, ast_format_cap_count(), ast_format_cap_get_compatible_format(), ast_format_cap_get_format(), AST_RWLIST_RDLOCK, and AST_RWLIST_UNLOCK.
Referenced by ast_rtp_instance_available_formats().
int ast_translate_init | ( | void | ) |
Initialize the translation matrix and index to format conversion table.
0 | on success |
-1 | on failure |
Definition at line 1675 of file translate.c.
References ast_cli_register_multiple, ast_register_cleanup(), and ast_rwlock_init.
unsigned int ast_translate_path_steps | ( | struct ast_format * | dest, |
struct ast_format * | src | ||
) |
Returns the number of steps required to convert from 'src' to 'dest'.
dest | destination format |
src | source format |
-1 | if no path is available |
Definition at line 1536 of file translate.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and translator_path::multistep.
Referenced by ast_channel_make_compatible_helper().
const char* ast_translate_path_to_str | ( | struct ast_trans_pvt * | t, |
struct ast_str ** | str | ||
) |
Puts a string representation of the translation path into outbuf.
t | translator structure containing the translation path |
str | ast_str output buffer |
"" | on failure |
Definition at line 930 of file translate.c.
References ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_translator::dst_codec, ast_trans_pvt::next, and ast_translator::src_codec.
Referenced by handle_showchan().
void ast_translator_activate | ( | struct ast_translator * | t | ) |
Activate a previously deactivated translator.
t | translator to activate |
Enables the specified translator for use.
Definition at line 1378 of file translate.c.
References ast_translator::active, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and matrix_rebuild().
int ast_translator_best_choice | ( | struct ast_format_cap * | dst_cap, |
struct ast_format_cap * | src_cap, | ||
struct ast_format ** | dst_fmt_out, | ||
struct ast_format ** | src_fmt_out | ||
) |
Calculate our best translator source format, given costs, and a desired destination.
Chooses the best translation path.
Definition at line 1402 of file translate.c.
References ao2_ref, ao2_replace, ast_debug, ast_format_cap_alloc, ast_format_cap_count(), ast_format_cap_empty(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_compatible(), ast_format_cap_get_format(), ast_format_get_codec(), ast_format_get_name(), ast_format_get_sample_rate(), ast_format_get_type(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, format_sample_rate_absdiff, translator_path::multistep, ast_codec::quality, RAII_VAR, and translator_path::table_cost.
Referenced by ast_channel_make_compatible_helper(), ast_speech_new(), and local_request_with_stream_topology().
struct ast_trans_pvt* ast_translator_build_path | ( | struct ast_format * | dst, |
struct ast_format * | src | ||
) |
Build a chain of translators based upon the given source and dest formats.
Builds a translator path Build a path (possibly NULL) from source to dest.
Definition at line 486 of file translate.c.
References ast_format_get_name(), ast_format_get_sample_rate(), ast_format_get_type(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_free_path(), ast_tv(), ast_translator::dst_codec, ast_translator::dst_fmt_index, newpvt(), ast_trans_pvt::next, ast_codec::sample_rate, translator_path::step, and ast_codec::type.
Referenced by ast_set_read_format_path(), ast_set_write_format_path(), ast_slinfactory_feed(), and ast_writestream().
void ast_translator_deactivate | ( | struct ast_translator * | t | ) |
Deactivate a translator.
t | translator to deactivate |
Disables the specified translator from being used.
Definition at line 1386 of file translate.c.
References ast_translator::active, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and matrix_rebuild().
void ast_translator_free_path | ( | struct ast_trans_pvt * | tr | ) |
Frees a translator path Frees the given translator path structure.
tr | translator path to get rid of |
Definition at line 476 of file translate.c.
References ast_trans_pvt::next.
Referenced by ast_audiohook_destroy(), ast_audiohook_detach_list(), ast_channel_destructor(), ast_set_read_format_path(), ast_set_write_format_path(), ast_slinfactory_destroy(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_translator_build_path(), ast_writestream(), and conf_free().
int ast_unregister_translator | ( | struct ast_translator * | t | ) |
unregister codec translator
Unregister a translator Unregisters the given translator.
Definition at line 1350 of file translate.c.
References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_shutting_down(), ast_translator::dst_codec, ast_translator::list, matrix_rebuild(), ast_codec::name, ast_translator::name, ast_translator::src_codec, and term_color().
Referenced by unload_module().
|
static |
rebuild a translation matrix.
Definition at line 825 of file translate.c.
References ast_translator::active, ao2_ref, ast_debug, translator_path::comp_cost, ast_translator::comp_cost, cur_max_index, ast_translator::dst_fmt_index, ast_translator::list, translator_path::multistep, ast_codec::name, ast_translator::src_fmt_index, translator_path::step, translator_path::table_cost, and ast_translator::table_cost.
Referenced by __ast_register_translator(), ast_translator_activate(), ast_translator_deactivate(), and ast_unregister_translator().
|
static |
table for converting index to format values.
Definition at line 84 of file translate.c.
|
static |
a matrix that, for any pair of supported formats, indicates the total cost of translation and the first step. The full path can be reconstructed iterating on the matrix until step->dstfmt == desired_format.
Array indexes are 'src' and 'dest', in that order.
Note: the lock in the 'translators' list is also used to protect this structure.
Definition at line 77 of file translate.c.
|
static |
Definition at line 1232 of file translate.c.
|
static |
the current largest index used by the __matrix and __indextable arrays
Definition at line 95 of file translate.c.
Referenced by matrix_rebuild().
|
static |
the largest index that can be used in either the __indextable or __matrix before resize must occur
Definition at line 97 of file translate.c.
|
static |
protects the __indextable for resizing
Definition at line 87 of file translate.c.