Sat Aug 6 00:39:39 2011

Asterisk developer's documentation


audiohook.h File Reference

Audiohooks Architecture. More...

#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), AST_AUDIOHOOK_SMALL_QUEUE = (1 << 3)
}
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_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_audiohook_write_list_empty (struct ast_audiohook_list *audiohook_list)
 determines if a audiohook_list is empty or not.


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 218 of file audiohook.h.

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

#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 223 of file audiohook.h.

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


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.

The input frame should never be freed or corrupted during a manipulate callback. If the callback has the potential to corrupt the frame's data during manipulation, local data should be used for the manipulation and only copied to the frame on success.

A failure return value indicates that the frame was not manipulated and that is being returned in its original state.

Definition at line 83 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 45 of file audiohook.h.

00045                              {
00046    AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
00047    AST_AUDIOHOOK_DIRECTION_WRITE,    /*!< Writing audio out */
00048    AST_AUDIOHOOK_DIRECTION_BOTH,     /*!< Both reading audio in and writing audio out */
00049 };

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
AST_AUDIOHOOK_SMALL_QUEUE  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.

Definition at line 51 of file audiohook.h.

00051                          {
00052    AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0),  /*!< When audiohook should be triggered to do something */
00053    AST_AUDIOHOOK_TRIGGER_READ = (1 << 0),  /*!< Audiohook wants to be triggered when reading audio in */
00054    AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
00055    AST_AUDIOHOOK_WANTS_DTMF = (1 << 1),    /*!< Audiohook also wants to receive DTMF frames */
00056    AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 2),  /*!< Audiohook wants to be triggered when both sides have combined audio available */
00057    /*! Audiohooks with this flag set will not allow for a large amount of samples to build up on its
00058     * slinfactories. We will flush the factories if they contain too many samples.
00059     */
00060    AST_AUDIOHOOK_SMALL_QUEUE = (1 << 3),
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 38 of file audiohook.h.

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

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 32 of file audiohook.h.

00032                         {
00033    AST_AUDIOHOOK_TYPE_SPY = 0,    /*!< Audiohook wants to receive audio */
00034    AST_AUDIOHOOK_TYPE_WHISPER,    /*!< Audiohook wants to provide audio to be mixed with existing audio */
00035    AST_AUDIOHOOK_TYPE_MANIPULATE, /*!< Audiohook wants to manipulate the audio */
00036 };


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 341 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_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(), start_spying(), and startmon().

00342 {
00343    ast_channel_lock(chan);
00344 
00345    if (!chan->audiohooks) {
00346       /* Whoops... allocate a new structure */
00347       if (!(chan->audiohooks = ast_calloc(1, sizeof(*chan->audiohooks)))) {
00348          ast_channel_unlock(chan);
00349          return -1;
00350       }
00351       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->spy_list);
00352       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->whisper_list);
00353       AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->manipulate_list);
00354    }
00355 
00356    /* Drop into respective list */
00357    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
00358       AST_LIST_INSERT_TAIL(&chan->audiohooks->spy_list, audiohook, list);
00359    else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
00360       AST_LIST_INSERT_TAIL(&chan->audiohooks->whisper_list, audiohook, list);
00361    else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
00362       AST_LIST_INSERT_TAIL(&chan->audiohooks->manipulate_list, audiohook, list);
00363 
00364    /* Change status over to running since it is now attached */
00365    audiohook->status = AST_AUDIOHOOK_STATUS_RUNNING;
00366 
00367    ast_channel_unlock(chan);
00368 
00369    return 0;
00370 }

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 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(), destroy_monitor_audiohook(), and launch_monitor_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.

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

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

00377 {
00378    if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
00379       return 0;
00380 
00381    audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
00382 
00383    while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
00384       ast_audiohook_trigger_wait(audiohook);
00385 
00386    return 0;
00387 }

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 393 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::manipulate_list, ast_audiohook_list::out_translate, ast_audiohook_list::spy_list, ast_audiohook::status, ast_audiohook_translate::trans_pvt, ast_audiohook::trigger, and ast_audiohook_list::whisper_list.

Referenced by __ast_read(), ast_hangup(), and ast_write().

00394 {
00395    int i = 0;
00396    struct ast_audiohook *audiohook = NULL;
00397 
00398    /* Drop any spies */
00399    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
00400       ast_audiohook_lock(audiohook);
00401       AST_LIST_REMOVE_CURRENT(&audiohook_list->spy_list, list);
00402       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00403       ast_cond_signal(&audiohook->trigger);
00404       ast_audiohook_unlock(audiohook);
00405    }
00406    AST_LIST_TRAVERSE_SAFE_END
00407 
00408    /* Drop any whispering sources */
00409    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
00410       ast_audiohook_lock(audiohook);
00411       AST_LIST_REMOVE_CURRENT(&audiohook_list->whisper_list, list);
00412       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00413       ast_cond_signal(&audiohook->trigger);
00414       ast_audiohook_unlock(audiohook);
00415    }
00416    AST_LIST_TRAVERSE_SAFE_END
00417 
00418    /* Drop any manipulaters */
00419    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
00420       ast_audiohook_lock(audiohook);
00421       AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
00422       audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00423       ast_audiohook_unlock(audiohook);
00424       audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
00425    }
00426    AST_LIST_TRAVERSE_SAFE_END
00427 
00428    /* Drop translation paths if present */
00429    for (i = 0; i < 2; i++) {
00430       if (audiohook_list->in_translate[i].trans_pvt)
00431          ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
00432       if (audiohook_list->out_translate[i].trans_pvt)
00433          ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt);
00434    }
00435    
00436    /* Free ourselves */
00437    ast_free(audiohook_list);
00438 
00439    return 0;
00440 }

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 488 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().

00489 {
00490    struct ast_audiohook *audiohook = NULL;
00491 
00492    ast_channel_lock(chan);
00493 
00494    /* Ensure the channel has audiohooks on it */
00495    if (!chan->audiohooks) {
00496       ast_channel_unlock(chan);
00497       return -1;
00498    }
00499 
00500    audiohook = find_audiohook_by_source(chan->audiohooks, source);
00501 
00502    ast_channel_unlock(chan);
00503 
00504    if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
00505       audiohook->status = AST_AUDIOHOOK_STATUS_SHUTDOWN;
00506 
00507    return (audiohook ? 0 : -1);
00508 }

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 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 }

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 464 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().

00465 {
00466    struct ast_audiohook *audiohook;
00467 
00468    if (!old_chan->audiohooks || !(audiohook = find_audiohook_by_source(old_chan->audiohooks, source))) {
00469       return;
00470    }
00471 
00472    /* By locking both channels and the audiohook, we can assure that
00473     * another thread will not have a chance to read the audiohook's status
00474     * as done, even though ast_audiohook_remove signals the trigger
00475     * condition
00476     */
00477    ast_audiohook_lock(audiohook);
00478    ast_audiohook_remove(old_chan, audiohook);
00479    ast_audiohook_attach(new_chan, audiohook);
00480    ast_audiohook_unlock(audiohook);
00481 }

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 306 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(), audiohook_read_frame_single(), and read_frame().

Referenced by mixmonitor_thread(), and spy_generate().

00307 {
00308    struct ast_frame *read_frame = NULL, *final_frame = NULL;
00309 
00310    if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction))))
00311       return NULL;
00312 
00313    /* If they don't want signed linear back out, we'll have to send it through the translation path */
00314    if (format != AST_FORMAT_SLINEAR) {
00315       /* Rebuild translation path if different format then previously */
00316       if (audiohook->format != format) {
00317          if (audiohook->trans_pvt) {
00318             ast_translator_free_path(audiohook->trans_pvt);
00319             audiohook->trans_pvt = NULL;
00320          }
00321          /* 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 */
00322          if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) {
00323             ast_frfree(read_frame);
00324             return NULL;
00325          }
00326       }
00327       /* Convert to requested format, and allow the read in frame to be freed */
00328       final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1);
00329    } else {
00330       final_frame = read_frame;
00331    }
00332 
00333    return final_frame;
00334 }

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 520 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, 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().

00521 {
00522    ast_channel_lock(chan);
00523 
00524    if (!chan->audiohooks) {
00525       ast_channel_unlock(chan);
00526       return -1;
00527    }
00528 
00529    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
00530       AST_LIST_REMOVE(&chan->audiohooks->spy_list, audiohook, list);
00531    else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
00532       AST_LIST_REMOVE(&chan->audiohooks->whisper_list, audiohook, list);
00533    else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
00534       AST_LIST_REMOVE(&chan->audiohooks->manipulate_list, audiohook, list);
00535 
00536    ast_audiohook_lock(audiohook);
00537    audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
00538    ast_cond_signal(&audiohook->trigger);
00539    ast_audiohook_unlock(audiohook);
00540 
00541    ast_channel_unlock(chan);
00542 
00543    return 0;
00544 }

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 760 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().

00761 {
00762    struct timeval tv;
00763    struct timespec ts;
00764 
00765    tv = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
00766    ts.tv_sec = tv.tv_sec;
00767    ts.tv_nsec = tv.tv_usec * 1000;
00768    
00769    ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
00770    
00771    return;
00772 }

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 128 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_SMALL_QUEUE, 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().

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    int our_factory_samples;
00134    int our_factory_ms;
00135    int other_factory_samples;
00136    int other_factory_ms;
00137 
00138    /* Update last feeding time to be current */
00139    *time = ast_tvnow();
00140 
00141    our_factory_samples = ast_slinfactory_available(factory);
00142    our_factory_ms = ast_tvdiff_ms(*time, previous_time) + (our_factory_samples / 8);
00143    other_factory_samples = ast_slinfactory_available(other_factory);
00144    other_factory_ms = other_factory_samples / 8;
00145 
00146    /* 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 */
00147    if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
00148       if (option_debug)
00149          ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook);
00150       ast_slinfactory_flush(factory);
00151       ast_slinfactory_flush(other_factory);
00152    }
00153 
00154    if (ast_test_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE) && (our_factory_samples > 640 || other_factory_samples > 640)) {
00155       if (option_debug) {
00156          ast_log(LOG_DEBUG, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
00157       }
00158       ast_slinfactory_flush(factory);
00159       ast_slinfactory_flush(other_factory);
00160    }
00161 
00162    /* Write frame out to respective factory */
00163    ast_slinfactory_feed(factory, frame);
00164 
00165    /* If we need to notify the respective handler of this audiohook, do so */
00166    if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
00167       ast_cond_signal(&audiohook->trigger);
00168    } else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) {
00169       ast_cond_signal(&audiohook->trigger);
00170    } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
00171       ast_cond_signal(&audiohook->trigger);
00172    }
00173 
00174    return 0;
00175 }

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 746 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().

00747 {
00748    /* Pass off frame to it's respective list write function */
00749    if (frame->frametype == AST_FRAME_VOICE)
00750       return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
00751    else if (frame->frametype == AST_FRAME_DTMF)
00752       return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
00753    else
00754       return frame;
00755 }

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 728 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().

00729 {
00730    if (AST_LIST_EMPTY(&audiohook_list->spy_list) &&
00731       AST_LIST_EMPTY(&audiohook_list->whisper_list) &&
00732       AST_LIST_EMPTY(&audiohook_list->manipulate_list)) {
00733 
00734       return 1;
00735    }
00736    return 0;
00737 }


Generated on Sat Aug 6 00:39:39 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7