44 #define SNOOP_INTERVAL 20 123 if (!blob || !type) {
133 if (!snoop_snapshot) {
139 if (spyee_snapshot) {
208 return frame ? frame : &snoop->
silence;
241 if (snoop->
chan != oldchan) {
247 snoop->
chan = newchan;
255 .description =
"Snoop Channel Driver",
311 const char *
app,
const char *app_args,
const char *snoop_id)
352 snoop->chan =
ast_channel_alloc(1,
AST_STATE_UP,
"",
"",
"",
"",
"", &assignedids,
NULL, 0,
"Snoop/%s-%08x",
ast_channel_uniqueid(chan),
391 snoop->spy_active = 1;
394 snoop->silence.datalen = snoop->spy_samples *
sizeof(uint16_t),
395 snoop->silence.samples = snoop->spy_samples,
396 snoop->silence.mallocd = 0,
397 snoop->silence.offset = 0,
398 snoop->silence.src = __PRETTY_FUNCTION__,
399 snoop->silence.subclass.format = snoop->spy_format,
400 snoop->silence.data.ptr =
ast_calloc(snoop->spy_samples,
sizeof(uint16_t));
401 if (!snoop->silence.data.ptr) {
414 snoop->whisper_active = 1;
450 .requires =
"res_stasis",
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.
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
struct ast_str * app
Stasis application and arguments.
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#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.
static void publish_chanspy_message(struct stasis_app_snoop *snoop, int start)
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
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.
#define ao2_alloc_options(data_size, destructor_fn, options)
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.
#define ast_pthread_create_detached_background(a, b, c, d)
static struct ast_frame * snoop_read(struct ast_channel *chan)
Callback function for reading from a Snoop channel.
static int unload_module(void)
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
static int snoop_write(struct ast_channel *chan, struct ast_frame *frame)
Callback function for writing to a Snoop whisper audiohook.
#define ast_strlen_zero(foo)
void ast_frame_dtor(struct ast_frame *frame)
NULL-safe wrapper for ast_frfree, good for RAII_VAR.
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
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.
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Asterisk JSON abstraction layer.
struct ast_channel * chan
Snoop channel.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
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 ast_channel_cleanup(c)
Cleanup a channel reference.
#define ao2_ref(o, delta)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
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.
const char * ast_channel_uniqueid(const struct ast_channel *chan)
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.
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Backend API for implementing components of res_stasis.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
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.
static int snoop_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
#define ast_channel_unlock(chan)
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
#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...
static const char * stasis
Dialplan application name.
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.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
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.
static int load_module(void)
#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...
ast_app: A registered application
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
union ast_frame::@263 data
struct ast_app * pbx_findapp(const char *app)
Look up an application.
#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.
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.
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
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.