Fri Jul 24 00:41:18 2009

Asterisk developer's documentation


audiohook.h File Reference

Audiohooks Architecture. More...

#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/slinfactory.h"

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_SYNC_TOLERANCE   100
#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 << 1),
  AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 2)
}
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)
 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.
ast_frameast_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.
int ast_audiohook_remove (struct ast_channel *chan, struct ast_audiohook *audiohook)
 Remove an audiohook from a specified channel.
void ast_audiohook_trigger_wait (struct ast_audiohook *audiohook)
 Wait for audiohook trigger to be triggered.
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.
ast_frameast_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_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.


Detailed Description

Audiohooks Architecture.

Definition in file audiohook.h.


Define Documentation

#define ast_audiohook_lock ( ah   )     ast_mutex_lock(&(ah)->lock)

Lock an audiohook.

Parameters:
ah Audiohook structure

Definition at line 231 of file audiohook.h.

Referenced by ast_audiohook_detach_list(), ast_audiohook_move_by_source(), ast_audiohook_remove(), audio_audiohook_write_list(), channel_spy(), dtmf_audiohook_write_list(), mixmonitor_thread(), and spy_generate().

#define AST_AUDIOHOOK_SYNC_TOLERANCE   100

Definition at line 63 of file audiohook.h.

Referenced by ast_audiohook_write_frame().

#define ast_audiohook_unlock ( ah   )     ast_mutex_unlock(&(ah)->lock)

Unlock an audiohook.

Parameters:
ah Audiohook structure

Definition at line 236 of file audiohook.h.

Referenced by ast_audiohook_detach_list(), ast_audiohook_move_by_source(), ast_audiohook_remove(), audio_audiohook_write_list(), channel_spy(), dtmf_audiohook_write_list(), mixmonitor_thread(), and spy_generate().


Typedef Documentation

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.

Parameters:
audiohook Audiohook structure
chan Channel
frame Frame of audio to manipulate
direction Direction frame came from
Returns:
Returns 0 on success, -1 on failure
Note:
An audiohook does not have any reference to a private data structure for manipulate types. It is up to the manipulate callback to store this data via it's own method. An example would be datastores.

Definition at line 76 of file audiohook.h.


Enumeration Type Documentation

enum ast_audiohook_direction

Enumerator:
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 49 of file audiohook.h.

00049                              {
00050    AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
00051    AST_AUDIOHOOK_DIRECTION_WRITE,    /*!< Writing audio out */
00052    AST_AUDIOHOOK_DIRECTION_BOTH,     /*!< Both reading audio in and writing audio out */
00053 };

enum ast_audiohook_flags

Enumerator:
AST_AUDIOHOOK_TRIGGER_MODE  When audiohook should be triggered to do something
AST_AUDIOHOOK_TRIGGER_READ  Audiohook wants to be triggered when reading audio in
AST_AUDIOHOOK_TRIGGER_WRITE  Audiohook wants to be triggered when writing audio out
AST_AUDIOHOOK_WANTS_DTMF  Audiohook also wants to receive DTMF frames
AST_AUDIOHOOK_TRIGGER_SYNC  Audiohook wants to be triggered when both sides have combined audio available

Definition at line 55 of file audiohook.h.

00055                          {
00056    AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0),  /*!< When audiohook should be triggered to do something */
00057    AST_AUDIOHOOK_TRIGGER_READ = (1 << 0),  /*!< Audiohook wants to be triggered when reading audio in */
00058    AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
00059    AST_AUDIOHOOK_WANTS_DTMF = (1 << 1),    /*!< Audiohook also wants to receive DTMF frames */
00060    AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 2),  /*!< Audiohook wants to be triggered when both sides have combined audio available */
00061 };

enum ast_audiohook_status

Enumerator:
AST_AUDIOHOOK_STATUS_NEW  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

Definition at line 42 of file audiohook.h.

00042                           {
00043    AST_AUDIOHOOK_STATUS_NEW = 0,  /*!< Audiohook was just created, not in use yet */
00044    AST_AUDIOHOOK_STATUS_RUNNING,  /*!< Audiohook is running on a channel */
00045    AST_AUDIOHOOK_STATUS_SHUTDOWN, /*!< Audiohook is being shutdown */
00046    AST_AUDIOHOOK_STATUS_DONE,     /*!< Audiohook has shutdown and is not running on a channel any longer */
00047 };

enum ast_audiohook_type

Enumerator:
AST_AUDIOHOOK_TYPE_SPY  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

Definition at line 36 of file audiohook.h.

00036                         {
00037    AST_AUDIOHOOK_TYPE_SPY = 0,    /*!< Audiohook wants to receive audio */
00038    AST_AUDIOHOOK_TYPE_WHISPER,    /*!< Audiohook wants to provide audio to be mixed with existing audio */
00039    AST_AUDIOHOOK_TYPE_MANIPULATE, /*!< Audiohook wants to manipulate the audio */
00040 };


Function Documentation

int ast_audiohook_attach ( struct ast_channel chan,
struct ast_audiohook audiohook 
)

Attach audiohook to channel.

Parameters:
chan Channel
audiohook Audiohook structure
Returns:
Returns 0 on success, -1 on failure

Definition at line 320 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, chan, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::status, ast_audiohook::type, and ast_audiohook_list::whisper_list.

Referenced by ast_audiohook_move_by_source(), audiohook_volume_get(), enable_jack_hook(), speex_write(), start_spying(), startmon(), and volume_write().

00321 {
00322    ast_channel_lock(chan);
00323 
00324    if (!chan->audiohooks) {
00325       /* Whoops... allocate a new structure */
00326       if (!(chan->audiohooks = ast_calloc(1, sizeof(*chan->audiohooks)))) {
00327          ast_channel_unlock(chan);
00328          return -1;
00329       }
00330       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->spy_list);
00331       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->whisper_list);
00332       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->manipulate_list);
00333    }
00334 
00335    /* Drop into respective list */
00336    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
00337       AST_LIST_INSERT_TAIL(&chan->audiohooks->spy_list, audiohook, list);
00338    else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
00339       AST_LIST_INSERT_TAIL(&chan->audiohooks->whisper_list, audiohook, list);
00340    else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
00341       AST_LIST_INSERT_TAIL(&chan->audiohooks->manipulate_list, audiohook, list);
00342 
00343    /* Change status over to running since it is now attached */
00344    audiohook->status = AST_AUDIOHOOK_STATUS_RUNNING;
00345 
00346    ast_channel_unlock(chan);
00347 
00348    return 0;
00349 }

int ast_audiohook_destroy ( struct ast_audiohook audiohook  ) 

Destroys an audiohook structure.

Parameters:
audiohook Audiohook structure
Returns:
Returns 0 on success, -1 on failure

Definition at line 91 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(), launch_monitor_thread(), and mixmonitor_thread().

00092 {
00093    /* Drop the factories used by this audiohook type */
00094    switch (audiohook->type) {
00095    case AST_AUDIOHOOK_TYPE_SPY:
00096       ast_slinfactory_destroy(&audiohook->read_factory);
00097    case AST_AUDIOHOOK_TYPE_WHISPER:
00098       ast_slinfactory_destroy(&audiohook->write_factory);
00099       break;
00100    default:
00101       break;
00102    }
00103 
00104    /* Destroy translation path if present */
00105    if (audiohook->trans_pvt)
00106       ast_translator_free_path(audiohook->trans_pvt);
00107 
00108    /* Lock and trigger be gone! */
00109    ast_cond_destroy(&audiohook->trigger);
00110    ast_mutex_destroy(&audiohook->lock);
00111 
00112    return 0;
00113 }

int ast_audiohook_detach ( struct ast_audiohook audiohook  ) 

Detach audiohook from channel.

Parameters:
audiohook Audiohook structure
Returns:
Returns 0 on success, -1 on failure

Definition at line 355 of file audiohook.c.

References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_NEW, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_audiohook_trigger_wait(), and ast_audiohook::status.

Referenced by channel_spy(), disable_jack_hook(), mixmonitor_thread(), and speex_write().

00356 {
00357    if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
00358       return 0;
00359 
00360    audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
00361 
00362    while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
00363       ast_audiohook_trigger_wait(audiohook);
00364 
00365    return 0;
00366 }

int ast_audiohook_detach_list ( struct ast_audiohook_list audiohook_list  ) 

Detach audiohooks from list and destroy said list.

Parameters:
audiohook_list List of audiohooks
Returns:
Returns 0 on success, -1 on failure

Definition at line 372 of file audiohook.c.

References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_unlock, ast_cond_signal(), ast_free, AST_LIST_REMOVE_HEAD, ast_translator_free_path(), ast_audiohook_list::in_translate, ast_audiohook::list, 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_hangup().

00373 {
00374    int i = 0;
00375    struct ast_audiohook *audiohook = NULL;
00376 
00377    /* Drop any spies */
00378    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
00379       ast_audiohook_lock(audiohook);
00380       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00381       ast_cond_signal(&audiohook->trigger);
00382       ast_audiohook_unlock(audiohook);
00383    }
00384 
00385    /* Drop any whispering sources */
00386    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
00387       ast_audiohook_lock(audiohook);
00388       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00389       ast_cond_signal(&audiohook->trigger);
00390       ast_audiohook_unlock(audiohook);
00391    }
00392 
00393    /* Drop any manipulaters */
00394    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
00395       ast_audiohook_lock(audiohook);
00396       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00397       ast_audiohook_unlock(audiohook);
00398       audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
00399    }
00400 
00401    /* Drop translation paths if present */
00402    for (i = 0; i < 2; i++) {
00403       if (audiohook_list->in_translate[i].trans_pvt)
00404          ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
00405       if (audiohook_list->out_translate[i].trans_pvt)
00406          ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt);
00407    }
00408    
00409    /* Free ourselves */
00410    ast_free(audiohook_list);
00411 
00412    return 0;
00413 }

int ast_audiohook_detach_source ( struct ast_channel chan,
const char *  source 
)

Detach specified source audiohook from channel.

Parameters:
chan Channel to detach from
source Name of source to detach
Returns:
Returns 0 on success, -1 on failure

Definition at line 466 of file audiohook.c.

References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_channel_lock, ast_channel_unlock, ast_channel::audiohooks, chan, find_audiohook_by_source(), and ast_audiohook::status.

Referenced by handle_cli_mixmonitor(), and stop_mixmonitor_exec().

00467 {
00468    struct ast_audiohook *audiohook = NULL;
00469 
00470    ast_channel_lock(chan);
00471 
00472    /* Ensure the channel has audiohooks on it */
00473    if (!chan->audiohooks) {
00474       ast_channel_unlock(chan);
00475       return -1;
00476    }
00477 
00478    audiohook = find_audiohook_by_source(chan->audiohooks, source);
00479 
00480    ast_channel_unlock(chan);
00481 
00482    if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
00483       audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
00484 
00485    return (audiohook ? 0 : -1);
00486 }

int ast_audiohook_init ( struct ast_audiohook audiohook,
enum ast_audiohook_type  type,
const char *  source 
)

Initialize an audiohook structure.

Parameters:
audiohook Audiohook structure
type 
source 
Returns:
Returns 0 on success, -1 on failure

Definition at line 60 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 audiohook_volume_get(), channel_spy(), enable_jack_hook(), launch_monitor_thread(), speex_write(), and volume_write().

00061 {
00062    /* Need to keep the type and source */
00063    audiohook->type = type;
00064    audiohook->source = source;
00065 
00066    /* Initialize lock that protects our audiohook */
00067    ast_mutex_init(&audiohook->lock);
00068    ast_cond_init(&audiohook->trigger, NULL);
00069 
00070    /* Setup the factories that are needed for this audiohook type */
00071    switch (type) {
00072    case AST_AUDIOHOOK_TYPE_SPY:
00073       ast_slinfactory_init(&audiohook->read_factory);
00074    case AST_AUDIOHOOK_TYPE_WHISPER:
00075       ast_slinfactory_init(&audiohook->write_factory);
00076       break;
00077    default:
00078       break;
00079    }
00080 
00081    /* Since we are just starting out... this audiohook is new */
00082    audiohook->status = AST_AUDIOHOOK_STATUS_NEW;
00083 
00084    return 0;
00085 }

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.

Todo:
Currently only the first audiohook of a specific source found will be moved. We should add the capability to move multiple audiohooks from a single source as well.
Note:
It is required that both old_chan and new_chan are locked prior to calling this function. Besides needing to protect the data within the channels, not locking these channels can lead to a potential deadlock
Parameters:
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 442 of file audiohook.c.

References ast_audiohook_attach(), ast_audiohook_lock, ast_audiohook_remove(), ast_audiohook_unlock, ast_channel::audiohooks, and find_audiohook_by_source().

Referenced by audiohook_inheritance_fixup().

00443 {
00444    struct ast_audiohook *audiohook;
00445 
00446    if (!old_chan->audiohooks || !(audiohook = find_audiohook_by_source(old_chan->audiohooks, source))) {
00447       return;
00448    }
00449 
00450    /* By locking both channels and the audiohook, we can assure that
00451     * another thread will not have a chance to read the audiohook's status
00452     * as done, even though ast_audiohook_remove signals the trigger
00453     * condition
00454     */
00455    ast_audiohook_lock(audiohook);
00456    ast_audiohook_remove(old_chan, audiohook);
00457    ast_audiohook_attach(new_chan, audiohook);
00458    ast_audiohook_unlock(audiohook);
00459 }

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.

Parameters:
audiohook Audiohook structure
samples Number of samples wanted
direction Direction the audio frame came from
format Format of frame remote side wants back
Returns:
Returns frame on success, NULL on failure

Definition at line 285 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().

00286 {
00287    struct ast_frame *read_frame = NULL, *final_frame = NULL;
00288 
00289    if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction))))
00290       return NULL;
00291 
00292    /* If they don't want signed linear back out, we'll have to send it through the translation path */
00293    if (format != AST_FORMAT_SLINEAR) {
00294       /* Rebuild translation path if different format then previously */
00295       if (audiohook->format != format) {
00296          if (audiohook->trans_pvt) {
00297             ast_translator_free_path(audiohook->trans_pvt);
00298             audiohook->trans_pvt = NULL;
00299          }
00300          /* 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 */
00301          if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) {
00302             ast_frfree(read_frame);
00303             return NULL;
00304          }
00305       }
00306       /* Convert to requested format, and allow the read in frame to be freed */
00307       final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1);
00308    } else {
00309       final_frame = read_frame;
00310    }
00311 
00312    return final_frame;
00313 }

int ast_audiohook_remove ( struct ast_channel chan,
struct ast_audiohook audiohook 
)

Remove an audiohook from a specified channel.

Parameters:
chan Channel to remove from
audiohook Audiohook to remove
Returns:
Returns 0 on success, -1 on failure
Note:
The channel does not need to be locked before calling this function

Definition at line 498 of file audiohook.c.

References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_audiohook_unlock, ast_channel_lock, ast_channel_unlock, ast_cond_signal(), AST_LIST_REMOVE, ast_channel::audiohooks, chan, ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::status, ast_audiohook::trigger, ast_audiohook::type, and ast_audiohook_list::whisper_list.

Referenced by ast_audiohook_move_by_source(), and speex_write().

00499 {
00500    ast_channel_lock(chan);
00501 
00502    if (!chan->audiohooks) {
00503       ast_channel_unlock(chan);
00504       return -1;
00505    }
00506 
00507    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
00508       AST_LIST_REMOVE(&chan->audiohooks->spy_list, audiohook, list);
00509    else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
00510       AST_LIST_REMOVE(&chan->audiohooks->whisper_list, audiohook, list);
00511    else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
00512       AST_LIST_REMOVE(&chan->audiohooks->manipulate_list, audiohook, list);
00513 
00514    ast_audiohook_lock(audiohook);
00515    audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00516    ast_cond_signal(&audiohook->trigger);
00517    ast_audiohook_unlock(audiohook);
00518 
00519    ast_channel_unlock(chan);
00520 
00521    return 0;
00522 }

void ast_audiohook_trigger_wait ( struct ast_audiohook audiohook  ) 

Wait for audiohook trigger to be triggered.

Parameters:
audiohook Audiohook to wait on

Definition at line 698 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().

00699 {
00700    struct timeval wait;
00701    struct timespec ts;
00702 
00703    wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
00704    ts.tv_sec = wait.tv_sec;
00705    ts.tv_nsec = wait.tv_usec * 1000;
00706    
00707    ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
00708    
00709    return;
00710 }

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.

Parameters:
chan Channel to muck with
direction Direction to increase
volume Value to adjust the adjustment by
Returns:
Returns 0 on success, -1 on failure

Definition at line 958 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_BOTH, AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), chan, audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.

00959 {
00960    struct audiohook_volume *audiohook_volume = NULL;
00961 
00962    /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
00963    if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
00964       return -1;
00965    }
00966 
00967    /* Based on the direction change the specific adjustment value */
00968    if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
00969       audiohook_volume->read_adjustment += volume;
00970    }
00971    if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
00972       audiohook_volume->write_adjustment += volume;
00973    }
00974 
00975    return 0;
00976 }

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.

Parameters:
chan Channel to retrieve volume adjustment from
direction Direction to retrieve
Returns:
Returns adjustment value

Definition at line 932 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), chan, audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.

00933 {
00934    struct audiohook_volume *audiohook_volume = NULL;
00935    int adjustment = 0;
00936 
00937    /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
00938    if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
00939       return 0;
00940    }
00941 
00942    /* Grab the adjustment value based on direction given */
00943    if (direction == AST_AUDIOHOOK_DIRECTION_READ) {
00944       adjustment = audiohook_volume->read_adjustment;
00945    } else if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
00946       adjustment = audiohook_volume->write_adjustment;
00947    }
00948 
00949    return adjustment;
00950 }

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.

Parameters:
chan Channel to muck with
direction Direction to set on
volume Value to adjust the volume by
Returns:
Returns 0 on success, -1 on failure

Definition at line 907 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_BOTH, AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, audiohook_volume_get(), chan, audiohook_volume::read_adjustment, and audiohook_volume::write_adjustment.

00908 {
00909    struct audiohook_volume *audiohook_volume = NULL;
00910 
00911    /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
00912    if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
00913       return -1;
00914    }
00915 
00916    /* Now based on the direction set the proper value */
00917    if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
00918       audiohook_volume->read_adjustment = volume;
00919    }
00920    if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
00921       audiohook_volume->write_adjustment = volume;
00922    }
00923 
00924    return 0;
00925 }

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.

Parameters:
audiohook Audiohook structure
direction Direction the audio frame came from
frame Frame to write in
Returns:
Returns 0 on success, -1 on failure

Definition at line 121 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_SYNC_TOLERANCE, 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, ast_tvdiff_ms(), ast_tvnow(), 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().

00122 {
00123    struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
00124    struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
00125    struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
00126    int our_factory_ms;
00127    int other_factory_samples;
00128    int other_factory_ms;
00129 
00130    /* Update last feeding time to be current */
00131    *rwtime = ast_tvnow();
00132 
00133    our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (ast_slinfactory_available(factory) / 8);
00134    other_factory_samples = ast_slinfactory_available(other_factory);
00135    other_factory_ms = other_factory_samples / 8;
00136 
00137    if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
00138       if (option_debug)
00139          ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook);
00140       ast_slinfactory_flush(factory);
00141       ast_slinfactory_flush(other_factory);
00142    }
00143 
00144    /* Write frame out to respective factory */
00145    ast_slinfactory_feed(factory, frame);
00146 
00147    /* If we need to notify the respective handler of this audiohook, do so */
00148    if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
00149       ast_cond_signal(&audiohook->trigger);
00150    } else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) {
00151       ast_cond_signal(&audiohook->trigger);
00152    } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
00153       ast_cond_signal(&audiohook->trigger);
00154    }
00155 
00156    return 0;
00157 }

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.

Parameters:
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
Returns:
Return frame on success, NULL on failure

Definition at line 683 of file audiohook.c.

References AST_FRAME_DTMF, AST_FRAME_VOICE, audio_audiohook_write_list(), chan, dtmf_audiohook_write_list(), and ast_frame::frametype.

Referenced by __ast_read(), and ast_write().

00684 {
00685    /* Pass off frame to it's respective list write function */
00686    if (frame->frametype == AST_FRAME_VOICE)
00687       return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
00688    else if (frame->frametype == AST_FRAME_DTMF)
00689       return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
00690    else
00691       return frame;
00692 }

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.

Parameters:
chan The channel on which to find the spies
source The audiohook's source
type The type of audiohook
Returns:
Return the number of audiohooks which are from the source specified
Note: Function performs nlocking.

Definition at line 713 of file audiohook.c.

References AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_channel::audiohooks, chan, 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().

00714 {
00715    int count = 0;
00716    struct ast_audiohook *ah = NULL;
00717 
00718    if (!chan->audiohooks)
00719       return -1;
00720 
00721    switch (type) {
00722       case AST_AUDIOHOOK_TYPE_SPY:
00723          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->spy_list, ah, list) {
00724             if (!strcmp(ah->source, source)) {
00725                count++;
00726             }
00727          }
00728          AST_LIST_TRAVERSE_SAFE_END;
00729          break;
00730       case AST_AUDIOHOOK_TYPE_WHISPER:
00731          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->whisper_list, ah, list) {
00732             if (!strcmp(ah->source, source)) {
00733                count++;
00734             }
00735          }
00736          AST_LIST_TRAVERSE_SAFE_END;
00737          break;
00738       case AST_AUDIOHOOK_TYPE_MANIPULATE:
00739          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->manipulate_list, ah, list) {
00740             if (!strcmp(ah->source, source)) {
00741                count++;
00742             }
00743          }
00744          AST_LIST_TRAVERSE_SAFE_END;
00745          break;
00746       default:
00747          ast_log(LOG_DEBUG, "Invalid audiohook type supplied, (%d)\n", type);
00748          return -1;
00749    }
00750 
00751    return count;
00752 }

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.

Parameters:
chan The channel on which to find the spies
source The source of the audiohook
type The type of spy to look for
Returns:
Return the number of running audiohooks which are from the source specified
Note: Function performs no locking.

Definition at line 755 of file audiohook.c.

References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_channel::audiohooks, chan, 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().

00756 {
00757    int count = 0;
00758    struct ast_audiohook *ah = NULL;
00759    if (!chan->audiohooks)
00760       return -1;
00761 
00762    switch (type) {
00763       case AST_AUDIOHOOK_TYPE_SPY:
00764          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->spy_list, ah, list) {
00765             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
00766                count++;
00767          }
00768          AST_LIST_TRAVERSE_SAFE_END;
00769          break;
00770       case AST_AUDIOHOOK_TYPE_WHISPER:
00771          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->whisper_list, ah, list) {
00772             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
00773                count++;
00774          }
00775          AST_LIST_TRAVERSE_SAFE_END;
00776          break;
00777       case AST_AUDIOHOOK_TYPE_MANIPULATE:
00778          AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->manipulate_list, ah, list) {
00779             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
00780                count++;
00781          }
00782          AST_LIST_TRAVERSE_SAFE_END;
00783          break;
00784       default:
00785          ast_log(LOG_DEBUG, "Invalid audiohook type supplied, (%d)\n", type);
00786          return -1;
00787    }
00788    return count;
00789 }


Generated on Fri Jul 24 00:41:18 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7