Asterisk - The Open Source Telephony Project
21.4.1
|
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 | |
static void | __frame_free (struct ast_frame *fr, int cache) |
static void | __init_frame_cache (void) |
A per-thread cache of frame headers. | |
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. | |
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.
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 ast_format_cache_is_slinear(), AST_FRAME_VOICE, ast_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_frame::samples, and ast_frame::subclass.
Referenced by audiohook_volume_callback().
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_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_frame::samples, and ast_frame::subclass.
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.
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_frame::frametype, ast_frame_subclass::integer, 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 AST_LIST_NEXT.
Referenced by __ast_frisolate(), and ast_rtp_read().
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_frame::data, ast_frame_subclass::format, ast_frame::frametype, 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_control_t38_parameters::request_response, and ast_frame::subclass.
Referenced by ast_frame_dump(), and chan_pjsip_indicate().
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, and AST_FRAME_VOICE.
Referenced by ast_frame_dump().
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(), ast_audiosocket_receive_frame(), ast_channel_set_unbridged_nolock(), ast_channel_setwhentohangup_tv(), ast_rtcp_interpret(), ast_rtcp_read(), ast_rtp_read(), ast_softhangup_nolock(), ast_translate(), ast_unreal_read(), chan_pjsip_cng_tone_detected(), chan_pjsip_read_stream(), channel_do_masquerade(), console_read(), fax_detect_framehook(), fax_gateway_detect_t38(), fax_gateway_framehook(), hold_intercept_framehook(), jingle_read(), multicast_rtp_read(), rtp_read(), set_interval_hook(), snoop_read(), and spandsp_fax_read().