39 #include "asterisk/stasis_channels.h"
44 #define SNOOP_INTERVAL 20
101 ast_free(snoop->
app);
113 static void publish_chanspy_message(
struct stasis_app_snoop *snoop,
int start)
123 if (!blob || !type) {
133 if (!snoop_snapshot) {
142 if (spyee_snapshot) {
200 return frame ? frame : &snoop->
silence;
220 publish_chanspy_message(snoop, 0);
224 ast_channel_tech_pvt_set(chan, NULL);
233 if (snoop->
chan != oldchan) {
239 snoop->
chan = newchan;
247 .description =
"Snoop Channel Driver",
251 .fixup = snoop_fixup,
305 const char *app,
const char *app_args,
const char *snoop_id)
311 .uniqueid = snoop_id,
331 if (!ast_strlen_zero(app_args)) {
346 snoop->
chan =
ast_channel_alloc(1,
AST_STATE_UP,
"",
"",
"",
"",
"", &assignedids, NULL, 0,
"Snoop/%s-%08x", ast_channel_uniqueid(chan),
355 ast_channel_tech_set(snoop->
chan, &snoop_tech);
357 ast_channel_tech_pvt_set(snoop->
chan, snoop);
363 ast_channel_unlock(snoop->
chan);
368 ast_channel_nativeformats_set(snoop->
chan, caps);
376 ast_channel_unlock(snoop->
chan);
424 publish_chanspy_message(snoop, 1);
430 static int load_module(
void)
435 static int unload_module(
void)
440 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,
"Stasis application snoop support",
441 .support_level = AST_MODULE_SUPPORT_CORE,
443 .unload = unload_module,
444 .requires =
"res_stasis",
int ast_audiohook_set_frame_feed_direction(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction)
Sets direction on audiohook.
Main Channel structure associated with a channel.
stasis_app_snoop_direction
Directions for audio stream flow.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_audiohook spy
Audiohook used to spy on the channel.
int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction, struct ast_frame *frame)
Writes a frame into the audiohook structure.
struct ast_str * app
Stasis application and arguments.
#define ast_channel_unref(c)
Decrease channel reference count.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Audio stream in from the channel.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
struct ast_audiohook whisper
Audiohook used to whisper on the channel.
Structure representing a snapshot of channel state.
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
Structure to pass both assignedid values to channel drivers.
struct ast_timer * ast_timer_open(void)
Open a timer.
static int snoop_hangup(struct ast_channel *chan)
Callback function for hanging up a Snoop channel.
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Audio stream to AND from the channel.
struct stasis_message_type * ast_channel_chanspy_start_type(void)
Message type for when a channel starts spying on another channel.
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
struct ast_channel * spyee_chan
The channel that the Snoop channel is snooping on.
static struct ast_frame * snoop_read(struct ast_channel *chan)
Callback function for reading from a Snoop channel.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
struct ast_frame_subclass subclass
static int snoop_write(struct ast_channel *chan, struct ast_frame *frame)
Callback function for writing to a Snoop whisper audiohook.
struct ast_json * ast_json_null(void)
Get the JSON null value.
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.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
unsigned int spy_samples
Number of samples to be read in when spying.
Structure which contains all of the snoop information.
enum ast_audiohook_direction spy_direction
Direction for spying.
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
static unsigned int chan_idx
Index used to keep Snoop channel names unique.
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Asterisk JSON abstraction layer.
struct ast_channel * chan
Snoop channel.
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
Add a ast_channel_snapshot to a ast_multi_channel_blob object.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Audio stream out to the channel.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
static void * snoop_stasis_thread(void *obj)
Thread used for running the Stasis application.
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
int ast_pbx_exec_application(struct ast_channel *chan, const char *app_name, const char *app_args)
Execute an application.
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Backend API for implementing components of res_stasis.
Support for dynamic strings.
static struct ast_channel_tech snoop_tech
Channel interface declaration.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
static void snoop_determine_format(struct ast_channel *chan, struct stasis_app_snoop *snoop)
Helper function which gets the format for a Snoop channel based on the channel being snooped on...
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
#define SNOOP_INTERVAL
The interval (in milliseconds) that the Snoop timer is triggered, also controls length of audio withi...
struct ast_channel * stasis_app_control_snoop(struct ast_channel *chan, enum stasis_app_snoop_direction spy, enum stasis_app_snoop_direction whisper, const char *app, const char *app_args, const char *snoop_id)
Create a snoop on the provided channel.
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
struct ast_timer * timer
Timer used for waking up Stasis thread.
unsigned int whisper_active
Whether the whisper capability is active or not.
struct ast_frame ast_null_frame
enum ast_audiohook_direction whisper_direction
Direction for whispering.
#define ast_channel_ref(c)
Increase channel reference count.
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...
Stasis Application Snoop API. See StasisApplication API" for detailed documentation.
A multi channel blob data structure for multi_channel_blob stasis messages.
unsigned int spy_active
Whether the spy capability is active or not.
Data structure associated with a single frame of data.
Abstract JSON element (object, array, string, int, ...).
enum ast_audiohook_status status
enum ast_frame_type frametype
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_audiohook_lock(ah)
Lock an audiohook.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
struct ast_format * spy_format
Format in use by the spy audiohook.
static int snoop_setup_audiohook(struct ast_channel *chan, enum ast_audiohook_type type, enum stasis_app_snoop_direction requested_direction, enum ast_audiohook_direction *direction, struct ast_audiohook *audiohook)
Internal helper function which sets up and attaches a snoop audiohook.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_frame silence
A frame of silence to use when the audiohook returns null.
static void snoop_destroy(void *obj)
Destructor for snoop structure.
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.
Timing source management.
struct ast_multi_channel_blob * ast_multi_channel_blob_create(struct ast_json *blob)
Create a ast_multi_channel_blob suitable for a stasis_message.
struct stasis_message_type * ast_channel_chanspy_stop_type(void)
Message type for when a channel stops spying on another channel.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.