Audiohooks Architecture. More...


Go to the source code of this file.
Data Structures | |
| struct | ast_audiohook |
| struct | ast_audiohook_options |
Defines | |
| #define | ast_audiohook_lock(ah) ast_mutex_lock(&(ah)->lock) |
| Lock an audiohook. | |
| #define | ast_audiohook_unlock(ah) ast_mutex_unlock(&(ah)->lock) |
| Unlock an audiohook. | |
Typedefs | |
| typedef int(* | ast_audiohook_manipulate_callback )(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction) |
| Callback function for manipulate audiohook type. | |
Enumerations | |
| enum | ast_audiohook_direction { AST_AUDIOHOOK_DIRECTION_READ = 0, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_DIRECTION_BOTH } |
| enum | ast_audiohook_flags { AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0), AST_AUDIOHOOK_TRIGGER_READ = (1 << 0), AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), AST_AUDIOHOOK_WANTS_DTMF = (1 << 2), AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 3), AST_AUDIOHOOK_SMALL_QUEUE = (1 << 4), AST_AUDIOHOOK_MUTE_READ = (1 << 5), AST_AUDIOHOOK_MUTE_WRITE = (1 << 6) } |
| enum | ast_audiohook_init_flags { AST_AUDIOHOOK_MANIPULATE_ALL_RATES = (1 << 0) } |
| enum | ast_audiohook_status { AST_AUDIOHOOK_STATUS_NEW = 0, AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_STATUS_SHUTDOWN, AST_AUDIOHOOK_STATUS_DONE } |
| enum | ast_audiohook_type { AST_AUDIOHOOK_TYPE_SPY = 0, AST_AUDIOHOOK_TYPE_WHISPER, AST_AUDIOHOOK_TYPE_MANIPULATE } |
Functions | |
| int | ast_audiohook_attach (struct ast_channel *chan, struct ast_audiohook *audiohook) |
| Attach audiohook to channel. | |
| int | ast_audiohook_destroy (struct ast_audiohook *audiohook) |
| Destroys an audiohook structure. | |
| int | ast_audiohook_detach (struct ast_audiohook *audiohook) |
| Detach audiohook from channel. | |
| int | ast_audiohook_detach_list (struct ast_audiohook_list *audiohook_list) |
| Detach audiohooks from list and destroy said list. | |
| int | ast_audiohook_detach_source (struct ast_channel *chan, const char *source) |
| Detach specified source audiohook from channel. | |
| int | ast_audiohook_init (struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags) |
| Initialize an audiohook structure. | |
| 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_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_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 data to provided arguments. | |
| int | ast_audiohook_remove (struct ast_channel *chan, struct ast_audiohook *audiohook) |
| Remove an audiohook from a specified channel. | |
| 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. | |
| void | ast_audiohook_trigger_wait (struct ast_audiohook *audiohook) |
| Wait for audiohook trigger to be triggered. | |
| void | ast_audiohook_update_status (struct ast_audiohook *audiohook, enum ast_audiohook_status status) |
| Update audiohook's status. | |
| 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_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. | |
| 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. | |
| 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. | |
| 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. | |
| int | ast_audiohook_write_list_empty (struct ast_audiohook_list *audiohook_list) |
| determines if a audiohook_list is empty or not. | |
| 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_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. | |
Audiohooks Architecture.
Definition in file audiohook.h.
| #define ast_audiohook_lock | ( | ah | ) | ast_mutex_lock(&(ah)->lock) |
Lock an audiohook.
| ah | Audiohook structure |
Definition at line 278 of file audiohook.h.
Referenced by ast_audiohook_move_by_source(), ast_audiohook_update_status(), audio_audiohook_write_list(), channel_spy(), destroy_callback(), destroy_monitor_audiohook(), dtmf_audiohook_write_list(), mixmonitor_thread(), spy_generate(), and stop_mixmonitor_full().
| #define ast_audiohook_unlock | ( | ah | ) | ast_mutex_unlock(&(ah)->lock) |
Unlock an audiohook.
| ah | Audiohook structure |
Definition at line 283 of file audiohook.h.
Referenced by ast_audiohook_move_by_source(), ast_audiohook_update_status(), audio_audiohook_write_list(), channel_spy(), destroy_callback(), destroy_monitor_audiohook(), dtmf_audiohook_write_list(), mixmonitor_thread(), spy_generate(), and stop_mixmonitor_full().
| typedef int(* ast_audiohook_manipulate_callback)(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction) |
Callback function for manipulate audiohook type.
| audiohook | Audiohook structure |
| chan | Channel |
| frame | Frame of audio to manipulate |
| direction | Direction frame came from |
Definition at line 93 of file audiohook.h.
| AST_AUDIOHOOK_DIRECTION_READ |
Reading audio in |
| AST_AUDIOHOOK_DIRECTION_WRITE |
Writing audio out |
| AST_AUDIOHOOK_DIRECTION_BOTH |
Both reading audio in and writing audio out |
Definition at line 48 of file audiohook.h.
{
AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
AST_AUDIOHOOK_DIRECTION_WRITE, /*!< Writing audio out */
AST_AUDIOHOOK_DIRECTION_BOTH, /*!< Both reading audio in and writing audio out */
};
| enum ast_audiohook_flags |
Definition at line 54 of file audiohook.h.
{
AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0), /*!< When audiohook should be triggered to do something */
AST_AUDIOHOOK_TRIGGER_READ = (1 << 0), /*!< Audiohook wants to be triggered when reading audio in */
AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
AST_AUDIOHOOK_WANTS_DTMF = (1 << 2), /*!< Audiohook also wants to receive DTMF frames */
AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 3), /*!< Audiohook wants to be triggered when both sides have combined audio available */
/*! Audiohooks with this flag set will not allow for a large amount of samples to build up on its
* slinfactories. We will flush the factories if they contain too many samples.
*/
AST_AUDIOHOOK_SMALL_QUEUE = (1 << 4),
AST_AUDIOHOOK_MUTE_READ = (1 << 5), /*!< audiohook should be mute frames read */
AST_AUDIOHOOK_MUTE_WRITE = (1 << 6), /*!< audiohook should be mute frames written */
};
Definition at line 68 of file audiohook.h.
{
/*! Audiohook manipulate callback is capable of handling slinear at any sample rate.
* Without enabling this flag on initialization the manipulation callback is guaranteed
* 8khz audio only. */
AST_AUDIOHOOK_MANIPULATE_ALL_RATES = (1 << 0),
};
| enum ast_audiohook_status |
Definition at line 41 of file audiohook.h.
{
AST_AUDIOHOOK_STATUS_NEW = 0, /*!< Audiohook was just created, not in use yet */
AST_AUDIOHOOK_STATUS_RUNNING, /*!< Audiohook is running on a channel */
AST_AUDIOHOOK_STATUS_SHUTDOWN, /*!< Audiohook is being shutdown */
AST_AUDIOHOOK_STATUS_DONE, /*!< Audiohook has shutdown and is not running on a channel any longer */
};
| enum ast_audiohook_type |
Definition at line 35 of file audiohook.h.
{
AST_AUDIOHOOK_TYPE_SPY = 0, /*!< Audiohook wants to receive audio */
AST_AUDIOHOOK_TYPE_WHISPER, /*!< Audiohook wants to provide audio to be mixed with existing audio */
AST_AUDIOHOOK_TYPE_MANIPULATE, /*!< Audiohook wants to manipulate the audio */
};
| int ast_audiohook_attach | ( | struct ast_channel * | chan, |
| struct ast_audiohook * | audiohook | ||
| ) |
Attach audiohook to channel.
| chan | Channel |
| audiohook | Audiohook structure |
Definition at line 439 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_audiohook_update_status(), ast_calloc, ast_channel_audiohooks(), ast_channel_audiohooks_set(), ast_channel_lock, ast_channel_unlock, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, audiohook_list_set_samplerate_compatibility(), audiohook_set_internal_rate(), ast_audiohook_list::list_internal_samp_rate, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::type, and ast_audiohook_list::whisper_list.
Referenced by ast_audiohook_move_by_source(), audiohook_volume_get(), enable_jack_hook(), mute_add_audiohook(), pitchshift_helper(), speex_write(), start_spying(), startmon(), and volume_write().
{
ast_channel_lock(chan);
if (!ast_channel_audiohooks(chan)) {
struct ast_audiohook_list *ahlist;
/* Whoops... allocate a new structure */
if (!(ahlist = ast_calloc(1, sizeof(*ahlist)))) {
ast_channel_unlock(chan);
return -1;
}
ast_channel_audiohooks_set(chan, ahlist);
AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->spy_list);
AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->whisper_list);
AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->manipulate_list);
/* This sample rate will adjust as necessary when writing to the list. */
ast_channel_audiohooks(chan)->list_internal_samp_rate = 8000;
}
/* Drop into respective list */
if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
audiohook_set_internal_rate(audiohook, ast_channel_audiohooks(chan)->list_internal_samp_rate, 1);
audiohook_list_set_samplerate_compatibility(ast_channel_audiohooks(chan));
/* Change status over to running since it is now attached */
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_RUNNING);
ast_channel_unlock(chan);
return 0;
}
| int ast_audiohook_destroy | ( | struct ast_audiohook * | audiohook | ) |
Destroys an audiohook structure.
| audiohook | Audiohook structure |
Definition at line 130 of file audiohook.c.
References AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_cond_destroy, ast_mutex_destroy, ast_slinfactory_destroy(), ast_translator_free_path(), ast_audiohook::lock, ast_audiohook::read_factory, ast_audiohook::trans_pvt, ast_audiohook::trigger, ast_audiohook::type, and ast_audiohook::write_factory.
Referenced by audiohook_volume_destroy(), channel_spy(), destroy_callback(), destroy_jack_data(), destroy_monitor_audiohook(), and launch_monitor_thread().
{
/* Drop the factories used by this audiohook type */
switch (audiohook->type) {
case AST_AUDIOHOOK_TYPE_SPY:
ast_slinfactory_destroy(&audiohook->read_factory);
case AST_AUDIOHOOK_TYPE_WHISPER:
ast_slinfactory_destroy(&audiohook->write_factory);
break;
default:
break;
}
/* Destroy translation path if present */
if (audiohook->trans_pvt)
ast_translator_free_path(audiohook->trans_pvt);
/* Lock and trigger be gone! */
ast_cond_destroy(&audiohook->trigger);
ast_mutex_destroy(&audiohook->lock);
return 0;
}
| int ast_audiohook_detach | ( | struct ast_audiohook * | audiohook | ) |
Detach audiohook from channel.
| audiohook | Audiohook structure |
Definition at line 500 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_NEW, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_audiohook_trigger_wait(), ast_audiohook_update_status(), and ast_audiohook::status.
Referenced by channel_spy(), destroy_callback(), destroy_monitor_audiohook(), disable_jack_hook(), and speex_write().
{
if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
return 0;
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);
while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
ast_audiohook_trigger_wait(audiohook);
return 0;
}
| int ast_audiohook_detach_list | ( | struct ast_audiohook_list * | audiohook_list | ) |
Detach audiohooks from list and destroy said list.
| audiohook_list | List of audiohooks |
Definition at line 517 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_update_status(), ast_free, AST_LIST_REMOVE_HEAD, ast_translator_free_path(), ast_audiohook_list::in_translate, ast_audiohook::list, ast_audiohook::manipulate_callback, ast_audiohook_list::manipulate_list, ast_audiohook_list::out_translate, ast_audiohook_list::spy_list, ast_audiohook_translate::trans_pvt, and ast_audiohook_list::whisper_list.
Referenced by __ast_read(), ast_write(), and destroy_hooks().
{
int i = 0;
struct ast_audiohook *audiohook = NULL;
/* Drop any spies */
while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
}
/* Drop any whispering sources */
while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
}
/* Drop any manipulaters */
while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
}
/* Drop translation paths if present */
for (i = 0; i < 2; i++) {
if (audiohook_list->in_translate[i].trans_pvt)
ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
if (audiohook_list->out_translate[i].trans_pvt)
ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt);
}
/* Free ourselves */
ast_free(audiohook_list);
return 0;
}
| int ast_audiohook_detach_source | ( | struct ast_channel * | chan, |
| const char * | source | ||
| ) |
Detach specified source audiohook from channel.
| chan | Channel to detach from |
| source | Name of source to detach |
| chan | Channel to detach from |
| source | Name of source to detach |
Definition at line 608 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_audiohook_update_status(), ast_channel_audiohooks(), ast_channel_lock, ast_channel_unlock, find_audiohook_by_source(), and ast_audiohook::status.
{
struct ast_audiohook *audiohook = NULL;
ast_channel_lock(chan);
/* Ensure the channel has audiohooks on it */
if (!ast_channel_audiohooks(chan)) {
ast_channel_unlock(chan);
return -1;
}
audiohook = find_audiohook_by_source(ast_channel_audiohooks(chan), source);
ast_channel_unlock(chan);
if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);
return (audiohook ? 0 : -1);
}
| 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.
| audiohook | Audiohook structure |
| type | Type of audiohook to initialize this as |
| source | Who is initializing this audiohook |
| init | flags |
| audiohook | Audiohook structure |
| type | |
| source |
Definition at line 105 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_NEW, ast_audiohook_update_status(), ast_cond_init, ast_mutex_init, audiohook_set_internal_rate(), ast_audiohook::init_flags, ast_audiohook::lock, ast_audiohook::source, ast_audiohook::trigger, type, and ast_audiohook::type.
Referenced by audiohook_volume_get(), channel_spy(), enable_jack_hook(), initialize_mutehook(), launch_monitor_thread(), pitchshift_helper(), speex_write(), and volume_write().
{
/* Need to keep the type and source */
audiohook->type = type;
audiohook->source = source;
/* Initialize lock that protects our audiohook */
ast_mutex_init(&audiohook->lock);
ast_cond_init(&audiohook->trigger, NULL);
audiohook->init_flags = init_flags;
/* initialize internal rate at 8khz, this will adjust if necessary */
audiohook_set_internal_rate(audiohook, 8000, 0);
/* Since we are just starting out... this audiohook is new */
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_NEW);
return 0;
}
| 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.
| old_chan | The source of the audiohook to move |
| new_chan | The destination to which we want the audiohook to move |
| source | The source of the audiohook we want to move |
Definition at line 579 of file audiohook.c.
References ast_audiohook_attach(), ast_audiohook_lock, ast_audiohook_remove(), ast_audiohook_unlock, ast_channel_audiohooks(), find_audiohook_by_source(), and ast_audiohook::status.
Referenced by audiohook_inheritance_fixup().
{
struct ast_audiohook *audiohook;
enum ast_audiohook_status oldstatus;
if (!ast_channel_audiohooks(old_chan) || !(audiohook = find_audiohook_by_source(ast_channel_audiohooks(old_chan), source))) {
return;
}
/* By locking both channels and the audiohook, we can assure that
* another thread will not have a chance to read the audiohook's status
* as done, even though ast_audiohook_remove signals the trigger
* condition.
*/
ast_audiohook_lock(audiohook);
oldstatus = audiohook->status;
ast_audiohook_remove(old_chan, audiohook);
ast_audiohook_attach(new_chan, audiohook);
audiohook->status = oldstatus;
ast_audiohook_unlock(audiohook);
}
| struct ast_frame* ast_audiohook_read_frame | ( | struct ast_audiohook * | audiohook, |
| size_t | samples, | ||
| enum ast_audiohook_direction | direction, | ||
| struct ast_format * | format | ||
| ) | [read] |
Reads a frame in from the audiohook structure.
| audiohook | Audiohook structure |
| samples | Number of samples wanted |
| direction | Direction the audio frame came from |
| format | Format of frame remote side wants back |
| audiohook | Audiohook structure |
| samples | Number of samples wanted in requested output format |
| direction | Direction the audio frame came from |
| format | Format of frame remote side wants back |
Definition at line 403 of file audiohook.c.
References audiohook_read_frame_helper().
Referenced by spy_generate().
{
return audiohook_read_frame_helper(audiohook, samples, direction, format, NULL, NULL);
}
| 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 | ||
| ) | [read] |
Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame data to provided arguments.
| audiohook | Audiohook structure |
| samples | Number of samples wanted |
| direction | Direction the audio frame came from |
| format | Format of frame remote side wants back |
| ast_frame | read_frame - if available, we'll copy the read buffer to this. |
| ast_frame | write_frame - if available, we'll copy the write buffer to this. |
Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame data to provided arguments.
| audiohook | Audiohook structure |
| samples | Number of samples wanted |
| direction | Direction the audio frame came from |
| format | Format of frame remote side wants back |
| read_frame | frame pointer for copying read frame data |
| write_frame | frame pointer for copying write frame data |
Definition at line 417 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_BOTH, and audiohook_read_frame_helper().
Referenced by mixmonitor_thread().
{
return audiohook_read_frame_helper(audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, format, read_frame, write_frame);
}
| int ast_audiohook_remove | ( | struct ast_channel * | chan, |
| struct ast_audiohook * | audiohook | ||
| ) |
Remove an audiohook from a specified channel.
| chan | Channel to remove from |
| audiohook | Audiohook to remove |
Definition at line 640 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_audiohook_update_status(), ast_channel_audiohooks(), ast_channel_lock, ast_channel_unlock, AST_LIST_REMOVE, audiohook_list_set_samplerate_compatibility(), ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::type, and ast_audiohook_list::whisper_list.
Referenced by ast_audiohook_move_by_source(), and speex_write().
{
ast_channel_lock(chan);
if (!ast_channel_audiohooks(chan)) {
ast_channel_unlock(chan);
return -1;
}
if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
audiohook_list_set_samplerate_compatibility(ast_channel_audiohooks(chan));
ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
ast_channel_unlock(chan);
return 0;
}
| 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.
| chan | Channel to muck with |
| source | Type of audiohook |
| flag | which direction to set / clear |
| clear | set or clear muted frames on direction based on flag parameter |
| 0 | success |
| -1 | failure |
| chan | Channel to muck with |
| source | Type of audiohook |
| flag | which flag to set / clear |
| clear | set or clear |
Definition at line 1211 of file audiohook.c.
References ast_channel_audiohooks(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_set_flag, and find_audiohook_by_source().
Referenced by manager_mute_mixmonitor().
{
struct ast_audiohook *audiohook = NULL;
ast_channel_lock(chan);
/* Ensure the channel has audiohooks on it */
if (!ast_channel_audiohooks(chan)) {
ast_channel_unlock(chan);
return -1;
}
audiohook = find_audiohook_by_source(ast_channel_audiohooks(chan), source);
if (audiohook) {
if (clear) {
ast_clear_flag(audiohook, flag);
} else {
ast_set_flag(audiohook, flag);
}
}
ast_channel_unlock(chan);
return (audiohook ? 0 : -1);
}
| void ast_audiohook_trigger_wait | ( | struct ast_audiohook * | audiohook | ) |
Wait for audiohook trigger to be triggered.
| audiohook | Audiohook to wait on |
Definition at line 930 of file audiohook.c.
References ast_cond_timedwait, ast_samp2tv(), ast_tvadd(), ast_tvnow(), ast_audiohook::lock, and ast_audiohook::trigger.
Referenced by ast_audiohook_detach(), and mixmonitor_thread().
{
struct timeval wait;
struct timespec ts;
wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
ts.tv_sec = wait.tv_sec;
ts.tv_nsec = wait.tv_usec * 1000;
ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
return;
}
| void ast_audiohook_update_status | ( | struct ast_audiohook * | audiohook, |
| enum ast_audiohook_status | status | ||
| ) |
Update audiohook's status.
| audiohook | Audiohook structure |
| audiohook | status enum |
| audiohook | Audiohook structure |
| status | Audiohook status enum |
Definition at line 486 of file audiohook.c.
References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_unlock, ast_cond_signal, ast_audiohook::status, status, and ast_audiohook::trigger.
Referenced by ast_audiohook_attach(), ast_audiohook_detach(), ast_audiohook_detach_list(), ast_audiohook_detach_source(), ast_audiohook_init(), ast_audiohook_remove(), audio_audiohook_write_list(), dtmf_audiohook_write_list(), and stop_mixmonitor_full().
{
ast_audiohook_lock(audiohook);
if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
audiohook->status = status;
ast_cond_signal(&audiohook->trigger);
}
ast_audiohook_unlock(audiohook);
}
| 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.
| chan | Channel to muck with |
| direction | Direction to increase |
| volume | Value to adjust the adjustment by |
| chan | Channel to muck with |
| direction | Direction to increase |
| volume | Value to adjust the adjustment by |
Definition at line 1184 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_BOTH, AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.
Referenced by execute_menu_entry().
{
struct audiohook_volume *audiohook_volume = NULL;
/* Attempt to find the audiohook volume information, and create an audiohook if none exists */
if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
return -1;
}
/* Based on the direction change the specific adjustment value */
if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
audiohook_volume->read_adjustment += volume;
}
if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
audiohook_volume->write_adjustment += volume;
}
return 0;
}
| 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.
| chan | Channel to retrieve volume adjustment from |
| direction | Direction to retrieve |
| chan | Channel to retrieve volume adjustment from |
| direction | Direction to retrieve |
Definition at line 1158 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.
Referenced by confbridge_exec().
{
struct audiohook_volume *audiohook_volume = NULL;
int adjustment = 0;
/* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
return 0;
}
/* Grab the adjustment value based on direction given */
if (direction == AST_AUDIOHOOK_DIRECTION_READ) {
adjustment = audiohook_volume->read_adjustment;
} else if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
adjustment = audiohook_volume->write_adjustment;
}
return adjustment;
}
| 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.
| chan | Channel to muck with |
| direction | Direction to set on |
| volume | Value to adjust the volume by |
| chan | Channel to muck with |
| direction | Direction to set on |
| volume | Value to adjust the volume by |
Definition at line 1133 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_BOTH, AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.
Referenced by confbridge_exec(), and execute_menu_entry().
{
struct audiohook_volume *audiohook_volume = NULL;
/* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
return -1;
}
/* Now based on the direction set the proper value */
if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
audiohook_volume->read_adjustment = volume;
}
if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
audiohook_volume->write_adjustment = volume;
}
return 0;
}
| 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.
| audiohook | Audiohook structure |
| direction | Direction the audio frame came from |
| frame | Frame to write in |
Definition at line 160 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_MUTE_READ, AST_AUDIOHOOK_MUTE_WRITE, AST_AUDIOHOOK_SMALL_QUEUE, AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE, AST_AUDIOHOOK_SYNC_TOLERANCE, AST_AUDIOHOOK_TRIGGER_MODE, AST_AUDIOHOOK_TRIGGER_READ, AST_AUDIOHOOK_TRIGGER_SYNC, AST_AUDIOHOOK_TRIGGER_WRITE, ast_cond_signal, ast_debug, ast_frame_clear(), ast_slinfactory_available(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_frame::datalen, ast_audiohook::hook_internal_samp_rate, ast_audiohook::read_factory, ast_audiohook::read_time, ast_audiohook::trigger, ast_audiohook::write_factory, and ast_audiohook::write_time.
Referenced by audio_audiohook_write_list(), and channel_spy().
{
struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
int our_factory_samples;
int our_factory_ms;
int other_factory_samples;
int other_factory_ms;
int muteme = 0;
/* Update last feeding time to be current */
*rwtime = ast_tvnow();
our_factory_samples = ast_slinfactory_available(factory);
our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / (audiohook->hook_internal_samp_rate / 1000));
other_factory_samples = ast_slinfactory_available(other_factory);
other_factory_ms = other_factory_samples / (audiohook->hook_internal_samp_rate / 1000);
if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
ast_debug(1, "Flushing audiohook %p so it remains in sync\n", audiohook);
ast_slinfactory_flush(factory);
ast_slinfactory_flush(other_factory);
}
if (ast_test_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE) && ((our_factory_ms > AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE) || (other_factory_ms > AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE))) {
ast_debug(1, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
ast_slinfactory_flush(factory);
ast_slinfactory_flush(other_factory);
}
/* swap frame data for zeros if mute is required */
if ((ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) ||
(ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) ||
(ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE) == (AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE))) {
muteme = 1;
}
if (muteme && frame->datalen > 0) {
ast_frame_clear(frame);
}
/* Write frame out to respective factory */
ast_slinfactory_feed(factory, frame);
/* If we need to notify the respective handler of this audiohook, do so */
if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
ast_cond_signal(&audiohook->trigger);
} else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) {
ast_cond_signal(&audiohook->trigger);
} else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
ast_cond_signal(&audiohook->trigger);
}
return 0;
}
| 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 | ||
| ) | [read] |
Pass a frame off to be handled by the audiohook core.
| chan | Channel that the list is coming off of |
| audiohook_list | List of audiohooks |
| direction | Direction frame is coming in from |
| frame | The frame itself |
Definition at line 916 of file audiohook.c.
References AST_FRAME_DTMF, AST_FRAME_VOICE, audio_audiohook_write_list(), dtmf_audiohook_write_list(), and ast_frame::frametype.
Referenced by __ast_read(), and ast_write().
{
/* Pass off frame to it's respective list write function */
if (frame->frametype == AST_FRAME_VOICE)
return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
else if (frame->frametype == AST_FRAME_DTMF)
return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
else
return frame;
}
| int ast_audiohook_write_list_empty | ( | struct ast_audiohook_list * | audiohook_list | ) |
determines if a audiohook_list is empty or not.
retval 0 false, 1 true
Definition at line 898 of file audiohook.c.
References AST_LIST_EMPTY, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.
Referenced by __ast_read(), and ast_write().
{
if (AST_LIST_EMPTY(&audiohook_list->spy_list) &&
AST_LIST_EMPTY(&audiohook_list->whisper_list) &&
AST_LIST_EMPTY(&audiohook_list->manipulate_list)) {
return 1;
}
return 0;
}
| 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.
| chan | The channel on which to find the spies |
| source | The audiohook's source |
| type | The type of audiohook |
Note: Function performs nlocking.
Definition at line 945 of file audiohook.c.
References AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_channel_audiohooks(), ast_debug, AST_LIST_TRAVERSE, ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook::source, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.
Referenced by builtin_automixmonitor().
{
int count = 0;
struct ast_audiohook *ah = NULL;
if (!ast_channel_audiohooks(chan))
return -1;
switch (type) {
case AST_AUDIOHOOK_TYPE_SPY:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
if (!strcmp(ah->source, source)) {
count++;
}
}
break;
case AST_AUDIOHOOK_TYPE_WHISPER:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
if (!strcmp(ah->source, source)) {
count++;
}
}
break;
case AST_AUDIOHOOK_TYPE_MANIPULATE:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
if (!strcmp(ah->source, source)) {
count++;
}
}
break;
default:
ast_debug(1, "Invalid audiohook type supplied, (%d)\n", type);
return -1;
}
return count;
}
| 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.
| chan | The channel on which to find the spies |
| source | The source of the audiohook |
| type | The type of spy to look for |
Note: Function performs no locking.
Definition at line 984 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_channel_audiohooks(), ast_debug, AST_LIST_TRAVERSE, ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook::source, ast_audiohook_list::spy_list, ast_audiohook::status, and ast_audiohook_list::whisper_list.
Referenced by builtin_automixmonitor().
{
int count = 0;
struct ast_audiohook *ah = NULL;
if (!ast_channel_audiohooks(chan))
return -1;
switch (type) {
case AST_AUDIOHOOK_TYPE_SPY:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
count++;
}
break;
case AST_AUDIOHOOK_TYPE_WHISPER:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
count++;
}
break;
case AST_AUDIOHOOK_TYPE_MANIPULATE:
AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
count++;
}
break;
default:
ast_debug(1, "Invalid audiohook type supplied, (%d)\n", type);
return -1;
}
return count;
}