[asterisk-commits] dlee: branch dlee/playback-controls r389367 - in /team/dlee/playback-controls...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 21 11:09:04 CDT 2013


Author: dlee
Date: Tue May 21 11:09:00 2013
New Revision: 389367

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389367
Log:
Fixed playback language selection; added skipms and offsetms

Modified:
    team/dlee/playback-controls/include/asterisk/app.h
    team/dlee/playback-controls/include/asterisk/stasis_app_playback.h
    team/dlee/playback-controls/main/app.c
    team/dlee/playback-controls/res/res_stasis_http_channels.c
    team/dlee/playback-controls/res/res_stasis_playback.c
    team/dlee/playback-controls/res/stasis_http/resource_channels.c
    team/dlee/playback-controls/res/stasis_http/resource_channels.h
    team/dlee/playback-controls/rest-api/api-docs/channels.json

Modified: team/dlee/playback-controls/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/include/asterisk/app.h?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/include/asterisk/app.h (original)
+++ team/dlee/playback-controls/include/asterisk/app.h Tue May 21 11:09:00 2013
@@ -653,6 +653,17 @@
 int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms, long *offsetms);
 
 /*!
+ * \brief Version of ast_control_streamfile() which allows the language of the
+ * media file to be specified.
+ *
+ * \retval 0 on success
+ * \retval Non-zero on failure
+ */
+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);
+
+/*!
  * \brief Stream a file with fast forward, pause, reverse, restart.
  * \param chan
  * \param file filename

Modified: team/dlee/playback-controls/include/asterisk/stasis_app_playback.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/include/asterisk/stasis_app_playback.h?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/include/asterisk/stasis_app_playback.h (original)
+++ team/dlee/playback-controls/include/asterisk/stasis_app_playback.h Tue May 21 11:09:00 2013
@@ -78,12 +78,15 @@
  *
  * \param control Control for \c res_stasis.
  * \param file Base filename for the file to play.
+ * \param language Spoken language of the file to play.
+ * \param skipms Number of milliseconds to skip for forward/reverse operations.
+ * \param offsetms Number of milliseconds to skip before playing.
  * \return Playback control object.
  * \return \c NULL on error.
  */
 struct stasis_app_playback *stasis_app_control_play_uri(
 	struct stasis_app_control *control, const char *file,
-	const char *language);
+	const char *language, int skipms, long offsetms);
 
 /*!
  * \brief Gets the current state of a playback operation.

Modified: team/dlee/playback-controls/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/main/app.c?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/main/app.c (original)
+++ team/dlee/playback-controls/main/app.c Tue May 21 11:09:00 2013
@@ -930,6 +930,7 @@
 	const char *restart,
 	int skipms,
 	long *offsetms,
+	const char *lang,
 	ast_waitstream_fr_cb cb)
 {
 	char *breaks = NULL;
@@ -945,6 +946,9 @@
 	if (offsetms) {
 		offset = *offsetms * 8; /* XXX Assumes 8kHz */
 	}
+	if (lang == NULL) {
+		lang = ast_channel_language(chan);
+	}
 
 	if (stop) {
 		blen += strlen(stop);
@@ -982,7 +986,7 @@
 
 	for (;;) {
 		ast_stopstream(chan);
-		res = ast_streamfile(chan, file, ast_channel_language(chan));
+		res = ast_streamfile(chan, file, lang);
 		if (!res) {
 			if (pause_restart_point) {
 				ast_seekstream(ast_channel_stream(chan), pause_restart_point, SEEK_SET);
@@ -1093,7 +1097,7 @@
 	long *offsetms,
 	ast_waitstream_fr_cb cb)
 {
-	return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, cb);
+	return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, cb);
 }
 
 int ast_control_streamfile(struct ast_channel *chan, const char *file,
@@ -1101,7 +1105,14 @@
 			   const char *stop, const char *suspend,
 			   const char *restart, int skipms, long *offsetms)
 {
-	return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL);
+	return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, NULL);
+}
+
+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)
+{
+	return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, lang, NULL);
 }
 
 int ast_play_and_wait(struct ast_channel *chan, const char *fn)

Modified: team/dlee/playback-controls/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/res/res_stasis_http_channels.c?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/res/res_stasis_http_channels.c (original)
+++ team/dlee/playback-controls/res/res_stasis_http_channels.c Tue May 21 11:09:00 2013
@@ -330,6 +330,12 @@
 		if (strcmp(i->name, "lang") == 0) {
 			args.lang = (i->value);
 		} else
+		if (strcmp(i->name, "offsetms") == 0) {
+			args.offsetms = atoi(i->value);
+		} else
+		if (strcmp(i->name, "skipms") == 0) {
+			args.skipms = atoi(i->value);
+		} else
 		{}
 	}
 	for (i = path_vars; i; i = i->next) {

Modified: team/dlee/playback-controls/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/res/res_stasis_playback.c?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/res/res_stasis_playback.c (original)
+++ team/dlee/playback-controls/res/res_stasis_playback.c Tue May 21 11:09:00 2013
@@ -68,6 +68,10 @@
 	enum stasis_app_playback_state state;
 	/*! Control object for the channel we're playing back to */
 	struct stasis_app_control *control;
+	/*! Number of milliseconds to skip before playing */
+	long offsetms;
+	/*! Number of milliseconds to skip for forward/reverse operations */
+	int skipms;
 };
 
 static int playback_hash(const void *obj, int flags)
@@ -146,11 +150,12 @@
 	const char *stop = NULL;
 	const char *pause = NULL;
 	const char *restart = NULL;
-	int skipms = PLAYBACK_SKIPMS;
-	long offsetms = 0;
+	long offsetms;
 
 	playback = data;
 	ast_assert(playback != NULL);
+
+	offsetms = playback->offsetms;
 
 	ao2_lock(playback);
 	if (playback->state == STASIS_PLAYBACK_STATE_CANCELED) {
@@ -178,8 +183,8 @@
 		return NULL;
 	}
 
-	res = ast_control_streamfile(chan, file, fwd, rev, stop, pause,
-		restart, skipms, &offsetms);
+	res = ast_control_streamfile_lang(chan, file, fwd, rev, stop, pause,
+		restart, playback->skipms, playback->language, &offsetms);
 
 	if (res != 0) {
 		enum stasis_app_playback_state state =
@@ -199,7 +204,7 @@
 
 struct stasis_app_playback *stasis_app_control_play_uri(
 	struct stasis_app_control *control, const char *uri,
-	const char *language)
+	const char *language, int skipms, long offsetms)
 {
 	RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
 	char id[AST_UUID_STR_LEN];
@@ -210,6 +215,10 @@
 	playback = ao2_alloc(sizeof(*playback) + strlen(uri) + 1, NULL);
 	if (!playback || ast_string_field_init(playback, 128) ){
 		return NULL;
+	}
+
+	if (skipms == 0) {
+		skipms = PLAYBACK_SKIPMS;
 	}
 
 	ast_uuid_generate_str(id, sizeof(id));
@@ -217,6 +226,8 @@
 	ast_string_field_set(playback, media, uri);
 	ast_string_field_set(playback, language, language);
 	playback->control = control;
+	playback->skipms = skipms;
+	playback->offsetms = offsetms;
 	ao2_link(playbacks, playback);
 
 	playback_set_state(playback, STASIS_PLAYBACK_STATE_QUEUED);

Modified: team/dlee/playback-controls/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/res/stasis_http/resource_channels.c?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/res/stasis_http/resource_channels.c (original)
+++ team/dlee/playback-controls/res/stasis_http/resource_channels.c Tue May 21 11:09:00 2013
@@ -167,11 +167,12 @@
 
 	language = S_OR(args->lang, snapshot->language);
 
-	playback = stasis_app_control_play_uri(control, args->media, language);
+	playback = stasis_app_control_play_uri(control, args->media, language,
+		args->skipms, args->offsetms);
 	if (!playback) {
 		stasis_http_response_error(
 			response, 500, "Internal Server Error",
-			"Failed to answer channel");
+			"Failed to queue media for playback");
 		return;
 	}
 

Modified: team/dlee/playback-controls/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/res/stasis_http/resource_channels.h?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/res/stasis_http/resource_channels.h (original)
+++ team/dlee/playback-controls/res/stasis_http/resource_channels.h Tue May 21 11:09:00 2013
@@ -200,8 +200,12 @@
 	const char *channel_id;
 	/*! \brief Media's URI to play. */
 	const char *media;
-	/*! \brief For sounds, selects language for sound */
+	/*! \brief For sounds, selects language for sound. */
 	const char *lang;
+	/*! \brief Number of media to skip before playing. */
+	int offsetms;
+	/*! \brief Number of milliseconds to skip for forward/reverse operations. */
+	int skipms;
 };
 /*!
  * \brief Start playback of media.

Modified: team/dlee/playback-controls/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/playback-controls/rest-api/api-docs/channels.json?view=diff&rev=389367&r1=389366&r2=389367
==============================================================================
--- team/dlee/playback-controls/rest-api/api-docs/channels.json (original)
+++ team/dlee/playback-controls/rest-api/api-docs/channels.json Tue May 21 11:09:00 2013
@@ -408,11 +408,28 @@
 						},
 						{
 							"name": "lang",
-							"description": "For sounds, selects language for sound",
-							"paramType": "query",
-							"required": false,
-							"allowMultiple": false,
-							"dataType": "string"
+							"description": "For sounds, selects language for sound.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
+						},
+						{
+							"name": "offsetms",
+							"description": "Number of media to skip before playing.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "int"
+						},
+						{
+							"name": "skipms",
+							"description": "Number of milliseconds to skip for forward/reverse operations.",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "int",
+							"defaultValue": 3000
 						}
 					],
 					"errorResponses": [




More information about the asterisk-commits mailing list