Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
res_stasis playback support. More...
#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/astobj2.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_internal.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/paths.h"
#include "asterisk/stasis_app_impl.h"
#include "asterisk/stasis_app_playback.h"
#include "asterisk/stasis_app_recording.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stringfields.h"
#include "asterisk/uuid.h"
#include "asterisk/say.h"
#include "asterisk/indications.h"
Go to the source code of this file.
Data Structures | |
struct | stasis_app_playback |
Macros | |
#define | CHARACTERS_URI_SCHEME "characters:" |
#define | DIGITS_URI_SCHEME "digits:" |
#define | NUMBER_URI_SCHEME "number:" |
#define | PLAYBACK_BUCKETS 127 |
#define | PLAYBACK_DEFAULT_SKIPMS 3000 |
#define | RECORDING_URI_SCHEME "recording:" |
#define | SOUND_URI_SCHEME "sound:" |
#define | TONE_URI_SCHEME "tone:" |
Typedefs | |
typedef int(* | playback_operation_cb) (struct stasis_app_playback *playback) |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static int | load_module (void) |
static void | play_on_channel (struct stasis_app_playback *playback, struct ast_channel *chan) |
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. More... | |
static int | play_uri (struct stasis_app_control *control, struct ast_channel *chan, void *data) |
static int | playback_cancel (struct stasis_app_playback *playback) |
static int | playback_cmp (void *obj, void *arg, int flags) |
static struct stasis_app_playback * | playback_create (struct stasis_app_control *control, const char *id) |
static void | playback_dtor (void *obj) |
static void | playback_final_update (struct stasis_app_playback *playback, long playedms, int res, int hangup, const char *uniqueid) |
static int | playback_first_update (struct stasis_app_playback *playback, const char *uniqueid) |
static int | playback_forward (struct stasis_app_playback *playback) |
static int | playback_hash (const void *obj, int flags) |
static int | playback_noop (struct stasis_app_playback *playback) |
static int | playback_pause (struct stasis_app_playback *playback) |
static void | playback_publish (struct stasis_app_playback *playback) |
static int | playback_restart (struct stasis_app_playback *playback) |
static int | playback_reverse (struct stasis_app_playback *playback) |
static int | playback_stop (struct stasis_app_playback *playback) |
static struct ast_json * | playback_to_json (struct stasis_message *message, const struct stasis_message_sanitizer *sanitize) |
static int | playback_unpause (struct stasis_app_playback *playback) |
static void | remove_from_playbacks (void *data) |
RAII_VAR function to remove a playback from the global list when leaving scope. More... | |
static void | set_target_uri (struct stasis_app_playback *playback, enum stasis_app_playback_target_type target_type, const char *target_id) |
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. More... | |
struct stasis_app_playback * | stasis_app_playback_find_by_id (const char *id) |
Finds the playback object with the given id. More... | |
const char * | stasis_app_playback_get_id (struct stasis_app_playback *control) |
Gets the unique id of a playback object. More... | |
enum stasis_app_playback_state | stasis_app_playback_get_state (struct stasis_app_playback *control) |
Gets the current state of a playback operation. More... | |
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. More... | |
struct ast_json * | stasis_app_playback_to_json (const struct stasis_app_playback *playback) |
Convert a playback to its JSON representation. More... | |
STASIS_MESSAGE_TYPE_DEFN (stasis_app_playback_snapshot_type,.to_json=playback_to_json,) | |
static const char * | state_to_string (enum stasis_app_playback_state state) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "Stasis application playback support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_stasis,res_stasis_recording" } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
playback_operation_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. More... | |
static struct ao2_container * | playbacks |
res_stasis playback support.
Definition in file res_stasis_playback.c.
#define CHARACTERS_URI_SCHEME "characters:" |
Definition at line 61 of file res_stasis_playback.c.
#define DIGITS_URI_SCHEME "digits:" |
Definition at line 60 of file res_stasis_playback.c.
#define NUMBER_URI_SCHEME "number:" |
Definition at line 59 of file res_stasis_playback.c.
#define PLAYBACK_BUCKETS 127 |
Number of hash buckets for playback container. Keep it prime!
Definition at line 52 of file res_stasis_playback.c.
#define PLAYBACK_DEFAULT_SKIPMS 3000 |
Default number of milliseconds of media to skip
Definition at line 55 of file res_stasis_playback.c.
#define RECORDING_URI_SCHEME "recording:" |
Definition at line 58 of file res_stasis_playback.c.
#define SOUND_URI_SCHEME "sound:" |
Definition at line 57 of file res_stasis_playback.c.
#define TONE_URI_SCHEME "tone:" |
Definition at line 62 of file res_stasis_playback.c.
typedef int(* playback_operation_cb) (struct stasis_app_playback *playback) |
Definition at line 601 of file res_stasis_playback.c.
|
static |
Definition at line 791 of file res_stasis_playback.c.
|
static |
Definition at line 791 of file res_stasis_playback.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 791 of file res_stasis_playback.c.
|
static |
Definition at line 760 of file res_stasis_playback.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, NULL, PLAYBACK_BUCKETS, playback_cmp(), playback_hash(), playbacks, stasis_app_playback_snapshot_type(), STASIS_MESSAGE_TYPE_CLEANUP, and STASIS_MESSAGE_TYPE_INIT.
|
static |
Definition at line 293 of file res_stasis_playback.c.
References ao2_cleanup, ast_assert, ast_begins_with(), ast_channel_name(), ast_channel_uniqueid(), ast_check_hangup(), AST_CONTROL_PROGRESS, AST_CONTROL_STREAM_STOP, ast_control_streamfile_lang(), ast_control_tone(), ast_indicate(), ast_log, AST_SAY_CASE_NONE, ast_say_character_str(), ast_say_digit_str(), ast_say_number(), AST_STATE_UP, ast_string_field_set, AST_VECTOR_GET, AST_VECTOR_SIZE, CHARACTERS_URI_SCHEME, stasis_app_playback::controllable, DIGITS_URI_SCHEME, hangup(), stasis_app_playback::language, LOG_DEBUG, LOG_ERROR, stasis_app_playback::media, stasis_app_playback::media_index, stasis_app_playback::medias, NULL, NUMBER_URI_SCHEME, stasis_app_playback::offsetms, playback_final_update(), playback_first_update(), RAII_VAR, RECORDING_URI_SCHEME, stasis_app_playback::skipms, SOUND_URI_SCHEME, stasis_app_stored_recording_find_by_name(), stasis_app_stored_recording_get_file(), stop, and TONE_URI_SCHEME.
Referenced by play_on_channel_in_bridge(), and play_uri().
|
static |
Special case code to play while a channel is in a bridge.
bridge_channel | The channel's bridge_channel. |
playback_id | Id of the playback to start. |
Definition at line 407 of file res_stasis_playback.c.
References ao2_cleanup, ast_log, ast_bridge_channel::chan, LOG_ERROR, NULL, play_on_channel(), RAII_VAR, and stasis_app_playback_find_by_id().
Referenced by play_uri().
|
static |
Definition at line 435 of file res_stasis_playback.c.
References ao2_bump, ao2_cleanup, ast_bridge_channel_queue_playfile_sync(), ast_bridge_lock, ast_bridge_unlock, ast_bridge_channel::bridge, bridge_find_channel(), ast_bridge_channel::chan, stasis_app_playback::id, NULL, play_on_channel(), play_on_channel_in_bridge(), and stasis_app_get_bridge().
Referenced by stasis_app_control_play_uri().
|
static |
Definition at line 608 of file res_stasis_playback.c.
References lock, SCOPED_AO2LOCK, STASIS_PLAYBACK_STATE_CANCELED, and stasis_app_playback::state.
|
static |
Definition at line 183 of file res_stasis_playback.c.
References CMP_MATCH, CMP_STOP, stasis_app_playback::id, and OBJ_KEY.
Referenced by load_module().
|
static |
Definition at line 142 of file res_stasis_playback.c.
References ao2_alloc, ao2_cleanup, ao2_ref, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_uuid_generate_str(), AST_UUID_STR_LEN, AST_VECTOR_INIT, stasis_app_playback::control, NULL, playback_dtor(), RAII_VAR, and uuid().
Referenced by stasis_app_control_play_uri().
|
static |
Definition at line 126 of file res_stasis_playback.c.
References ao2_cleanup, ast_free, ast_string_field_free_memory, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, stasis_app_playback::control, stasis_app_playback::media, and stasis_app_playback::medias.
Referenced by playback_create().
|
static |
Definition at line 263 of file res_stasis_playback.c.
References ast_log, AST_VECTOR_SIZE, hangup(), lock, LOG_NOTICE, LOG_WARNING, stasis_app_playback::media, stasis_app_playback::media_index, stasis_app_playback::medias, playback_publish(), stasis_app_playback::playedms, SCOPED_AO2LOCK, STASIS_PLAYBACK_STATE_COMPLETE, STASIS_PLAYBACK_STATE_CONTINUING, STASIS_PLAYBACK_STATE_FAILED, STASIS_PLAYBACK_STATE_STOPPED, and stasis_app_playback::state.
Referenced by play_on_channel().
|
static |
Definition at line 244 of file res_stasis_playback.c.
References ast_log, lock, LOG_NOTICE, stasis_app_playback::media, playback_publish(), SCOPED_AO2LOCK, STASIS_PLAYBACK_STATE_CANCELED, STASIS_PLAYBACK_STATE_PLAYING, and stasis_app_playback::state.
Referenced by play_on_channel().
|
static |
Definition at line 682 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_FORWARD, stasis_app_playback::control, stasis_app_playback::controllable, lock, SCOPED_AO2LOCK, and stasis_app_control_queue_control().
|
static |
Definition at line 176 of file res_stasis_playback.c.
References ast_str_hash(), stasis_app_playback::id, and OBJ_KEY.
Referenced by load_module().
|
static |
Definition at line 603 of file res_stasis_playback.c.
|
static |
Definition at line 640 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_SUSPEND, stasis_app_playback::control, stasis_app_playback::controllable, lock, playback_publish(), SCOPED_AO2LOCK, stasis_app_control_queue_control(), STASIS_PLAYBACK_STATE_PAUSED, and stasis_app_playback::state.
|
static |
Definition at line 222 of file res_stasis_playback.c.
References ao2_cleanup, ast_assert, ast_channel_blob_create_from_cache(), ast_json_unref(), stasis_app_playback::control, NULL, RAII_VAR, stasis_app_control_get_channel_id(), stasis_app_control_publish(), stasis_app_playback_snapshot_type(), and stasis_app_playback_to_json().
Referenced by playback_final_update(), playback_first_update(), playback_pause(), playback_unpause(), and stasis_app_control_play_uri().
|
static |
Definition at line 628 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_RESTART, stasis_app_playback::control, stasis_app_playback::controllable, lock, SCOPED_AO2LOCK, and stasis_app_control_queue_control().
|
static |
Definition at line 670 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_REVERSE, stasis_app_playback::control, stasis_app_playback::controllable, lock, SCOPED_AO2LOCK, and stasis_app_control_queue_control().
|
static |
Definition at line 615 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_STOP, stasis_app_playback::control, stasis_app_playback::controllable, lock, SCOPED_AO2LOCK, stasis_app_control_queue_control(), STASIS_PLAYBACK_STATE_STOPPED, and stasis_app_playback::state.
|
static |
Definition at line 95 of file res_stasis_playback.c.
References ast_json_object_get(), ast_json_pack(), ast_json_string_get(), ast_json_timeval(), ast_channel_blob::blob, NULL, stasis_message_data(), stasis_message_timestamp(), and type.
|
static |
Definition at line 655 of file res_stasis_playback.c.
References AST_CONTROL_STREAM_SUSPEND, stasis_app_playback::control, stasis_app_playback::controllable, lock, playback_publish(), SCOPED_AO2LOCK, stasis_app_control_queue_control(), STASIS_PLAYBACK_STATE_PLAYING, and stasis_app_playback::state.
|
static |
RAII_VAR function to remove a playback from the global list when leaving scope.
Definition at line 426 of file res_stasis_playback.c.
References ao2_ref, ao2_unlink_flags, OBJ_NODATA, OBJ_POINTER, OBJ_UNLINK, and playbacks.
Referenced by stasis_app_control_play_uri().
|
static |
Definition at line 468 of file res_stasis_playback.c.
References ast_assert, ast_string_field_build, NULL, STASIS_PLAYBACK_TARGET_BRIDGE, STASIS_PLAYBACK_TARGET_CHANNEL, and type.
Referenced by stasis_app_control_play_uri().
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.
Note that the file isn't the full path to the file. Asterisk's internal playback mechanism will automagically select the best format based on the available codecs for the channel.
control | Control for res_stasis . |
media | Array of const char * media files to play. |
media_count | The number of media files in media . |
language | Selects the file based on language. |
target_id | ID of the target bridge or channel. |
target_type | What the target type is |
skipms | Number of milliseconds to skip for forward/reverse operations. |
offsetms | Number of milliseconds to skip before playing. |
id | ID to assign the new playback or NULL for default. |
NULL | on error. |
Definition at line 488 of file res_stasis_playback.c.
References ao2_bump, ao2_link, ao2_ref, ast_debug, ast_free, ast_log, ast_malloc, ast_string_field_set, ast_strlen_zero(), AST_VECTOR_APPEND, AST_VECTOR_GET, stasis_app_playback::control, language, LOG_ERROR, stasis_app_playback::media, stasis_app_playback::medias, NULL, stasis_app_playback::offsetms, play_uri(), playback_create(), PLAYBACK_DEFAULT_SKIPMS, playback_publish(), playbacks, remove_from_playbacks(), set_target_uri(), skipms, stasis_app_playback::skipms, stasis_app_control_get_channel_id(), stasis_app_send_command_async(), STASIS_PLAYBACK_STATE_QUEUED, and stasis_app_playback::state.
Referenced by ari_bridges_play_helper(), and ari_channels_handle_play().
struct stasis_app_playback * stasis_app_playback_find_by_id | ( | const char * | id | ) |
Finds the playback object with the given id.
id | Id of the playback object to find. |
NULL | if id not found. |
Definition at line 567 of file res_stasis_playback.c.
References ao2_find, OBJ_KEY, and playbacks.
Referenced by ast_ari_playbacks_control(), ast_ari_playbacks_get(), ast_ari_playbacks_stop(), and play_on_channel_in_bridge().
const char * stasis_app_playback_get_id | ( | struct stasis_app_playback * | playback | ) |
Gets the unique id of a playback object.
playback | Playback control object. |
NULL | if playback ic NULL |
Definition at line 560 of file res_stasis_playback.c.
References stasis_app_playback::control.
Referenced by ari_bridges_play_helper(), and ari_channels_handle_play().
enum stasis_app_playback_state stasis_app_playback_get_state | ( | struct stasis_app_playback * | playback | ) |
Gets the current state of a playback operation.
playback | Playback control object. |
Definition at line 553 of file res_stasis_playback.c.
References stasis_app_playback::control, lock, and SCOPED_AO2LOCK.
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.
playback | Playback control object. |
operation | Media control operation. |
STASIS_PLAYBACK_OPER_OK | on success. |
Definition at line 726 of file res_stasis_playback.c.
References ast_assert, ast_log, lock, LOG_ERROR, operations, SCOPED_AO2LOCK, STASIS_PLAYBACK_MEDIA_OP_MAX, STASIS_PLAYBACK_OPER_FAILED, STASIS_PLAYBACK_OPER_NOT_PLAYING, STASIS_PLAYBACK_OPER_OK, STASIS_PLAYBACK_STATE_MAX, STASIS_PLAYBACK_STATE_PLAYING, and stasis_app_playback::state.
Referenced by ast_ari_playbacks_control(), and ast_ari_playbacks_stop().
struct ast_json * stasis_app_playback_to_json | ( | const struct stasis_app_playback * | playback | ) |
Convert a playback to its JSON representation.
playback | The playback object to convert to JSON |
NULL | on error |
Definition at line 572 of file res_stasis_playback.c.
References ast_json_pack(), ast_json_ref(), ast_json_unref(), AST_VECTOR_GET, AST_VECTOR_SIZE, stasis_app_playback::id, stasis_app_playback::language, stasis_app_playback::media, stasis_app_playback::media_index, stasis_app_playback::medias, NULL, RAII_VAR, stasis_app_playback::state, state_to_string(), and stasis_app_playback::target.
Referenced by ari_bridges_play_helper(), ari_channels_handle_play(), ast_ari_playbacks_get(), and playback_publish().
STASIS_MESSAGE_TYPE_DEFN | ( | stasis_app_playback_snapshot_type | , |
. | to_json = playback_to_json |
||
) |
|
static |
Definition at line 196 of file res_stasis_playback.c.
References STASIS_PLAYBACK_STATE_CANCELED, STASIS_PLAYBACK_STATE_COMPLETE, STASIS_PLAYBACK_STATE_CONTINUING, STASIS_PLAYBACK_STATE_FAILED, STASIS_PLAYBACK_STATE_MAX, STASIS_PLAYBACK_STATE_PAUSED, STASIS_PLAYBACK_STATE_PLAYING, STASIS_PLAYBACK_STATE_QUEUED, and STASIS_PLAYBACK_STATE_STOPPED.
Referenced by stasis_app_playback_to_json().
|
static |
Definition at line 778 of file res_stasis_playback.c.
References ao2_cleanup, NULL, playbacks, stasis_app_playback_snapshot_type(), and STASIS_MESSAGE_TYPE_CLEANUP.
|
static |
Definition at line 791 of file res_stasis_playback.c.
|
static |
Definition at line 791 of file res_stasis_playback.c.
A sparse array detailing how commands should be handled in the various playback states. Unset entries imply invalid operations.
Definition at line 698 of file res_stasis_playback.c.
Referenced by stasis_app_playback_operation().
|
static |
Container of all current playbacks
Definition at line 65 of file res_stasis_playback.c.
Referenced by load_module(), remove_from_playbacks(), stasis_app_control_play_uri(), stasis_app_playback_find_by_id(), and unload_module().