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) {
104 audiohook->
source = source;
127 switch (audiohook->
type) {
154 ast_debug(3,
"Can not set direction on attached Audiohook %p\n", audiohook);
162#define SHOULD_MUTE(hook, dir) \
163 ((ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ) && (dir == AST_AUDIOHOOK_DIRECTION_READ)) || \
164 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_WRITE) && (dir == AST_AUDIOHOOK_DIRECTION_WRITE)) || \
165 (ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE) == (AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE)))
172 int our_factory_samples;
174 int other_factory_samples;
175 int other_factory_ms;
193 ast_debug(4,
"Flushing audiohook %p so it remains in sync\n", audiohook);
199 ast_debug(4,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
203 ast_debug(4,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
232 .datalen =
sizeof(
buf),
265 short *read_buf =
NULL;
269 .datalen =
sizeof(
buf1),
277 if (!usable_read && !usable_write) {
313 ast_debug(3,
"Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->
write_factory);
319 ast_debug(3,
"Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->
read_factory);
334 for (count = 0; count <
samples; count++) {
358 for (count = 0; count <
samples; count++) {
375 if (read_reference && !read_buf &&
write_buf) {
378 }
else if (write_reference && read_buf && !
write_buf) {
385 if (read_buf && read_reference) {
398 for (count = 0; count <
samples; count++) {
528 if (!(ahlist =
ast_calloc(1,
sizeof(*ahlist)))) {
598 if (!audiohook_list) {
619 for (i = 0; i < 2; i++) {
675 oldstatus = audiohook->
status;
680 audiohook->
status = oldstatus;
706 if (!audiohook_list) {
746 return (audiohook ? 0 : -1);
840 if (!in_translate->
format ||
944 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame;
947 int middle_frame_manipulated = 0;
949 int internal_sample_rate;
959 if (!middle_frame->data.ptr) {
960 if (middle_frame != start_frame) {
966 samples = middle_frame->
samples;
1004 short read_buf[samples], combine_buf[samples], *data1 =
NULL, *data2 =
NULL;
1005 memset(&combine_buf, 0,
sizeof(combine_buf));
1022 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++) {
1030 for (i = 0, data1 = middle_frame->data.ptr, data2 = combine_buf; i < samples; i++, data1++, data2++) {
1033 middle_frame_manipulated = 1;
1063 middle_frame_manipulated = 1;
1071 if (middle_frame_manipulated) {
1074 end_frame = start_frame;
1077 end_frame = start_frame;
1080 if (middle_frame != end_frame) {
1082 middle_frame =
NULL;
1101 return !audiohook_list
1124 struct timeval wait;
1128 ts.tv_sec = wait.tv_sec;
1129 ts.tv_nsec = wait.tv_usec * 1000;
1169 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n",
type);
1204 ast_debug(1,
"Invalid audiohook type supplied, (%u)\n",
type);
1273 if (gain && *gain) {
1293 return datastore->
data;
1405 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 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.
#define AST_AUDIOHOOK_SYNC_TOLERANCE
void ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
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
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.
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 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 * 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...
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
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.
#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.
#define ast_channel_lock(chan)
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
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.
#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)
static struct ast_threadstorage buf2
static struct ast_threadstorage buf1
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_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_translate out_translate[2]
int list_internal_samp_rate
int native_slin_compatible
struct ast_audiohook_list::@302 spy_list
struct ast_audiohook_list::@304 manipulate_list
struct ast_audiohook_list::@303 whisper_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_audiohook::@187 list
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
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
union ast_frame::@226 data
enum ast_frame_type frametype
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
#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 ...
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().
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)