46#define AST_AUDIOHOOK_SYNC_TOLERANCE 100
47#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE 100
48#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE 500
49#define AST_WHISPER_TIMER_INTERVAL 20
50#define AST_WHISPER_TIMER_INTERVAL_MIN 10
51#define AST_WHISPER_TIMER_INTERVAL_MAX 60
52#define AST_WHISPER_TIMER_CLAMP(interval) \
53 ((interval) < AST_WHISPER_TIMER_INTERVAL_MIN ? AST_WHISPER_TIMER_INTERVAL_MIN : \
54 ((interval) > AST_WHISPER_TIMER_INTERVAL_MAX ? AST_WHISPER_TIMER_INTERVAL_MAX : (interval)))
55#define AST_WHISPER_TIMER_SRC "audiohook whisper timer"
57#define DEFAULT_INTERNAL_SAMPLE_RATE 8000
91 int internal_sample_rate,
98 if (!hook_data || internal_sample_rate <= 0 || samples <= 0) {
112 if (hook_data->
timer) {
137 .datalen =
sizeof(
buf),
163 if (!hook_data->
timer) {
165 if (!hook_data->
timer) {
184 if (hook_data->
timer) {
262 hook_data =
ast_calloc(1,
sizeof(*hook_data));
270 interface.
data = hook_data;
272 if (framehook_id < 0) {
307 switch (audiohook->
type) {
328 audiohook->
source = source;
351 switch (audiohook->
type) {
378 ast_debug(3,
"Can not set direction on attached Audiohook %p\n", audiohook);
386#define SHOULD_MUTE(hook, dir) \
387 ((ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ) && (dir == AST_AUDIOHOOK_DIRECTION_READ)) || \
388 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_WRITE) && (dir == AST_AUDIOHOOK_DIRECTION_WRITE)) || \
389 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE) == (AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE)))
396 int our_factory_samples;
398 int other_factory_samples;
399 int other_factory_ms;
417 ast_debug(4,
"Flushing audiohook %p so it remains in sync\n", audiohook);
423 ast_debug(4,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
427 ast_debug(4,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
456 .datalen =
sizeof(
buf),
489 short *read_buf =
NULL;
493 .datalen =
sizeof(buf1),
501 if (!usable_read && !usable_write) {
546 ast_debug(3,
"Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->
write_factory);
552 ast_debug(3,
"Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->
read_factory);
563 memset(buf1, 0,
sizeof(buf1));
567 for (count = 0; count <
samples; count++) {
587 memset(buf2, 0,
sizeof(buf2));
591 for (count = 0; count <
samples; count++) {
608 if (read_reference && !read_buf &&
write_buf) {
610 memset(buf1, 0,
sizeof(buf1));
611 }
else if (write_reference && read_buf && !
write_buf) {
613 memset(buf2, 0,
sizeof(buf2));
618 if (read_buf && read_reference) {
631 for (count = 0; count <
samples; count++) {
761 if (!(ahlist =
ast_calloc(1,
sizeof(*ahlist)))) {
841 if (!audiohook_list) {
862 for (i = 0; i < 2; i++) {
918 oldstatus = audiohook->
status;
923 audiohook->
status = oldstatus;
949 if (!audiohook_list) {
989 return (audiohook ? 0 : -1);
1087 if (!in_translate->
format ||
1191 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame;
1194 int middle_frame_manipulated = 0;
1196 int internal_sample_rate;
1206 if (!middle_frame->data.ptr) {
1207 if (middle_frame != start_frame) {
1213 samples = middle_frame->
samples;
1251 short read_buf[samples], combine_buf[samples], *data1 =
NULL, *data2 =
NULL;
1252 memset(&combine_buf, 0,
sizeof(combine_buf));
1269 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++) {
1277 for (i = 0, data1 = middle_frame->data.ptr, data2 = combine_buf; i < samples; i++, data1++, data2++) {
1280 middle_frame_manipulated = 1;
1310 middle_frame_manipulated = 1;
1318 if (middle_frame_manipulated) {
1321 end_frame = start_frame;
1324 end_frame = start_frame;
1327 if (middle_frame != end_frame) {
1329 middle_frame =
NULL;
1347 internal_sample_rate, samples);
1356 return !audiohook_list
1379 struct timeval wait;
1383 ts.tv_sec = wait.tv_sec;
1384 ts.tv_nsec = wait.tv_usec * 1000;
1424 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n",
type);
1459 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n",
type);
1528 if (gain && *gain) {
1548 return datastore->
data;
1609 float adjustment = 0;
1675 return (audiohook ? 0 : -1);
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
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.
static void whisper_framehook_destroy_cb(void *data)
#define AST_WHISPER_TIMER_SRC
static void audiohook_list_set_samplerate_compatibility(struct ast_audiohook_list *audiohook_list)
static const struct ast_datastore_info audiohook_volume_datastore
Datastore used to store audiohook volume information.
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.
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 in mixed audio mode and copies read and write frame dat...
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...
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.
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.
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_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
int ast_audiohook_detach_source(struct ast_channel *chan, const char *source)
Detach specified source audiohook from channel.
#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE
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.
static struct ast_frame * audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
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.
int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
Determine if a audiohook_list is empty or not.
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
int ast_audiohook_volume_adjust_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume)
Adjust the volume on frames read from or written to a channel.
#define AST_AUDIOHOOK_SYNC_TOLERANCE
void ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
#define AST_WHISPER_TIMER_INTERVAL_MAX
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
#define AST_WHISPER_TIMER_INTERVAL
static int whisper_framehook_attach(struct ast_channel *chan, struct ast_audiohook_list *audiohook_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.
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
int ast_audiohook_volume_set_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume)
Adjust the volume on frames read from or written to a channel.
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.
static void whisper_framehook_detach(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list)
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
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.
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
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)
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)
static struct ast_frame * whisper_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
static struct ast_frame * audiohook_list_translate_to_slin(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
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.
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)
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...
#define AST_WHISPER_TIMER_CLAMP(interval)
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
static void whisper_framehook_timer_update(struct ast_audiohook_list *audiohook_list, struct ast_frame *start_frame, int internal_sample_rate, int samples)
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.
int ast_audiohook_set_frame_feed_direction(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction)
Sets direction on audiohook.
int ast_audiohook_set_mute_all(struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clearmute)
Mute frames read from or written for all audiohooks on a channel.
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.
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.
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE
void ast_audiohook_move_all(struct ast_channel *old_chan, struct ast_channel *new_chan)
Move all audiohooks from one channel to another.
#define DEFAULT_INTERNAL_SAMPLE_RATE
static void audiohook_volume_destroy(void *data)
Callback used to destroy the audiohook volume datastore.
float ast_audiohook_volume_get_float(struct ast_channel *chan, enum ast_audiohook_direction direction)
Retrieve the volume adjustment value on frames read from or written to a channel.
#define SHOULD_MUTE(hook, dir)
@ AST_AUDIOHOOK_MANIPULATE_ALL_RATES
@ AST_AUDIOHOOK_DIRECTION_READ
@ AST_AUDIOHOOK_DIRECTION_WRITE
@ AST_AUDIOHOOK_DIRECTION_BOTH
#define ast_audiohook_lock(ah)
Lock an audiohook.
@ AST_AUDIOHOOK_COMPATIBLE
@ AST_AUDIOHOOK_WANTS_DTMF
@ AST_AUDIOHOOK_TRIGGER_MODE
@ AST_AUDIOHOOK_MUTE_READ
@ AST_AUDIOHOOK_MUTE_WRITE
@ AST_AUDIOHOOK_SUBSTITUTE_SILENCE
@ AST_AUDIOHOOK_SMALL_QUEUE
@ AST_AUDIOHOOK_TRIGGER_READ
@ AST_AUDIOHOOK_TRIGGER_WRITE
@ AST_AUDIOHOOK_TRIGGER_SYNC
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
@ AST_AUDIOHOOK_TYPE_MANIPULATE
@ AST_AUDIOHOOK_TYPE_WHISPER
@ AST_AUDIOHOOK_STATUS_DONE
@ AST_AUDIOHOOK_STATUS_NEW
@ AST_AUDIOHOOK_STATUS_RUNNING
@ AST_AUDIOHOOK_STATUS_SHUTDOWN
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
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.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
int ast_channel_fdno(const struct ast_channel *chan)
#define ast_channel_lock(chan)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
int ast_channel_fd_add(struct ast_channel *chan, int value)
Add a file descriptor to the channel without a fixed position.
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
#define ast_channel_unlock(chan)
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.
#define ast_datastore_alloc(info, uid)
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
void write_buf(int file, char *buffer, int num)
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i)
Attach an framehook onto a channel for frame interception.
ast_framehook_event
These are the types of events that the framehook's event callback can receive.
@ AST_FRAMEHOOK_EVENT_ATTACHED
@ AST_FRAMEHOOK_EVENT_DETACHED
@ AST_FRAMEHOOK_EVENT_WRITE
@ AST_FRAMEHOOK_EVENT_READ
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
#define AST_FRAMEHOOK_INTERFACE_VERSION
Asterisk internal frame definitions.
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 ast_frdup(fr)
Copies a frame.
int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
Adjusts the volume of the audio samples contained in a frame.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
int ast_frame_adjust_volume_float(struct ast_frame *f, float adjustment)
Adjusts the volume of the audio samples contained in a frame.
struct ast_frame ast_null_frame
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Asterisk locking-related definitions:
#define ast_cond_destroy(cond)
#define ast_cond_init(cond, attr)
#define ast_cond_timedwait(cond, mutex, time)
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
#define ast_cond_signal(cond)
A machine to gather up arbitrary frames and convert them to raw slinear on demand.
int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out)
Initialize a slinfactory.
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
Read samples from a slinfactory.
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
struct ast_audiohook_list::@322 spy_list
struct ast_audiohook_translate out_translate[2]
int list_internal_samp_rate
int native_slin_compatible
struct ast_audiohook_list::@323 whisper_list
struct whisper_framehook_data * whisper_framehook_data
struct ast_audiohook_list::@324 manipulate_list
struct ast_audiohook_translate in_translate[2]
struct ast_trans_pvt * trans_pvt
struct ast_format * format
struct timeval write_time
enum ast_audiohook_type type
ast_audiohook_manipulate_callback manipulate_callback
unsigned int hook_internal_samp_rate
struct ast_slinfactory read_factory
struct ast_trans_pvt * trans_pvt
struct ast_audiohook_options options
enum ast_audiohook_init_flags init_flags
enum ast_audiohook_status status
enum ast_audiohook_direction direction
struct ast_format * format
struct ast_slinfactory write_factory
struct ast_audiohook::@196 list
Main Channel structure associated with a channel.
Structure for a data store type.
Structure for a data store object.
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@237 data
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Audiohook volume adjustment structure.
struct ast_audiohook audiohook
struct timeval last_external_write_tv
#define ast_test_suite_event_notify(s, f,...)
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 ...
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Timing source management.
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
struct ast_timer * ast_timer_open(void)
Open a timer.
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
Support for translation of data formats. translate.c.
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...
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
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.
#define ast_test_flag(p, flag)
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
#define ast_clear_flag(p, flag)
static force_inline void ast_slinear_saturated_add(short *input, short *value)
#define ast_set_flag(p, flag)
static force_inline void ast_slinear_saturated_divide(short *input, short *value)