[asterisk-commits] dlee: branch dlee/playback r387736 - in /team/dlee/playback: include/asterisk...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 6 11:50:03 CDT 2013


Author: dlee
Date: Mon May  6 11:50:01 2013
New Revision: 387736

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387736
Log:
Playbacks work

Modified:
    team/dlee/playback/include/asterisk/stasis_app_playback.h
    team/dlee/playback/res/res_stasis.c
    team/dlee/playback/res/res_stasis_http_channels.c
    team/dlee/playback/res/res_stasis_playback.c
    team/dlee/playback/res/stasis/control.c
    team/dlee/playback/res/stasis/control.h
    team/dlee/playback/res/stasis_http/resource_channels.c
    team/dlee/playback/res/stasis_http/resource_channels.h
    team/dlee/playback/rest-api/api-docs/channels.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=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/include/asterisk/stasis_app_playback.h (original)
+++ team/dlee/playback/include/asterisk/stasis_app_playback.h Mon May  6 11:50:01 2013
@@ -43,6 +43,16 @@
 	STASIS_PLAYBACK_COMPLETE,
 };
 
+enum stasis_app_playback_media_control {
+	STASIS_PLAYBACK_STOP,
+	STASIS_PLAYBACK_PAUSE,
+	STASIS_PLAYBACK_PLAY,
+	STASIS_PLAYBACK_REWIND,
+	STASIS_PLAYBACK_FAST_FORWARD,
+	STASIS_PLAYBACK_SPEED_UP,
+	STASIS_PLAYBACK_SLOW_DOWN,
+};
+
 /*!
  * \brief Play a file to the control's channel.
  *
@@ -56,18 +66,15 @@
  * \return \c NULL on error.
  */
 struct stasis_app_playback *stasis_app_control_play_file(
-	struct stasis_app_control *control, const char *file);
+	struct stasis_app_control *control, const char *file,
+	const char *language);
 
 enum stasis_app_playback_state stasis_app_playback_get_state(
 	struct stasis_app_playback *control);
 const char *stasis_app_playback_get_id(
 	struct stasis_app_playback *control);
 struct stasis_app_playback *stasis_app_playback_find_by_id(const char *id);
-int stasis_app_playback_stop(struct stasis_app_playback *control);
-int stasis_app_playback_pause(struct stasis_app_playback *control);
-int stasis_app_playback_rewind(struct stasis_app_playback *control);
-int stasis_app_playback_fast_forward(struct stasis_app_playback *control);
-int stasis_app_playback_speed_up(struct stasis_app_playback *control);
-int stasis_app_playback_slow_down(struct stasis_app_playback *control);
+int stasis_app_playback_control(struct stasis_app_playback *playback,
+	enum stasis_app_playback_media_control);
 
 #endif /* _ASTERISK_STASIS_APP_PLAYBACK_H */

Modified: team/dlee/playback/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/res_stasis.c?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/res_stasis.c (original)
+++ team/dlee/playback/res/res_stasis.c Mon May  6 11:50:01 2013
@@ -169,6 +169,7 @@
 	snapshot = stasis_message_data(msg);
 	ast_assert(snapshot != NULL);
 
+	ao2_ref(snapshot, +1);
 	return snapshot;
 }
 
@@ -183,7 +184,7 @@
 	}
 
 	ao2_unlink_flags(app_controls, control,
-			 OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+		OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
 	ao2_cleanup(control);
 }
 
@@ -233,6 +234,7 @@
 	while (!control_is_done(control)) {
 		RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
 		int r;
+		int command_count;
 
 		r = ast_waitfor(chan, MAX_WAIT_MS);
 
@@ -243,6 +245,11 @@
 		}
 
 		control_dispatch_all(control, chan);
+
+		if (command_count > 0 && ast_channel_fdno(chan) == -1) {
+			/* Command drained the channel; wait for next frame */
+			continue;
+		}
 
 		if (r == 0) {
 			/* Timeout */

Modified: team/dlee/playback/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/res_stasis_http_channels.c?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/res_stasis_http_channels.c (original)
+++ team/dlee/playback/res/res_stasis_http_channels.c Mon May  6 11:50:01 2013
@@ -325,6 +325,9 @@
 		if (strcmp(i->name, "media") == 0) {
 			args.media = (i->value);
 		} else
+		if (strcmp(i->name, "lang") == 0) {
+			args.lang = (i->value);
+		} else
 		{}
 	}
 	for (i = path_vars; i; i = i->next) {

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=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/res_stasis_playback.c (original)
+++ team/dlee/playback/res/res_stasis_playback.c Mon May  6 11:50:01 2013
@@ -33,9 +33,12 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/astobj2.h"
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis_app_impl.h"
 #include "asterisk/stasis_app_playback.h"
+#include "asterisk/stringfields.h"
 #include "asterisk/uuid.h"
 
 /*! Number of hash buckets for playback container. Keep it prime! */
@@ -49,6 +52,7 @@
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(id);	/*!< Playback unique id */
 		AST_STRING_FIELD(file);	/*!< Playback file */
+		AST_STRING_FIELD(language);	/*!< Preferred language */
 		);
 	/*! Current playback state */
 	enum stasis_app_playback_state state;
@@ -77,11 +81,39 @@
 static void *__app_control_play_file(struct stasis_app_control *control,
 	struct ast_channel *chan, void *data)
 {
+	RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
+	int res;
+	playback = data;
+
+	ao2_lock(playback);
+	playback->state = STASIS_PLAYBACK_PLAYING;
+	ao2_unlock(playback);
+
+	if (ast_channel_state(chan) != AST_STATE_UP) {
+		ast_answer(chan);
+	}
+	res = ast_streamfile(chan, playback->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);
 	return NULL;
 }
 
 struct stasis_app_playback *stasis_app_control_play_file(
-	struct stasis_app_control *control, const char *file)
+	struct stasis_app_control *control, const char *file,
+	const char *language)
 {
 	RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
 	char id[AST_UUID_STR_LEN];
@@ -97,8 +129,10 @@
 	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, language, language);
 
 	ao2_link(playbacks, playback);
+	ao2_ref(playback, +1);
 	stasis_app_send_command_async(
 		control, __app_control_play_file, playback);
 
@@ -125,44 +159,10 @@
 	return ao2_find(playbacks, id, OBJ_KEY);
 }
 
-int stasis_app_playback_stop(struct stasis_app_playback *control)
+int stasis_app_playback_control(struct stasis_app_playback *playback,
+	enum stasis_app_playback_media_control control)
 {
-	SCOPED_AO2LOCK(lock, control);
-	ast_assert(0); /* TODO */
-	return -1;
-}
-
-int stasis_app_playback_pause(struct stasis_app_playback *control)
-{
-	SCOPED_AO2LOCK(lock, control);
-	ast_assert(0); /* TODO */
-	return -1;
-}
-
-int stasis_app_playback_rewind(struct stasis_app_playback *control)
-{
-	SCOPED_AO2LOCK(lock, control);
-	ast_assert(0); /* TODO */
-	return -1;
-}
-
-int stasis_app_playback_fast_forward(struct stasis_app_playback *control)
-{
-	SCOPED_AO2LOCK(lock, control);
-	ast_assert(0); /* TODO */
-	return -1;
-}
-
-int stasis_app_playback_speed_up(struct stasis_app_playback *control)
-{
-	SCOPED_AO2LOCK(lock, control);
-	ast_assert(0); /* TODO */
-	return -1;
-}
-
-int stasis_app_playback_slow_down(struct stasis_app_playback *control)
-{
-	SCOPED_AO2LOCK(lock, control);
+	SCOPED_AO2LOCK(lock, playback);
 	ast_assert(0); /* TODO */
 	return -1;
 }

Modified: team/dlee/playback/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/stasis/control.c?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/stasis/control.c (original)
+++ team/dlee/playback/res/stasis/control.c Mon May  6 11:50:01 2013
@@ -139,9 +139,10 @@
 	stasis_app_send_command_async(control, app_control_continue, NULL);
 }
 
-void control_dispatch_all(struct stasis_app_control *control,
+int control_dispatch_all(struct stasis_app_control *control,
 	struct ast_channel *chan)
 {
+	int count = 0;
 	struct ao2_iterator i;
 	void *obj;
 
@@ -155,8 +156,10 @@
 	while ((obj = ao2_iterator_next(&i))) {
 		RAII_VAR(struct stasis_app_command *, command, obj, ao2_cleanup);
 		command_invoke(command, control, chan);
+		++count;
 	}
 
 	ao2_iterator_destroy(&i);
+	return count;
 }
 

Modified: team/dlee/playback/res/stasis/control.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/stasis/control.h?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/stasis/control.h (original)
+++ team/dlee/playback/res/stasis/control.h Mon May  6 11:50:01 2013
@@ -43,8 +43,9 @@
  *
  * \param control Control object to dispatch.
  * \param chan Associated channel.
+ * \return Number of commands executed
  */
-void control_dispatch_all(struct stasis_app_control *control,
+int control_dispatch_all(struct stasis_app_control *control,
 	struct ast_channel *chan);
 
 int control_is_done(struct stasis_app_control *control);

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=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/stasis_http/resource_channels.c (original)
+++ team/dlee/playback/res/stasis_http/resource_channels.c Mon May  6 11:50:01 2013
@@ -147,9 +147,9 @@
 	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
-	char *playback_url;
-	char file[PATH_MAX];
-	enum ast_locate_result locate_res;
+	RAII_VAR(char *, playback_url, NULL, ast_free);
+	const char *file;
+	const char *language;
 
 	ast_assert(response != NULL);
 
@@ -167,18 +167,14 @@
 		return;
 	}
 
+	language = S_OR(args->lang, snapshot->language);
+
 	if (ast_begins_with(args->media, SOUND_URI_SCHEME)) {
 		/* Play sound */
-		const char *sound_name = args->media + strlen(SOUND_URI_SCHEME);
-
-		locate_res = ast_locate_sound(file, sizeof(file), sound_name,
-			snapshot->language);
+		file = args->media + strlen(SOUND_URI_SCHEME);
 	} else if (ast_begins_with(args->media, RECORDING_URI_SCHEME)) {
 		/* Play recording */
-		const char *recording_name =
-			args->media + strlen(RECORDING_URI_SCHEME);
-		locate_res = ast_locate_recording(file, sizeof(file),
-			recording_name);
+		file = args->media + strlen(RECORDING_URI_SCHEME);
 	} else {
 		/* Play URL */
 		stasis_http_response_error(response, 501, "Not Implemented",
@@ -186,17 +182,7 @@
 		return;
 	}
 
-	switch (locate_res) {
-	case AST_LOCATE_NOT_FOUND:
-		stasis_http_response_error(response, 406, "Not Acceptable",
-			"%s not found", args->media);
-		return;
-	case AST_LOCATE_FOUND:
-		/* Continues below */
-		break;
-	}
-
-	playback = stasis_app_control_play_file(control, file);
+	playback = stasis_app_control_play_file(control, file, language);
 	if (!playback) {
 		stasis_http_response_error(
 			response, 500, "Internal Server Error",

Modified: team/dlee/playback/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/res/stasis_http/resource_channels.h?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/res/stasis_http/resource_channels.h (original)
+++ team/dlee/playback/res/stasis_http/resource_channels.h Mon May  6 11:50:01 2013
@@ -200,6 +200,8 @@
 	const char *channel_id;
 	/*! \brief Media's URI to play. */
 	const char *media;
+	/*! \brief For sounds, selects language for sound */
+	const char *lang;
 };
 /*!
  * \brief Start playback of media.

Modified: team/dlee/playback/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback/rest-api/api-docs/channels.json?view=diff&rev=387736&r1=387735&r2=387736
==============================================================================
--- team/dlee/playback/rest-api/api-docs/channels.json (original)
+++ team/dlee/playback/rest-api/api-docs/channels.json Mon May  6 11:50:01 2013
@@ -403,6 +403,14 @@
 							"description": "Media's URI to play.",
 							"paramType": "query",
 							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						},
+						{
+							"name": "lang",
+							"description": "For sounds, selects language for sound",
+							"paramType": "query",
+							"required": false,
 							"allowMultiple": false,
 							"dataType": "string"
 						}




More information about the asterisk-commits mailing list