67 audiohook->type =
type;
68 audiohook->source = source;
99 switch (audiohook->
type) {
132 int our_factory_samples;
134 int other_factory_samples;
135 int other_factory_ms;
142 our_factory_ms =
ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / 8);
144 other_factory_ms = other_factory_samples / 8;
148 ast_log(
LOG_DEBUG,
"Flushing audiohook %p so it remains in sync\n", audiohook);
155 ast_log(
LOG_DEBUG,
"Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
168 if (muteme && frame->
datalen > 0) {
196 .datalen =
sizeof(buf),
217 int i = 0, usable_read, usable_write;
218 short buf1[
samples],
buf2[
samples], *read_buf = NULL, *write_buf = NULL, *final_buf = NULL, *data1 = NULL, *data2 = NULL;
223 .datalen =
sizeof(
buf1),
231 if (!usable_read && !usable_write) {
239 ast_debug(3,
"Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->
write_factory);
245 ast_debug(3,
"Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->
read_factory);
257 for (count = 0; count <
samples; count++) {
276 for (count = 0; count <
samples; count++) {
288 if (!read_buf && !write_buf)
290 else if (read_buf && write_buf) {
291 for (i = 0, data1 = read_buf, data2 = write_buf; i <
samples; i++, data1++, data2++)
323 if (audiohook->
format != format) {
440 for (i = 0; i < 2; i++) {
463 if (!strcasecmp(audiohook->
source, source))
468 if (!strcasecmp(audiohook->
source, source))
473 if (!strcasecmp(audiohook->
source, source))
495 oldstatus = audiohook->
status;
500 audiohook->
status = oldstatus;
528 return (audiohook ? 0 : -1);
626 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame;
642 samples = middle_frame->
samples;
663 short read_buf[samples], combine_buf[samples], *data1 = NULL, *data2 = NULL;
664 memset(&combine_buf, 0,
sizeof(combine_buf));
675 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++)
682 for (i = 0, data1 = middle_frame->data.ptr, data2 = combine_buf; i < samples; i++, data1++, data2++)
684 end_frame = middle_frame;
710 end_frame = middle_frame;
714 if (middle_frame == end_frame) {
716 if (end_frame->subclass.codec != start_frame->
subclass.
codec) {
782 ts.tv_sec = wait.tv_sec;
783 ts.tv_nsec = wait.tv_usec * 1000;
802 if (!strcmp(ah->
source, source)) {
809 if (!strcmp(ah->
source, source)) {
816 if (!strcmp(ah->
source, source)) {
916 audiohook_volume = datastore->
data;
945 return datastore->
data;
954 if (!(audiohook_volume =
ast_calloc(1,
sizeof(*audiohook_volume)))) {
964 datastore->
data = audiohook_volume;
970 return audiohook_volume;
1081 return (audiohook ? 0 : -1);
struct ast_audiohook audiohook
static struct ast_datastore_info audiohook_volume_datastore
Datastore used to store audiohook volume information.
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.
union ast_frame_subclass subclass
Audiohook volume adjustment structure.
#define ast_channel_lock(chan)
Main Channel structure associated with 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.
struct ast_audiohook_list::@225 manipulate_list
struct ast_frame * ast_audiohook_read_frame(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, format_t format)
Reads a frame in from the audiohook structure.
struct ast_slinfactory write_factory
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static void audiohook_volume_destroy(void *data)
Callback used to destroy the audiohook volume datastore.
enum ast_audiohook_type type
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.
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_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_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
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.
#define ast_test_flag(p, flag)
Support for translation of data formats. translate.c.
int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
determines if a audiohook_list is empty or not.
#define ast_set_flag(p, flag)
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source)
Initialize an audiohook structure.
struct ast_audiohook_translate out_translate[2]
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
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_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...
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
#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...
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.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define ast_cond_signal(cond)
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.
ast_audiohook_manipulate_callback manipulate_callback
struct ast_trans_pvt * ast_translator_build_path(format_t dest, format_t source)
Builds a translator path Build a path (possibly NULL) from source to dest.
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
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_debug(level,...)
Log a DEBUG message.
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
General Asterisk PBX channel definitions.
struct ast_audiohook_list * audiohooks
Asterisk internal frame definitions.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
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
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
int ast_audiohook_detach_source(struct ast_channel *chan, const char *source)
Detach specified source audiohook from channel.
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
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.
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
struct ast_audiohook_list::@224 whisper_list
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ast_cond_destroy(cond)
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
static struct ast_threadstorage buf1
struct ast_audiohook::@143 list
#define ast_channel_unlock(chan)
A machine to gather up arbitrary frames and convert them to raw slinear on demand.
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
void ast_slinfactory_init(struct ast_slinfactory *sf)
Initialize 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_both(struct ast_audiohook *audiohook, size_t samples)
#define ast_clear_flag(p, flag)
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.
#define AST_AUDIOHOOK_SYNC_TOLERANCE
#define AST_FORMAT_SLINEAR
struct timeval write_time
int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
Adjusts the volume of the audio samples contained in a frame.
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.
enum ast_audiohook_status status
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
struct ast_audiohook_list::@223 spy_list
#define ast_audiohook_lock(ah)
Lock an audiohook.
static snd_pcm_format_t format
union ast_frame::@172 data
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
int ast_audiohook_detach_list(struct ast_audiohook_list *audiohook_list)
Detach audiohooks from list and destroy said list.
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
static struct ast_frame * audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
#define ast_cond_timedwait(cond, mutex, 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...
struct ast_frame * ast_frdup(const struct ast_frame *fr)
Copies a frame.
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
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.