Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Frame and codec manipulation routines. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/lock.h"
#include "asterisk/frame.h"
#include "asterisk/format_cache.h"
#include "asterisk/channel.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
#include "asterisk/linkedlists.h"
#include "asterisk/translate.h"
#include "asterisk/dsp.h"
#include "asterisk/file.h"
#include <math.h>
Go to the source code of this file.
Data Structures | |
struct | ast_frame_cache |
struct | ast_frames |
This is just so ast_frames, a list head struct for holding a list of ast_frame structures, is defined. More... | |
Macros | |
#define | FRAME_CACHE_MAX_SIZE 10 |
Maximum ast_frame cache size. More... | |
Functions | |
struct ast_frame * | __ast_frdup (const struct ast_frame *f, const char *file, int line, const char *func) |
struct ast_frame * | __ast_frisolate (struct ast_frame *fr, const char *file, int line, const char *func) |
'isolates' a frame by duplicating non-malloc'ed components (header, src, data). On return all components are malloc'ed More... | |
static void | __frame_free (struct ast_frame *fr, int cache) |
static void | __init_frame_cache (void) |
A per-thread cache of frame headers. More... | |
int | ast_frame_adjust_volume (struct ast_frame *f, int adjustment) |
Adjusts the volume of the audio samples contained in a frame. More... | |
int | ast_frame_adjust_volume_float (struct ast_frame *f, float adjustment) |
Adjusts the volume of the audio samples contained in a frame. More... | |
int | ast_frame_clear (struct ast_frame *frame) |
Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR. More... | |
void | ast_frame_dtor (struct ast_frame *f) |
NULL-safe wrapper for ast_frfree, good for RAII_VAR. More... | |
void | ast_frame_dump (const char *name, struct ast_frame *f, char *prefix) |
void | ast_frame_free (struct ast_frame *frame, int cache) |
Frees a frame or list of frames. More... | |
static struct ast_frame * | ast_frame_header_new (const char *file, int line, const char *func) |
int | ast_frame_slinear_sum (struct ast_frame *f1, struct ast_frame *f2) |
Sums two frames of audio samples. More... | |
char * | ast_frame_subclass2str (struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen) |
Copy the discription of a frame's subclass into the provided string. More... | |
char * | ast_frame_type2str (enum ast_frame_type frame_type, char *ftype, size_t len) |
Copy the discription of a frame type into the provided string. More... | |
void | ast_swapcopy_samples (void *dst, const void *src, int samples) |
static void | frame_cache_cleanup (void *data) |
Variables | |
struct ast_frame | ast_null_frame = { AST_FRAME_NULL, } |
static struct ast_threadstorage | frame_cache = { .once = PTHREAD_ONCE_INIT , .key_init = __init_frame_cache , .custom_init = NULL , } |
Frame and codec manipulation routines.
Definition in file main/frame.c.
#define FRAME_CACHE_MAX_SIZE 10 |
Maximum ast_frame cache size.
In most cases where the frame header cache will be useful, the size of the cache will stay very small. However, it is not always the case that the same thread that allocates the frame will be the one freeing them, so sometimes a thread will never have any frames in its cache, or the cache will never be pulled from. For the latter case, we limit the maximum size.
Definition at line 67 of file main/frame.c.
struct ast_frame * __ast_frdup | ( | const struct ast_frame * | f, |
const char * | file, | ||
int | line, | ||
const char * | func | ||
) |
Definition at line 305 of file main/frame.c.
References __ast_calloc(), ao2_bump, AST_CONTROL_ANSWER, ast_copy_flags, AST_FLAGS_ALL, AST_FRAME_CONTROL, AST_FRAME_IMAGE, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_MALLOCD_HDR, ast_threadstorage_get(), buf, ast_frame::data, ast_frame::datalen, ast_frame::delivery, make_ari_stubs::file, frame_cache, frames, ast_frame::frametype, ast_frame_subclass::integer, len(), ast_frame::len, NULL, out, ast_frame::ptr, ast_frame::samples, ast_frame::seqno, ast_frame::src, ast_frame::stream_num, ast_frame::subclass, ast_frame::ts, and ast_frame::uint32.
Referenced by __ast_frisolate().
struct ast_frame * __ast_frisolate | ( | struct ast_frame * | fr, |
const char * | file, | ||
int | line, | ||
const char * | func | ||
) |
'isolates' a frame by duplicating non-malloc'ed components (header, src, data). On return all components are malloc'ed
Definition at line 197 of file main/frame.c.
References __ast_frdup(), ao2_bump, AST_CONTROL_ANSWER, ast_copy_flags, AST_FLAGS_ALL, ast_frame_free(), ast_frame_header_new(), AST_FRAME_IMAGE, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, AST_FRFLAG_HAS_TIMING_INFO, AST_FRIENDLY_OFFSET, ast_malloc, AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_strdup, ast_test_flag, ast_frame::data, ast_frame::datalen, make_ari_stubs::file, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::len, ast_frame::mallocd, NULL, ast_frame::offset, out, ast_frame::ptr, ast_frame::samples, ast_frame::seqno, ast_frame::src, ast_frame::stream_num, ast_frame::subclass, ast_frame::ts, and ast_frame::uint32.
|
static |
Definition at line 122 of file main/frame.c.
References ao2_cleanup, AST_CONTROL_ANSWER, AST_FRAME_CONTROL, AST_FRAME_IMAGE, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_free, AST_LIST_INSERT_HEAD, AST_MALLOCD_DATA, AST_MALLOCD_HDR, AST_MALLOCD_SRC, ast_opt_cache_media_frames, ast_threadstorage_get(), cache, ast_frame::data, ast_frame_subclass::format, frame_cache, FRAME_CACHE_MAX_SIZE, frames, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_frame::src, ast_frame::subclass, and ast_frame_subclass::topology.
Referenced by ast_frame_free().
|
static |
int ast_frame_adjust_volume | ( | struct ast_frame * | f, |
int | adjustment | ||
) |
Adjusts the volume of the audio samples contained in a frame.
f | The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR) |
adjustment | The number of dB to adjust up or down. |
Definition at line 787 of file main/frame.c.
References abs, ast_format_cache_is_slinear(), AST_FRAME_VOICE, ast_slinear_saturated_divide(), ast_slinear_saturated_multiply(), ast_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.
Referenced by audiohook_read_frame_single(), audiohook_volume_callback(), and conf_run().
int ast_frame_adjust_volume_float | ( | struct ast_frame * | f, |
float | adjustment | ||
) |
Adjusts the volume of the audio samples contained in a frame.
f | The frame containing the samples (must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR) |
adjustment | The number of dB to adjust up or down. |
Definition at line 812 of file main/frame.c.
References ast_format_cache_is_slinear(), AST_FRAME_VOICE, ast_slinear_saturated_divide_float(), ast_slinear_saturated_multiply_float(), ast_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.
Referenced by volume_callback().
int ast_frame_clear | ( | struct ast_frame * | frame | ) |
Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR.
Definition at line 859 of file main/frame.c.
References AST_LIST_NEXT, ast_frame::data, ast_frame::datalen, ast_frame::next, NULL, and ast_frame::ptr.
Referenced by audiohook_read_frame_single().
void ast_frame_dtor | ( | struct ast_frame * | frame | ) |
NULL-safe wrapper for ast_frfree, good for RAII_VAR.
frame | Frame to free, or head of list to free. |
Definition at line 187 of file main/frame.c.
References ast_frfree.
Referenced by __ast_play_and_record(), and stasis_app_exec().
void ast_frame_dump | ( | const char * | name, |
struct ast_frame * | f, | ||
char * | prefix | ||
) |
Dump a frame for debugging purposes
Definition at line 731 of file main/frame.c.
References AST_FRAME_RTCP, ast_frame_subclass2str(), ast_frame_type2str(), AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_strlen_zero(), ast_verb, COLOR_BLACK, COLOR_BRCYAN, COLOR_BRGREEN, COLOR_BRMAGENTA, COLOR_BRRED, COLOR_YELLOW, ast_frame::frametype, ast_frame_subclass::integer, name, prefix, ast_frame::subclass, and term_color().
Referenced by __ast_read(), and ast_write_stream().
void ast_frame_free | ( | struct ast_frame * | frame, |
int | cache | ||
) |
Frees a frame or list of frames.
frame | Frame to free, or head of list to free |
cache | Whether to consider this frame for frame caching |
Definition at line 176 of file main/frame.c.
References __frame_free(), AST_LIST_NEXT, cache, and ast_frame::next.
Referenced by __ast_frisolate(), ast_rtp_read(), mixmonitor_thread(), and spy_generate().
|
static |
Definition at line 81 of file main/frame.c.
References __ast_calloc(), AST_LIST_REMOVE_HEAD, ast_threadstorage_get(), make_ari_stubs::file, frame_cache, frames, ast_frame::mallocd_hdr_len, and NULL.
Referenced by __ast_frisolate().
Sums two frames of audio samples.
f1 | The first frame (which will contain the result) |
f2 | The second frame |
The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples, and must contain the same number of samples.
Definition at line 837 of file main/frame.c.
References ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_slin, AST_FRAME_VOICE, ast_slinear_saturated_add(), ast_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.
char * ast_frame_subclass2str | ( | struct ast_frame * | f, |
char * | subclass, | ||
size_t | slen, | ||
char * | moreinfo, | ||
size_t | mlen | ||
) |
Copy the discription of a frame's subclass into the provided string.
f | The frame to get the information from |
subclass | Buffer to fill with subclass information |
slen | Length of subclass buffer |
moreinfo | Buffer to fill with additional information |
mlen | Length of moreinfo buffer |
Definition at line 406 of file main/frame.c.
References AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_MASQUERADE_NOTIFY, AST_CONTROL_MCID, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_READ_ACTION, AST_CONTROL_RECORD_CANCEL, AST_CONTROL_RECORD_MUTE, AST_CONTROL_RECORD_STOP, AST_CONTROL_RECORD_SUSPEND, AST_CONTROL_REDIRECTING, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_STREAM_FORWARD, AST_CONTROL_STREAM_RESTART, AST_CONTROL_STREAM_REVERSE, AST_CONTROL_STREAM_STOP, AST_CONTROL_STREAM_SUSPEND, AST_CONTROL_STREAM_TOPOLOGY_CHANGED, AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE, AST_CONTROL_STREAM_TOPOLOGY_SOURCE_CHANGED, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_TRANSFER, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_copy_string(), ast_format_get_name(), AST_FRAME_BRIDGE_ACTION, AST_FRAME_BRIDGE_ACTION_SYNC, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_RTCP, AST_FRAME_TEXT, AST_HTML_BEGIN, AST_HTML_DATA, AST_HTML_END, AST_HTML_LDCOMPLETE, AST_HTML_LINKREJECT, AST_HTML_LINKURL, AST_HTML_NOSUPPORT, AST_HTML_UNLINK, AST_HTML_URL, AST_MODEM_T38, AST_MODEM_V150, AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_frame::data, ast_frame::datalen, ast_frame_subclass::format, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::ptr, ast_control_t38_parameters::request_response, and ast_frame::subclass.
Referenced by ast_frame_dump(), chan_pjsip_indicate(), and handle_dump_frames().
char * ast_frame_type2str | ( | enum ast_frame_type | frame_type, |
char * | ftype, | ||
size_t | len | ||
) |
Copy the discription of a frame type into the provided string.
frame_type | The frame type to be described |
ftype | Buffer to fill with frame type description |
len | Length of subclass buffer |
Definition at line 671 of file main/frame.c.
References ast_copy_string(), AST_FRAME_BRIDGE_ACTION, AST_FRAME_BRIDGE_ACTION_SYNC, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_RTCP, AST_FRAME_TEXT, AST_FRAME_TEXT_DATA, AST_FRAME_VIDEO, AST_FRAME_VOICE, and len().
Referenced by ast_frame_dump(), handle_dump_frames(), softmix_bridge_write_text(), and stream_echo_write_error().
void ast_swapcopy_samples | ( | void * | dst, |
const void * | src, | ||
int | samples | ||
) |
Definition at line 396 of file main/frame.c.
Referenced by __ast_smoother_feed(), iax_frame_wrap(), and smoother_frame_feed().
|
static |
Definition at line 110 of file main/frame.c.
References ast_free, AST_LIST_REMOVE_HEAD, and frames.
struct ast_frame ast_null_frame = { AST_FRAME_NULL, } |
Queueing a null frame is fairly common, so we declare a global null frame object for this purpose instead of having to declare one on the stack
Definition at line 79 of file main/frame.c.
Referenced by __analog_handle_event(), __ast_read(), aoc_framehook(), apply_negotiated_sdp_stream(), ast_audiosocket_receive_frame(), ast_channel_set_unbridged_nolock(), ast_channel_setwhentohangup_tv(), ast_rtcp_interpret(), ast_rtcp_read(), ast_rtp_interpret(), ast_rtp_read(), ast_softhangup_nolock(), AST_TEST_DEFINE(), ast_translate(), ast_udptl_read(), ast_unreal_read(), bridge_channel_internal_push_full(), bridge_channel_poke(), chan_msg_read(), chan_pjsip_cng_tone_detected(), chan_pjsip_read_stream(), channel_do_masquerade(), conf_run(), console_read(), create_dtmf_frame(), dahdi_handle_event(), dahdi_read(), exec_command_on_condition(), fax_detect_framehook(), fax_gateway_detect_t38(), fax_gateway_framehook(), handle_negotiated_sdp(), hold_intercept_framehook(), hook_event_cb(), iax2_read(), jb_get_adaptive(), jb_get_fixed(), jingle_read(), mbl_read(), media_session_rtcp_read_callback(), media_session_rtp_read_callback(), media_session_udptl_read_callback(), multicast_rtp_read(), ooh323_rtp_read(), rec_read(), refer_incoming_invite_request(), rtp_read(), set_interval_hook(), snoop_read(), spandsp_fax_read(), stream_periodic_frames(), suppress_framehook_event_cb(), test_vm_api_mock_channel_read(), unistim_rtp_read(), and wakeup_sub().
|
static |
Definition at line 56 of file main/frame.c.
Referenced by __ast_frdup(), __frame_free(), and ast_frame_header_new().