audiohook.h File Reference

Audiohooks Architecture. More...

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

Include dependency graph for audiohook.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_audiohook
struct  ast_audiohook_options

Defines

#define ast_audiohook_lock(ah)   ast_mutex_lock(&(ah)->lock)
 Lock an audiohook.
#define ast_audiohook_unlock(ah)   ast_mutex_unlock(&(ah)->lock)
 Unlock an audiohook.

Typedefs

typedef int(* ast_audiohook_manipulate_callback )(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
 Callback function for manipulate audiohook type.

Enumerations

enum  ast_audiohook_direction { AST_AUDIOHOOK_DIRECTION_READ = 0, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_DIRECTION_BOTH }
enum  ast_audiohook_flags {
  AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0), AST_AUDIOHOOK_TRIGGER_READ = (1 << 0), AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), AST_AUDIOHOOK_WANTS_DTMF = (1 << 2),
  AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 3), AST_AUDIOHOOK_SMALL_QUEUE = (1 << 4), AST_AUDIOHOOK_MUTE_READ = (1 << 5), AST_AUDIOHOOK_MUTE_WRITE = (1 << 6)
}
enum  ast_audiohook_init_flags { AST_AUDIOHOOK_MANIPULATE_ALL_RATES = (1 << 0) }
enum  ast_audiohook_status { AST_AUDIOHOOK_STATUS_NEW = 0, AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_STATUS_SHUTDOWN, AST_AUDIOHOOK_STATUS_DONE }
enum  ast_audiohook_type { AST_AUDIOHOOK_TYPE_SPY = 0, AST_AUDIOHOOK_TYPE_WHISPER, AST_AUDIOHOOK_TYPE_MANIPULATE }

Functions

int ast_audiohook_attach (struct ast_channel *chan, struct ast_audiohook *audiohook)
 Attach audiohook to channel.
int ast_audiohook_destroy (struct ast_audiohook *audiohook)
 Destroys an audiohook structure.
int ast_audiohook_detach (struct ast_audiohook *audiohook)
 Detach audiohook from channel.
void ast_audiohook_detach_list (struct ast_audiohook_list *audiohook_list)
 Detach audiohooks from list and destroy said list.
int ast_audiohook_detach_source (struct ast_channel *chan, const char *source)
 Detach specified source audiohook from channel.
int ast_audiohook_init (struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
 Initialize an audiohook structure.
void ast_audiohook_move_all (struct ast_channel *old_chan, struct ast_channel *new_chan)
 Move all audiohooks from one channel to another.
void ast_audiohook_move_by_source (struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source)
 Move an audiohook from one channel to a new one.
struct ast_frameast_audiohook_read_frame (struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format)
 Reads a frame in from the audiohook structure.
struct ast_frameast_audiohook_read_frame_all (struct ast_audiohook *audiohook, size_t samples, struct ast_format *format, struct ast_frame **read_frame, struct ast_frame **write_frame)
 Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame data to provided arguments.
int ast_audiohook_remove (struct ast_channel *chan, struct ast_audiohook *audiohook)
 Remove an audiohook from a specified channel.
int ast_audiohook_set_mute (struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clear)
 Mute frames read from or written to a channel.
void ast_audiohook_trigger_wait (struct ast_audiohook *audiohook)
 Wait for audiohook trigger to be triggered.
void ast_audiohook_update_status (struct ast_audiohook *audiohook, enum ast_audiohook_status status)
 Update audiohook's status.
int ast_audiohook_volume_adjust (struct ast_channel *chan, enum ast_audiohook_direction direction, int volume)
 Adjust the volume on frames read from or written to a channel.
int ast_audiohook_volume_get (struct ast_channel *chan, enum ast_audiohook_direction direction)
 Retrieve the volume adjustment value on frames read from or written to a channel.
int ast_audiohook_volume_set (struct ast_channel *chan, enum ast_audiohook_direction direction, int volume)
 Adjust the volume on frames read from or written to a channel.
int ast_audiohook_write_frame (struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame)
 Writes a frame into the audiohook structure.
struct ast_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)
 Determine if a audiohook_list is empty or not.
int ast_channel_audiohook_count_by_source (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many audiohooks from a certain source exist on a given channel, regardless of status.
int ast_channel_audiohook_count_by_source_running (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many spies of a certain type exist on a given channel, and are in state running.


Detailed Description

Audiohooks Architecture.

Definition in file audiohook.h.


Define Documentation

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

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


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


Enumeration Type Documentation

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

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

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.
AST_AUDIOHOOK_MUTE_READ  audiohook should be mute frames read
AST_AUDIOHOOK_MUTE_WRITE  audiohook should be mute frames written

Definition at line 54 of file audiohook.h.

00054                          {
00055    AST_AUDIOHOOK_TRIGGER_MODE  = (3 << 0), /*!< When audiohook should be triggered to do something */
00056    AST_AUDIOHOOK_TRIGGER_READ  = (1 << 0), /*!< Audiohook wants to be triggered when reading audio in */
00057    AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
00058    AST_AUDIOHOOK_WANTS_DTMF    = (1 << 2), /*!< Audiohook also wants to receive DTMF frames */
00059    AST_AUDIOHOOK_TRIGGER_SYNC  = (1 << 3), /*!< Audiohook wants to be triggered when both sides have combined audio available */
00060    /*! Audiohooks with this flag set will not allow for a large amount of samples to build up on its
00061     * slinfactories. We will flush the factories if they contain too many samples.
00062     */
00063    AST_AUDIOHOOK_SMALL_QUEUE   = (1 << 4),
00064    AST_AUDIOHOOK_MUTE_READ     = (1 << 5), /*!< audiohook should be mute frames read */
00065    AST_AUDIOHOOK_MUTE_WRITE    = (1 << 6), /*!< audiohook should be mute frames written */
00066 };

Enumerator:
AST_AUDIOHOOK_MANIPULATE_ALL_RATES  Audiohook manipulate callback is capable of handling slinear at any sample rate. Without enabling this flag on initialization the manipulation callback is guaranteed 8khz audio only.

Definition at line 68 of file audiohook.h.

00068                               {
00069    /*! Audiohook manipulate callback is capable of handling slinear at any sample rate.
00070     * Without enabling this flag on initialization the manipulation callback is guaranteed
00071     * 8khz audio only. */
00072    AST_AUDIOHOOK_MANIPULATE_ALL_RATES = (1 << 0),
00073 };

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

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

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

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


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

References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_audiohook_update_status(), ast_calloc, ast_channel_audiohooks(), ast_channel_audiohooks_set(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_set_unbridged_nolock(), ast_channel_unlock, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, audiohook_list_set_samplerate_compatibility(), audiohook_set_internal_rate(), ast_audiohook_list::list_internal_samp_rate, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::type, and ast_audiohook_list::whisper_list.

Referenced by audiohook_move(), audiohook_volume_get(), enable_jack_hook(), init_hook(), pitchshift_helper(), set_talk_detect(), snoop_setup_audiohook(), speex_write(), start_spying(), startmon(), and volume_write().

00443 {
00444    ast_channel_lock(chan);
00445 
00446    if (!ast_channel_audiohooks(chan)) {
00447       struct ast_audiohook_list *ahlist;
00448       /* Whoops... allocate a new structure */
00449       if (!(ahlist = ast_calloc(1, sizeof(*ahlist)))) {
00450          ast_channel_unlock(chan);
00451          return -1;
00452       }
00453       ast_channel_audiohooks_set(chan, ahlist);
00454       AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->spy_list);
00455       AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->whisper_list);
00456       AST_LIST_HEAD_INIT_NOLOCK(&ast_channel_audiohooks(chan)->manipulate_list);
00457       /* This sample rate will adjust as necessary when writing to the list. */
00458       ast_channel_audiohooks(chan)->list_internal_samp_rate = 8000;
00459    }
00460 
00461    /* Drop into respective list */
00462    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
00463       AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
00464    } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
00465       AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
00466    } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
00467       AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
00468    }
00469 
00470 
00471    audiohook_set_internal_rate(audiohook, ast_channel_audiohooks(chan)->list_internal_samp_rate, 1);
00472    audiohook_list_set_samplerate_compatibility(ast_channel_audiohooks(chan));
00473 
00474    /* Change status over to running since it is now attached */
00475    ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_RUNNING);
00476 
00477    if (ast_channel_is_bridged(chan)) {
00478       ast_channel_set_unbridged_nolock(chan, 1);
00479    }
00480 
00481    ast_channel_unlock(chan);
00482 
00483    return 0;
00484 }

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

References ao2_cleanup, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_cond_destroy, ast_mutex_destroy, ast_slinfactory_destroy(), ast_translator_free_path(), ast_audiohook::format, 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(), datastore_destroy_cb(), destroy_callback(), destroy_jack_data(), destroy_monitor_audiohook(), hook_datastore_destroy_callback(), launch_monitor_thread(), and snoop_destroy().

00133 {
00134    /* Drop the factories used by this audiohook type */
00135    switch (audiohook->type) {
00136    case AST_AUDIOHOOK_TYPE_SPY:
00137    case AST_AUDIOHOOK_TYPE_WHISPER:
00138       ast_slinfactory_destroy(&audiohook->read_factory);
00139       ast_slinfactory_destroy(&audiohook->write_factory);
00140       break;
00141    default:
00142       break;
00143    }
00144 
00145    /* Destroy translation path if present */
00146    if (audiohook->trans_pvt)
00147       ast_translator_free_path(audiohook->trans_pvt);
00148 
00149    ao2_cleanup(audiohook->format);
00150 
00151    /* Lock and trigger be gone! */
00152    ast_cond_destroy(&audiohook->trigger);
00153    ast_mutex_destroy(&audiohook->lock);
00154 
00155    return 0;
00156 }

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

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

Referenced by channel_spy(), destroy_callback(), destroy_monitor_audiohook(), disable_jack_hook(), hook_datastore_destroy_callback(), snoop_hangup(), and speex_write().

00509 {
00510    if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
00511       return 0;
00512    }
00513 
00514    ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);
00515 
00516    while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
00517       ast_audiohook_trigger_wait(audiohook);
00518    }
00519 
00520    return 0;
00521 }

void ast_audiohook_detach_list ( struct ast_audiohook_list audiohook_list  ) 

Detach audiohooks from list and destroy said list.

Parameters:
audiohook_list List of audiohooks (NULL tolerant)
Returns:
Nothing

Definition at line 523 of file audiohook.c.

References ao2_cleanup, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_update_status(), ast_free, AST_LIST_REMOVE_HEAD, ast_translator_free_path(), ast_audiohook_translate::format, ast_audiohook_list::in_translate, ast_audiohook::list, ast_audiohook::manipulate_callback, ast_audiohook_list::manipulate_list, NULL, ast_audiohook_list::out_translate, ast_audiohook_list::spy_list, ast_audiohook_translate::trans_pvt, and ast_audiohook_list::whisper_list.

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

00524 {
00525    int i;
00526    struct ast_audiohook *audiohook;
00527 
00528    if (!audiohook_list) {
00529       return;
00530    }
00531 
00532    /* Drop any spies */
00533    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
00534       ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
00535    }
00536 
00537    /* Drop any whispering sources */
00538    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
00539       ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
00540    }
00541 
00542    /* Drop any manipulaters */
00543    while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
00544       ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
00545       audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
00546    }
00547 
00548    /* Drop translation paths if present */
00549    for (i = 0; i < 2; i++) {
00550       if (audiohook_list->in_translate[i].trans_pvt) {
00551          ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
00552          ao2_cleanup(audiohook_list->in_translate[i].format);
00553       }
00554       if (audiohook_list->out_translate[i].trans_pvt) {
00555          ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt);
00556          ao2_cleanup(audiohook_list->in_translate[i].format);
00557       }
00558    }
00559 
00560    /* Free ourselves */
00561    ast_free(audiohook_list);
00562 }

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
Note:
The channel does not need to be locked before calling this function.
Parameters:
chan Channel to detach from
source Name of source to detach
Returns:
Returns 0 on success, -1 on failure

Definition at line 660 of file audiohook.c.

References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_SHUTDOWN, ast_audiohook_update_status(), ast_channel_audiohooks(), ast_channel_lock, ast_channel_unlock, find_audiohook_by_source(), NULL, and ast_audiohook::status.

00661 {
00662    struct ast_audiohook *audiohook = NULL;
00663 
00664    ast_channel_lock(chan);
00665 
00666    /* Ensure the channel has audiohooks on it */
00667    if (!ast_channel_audiohooks(chan)) {
00668       ast_channel_unlock(chan);
00669       return -1;
00670    }
00671 
00672    audiohook = find_audiohook_by_source(ast_channel_audiohooks(chan), source);
00673 
00674    ast_channel_unlock(chan);
00675 
00676    if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
00677       ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);
00678    }
00679 
00680    return (audiohook ? 0 : -1);
00681 }

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

Initialize an audiohook structure.

Parameters:
audiohook Audiohook structure
type Type of audiohook to initialize this as
source Who is initializing this audiohook
init flags
Returns:
Returns 0 on success, -1 on failure
Parameters:
audiohook Audiohook structure
type 
source,init_flags 
Returns:
Returns 0 on success, -1 on failure

Definition at line 107 of file audiohook.c.

References AST_AUDIOHOOK_STATUS_NEW, ast_audiohook_update_status(), ast_cond_init, ast_mutex_init, audiohook_set_internal_rate(), ast_audiohook::init_flags, ast_audiohook::lock, NULL, ast_audiohook::source, ast_audiohook::trigger, and ast_audiohook::type.

Referenced by attach_barge(), audiohook_volume_get(), channel_spy(), enable_jack_hook(), hook_state_alloc(), launch_monitor_thread(), pitchshift_helper(), set_talk_detect(), snoop_setup_audiohook(), speex_write(), and volume_write().

00108 {
00109    /* Need to keep the type and source */
00110    audiohook->type = type;
00111    audiohook->source = source;
00112 
00113    /* Initialize lock that protects our audiohook */
00114    ast_mutex_init(&audiohook->lock);
00115    ast_cond_init(&audiohook->trigger, NULL);
00116 
00117    audiohook->init_flags = init_flags;
00118 
00119    /* initialize internal rate at 8khz, this will adjust if necessary */
00120    audiohook_set_internal_rate(audiohook, 8000, 0);
00121 
00122    /* Since we are just starting out... this audiohook is new */
00123    ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_NEW);
00124 
00125    return 0;
00126 }

void ast_audiohook_move_all ( struct ast_channel old_chan,
struct ast_channel new_chan 
)

Move all audiohooks from one channel to another.

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 audiohooks being moved
new_chan The destination channel for the audiohooks to be moved to

Definition at line 629 of file audiohook.c.

References ast_channel_audiohooks(), AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, audiohook_move(), ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.

Referenced by channel_do_masquerade().

00630 {
00631    struct ast_audiohook *audiohook;
00632    struct ast_audiohook_list *audiohook_list;
00633 
00634    audiohook_list = ast_channel_audiohooks(old_chan);
00635    if (!audiohook_list) {
00636       return;
00637    }
00638 
00639    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
00640       audiohook_move(old_chan, new_chan, audiohook);
00641    }
00642    AST_LIST_TRAVERSE_SAFE_END;
00643 
00644    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
00645       audiohook_move(old_chan, new_chan, audiohook);
00646    }
00647    AST_LIST_TRAVERSE_SAFE_END;
00648 
00649    AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
00650       audiohook_move(old_chan, new_chan, audiohook);
00651    }
00652    AST_LIST_TRAVERSE_SAFE_END;
00653 }

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

References ast_channel_audiohooks(), audiohook_move(), and find_audiohook_by_source().

00614 {
00615    struct ast_audiohook *audiohook;
00616 
00617    if (!ast_channel_audiohooks(old_chan)) {
00618       return;
00619    }
00620 
00621    audiohook = find_audiohook_by_source(ast_channel_audiohooks(old_chan), source);
00622    if (!audiohook) {
00623       return;
00624    }
00625 
00626    audiohook_move(old_chan, new_chan, audiohook);
00627 }

struct ast_frame* ast_audiohook_read_frame ( struct ast_audiohook audiohook,
size_t  samples,
enum ast_audiohook_direction  direction,
struct ast_format format 
) [read]

Reads a frame in from the audiohook structure.

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
Parameters:
audiohook Audiohook structure
samples Number of samples wanted in requested output format
direction Direction the audio frame came from
format Format of frame remote side wants back
Returns:
Returns frame on success, NULL on failure

Definition at line 406 of file audiohook.c.

References audiohook_read_frame_helper(), and NULL.

Referenced by snoop_read(), and spy_generate().

00407 {
00408    return audiohook_read_frame_helper(audiohook, samples, direction, format, NULL, NULL);
00409 }

struct ast_frame* ast_audiohook_read_frame_all ( struct ast_audiohook audiohook,
size_t  samples,
struct ast_format format,
struct ast_frame **  read_frame,
struct ast_frame **  write_frame 
) [read]

Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame data to provided arguments.

Parameters:
audiohook Audiohook structure
samples Number of samples wanted
ast_format Format of frame remote side wants back
read_frame if available, we'll copy the read buffer to this.
write_frame if available, we'll copy the write buffer to this.
direction 
Returns:
Returns frame on success, NULL on failure
Reads a frame in from the audiohook structure in mixed audio mode and copies read and write frame data to provided arguments.

Parameters:
audiohook Audiohook structure
samples Number of samples wanted
direction Direction the audio frame came from
format Format of frame remote side wants back
read_frame frame pointer for copying read frame data
write_frame frame pointer for copying write frame data
Returns:
Returns frame on success, NULL on failure

Definition at line 420 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_BOTH, and audiohook_read_frame_helper().

Referenced by mixmonitor_thread().

00421 {
00422    return audiohook_read_frame_helper(audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, format, read_frame, write_frame);
00423 }

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

References AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_audiohook_update_status(), ast_channel_audiohooks(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_set_unbridged_nolock(), ast_channel_unlock, AST_LIST_REMOVE, audiohook_list_set_samplerate_compatibility(), ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::type, and ast_audiohook_list::whisper_list.

Referenced by audiohook_move(), remove_talk_detect(), and speex_write().

00694 {
00695    ast_channel_lock(chan);
00696 
00697    if (!ast_channel_audiohooks(chan)) {
00698       ast_channel_unlock(chan);
00699       return -1;
00700    }
00701 
00702    if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
00703       AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
00704    } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
00705       AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
00706    } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
00707       AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
00708    }
00709 
00710    audiohook_list_set_samplerate_compatibility(ast_channel_audiohooks(chan));
00711    ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
00712 
00713    if (ast_channel_is_bridged(chan)) {
00714       ast_channel_set_unbridged_nolock(chan, 1);
00715    }
00716 
00717    ast_channel_unlock(chan);
00718 
00719    return 0;
00720 }

int ast_audiohook_set_mute ( struct ast_channel chan,
const char *  source,
enum ast_audiohook_flags  flag,
int  clear 
)

Mute frames read from or written to a channel.

Parameters:
chan Channel to muck with
source Type of audiohook
flag which direction to set / clear
clear set or clear muted frames on direction based on flag parameter
Return values:
0 success
-1 failure
Parameters:
chan Channel to muck with
source Type of audiohook
flag which flag to set / clear
clear set or clear
Returns:
Returns 0 on success, -1 on failure

Definition at line 1280 of file audiohook.c.

References ast_channel_audiohooks(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_set_flag, find_audiohook_by_source(), and NULL.

Referenced by manager_mute_mixmonitor().

01281 {
01282    struct ast_audiohook *audiohook = NULL;
01283 
01284    ast_channel_lock(chan);
01285 
01286    /* Ensure the channel has audiohooks on it */
01287    if (!ast_channel_audiohooks(chan)) {
01288       ast_channel_unlock(chan);
01289       return -1;
01290    }
01291 
01292    audiohook = find_audiohook_by_source(ast_channel_audiohooks(chan), source);
01293 
01294    if (audiohook) {
01295       if (clear) {
01296          ast_clear_flag(audiohook, flag);
01297       } else {
01298          ast_set_flag(audiohook, flag);
01299       }
01300    }
01301 
01302    ast_channel_unlock(chan);
01303 
01304    return (audiohook ? 0 : -1);
01305 }

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

00999 {
01000    struct timeval wait;
01001    struct timespec ts;
01002 
01003    wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
01004    ts.tv_sec = wait.tv_sec;
01005    ts.tv_nsec = wait.tv_usec * 1000;
01006 
01007    ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
01008 
01009    return;
01010 }

void ast_audiohook_update_status ( struct ast_audiohook audiohook,
enum ast_audiohook_status  status 
)

Update audiohook's status.

Parameters:
audiohook Audiohook structure
audiohook status enum
Note:
once status is updated to DONE, this function can not be used to set the status back to any other setting. Setting DONE effectively locks the status as such.
Parameters:
audiohook Audiohook structure
status Audiohook status enum
Note:
once status is updated to DONE, this function can not be used to set the status back to any other setting. Setting DONE effectively locks the status as such.

Definition at line 494 of file audiohook.c.

References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_unlock, ast_cond_signal, ast_audiohook::status, and ast_audiohook::trigger.

Referenced by ast_audiohook_attach(), ast_audiohook_detach(), ast_audiohook_detach_list(), ast_audiohook_detach_source(), ast_audiohook_init(), ast_audiohook_remove(), audio_audiohook_write_list(), dtmf_audiohook_write_list(), and stop_mixmonitor_full().

00495 {
00496    ast_audiohook_lock(audiohook);
00497    if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
00498       audiohook->status = status;
00499       ast_cond_signal(&audiohook->trigger);
00500    }
00501    ast_audiohook_unlock(audiohook);
00502 }

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
Since:
1.6.1
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 1253 of file audiohook.c.

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

Referenced by execute_menu_entry().

01254 {
01255    struct audiohook_volume *audiohook_volume = NULL;
01256 
01257    /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
01258    if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
01259       return -1;
01260    }
01261 
01262    /* Based on the direction change the specific adjustment value */
01263    if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
01264       audiohook_volume->read_adjustment += volume;
01265    }
01266    if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
01267       audiohook_volume->write_adjustment += volume;
01268    }
01269 
01270    return 0;
01271 }

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
Since:
1.6.1
Parameters:
chan Channel to retrieve volume adjustment from
direction Direction to retrieve
Returns:
Returns adjustment value

Definition at line 1227 of file audiohook.c.

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

Referenced by confbridge_exec().

01228 {
01229    struct audiohook_volume *audiohook_volume = NULL;
01230    int adjustment = 0;
01231 
01232    /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
01233    if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
01234       return 0;
01235    }
01236 
01237    /* Grab the adjustment value based on direction given */
01238    if (direction == AST_AUDIOHOOK_DIRECTION_READ) {
01239       adjustment = audiohook_volume->read_adjustment;
01240    } else if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
01241       adjustment = audiohook_volume->write_adjustment;
01242    }
01243 
01244    return adjustment;
01245 }

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
Since:
1.6.1
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 1202 of file audiohook.c.

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

Referenced by confbridge_exec(), and execute_menu_entry().

01203 {
01204    struct audiohook_volume *audiohook_volume = NULL;
01205 
01206    /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
01207    if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
01208       return -1;
01209    }
01210 
01211    /* Now based on the direction set the proper value */
01212    if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
01213       audiohook_volume->read_adjustment = volume;
01214    }
01215    if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
01216       audiohook_volume->write_adjustment = volume;
01217    }
01218 
01219    return 0;
01220 }

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

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_MUTE_READ, AST_AUDIOHOOK_MUTE_WRITE, AST_AUDIOHOOK_SMALL_QUEUE, AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE, AST_AUDIOHOOK_SYNC_TOLERANCE, AST_AUDIOHOOK_TRIGGER_MODE, AST_AUDIOHOOK_TRIGGER_READ, AST_AUDIOHOOK_TRIGGER_SYNC, AST_AUDIOHOOK_TRIGGER_WRITE, ast_cond_signal, ast_debug, ast_frame_clear(), ast_slinfactory_available(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_frame::datalen, ast_audiohook::hook_internal_samp_rate, ast_audiohook::read_factory, ast_audiohook::read_time, ast_audiohook::trigger, ast_audiohook::write_factory, and ast_audiohook::write_time.

Referenced by audio_audiohook_write_list(), channel_spy(), and snoop_write().

00165 {
00166    struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
00167    struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
00168    struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
00169    int our_factory_samples;
00170    int our_factory_ms;
00171    int other_factory_samples;
00172    int other_factory_ms;
00173    int muteme = 0;
00174 
00175    /* Update last feeding time to be current */
00176    *rwtime = ast_tvnow();
00177 
00178    our_factory_samples = ast_slinfactory_available(factory);
00179    our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / (audiohook->hook_internal_samp_rate / 1000));
00180    other_factory_samples = ast_slinfactory_available(other_factory);
00181    other_factory_ms = other_factory_samples / (audiohook->hook_internal_samp_rate / 1000);
00182 
00183    if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
00184       ast_debug(1, "Flushing audiohook %p so it remains in sync\n", audiohook);
00185       ast_slinfactory_flush(factory);
00186       ast_slinfactory_flush(other_factory);
00187    }
00188 
00189    if (ast_test_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE) && ((our_factory_ms > AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE) || (other_factory_ms > AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE))) {
00190       ast_debug(1, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
00191       ast_slinfactory_flush(factory);
00192       ast_slinfactory_flush(other_factory);
00193    }
00194 
00195    /* swap frame data for zeros if mute is required */
00196    if ((ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) ||
00197       (ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) ||
00198       (ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE) == (AST_AUDIOHOOK_MUTE_READ | AST_AUDIOHOOK_MUTE_WRITE))) {
00199          muteme = 1;
00200    }
00201 
00202    if (muteme && frame->datalen > 0) {
00203       ast_frame_clear(frame);
00204    }
00205 
00206    /* Write frame out to respective factory */
00207    ast_slinfactory_feed(factory, frame);
00208 
00209    /* If we need to notify the respective handler of this audiohook, do so */
00210    if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
00211       ast_cond_signal(&audiohook->trigger);
00212    } else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) {
00213       ast_cond_signal(&audiohook->trigger);
00214    } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
00215       ast_cond_signal(&audiohook->trigger);
00216    }
00217 
00218    return 0;
00219 }

struct ast_frame* ast_audiohook_write_list ( struct ast_channel chan,
struct ast_audiohook_list audiohook_list,
enum ast_audiohook_direction  direction,
struct ast_frame frame 
) [read]

Pass a frame off to be handled by the audiohook core.

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

00984 {
00985    /* Pass off frame to it's respective list write function */
00986    if (frame->frametype == AST_FRAME_VOICE) {
00987       return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
00988    } else if (frame->frametype == AST_FRAME_DTMF) {
00989       return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
00990    } else {
00991       return frame;
00992    }
00993 }

int ast_audiohook_write_list_empty ( struct ast_audiohook_list audiohook_list  ) 

Determine if a audiohook_list is empty or not.

Parameters:
audiohook Audiohook to check. (NULL also means empty)
retval 0 false, 1 true

Definition at line 968 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(), ast_channel_has_audio_frame_or_monitor(), ast_channel_has_hook_requiring_audio(), and ast_write().

00969 {
00970    return !audiohook_list
00971       || (AST_LIST_EMPTY(&audiohook_list->spy_list)
00972          && AST_LIST_EMPTY(&audiohook_list->whisper_list)
00973          && AST_LIST_EMPTY(&audiohook_list->manipulate_list));
00974 }

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

References AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_channel_audiohooks(), ast_debug, AST_LIST_TRAVERSE, ast_audiohook::list, ast_audiohook_list::manipulate_list, NULL, ast_audiohook::source, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.

Referenced by feature_automixmonitor().

01014 {
01015    int count = 0;
01016    struct ast_audiohook *ah = NULL;
01017 
01018    if (!ast_channel_audiohooks(chan)) {
01019       return -1;
01020    }
01021 
01022    switch (type) {
01023       case AST_AUDIOHOOK_TYPE_SPY:
01024          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
01025             if (!strcmp(ah->source, source)) {
01026                count++;
01027             }
01028          }
01029          break;
01030       case AST_AUDIOHOOK_TYPE_WHISPER:
01031          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
01032             if (!strcmp(ah->source, source)) {
01033                count++;
01034             }
01035          }
01036          break;
01037       case AST_AUDIOHOOK_TYPE_MANIPULATE:
01038          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
01039             if (!strcmp(ah->source, source)) {
01040                count++;
01041             }
01042          }
01043          break;
01044       default:
01045          ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
01046          return -1;
01047    }
01048 
01049    return count;
01050 }

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

References AST_AUDIOHOOK_STATUS_RUNNING, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_channel_audiohooks(), ast_debug, AST_LIST_TRAVERSE, ast_audiohook::list, ast_audiohook_list::manipulate_list, NULL, ast_audiohook::source, ast_audiohook_list::spy_list, ast_audiohook::status, and ast_audiohook_list::whisper_list.

01054 {
01055    int count = 0;
01056    struct ast_audiohook *ah = NULL;
01057    if (!ast_channel_audiohooks(chan))
01058       return -1;
01059 
01060    switch (type) {
01061       case AST_AUDIOHOOK_TYPE_SPY:
01062          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
01063             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
01064                count++;
01065          }
01066          break;
01067       case AST_AUDIOHOOK_TYPE_WHISPER:
01068          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
01069             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
01070                count++;
01071          }
01072          break;
01073       case AST_AUDIOHOOK_TYPE_MANIPULATE:
01074          AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
01075             if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
01076                count++;
01077          }
01078          break;
01079       default:
01080          ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
01081          return -1;
01082    }
01083    return count;
01084 }


Generated on Thu Apr 16 06:29:02 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6