Thu Apr 28 2011 17:15:36

Asterisk developer's documentation


audiohook.h File Reference

Audiohooks Architecture. More...

#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/slinfactory.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_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.
struct 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.
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)
 determines if a audiohook_list is empty or not.
int ast_channel_audiohook_count_by_source (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many audiohooks from a certain source exist on a given channel, regardless of status.
int ast_channel_audiohook_count_by_source_running (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many spies of a certain type exist on a given channel, and are in state running.

Detailed Description

Audiohooks Architecture.

Definition in file audiohook.h.


Define Documentation

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

Definition at line 67 of file audiohook.h.

Referenced by ast_audiohook_write_frame().

#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:
audiohookAudiohook structure
chanChannel
frameFrame of audio to manipulate
directionDirection 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 87 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 49 of file audiohook.h.

                             {
   AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
   AST_AUDIOHOOK_DIRECTION_WRITE,    /*!< Writing audio out */
   AST_AUDIOHOOK_DIRECTION_BOTH,     /*!< Both reading audio in and writing audio out */
};
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 55 of file audiohook.h.

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

                          {
   AST_AUDIOHOOK_STATUS_NEW = 0,  /*!< Audiohook was just created, not in use yet */
   AST_AUDIOHOOK_STATUS_RUNNING,  /*!< Audiohook is running on a channel */
   AST_AUDIOHOOK_STATUS_SHUTDOWN, /*!< Audiohook is being shutdown */
   AST_AUDIOHOOK_STATUS_DONE,     /*!< Audiohook has shutdown and is not running on a channel any longer */
};
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.

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

Function Documentation

int ast_audiohook_attach ( struct ast_channel chan,
struct ast_audiohook audiohook 
)

Attach audiohook to channel.

Parameters:
chanChannel
audiohookAudiohook structure
Returns:
Returns 0 on success, -1 on failure

Definition at line 330 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_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::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().

{
   ast_channel_lock(chan);

   if (!chan->audiohooks) {
      /* Whoops... allocate a new structure */
      if (!(chan->audiohooks = ast_calloc(1, sizeof(*chan->audiohooks)))) {
         ast_channel_unlock(chan);
         return -1;
      }
      AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->spy_list);
      AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->whisper_list);
      AST_LIST_HEAD_INIT_NOLOCK(&chan->audiohooks->manipulate_list);
   }

   /* Drop into respective list */
   if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
      AST_LIST_INSERT_TAIL(&chan->audiohooks->spy_list, audiohook, list);
   else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
      AST_LIST_INSERT_TAIL(&chan->audiohooks->whisper_list, audiohook, list);
   else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
      AST_LIST_INSERT_TAIL(&chan->audiohooks->manipulate_list, audiohook, list);

   /* Change status over to running since it is now attached */
   ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_RUNNING);

   ast_channel_unlock(chan);

   return 0;
}
int ast_audiohook_destroy ( struct ast_audiohook audiohook)

Destroys an audiohook structure.

Parameters:
audiohookAudiohook 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(), destroy_monitor_audiohook(), and launch_monitor_thread().

{
   /* Drop the factories used by this audiohook type */
   switch (audiohook->type) {
   case AST_AUDIOHOOK_TYPE_SPY:
      ast_slinfactory_destroy(&audiohook->read_factory);
   case AST_AUDIOHOOK_TYPE_WHISPER:
      ast_slinfactory_destroy(&audiohook->write_factory);
      break;
   default:
      break;
   }

   /* Destroy translation path if present */
   if (audiohook->trans_pvt)
      ast_translator_free_path(audiohook->trans_pvt);

   /* Lock and trigger be gone! */
   ast_cond_destroy(&audiohook->trigger);
   ast_mutex_destroy(&audiohook->lock);

   return 0;
}
int ast_audiohook_detach ( struct ast_audiohook audiohook)

Detach audiohook from channel.

Parameters:
audiohookAudiohook structure
Returns:
Returns 0 on success, -1 on failure

Definition at line 383 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_monitor_audiohook(), disable_jack_hook(), and speex_write().

{
   if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
      return 0;

   ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);

   while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
      ast_audiohook_trigger_wait(audiohook);

   return 0;
}
int ast_audiohook_detach_list ( struct ast_audiohook_list audiohook_list)

Detach audiohooks from list and destroy said list.

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

Definition at line 400 of file audiohook.c.

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

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

{
   int i = 0;
   struct ast_audiohook *audiohook = NULL;

   /* Drop any spies */
   while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
      ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
   }

   /* Drop any whispering sources */
   while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
      ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
   }

   /* Drop any manipulaters */
   while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
      ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);
      audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
   }

   /* Drop translation paths if present */
   for (i = 0; i < 2; i++) {
      if (audiohook_list->in_translate[i].trans_pvt)
         ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
      if (audiohook_list->out_translate[i].trans_pvt)
         ast_translator_free_path(audiohook_list->out_translate[i].trans_pvt);
   }
   
   /* Free ourselves */
   ast_free(audiohook_list);

   return 0;
}
int ast_audiohook_detach_source ( struct ast_channel chan,
const char *  source 
)

Detach specified source audiohook from channel.

Parameters:
chanChannel to detach from
sourceName 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:
chanChannel to detach from
sourceName of source to detach
Returns:
Returns 0 on success, -1 on failure

Definition at line 491 of file audiohook.c.

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

Referenced by handle_cli_mixmonitor(), and stop_mixmonitor_exec().

{
   struct ast_audiohook *audiohook = NULL;

   ast_channel_lock(chan);

   /* Ensure the channel has audiohooks on it */
   if (!chan->audiohooks) {
      ast_channel_unlock(chan);
      return -1;
   }

   audiohook = find_audiohook_by_source(chan->audiohooks, source);

   ast_channel_unlock(chan);

   if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE)
      ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_SHUTDOWN);

   return (audiohook ? 0 : -1);
}
int ast_audiohook_init ( struct ast_audiohook audiohook,
enum ast_audiohook_type  type,
const char *  source 
)

Initialize an audiohook structure.

Parameters:
audiohookAudiohook structure
typeType of audiohook to initialize this as
sourceWho is initializing this audiohook
Returns:
Returns 0 on success, -1 on failure
Parameters:
audiohookAudiohook 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_audiohook_update_status(), ast_cond_init(), ast_mutex_init(), ast_slinfactory_init(), and type.

Referenced by audiohook_volume_get(), channel_spy(), enable_jack_hook(), launch_monitor_thread(), speex_write(), and volume_write().

{
   /* Need to keep the type and source */
   audiohook->type = type;
   audiohook->source = source;

   /* Initialize lock that protects our audiohook */
   ast_mutex_init(&audiohook->lock);
   ast_cond_init(&audiohook->trigger, NULL);

   /* Setup the factories that are needed for this audiohook type */
   switch (type) {
   case AST_AUDIOHOOK_TYPE_SPY:
      ast_slinfactory_init(&audiohook->read_factory);
   case AST_AUDIOHOOK_TYPE_WHISPER:
      ast_slinfactory_init(&audiohook->write_factory);
      break;
   default:
      break;
   }

   /* Since we are just starting out... this audiohook is new */
   ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_NEW);

   return 0;
}
void ast_audiohook_move_by_source ( struct ast_channel old_chan,
struct ast_channel new_chan,
const char *  source 
)

Move an audiohook from one channel to a new one.

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_chanThe source of the audiohook to move
new_chanThe destination to which we want the audiohook to move
sourceThe source of the audiohook we want to move

Definition at line 462 of file audiohook.c.

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

Referenced by audiohook_inheritance_fixup().

{
   struct ast_audiohook *audiohook;
   enum ast_audiohook_status oldstatus;

   if (!old_chan->audiohooks || !(audiohook = find_audiohook_by_source(old_chan->audiohooks, source))) {
      return;
   }

   /* By locking both channels and the audiohook, we can assure that
    * another thread will not have a chance to read the audiohook's status
    * as done, even though ast_audiohook_remove signals the trigger
    * condition.
    */
   ast_audiohook_lock(audiohook);
   oldstatus = audiohook->status;

   ast_audiohook_remove(old_chan, audiohook);
   ast_audiohook_attach(new_chan, audiohook);

   audiohook->status = oldstatus;
   ast_audiohook_unlock(audiohook);
}
struct ast_frame* ast_audiohook_read_frame ( struct ast_audiohook audiohook,
size_t  samples,
enum ast_audiohook_direction  direction,
int  format 
) [read]

Reads a frame in from the audiohook structure.

Parameters:
audiohookAudiohook structure
samplesNumber of samples wanted
directionDirection the audio frame came from
formatFormat of frame remote side wants back
Returns:
Returns frame on success, NULL on failure

Definition at line 295 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(), ast_audiohook::format, read_frame(), and ast_audiohook::trans_pvt.

Referenced by mixmonitor_thread(), and spy_generate().

{
   struct ast_frame *read_frame = NULL, *final_frame = NULL;

   if (!(read_frame = (direction == AST_AUDIOHOOK_DIRECTION_BOTH ? audiohook_read_frame_both(audiohook, samples) : audiohook_read_frame_single(audiohook, samples, direction))))
      return NULL;

   /* If they don't want signed linear back out, we'll have to send it through the translation path */
   if (format != AST_FORMAT_SLINEAR) {
      /* Rebuild translation path if different format then previously */
      if (audiohook->format != format) {
         if (audiohook->trans_pvt) {
            ast_translator_free_path(audiohook->trans_pvt);
            audiohook->trans_pvt = NULL;
         }
         /* 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 */
         if (!(audiohook->trans_pvt = ast_translator_build_path(format, AST_FORMAT_SLINEAR))) {
            ast_frfree(read_frame);
            return NULL;
         }
      }
      /* Convert to requested format, and allow the read in frame to be freed */
      final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1);
   } else {
      final_frame = read_frame;
   }

   return final_frame;
}
int ast_audiohook_remove ( struct ast_channel chan,
struct ast_audiohook audiohook 
)

Remove an audiohook from a specified channel.

Parameters:
chanChannel to remove from
audiohookAudiohook 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 523 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_lock, ast_channel_unlock, AST_LIST_REMOVE, ast_channel::audiohooks, ast_audiohook::list, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, ast_audiohook::type, and ast_audiohook_list::whisper_list.

Referenced by ast_audiohook_move_by_source(), and speex_write().

{
   ast_channel_lock(chan);

   if (!chan->audiohooks) {
      ast_channel_unlock(chan);
      return -1;
   }

   if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY)
      AST_LIST_REMOVE(&chan->audiohooks->spy_list, audiohook, list);
   else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER)
      AST_LIST_REMOVE(&chan->audiohooks->whisper_list, audiohook, list);
   else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE)
      AST_LIST_REMOVE(&chan->audiohooks->manipulate_list, audiohook, list);

   ast_audiohook_update_status(audiohook, AST_AUDIOHOOK_STATUS_DONE);

   ast_channel_unlock(chan);

   return 0;
}
void ast_audiohook_trigger_wait ( struct ast_audiohook audiohook)

Wait for audiohook trigger to be triggered.

Parameters:
audiohookAudiohook to wait on

Definition at line 758 of file audiohook.c.

References ast_cond_timedwait(), ast_samp2tv(), ast_tvadd(), ast_tvnow(), ast_audiohook::lock, and ast_audiohook::trigger.

Referenced by ast_audiohook_detach(), and mixmonitor_thread().

{
   struct timeval wait;
   struct timespec ts;

   wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
   ts.tv_sec = wait.tv_sec;
   ts.tv_nsec = wait.tv_usec * 1000;
   
   ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
   
   return;
}
void ast_audiohook_update_status ( struct ast_audiohook audiohook,
enum ast_audiohook_status  status 
)

Update audiohook's status.

Parameters:
audiohookAudiohook structure
audiohookstatus 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:
audiohookstatus enum
audiohookAudiohook structure
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 369 of file audiohook.c.

References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, ast_audiohook_unlock, ast_cond_signal(), status, 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(), and dtmf_audiohook_write_list().

{
   ast_audiohook_lock(audiohook);
   if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
      audiohook->status = status;
      ast_cond_signal(&audiohook->trigger);
   }
   ast_audiohook_unlock(audiohook);
}
int ast_audiohook_volume_adjust ( struct ast_channel chan,
enum ast_audiohook_direction  direction,
int  volume 
)

Adjust the volume on frames read from or written to a channel.

Parameters:
chanChannel to muck with
directionDirection to increase
volumeValue to adjust the adjustment by
Returns:
Returns 0 on success, -1 on failure
Since:
1.6.1
Parameters:
chanChannel to muck with
directionDirection to increase
volumeValue to adjust the adjustment by
Returns:
Returns 0 on success, -1 on failure

Definition at line 1018 of file audiohook.c.

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

Referenced by menu_callback().

{
   struct audiohook_volume *audiohook_volume = NULL;

   /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
   if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
      return -1;
   }

   /* Based on the direction change the specific adjustment value */
   if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
      audiohook_volume->read_adjustment += volume;
   }
   if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
      audiohook_volume->write_adjustment += volume;
   }

   return 0;
}
int ast_audiohook_volume_get ( struct ast_channel chan,
enum ast_audiohook_direction  direction 
)

Retrieve the volume adjustment value on frames read from or written to a channel.

Parameters:
chanChannel to retrieve volume adjustment from
directionDirection to retrieve
Returns:
Returns adjustment value
Since:
1.6.1
Parameters:
chanChannel to retrieve volume adjustment from
directionDirection to retrieve
Returns:
Returns adjustment value

Definition at line 992 of file audiohook.c.

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

Referenced by confbridge_exec().

{
   struct audiohook_volume *audiohook_volume = NULL;
   int adjustment = 0;

   /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
   if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
      return 0;
   }

   /* Grab the adjustment value based on direction given */
   if (direction == AST_AUDIOHOOK_DIRECTION_READ) {
      adjustment = audiohook_volume->read_adjustment;
   } else if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
      adjustment = audiohook_volume->write_adjustment;
   }

   return adjustment;
}
int ast_audiohook_volume_set ( struct ast_channel chan,
enum ast_audiohook_direction  direction,
int  volume 
)

Adjust the volume on frames read from or written to a channel.

Parameters:
chanChannel to muck with
directionDirection to set on
volumeValue to adjust the volume by
Returns:
Returns 0 on success, -1 on failure
Since:
1.6.1
Parameters:
chanChannel to muck with
directionDirection to set on
volumeValue to adjust the volume by
Returns:
Returns 0 on success, -1 on failure

Definition at line 967 of file audiohook.c.

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

Referenced by confbridge_exec().

{
   struct audiohook_volume *audiohook_volume = NULL;

   /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
   if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
      return -1;
   }

   /* Now based on the direction set the proper value */
   if (direction == AST_AUDIOHOOK_DIRECTION_READ || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
      audiohook_volume->read_adjustment = volume;
   }
   if (direction == AST_AUDIOHOOK_DIRECTION_WRITE || direction == AST_AUDIOHOOK_DIRECTION_BOTH) {
      audiohook_volume->write_adjustment = volume;
   }

   return 0;
}
int ast_audiohook_write_frame ( struct ast_audiohook audiohook,
enum ast_audiohook_direction  direction,
struct ast_frame frame 
)

Writes a frame into the audiohook structure.

Parameters:
audiohookAudiohook structure
directionDirection the audio frame came from
frameFrame 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_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().

{
   struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
   struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
   struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
   int our_factory_samples;
   int our_factory_ms;
   int other_factory_samples;
   int other_factory_ms;

   /* Update last feeding time to be current */
   *rwtime = ast_tvnow();

   our_factory_samples = ast_slinfactory_available(factory);
   our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / 8);
   other_factory_samples = ast_slinfactory_available(other_factory);
   other_factory_ms = other_factory_samples / 8;

   if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && other_factory_samples && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
      if (option_debug)
         ast_log(LOG_DEBUG, "Flushing audiohook %p so it remains in sync\n", audiohook);
      ast_slinfactory_flush(factory);
      ast_slinfactory_flush(other_factory);
   }

   if (ast_test_flag(audiohook, AST_AUDIOHOOK_SMALL_QUEUE) && (our_factory_samples > 640 || other_factory_samples > 640)) {
      if (option_debug) {
         ast_log(LOG_DEBUG, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
      }
      ast_slinfactory_flush(factory);
      ast_slinfactory_flush(other_factory);
   }

   /* Write frame out to respective factory */
   ast_slinfactory_feed(factory, frame);

   /* If we need to notify the respective handler of this audiohook, do so */
   if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
      ast_cond_signal(&audiohook->trigger);
   } else if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_WRITE) && (direction == AST_AUDIOHOOK_DIRECTION_WRITE)) {
      ast_cond_signal(&audiohook->trigger);
   } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
      ast_cond_signal(&audiohook->trigger);
   }

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

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

Parameters:
chanChannel that the list is coming off of
audiohook_listList of audiohooks
directionDirection frame is coming in from
frameThe frame itself
Returns:
Return frame on success, NULL on failure

Definition at line 744 of file audiohook.c.

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

Referenced by __ast_read(), and ast_write().

{
   /* Pass off frame to it's respective list write function */
   if (frame->frametype == AST_FRAME_VOICE)
      return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
   else if (frame->frametype == AST_FRAME_DTMF)
      return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
   else
      return frame;
}
int ast_audiohook_write_list_empty ( struct ast_audiohook_list audiohook_list)

determines if a audiohook_list is empty or not.

retval 0 false, 1 true

Definition at line 726 of file audiohook.c.

References AST_LIST_EMPTY, ast_audiohook_list::manipulate_list, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.

Referenced by __ast_read(), and ast_write().

{
   if (AST_LIST_EMPTY(&audiohook_list->spy_list) &&
      AST_LIST_EMPTY(&audiohook_list->whisper_list) &&
      AST_LIST_EMPTY(&audiohook_list->manipulate_list)) {

      return 1;
   }
   return 0;
}
int ast_channel_audiohook_count_by_source ( struct ast_channel chan,
const char *  source,
enum ast_audiohook_type  type 
)

Find out how many audiohooks from a certain source exist on a given channel, regardless of status.

Parameters:
chanThe channel on which to find the spies
sourceThe audiohook's source
typeThe type of audiohook
Returns:
Return the number of audiohooks which are from the source specified

Note: Function performs nlocking.

Definition at line 773 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, ast_audiohook::list, LOG_DEBUG, ast_audiohook_list::manipulate_list, ast_audiohook::source, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.

Referenced by builtin_automixmonitor().

{
   int count = 0;
   struct ast_audiohook *ah = NULL;

   if (!chan->audiohooks)
      return -1;

   switch (type) {
      case AST_AUDIOHOOK_TYPE_SPY:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->spy_list, ah, list) {
            if (!strcmp(ah->source, source)) {
               count++;
            }
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      case AST_AUDIOHOOK_TYPE_WHISPER:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->whisper_list, ah, list) {
            if (!strcmp(ah->source, source)) {
               count++;
            }
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      case AST_AUDIOHOOK_TYPE_MANIPULATE:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->manipulate_list, ah, list) {
            if (!strcmp(ah->source, source)) {
               count++;
            }
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      default:
         ast_log(LOG_DEBUG, "Invalid audiohook type supplied, (%d)\n", type);
         return -1;
   }

   return count;
}
int ast_channel_audiohook_count_by_source_running ( struct ast_channel chan,
const char *  source,
enum ast_audiohook_type  type 
)

Find out how many spies of a certain type exist on a given channel, and are in state running.

Parameters:
chanThe channel on which to find the spies
sourceThe source of the audiohook
typeThe 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 815 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, ast_audiohook::list, LOG_DEBUG, ast_audiohook_list::manipulate_list, ast_audiohook::source, ast_audiohook_list::spy_list, ast_audiohook::status, and ast_audiohook_list::whisper_list.

Referenced by builtin_automixmonitor().

{
   int count = 0;
   struct ast_audiohook *ah = NULL;
   if (!chan->audiohooks)
      return -1;

   switch (type) {
      case AST_AUDIOHOOK_TYPE_SPY:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->spy_list, ah, list) {
            if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
               count++;
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      case AST_AUDIOHOOK_TYPE_WHISPER:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->whisper_list, ah, list) {
            if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
               count++;
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      case AST_AUDIOHOOK_TYPE_MANIPULATE:
         AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->audiohooks->manipulate_list, ah, list) {
            if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
               count++;
         }
         AST_LIST_TRAVERSE_SAFE_END;
         break;
      default:
         ast_log(LOG_DEBUG, "Invalid audiohook type supplied, (%d)\n", type);
         return -1;
   }
   return count;
}