Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Functions | Variables
audiohook.c File Reference

Audiohooks Architecture. More...

#include "asterisk.h"
#include <signal.h>
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/audiohook.h"
#include "asterisk/slinfactory.h"
#include "asterisk/frame.h"
#include "asterisk/translate.h"
#include "asterisk/format_cache.h"
#include "asterisk/test.h"
Include dependency graph for audiohook.c:

Go to the source code of this file.

Data Structures

struct  ast_audiohook_list
 
struct  ast_audiohook_translate
 
struct  audiohook_volume
 Audiohook volume adjustment structure. More...
 

Macros

#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE   500
 
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE   100
 
#define AST_AUDIOHOOK_SYNC_TOLERANCE   100
 
#define DEFAULT_INTERNAL_SAMPLE_RATE   8000
 
#define SHOULD_MUTE(hook, dir)
 

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 init_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_frame_feed_direction (struct ast_audiohook *audiohook, enum ast_audiohook_direction direction)
 Sets direction on audiohook. 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...
 
int ast_audiohook_set_mute_all (struct ast_channel *chan, const char *source, enum ast_audiohook_flags flag, int clearmute)
 Mute frames read from or written for all audiohooks on 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...
 
static struct ast_frameaudio_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. More...
 
static void audiohook_list_set_hook_rate (struct ast_audiohook_list *audiohook_list, struct ast_audiohook *audiohook, int *rate)
 Set the audiohook's internal sample rate to the audiohook_list's rate, but only when native slin compatibility is turned on. More...
 
static void audiohook_list_set_samplerate_compatibility (struct ast_audiohook_list *audiohook_list)
 
static struct ast_frameaudiohook_list_translate_to_native (struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *slin_frame, struct ast_format *outformat)
 
static struct ast_frameaudiohook_list_translate_to_slin (struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
 
static void audiohook_move (struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
 
static struct ast_frameaudiohook_read_frame_both (struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
 
static struct ast_frameaudiohook_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)
 
static struct ast_frameaudiohook_read_frame_single (struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
 
static int audiohook_set_internal_rate (struct ast_audiohook *audiohook, int rate, int reset)
 
static int audiohook_volume_callback (struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
 Helper function which actually gets called by audiohooks to perform the adjustment. More...
 
static void audiohook_volume_destroy (void *data)
 Callback used to destroy the audiohook volume datastore. More...
 
static struct audiohook_volumeaudiohook_volume_get (struct ast_channel *chan, int create)
 Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a channel. More...
 
static struct ast_framedtmf_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. More...
 
static struct ast_audiohookfind_audiohook_by_source (struct ast_audiohook_list *audiohook_list, const char *source)
 find an audiohook based on its source More...
 

Variables

static const struct ast_datastore_info audiohook_volume_datastore
 Datastore used to store audiohook volume information. More...
 

Detailed Description

Audiohooks Architecture.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file audiohook.c.

Macro Definition Documentation

◆ AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE

#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE   500

Otheriwise we still don't want the queue to grow indefinitely

Definition at line 46 of file audiohook.c.

◆ AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE

#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE   100

When small queue is enabled, this is the maximum amount of audio that can remain queued at a time.

Definition at line 45 of file audiohook.c.

◆ AST_AUDIOHOOK_SYNC_TOLERANCE

#define AST_AUDIOHOOK_SYNC_TOLERANCE   100

Tolerance in milliseconds for audiohooks synchronization

Definition at line 44 of file audiohook.c.

◆ DEFAULT_INTERNAL_SAMPLE_RATE

#define DEFAULT_INTERNAL_SAMPLE_RATE   8000

Definition at line 48 of file audiohook.c.

◆ SHOULD_MUTE

#define SHOULD_MUTE (   hook,
  dir 
)
Value:
@ AST_AUDIOHOOK_DIRECTION_READ
Definition: audiohook.h:49
@ AST_AUDIOHOOK_DIRECTION_WRITE
Definition: audiohook.h:50
@ AST_AUDIOHOOK_MUTE_READ
Definition: audiohook.h:64
@ AST_AUDIOHOOK_MUTE_WRITE
Definition: audiohook.h:65
#define ast_test_flag(p, flag)
Definition: utils.h:63

Definition at line 162 of file audiohook.c.

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

513{
514 ast_channel_lock(chan);
515
516 /* Don't allow an audiohook to be attached to a channel that is already hung up.
517 * The hang up process is what actually notifies the audiohook that it should
518 * stop.
519 */
521 ast_channel_unlock(chan);
522 return -1;
523 }
524
525 if (!ast_channel_audiohooks(chan)) {
526 struct ast_audiohook_list *ahlist;
527 /* Whoops... allocate a new structure */
528 if (!(ahlist = ast_calloc(1, sizeof(*ahlist)))) {
529 ast_channel_unlock(chan);
530 return -1;
531 }
532 ast_channel_audiohooks_set(chan, ahlist);
536 /* This sample rate will adjust as necessary when writing to the list. */
538 }
539
540 /* Drop into respective list */
541 if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
542 AST_LIST_INSERT_TAIL(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
543 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
545 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
547 }
548
549 /*
550 * Initialize the audiohook's rate to the default. If it needs to be,
551 * it will get updated later.
552 */
555
556 /* Change status over to running since it is now attached */
558
559 if (ast_channel_is_bridged(chan)) {
561 }
562
563 ast_channel_unlock(chan);
564
565 return 0;
566}
#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:484
void ast_audiohook_update_status(struct ast_audiohook *audiohook, enum ast_audiohook_status status)
Update audiohook's status.
Definition: audiohook.c:568
static int audiohook_set_internal_rate(struct ast_audiohook *audiohook, int rate, int reset)
Definition: audiohook.c:70
#define DEFAULT_INTERNAL_SAMPLE_RATE
Definition: audiohook.c:48
@ AST_AUDIOHOOK_TYPE_MANIPULATE
Definition: audiohook.h:38
@ AST_AUDIOHOOK_TYPE_SPY
Definition: audiohook.h:36
@ AST_AUDIOHOOK_TYPE_WHISPER
Definition: audiohook.h:37
@ AST_AUDIOHOOK_STATUS_RUNNING
Definition: audiohook.h:43
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:2968
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:10567
@ AST_FLAG_ZOMBIE
Definition: channel.h:1007
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
int list_internal_samp_rate
Definition: audiohook.c:61
struct ast_audiohook_list::@302 spy_list
struct ast_audiohook_list::@304 manipulate_list
struct ast_audiohook_list::@303 whisper_list
enum ast_audiohook_type type
Definition: audiohook.h:107

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(), 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 124 of file audiohook.c.

125{
126 /* Drop the factories used by this audiohook type */
127 switch (audiohook->type) {
132 break;
133 default:
134 break;
135 }
136
137 /* Destroy translation path if present */
138 if (audiohook->trans_pvt)
140
141 ao2_cleanup(audiohook->format);
142
143 /* Lock and trigger be gone! */
144 ast_cond_destroy(&audiohook->trigger);
145 ast_mutex_destroy(&audiohook->lock);
146
147 return 0;
148}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ast_cond_destroy(cond)
Definition: lock.h:202
#define ast_mutex_destroy(a)
Definition: lock.h:188
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:476

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(), 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 578 of file audiohook.c.

579{
580 if (audiohook->status == AST_AUDIOHOOK_STATUS_NEW || audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
581 return 0;
582 }
583
585
586 while (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
588 }
589
590 return 0;
591}
void ast_audiohook_trigger_wait(struct ast_audiohook *audiohook)
Wait for audiohook trigger to be triggered.
Definition: audiohook.c:1122
@ AST_AUDIOHOOK_STATUS_DONE
Definition: audiohook.h:45
@ AST_AUDIOHOOK_STATUS_NEW
Definition: audiohook.h:42
@ AST_AUDIOHOOK_STATUS_SHUTDOWN
Definition: audiohook.h:44
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_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 593 of file audiohook.c.

594{
595 int i;
596 struct ast_audiohook *audiohook;
597
598 if (!audiohook_list) {
599 return;
600 }
601
602 /* Drop any spies */
603 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->spy_list, list))) {
605 }
606
607 /* Drop any whispering sources */
608 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->whisper_list, list))) {
610 }
611
612 /* Drop any manipulators */
613 while ((audiohook = AST_LIST_REMOVE_HEAD(&audiohook_list->manipulate_list, list))) {
615 audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
616 }
617
618 /* Drop translation paths if present */
619 for (i = 0; i < 2; i++) {
620 if (audiohook_list->in_translate[i].trans_pvt) {
622 ao2_cleanup(audiohook_list->in_translate[i].format);
623 }
624 if (audiohook_list->out_translate[i].trans_pvt) {
626 ao2_cleanup(audiohook_list->in_translate[i].format);
627 }
628 }
629
630 /* Free ourselves */
631 ast_free(audiohook_list);
632}
#define ast_free(a)
Definition: astmm.h:180
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
#define NULL
Definition: resample.c:96
struct ast_audiohook_translate out_translate[2]
Definition: audiohook.c:64
struct ast_audiohook_translate in_translate[2]
Definition: audiohook.c:63
struct ast_trans_pvt * trans_pvt
Definition: audiohook.c:51
struct ast_format * format
Definition: audiohook.c:52
ast_audiohook_manipulate_callback manipulate_callback
Definition: audiohook.h:118
struct ast_audiohook::@187 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 726 of file audiohook.c.

727{
728 struct ast_audiohook *audiohook = NULL;
729
730 ast_channel_lock(chan);
731
732 /* Ensure the channel has audiohooks on it */
733 if (!ast_channel_audiohooks(chan)) {
734 ast_channel_unlock(chan);
735 return -1;
736 }
737
739
740 ast_channel_unlock(chan);
741
742 if (audiohook && audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
744 }
745
746 return (audiohook ? 0 : -1);
747}
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: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 100 of file audiohook.c.

101{
102 /* Need to keep the type and source */
103 audiohook->type = type;
104 audiohook->source = source;
105
106 /* Initialize lock that protects our audiohook */
107 ast_mutex_init(&audiohook->lock);
108 ast_cond_init(&audiohook->trigger, NULL);
109
110 audiohook->init_flags = init_flags;
111
112 /* Set direction to BOTH so that we feed frames in both directions */
114
115 /* initialize internal rate at 8khz, this will adjust if necessary */
117
118 /* Since we are just starting out... this audiohook is new */
120
121 return 0;
122}
@ AST_AUDIOHOOK_DIRECTION_BOTH
Definition: audiohook.h:51
static const char type[]
Definition: chan_ooh323.c:109
#define ast_cond_init(cond, attr)
Definition: lock.h:201
#define ast_mutex_init(pmutex)
Definition: lock.h:186
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(), 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 700 of file audiohook.c.

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}
static void audiohook_move(struct ast_channel *old_chan, struct ast_channel *new_chan, struct ast_audiohook *audiohook)
Definition: audiohook.c:665
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529

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

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}

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

475{
476 return audiohook_read_frame_helper(audiohook, samples, direction, format, NULL, NULL);
477}
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:412
direction

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

Referenced by snoop_read(), 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

Definition at line 479 of file audiohook.c.

480{
481 return audiohook_read_frame_helper(audiohook, samples, AST_AUDIOHOOK_DIRECTION_BOTH, format, read_frame, write_frame);
482}
static struct ast_frame * read_frame(struct ast_filestream *s, int *whennext)
Definition: file.c:911

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

750{
751 ast_channel_lock(chan);
752
753 if (!ast_channel_audiohooks(chan)) {
754 ast_channel_unlock(chan);
755 return -1;
756 }
757
758 if (audiohook->type == AST_AUDIOHOOK_TYPE_SPY) {
759 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list);
760 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_WHISPER) {
761 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->whisper_list, audiohook, list);
762 } else if (audiohook->type == AST_AUDIOHOOK_TYPE_MANIPULATE) {
763 AST_LIST_REMOVE(&ast_channel_audiohooks(chan)->manipulate_list, audiohook, list);
764 }
765
768
769 if (ast_channel_is_bridged(chan)) {
771 }
772
773 ast_channel_unlock(chan);
774
775 return 0;
776}
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:856

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

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

151{
152 /* Only set the direction on new audiohooks */
153 if (audiohook->status != AST_AUDIOHOOK_STATUS_NEW) {
154 ast_debug(3, "Can not set direction on attached Audiohook %p\n", audiohook);
155 return -1;
156 }
157
158 audiohook->direction = direction;
159 return 0;
160}
#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(), 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 1381 of file audiohook.c.

1382{
1383 struct ast_audiohook *audiohook = NULL;
1384
1385 ast_channel_lock(chan);
1386
1387 /* Ensure the channel has audiohooks on it */
1388 if (!ast_channel_audiohooks(chan)) {
1389 ast_channel_unlock(chan);
1390 return -1;
1391 }
1392
1394
1395 if (audiohook) {
1396 if (clear) {
1397 ast_clear_flag(audiohook, flag);
1398 } else {
1399 ast_set_flag(audiohook, flag);
1400 }
1401 }
1402
1403 ast_channel_unlock(chan);
1404
1405 return (audiohook ? 0 : -1);
1406}
long int flag
Definition: f2c.h:83
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define ast_set_flag(p, flag)
Definition: utils.h:70

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

1409{
1410 struct ast_audiohook *audiohook = NULL;
1411 int count = 0;
1412
1413 ast_channel_lock(chan);
1414
1415 if (!ast_channel_audiohooks(chan)) {
1416 ast_channel_unlock(chan);
1417 return -1;
1418 }
1419
1420 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, audiohook, list) {
1421 if (!strcasecmp(audiohook->source, source)) {
1422 count++;
1423 if (clearmute) {
1424 ast_clear_flag(audiohook, flag);
1425 } else {
1426 ast_set_flag(audiohook, flag);
1427 }
1428 }
1429 }
1430
1431 ast_test_suite_event_notify("AUDIOHOOK_GROUP_MUTE_TOGGLE", "Channel: %s\r\nSource: %s\r\nCount: %d\r\n",
1432 ast_channel_name(chan), source, count);
1433
1434 ast_channel_unlock(chan);
1435
1436 return count;
1437}
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.
Definition: linkedlists.h:491
#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 1122 of file audiohook.c.

1123{
1124 struct timeval wait;
1125 struct timespec ts;
1126
1127 wait = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000));
1128 ts.tv_sec = wait.tv_sec;
1129 ts.tv_nsec = wait.tv_usec * 1000;
1130
1131 ast_cond_timedwait(&audiohook->trigger, &audiohook->lock, &ts);
1132
1133 return;
1134}
#define ast_cond_timedwait(cond, mutex, time)
Definition: lock.h:206
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:2282
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 568 of file audiohook.c.

569{
570 ast_audiohook_lock(audiohook);
571 if (audiohook->status != AST_AUDIOHOOK_STATUS_DONE) {
572 audiohook->status = status;
573 ast_cond_signal(&audiohook->trigger);
574 }
575 ast_audiohook_unlock(audiohook);
576}
jack_status_t status
Definition: app_jack.c:146
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition: audiohook.h:313
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition: audiohook.h:318
#define ast_cond_signal(cond)
Definition: lock.h:203

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

1362{
1364
1365 /* Attempt to find the audiohook volume information, and create an audiohook if none exists */
1366 if (!(audiohook_volume = audiohook_volume_get(chan, 1))) {
1367 return -1;
1368 }
1369
1370 /* Based on the direction change the specific adjustment value */
1373 }
1376 }
1377
1378 return 0;
1379}
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:1286
Audiohook volume adjustment structure.
Definition: audiohook.c:1211

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

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

1342{
1344 int adjustment = 0;
1345
1346 /* Attempt to find the audiohook volume information, but do not create it as we only want to look at the values */
1347 if (!(audiohook_volume = audiohook_volume_get(chan, 0))) {
1348 return 0;
1349 }
1350
1351 /* Grab the adjustment value based on direction given */
1353 adjustment = audiohook_volume->read_adjustment;
1355 adjustment = audiohook_volume->write_adjustment;
1356 }
1357
1358 return adjustment;
1359}

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

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

1322{
1324
1325 /* Attempt to find the audiohook volume information, but only create it if we are not setting the adjustment value to zero */
1326 if (!(audiohook_volume = audiohook_volume_get(chan, (volume ? 1 : 0)))) {
1327 return -1;
1328 }
1329
1330 /* Now based on the direction set the proper value */
1333 }
1336 }
1337
1338 return 0;
1339}

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

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

168{
169 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
170 struct ast_slinfactory *other_factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->write_factory : &audiohook->read_factory);
171 struct timeval *rwtime = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_time : &audiohook->write_time), previous_time = *rwtime;
172 int our_factory_samples;
173 int our_factory_ms;
174 int other_factory_samples;
175 int other_factory_ms;
176
177 /* Don't feed the frame if we are set to read and this is a write frame or if set to
178 write and this is a read frame as we don't want it. Plus, it can cause mis-resampling
179 if the READ and WRITE frames have different bitrates */
180 if (audiohook->direction != AST_AUDIOHOOK_DIRECTION_BOTH && audiohook->direction != direction) {
181 return 0;
182 }
183
184 /* Update last feeding time to be current */
185 *rwtime = ast_tvnow();
186
187 our_factory_samples = ast_slinfactory_available(factory);
188 our_factory_ms = ast_tvdiff_ms(*rwtime, previous_time) + (our_factory_samples / (audiohook->hook_internal_samp_rate / 1000));
189 other_factory_samples = ast_slinfactory_available(other_factory);
190 other_factory_ms = other_factory_samples / (audiohook->hook_internal_samp_rate / 1000);
191
192 if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC) && (our_factory_ms - other_factory_ms > AST_AUDIOHOOK_SYNC_TOLERANCE)) {
193 ast_debug(4, "Flushing audiohook %p so it remains in sync\n", audiohook);
194 ast_slinfactory_flush(factory);
195 ast_slinfactory_flush(other_factory);
196 }
197
198 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))) {
199 ast_debug(4, "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 } else if ((our_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE) || (other_factory_ms > AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE)) {
203 ast_debug(4, "Audiohook %p has stale audio in its factories. Flushing them both\n", audiohook);
204 ast_slinfactory_flush(factory);
205 ast_slinfactory_flush(other_factory);
206 }
207
208 /* Write frame out to respective factory */
209 ast_slinfactory_feed(factory, frame);
210
211 /* If we need to notify the respective handler of this audiohook, do so */
213 ast_cond_signal(&audiohook->trigger);
215 ast_cond_signal(&audiohook->trigger);
216 } else if (ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC)) {
217 ast_cond_signal(&audiohook->trigger);
218 }
219
220 return 0;
221}
#define AST_AUDIOHOOK_LONG_QUEUE_TOLERANCE
Definition: audiohook.c:46
#define AST_AUDIOHOOK_SYNC_TOLERANCE
Definition: audiohook.c:44
#define AST_AUDIOHOOK_SMALL_QUEUE_TOLERANCE
Definition: audiohook.c:45
@ AST_AUDIOHOOK_TRIGGER_MODE
Definition: audiohook.h:55
@ 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
unsigned int ast_slinfactory_available(const struct ast_slinfactory *sf)
Retrieve number of samples currently in a slinfactory.
Definition: slinfactory.c:199
void ast_slinfactory_flush(struct ast_slinfactory *sf)
Flush the contents of a slinfactory.
Definition: slinfactory.c:204
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 1107 of file audiohook.c.

1108{
1109 /* Pass off frame to it's respective list write function */
1110 if (frame->frametype == AST_FRAME_VOICE) {
1111 return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
1112 } else if (frame->frametype == AST_FRAME_DTMF) {
1113 return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
1114 } else {
1115 return frame;
1116 }
1117}
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:942
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:786
#define AST_FRAME_DTMF
@ AST_FRAME_VOICE
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 1099 of file audiohook.c.

1100{
1101 return !audiohook_list
1102 || (AST_LIST_EMPTY(&audiohook_list->spy_list)
1103 && AST_LIST_EMPTY(&audiohook_list->whisper_list)
1104 && AST_LIST_EMPTY(&audiohook_list->manipulate_list));
1105}
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450

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

1138{
1139 int count = 0;
1140 struct ast_audiohook *ah = NULL;
1141
1142 if (!ast_channel_audiohooks(chan)) {
1143 return -1;
1144 }
1145
1146 switch (type) {
1148 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1149 if (!strcmp(ah->source, source)) {
1150 count++;
1151 }
1152 }
1153 break;
1155 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1156 if (!strcmp(ah->source, source)) {
1157 count++;
1158 }
1159 }
1160 break;
1162 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1163 if (!strcmp(ah->source, source)) {
1164 count++;
1165 }
1166 }
1167 break;
1168 default:
1169 ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1170 return -1;
1171 }
1172
1173 return count;
1174}

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

1178{
1179 int count = 0;
1180 struct ast_audiohook *ah = NULL;
1181 if (!ast_channel_audiohooks(chan))
1182 return -1;
1183
1184 switch (type) {
1186 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->spy_list, ah, list) {
1187 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1188 count++;
1189 }
1190 break;
1192 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->whisper_list, ah, list) {
1193 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1194 count++;
1195 }
1196 break;
1198 AST_LIST_TRAVERSE(&ast_channel_audiohooks(chan)->manipulate_list, ah, list) {
1199 if ((!strcmp(ah->source, source)) && (ah->status == AST_AUDIOHOOK_STATUS_RUNNING))
1200 count++;
1201 }
1202 break;
1203 default:
1204 ast_debug(1, "Invalid audiohook type supplied, (%u)\n", type);
1205 return -1;
1206 }
1207 return count;
1208}

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.

◆ audio_audiohook_write_list()

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

Pass an AUDIO frame off to be handled by the audiohook core.

This function has 3 ast_frames and 3 parts to handle each. At the beginning of this function all 3 frames, start_frame, middle_frame, and end_frame point to the initial input frame.

Part_1: Translate the start_frame into SLINEAR audio if it is not already in that format. The result of this part is middle_frame is guaranteed to be in SLINEAR format for Part_2. Part_2: Send middle_frame off to spies and manipulators. At this point middle_frame is either a new frame as result of the translation, or points directly to the start_frame because no translation to SLINEAR audio was required. Part_3: Translate end_frame's audio back into the format of start frame if necessary. This is only necessary if manipulation of middle_frame occurred.

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

943{
944 struct ast_frame *start_frame = frame, *middle_frame = frame, *end_frame = frame;
945 struct ast_audiohook *audiohook = NULL;
946 int samples;
947 int middle_frame_manipulated = 0;
948 int removed = 0;
949 int internal_sample_rate;
950
951 /* ---Part_1. translate start_frame to SLINEAR if necessary. */
952 if (!(middle_frame = audiohook_list_translate_to_slin(audiohook_list, direction, start_frame))) {
953 return frame;
954 }
955
956 /* If the translation resulted in an interpolated frame then immediately return as audiohooks
957 * rely on actual media being present to do things.
958 */
959 if (!middle_frame->data.ptr) {
960 if (middle_frame != start_frame) {
961 ast_frfree(middle_frame);
962 }
963 return start_frame;
964 }
965
966 samples = middle_frame->samples;
967
968 /*
969 * While processing each audiohook check to see if the internal sample rate needs
970 * to be adjusted (it should be the highest rate specified between formats and
971 * hooks). The given audiohook_list's internal sample rate is then set to the
972 * updated value before returning.
973 *
974 * If slin compatibility mode is turned on then an audiohook's internal sample
975 * rate is set to its audiohook_list's rate. If an audiohook_list's rate is
976 * adjusted during this pass then the change is picked up by the audiohooks
977 * on the next pass.
978 */
979 internal_sample_rate = audiohook_list->list_internal_samp_rate;
980
981 /* ---Part_2: Send middle_frame to spy and manipulator lists. middle_frame is guaranteed to be SLINEAR here.*/
982 /* Queue up signed linear frame to each spy */
983 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->spy_list, audiohook, list) {
984 ast_audiohook_lock(audiohook);
985 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
987 removed = 1;
989 ast_audiohook_unlock(audiohook);
990 if (ast_channel_is_bridged(chan)) {
992 }
993 continue;
994 }
995 audiohook_list_set_hook_rate(audiohook_list, audiohook, &internal_sample_rate);
996 ast_audiohook_write_frame(audiohook, direction, middle_frame);
997 ast_audiohook_unlock(audiohook);
998 }
1000
1001 /* If this frame is being written out to the channel then we need to use whisper sources */
1002 if (!AST_LIST_EMPTY(&audiohook_list->whisper_list)) {
1003 int i = 0;
1004 short read_buf[samples], combine_buf[samples], *data1 = NULL, *data2 = NULL;
1005 memset(&combine_buf, 0, sizeof(combine_buf));
1006 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->whisper_list, audiohook, list) {
1007 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
1008 ast_audiohook_lock(audiohook);
1009 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
1011 removed = 1;
1013 ast_audiohook_unlock(audiohook);
1014 if (ast_channel_is_bridged(chan)) {
1016 }
1017 continue;
1018 }
1019 audiohook_list_set_hook_rate(audiohook_list, audiohook, &internal_sample_rate);
1020 if (ast_slinfactory_available(factory) >= samples && ast_slinfactory_read(factory, read_buf, samples)) {
1021 /* Take audio from this whisper source and combine it into our main buffer */
1022 for (i = 0, data1 = combine_buf, data2 = read_buf; i < samples; i++, data1++, data2++) {
1023 ast_slinear_saturated_add(data1, data2);
1024 }
1025 }
1026 ast_audiohook_unlock(audiohook);
1027 }
1029 /* We take all of the combined whisper sources and combine them into the audio being written out */
1030 for (i = 0, data1 = middle_frame->data.ptr, data2 = combine_buf; i < samples; i++, data1++, data2++) {
1031 ast_slinear_saturated_add(data1, data2);
1032 }
1033 middle_frame_manipulated = 1;
1034 }
1035
1036 /* Pass off frame to manipulate audiohooks */
1037 if (!AST_LIST_EMPTY(&audiohook_list->manipulate_list)) {
1038 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
1039 ast_audiohook_lock(audiohook);
1040 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
1042 removed = 1;
1044 ast_audiohook_unlock(audiohook);
1045 /* We basically drop all of our links to the manipulate audiohook and prod it to do it's own destructive things */
1046 audiohook->manipulate_callback(audiohook, chan, NULL, direction);
1047 if (ast_channel_is_bridged(chan)) {
1049 }
1050 continue;
1051 }
1052 audiohook_list_set_hook_rate(audiohook_list, audiohook, &internal_sample_rate);
1053 /*
1054 * Feed in frame to manipulation.
1055 */
1056 if (!audiohook->manipulate_callback(audiohook, chan, middle_frame, direction)) {
1057 /*
1058 * XXX FAILURES ARE IGNORED XXX
1059 * If the manipulation fails then the frame will be returned in its original state.
1060 * Since there are potentially more manipulator callbacks in the list, no action should
1061 * be taken here to exit early.
1062 */
1063 middle_frame_manipulated = 1;
1064 }
1065 ast_audiohook_unlock(audiohook);
1066 }
1068 }
1069
1070 /* ---Part_3: Decide what to do with the end_frame (whether to transcode or not) */
1071 if (middle_frame_manipulated) {
1072 if (!(end_frame = audiohook_list_translate_to_native(audiohook_list, direction, middle_frame, start_frame->subclass.format))) {
1073 /* translation failed, so just pass back the input frame */
1074 end_frame = start_frame;
1075 }
1076 } else {
1077 end_frame = start_frame;
1078 }
1079 /* clean up our middle_frame if required */
1080 if (middle_frame != end_frame) {
1081 ast_frfree(middle_frame);
1082 middle_frame = NULL;
1083 }
1084
1085 /* Before returning, if an audiohook got removed, reset samplerate compatibility */
1086 if (removed) {
1088 } else {
1089 /*
1090 * Set the audiohook_list's rate to the updated rate. Note that if a hook
1091 * was removed then the list's internal rate is reset to the default.
1092 */
1093 audiohook_list->list_internal_samp_rate = internal_sample_rate;
1094 }
1095
1096 return end_frame;
1097}
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.
Definition: audiohook.c:167
static struct ast_frame * audiohook_list_translate_to_native(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *slin_frame, struct ast_format *outformat)
Definition: audiohook.c:864
static struct ast_frame * audiohook_list_translate_to_slin(struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
Definition: audiohook.c:818
static void audiohook_list_set_hook_rate(struct ast_audiohook_list *audiohook_list, struct ast_audiohook *audiohook, int *rate)
Set the audiohook's internal sample rate to the audiohook_list's rate, but only when native slin comp...
Definition: audiohook.c:896
#define ast_frfree(fr)
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
Read samples from a slinfactory.
Definition: slinfactory.c:145
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
static force_inline void ast_slinear_saturated_add(short *input, short *value)
Definition: utils.h:450

References AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_RUNNING, ast_audiohook_unlock, ast_audiohook_update_status(), ast_audiohook_write_frame(), ast_channel_is_bridged(), ast_channel_set_unbridged_nolock(), ast_frfree, AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_slinear_saturated_add(), ast_slinfactory_available(), ast_slinfactory_read(), audiohook_list_set_hook_rate(), audiohook_list_set_samplerate_compatibility(), audiohook_list_translate_to_native(), audiohook_list_translate_to_slin(), ast_frame_subclass::format, ast_audiohook::list, ast_audiohook_list::list_internal_samp_rate, ast_audiohook::manipulate_callback, ast_audiohook_list::manipulate_list, NULL, ast_audiohook::read_factory, ast_frame::samples, ast_audiohook_list::spy_list, ast_audiohook::status, ast_frame::subclass, ast_audiohook_list::whisper_list, and ast_audiohook::write_factory.

Referenced by ast_audiohook_write_list().

◆ audiohook_list_set_hook_rate()

static void audiohook_list_set_hook_rate ( struct ast_audiohook_list audiohook_list,
struct ast_audiohook audiohook,
int *  rate 
)
static

Set the audiohook's internal sample rate to the audiohook_list's rate, but only when native slin compatibility is turned on.

Parameters
audiohook_listaudiohook_list data object
audiohookthe audiohook to update
ratethe current max internal sample rate

Definition at line 896 of file audiohook.c.

898{
899 /* The rate should always be the max between itself and the hook */
900 if (audiohook->hook_internal_samp_rate > *rate) {
901 *rate = audiohook->hook_internal_samp_rate;
902 }
903
904 /*
905 * If native slin compatibility is turned on then update the audiohook
906 * with the audiohook_list's current rate. Note, the audiohook's rate is
907 * set to the audiohook_list's rate and not the given rate. If there is
908 * a change in rate the hook's rate is changed on its next check.
909 */
910 if (audiohook_list->native_slin_compatible) {
912 audiohook_set_internal_rate(audiohook, audiohook_list->list_internal_samp_rate, 1);
913 } else {
915 }
916}
@ AST_AUDIOHOOK_COMPATIBLE
Definition: audiohook.h:66
int native_slin_compatible
Definition: audiohook.c:60

References AST_AUDIOHOOK_COMPATIBLE, ast_clear_flag, ast_set_flag, audiohook_set_internal_rate(), ast_audiohook::hook_internal_samp_rate, ast_audiohook_list::list_internal_samp_rate, and ast_audiohook_list::native_slin_compatible.

Referenced by audio_audiohook_write_list().

◆ audiohook_list_set_samplerate_compatibility()

static void audiohook_list_set_samplerate_compatibility ( struct ast_audiohook_list audiohook_list)
static

Definition at line 484 of file audiohook.c.

485{
486 struct ast_audiohook *ah = NULL;
487
488 /*
489 * Anytime the samplerate compatibility is set (attach/remove an audiohook) the
490 * list's internal sample rate needs to be reset so that the next time processing
491 * through write_list, if needed, it will get updated to the correct rate.
492 *
493 * A list's internal rate always chooses the higher between its own rate and a
494 * given rate. If the current rate is being driven by an audiohook that wanted a
495 * higher rate then when this audiohook is removed the list's rate would remain
496 * at that level when it should be lower, and with no way to lower it since any
497 * rate compared against it would be lower.
498 *
499 * By setting it back to the lowest rate it can recalulate the new highest rate.
500 */
502
503 audiohook_list->native_slin_compatible = 1;
504 AST_LIST_TRAVERSE(&audiohook_list->manipulate_list, ah, list) {
506 audiohook_list->native_slin_compatible = 0;
507 return;
508 }
509 }
510}
@ AST_AUDIOHOOK_MANIPULATE_ALL_RATES
Definition: audiohook.h:75

References AST_AUDIOHOOK_MANIPULATE_ALL_RATES, AST_LIST_TRAVERSE, DEFAULT_INTERNAL_SAMPLE_RATE, ast_audiohook::init_flags, ast_audiohook::list, ast_audiohook_list::list_internal_samp_rate, ast_audiohook_list::manipulate_list, ast_audiohook_list::native_slin_compatible, and NULL.

Referenced by ast_audiohook_attach(), ast_audiohook_remove(), audio_audiohook_write_list(), and dtmf_audiohook_write_list().

◆ audiohook_list_translate_to_native()

static struct ast_frame * audiohook_list_translate_to_native ( struct ast_audiohook_list audiohook_list,
enum ast_audiohook_direction  direction,
struct ast_frame slin_frame,
struct ast_format outformat 
)
static

Definition at line 864 of file audiohook.c.

866{
867 struct ast_audiohook_translate *out_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->out_translate[0] : &audiohook_list->out_translate[1]);
868 struct ast_frame *outframe = NULL;
869 if (ast_format_cmp(slin_frame->subclass.format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
870 /* rebuild translators if necessary */
871 if (ast_format_cmp(out_translate->format, outformat) == AST_FORMAT_CMP_NOT_EQUAL) {
872 if (out_translate->trans_pvt) {
873 ast_translator_free_path(out_translate->trans_pvt);
874 }
875 if (!(out_translate->trans_pvt = ast_translator_build_path(outformat, slin_frame->subclass.format))) {
876 return NULL;
877 }
878 ao2_replace(out_translate->format, outformat);
879 }
880 /* translate back to the format the frame came in as. */
881 if (!(outframe = ast_translate(out_translate->trans_pvt, slin_frame, 0))) {
882 return NULL;
883 }
884 }
885 return outframe;
886}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
Definition: translate.c:566
struct ast_trans_pvt * ast_translator_build_path(struct ast_format *dest, struct ast_format *source)
Builds a translator path Build a path (possibly NULL) from source to dest.
Definition: translate.c:486

References ao2_replace, AST_AUDIOHOOK_DIRECTION_READ, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_frame_subclass::format, ast_audiohook_translate::format, NULL, ast_audiohook_list::out_translate, ast_frame::subclass, and ast_audiohook_translate::trans_pvt.

Referenced by audio_audiohook_write_list().

◆ audiohook_list_translate_to_slin()

static struct ast_frame * audiohook_list_translate_to_slin ( struct ast_audiohook_list audiohook_list,
enum ast_audiohook_direction  direction,
struct ast_frame frame 
)
static

Definition at line 818 of file audiohook.c.

820{
822 &audiohook_list->in_translate[0] : &audiohook_list->in_translate[1]);
823 struct ast_frame *new_frame = frame;
824 struct ast_format *slin;
825
826 /*
827 * If we are capable of sample rates other that 8khz, update the internal
828 * audiohook_list's rate and higher sample rate audio arrives. If native
829 * slin compatibility is turned on all audiohooks in the list will be
830 * updated as well during read/write processing.
831 */
832 audiohook_list->list_internal_samp_rate =
834
836 if (ast_format_cmp(frame->subclass.format, slin) == AST_FORMAT_CMP_EQUAL) {
837 return new_frame;
838 }
839
840 if (!in_translate->format ||
841 ast_format_cmp(frame->subclass.format, in_translate->format) != AST_FORMAT_CMP_EQUAL) {
842 struct ast_trans_pvt *new_trans;
843
844 new_trans = ast_translator_build_path(slin, frame->subclass.format);
845 if (!new_trans) {
846 return NULL;
847 }
848
849 if (in_translate->trans_pvt) {
850 ast_translator_free_path(in_translate->trans_pvt);
851 }
852 in_translate->trans_pvt = new_trans;
853
854 ao2_replace(in_translate->format, frame->subclass.format);
855 }
856
857 if (!(new_frame = ast_translate(in_translate->trans_pvt, frame, 0))) {
858 return NULL;
859 }
860
861 return new_frame;
862}
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
struct ast_format * ast_format_cache_get_slin_by_rate(unsigned int rate)
Retrieve the best signed linear format given a sample rate.
Definition: format_cache.c:512
Definition of a media format.
Definition: format.c:43
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition: translate.h:213
#define MAX(a, b)
Definition: utils.h:233

References ao2_replace, AST_AUDIOHOOK_DIRECTION_READ, ast_format_cache_get_slin_by_rate(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_get_sample_rate(), ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_frame_subclass::format, ast_audiohook_translate::format, ast_audiohook_list::in_translate, ast_audiohook_list::list_internal_samp_rate, MAX, NULL, ast_frame::subclass, and ast_audiohook_translate::trans_pvt.

Referenced by audio_audiohook_write_list().

◆ audiohook_move()

static void audiohook_move ( struct ast_channel old_chan,
struct ast_channel new_chan,
struct ast_audiohook audiohook 
)
static

Definition at line 665 of file audiohook.c.

666{
667 enum ast_audiohook_status oldstatus;
668
669 /* By locking both channels and the audiohook, we can assure that
670 * another thread will not have a chance to read the audiohook's status
671 * as done, even though ast_audiohook_remove signals the trigger
672 * condition.
673 */
674 ast_audiohook_lock(audiohook);
675 oldstatus = audiohook->status;
676
677 ast_audiohook_remove(old_chan, audiohook);
678 ast_audiohook_attach(new_chan, audiohook);
679
680 audiohook->status = oldstatus;
681 ast_audiohook_unlock(audiohook);
682}
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
Definition: audiohook.c:749
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition: audiohook.c:512
ast_audiohook_status
Definition: audiohook.h:41

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

Referenced by ast_audiohook_move_all(), and ast_audiohook_move_by_source().

◆ audiohook_read_frame_both()

static struct ast_frame * audiohook_read_frame_both ( struct ast_audiohook audiohook,
size_t  samples,
struct ast_frame **  read_reference,
struct ast_frame **  write_reference 
)
static

Definition at line 257 of file audiohook.c.

258{
259 int count;
260 int usable_read;
261 int usable_write;
262 short adjust_value;
263 short buf1[samples];
264 short buf2[samples];
265 short *read_buf = NULL;
266 short *write_buf = NULL;
267 struct ast_frame frame = {
269 .datalen = sizeof(buf1),
270 .samples = samples,
271 };
272
273 /* Make sure both factories have the required samples */
274 usable_read = (ast_slinfactory_available(&audiohook->read_factory) >= samples ? 1 : 0);
275 usable_write = (ast_slinfactory_available(&audiohook->write_factory) >= samples ? 1 : 0);
276
277 if (!usable_read && !usable_write) {
278 /* If both factories are unusable bail out */
279 ast_debug(3, "Read factory %p and write factory %p both fail to provide %zu samples\n", &audiohook->read_factory, &audiohook->write_factory, samples);
280 return NULL;
281 }
282
283 /* usable_read=1: indicates that read factory have the required samples
284 * usable_write=0: indicates that write factory have not the required samples
285 * usable_write, follows:
286 * 1. Due to RTT issues, the direction write frame has not been received,
287 * and it may take more than (samples/8)*2ms to receive it.
288 * 2. Due to packet loss, the direction write frame could not been received.
289 *
290 * (ast_tvdiff_ms(ast_tvnow(), audiohook->write_time) < (samples/8)*2)(Expression A): This ensures that
291 * packets on both sides can be read correctly even with RTT; however, if the RTT exceeds
292 * (samples/8)*2ms, it may result in the number of packets reading on both sides being greater than the
293 * actual number of packets. for example, this may cause the recording length of mixmonitor to be greater
294 * than the actual duration. Additionally, when RTT = 0 and packet loss is 50%, some packets in the
295 * write direction will never arrive. In this case, continuously waiting will only cause the read
296 * factory to exceed the safe length limit, resulting in both the read factory and write factory
297 * being cleared, thus same packets received in the read direction cannot be read.
298 *
299 * (ast_slinfactory_available(&audiohook->read_factory) < 2 * samples)(Expression B): This ensures that
300 * packets on both sides can be read correctly, even in the presence of packet loss; regardless of
301 * the amount of packet loss.
302 *
303 * (Expression A)&&(Expression B): This combination can comprehensively solve both RTT and packet loss
304 * issues; however when RTT exceeds (samples/8)*2ms, it may result in the number of packets read
305 * on both sides being greater than the actual number of packets, causing the recording length of
306 * mixmonitor to be longer than the actual duration. We can adjust (ast_tvdiff_ms(ast_tvnow(),
307 * audiohook->write_time)<(samples/8)*2) && (ast_slinfactory_available(&audiohook->read_factory) <
308 * 2 * samples) according to actual needs, for example, setting it to (ast_tvdiff_ms(ast_tvnow(),
309 * audiohook->write_time) < (samples/8)*4) && (ast_slinfactory_available(&audiohook->read_factory)
310 * < 4 * samples).
311 */
312 if (usable_read && !usable_write && (ast_tvdiff_ms(ast_tvnow(), audiohook->write_time) < (samples/8)*2) && (ast_slinfactory_available(&audiohook->read_factory) < 2 * samples)) {
313 ast_debug(3, "Write factory %p was pretty quick last time, waiting for them.\n", &audiohook->write_factory);
314 return NULL;
315 }
316
317 /* As shown in the above comment. */
318 if (usable_write && !usable_read && (ast_tvdiff_ms(ast_tvnow(), audiohook->read_time) < (samples/8)*2) && (ast_slinfactory_available(&audiohook->write_factory) < 2 * samples)) {
319 ast_debug(3, "Read factory %p was pretty quick last time, waiting for them.\n", &audiohook->read_factory);
320 return NULL;
321 }
322
323 /* Start with the read factory... if there are enough samples, read them in */
324 if (usable_read) {
325 if (ast_slinfactory_read(&audiohook->read_factory, buf1, samples)) {
326 read_buf = buf1;
327
328 if ((ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_READ))) {
329 /* Clear the frame data if we are muting */
330 memset(buf1, 0, sizeof(buf1));
331 } else if (audiohook->options.read_volume) {
332 /* Adjust read volume if need be */
333 adjust_value = abs(audiohook->options.read_volume);
334 for (count = 0; count < samples; count++) {
335 if (audiohook->options.read_volume > 0) {
336 ast_slinear_saturated_multiply(&buf1[count], &adjust_value);
337 } else if (audiohook->options.read_volume < 0) {
338 ast_slinear_saturated_divide(&buf1[count], &adjust_value);
339 }
340 }
341 }
342 }
343 } else {
344 ast_debug(1, "Failed to get %d samples from read factory %p\n", (int)samples, &audiohook->read_factory);
345 }
346
347 /* Move on to the write factory... if there are enough samples, read them in */
348 if (usable_write) {
349 if (ast_slinfactory_read(&audiohook->write_factory, buf2, samples)) {
350 write_buf = buf2;
351
352 if ((ast_test_flag(audiohook, AST_AUDIOHOOK_MUTE_WRITE))) {
353 /* Clear the frame data if we are muting */
354 memset(buf2, 0, sizeof(buf2));
355 } else if (audiohook->options.write_volume) {
356 /* Adjust write volume if need be */
357 adjust_value = abs(audiohook->options.write_volume);
358 for (count = 0; count < samples; count++) {
359 if (audiohook->options.write_volume > 0) {
360 ast_slinear_saturated_multiply(&buf2[count], &adjust_value);
361 } else if (audiohook->options.write_volume < 0) {
362 ast_slinear_saturated_divide(&buf2[count], &adjust_value);
363 }
364 }
365 }
366 }
367 } else {
368 ast_debug(3, "Failed to get %d samples from write factory %p\n", (int)samples, &audiohook->write_factory);
369 }
370
372
373 /* Should we substitute silence if one side lacks audio? */
375 if (read_reference && !read_buf && write_buf) {
376 read_buf = buf1;
377 memset(buf1, 0, sizeof(buf1));
378 } else if (write_reference && read_buf && !write_buf) {
379 write_buf = buf2;
380 memset(buf2, 0, sizeof(buf2));
381 }
382 }
383
384 /* Basically we figure out which buffer to use... and if mixing can be done here */
385 if (read_buf && read_reference) {
386 frame.data.ptr = read_buf;
387 *read_reference = ast_frdup(&frame);
388 }
389 if (write_buf && write_reference) {
390 frame.data.ptr = write_buf;
391 *write_reference = ast_frdup(&frame);
392 }
393
394 /* Make the correct buffer part of the built frame, so it gets duplicated. */
395 if (read_buf) {
396 frame.data.ptr = read_buf;
397 if (write_buf) {
398 for (count = 0; count < samples; count++) {
400 }
401 }
402 } else if (write_buf) {
403 frame.data.ptr = write_buf;
404 } else {
405 return NULL;
406 }
407
408 /* Yahoo, a combined copy of the audio! */
409 return ast_frdup(&frame);
410}
@ AST_AUDIOHOOK_SUBSTITUTE_SILENCE
Definition: audiohook.h:68
void write_buf(int file, char *buffer, int num)
Definition: eagi_proxy.c:312
#define abs(x)
Definition: f2c.h:195
static struct ast_threadstorage buf2
static struct ast_threadstorage buf1
#define ast_frdup(fr)
Copies a frame.
struct ast_audiohook_options options
Definition: audiohook.h:119
union ast_frame::@226 data
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
Definition: utils.h:476
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
Definition: utils.h:502

References abs, AST_AUDIOHOOK_MUTE_READ, AST_AUDIOHOOK_MUTE_WRITE, AST_AUDIOHOOK_SUBSTITUTE_SILENCE, ast_debug, ast_format_cache_get_slin_by_rate(), AST_FRAME_VOICE, ast_frdup, ast_slinear_saturated_add(), ast_slinear_saturated_divide(), ast_slinear_saturated_multiply(), ast_slinfactory_available(), ast_slinfactory_read(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), buf1, buf2, ast_frame::data, ast_frame_subclass::format, ast_frame::frametype, ast_audiohook::hook_internal_samp_rate, NULL, ast_audiohook::options, ast_frame::ptr, ast_audiohook::read_factory, ast_audiohook::read_time, ast_audiohook_options::read_volume, ast_frame::samples, ast_frame::subclass, write_buf(), ast_audiohook::write_factory, ast_audiohook::write_time, and ast_audiohook_options::write_volume.

Referenced by audiohook_read_frame_helper().

◆ audiohook_read_frame_helper()

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

Definition at line 412 of file audiohook.c.

413{
414 struct ast_frame *read_frame = NULL, *final_frame = NULL;
415 struct ast_format *slin;
416
417 /*
418 * Update the rate if compatibility mode is turned off or if it is
419 * turned on and the format rate is higher than the current rate.
420 *
421 * This makes it so any unnecessary rate switching/resetting does
422 * not take place and also any associated audiohook_list's internal
423 * sample rate maintains the highest sample rate between hooks.
424 */
425 if (!ast_test_flag(audiohook, AST_AUDIOHOOK_COMPATIBLE) ||
429 }
430
431 /* If the sample rate of the requested format differs from that of the underlying audiohook
432 * sample rate determine how many samples we actually need to get from the audiohook. This
433 * needs to occur as the signed linear factory stores them at the rate of the audiohook.
434 * We do this by determining the duration of audio they've requested and then determining
435 * how many samples that would be in the audiohook format.
436 */
437 if (ast_format_get_sample_rate(format) != audiohook->hook_internal_samp_rate) {
438 samples = (audiohook->hook_internal_samp_rate / 1000) * (samples / (ast_format_get_sample_rate(format) / 1000));
439 }
440
442 audiohook_read_frame_both(audiohook, samples, read_reference, write_reference) :
443 audiohook_read_frame_single(audiohook, samples, direction)))) {
444 return NULL;
445 }
446
448
449 /* If they don't want signed linear back out, we'll have to send it through the translation path */
450 if (ast_format_cmp(format, slin) != AST_FORMAT_CMP_EQUAL) {
451 /* Rebuild translation path if different format then previously */
452 if (ast_format_cmp(format, audiohook->format) == AST_FORMAT_CMP_NOT_EQUAL) {
453 if (audiohook->trans_pvt) {
455 audiohook->trans_pvt = NULL;
456 }
457
458 /* Setup new translation path for this format... if we fail we can't very well return signed linear so free the frame and return nothing */
459 if (!(audiohook->trans_pvt = ast_translator_build_path(format, slin))) {
461 return NULL;
462 }
463 ao2_replace(audiohook->format, format);
464 }
465 /* Convert to requested format, and allow the read in frame to be freed */
466 final_frame = ast_translate(audiohook->trans_pvt, read_frame, 1);
467 } else {
468 final_frame = read_frame;
469 }
470
471 return final_frame;
472}
static struct ast_frame * audiohook_read_frame_single(struct ast_audiohook *audiohook, size_t samples, enum ast_audiohook_direction direction)
Definition: audiohook.c:223
static struct ast_frame * audiohook_read_frame_both(struct ast_audiohook *audiohook, size_t samples, struct ast_frame **read_reference, struct ast_frame **write_reference)
Definition: audiohook.c:257

References ao2_replace, AST_AUDIOHOOK_COMPATIBLE, AST_AUDIOHOOK_DIRECTION_BOTH, ast_format_cache_get_slin_by_rate(), ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_sample_rate(), ast_frfree, ast_test_flag, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), audiohook_read_frame_both(), audiohook_read_frame_single(), audiohook_set_internal_rate(), ast_audiohook::format, ast_audiohook::hook_internal_samp_rate, NULL, read_frame(), and ast_audiohook::trans_pvt.

Referenced by ast_audiohook_read_frame(), and ast_audiohook_read_frame_all().

◆ audiohook_read_frame_single()

static struct ast_frame * audiohook_read_frame_single ( struct ast_audiohook audiohook,
size_t  samples,
enum ast_audiohook_direction  direction 
)
static

Definition at line 223 of file audiohook.c.

224{
225 struct ast_slinfactory *factory = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook->read_factory : &audiohook->write_factory);
226 int vol = (direction == AST_AUDIOHOOK_DIRECTION_READ ? audiohook->options.read_volume : audiohook->options.write_volume);
227 short buf[samples];
228 struct ast_frame frame = {
230 .subclass.format = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate),
231 .data.ptr = buf,
232 .datalen = sizeof(buf),
233 .samples = samples,
234 };
235
236 /* Ensure the factory is able to give us the samples we want */
237 if (samples > ast_slinfactory_available(factory)) {
238 return NULL;
239 }
240
241 /* Read data in from factory */
242 if (!ast_slinfactory_read(factory, buf, samples)) {
243 return NULL;
244 }
245
246 if (SHOULD_MUTE(audiohook, direction)) {
247 /* Swap frame data for zeros if mute is required */
248 ast_frame_clear(&frame);
249 } else if (vol) {
250 /* If a volume adjustment needs to be applied apply it */
251 ast_frame_adjust_volume(&frame, vol);
252 }
253
254 return ast_frdup(&frame);
255}
#define SHOULD_MUTE(hook, dir)
Definition: audiohook.c:162
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int ast_frame_clear(struct ast_frame *frame)
Clear all audio samples from an ast_frame. The frame must be AST_FRAME_VOICE and AST_FORMAT_SLINEAR.
Definition: main/frame.c:859
int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
Adjusts the volume of the audio samples contained in a frame.
Definition: main/frame.c:787

References AST_AUDIOHOOK_DIRECTION_READ, ast_format_cache_get_slin_by_rate(), ast_frame_adjust_volume(), ast_frame_clear(), AST_FRAME_VOICE, ast_frdup, ast_slinfactory_available(), ast_slinfactory_read(), buf, ast_frame::frametype, ast_audiohook::hook_internal_samp_rate, NULL, ast_audiohook::options, ast_audiohook::read_factory, ast_audiohook_options::read_volume, ast_frame::samples, SHOULD_MUTE, ast_audiohook::write_factory, and ast_audiohook_options::write_volume.

Referenced by audiohook_read_frame_helper().

◆ audiohook_set_internal_rate()

static int audiohook_set_internal_rate ( struct ast_audiohook audiohook,
int  rate,
int  reset 
)
static

Definition at line 70 of file audiohook.c.

71{
72 struct ast_format *slin;
73
74 if (audiohook->hook_internal_samp_rate == rate) {
75 return 0;
76 }
77
78 audiohook->hook_internal_samp_rate = rate;
79
81
82 /* Setup the factories that are needed for this audiohook type */
83 switch (audiohook->type) {
86 if (reset) {
89 }
92 break;
93 default:
94 break;
95 }
96
97 return 0;
98}
int ast_slinfactory_init_with_format(struct ast_slinfactory *sf, struct ast_format *slin_out)
Initialize a slinfactory.
Definition: slinfactory.c:46

References AST_AUDIOHOOK_TYPE_SPY, AST_AUDIOHOOK_TYPE_WHISPER, ast_format_cache_get_slin_by_rate(), ast_slinfactory_destroy(), ast_slinfactory_init_with_format(), ast_audiohook::hook_internal_samp_rate, ast_audiohook::read_factory, ast_audiohook::type, and ast_audiohook::write_factory.

Referenced by ast_audiohook_attach(), ast_audiohook_init(), audiohook_list_set_hook_rate(), and audiohook_read_frame_helper().

◆ audiohook_volume_callback()

static int audiohook_volume_callback ( struct ast_audiohook audiohook,
struct ast_channel chan,
struct ast_frame frame,
enum ast_audiohook_direction  direction 
)
static

Helper function which actually gets called by audiohooks to perform the adjustment.

Parameters
audiohookAudiohook attached to the channel
chanChannel we are attached to
frameFrame of audio we want to manipulate
directionDirection the audio came in from
Return values
0on success
-1on failure

Definition at line 1247 of file audiohook.c.

1248{
1249 struct ast_datastore *datastore = NULL;
1251 int *gain = NULL;
1252
1253 /* If the audiohook is shutting down don't even bother */
1255 return 0;
1256 }
1257
1258 /* Try to find the datastore containg adjustment information, if we can't just bail out */
1259 if (!(datastore = ast_channel_datastore_find(chan, &audiohook_volume_datastore, NULL))) {
1260 return 0;
1261 }
1262
1263 audiohook_volume = datastore->data;
1264
1265 /* Based on direction grab the appropriate adjustment value */
1270 }
1271
1272 /* If an adjustment value is present modify the frame */
1273 if (gain && *gain) {
1274 ast_frame_adjust_volume(frame, *gain);
1275 }
1276
1277 return 0;
1278}
static const struct ast_datastore_info audiohook_volume_datastore
Datastore used to store audiohook volume information.
Definition: audiohook.c:1234
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2418
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
struct ast_audiohook audiohook
Definition: audiohook.c:1212

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_DIRECTION_WRITE, AST_AUDIOHOOK_STATUS_DONE, ast_channel_datastore_find(), ast_frame_adjust_volume(), audiohook_volume::audiohook, audiohook_volume_datastore, ast_datastore::data, NULL, audiohook_volume::read_adjustment, ast_audiohook::status, and audiohook_volume::write_adjustment.

Referenced by audiohook_volume_get().

◆ audiohook_volume_destroy()

static void audiohook_volume_destroy ( void *  data)
static

Callback used to destroy the audiohook volume datastore.

Parameters
dataVolume information structure

Definition at line 1220 of file audiohook.c.

1221{
1222 struct audiohook_volume *audiohook_volume = data;
1223
1224 /* Destroy the audiohook as it is no longer in use */
1226
1227 /* Finally free ourselves, we are of no more use */
1229
1230 return;
1231}
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
Definition: audiohook.c:124

References ast_audiohook_destroy(), ast_free, and audiohook_volume::audiohook.

◆ audiohook_volume_get()

static struct audiohook_volume * audiohook_volume_get ( struct ast_channel chan,
int  create 
)
static

Helper function which finds and optionally creates an audiohook_volume_datastore datastore on a channel.

Parameters
chanChannel to look on
createWhether to create the datastore if not found
Returns
audiohook_volume structure on success
Return values
NULLon failure

Definition at line 1286 of file audiohook.c.

1287{
1288 struct ast_datastore *datastore = NULL;
1290
1291 /* If we are able to find the datastore return the contents (which is actually an audiohook_volume structure) */
1292 if ((datastore = ast_channel_datastore_find(chan, &audiohook_volume_datastore, NULL))) {
1293 return datastore->data;
1294 }
1295
1296 /* If we are not allowed to create a datastore or if we fail to create a datastore, bail out now as we have nothing for them */
1297 if (!create || !(datastore = ast_datastore_alloc(&audiohook_volume_datastore, NULL))) {
1298 return NULL;
1299 }
1300
1301 /* Create a new audiohook_volume structure to contain our adjustments and audiohook */
1302 if (!(audiohook_volume = ast_calloc(1, sizeof(*audiohook_volume)))) {
1303 ast_datastore_free(datastore);
1304 return NULL;
1305 }
1306
1307 /* Setup our audiohook structure so we can manipulate the audio */
1310
1311 /* Attach the audiohook_volume blob to the datastore and attach to the channel */
1312 datastore->data = audiohook_volume;
1313 ast_channel_datastore_add(chan, datastore);
1314
1315 /* All is well... put the audiohook into motion */
1317
1318 return audiohook_volume;
1319}
static int audiohook_volume_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
Helper function which actually gets called by audiohooks to perform the adjustment.
Definition: audiohook.c:1247
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.
Definition: audiohook.c:100
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2404
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68

References ast_audiohook_attach(), ast_audiohook_init(), AST_AUDIOHOOK_MANIPULATE_ALL_RATES, AST_AUDIOHOOK_TYPE_MANIPULATE, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), audiohook_volume::audiohook, audiohook_volume_callback(), audiohook_volume_datastore, ast_datastore::data, ast_audiohook::manipulate_callback, and NULL.

Referenced by ast_audiohook_volume_adjust(), ast_audiohook_volume_get(), and ast_audiohook_volume_set().

◆ dtmf_audiohook_write_list()

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

Pass a DTMF 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 786 of file audiohook.c.

787{
788 struct ast_audiohook *audiohook = NULL;
789 int removed = 0;
790
791 AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
792 ast_audiohook_lock(audiohook);
793 if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
795 removed = 1;
797 ast_audiohook_unlock(audiohook);
798 audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
799 if (ast_channel_is_bridged(chan)) {
801 }
802 continue;
803 }
804 if (ast_test_flag(audiohook, AST_AUDIOHOOK_WANTS_DTMF)) {
805 audiohook->manipulate_callback(audiohook, chan, frame, direction);
806 }
807 ast_audiohook_unlock(audiohook);
808 }
810
811 /* if an audiohook got removed, reset samplerate compatibility */
812 if (removed) {
814 }
815 return frame;
816}
@ AST_AUDIOHOOK_WANTS_DTMF
Definition: audiohook.h:58

References ast_audiohook_lock, AST_AUDIOHOOK_STATUS_DONE, AST_AUDIOHOOK_STATUS_RUNNING, ast_audiohook_unlock, ast_audiohook_update_status(), AST_AUDIOHOOK_WANTS_DTMF, ast_channel_is_bridged(), ast_channel_set_unbridged_nolock(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_test_flag, audiohook_list_set_samplerate_compatibility(), ast_audiohook::list, ast_audiohook::manipulate_callback, ast_audiohook_list::manipulate_list, NULL, and ast_audiohook::status.

Referenced by ast_audiohook_write_list().

◆ find_audiohook_by_source()

static struct ast_audiohook * find_audiohook_by_source ( struct ast_audiohook_list audiohook_list,
const char *  source 
)
static

find an audiohook based on its source

Parameters
audiohook_listThe list of audiohooks to search in
sourceThe source of the audiohook we wish to find
Returns
corresponding audiohook
Return values
NULLif it cannot be found

Definition at line 640 of file audiohook.c.

641{
642 struct ast_audiohook *audiohook = NULL;
643
644 AST_LIST_TRAVERSE(&audiohook_list->spy_list, audiohook, list) {
645 if (!strcasecmp(audiohook->source, source)) {
646 return audiohook;
647 }
648 }
649
650 AST_LIST_TRAVERSE(&audiohook_list->whisper_list, audiohook, list) {
651 if (!strcasecmp(audiohook->source, source)) {
652 return audiohook;
653 }
654 }
655
656 AST_LIST_TRAVERSE(&audiohook_list->manipulate_list, audiohook, list) {
657 if (!strcasecmp(audiohook->source, source)) {
658 return audiohook;
659 }
660 }
661
662 return NULL;
663}

References AST_LIST_TRAVERSE, ast_audiohook::list, ast_audiohook_list::manipulate_list, NULL, ast_audiohook::source, ast_audiohook_list::spy_list, and ast_audiohook_list::whisper_list.

Referenced by ast_audiohook_detach_source(), ast_audiohook_move_by_source(), and ast_audiohook_set_mute().

Variable Documentation

◆ audiohook_volume_datastore

const struct ast_datastore_info audiohook_volume_datastore
static
Initial value:
= {
.type = "Volume",
}
static void audiohook_volume_destroy(void *data)
Callback used to destroy the audiohook volume datastore.
Definition: audiohook.c:1220

Datastore used to store audiohook volume information.

Definition at line 1234 of file audiohook.c.

Referenced by audiohook_volume_callback(), and audiohook_volume_get().