[asterisk-commits] dlee: branch dlee/playback r387765 - in /team/dlee/playback: include/asterisk...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 6 12:45:49 CDT 2013
Author: dlee
Date: Mon May 6 12:45:47 2013
New Revision: 387765
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387765
Log:
Better playback abstraction for res_stasis
Modified:
team/dlee/playback/include/asterisk/stasis_app_playback.h
team/dlee/playback/res/res_stasis_playback.c
team/dlee/playback/res/stasis_http/resource_channels.c
team/dlee/playback/rest-api/api-docs/events.json
Modified: team/dlee/playback/include/asterisk/stasis_app_playback.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/include/asterisk/stasis_app_playback.h?view=diff&rev=387765&r1=387764&r2=387765
==============================================================================
--- team/dlee/playback/include/asterisk/stasis_app_playback.h (original)
+++ team/dlee/playback/include/asterisk/stasis_app_playback.h Mon May 6 12:45:47 2013
@@ -65,7 +65,7 @@
* \return Playback control object.
* \return \c NULL on error.
*/
-struct stasis_app_playback *stasis_app_control_play_file(
+struct stasis_app_playback *stasis_app_control_play_uri(
struct stasis_app_control *control, const char *file,
const char *language);
Modified: team/dlee/playback/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/res_stasis_playback.c?view=diff&rev=387765&r1=387764&r2=387765
==============================================================================
--- team/dlee/playback/res/res_stasis_playback.c (original)
+++ team/dlee/playback/res/res_stasis_playback.c Mon May 6 12:45:47 2013
@@ -44,6 +44,9 @@
/*! Number of hash buckets for playback container. Keep it prime! */
#define PLAYBACK_BUCKETS 127
+#define SOUND_URI_SCHEME "sound:"
+#define RECORDING_URI_SCHEME "recording:"
+
/*! Container of all current playbacks */
static struct ao2_container *playbacks;
@@ -51,7 +54,7 @@
struct stasis_app_playback {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(id); /*!< Playback unique id */
- AST_STRING_FIELD(file); /*!< Playback file */
+ AST_STRING_FIELD(media); /*!< Playback media uri */
AST_STRING_FIELD(language); /*!< Preferred language */
);
/*! Current playback state */
@@ -78,12 +81,26 @@
}
}
-static void *__app_control_play_file(struct stasis_app_control *control,
+static void playback_cleanup(struct stasis_app_playback *playback)
+{
+ ao2_lock(playback);
+ playback->state = STASIS_PLAYBACK_COMPLETE;
+ ao2_unlock(playback);
+
+ ao2_unlink_flags(playbacks, playback,
+ OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+}
+
+static void *__app_control_play_uri(struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
- RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_app_playback *, playback, NULL,
+ playback_cleanup);
+ const char *file;
int res;
+
playback = data;
+ ast_assert(playback != NULL);
ao2_lock(playback);
playback->state = STASIS_PLAYBACK_PLAYING;
@@ -92,49 +109,56 @@
if (ast_channel_state(chan) != AST_STATE_UP) {
ast_answer(chan);
}
- res = ast_streamfile(chan, playback->file, playback->language);
+
+ if (ast_begins_with(playback->media, SOUND_URI_SCHEME)) {
+ /* Play sound */
+ file = playback->media + strlen(SOUND_URI_SCHEME);
+ } else if (ast_begins_with(playback->media, RECORDING_URI_SCHEME)) {
+ /* Play recording */
+ file = playback->media + strlen(RECORDING_URI_SCHEME);
+ } else {
+ /* Play URL */
+ ast_log(LOG_ERROR, "Unimplemented\n");
+ return NULL;
+ }
+
+ res = ast_streamfile(chan, file, playback->language);
if (res == 0) {
res = ast_waitstream(chan, "");
ast_stopstream(chan);
}
if (res != 0) {
ast_log(LOG_WARNING, "%s: Playback failed for %s",
- ast_channel_uniqueid(chan), playback->file);
- }
-
- ao2_lock(playback);
- playback->state = STASIS_PLAYBACK_COMPLETE;
- ao2_unlock(playback);
-
- ao2_unlink_flags(playbacks, playback,
- OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+ ast_channel_uniqueid(chan), playback->media);
+ }
+
return NULL;
}
-struct stasis_app_playback *stasis_app_control_play_file(
- struct stasis_app_control *control, const char *file,
+struct stasis_app_playback *stasis_app_control_play_uri(
+ struct stasis_app_control *control, const char *uri,
const char *language)
{
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
char id[AST_UUID_STR_LEN];
ast_debug(3, "%s: Sending play(%s) command\n",
- stasis_app_control_get_channel_id(control), file);
-
- playback = ao2_alloc(sizeof(*playback) + strlen(file) + 1, NULL);
+ stasis_app_control_get_channel_id(control), uri);
+
+ playback = ao2_alloc(sizeof(*playback) + strlen(uri) + 1, NULL);
if (!playback || ast_string_field_init(playback, 128) ){
return NULL;
}
ast_uuid_generate_str(id, sizeof(id));
ast_string_field_set(playback, id, id);
- ast_string_field_set(playback, file, file);
+ ast_string_field_set(playback, media, uri);
ast_string_field_set(playback, language, language);
ao2_link(playbacks, playback);
ao2_ref(playback, +1);
stasis_app_send_command_async(
- control, __app_control_play_file, playback);
+ control, __app_control_play_uri, playback);
ao2_ref(playback, +1);
return playback;
Modified: team/dlee/playback/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/stasis_http/resource_channels.c?view=diff&rev=387765&r1=387764&r2=387765
==============================================================================
--- team/dlee/playback/res/stasis_http/resource_channels.c (original)
+++ team/dlee/playback/res/stasis_http/resource_channels.c Mon May 6 12:45:47 2013
@@ -137,9 +137,6 @@
ast_log(LOG_ERROR, "TODO: stasis_http_unhold_channel\n");
}
-#define SOUND_URI_SCHEME "sound:"
-#define RECORDING_URI_SCHEME "recording:"
-
void stasis_http_play_on_channel(struct ast_variable *headers,
struct ast_play_on_channel_args *args,
struct stasis_http_response *response)
@@ -148,7 +145,6 @@
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
RAII_VAR(char *, playback_url, NULL, ast_free);
- const char *file;
const char *language;
ast_assert(response != NULL);
@@ -169,20 +165,7 @@
language = S_OR(args->lang, snapshot->language);
- if (ast_begins_with(args->media, SOUND_URI_SCHEME)) {
- /* Play sound */
- file = args->media + strlen(SOUND_URI_SCHEME);
- } else if (ast_begins_with(args->media, RECORDING_URI_SCHEME)) {
- /* Play recording */
- file = args->media + strlen(RECORDING_URI_SCHEME);
- } else {
- /* Play URL */
- stasis_http_response_error(response, 501, "Not Implemented",
- "URL Playback not implemented");
- return;
- }
-
- playback = stasis_app_control_play_file(control, file, language);
+ playback = stasis_app_control_play_uri(control, args->media, language);
if (!playback) {
stasis_http_response_error(
response, 500, "Internal Server Error",
Modified: team/dlee/playback/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/rest-api/api-docs/events.json?view=diff&rev=387765&r1=387764&r2=387765
==============================================================================
--- team/dlee/playback/rest-api/api-docs/events.json (original)
+++ team/dlee/playback/rest-api/api-docs/events.json Mon May 6 12:45:47 2013
@@ -74,10 +74,6 @@
"type": "Playback",
"description": "Playback control object",
"required": true
- },
- "channel": {
- "type": "Channel",
- "required": true
}
}
},
@@ -86,13 +82,9 @@
"description": "Event showing the completion of a media playback operation.",
"properties": {
"playback": {
- "type": "Playback"
- },
- "channel": {
- "type": "Channel"
- },
- "media_uri": {
- "type": "string"
+ "type": "Playback",
+ "description": "Playback control object",
+ "required": true
}
}
},
More information about the asterisk-commits
mailing list