Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Enumerations | Functions
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
 

Macros

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

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

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),
  AST_AUDIOHOOK_COMPATIBLE = (1 << 7), AST_AUDIOHOOK_SUBSTITUTE_SILENCE = (1 << 8)
}
 
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. More...
 
int ast_audiohook_destroy (struct ast_audiohook *audiohook)
 Destroys an audiohook structure. More...
 
int ast_audiohook_detach (struct ast_audiohook *audiohook)
 Detach audiohook from channel. More...
 
void ast_audiohook_detach_list (struct ast_audiohook_list *audiohook_list)
 Detach audiohooks from list and destroy said list. More...
 
int ast_audiohook_detach_source (struct ast_channel *chan, const char *source)
 Detach specified source audiohook from channel. More...
 
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. More...
 
void ast_audiohook_move_all (struct ast_channel *old_chan, struct ast_channel *new_chan)
 Move all audiohooks from one channel to another. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_audiohook_remove (struct ast_channel *chan, struct ast_audiohook *audiohook)
 Remove an audiohook from a specified channel. More...
 
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. More...
 
void ast_audiohook_trigger_wait (struct ast_audiohook *audiohook)
 Wait for audiohook trigger to be triggered. More...
 
void ast_audiohook_update_status (struct ast_audiohook *audiohook, enum ast_audiohook_status status)
 Update audiohook's status. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_audiohook_write_list_empty (struct ast_audiohook_list *audiohook_list)
 Determine if a audiohook_list is empty or not. More...
 
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. More...
 
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. More...
 

Detailed Description

Audiohooks Architecture.

Definition in file audiohook.h.

Macro Definition Documentation

◆ ast_audiohook_lock

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

◆ ast_audiohook_unlock

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

Typedef Documentation

◆ ast_audiohook_manipulate_callback

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

Enumeration Type Documentation

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

48  {
49  AST_AUDIOHOOK_DIRECTION_READ = 0, /*!< Reading audio in */
50  AST_AUDIOHOOK_DIRECTION_WRITE, /*!< Writing audio out */
51  AST_AUDIOHOOK_DIRECTION_BOTH, /*!< Both reading audio in and writing audio out */
52 };

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

AST_AUDIOHOOK_MUTE_READ 

audiohook should be mute frames read

AST_AUDIOHOOK_MUTE_WRITE 

audiohook should be mute frames written

AST_AUDIOHOOK_COMPATIBLE 

is the audiohook native slin compatible

AST_AUDIOHOOK_SUBSTITUTE_SILENCE 

Substitute silence for missing audio

Definition at line 54 of file audiohook.h.

54  {
55  AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0), /*!< When audiohook should be triggered to do something */
56  AST_AUDIOHOOK_TRIGGER_READ = (1 << 0), /*!< Audiohook wants to be triggered when reading audio in */
57  AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0), /*!< Audiohook wants to be triggered when writing audio out */
58  AST_AUDIOHOOK_WANTS_DTMF = (1 << 2), /*!< Audiohook also wants to receive DTMF frames */
59  AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 3), /*!< Audiohook wants to be triggered when both sides have combined audio available */
60  /*! Audiohooks with this flag set will not allow for a large amount of samples to build up on its
61  * slinfactories. We will flush the factories if they contain too many samples.
62  */
63  AST_AUDIOHOOK_SMALL_QUEUE = (1 << 4),
64  AST_AUDIOHOOK_MUTE_READ = (1 << 5), /*!< audiohook should be mute frames read */
65  AST_AUDIOHOOK_MUTE_WRITE = (1 << 6), /*!< audiohook should be mute frames written */
66  AST_AUDIOHOOK_COMPATIBLE = (1 << 7), /*!< is the audiohook native slin compatible */
67 
68  AST_AUDIOHOOK_SUBSTITUTE_SILENCE = (1 << 8), /*!< Substitute silence for missing audio */
69 };

◆ ast_audiohook_init_flags

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

71  {
72  /*! Audiohook manipulate callback is capable of handling slinear at any sample rate.
73  * Without enabling this flag on initialization the manipulation callback is guaranteed
74  * 8khz audio only. */
76 };

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

41  {
42  AST_AUDIOHOOK_STATUS_NEW = 0, /*!< Audiohook was just created, not in use yet */
43  AST_AUDIOHOOK_STATUS_RUNNING, /*!< Audiohook is running on a channel */
44  AST_AUDIOHOOK_STATUS_SHUTDOWN, /*!< Audiohook is being shutdown */
45  AST_AUDIOHOOK_STATUS_DONE, /*!< Audiohook has shutdown and is not running on a channel any longer */
46 };

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

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

Function Documentation

◆ ast_audiohook_attach()

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 501 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_flags(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_set_unbridged_nolock(), ast_channel_unlock, AST_FLAG_ZOMBIE, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, ast_test_flag, audiohook_list_set_samplerate_compatibility(), audiohook_set_internal_rate(), DEFAULT_INTERNAL_SAMPLE_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(), detect_write(), enable_jack_hook(), init_hook(), pitchshift_helper(), scramble_write(), set_talk_detect(), snoop_setup_audiohook(), speex_write(), start_spying(), startmon(), and volume_write().

502 {
503  ast_channel_lock(chan);
504 
505  /* Don't allow an audiohook to be attached to a channel that is already hung up.
506  * The hang up process is what actually notifies the audiohook that it should
507  * stop.
508  */
510  ast_channel_unlock(chan);
511  return -1;
512  }
513 
514  if (!ast_channel_audiohooks(chan)) {
515  struct ast_audiohook_list *ahlist;
516  /* Whoops... allocate a new structure */
517  if (!(ahlist = ast_calloc(1, sizeof(*ahlist)))) {
518  ast_channel_unlock(chan);
519  return -1;
520  }
521  ast_channel_audiohooks_set(chan, ahlist);
525  /* This sample rate will adjust as necessary when writing to the list. */
527  }
528 
529  /* Drop into respective list */
530  if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
531  AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
532  } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
533  AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
534  } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
536  }
537 
538  /*
539  * Initialize the audiohook's rate to the default. If it needs to be,
540  * it will get updated later.
541  */
544 
545  /* Change status over to running since it is now attached */
547 
548  if (ast_channel_is_bridged(chan)) {
550  }
551 
552  ast_channel_unlock(chan);
553 
554  return 0;
555 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
struct ast_audiohook_list::@344 manipulate_list
enum ast_audiohook_type type
Definition: audiohook.h:106
int list_internal_samp_rate
Definition: audiohook.c:61
#define ast_test_flag(p, flag)
Definition: utils.h:63
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
struct ast_audiohook_list::@342 spy_list
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
Definition: audiohook.c:70
void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value)
Variant of ast_channel_set_unbridged. Use this if the channel is already locked prior to calling...
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10746
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
struct ast_audiohook_list::@343 whisper_list
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
static void audiohook_list_set_samplerate_compatibility(struct ast_audiohook_list *audiohook_list)
Definition: audiohook.c:468
#define DEFAULT_INTERNAL_SAMPLE_RATE
Definition: audiohook.c:48

◆ ast_audiohook_destroy()

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

134 {
135  /* Drop the factories used by this audiohook type */
136  switch (audiohook->type) {
141  break;
142  default:
143  break;
144  }
145 
146  /* Destroy translation path if present */
147  if (audiohook->trans_pvt)
149 
150  ao2_cleanup(audiohook->format);
151 
152  /* Lock and trigger be gone! */
153  ast_cond_destroy(&audiohook->trigger);
154  ast_mutex_destroy(&audiohook->lock);
155 
156  return 0;
157 }
struct ast_slinfactory write_factory
Definition: audiohook.h:112
enum ast_audiohook_type type
Definition: audiohook.h:106
ast_mutex_t lock
Definition: audiohook.h:104
struct ast_format * format
Definition: audiohook.h:115
struct ast_trans_pvt * trans_pvt
Definition: audiohook.h:116
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
Definition: slinfactory.c:58
#define ast_cond_destroy(cond)
Definition: lock.h:200
ast_cond_t trigger
Definition: audiohook.h:105
struct ast_slinfactory read_factory
Definition: audiohook.h:111
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_mutex_destroy(a)
Definition: lock.h:186
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
Definition: translate.c:475

◆ ast_audiohook_detach()

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

580 {
581  if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
582  return 0;
583  }
584 
586 
587  while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
588  ast_audiohook_trigger_wait(audiohook);
589  }
590 
591  return 0;
592 }
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
Definition: audiohook.c:1142
enum ast_audiohook_status status
Definition: audiohook.h:107

◆ ast_audiohook_detach_list()

void ast_audiohook_detach_list ( struct ast_audiohook_list audiohook_list)

Detach audiohooks from list and destroy said list.

Parameters
audiohook_listList of audiohooks (NULL tolerant)
Returns
Nothing

Definition at line 594 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_stream(), and destroy_hooks().

595 {
596  int i;
597  struct ast_audiohook *audiohook;
598 
599  if (!audiohook_list) {
600  return;
601  }
602 
603  /* Drop any spies */
604  while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
606  }
607 
608  /* Drop any whispering sources */
609  while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
611  }
612 
613  /* Drop any manipulaters */
614  while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
616  audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
617  }
618 
619  /* Drop translation paths if present */
620  for (i = 0; i < 2; i++) {
621  if (audiohook_list->in_translate[i].trans_pvt) {
622  ast_translator_free_path(audiohook_list->in_translate[i].trans_pvt);
623  ao2_cleanup(audiohook_list->in_translate[i].format);
624  }
625  if (audiohook_list->out_translate[i].trans_pvt) {
627  ao2_cleanup(audiohook_list->in_translate[i].format);
628  }
629  }
630 
631  /* Free ourselves */
632  ast_free(audiohook_list);
633 }
struct ast_audiohook_list::@344 manipulate_list
struct ast_format * format
Definition: audiohook.c:52
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
struct ast_audiohook_translate out_translate[2]
Definition: audiohook.c:64
struct ast_trans_pvt * trans_pvt
Definition: audiohook.c:51
struct ast_audiohook_list::@342 spy_list
#define NULL
Definition: resample.c:96
ast_audiohook_manipulate_callback manipulate_callback
Definition: audiohook.h:117
struct ast_audiohook::@225 list
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182
struct ast_audiohook_translate in_translate[2]
Definition: audiohook.c:63
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_audiohook_list::@343 whisper_list
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
Definition: translate.c:475

◆ ast_audiohook_detach_source()

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

732 {
733  struct ast_audiohook *audiohook = NULL;
734 
735  ast_channel_lock(chan);
736 
737  /* Ensure the channel has audiohooks on it */
738  if (!ast_channel_audiohooks(chan)) {
739  ast_channel_unlock(chan);
740  return -1;
741  }
742 
744 
745  ast_channel_unlock(chan);
746 
747  if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
749  }
750 
751  return (audiohook ? 0 : -1);
752 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
#define NULL
Definition: resample.c:96
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
Definition: audiohook.c:640
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * source
Definition: audiohook.h:109
enum ast_audiohook_status status
Definition: audiohook.h:107
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)

◆ ast_audiohook_init()

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
audiohookAudiohook structure
typeType of audiohook to initialize this as
sourceWho is initializing this audiohook
initflags
Returns
Returns 0 on success, -1 on failure
Parameters
audiohookAudiohook structure
type
source,init_flags
Returns
Returns 0 on success, -1 on failure

Definition at line 108 of file audiohook.c.

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

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

109 {
110  /* Need to keep the type and source */
111  audiohook->type = type;
112  audiohook->source = source;
113 
114  /* Initialize lock that protects our audiohook */
115  ast_mutex_init(&audiohook->lock);
116  ast_cond_init(&audiohook->trigger, NULL);
117 
118  audiohook->init_flags = init_flags;
119 
120  /* initialize internal rate at 8khz, this will adjust if necessary */
122 
123  /* Since we are just starting out... this audiohook is new */
125 
126  return 0;
127 }
static const char type[]
Definition: chan_ooh323.c:109
enum ast_audiohook_type type
Definition: audiohook.h:106
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
#define ast_cond_init(cond, attr)
Definition: lock.h:199
ast_mutex_t lock
Definition: audiohook.h:104
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
Definition: audiohook.c:70
#define NULL
Definition: resample.c:96
enum ast_audiohook_init_flags init_flags
Definition: audiohook.h:108
const char * source
Definition: audiohook.h:109
ast_cond_t trigger
Definition: audiohook.h:105
#define ast_mutex_init(pmutex)
Definition: lock.h:184
#define DEFAULT_INTERNAL_SAMPLE_RATE
Definition: audiohook.c:48

◆ ast_audiohook_move_all()

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_chanThe source of the audiohooks being moved
new_chanThe destination channel for the audiohooks to be moved to

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

701 {
702  struct ast_audiohook *audiohook;
703  struct ast_audiohook_list *audiohook_list;
704 
705  audiohook_list = ast_channel_audiohooks(old_chan);
706  if (!audiohook_list) {
707  return;
708  }
709 
710  AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
711  audiohook_move(old_chan, new_chan, audiohook);
712  }
714 
715  AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
716  audiohook_move(old_chan, new_chan, audiohook);
717  }
719 
720  AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
721  audiohook_move(old_chan, new_chan, audiohook);
722  }
724 }
struct ast_audiohook_list::@344 manipulate_list
struct ast_audiohook_list::@342 spy_list
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
Definition: audiohook.c:665
struct ast_audiohook_list::@343 whisper_list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)

◆ ast_audiohook_move_by_source()

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

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

685 {
686  struct ast_audiohook *audiohook;
687 
688  if (!ast_channel_audiohooks(old_chan)) {
689  return;
690  }
691 
693  if (!audiohook) {
694  return;
695  }
696 
697  audiohook_move(old_chan, new_chan, audiohook);
698 }
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
Definition: audiohook.c:640
const char * source
Definition: audiohook.h:109
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
Definition: audiohook.c:665
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)

◆ ast_audiohook_read_frame()

struct ast_frame* ast_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.

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
Parameters
audiohookAudiohook structure
samplesNumber of samples wanted in requested output format
directionDirection the audio frame came from
formatFormat of frame remote side wants back
Returns
Returns frame on success, NULL on failure

Definition at line 449 of file audiohook.c.

References audiohook_read_frame_helper(), and NULL.

Referenced by snoop_read(), and spy_generate().

450 {
451  return audiohook_read_frame_helper(audiohook, samples, direction, format, NULL, NULL);
452 }
#define NULL
Definition: resample.c:96
static struct ast_frame * audiohook_read_frame_helper(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format, struct ast_frame **read_reference, struct ast_frame **write_reference)
Definition: audiohook.c:380
direction

◆ ast_audiohook_read_frame_all()

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 
)

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

Parameters
audiohookAudiohook structure
samplesNumber of samples wanted
ast_formatFormat of frame remote side wants back
read_frameif available, we'll copy the read buffer to this.
write_frameif 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
audiohookAudiohook structure
samplesNumber of samples wanted
directionDirection the audio frame came from
formatFormat of frame remote side wants back
read_frameframe pointer for copying read frame data
write_frameframe pointer for copying write frame data
Returns
Returns frame on success, NULL on failure

Definition at line 463 of file audiohook.c.

References AST_AUDIOHOOK_DIRECTION_BOTH, and audiohook_read_frame_helper().

Referenced by mixmonitor_thread().

464 {
465  return audiohook_read_frame_helper(audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, format, read_frame, write_frame);
466 }
static struct ast_frame * audiohook_read_frame_helper(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction, struct ast_format *format, struct ast_frame **read_reference, struct ast_frame **write_reference)
Definition: audiohook.c:380

◆ ast_audiohook_remove()

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 764 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, and ast_audiohook::type.

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

765 {
766  ast_channel_lock(chan);
767 
768  if (!ast_channel_audiohooks(chan)) {
769  ast_channel_unlock(chan);
770  return -1;
771  }
772 
773  if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
774  AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
775  } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
776  AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
777  } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
778  AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
779  }
780 
783 
784  if (ast_channel_is_bridged(chan)) {
786  }
787 
788  ast_channel_unlock(chan);
789 
790  return 0;
791 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
enum ast_audiohook_type type
Definition: audiohook.h:106
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook&#39;s status.
Definition: audiohook.c:565
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:855
struct ast_audiohook::@225 list
void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value)
Variant of ast_channel_set_unbridged. Use this if the channel is already locked prior to calling...
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10746
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
static void audiohook_list_set_samplerate_compatibility(struct ast_audiohook_list *audiohook_list)
Definition: audiohook.c:468

◆ ast_audiohook_set_mute()

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
chanChannel to muck with
sourceType of audiohook
flagwhich direction to set / clear
clearset or clear muted frames on direction based on flag parameter
Return values
0success
-1failure
Parameters
chanChannel to muck with
sourceType of audiohook
flagwhich flag to set / clear
clearset or clear
Returns
Returns 0 on success, -1 on failure

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

1425 {
1426  struct ast_audiohook *audiohook = NULL;
1427 
1428  ast_channel_lock(chan);
1429 
1430  /* Ensure the channel has audiohooks on it */
1431  if (!ast_channel_audiohooks(chan)) {
1432  ast_channel_unlock(chan);
1433  return -1;
1434  }
1435 
1437 
1438  if (audiohook) {
1439  if (clear) {
1440  ast_clear_flag(audiohook, flag);
1441  } else {
1442  ast_set_flag(audiohook, flag);
1443  }
1444  }
1445 
1446  ast_channel_unlock(chan);
1447 
1448  return (audiohook ? 0 : -1);
1449 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define NULL
Definition: resample.c:96
static struct ast_audiohook * find_audiohook_by_source(struct ast_audiohook_list *audiohook_list, const char *source)
find an audiohook based on its source
Definition: audiohook.c:640
long int flag
Definition: f2c.h:83
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * source
Definition: audiohook.h:109
#define ast_clear_flag(p, flag)
Definition: utils.h:77
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)

◆ ast_audiohook_trigger_wait()

void ast_audiohook_trigger_wait ( struct ast_audiohook audiohook)

Wait for audiohook trigger to be triggered.

Parameters
audiohookAudiohook to wait on

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

1143 {
1144  struct timeval wait;
1145  struct timespec ts;
1146 
1147  wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
1148  ts.tv_sec = wait.tv_sec;
1149  ts.tv_nsec = wait.tv_usec * 1000;
1150 
1151  ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
1152 
1153  return;
1154 }
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
ast_mutex_t lock
Definition: audiohook.h:104
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:238
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
ast_cond_t trigger
Definition: audiohook.h:105
#define ast_cond_timedwait(cond, mutex, time)
Definition: lock.h:204

◆ ast_audiohook_update_status()

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
audiohookAudiohook structure
statusAudiohook 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 565 of file audiohook.c.

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

566 {
567  ast_audiohook_lock(audiohook);
568  if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
569  audiohook->status = status;
570  ast_cond_signal(&audiohook->trigger);
571  }
572  ast_audiohook_unlock(audiohook);
573 }
#define ast_cond_signal(cond)
Definition: lock.h:201
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition: audiohook.h:300
ast_cond_t trigger
Definition: audiohook.h:105
enum ast_audiohook_status status
Definition: audiohook.h:107
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition: audiohook.h:295
jack_status_t status
Definition: app_jack.c:146

◆ ast_audiohook_volume_adjust()

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

1398 {
1400 
1401  /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
1402  if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
1403  return -1;
1404  }
1405 
1406  /* Based on the direction change the specific adjustment value */
1408  audiohook_volume->read_adjustment += volume;
1409  }
1411  audiohook_volume->write_adjustment += volume;
1412  }
1413 
1414  return 0;
1415 }
Audiohook volume adjustment structure.
Definition: audiohook.c:1231
static struct audiohook_volume * audiohook_volume_get(struct ast_channel *chan, int create)
Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a chann...
Definition: audiohook.c:1305
#define NULL
Definition: resample.c:96
direction

◆ ast_audiohook_volume_get()

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

1372 {
1374  int adjustment = 0;
1375 
1376  /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
1377  if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
1378  return 0;
1379  }
1380 
1381  /* Grab the adjustment value based on direction given */
1383  adjustment = audiohook_volume->read_adjustment;
1384  } else if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
1385  adjustment = audiohook_volume->write_adjustment;
1386  }
1387 
1388  return adjustment;
1389 }
Audiohook volume adjustment structure.
Definition: audiohook.c:1231
static struct audiohook_volume * audiohook_volume_get(struct ast_channel *chan, int create)
Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a chann...
Definition: audiohook.c:1305
#define NULL
Definition: resample.c:96
direction

◆ ast_audiohook_volume_set()

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

1347 {
1349 
1350  /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
1351  if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
1352  return -1;
1353  }
1354 
1355  /* Now based on the direction set the proper value */
1357  audiohook_volume->read_adjustment = volume;
1358  }
1360  audiohook_volume->write_adjustment = volume;
1361  }
1362 
1363  return 0;
1364 }
Audiohook volume adjustment structure.
Definition: audiohook.c:1231
static struct audiohook_volume * audiohook_volume_get(struct ast_channel *chan, int create)
Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a chann...
Definition: audiohook.c:1305
#define NULL
Definition: resample.c:96
direction

◆ ast_audiohook_write_frame()

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

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE, 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_slinfactory_available(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), 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().

171 {
172  struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
173  struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
174  struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
175  int our_factory_samples;
176  int our_factory_ms;
177  int other_factory_samples;
178  int other_factory_ms;
179 
180  /* Update last feeding time to be current */
181  *rwtime = ast_tvnow();
182 
183  our_factory_samples = ast_slinfactory_available(factory);
184  our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / (audiohook->hook_internal_samp_rate / 1000));
185  other_factory_samples = ast_slinfactory_available(other_factory);
186  other_factory_ms = other_factory_samples / (audiohook->hook_internal_samp_rate / 1000);
187 
188  if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
189  ast_debug(1, "Flushing audiohook %p so it remains in sync\n", audiohook);
190  ast_slinfactory_flush(factory);
191  ast_slinfactory_flush(other_factory);
192  }
193 
194  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))) {
195  ast_debug(1, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
196  ast_slinfactory_flush(factory);
197  ast_slinfactory_flush(other_factory);
198  } else if ((our_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE) || (other_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE)) {
199  ast_debug(1, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
200  ast_slinfactory_flush(factory);
201  ast_slinfactory_flush(other_factory);
202  }
203 
204  /* Write frame out to respective factory */
205  ast_slinfactory_feed(factory, frame);
206 
207  /* If we need to notify the respective handler of this audiohook, do so */
209  ast_cond_signal(&audiohook->trigger);
211  ast_cond_signal(&audiohook->trigger);
212  } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
213  ast_cond_signal(&audiohook->trigger);
214  }
215 
216  return 0;
217 }
struct ast_slinfactory write_factory
Definition: audiohook.h:112
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
Definition: slinfactory.c:204
#define ast_test_flag(p, flag)
Definition: utils.h:63
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
Definition: slinfactory.c:77
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define ast_cond_signal(cond)
Definition: lock.h:201
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
Definition: slinfactory.c:199
#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE
Definition: audiohook.c:46
#define AST_AUDIOHOOK_SYNC_TOLERANCE
Definition: audiohook.c:44
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
unsigned int hook_internal_samp_rate
Definition: audiohook.h:119
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE
Definition: audiohook.c:45
ast_cond_t trigger
Definition: audiohook.h:105
struct ast_slinfactory read_factory
Definition: audiohook.h:111
struct timeval write_time
Definition: audiohook.h:114
struct timeval read_time
Definition: audiohook.h:113
direction

◆ ast_audiohook_write_list()

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
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 1127 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_stream().

1128 {
1129  /* Pass off frame to it's respective list write function */
1130  if (frame->frametype == AST_FRAME_VOICE) {
1131  return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
1132  } else if (frame->frametype == AST_FRAME_DTMF) {
1133  return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
1134  } else {
1135  return frame;
1136  }
1137 }
static struct ast_frame * audio_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass an AUDIO frame off to be handled by the audiohook core.
Definition: audiohook.c:955
#define AST_FRAME_DTMF
static struct ast_frame * dtmf_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Pass a DTMF frame off to be handled by the audiohook core.
Definition: audiohook.c:800
enum ast_frame_type frametype
direction

◆ ast_audiohook_write_list_empty()

int ast_audiohook_write_list_empty ( struct ast_audiohook_list audiohook_list)

Determine if a audiohook_list is empty or not.

Parameters
audiohookAudiohook to check. (NULL also means empty)

retval 0 false, 1 true

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

1113 {
1114  return !audiohook_list
1115  || (AST_LIST_EMPTY(&audiohook_list->spy_list)
1116  && AST_LIST_EMPTY(&audiohook_list->whisper_list)
1117  && AST_LIST_EMPTY(&audiohook_list->manipulate_list));
1118 }
struct ast_audiohook_list::@344 manipulate_list
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
struct ast_audiohook_list::@342 spy_list
struct ast_audiohook_list::@343 whisper_list

◆ ast_channel_audiohook_count_by_source()

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 1157 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, NULL, and ast_audiohook::source.

Referenced by feature_automixmonitor().

1158 {
1159  int count = 0;
1160  struct ast_audiohook *ah = NULL;
1161 
1162  if (!ast_channel_audiohooks(chan)) {
1163  return -1;
1164  }
1165 
1166  switch (type) {
1168  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1169  if (!strcmp(ah->source, source)) {
1170  count++;
1171  }
1172  }
1173  break;
1175  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1176  if (!strcmp(ah->source, source)) {
1177  count++;
1178  }
1179  }
1180  break;
1182  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1183  if (!strcmp(ah->source, source)) {
1184  count++;
1185  }
1186  }
1187  break;
1188  default:
1189  ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1190  return -1;
1191  }
1192 
1193  return count;
1194 }
static const char type[]
Definition: chan_ooh323.c:109
#define NULL
Definition: resample.c:96
struct ast_audiohook::@225 list
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
const char * source
Definition: audiohook.h:109
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)

◆ ast_channel_audiohook_count_by_source_running()

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 1197 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, NULL, ast_audiohook::source, and ast_audiohook::status.

1198 {
1199  int count = 0;
1200  struct ast_audiohook *ah = NULL;
1201  if (!ast_channel_audiohooks(chan))
1202  return -1;
1203 
1204  switch (type) {
1206  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1207  if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1208  count++;
1209  }
1210  break;
1212  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1213  if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1214  count++;
1215  }
1216  break;
1218  AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1219  if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1220  count++;
1221  }
1222  break;
1223  default:
1224  ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1225  return -1;
1226  }
1227  return count;
1228 }
static const char type[]
Definition: chan_ooh323.c:109
#define NULL
Definition: resample.c:96
struct ast_audiohook::@225 list
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
const char * source
Definition: audiohook.h:109
enum ast_audiohook_status status
Definition: audiohook.h:107
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)