Asterisk - The Open Source Telephony Project
18.5.0
|
Support for translation of data formats. translate.c. More...
#include "asterisk/frame.h"
#include "asterisk/plc.h"
#include "asterisk/linkedlists.h"
#include "asterisk/format_cap.h"
#include "asterisk/format_cache.h"
Go to the source code of this file.
Data Structures | |
struct | ast_trans_pvt |
Default structure for translators, with the basic fields and buffers, all allocated as part of the same chunk of memory. The buffer is preceded by AST_FRIENDLY_OFFSET bytes in front of the user portion. 'buf' points right after this space. More... | |
struct | ast_translator |
Descriptor of a translator. More... | |
Macros | |
#define | ast_register_translator(t) __ast_register_translator(t, AST_MODULE_SELF) |
See __ast_register_translator() More... | |
Enumerations | |
enum | ast_trans_cost_table { AST_TRANS_COST_LL_LL_ORIGSAMP = 400000, AST_TRANS_COST_LL_LY_ORIGSAMP = 600000, AST_TRANS_COST_LL_LL_UPSAMP = 800000, AST_TRANS_COST_LL_LY_UPSAMP = 825000, AST_TRANS_COST_LL_LL_DOWNSAMP = 850000, AST_TRANS_COST_LL_LY_DOWNSAMP = 875000, AST_TRANS_COST_LL_UNKNOWN = 885000, AST_TRANS_COST_LY_LL_ORIGSAMP = 900000, AST_TRANS_COST_LY_LY_ORIGSAMP = 915000, AST_TRANS_COST_LY_LL_UPSAMP = 930000, AST_TRANS_COST_LY_LY_UPSAMP = 945000, AST_TRANS_COST_LY_LL_DOWNSAMP = 960000, AST_TRANS_COST_LY_LY_DOWNSAMP = 975000, AST_TRANS_COST_LY_UNKNOWN = 985000 } |
Translator Cost Table definition. More... | |
Functions | |
int | __ast_register_translator (struct ast_translator *t, struct ast_module *module) |
Register a translator This registers a codec translator with asterisk. More... | |
struct ast_frame * | ast_trans_frameout (struct ast_trans_pvt *pvt, int datalen, int samples) |
generic frameout function More... | |
struct ast_frame * | ast_translate (struct ast_trans_pvt *tr, struct ast_frame *f, int consume) |
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. 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 *dest, struct ast_format *src) |
Returns the number of steps required to convert from 'src' to 'dest'. More... | |
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. 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) |
Chooses the best translation path. More... | |
struct ast_trans_pvt * | ast_translator_build_path (struct ast_format *dest, struct ast_format *source) |
Builds a translator path Build a path (possibly NULL) from source to dest. More... | |
void | ast_translator_deactivate (struct ast_translator *t) |
Deactivate a translator. More... | |
void | ast_translator_free_path (struct ast_trans_pvt *tr) |
Frees a translator path Frees the given translator path structure. More... | |
int | ast_unregister_translator (struct ast_translator *t) |
Unregister a translator Unregisters the given tranlator. More... | |
Support for translation of data formats. translate.c.
Definition in file translate.h.
#define ast_register_translator | ( | t | ) | __ast_register_translator(t, AST_MODULE_SELF) |
See __ast_register_translator()
Definition at line 257 of file translate.h.
Referenced by load_module(), and register_translator().
enum ast_trans_cost_table |
Translator Cost Table definition.
This table is built in a way that allows translation paths to be built that guarantee the best possible balance between performance and quality. With this table direct translation paths between two formats will always take precedence over multi step paths, lossless intermediate steps will always be chosen over lossy intermediate steps, and preservation of sample rate across the translation will always have precedence over a path that involves any re-sampling.
Definition at line 61 of file translate.h.
int __ast_register_translator | ( | struct ast_translator * | t, |
struct ast_module * | mod | ||
) |
Register a translator This registers a codec translator with asterisk.
t | populated ast_translator structure |
mod | module handle to the module that owns this translator |
Register a translator This registers a codec translator with asterisk.
Definition at line 1220 of file translate.c.
References a, ast_translator::active, add_codec2index(), ao2_cleanup, ast_assert, ast_codec_get(), ast_log, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, b, ast_translator::buf_size, codec2index(), COLOR_BLACK, COLOR_MAGENTA, ast_translator::comp_cost, cur_max_index, default_frameout(), ast_translator::dst_codec, ast_translator::dst_fmt_index, ast_translator::frameout, generate_computational_cost(), generate_table_cost(), LOG_WARNING, matrix_rebuild(), matrix_resize(), ast_translator::module, ast_codec::name, ast_translator::name, NULL, RAII_VAR, ast_codec::sample_rate, ast_translator::src_codec, ast_translator::src_fmt_index, ast_translator::table_cost, term_color(), tmp(), and ast_codec::type.
struct ast_frame* ast_trans_frameout | ( | struct ast_trans_pvt * | pvt, |
int | datalen, | ||
int | samples | ||
) |
generic frameout function
generic frameout function
Definition at line 438 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, NULL, ast_trans_pvt::outbuf, ast_frame::ptr, ast_frame::samples, and ast_trans_pvt::samples.
Referenced by default_frameout(), lintoadpcm_frameout(), lintocodec2_frameout(), lintogsm_frameout(), lintoilbc_frameout(), lintolpc10_frameout(), and lintospeex_frameout().
struct ast_frame* ast_translate | ( | struct ast_trans_pvt * | path, |
struct ast_frame * | f, | ||
int | consume | ||
) |
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.
path | tr translator structure to use for translation |
f | frame to translate |
consume | Whether or not to free the original frame |
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 565 of file translate.c.
References ast_clear_flag, ast_debug, ast_format_get_sample_rate(), AST_FRAME_CNG, AST_FRAME_RTCP, AST_FRFLAG_HAS_TIMING_INFO, ast_frfree, AST_LIST_NEXT, ast_null_frame, ast_samp2tv(), ast_set2_flag, ast_test_flag, 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, generate_interpolated_slin(), ast_frame::len, len(), ast_trans_pvt::next, ast_trans_pvt::nextin, ast_trans_pvt::nextout, out, ast_frame::samples, ast_frame::seqno, ast_frame::subclass, ast_trans_pvt::t, and ast_frame::ts.
Referenced by __ast_read(), ast_slinfactory_feed(), ast_write_stream(), ast_writestream(), audiohook_list_translate_to_native(), audiohook_list_translate_to_slin(), audiohook_read_frame_helper(), conf_run(), fax_gateway_framehook(), and softmix_process_write_audio().
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 |
result | capabilities structure to store available formats in |
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 1571 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_MEDIA_TYPE_AUDIO, AST_MEDIA_TYPE_VIDEO, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and check_translation_path().
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 1630 of file translate.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), ast_rwlock_init, matrix_resize(), and translate_shutdown().
Referenced by asterisk_daemon().
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 |
Definition at line 1491 of file translate.c.
References ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, format2index(), LOG_WARNING, matrix_get(), translator_path::multistep, and translator_path::step.
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 | success pointer to beginning of outbuf. on failure "". |
Definition at line 928 of file translate.c.
References ast_str_append(), ast_str_buffer(), ast_str_reset(), codec_append_name(), ast_translator::dst_codec, ast_trans_pvt::next, ast_translator::src_codec, and ast_trans_pvt::t.
Referenced by chan_pjsip_write_stream(), generate_status(), handle_showchan(), and serialize_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 1361 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 | ||
) |
Chooses the best translation path.
Given a list of sources, and a designed destination format, which should I choose?
dst_cap | destination capabilities |
src_cap | source capabilities |
dst_fmt_out | destination format chosen out of destination capabilities |
src_fmt_out | source format chosen out of source capabilities |
Chooses the best translation path.
Definition at line 1385 of file translate.c.
References ao2_cleanup, ao2_ref, ao2_replace, 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_sample_rate(), ast_format_get_type(), ast_log, AST_MEDIA_TYPE_AUDIO, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, format2index(), format_sample_rate_absdiff, LOG_ERROR, matrix_get(), translator_path::multistep, NULL, RAII_VAR, translator_path::step, and translator_path::table_cost.
Referenced by ast_channel_make_compatible_helper(), iax2_request(), local_request_with_stream_topology(), request_channel(), and set_format().
struct ast_trans_pvt* ast_translator_build_path | ( | struct ast_format * | dst, |
struct ast_format * | src | ||
) |
Builds a translator path Build a path (possibly NULL) from source to dest.
dst | dest destination format |
src | source source format |
Builds a translator path Build a path (possibly NULL) from source to dest.
Definition at line 485 of file translate.c.
References ast_format_get_name(), ast_format_get_sample_rate(), ast_format_get_type(), ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_free_path(), ast_tv(), ast_translator::dst_codec, ast_translator::dst_fmt_index, format2index(), LOG_WARNING, matrix_get(), newpvt(), ast_trans_pvt::next, ast_trans_pvt::nextin, ast_trans_pvt::nextout, NULL, ast_codec::sample_rate, translator_path::step, ast_trans_pvt::t, and ast_codec::type.
Referenced by ast_set_read_format_path(), ast_set_write_format_path(), ast_slinfactory_feed(), ast_writestream(), audiohook_list_translate_to_native(), audiohook_list_translate_to_slin(), audiohook_read_frame_helper(), conf_run(), set_format(), softmix_process_write_audio(), and softmix_translate_helper_change_rate().
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 1369 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 475 of file translate.c.
References destroy(), and 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(), audiohook_list_translate_to_native(), audiohook_list_translate_to_slin(), audiohook_read_frame_helper(), conf_free(), filestream_destructor(), free_translation(), set_format(), softmix_translate_helper_change_rate(), softmix_translate_helper_cleanup(), and softmix_translate_helper_free_entry().
int ast_unregister_translator | ( | struct ast_translator * | t | ) |
Unregister a translator Unregisters the given tranlator.
t | translator to unregister |
Unregister a translator Unregisters the given tranlator.
Definition at line 1333 of file translate.c.
References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_shutting_down(), ast_verb, COLOR_BLACK, COLOR_MAGENTA, ast_translator::dst_codec, ast_translator::list, matrix_rebuild(), ast_codec::name, ast_translator::name, ast_translator::src_codec, term_color(), and tmp().
Referenced by unload_module(), and unregister_translators().