52 #define PLAYBACK_BUCKETS 127 55 #define PLAYBACK_DEFAULT_SKIPMS 3000 57 #define SOUND_URI_SCHEME "sound:" 58 #define RECORDING_URI_SCHEME "recording:" 59 #define NUMBER_URI_SCHEME "number:" 60 #define DIGITS_URI_SCHEME "digits:" 61 #define CHARACTERS_URI_SCHEME "characters:" 62 #define TONE_URI_SCHEME "tone:" 92 unsigned int controllable:1;
104 if (!strcmp(state,
"playing")) {
105 type =
"PlaybackStarted";
106 }
else if (!strcmp(state,
"continuing")) {
107 type =
"PlaybackContinuing";
108 }
else if (!strcmp(state,
"done")) {
109 type =
"PlaybackFinished";
168 playback->control = control;
177 const char *
id = flags &
OBJ_KEY ? obj : playback->
id;
185 const char *rhs_id = flags &
OBJ_KEY ? arg : rhs->
id;
187 if (strcmp(lhs->
id, rhs_id) == 0) {
241 const char *uniqueid)
248 uniqueid, playback->
media);
260 long playedms,
int res,
const char *uniqueid)
264 playback->playedms = playedms;
274 uniqueid, playback->
media);
277 uniqueid, playback->
media);
295 const char *fwd =
NULL;
296 const char *rev =
NULL;
298 const char *pause =
NULL;
299 const char *restart =
NULL;
307 offsetms = playback->offsetms;
310 playback->media_index = index;
321 playback->controllable = 1;
325 fwd, rev, stop, pause, restart, playback->skipms, playback->
language,
331 const char *relname =
336 ast_log(
LOG_ERROR,
"Attempted to play recording '%s' on channel '%s' but recording does not exist",
341 playback->controllable = 1;
345 restart, playback->skipms, playback->
language, &offsetms);
350 ast_log(
LOG_ERROR,
"Attempted to play number '%s' on channel '%s' but number is invalid",
363 playback->controllable = 1;
367 ast_log(
LOG_ERROR,
"Attempted to play URI '%s' on channel '%s' but scheme is unsupported\n",
391 const char *playback_id)
454 const char *target_id)
457 switch (target_type) {
473 size_t media_count,
const char *
language,
const char *target_id,
475 int skipms,
long offsetms,
const char *
id)
480 if (skipms < 0 || offsetms < 0 || media_count == 0) {
489 for (i = 0; i < media_count; i++) {
493 ast_log(
LOG_ERROR,
"Attempted to play media on channel '%s' but no media URI was provided.\n",
505 ast_debug(3,
"%s: Sending play(%s) command\n",
509 strcpy(media_uri, media[i]);
524 playback->skipms =
skipms;
525 playback->offsetms = offsetms;
540 return control->state;
560 if (playback ==
NULL) {
567 "media_uri", playback->
media,
568 "target_uri", playback->
target,
574 "media_uri", playback->
media,
575 "next_media_uri",
AST_VECTOR_GET(&playback->medias, playback->media_index + 1),
576 "target_uri", playback->
target,
602 if (!playback->controllable) {
615 if (!playback->controllable) {
627 if (!playback->controllable) {
642 if (!playback->controllable) {
657 if (!playback->controllable) {
669 if (!playback->controllable) {
732 "Unhandled operation during playback: %u\n",
738 return cb(playback) ?
772 .requires =
"res_stasis,res_stasis_recording" #define AST_VECTOR_FREE(vec)
Deallocates this vector.
enum stasis_playback_oper_results stasis_app_playback_operation(struct stasis_app_playback *playback, enum stasis_app_playback_media_operation operation)
Controls the media for a given playback operation.
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
enum sip_cc_notify_state state
void stasis_app_control_publish(struct stasis_app_control *control, struct stasis_message *message)
Publish a message to the control's channel's topic.
Stasis Application Recording API. See StasisApplication API" for detailed documentation.
Main Channel structure associated with a channel.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Asterisk main include file. File version handling, generic pbx functions.
static void set_target_uri(struct stasis_app_playback *playback, enum stasis_app_playback_target_type target_type, const char *target_id)
static int playback_restart(struct stasis_app_playback *playback)
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
stasis_app_playback_target_type
static int playback_cmp(void *obj, void *arg, int flags)
stasis_app_playback_media_operation
int ast_control_streamfile_lang(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, const char *lang, long *offsetms)
Version of ast_control_streamfile() which allows the language of the media file to be specified...
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
static int playback_cancel(struct stasis_app_playback *playback)
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
static void play_on_channel_in_bridge(struct ast_bridge_channel *bridge_channel, const char *playback_id)
Special case code to play while a channel is in a bridge.
static struct ao2_container * playbacks
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
static void playback_dtor(void *obj)
Universally unique identifier support.
static int playback_reverse(struct stasis_app_playback *playback)
const char * stasis_app_stored_recording_get_file(struct stasis_app_stored_recording *recording)
Returns the filename for this recording, for use with streamfile.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
int ast_control_tone(struct ast_channel *chan, const char *tone)
Controls playback of a tone.
ast_channel_state
ast_channel states
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
enum stasis_app_playback_state stasis_app_playback_get_state(struct stasis_app_playback *control)
Gets the current state of a playback operation.
STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type,.to_json=playback_to_json,)
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
struct ast_bridge_channel * bridge_find_channel(struct ast_bridge *bridge, struct ast_channel *chan)
#define PLAYBACK_DEFAULT_SKIPMS
Structure containing callbacks for Stasis message sanitization.
const char * stasis_app_playback_get_id(struct stasis_app_playback *control)
Gets the unique id of a playback object.
const ast_string_field target
const ast_string_field id
Blob of data associated with a channel.
#define ast_strlen_zero(foo)
static int playback_first_update(struct stasis_app_playback *playback, const char *uniqueid)
const ast_string_field media
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
static const char * state_to_string(enum stasis_app_playback_state state)
Asterisk file paths, configured in asterisk.conf.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
struct stasis_app_playback * stasis_app_playback_find_by_id(const char *id)
Finds the playback object with the given id.
#define DIGITS_URI_SCHEME
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
static int playback_unpause(struct stasis_app_playback *playback)
struct stasis_message_type * stasis_app_playback_snapshot_type(void)
Message type for playback updates. The data is an ast_channel_blob.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
#define ast_malloc(len)
A wrapper for malloc()
int stasis_app_send_command_async(struct stasis_app_control *control, stasis_app_command_cb command, void *data, command_data_destructor_fn data_destructor)
Asynchronous version of stasis_app_send_command().
#define AST_VECTOR(name, type)
Define a vector structure.
int ast_say_character_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
function to pronounce character and phonetic strings
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
#define CHARACTERS_URI_SCHEME
playback_opreation_cb operations[STASIS_PLAYBACK_STATE_MAX][STASIS_PLAYBACK_MEDIA_OP_MAX]
A sparse array detailing how commands should be handled in the various playback states. Unset entries imply invalid operations.
static struct ast_json * playback_to_json(struct stasis_message *message, const struct stasis_message_sanitizer *sanitize)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
stasis_playback_oper_results
Structure that contains information about a bridge.
static void remove_from_playbacks(void *data)
RAII_VAR function to remove a playback from the global list when leaving scope.
Backend API for implementing components of res_stasis.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
const char * stasis_app_control_get_channel_id(const struct stasis_app_control *control)
Returns the uniqueid of the channel associated with this control.
static void play_on_channel(struct stasis_app_playback *playback, struct ast_channel *chan)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_app_playback * stasis_app_control_play_uri(struct stasis_app_control *control, const char **media, size_t media_count, const char *language, const char *target_id, enum stasis_app_playback_target_type target_type, int skipms, long offsetms, const char *id)
Play a file to the control's channel.
#define ao2_alloc(data_size, destructor_fn)
int(* playback_opreation_cb)(struct stasis_app_playback *playback)
#define NUMBER_URI_SCHEME
#define ast_bridge_unlock(bridge)
Unlock the bridge.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
static int play_uri(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Module has failed to load, may be in an inconsistent state.
static int playback_pause(struct stasis_app_playback *playback)
#define ao2_find(container, arg, flags)
static int load_module(void)
static int unload_module(void)
static int playback_stop(struct stasis_app_playback *playback)
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
static struct stasis_app_playback * playback_create(struct stasis_app_control *control, const char *id)
static int playback_forward(struct stasis_app_playback *playback)
Support for logging to various files, console and syslog Configuration in file logger.conf.
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",)
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
#define RECORDING_URI_SCHEME
#define ast_bridge_lock(bridge)
Lock the bridge.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
struct ast_channel * chan
Structure that contains information regarding a channel in a bridge.
Stasis Application Playback API. See StasisApplication API" for detailed documentation.
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
const char * ast_channel_name(const struct ast_channel *chan)
struct stasis_app_stored_recording * stasis_app_stored_recording_find_by_name(const char *name)
Creates a stored recording object, with the given name.
int stasis_app_control_queue_control(struct stasis_app_control *control, enum ast_control_frame_type frame_type)
Queue a control frame without payload.
stasis_app_playback_state
#define ao2_unlink_flags(container, obj, flags)
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
static void playback_publish(struct stasis_app_playback *playback)
Abstract JSON element (object, array, string, int, ...).
static void playback_final_update(struct stasis_app_playback *playback, long playedms, int res, const char *uniqueid)
int ast_bridge_channel_queue_playfile_sync(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
Synchronously queue a bridge action play file frame onto the bridge channel.
const ast_string_field language
static int playback_noop(struct stasis_app_playback *playback)
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ast_json * stasis_app_playback_to_json(const struct stasis_app_playback *playback)
Convert a playback to its JSON representation.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
static int playback_hash(const void *obj, int flags)
#define ao2_link(container, obj)