#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/audiohook.h"
#include "asterisk/slinfactory.h"
#include "asterisk/frame.h"
#include "asterisk/translate.h"
Go to the source code of this file.
Data Structures | |
struct | ast_audiohook_list |
struct | ast_audiohook_translate |
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) |
Initialize an audiohook structure. | |
ast_frame * | ast_audiohook_read_frame (struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, int format) |
Reads a frame in from the audiohook structure. | |
void | ast_audiohook_trigger_wait (struct ast_audiohook *audiohook) |
Wait for audiohook trigger to be triggered. | |
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. | |
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. | |
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 struct ast_frame * | audiohook_read_frame_both (struct ast_audiohook *audiohook, size_t samples) |
static struct ast_frame * | audiohook_read_frame_single (struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction) |
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_audiohook * | find_audiohook_by_source (struct ast_audiohook_list *audiohook_list, const char *source) |
Definition in file audiohook.c.
int ast_audiohook_attach | ( | struct ast_channel * | chan, | |
struct ast_audiohook * | audiohook | |||
) |
Attach audiohook to channel.
chan | Channel | |
audiohook | Audiohook structure |
Definition at line 324 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_calloc, ast_channel_lock, ast_channel_unlock, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, ast_channel::audiohooks, ast_audiohook::status, and ast_audiohook::type.
Referenced by start_spying(), and startmon().
00325 { 00326 ast_channel_lock(chan); 00327 00328 if (!chan->audiohooks) { 00329 /* Whoops... allocate a new structure */ 00330 if (!(chan->audiohooks = ast_calloc(1, sizeof(*chan->audiohooks)))) { 00331 ast_channel_unlock(chan); 00332 return -1; 00333 } 00334 AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->spy_list); 00335 AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->whisper_list); 00336 AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->manipulate_list); 00337 } 00338 00339 /* Drop into respective list */ 00340 if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) 00341 AST_LIST_INSERT_TAIL(&chan->audiohooks->spy_list, audiohook, list); 00342 else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) 00343 AST_LIST_INSERT_TAIL(&chan->audiohooks->whisper_list, audiohook, list); 00344 else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) 00345 AST_LIST_INSERT_TAIL(&chan->audiohooks->manipulate_list, audiohook, list); 00346 00347 /* Change status over to running since it is now attached */ 00348 audiohook->status = AST_AUDIOHOOK_STATUS_RUNNING; 00349 00350 ast_channel_unlock(chan); 00351 00352 return 0; 00353 }
int ast_audiohook_destroy | ( | struct ast_audiohook * | audiohook | ) |
Destroys an audiohook structure.
audiohook | Audiohook structure |
Definition at line 98 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 channel_spy(), launch_monitor_thread(), and mixmonitor_thread().
00099 { 00100 /* Drop the factories used by this audiohook type */ 00101 switch (audiohook->type) { 00102 case AST_AUDIOHOOK_TYPE_SPY: 00103 ast_slinfactory_destroy(&audiohook->read_factory); 00104 case AST_AUDIOHOOK_TYPE_WHISPER: 00105 ast_slinfactory_destroy(&audiohook->write_factory); 00106 break; 00107 default: 00108 break; 00109 } 00110 00111 /* Destroy translation path if present */ 00112 if (audiohook->trans_pvt) 00113 ast_translator_free_path(audiohook->trans_pvt); 00114 00115 /* Lock and trigger be gone! */ 00116 ast_cond_destroy(&audiohook->trigger); 00117 ast_mutex_destroy(&audiohook->lock); 00118 00119 return 0; 00120 }
int ast_audiohook_detach | ( | struct ast_audiohook * | audiohook | ) |
Detach audiohook from channel.
audiohook | Audiohook structure |
Definition at line 359 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_audiohook_trigger_wait(), and ast_audiohook::status.
Referenced by channel_spy(), and mixmonitor_thread().
00360 { 00361 if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE) 00362 return 0; 00363 00364 audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN; 00365 00366 while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) 00367 ast_audiohook_trigger_wait(audiohook); 00368 00369 return 0; 00370 }
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 376 of file audiohook.c.
References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_unlock, ast_cond_signal(), ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_translator_free_path(), ast_audiohook_list::in_translate, ast_audiohook::manipulate_callback, ast_audiohook_list::out_translate, ast_audiohook::status, ast_audiohook_translate::trans_pvt, and ast_audiohook::trigger.
Referenced by ast_hangup().
00377 { 00378 int i = 0; 00379 struct ast_audiohook *audiohook = NULL; 00380 00381 /* Drop any spies */ 00382 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) { 00383 ast_audiohook_lock(audiohook); 00384 AST_LIST_REMOVE_CURRENT(&audiohook_list->spy_list, list); 00385 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00386 ast_cond_signal(&audiohook->trigger); 00387 ast_audiohook_unlock(audiohook); 00388 } 00389 AST_LIST_TRAVERSE_SAFE_END 00390 00391 /* Drop any whispering sources */ 00392 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) { 00393 ast_audiohook_lock(audiohook); 00394 AST_LIST_REMOVE_CURRENT(&audiohook_list->whisper_list, list); 00395 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00396 ast_cond_signal(&audiohook->trigger); 00397 ast_audiohook_unlock(audiohook); 00398 } 00399 AST_LIST_TRAVERSE_SAFE_END 00400 00401 /* Drop any manipulaters */ 00402 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) { 00403 ast_audiohook_lock(audiohook); 00404 AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list); 00405 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00406 ast_audiohook_unlock(audiohook); 00407 audiohook->manipulate_callback(audiohook, NULL, NULL, 0); 00408 } 00409 AST_LIST_TRAVERSE_SAFE_END 00410 00411 /* Drop translation paths if present */ 00412 for (i = 0; i < 2; i++) { 00413 if (audiohook_list->in_translate[i].trans_pvt) 00414 ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt); 00415 if (audiohook_list->out_translate[i].trans_pvt) 00416 ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt); 00417 } 00418 00419 /* Free ourselves */ 00420 ast_free(audiohook_list); 00421 00422 return 0; 00423 }
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 |
Definition at line 452 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_channel_lock, ast_channel_unlock, ast_channel::audiohooks, find_audiohook_by_source(), and ast_audiohook::status.
Referenced by mixmonitor_cli(), and stop_mixmonitor_exec().
00453 { 00454 struct ast_audiohook *audiohook = NULL; 00455 00456 ast_channel_lock(chan); 00457 00458 /* Ensure the channel has audiohooks on it */ 00459 if (!chan->audiohooks) { 00460 ast_channel_unlock(chan); 00461 return -1; 00462 } 00463 00464 audiohook = find_audiohook_by_source(chan->audiohooks, source); 00465 00466 ast_channel_unlock(chan); 00467 00468 if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) 00469 audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN; 00470 00471 return (audiohook ? 0 : -1); 00472 }
int ast_audiohook_init | ( | struct ast_audiohook * | audiohook, | |
enum ast_audiohook_type | type, | |||
const char * | source | |||
) |
Initialize an audiohook structure.
audiohook | Audiohook structure | |
type | ||
source |
Definition at line 67 of file audiohook.c.
References AST_AUDIOHOOK_STATUS_NEW, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_cond_init(), ast_mutex_init(), and ast_slinfactory_init().
Referenced by channel_spy(), and launch_monitor_thread().
00068 { 00069 /* Need to keep the type and source */ 00070 audiohook->type = type; 00071 audiohook->source = source; 00072 00073 /* Initialize lock that protects our audiohook */ 00074 ast_mutex_init(&audiohook->lock); 00075 ast_cond_init(&audiohook->trigger, NULL); 00076 00077 /* Setup the factories that are needed for this audiohook type */ 00078 switch (type) { 00079 case AST_AUDIOHOOK_TYPE_SPY: 00080 ast_slinfactory_init(&audiohook->read_factory); 00081 case AST_AUDIOHOOK_TYPE_WHISPER: 00082 ast_slinfactory_init(&audiohook->write_factory); 00083 break; 00084 default: 00085 break; 00086 } 00087 00088 /* Since we are just starting out... this audiohook is new */ 00089 audiohook->status = AST_AUDIOHOOK_STATUS_NEW; 00090 00091 return 0; 00092 }
struct ast_frame* ast_audiohook_read_frame | ( | struct ast_audiohook * | audiohook, | |
size_t | samples, | |||
enum ast_audiohook_direction | direction, | |||
int | format | |||
) |
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 |
Definition at line 289 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_BOTH, AST_FORMAT_SLINEAR, ast_frfree, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), audiohook_read_frame_both(), and audiohook_read_frame_single().
Referenced by mixmonitor_thread(), and spy_generate().
00290 { 00291 struct ast_frame *read_frame = NULL, *final_frame = NULL; 00292 00293 if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction)))) 00294 return NULL; 00295 00296 /* If they don't want signed linear back out, we'll have to send it through the translation path */ 00297 if (format != AST_FORMAT_SLINEAR) { 00298 /* Rebuild translation path if different format then previously */ 00299 if (audiohook->format != format) { 00300 if (audiohook->trans_pvt) { 00301 ast_translator_free_path(audiohook->trans_pvt); 00302 audiohook->trans_pvt = NULL; 00303 } 00304 /* Setup new translation path for this format... if we fail we can't very well return signed linear so free the frame and return nothing */ 00305 if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) { 00306 ast_frfree(read_frame); 00307 return NULL; 00308 } 00309 } 00310 /* Convert to requested format, and allow the read in frame to be freed */ 00311 final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1); 00312 } else { 00313 final_frame = read_frame; 00314 } 00315 00316 return final_frame; 00317 }
void ast_audiohook_trigger_wait | ( | struct ast_audiohook * | audiohook | ) |
Wait for audiohook trigger to be triggered.
audiohook | Audiohook to wait on |
Definition at line 647 of file audiohook.c.
References ast_cond_timedwait(), ast_tvadd(), ast_audiohook::lock, and ast_audiohook::trigger.
Referenced by ast_audiohook_detach(), and mixmonitor_thread().
00648 { 00649 struct timeval tv; 00650 struct timespec ts; 00651 00652 tv = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000)); 00653 ts.tv_sec = tv.tv_sec; 00654 ts.tv_nsec = tv.tv_usec * 1000; 00655 00656 ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts); 00657 00658 return; 00659 }
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 128 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_TRIGGER_MODE, AST_AUDIOHOOK_TRIGGER_READ, AST_AUDIOHOOK_TRIGGER_SYNC, AST_AUDIOHOOK_TRIGGER_WRITE, ast_cond_signal(), ast_log(), ast_slinfactory_available(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_test_flag, LOG_DEBUG, option_debug, 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().
00129 { 00130 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory); 00131 struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory); 00132 struct timeval *time = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *time; 00133 00134 /* Update last feeding time to be current */ 00135 *time = ast_tvnow(); 00136 00137 /* If we are using a sync trigger and this factory suddenly got audio fed in after a lapse, then flush both factories to ensure they remain in sync */ 00138 if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && ast_slinfactory_available(other_factory) && (ast_tvdiff_ms(*time, previous_time) > (ast_slinfactory_available(other_factory) / 8))) { 00139 if (option_debug) 00140 ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook); 00141 ast_slinfactory_flush(factory); 00142 ast_slinfactory_flush(other_factory); 00143 } 00144 00145 /* Write frame out to respective factory */ 00146 ast_slinfactory_feed(factory, frame); 00147 00148 /* If we need to notify the respective handler of this audiohook, do so */ 00149 if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) { 00150 ast_cond_signal(&audiohook->trigger); 00151 } else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) { 00152 ast_cond_signal(&audiohook->trigger); 00153 } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) { 00154 ast_cond_signal(&audiohook->trigger); 00155 } 00156 00157 return 0; 00158 }
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.
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 632 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().
00633 { 00634 /* Pass off frame to it's respective list write function */ 00635 if (frame->frametype == AST_FRAME_VOICE) 00636 return audio_audiohook_write_list(chan, audiohook_list, direction, frame); 00637 else if (frame->frametype == AST_FRAME_DTMF) 00638 return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame); 00639 else 00640 return frame; 00641 }
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 | |||
) | [static] |
Pass an AUDIO 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 510 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_RUNNING, ast_audiohook_unlock, ast_audiohook_write_frame(), ast_cond_signal(), AST_FORMAT_SLINEAR, ast_frfree, AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_slinear_saturated_add(), ast_slinfactory_available(), ast_slinfactory_read(), ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_audiohook_translate::format, ast_audiohook_list::in_translate, ast_audiohook::manipulate_callback, ast_audiohook_list::out_translate, ast_frame::samples, ast_audiohook::status, ast_frame::subclass, ast_audiohook_translate::trans_pvt, ast_audiohook::trigger, and ast_audiohook::write_factory.
Referenced by ast_audiohook_write_list().
00511 { 00512 struct ast_audiohook_translate *in_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->in_translate[0] : &audiohook_list->in_translate[1]); 00513 struct ast_audiohook_translate *out_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->out_translate[0] : &audiohook_list->out_translate[1]); 00514 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame; 00515 struct ast_audiohook *audiohook = NULL; 00516 int samples = frame->samples; 00517 00518 /* If the frame coming in is not signed linear we have to send it through the in_translate path */ 00519 if (frame->subclass != AST_FORMAT_SLINEAR) { 00520 if (in_translate->format != frame->subclass) { 00521 if (in_translate->trans_pvt) 00522 ast_translator_free_path(in_translate->trans_pvt); 00523 if (!(in_translate->trans_pvt = ast_translator_build_path(AST_FORMAT_SLINEAR, frame->subclass))) 00524 return frame; 00525 in_translate->format = frame->subclass; 00526 } 00527 if (!(middle_frame = ast_translate(in_translate->trans_pvt, frame, 0))) 00528 return frame; 00529 } 00530 00531 /* Queue up signed linear frame to each spy */ 00532 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) { 00533 ast_audiohook_lock(audiohook); 00534 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) { 00535 AST_LIST_REMOVE_CURRENT(&audiohook_list->spy_list, list); 00536 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00537 ast_cond_signal(&audiohook->trigger); 00538 ast_audiohook_unlock(audiohook); 00539 continue; 00540 } 00541 ast_audiohook_write_frame(audiohook, direction, middle_frame); 00542 ast_audiohook_unlock(audiohook); 00543 } 00544 AST_LIST_TRAVERSE_SAFE_END 00545 00546 /* If this frame is being written out to the channel then we need to use whisper sources */ 00547 if (direction == AST_AUDIOHOOK_DIRECTION_WRITE && !AST_LIST_EMPTY(&audiohook_list->whisper_list)) { 00548 int i = 0; 00549 short read_buf[samples], combine_buf[samples], *data1 = NULL, *data2 = NULL; 00550 memset(&combine_buf, 0, sizeof(combine_buf)); 00551 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) { 00552 ast_audiohook_lock(audiohook); 00553 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) { 00554 AST_LIST_REMOVE_CURRENT(&audiohook_list->whisper_list, list); 00555 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00556 ast_cond_signal(&audiohook->trigger); 00557 ast_audiohook_unlock(audiohook); 00558 continue; 00559 } 00560 if (ast_slinfactory_available(&audiohook->write_factory) >= samples && ast_slinfactory_read(&audiohook->write_factory, read_buf, samples)) { 00561 /* Take audio from this whisper source and combine it into our main buffer */ 00562 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++) 00563 ast_slinear_saturated_add(data1, data2); 00564 } 00565 ast_audiohook_unlock(audiohook); 00566 } 00567 AST_LIST_TRAVERSE_SAFE_END 00568 /* We take all of the combined whisper sources and combine them into the audio being written out */ 00569 for (i = 0, data1 = middle_frame->data, data2 = combine_buf; i < samples; i++, data1++, data2++) 00570 ast_slinear_saturated_add(data1, data2); 00571 end_frame = middle_frame; 00572 } 00573 00574 /* Pass off frame to manipulate audiohooks */ 00575 if (!AST_LIST_EMPTY(&audiohook_list->manipulate_list)) { 00576 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) { 00577 ast_audiohook_lock(audiohook); 00578 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) { 00579 AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list); 00580 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00581 ast_audiohook_unlock(audiohook); 00582 /* We basically drop all of our links to the manipulate audiohook and prod it to do it's own destructive things */ 00583 audiohook->manipulate_callback(audiohook, chan, NULL, direction); 00584 continue; 00585 } 00586 /* Feed in frame to manipulation */ 00587 audiohook->manipulate_callback(audiohook, chan, middle_frame, direction); 00588 ast_audiohook_unlock(audiohook); 00589 } 00590 AST_LIST_TRAVERSE_SAFE_END 00591 end_frame = middle_frame; 00592 } 00593 00594 /* Now we figure out what to do with our end frame (whether to transcode or not) */ 00595 if (middle_frame == end_frame) { 00596 /* Middle frame was modified and became the end frame... let's see if we need to transcode */ 00597 if (end_frame->subclass != start_frame->subclass) { 00598 if (out_translate->format != start_frame->subclass) { 00599 if (out_translate->trans_pvt) 00600 ast_translator_free_path(out_translate->trans_pvt); 00601 if (!(out_translate->trans_pvt = ast_translator_build_path(start_frame->subclass, AST_FORMAT_SLINEAR))) { 00602 /* We can't transcode this... drop our middle frame and return the original */ 00603 ast_frfree(middle_frame); 00604 return start_frame; 00605 } 00606 out_translate->format = start_frame->subclass; 00607 } 00608 /* Transcode from our middle (signed linear) frame to new format of the frame that came in */ 00609 if (!(end_frame = ast_translate(out_translate->trans_pvt, middle_frame, 0))) { 00610 /* Failed to transcode the frame... drop it and return the original */ 00611 ast_frfree(middle_frame); 00612 return start_frame; 00613 } 00614 /* Here's the scoop... middle frame is no longer of use to us */ 00615 ast_frfree(middle_frame); 00616 } 00617 } else { 00618 /* No frame was modified, we can just drop our middle frame and pass the frame we got in out */ 00619 ast_frfree(middle_frame); 00620 } 00621 00622 return end_frame; 00623 }
static struct ast_frame* audiohook_read_frame_both | ( | struct ast_audiohook * | audiohook, | |
size_t | samples | |||
) | [static] |
Definition at line 188 of file audiohook.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_slinear_saturated_divide(), ast_slinear_saturated_multiply(), ast_slinfactory_available(), ast_slinfactory_read(), ast_frame::frametype, LOG_DEBUG, option_debug, ast_audiohook::options, ast_audiohook::read_factory, ast_audiohook::read_time, ast_audiohook_options::read_volume, ast_audiohook::write_factory, ast_audiohook::write_time, and ast_audiohook_options::write_volume.
Referenced by ast_audiohook_read_frame().
00189 { 00190 int i = 0, usable_read, usable_write; 00191 short buf1[samples], buf2[samples], *read_buf = NULL, *write_buf = NULL, *final_buf = NULL, *data1 = NULL, *data2 = NULL; 00192 struct ast_frame frame = { 00193 .frametype = AST_FRAME_VOICE, 00194 .subclass = AST_FORMAT_SLINEAR, 00195 .data = NULL, 00196 .datalen = sizeof(buf1), 00197 .samples = samples, 00198 }; 00199 00200 /* Make sure both factories have the required samples */ 00201 usable_read = (ast_slinfactory_available(&audiohook->read_factory) >= samples ? 1 : 0); 00202 usable_write = (ast_slinfactory_available(&audiohook->write_factory) >= samples ? 1 : 0); 00203 00204 if (!usable_read && !usable_write) { 00205 /* If both factories are unusable bail out */ 00206 if (option_debug) 00207 ast_log(LOG_DEBUG, "Read factory %p and write factory %p both fail to provide %zd samples\n", &audiohook->read_factory, &audiohook->write_factory, samples); 00208 return NULL; 00209 } 00210 00211 /* If we want to provide only a read factory make sure we aren't waiting for other audio */ 00212 if (usable_read && !usable_write && (ast_tvdiff_ms(ast_tvnow(), audiohook->write_time) < (samples/8)*2)) { 00213 if (option_debug > 2) 00214 ast_log(LOG_DEBUG, "Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->write_factory); 00215 return NULL; 00216 } 00217 00218 /* If we want to provide only a write factory make sure we aren't waiting for other audio */ 00219 if (usable_write && !usable_read && (ast_tvdiff_ms(ast_tvnow(), audiohook->read_time) < (samples/8)*2)) { 00220 if (option_debug > 2) 00221 ast_log(LOG_DEBUG, "Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->read_factory); 00222 return NULL; 00223 } 00224 00225 /* Start with the read factory... if there are enough samples, read them in */ 00226 if (usable_read) { 00227 if (ast_slinfactory_read(&audiohook->read_factory, buf1, samples)) { 00228 read_buf = buf1; 00229 /* Adjust read volume if need be */ 00230 if (audiohook->options.read_volume) { 00231 int count = 0; 00232 short adjust_value = abs(audiohook->options.read_volume); 00233 for (count = 0; count < samples; count++) { 00234 if (audiohook->options.read_volume > 0) 00235 ast_slinear_saturated_multiply(&buf1[count], &adjust_value); 00236 else if (audiohook->options.read_volume < 0) 00237 ast_slinear_saturated_divide(&buf1[count], &adjust_value); 00238 } 00239 } 00240 } 00241 } else if (option_debug) 00242 ast_log(LOG_DEBUG, "Failed to get %zd samples from read factory %p\n", samples, &audiohook->read_factory); 00243 00244 /* Move on to the write factory... if there are enough samples, read them in */ 00245 if (usable_write) { 00246 if (ast_slinfactory_read(&audiohook->write_factory, buf2, samples)) { 00247 write_buf = buf2; 00248 /* Adjust write volume if need be */ 00249 if (audiohook->options.write_volume) { 00250 int count = 0; 00251 short adjust_value = abs(audiohook->options.write_volume); 00252 for (count = 0; count < samples; count++) { 00253 if (audiohook->options.write_volume > 0) 00254 ast_slinear_saturated_multiply(&buf2[count], &adjust_value); 00255 else if (audiohook->options.write_volume < 0) 00256 ast_slinear_saturated_divide(&buf2[count], &adjust_value); 00257 } 00258 } 00259 } 00260 } else if (option_debug) 00261 ast_log(LOG_DEBUG, "Failed to get %zd samples from write factory %p\n", samples, &audiohook->write_factory); 00262 00263 /* Basically we figure out which buffer to use... and if mixing can be done here */ 00264 if (!read_buf && !write_buf) 00265 return NULL; 00266 else if (read_buf && write_buf) { 00267 for (i = 0, data1 = read_buf, data2 = write_buf; i < samples; i++, data1++, data2++) 00268 ast_slinear_saturated_add(data1, data2); 00269 final_buf = buf1; 00270 } else if (read_buf) 00271 final_buf = buf1; 00272 else if (write_buf) 00273 final_buf = buf2; 00274 00275 /* Make the final buffer part of the frame, so it gets duplicated fine */ 00276 frame.data = final_buf; 00277 00278 /* Yahoo, a combined copy of the audio! */ 00279 return ast_frdup(&frame); 00280 }
static struct ast_frame* audiohook_read_frame_single | ( | struct ast_audiohook * | audiohook, | |
size_t | samples, | |||
enum ast_audiohook_direction | direction | |||
) | [static] |
Definition at line 160 of file audiohook.c.
References AST_AUDIOHOOK_DIRECTION_READ, AST_FORMAT_SLINEAR, ast_frame_adjust_volume(), AST_FRAME_VOICE, ast_frdup(), ast_slinfactory_available(), ast_slinfactory_read(), ast_frame::frametype, ast_audiohook::options, ast_audiohook::read_factory, ast_audiohook_options::read_volume, ast_audiohook::write_factory, and ast_audiohook_options::write_volume.
Referenced by ast_audiohook_read_frame().
00161 { 00162 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory); 00163 int vol = (direction == AST_AUDIOHOOK_DIRECTION_READ ? audiohook->options.read_volume : audiohook->options.write_volume); 00164 short buf[samples]; 00165 struct ast_frame frame = { 00166 .frametype = AST_FRAME_VOICE, 00167 .subclass = AST_FORMAT_SLINEAR, 00168 .data = buf, 00169 .datalen = sizeof(buf), 00170 .samples = samples, 00171 }; 00172 00173 /* Ensure the factory is able to give us the samples we want */ 00174 if (samples > ast_slinfactory_available(factory)) 00175 return NULL; 00176 00177 /* Read data in from factory */ 00178 if (!ast_slinfactory_read(factory, buf, samples)) 00179 return NULL; 00180 00181 /* If a volume adjustment needs to be applied apply it */ 00182 if (vol) 00183 ast_frame_adjust_volume(&frame, vol); 00184 00185 return ast_frdup(&frame); 00186 }
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 | |||
) | [static] |
Pass a DTMF 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 481 of file audiohook.c.
References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_RUNNING, ast_audiohook_unlock, AST_AUDIOHOOK_WANTS_DTMF, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_test_flag, ast_audiohook::manipulate_callback, and ast_audiohook::status.
Referenced by ast_audiohook_write_list().
00482 { 00483 struct ast_audiohook *audiohook = NULL; 00484 00485 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) { 00486 ast_audiohook_lock(audiohook); 00487 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) { 00488 AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list); 00489 audiohook->status = AST_AUDIOHOOK_STATUS_DONE; 00490 ast_audiohook_unlock(audiohook); 00491 audiohook->manipulate_callback(audiohook, NULL, NULL, 0); 00492 continue; 00493 } 00494 if (ast_test_flag(audiohook, AST_AUDIOHOOK_WANTS_DTMF)) 00495 audiohook->manipulate_callback(audiohook, chan, frame, direction); 00496 ast_audiohook_unlock(audiohook); 00497 } 00498 AST_LIST_TRAVERSE_SAFE_END 00499 00500 return frame; 00501 }
static struct ast_audiohook* find_audiohook_by_source | ( | struct ast_audiohook_list * | audiohook_list, | |
const char * | source | |||
) | [static] |
Definition at line 425 of file audiohook.c.
References AST_LIST_TRAVERSE, and ast_audiohook::source.
Referenced by ast_audiohook_detach_source().
00426 { 00427 struct ast_audiohook *audiohook = NULL; 00428 00429 AST_LIST_TRAVERSE(&audiohook_list->spy_list, audiohook, list) { 00430 if (!strcasecmp(audiohook->source, source)) 00431 return audiohook; 00432 } 00433 00434 AST_LIST_TRAVERSE(&audiohook_list->whisper_list, audiohook, list) { 00435 if (!strcasecmp(audiohook->source, source)) 00436 return audiohook; 00437 } 00438 00439 AST_LIST_TRAVERSE(&audiohook_list->manipulate_list, audiohook, list) { 00440 if (!strcasecmp(audiohook->source, source)) 00441 return audiohook; 00442 } 00443 00444 return NULL; 00445 }