Asterisk - The Open Source Telephony Project GIT-master-57e2743
Loading...
Searching...
No Matches
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.
 
#define ast_audiohook_unlock(ah)   ast_mutex_unlock(&(ah)->lock)
 Unlock an audiohook.
 

Typedefs

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

Enumerations

enum  ast_audiohook_direction { AST_AUDIOHOOK_DIRECTION_READ = 0 , AST_AUDIOHOOK_DIRECTION_WRITE , AST_AUDIOHOOK_DIRECTION_BOTH }
 
enum  ast_audiohook_flags {
  AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0) , AST_AUDIOHOOK_TRIGGER_READ = (1 << 0) , AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0) , AST_AUDIOHOOK_WANTS_DTMF = (1 << 2) ,
  AST_AUDIOHOOK_TRIGGER_SYNC = (1 << 3) , AST_AUDIOHOOK_SMALL_QUEUE = (1 << 4) , AST_AUDIOHOOK_MUTE_READ = (1 << 5) , AST_AUDIOHOOK_MUTE_WRITE = (1 << 6) ,
  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.
 
int ast_audiohook_destroy (struct ast_audiohook *audiohook)
 Destroys an audiohook structure.
 
int ast_audiohook_detach (struct ast_audiohook *audiohook)
 Detach audiohook from channel.
 
void ast_audiohook_detach_list (struct ast_audiohook_list *audiohook_list)
 Detach audiohooks from list and destroy said list.
 
int ast_audiohook_detach_source (struct ast_channel *chan, const char *source)
 Detach specified source audiohook from channel.
 
int ast_audiohook_init (struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
 Initialize an audiohook structure.
 
void ast_audiohook_move_all (struct ast_channel *old_chan, struct ast_channel *new_chan)
 Move all audiohooks from one channel to another.
 
void ast_audiohook_move_by_source (struct ast_channel *old_chan, struct ast_channel *new_chan, const char *source)
 Move an audiohook from one channel to a new one.
 
struct ast_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.
 
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.
 
int ast_audiohook_remove (struct ast_channel *chan, struct ast_audiohook *audiohook)
 Remove an audiohook from a specified channel.
 
int ast_audiohook_set_frame_feed_direction (struct ast_audiohook *audiohook, enum ast_audiohook_direction direction)
 Sets direction on audiohook.
 
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.
 
int ast_audiohook_set_mute_all (struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clear)
 Mute frames read from or written for all audiohooks on a channel.
 
void ast_audiohook_trigger_wait (struct ast_audiohook *audiohook)
 Wait for audiohook trigger to be triggered.
 
void ast_audiohook_update_status (struct ast_audiohook *audiohook, enum ast_audiohook_status status)
 Update audiohook's status.
 
int ast_audiohook_volume_adjust (struct ast_channel *chan, enum ast_audiohook_direction direction, int volume)
 Adjust the volume on frames read from or written to a channel.
 
int ast_audiohook_volume_adjust_float (struct ast_channel *chan, enum ast_audiohook_direction direction, float 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.
 
float ast_audiohook_volume_get_float (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_volume_set_float (struct ast_channel *chan, enum ast_audiohook_direction direction, float 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_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.
 
int ast_audiohook_write_list_empty (struct ast_audiohook_list *audiohook_list)
 Determine if a audiohook_list is empty or not.
 
int ast_channel_audiohook_count_by_source (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many audiohooks from a certain source exist on a given channel, regardless of status.
 
int ast_channel_audiohook_count_by_source_running (struct ast_channel *chan, const char *source, enum ast_audiohook_type type)
 Find out how many spies of a certain type exist on a given channel, and are in state running.
 

Detailed Description

Audiohooks Architecture.

Definition in file audiohook.h.

Macro Definition Documentation

◆ ast_audiohook_lock

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

Lock an audiohook.

Parameters
ahAudiohook structure

Definition at line 316 of file audiohook.h.

◆ ast_audiohook_unlock

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

Unlock an audiohook.

Parameters
ahAudiohook structure

Definition at line 321 of file audiohook.h.

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
audiohook
chan
frameFrame of audio to manipulate
directionDirection frame came from
Return values
0on success
-1on 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 97 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_DIRECTION_READ
Definition audiohook.h:49
@ AST_AUDIOHOOK_DIRECTION_WRITE
Definition audiohook.h:50
@ AST_AUDIOHOOK_DIRECTION_BOTH
Definition audiohook.h:51

◆ 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 */
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_COMPATIBLE
Definition audiohook.h:66
@ AST_AUDIOHOOK_WANTS_DTMF
Definition audiohook.h:58
@ AST_AUDIOHOOK_TRIGGER_MODE
Definition audiohook.h:55
@ AST_AUDIOHOOK_MUTE_READ
Definition audiohook.h:64
@ AST_AUDIOHOOK_MUTE_WRITE
Definition audiohook.h:65
@ AST_AUDIOHOOK_SUBSTITUTE_SILENCE
Definition audiohook.h:68
@ AST_AUDIOHOOK_SMALL_QUEUE
Definition audiohook.h:63
@ AST_AUDIOHOOK_TRIGGER_READ
Definition audiohook.h:56
@ AST_AUDIOHOOK_TRIGGER_WRITE
Definition audiohook.h:57
@ AST_AUDIOHOOK_TRIGGER_SYNC
Definition audiohook.h:59

◆ 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_MANIPULATE_ALL_RATES
Definition audiohook.h:75

◆ 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_STATUS_DONE
Definition audiohook.h:45
@ AST_AUDIOHOOK_STATUS_NEW
Definition audiohook.h:42
@ AST_AUDIOHOOK_STATUS_RUNNING
Definition audiohook.h:43
@ AST_AUDIOHOOK_STATUS_SHUTDOWN
Definition audiohook.h:44

◆ 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};
@ AST_AUDIOHOOK_TYPE_MANIPULATE
Definition audiohook.h:38
@ AST_AUDIOHOOK_TYPE_SPY
Definition audiohook.h:36
@ AST_AUDIOHOOK_TYPE_WHISPER
Definition audiohook.h:37

Function Documentation

◆ ast_audiohook_attach()

int ast_audiohook_attach ( struct ast_channel *  chan,
struct ast_audiohook *  audiohook 
)

Attach audiohook to channel.

Parameters
chan
audiohook
Returns
0 on success
Return values
-1on failure

Definition at line 819 of file audiohook.c.

820{
821 ast_channel_lock(chan);
822
823 /* Don't allow an audiohook to be attached to a channel that is already hung up.
824 * The hang up process is what actually notifies the audiohook that it should
825 * stop.
826 */
828 ast_channel_unlock(chan);
829 return -1;
830 }
831
832 if (!ast_channel_audiohooks(chan)) {
833 struct ast_audiohook_list *ahlist;
834 /* Whoops... allocate a new structure */
835 if (!(ahlist = ast_calloc(1, sizeof(*ahlist)))) {
836 ast_channel_unlock(chan);
837 return -1;
838 }
839 ast_channel_audiohooks_set(chan, ahlist);
843 /* This sample rate will adjust as necessary when writing to the list. */
846 }
847
848 /* Drop into respective list */
849 if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
850 AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
851 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
852 int was_empty = AST_LIST_EMPTY(&ast_channel_audiohooks(chan)->whisper_list);
854 /* Only attach the framehook on the first whisper audiohook */
855 if (was_empty) {
857 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
858 ast_channel_unlock(chan);
859 return -1;
860 }
861 }
862 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
864 }
865
866 /*
867 * Initialize the audiohook's rate to the default. If it needs to be,
868 * it will get updated later.
869 */
872
873 /* Change status over to running since it is now attached */
875
876 if (ast_channel_is_bridged(chan)) {
878 }
879
880 ast_channel_unlock(chan);
881
882 return 0;
883}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static void audiohook_list_set_samplerate_compatibility(struct ast_audiohook_list *audiohook_list)
Definition audiohook.c:791
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
Definition audiohook.c:885
static int whisper_framehook_attach(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list)
Definition audiohook.c:316
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
Definition audiohook.c:368
#define DEFAULT_INTERNAL_SAMPLE_RATE
Definition audiohook.c:57
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_channel_lock(chan)
Definition channel.h:2983
@ AST_FLAG_ZOMBIE
Definition channel.h:1007
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value)
struct ast_audiohook_list * ast_channel_audiohooks(const struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition channel.c:10725
#define ast_channel_unlock(chan)
Definition channel.h:2984
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
struct ast_audiohook_list::@322 spy_list
int list_internal_samp_rate
Definition audiohook.c:78
struct ast_audiohook_list::@323 whisper_list
struct ast_audiohook_list::@324 manipulate_list
enum ast_audiohook_type type
Definition audiohook.h:107
#define ast_test_flag(p, flag)
Definition utils.h:64

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_EMPTY, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE, 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, whisper_framehook_attach(), ast_audiohook_list::whisper_framehook_id, 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(), start_spying(), start_whispering(), start_whispering(), startmon(), and volume_write().

◆ ast_audiohook_destroy()

int ast_audiohook_destroy ( struct ast_audiohook *  audiohook)

Destroys an audiohook structure.

Parameters
audiohook
Return values
0on success
-1on failure

Definition at line 422 of file audiohook.c.

423{
424 /* Drop the factories used by this audiohook type */
425 switch (audiohook->type) {
430 break;
431 default:
432 break;
433 }
434
435 /* Destroy translation path if present */
436 if (audiohook->trans_pvt)
438
439 ao2_cleanup(audiohook->format);
440
441 /* Lock and trigger be gone! */
442 ast_cond_destroy(&audiohook->trigger);
443 ast_mutex_destroy(&audiohook->lock);
444
445 return 0;
446}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ast_cond_destroy(cond)
Definition lock.h:209
#define ast_mutex_destroy(a)
Definition lock.h:195
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
Destroy the contents of a slinfactory.
Definition slinfactory.c:58
ast_cond_t trigger
Definition audiohook.h:106
struct ast_slinfactory read_factory
Definition audiohook.h:112
struct ast_trans_pvt * trans_pvt
Definition audiohook.h:117
struct ast_format * format
Definition audiohook.h:116
ast_mutex_t lock
Definition audiohook.h:105
struct ast_slinfactory write_factory
Definition audiohook.h:113
void ast_translator_free_path(struct ast_trans_pvt *tr)
Frees a translator path Frees the given translator path structure.
Definition translate.c:533

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_callback(), destroy_callback(), destroy_callback(), destroy_callback(), destroy_jack_data(), destroy_monitor_audiohook(), hook_datastore_destroy_callback(), launch_monitor_thread(), mixmonitor_thread(), multi_autochan_free(), and snoop_destroy().

◆ ast_audiohook_detach()

int ast_audiohook_detach ( struct ast_audiohook *  audiohook)

Detach audiohook from channel.

Parameters
audiohook
Returns
Returns 0 on success, -1 on failure

Definition at line 895 of file audiohook.c.

896{
897 if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
898 return 0;
899 }
900
902
903 while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
905 }
906
907 return 0;
908}
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
Definition audiohook.c:1462
enum ast_audiohook_status status
Definition audiohook.h:108

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_callback(), destroy_callback(), destroy_monitor_audiohook(), disable_jack_hook(), hook_datastore_destroy_callback(), multi_autochan_free(), snoop_hangup(), and speex_write().

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

Definition at line 910 of file audiohook.c.

911{
912 int i;
913 struct ast_audiohook *audiohook;
914
915 if (!audiohook_list) {
916 return;
917 }
918
919 /* Drop any spies */
920 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
922 }
923
924 /* Drop any whispering sources */
925 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
927 }
928
929 /* Drop any manipulators */
930 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
932 audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
933 }
934
935 /* Drop translation paths if present */
936 for (i = 0; i < 2; i++) {
937 if (audiohook_list->in_translate[i].trans_pvt) {
939 ao2_cleanup(audiohook_list->in_translate[i].format);
940 }
941 if (audiohook_list->out_translate[i].trans_pvt) {
943 ao2_cleanup(audiohook_list->out_translate[i].format);
944 }
945 }
946
947 /* Free ourselves */
948 ast_free(audiohook_list);
949}
#define ast_free(a)
Definition astmm.h:180
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define NULL
Definition resample.c:96
struct ast_audiohook_translate out_translate[2]
Definition audiohook.c:81
struct ast_audiohook_translate in_translate[2]
Definition audiohook.c:80
struct ast_trans_pvt * trans_pvt
Definition audiohook.c:60
struct ast_format * format
Definition audiohook.c:61
ast_audiohook_manipulate_callback manipulate_callback
Definition audiohook.h:118
struct ast_audiohook::@196 list

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

◆ 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
Return values
0on success
-1on failure
Note
The channel does not need to be locked before calling this function.

Definition at line 1051 of file audiohook.c.

1052{
1053 struct ast_audiohook *audiohook = NULL;
1054
1055 ast_channel_lock(chan);
1056
1057 /* Ensure the channel has audiohooks on it */
1058 if (!ast_channel_audiohooks(chan)) {
1059 ast_channel_unlock(chan);
1060 return -1;
1061 }
1062
1064
1065 ast_channel_unlock(chan);
1066
1067 if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
1069 }
1070
1071 return (audiohook ? 0 : -1);
1072}
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:957
const char * source
Definition audiohook.h:110

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

◆ ast_audiohook_init()

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.

Parameters
audiohook
typeType of audiohook to initialize this as
sourceWho is initializing this audiohook
flags
Return values
0on success
-1on failure

Definition at line 398 of file audiohook.c.

399{
400 /* Need to keep the type and source */
401 audiohook->type = type;
402 audiohook->source = source;
403
404 /* Initialize lock that protects our audiohook */
405 ast_mutex_init(&audiohook->lock);
406 ast_cond_init(&audiohook->trigger, NULL);
407
408 audiohook->init_flags = init_flags;
409
410 /* Set direction to BOTH so that we feed frames in both directions */
412
413 /* initialize internal rate at 8khz, this will adjust if necessary */
415
416 /* Since we are just starting out... this audiohook is new */
418
419 return 0;
420}
static const char type[]
#define ast_cond_init(cond, attr)
Definition lock.h:208
#define ast_mutex_init(pmutex)
Definition lock.h:193
enum ast_audiohook_init_flags init_flags
Definition audiohook.h:109
enum ast_audiohook_direction direction
Definition audiohook.h:121

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

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

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

1026{
1027 struct ast_audiohook *audiohook;
1028 struct ast_audiohook_list *audiohook_list;
1029
1030 audiohook_list = ast_channel_audiohooks(old_chan);
1031 if (!audiohook_list) {
1032 return;
1033 }
1034
1035 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
1036 audiohook_move(old_chan, new_chan, audiohook);
1037 }
1039
1040 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
1041 audiohook_move(old_chan, new_chan, audiohook);
1042 }
1044
1045 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
1046 audiohook_move(old_chan, new_chan, audiohook);
1047 }
1049}
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
Definition audiohook.c:982
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.

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

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

1010{
1011 struct ast_audiohook *audiohook;
1012
1013 if (!ast_channel_audiohooks(old_chan)) {
1014 return;
1015 }
1016
1018 if (!audiohook) {
1019 return;
1020 }
1021
1022 audiohook_move(old_chan, new_chan, audiohook);
1023}

References ast_channel_audiohooks(), audiohook_move(), find_audiohook_by_source(), and ast_audiohook::source.

◆ 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
audiohook
samplesNumber of samples wanted
directionDirection the audio frame came from
formatFormat of frame remote side wants back
Returns
frame on success
Return values
NULLon failure

Definition at line 781 of file audiohook.c.

782{
783 return audiohook_read_frame_helper(audiohook, samples, direction, format, NULL, NULL);
784}
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:719
direction

References audiohook_read_frame_helper(), NULL, and ast_frame::samples.

Referenced by snoop_read(), spy_generate(), and spy_generate().

◆ 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
audiohook
samplesNumber of samples wanted
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.
Returns
frame on success
Return values
NULLon failure
Note
The read_frame and write_frame may be in a different format from what was specified in format depending on the sample rate of the hooked channel's codec - ie; if we are requesting slin, but are hooked on channel using a 16K codec like g722, the read and write frames will be slin16.

Definition at line 786 of file audiohook.c.

787{
788 return audiohook_read_frame_helper(audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, format, read_frame, write_frame);
789}
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
Definition file.c:1000

References AST_AUDIOHOOK_DIRECTION_BOTH, audiohook_read_frame_helper(), read_frame(), and ast_frame::samples.

Referenced by mixmonitor_thread(), and spy_generate().

◆ 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
Return values
0on success
-1on failure
Note
The channel does not need to be locked before calling this function

Definition at line 1074 of file audiohook.c.

1075{
1076 ast_channel_lock(chan);
1077
1078 if (!ast_channel_audiohooks(chan)) {
1079 ast_channel_unlock(chan);
1080 return -1;
1081 }
1082
1083 if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
1084 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
1085 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
1086 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
1087 /* Detach the framehook if this was the last whisper audiohook */
1088 if (AST_LIST_EMPTY(&ast_channel_audiohooks(chan)->whisper_list)) {
1090 }
1091 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
1092 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
1093 }
1094
1097
1098 if (ast_channel_is_bridged(chan)) {
1100 }
1101
1102 ast_channel_unlock(chan);
1103
1104 return 0;
1105}
static void whisper_framehook_detach(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list)
Definition audiohook.c:355

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_EMPTY, AST_LIST_REMOVE, audiohook_list_set_samplerate_compatibility(), ast_audiohook::list, ast_audiohook::type, and whisper_framehook_detach().

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

◆ ast_audiohook_set_frame_feed_direction()

int ast_audiohook_set_frame_feed_direction ( struct ast_audiohook *  audiohook,
enum ast_audiohook_direction  direction 
)

Sets direction on audiohook.

Parameters
audiohook
directionIn which direction should the audiohook feed frames, ie if we are snooping 'in', set direction to READ so that only the 'in' frames are fed to the slin factory
Return values
0on success
-1on failure due to audiohook already in use or in shutdown. Can only set direction on NEW audiohooks

Definition at line 448 of file audiohook.c.

449{
450 /* Only set the direction on new audiohooks */
451 if (audiohook->status != AST_AUDIOHOOK_STATUS_NEW) {
452 ast_debug(3, "Can not set direction on attached Audiohook %p\n", audiohook);
453 return -1;
454 }
455
456 audiohook->direction = direction;
457 return 0;
458}
#define ast_debug(level,...)
Log a DEBUG message.

References AST_AUDIOHOOK_STATUS_NEW, ast_debug, ast_audiohook::direction, and ast_audiohook::status.

Referenced by snoop_setup_audiohook(), start_spying(), and start_spying().

◆ 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

Definition at line 1736 of file audiohook.c.

1737{
1738 struct ast_audiohook *audiohook = NULL;
1739
1740 ast_channel_lock(chan);
1741
1742 /* Ensure the channel has audiohooks on it */
1743 if (!ast_channel_audiohooks(chan)) {
1744 ast_channel_unlock(chan);
1745 return -1;
1746 }
1747
1749
1750 if (audiohook) {
1751 if (clear) {
1752 ast_clear_flag(audiohook, flag);
1753 } else {
1754 ast_set_flag(audiohook, flag);
1755 }
1756 }
1757
1758 ast_channel_unlock(chan);
1759
1760 return (audiohook ? 0 : -1);
1761}
long int flag
Definition f2c.h:83
#define ast_clear_flag(p, flag)
Definition utils.h:78
#define ast_set_flag(p, flag)
Definition utils.h:71

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

◆ ast_audiohook_set_mute_all()

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

Mute frames read from or written for all audiohooks on a channel.

Parameters
chanChannel to muck with
sourceType of audiohooks
flagwhich direction to set / clear
clearset or clear muted frames on direction based on flag parameter
Return values
>=0number of muted audiohooks
-1failure

Definition at line 1763 of file audiohook.c.

1764{
1765 struct ast_audiohook *audiohook = NULL;
1766 int count = 0;
1767
1768 ast_channel_lock(chan);
1769
1770 if (!ast_channel_audiohooks(chan)) {
1771 ast_channel_unlock(chan);
1772 return -1;
1773 }
1774
1775 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list) {
1776 if (!strcasecmp(audiohook->source, source)) {
1777 count++;
1778 if (clearmute) {
1779 ast_clear_flag(audiohook, flag);
1780 } else {
1781 ast_set_flag(audiohook, flag);
1782 }
1783 }
1784 }
1785
1786 ast_test_suite_event_notify("AUDIOHOOK_GROUP_MUTE_TOGGLE", "Channel: %s\r\nSource: %s\r\nCount: %d\r\n",
1787 ast_channel_name(chan), source, count);
1788
1789 ast_channel_unlock(chan);
1790
1791 return count;
1792}
const char * ast_channel_name(const struct ast_channel *chan)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define ast_test_suite_event_notify(s, f,...)
Definition test.h:189

References ast_channel_audiohooks(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_clear_flag, AST_LIST_TRAVERSE, ast_set_flag, ast_test_suite_event_notify, ast_audiohook::list, NULL, and ast_audiohook::source.

Referenced by manager_mute_mixmonitor().

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

1463{
1464 struct timeval wait;
1465 struct timespec ts;
1466
1467 wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
1468 ts.tv_sec = wait.tv_sec;
1469 ts.tv_nsec = wait.tv_usec * 1000;
1470
1471 ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
1472
1473 return;
1474}
#define ast_cond_timedwait(cond, mutex, time)
Definition lock.h:213
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:282
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition extconf.c:2278
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

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

◆ ast_audiohook_update_status()

void ast_audiohook_update_status ( struct ast_audiohook *  audiohook,
enum ast_audiohook_status  status 
)

Update audiohook's status.

Parameters
audiohook
status
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 885 of file audiohook.c.

886{
887 ast_audiohook_lock(audiohook);
888 if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
889 audiohook->status = status;
890 ast_cond_signal(&audiohook->trigger);
891 }
892 ast_audiohook_unlock(audiohook);
893}
jack_status_t status
Definition app_jack.c:149
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition audiohook.h:316
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition audiohook.h:321
#define ast_cond_signal(cond)
Definition lock.h:210

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(), dtmf_audiohook_write_list(), and stop_mixmonitor_full().

◆ 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
Return values
0on success
-1on failure
Since
1.6.1

Definition at line 1711 of file audiohook.c.

1712{
1713 return ast_audiohook_volume_adjust_float(chan, direction, (float) volume);
1714}
int ast_audiohook_volume_adjust_float(struct ast_channel *chan, enum ast_audiohook_direction direction, float volume)
Adjust the volume on frames read from or written to a channel.
Definition audiohook.c:1716

References ast_audiohook_volume_adjust_float().

Referenced by execute_menu_entry().

◆ ast_audiohook_volume_adjust_float()

int ast_audiohook_volume_adjust_float ( struct ast_channel *  chan,
enum ast_audiohook_direction  direction,
float  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
Return values
0on success
-1on failure

Definition at line 1716 of file audiohook.c.

1717{
1719
1720 /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
1721 if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
1722 return -1;
1723 }
1724
1725 /* Based on the direction change the specific adjustment value */
1728 }
1731 }
1732
1733 return 0;
1734}
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:1626
Audiohook volume adjustment structure.
Definition audiohook.c:1551

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 ast_audiohook_volume_adjust(), and ast_audiohook_volume_set().

◆ 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
adjustment value
Since
1.6.1

Definition at line 1686 of file audiohook.c.

1687{
1688 return (int) ast_audiohook_volume_get_float(chan, direction);
1689}
float ast_audiohook_volume_get_float(struct ast_channel *chan, enum ast_audiohook_direction direction)
Retrieve the volume adjustment value on frames read from or written to a channel.
Definition audiohook.c:1691

References ast_audiohook_volume_get_float().

Referenced by confbridge_exec().

◆ ast_audiohook_volume_get_float()

float ast_audiohook_volume_get_float ( 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
adjustment value

Definition at line 1691 of file audiohook.c.

1692{
1694 float adjustment = 0;
1695
1696 /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
1697 if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
1698 return 0;
1699 }
1700
1701 /* Grab the adjustment value based on direction given */
1703 adjustment = audiohook_volume->read_adjustment;
1705 adjustment = audiohook_volume->write_adjustment;
1706 }
1707
1708 return adjustment;
1709}

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

Referenced by ast_audiohook_volume_get().

◆ 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
Return values
0on success
-1on failure
Since
1.6.1

Definition at line 1661 of file audiohook.c.

1662{
1663 return ast_audiohook_volume_adjust_float(chan, direction, (float) volume);
1664}

References ast_audiohook_volume_adjust_float().

Referenced by confbridge_exec(), and execute_menu_entry().

◆ ast_audiohook_volume_set_float()

int ast_audiohook_volume_set_float ( struct ast_channel *  chan,
enum ast_audiohook_direction  direction,
float  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
Return values
0on success
-1on failure

Definition at line 1666 of file audiohook.c.

1667{
1669
1670 /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
1671 if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
1672 return -1;
1673 }
1674
1675 /* Now based on the direction set the proper value */
1678 }
1681 }
1682
1683 return 0;
1684}

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.

◆ 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
audiohook
directionDirection the audio frame came from
frameFrame to write in
Return values
0on success
-1on failure

Definition at line 465 of file audiohook.c.

466{
467 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
468 struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
469 struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
470 int our_factory_samples;
471 int our_factory_ms;
472 int other_factory_samples;
473 int other_factory_ms;
474
475 /* Don't feed the frame if we are set to read and this is a write frame or if set to
476 write and this is a read frame as we don't want it. Plus, it can cause mis-resampling
477 if the READ and WRITE frames have different bitrates */
478 if (audiohook->direction != AST_AUDIOHOOK_DIRECTION_BOTH && audiohook->direction != direction) {
479 return 0;
480 }
481
482 /* Update last feeding time to be current */
483 *rwtime = ast_tvnow();
484
485 our_factory_samples = ast_slinfactory_available(factory);
486 our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / (audiohook->hook_internal_samp_rate / 1000));
487 other_factory_samples = ast_slinfactory_available(other_factory);
488 other_factory_ms = other_factory_samples / (audiohook->hook_internal_samp_rate / 1000);
489
490 if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
491 ast_debug(4, "Flushing audiohook %p so it remains in sync\n", audiohook);
492 ast_slinfactory_flush(factory);
493 ast_slinfactory_flush(other_factory);
494 }
495
496 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))) {
497 ast_debug(4, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
498 ast_slinfactory_flush(factory);
499 ast_slinfactory_flush(other_factory);
500 } else if ((our_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE) || (other_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE)) {
501 ast_debug(4, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
502 ast_slinfactory_flush(factory);
503 ast_slinfactory_flush(other_factory);
504 }
505
506 /* Write frame out to respective factory */
507 ast_slinfactory_feed(factory, frame);
508
509 /* If we need to notify the respective handler of this audiohook, do so */
511 ast_cond_signal(&audiohook->trigger);
513 ast_cond_signal(&audiohook->trigger);
514 } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
515 ast_cond_signal(&audiohook->trigger);
516 }
517
518 return 0;
519}
#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE
Definition audiohook.c:48
#define AST_AUDIOHOOK_SYNC_TOLERANCE
Definition audiohook.c:46
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE
Definition audiohook.c:47
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
Feed audio into a slinfactory.
Definition slinfactory.c:77
struct timeval write_time
Definition audiohook.h:115
struct timeval read_time
Definition audiohook.h:114
unsigned int hook_internal_samp_rate
Definition audiohook.h:120
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107

References AST_AUDIOHOOK_DIRECTION_BOTH, 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::direction, 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(), do_broadcast(), and snoop_write().

◆ 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
frame on success
Return values
NULLon failure

Definition at line 1447 of file audiohook.c.

1448{
1449 /* Pass off frame to it's respective list write function */
1450 if (frame->frametype == AST_FRAME_VOICE) {
1451 return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
1452 } else if (frame->frametype == AST_FRAME_DTMF) {
1453 return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
1454 } else {
1455 return frame;
1456 }
1457}
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:1271
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:1115
#define AST_FRAME_DTMF
enum ast_frame_type frametype

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

◆ 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
audiohook_listAudiohook to check. (NULL also means empty)
Return values
0false
1true

Definition at line 1439 of file audiohook.c.

1440{
1441 return !audiohook_list
1442 || (AST_LIST_EMPTY(&audiohook_list->spy_list)
1443 && AST_LIST_EMPTY(&audiohook_list->whisper_list)
1444 && AST_LIST_EMPTY(&audiohook_list->manipulate_list));
1445}

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

◆ 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
number of audiohooks which are from the source specified

Note: Function performs nlocking.

Definition at line 1477 of file audiohook.c.

1478{
1479 int count = 0;
1480 struct ast_audiohook *ah = NULL;
1481
1482 if (!ast_channel_audiohooks(chan)) {
1483 return -1;
1484 }
1485
1486 switch (type) {
1488 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1489 if (!strcmp(ah->source, source)) {
1490 count++;
1491 }
1492 }
1493 break;
1495 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1496 if (!strcmp(ah->source, source)) {
1497 count++;
1498 }
1499 }
1500 break;
1502 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1503 if (!strcmp(ah->source, source)) {
1504 count++;
1505 }
1506 }
1507 break;
1508 default:
1509 ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1510 return -1;
1511 }
1512
1513 return count;
1514}

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

Referenced by feature_automixmonitor().

◆ 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
number of running audiohooks which are from the source specified

Note: Function performs no locking.

Definition at line 1517 of file audiohook.c.

1518{
1519 int count = 0;
1520 struct ast_audiohook *ah = NULL;
1521 if (!ast_channel_audiohooks(chan))
1522 return -1;
1523
1524 switch (type) {
1526 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1527 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1528 count++;
1529 }
1530 break;
1532 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1533 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1534 count++;
1535 }
1536 break;
1538 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1539 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1540 count++;
1541 }
1542 break;
1543 default:
1544 ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1545 return -1;
1546 }
1547 return count;
1548}

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