44 #define AST_AUDIOHOOK_SYNC_TOLERANCE 100 45 #define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE 100 46 #define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE 500 48 #define DEFAULT_INTERNAL_SAMPLE_RATE 8000 83 switch (audiohook->
type) {
112 audiohook->
source = source;
136 switch (audiohook->
type) {
159 #define SHOULD_MUTE(hook, dir) \ 160 ((ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ) && (dir == AST_AUDIOHOOK_DIRECTION_READ)) || \ 161 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_WRITE) && (dir == AST_AUDIOHOOK_DIRECTION_WRITE)) || \ 162 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE) == (AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE))) 175 int our_factory_samples;
177 int other_factory_samples;
178 int other_factory_ms;
189 ast_debug(1,
"Flushing audiohook %p so it remains in sync\n", audiohook);
195 ast_debug(1,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
199 ast_debug(1,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
228 .datalen =
sizeof(
buf),
261 short *read_buf =
NULL;
265 .datalen =
sizeof(
buf1),
273 if (!usable_read && !usable_write) {
281 ast_debug(3,
"Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->
write_factory);
287 ast_debug(3,
"Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->
read_factory);
298 memset(buf1, 0,
sizeof(buf1));
302 for (count = 0; count <
samples; count++) {
312 ast_debug(1,
"Failed to get %d samples from read factory %p\n", (
int)samples, &audiohook->
read_factory);
322 memset(buf2, 0,
sizeof(buf2));
326 for (count = 0; count <
samples; count++) {
336 ast_debug(1,
"Failed to get %d samples from write factory %p\n", (
int)samples, &audiohook->
write_factory);
343 if (read_reference && !read_buf && write_buf) {
345 memset(buf1, 0,
sizeof(buf1));
346 }
else if (write_reference && read_buf && !write_buf) {
348 memset(buf2, 0,
sizeof(buf2));
353 if (read_buf && read_reference) {
357 if (write_buf && write_reference) {
366 for (count = 0; count <
samples; count++) {
370 }
else if (write_buf) {
517 if (!(ahlist =
ast_calloc(1,
sizeof(*ahlist)))) {
599 if (!audiohook_list) {
620 for (i = 0; i < 2; i++) {
645 if (!strcasecmp(audiohook->
source, source)) {
651 if (!strcasecmp(audiohook->
source, source)) {
657 if (!strcasecmp(audiohook->
source, source)) {
675 oldstatus = audiohook->
status;
680 audiohook->
status = oldstatus;
706 if (!audiohook_list) {
751 return (audiohook ? 0 : -1);
854 if (!in_translate->
format ||
957 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame;
960 int middle_frame_manipulated = 0;
962 int internal_sample_rate;
972 if (!middle_frame->data.ptr) {
973 if (middle_frame != start_frame) {
979 samples = middle_frame->
samples;
1017 short read_buf[samples], combine_buf[samples], *data1 =
NULL, *data2 =
NULL;
1018 memset(&combine_buf, 0,
sizeof(combine_buf));
1035 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++) {
1043 for (i = 0, data1 = middle_frame->data.ptr, data2 = combine_buf; i < samples; i++, data1++, data2++) {
1046 middle_frame_manipulated = 1;
1076 middle_frame_manipulated = 1;
1084 if (middle_frame_manipulated) {
1087 end_frame = start_frame;
1090 end_frame = start_frame;
1093 if (middle_frame != end_frame) {
1095 middle_frame =
NULL;
1114 return !audiohook_list
1144 struct timeval wait;
1148 ts.tv_sec = wait.tv_sec;
1149 ts.tv_nsec = wait.tv_usec * 1000;
1169 if (!strcmp(ah->
source, source)) {
1176 if (!strcmp(ah->
source, source)) {
1183 if (!strcmp(ah->
source, source)) {
1189 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n", type);
1224 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n", type);
1283 audiohook_volume = datastore->
data;
1293 if (gain && *gain) {
1312 return datastore->
data;
1321 if (!(audiohook_volume =
ast_calloc(1,
sizeof(*audiohook_volume)))) {
1331 datastore->
data = audiohook_volume;
1337 return audiohook_volume;
1448 return (audiohook ? 0 : -1);
struct ast_audiohook audiohook
Audiohook volume adjustment structure.
#define ast_channel_lock(chan)
Main Channel structure associated with a channel.
#define ast_frdup(fr)
Copies a frame.
struct ast_slinfactory write_factory
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
struct ast_audiohook_list::@344 manipulate_list
int ast_audiohook_volume_set(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume)
Adjust the volume on frames read from or written to a channel.
static void audiohook_volume_destroy(void *data)
Callback used to destroy the audiohook volume datastore.
enum ast_audiohook_type type
struct ast_format * format
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags init_flags)
Initialize an audiohook structure.
static struct ast_frame * audio_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass an AUDIO frame off to be handled by the audiohook core.
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
int list_internal_samp_rate
#define ast_test_flag(p, flag)
Support for translation of data formats. translate.c.
int ast_audiohook_volume_get(struct ast_channel *chan, enum ast_audiohook_direction direction)
Retrieve the volume adjustment value on frames read from or written to a channel. ...
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
#define ast_set_flag(p, flag)
struct ast_audiohook_translate out_translate[2]
int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame)
Writes a frame into the audiohook structure.
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
Structure for a data store type.
static struct audiohook_volume * audiohook_volume_get(struct ast_channel *chan, int create)
Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a chann...
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
#define ast_cond_init(cond, attr)
static struct ast_threadstorage buf2
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
struct ast_trans_pvt * trans_pvt
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...
static const struct ast_datastore_info audiohook_volume_datastore
Datastore used to store audiohook volume information.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
struct ast_audiohook_list::@342 spy_list
int native_slin_compatible
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define ast_cond_signal(cond)
struct ast_format * format
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
static struct ast_frame * dtmf_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass a DTMF frame off to be handled by the audiohook core.
struct ast_frame_subclass subclass
void ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
int ast_channel_audiohook_count_by_source(struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
Find out how many audiohooks from a certain source exist on a given channel, regardless of status...
#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
#define AST_AUDIOHOOK_SYNC_TOLERANCE
ast_audiohook_manipulate_callback manipulate_callback
struct ast_audiohook::@225 list
#define SHOULD_MUTE(hook, dir)
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
static struct ast_frame * audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
#define ast_debug(level,...)
Log a DEBUG message.
void write_buf(int file, char *buffer, int num)
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
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.
General Asterisk PBX channel definitions.
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
void ast_audiohook_move_by_source(struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source)
Move an audiohook from one channel to a new one.
int ast_audiohook_set_mute(struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clear)
Mute frames read from or written to a channel.
enum ast_audiohook_init_flags init_flags
struct ast_frame * ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass a frame off to be handled by the audiohook core.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Asterisk internal frame definitions.
static force_inline void ast_slinear_saturated_add(short *input, short *value)
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
A set of macros to manage forward-linked lists.
struct ast_trans_pvt * trans_pvt
void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value)
Variant of ast_channel_set_unbridged. Use this if the channel is already locked prior to calling...
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
AST_LIST_HEAD_NOLOCK(contactliststruct, contact)
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
unsigned int hook_internal_samp_rate
int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out)
Initialize a slinfactory.
int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
Determine if a audiohook_list is empty or not.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
static void audiohook_list_set_hook_rate(struct ast_audiohook_list *audiohook_list, struct ast_audiohook *audiohook, int *rate)
Set the audiohook's internal sample rate to the audiohook_list's rate, but only when native slin comp...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
#define ast_cond_destroy(cond)
struct ast_frame * ast_audiohook_read_frame_all(struct ast_audiohook *audiohook, size_t samples, struct ast_format *format, struct ast_frame **read_frame, struct ast_frame **write_frame)
Reads a frame in from the audiohook structure.
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
static struct ast_threadstorage buf1
#define ast_channel_unlock(chan)
A machine to gather up arbitrary frames and convert them to raw slinear on demand.
#define ast_calloc(num, len)
A wrapper for calloc()
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
#define ast_clear_flag(p, flag)
int ast_audiohook_detach_source(struct ast_channel *chan, const char *source)
Detach specified source audiohook from channel.
struct ast_slinfactory read_factory
struct ast_audiohook_translate in_translate[2]
struct ast_audiohook_options options
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
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.
#define ao2_replace(dst, src)
struct timeval write_time
int ast_channel_audiohook_count_by_source_running(struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
Find out how many spies of a certain type exist on a given channel, and are in state running...
Data structure associated with a single frame of data.
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
Read samples from a slinfactory.
int ast_audiohook_volume_adjust(struct ast_channel *chan, enum ast_audiohook_direction direction, int volume)
Adjust the volume on frames read from or written to a channel.
static struct ast_frame * audiohook_read_frame_helper(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format, struct ast_frame **read_reference, struct ast_frame **write_reference)
enum ast_audiohook_status status
struct ast_audiohook_list::@343 whisper_list
#define ast_datastore_alloc(info, uid)
union ast_frame::@263 data
static struct ast_frame * audiohook_list_translate_to_native(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *slin_frame, struct ast_format *outformat)
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
Adjusts the volume of the audio samples contained in a frame.
#define ast_mutex_init(pmutex)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ast_mutex_destroy(a)
void ast_audiohook_move_all(struct ast_channel *old_chan, struct ast_channel *new_chan)
Move all audiohooks from one channel to another.
struct ast_format * format
struct ast_frame * ast_audiohook_read_frame(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format)
Reads a frame in from the audiohook structure.
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
static struct ast_frame * audiohook_list_translate_to_slin(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
#define ast_audiohook_lock(ah)
Lock an audiohook.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
static struct ast_frame * audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
static void audiohook_list_set_samplerate_compatibility(struct ast_audiohook_list *audiohook_list)
#define ast_cond_timedwait(cond, mutex, time)
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
#define DEFAULT_INTERNAL_SAMPLE_RATE
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
static int audiohook_volume_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
Helper function which actually gets called by audiohooks to perform the adjustment.