[asterisk-commits] dlee: branch dlee/record r389721 - in /team/dlee/record: include/asterisk/ ma...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 24 08:18:02 CDT 2013


Author: dlee
Date: Fri May 24 08:17:57 2013
New Revision: 389721

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389721
Log:
More recording stuffz

Modified:
    team/dlee/record/include/asterisk/channel.h
    team/dlee/record/include/asterisk/file.h
    team/dlee/record/include/asterisk/stasis_app_recording.h
    team/dlee/record/main/channel.c
    team/dlee/record/main/file.c
    team/dlee/record/res/res_stasis_recording.c
    team/dlee/record/res/stasis_http/resource_channels.c

Modified: team/dlee/record/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/channel.h?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/include/asterisk/channel.h (original)
+++ team/dlee/record/include/asterisk/channel.h Fri May 24 08:17:57 2013
@@ -1571,13 +1571,7 @@
  * \retval 0 on success
  * \retval non-zero on failure
  */
-static inline int ast_auto_answer(struct ast_channel *chan)
-{
-	if (ast_channel_state(chan) == AST_STATE_UP) {
-		/* Already answered */
-		return 0;
-	}
-	return ast_answer(chan);}
+int ast_auto_answer(struct ast_channel *chan);
 
 /*!
  * \brief Answer a channel

Modified: team/dlee/record/include/asterisk/file.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/file.h?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/include/asterisk/file.h (original)
+++ team/dlee/record/include/asterisk/file.h Fri May 24 08:17:57 2013
@@ -65,6 +65,18 @@
 typedef void (ast_waitstream_fr_cb)(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val);
 
 /*!
+ * \brief Plays a sound to the channel, in the channel's default language.
+ *
+ * This will stop any existing streams on the channel.
+
+ * \param chan channel to stream the file to
+ * \param filename the name of the file you wish to stream, minus the extension
+ * \retval 0 on success.
+ * \retval -1 on failure.
+ */
+int ast_play_sound(struct ast_channel *chan, const char *filename);
+
+/*!
  * \brief Streams a file
  * \param c channel to stream the file to
  * \param filename the name of the file you wish to stream, minus the extension
@@ -75,27 +87,6 @@
  * \retval -1 on failure.
  */
 int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang);
-
-/*!
- * \brief Plays a sound to the channel, in the channel's default language.
- *
- * This will stop any existing streams on the channel.
-
- * \param c channel to stream the file to
- * \param filename the name of the file you wish to stream, minus the extension
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int ast_play_sound(struct ast_channel *c, const char *filename)
-{
-	int res;
-	res = ast_streamfile(chan, "beep", ast_channel_language(chan));
-	if (res == 0) {
-		res = ast_waitstream(chan, "");
-	}
-	ast_stopstream(chan);
-	return res;
-}
 
 /*!
  * \brief stream file until digit

Modified: team/dlee/record/include/asterisk/stasis_app_recording.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/stasis_app_recording.h?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/include/asterisk/stasis_app_recording.h (original)
+++ team/dlee/record/include/asterisk/stasis_app_recording.h Fri May 24 08:17:57 2013
@@ -45,24 +45,17 @@
 	STASIS_APP_RECORDING_STATE_COMPLETE,
 	/*! The media has stopped playing */
 	STASIS_APP_RECORDING_STATE_FAILED,
-	/*! Enum end sentinel. */
-	STASIS_APP_RECORDING_STATE_MAX,
 };
 
 /*! Valid operation for controlling a recording. */
 enum stasis_app_recording_media_operation {
 	/*! Stop the recording operation. */
 	STASIS_APP_RECORDING_STOP,
-	/*! Enum end sentinel. */
-	STASIS_APP_RECORDING_MEDIA_OP_MAX,
 };
 
-enum stasis_app_recording_termination {
-	STASIS_APP_RECORDING_TERMINATE_NONE,
-	STASIS_APP_RECORDING_TERMINATE_HASH,
-	STASIS_APP_RECORDING_TERMINATE_STAR,
-	STASIS_APP_RECORDING_TERMINATE_ANY,
-};
+#define STASIS_APP_RECORDING_TERMINATE_INVALID 0
+#define STASIS_APP_RECORDING_TERMINATE_NONE -1
+#define STASIS_APP_RECORDING_TERMINATE_ANY -2
 
 struct stasis_app_recording_options {
 	/*! \param name Name of the recording. */
@@ -73,8 +66,11 @@
 	int max_silence_seconds;
 	/*! Maximum recording duration. 0 for no maximum. */
 	int max_duration_seconds;
-	/*! Which DTMF to use to terminate the recording */
-	enum stasis_app_recording_termination terminate_on;
+	/*! Which DTMF to use to terminate the recording
+	 *  \c STASIS_APP_RECORDING_TERMINATE_NONE to terminate only on hangup
+	 *  \c STASIS_APP_RECORDING_TERMINATE_ANY to terminate on any DTMF
+	 */
+	char terminate_on;
 	/*! If true, file is appended to instead of overwriting. */
 	int append:1;
 	/*! If true, no beep is played at the start of recording */
@@ -85,10 +81,12 @@
  * \brief Parse a string into the recording termination enum.
  *
  * \param str String to parse.
- * \return Parsed value.
- * \return -1 on error.
+ * \return DTMF value to terminate on.
+ * \return \c STASIS_APP_RECORDING_TERMINATE_NONE to not terminate on DTMF.
+ * \return \c STASIS_APP_RECORDING_TERMINATE_ANY to terminate on any DTMF.
+ * \return \c STASIS_APP_RECORDING_TERMINATE_INVALID if input was invalid.
  */
-enum stasis_app_recording_termination stasis_app_recording_termination_parse(const char *str);
+char stasis_app_recording_termination_parse(const char *str);
 
 /*!
  * \brief Record media from a channel.

Modified: team/dlee/record/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/main/channel.c?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/main/channel.c (original)
+++ team/dlee/record/main/channel.c Fri May 24 08:17:57 2013
@@ -3046,6 +3046,15 @@
 int ast_answer(struct ast_channel *chan)
 {
 	return __ast_answer(chan, 0, 1);
+}
+
+inline int ast_auto_answer(struct ast_channel *chan)
+{
+	if (ast_channel_state(chan) == AST_STATE_UP) {
+		/* Already answered */
+		return 0;
+	}
+	return ast_answer(chan);
 }
 
 void ast_deactivate_generator(struct ast_channel *chan)

Modified: team/dlee/record/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/main/file.c?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/main/file.c (original)
+++ team/dlee/record/main/file.c Fri May 24 08:17:57 2013
@@ -1001,6 +1001,17 @@
 int ast_filecopy(const char *filename, const char *filename2, const char *fmt)
 {
 	return filehelper(filename, filename2, fmt, ACTION_COPY);
+}
+
+int ast_play_sound(struct ast_channel *chan, const char *filename)
+{
+	int res;
+	res = ast_streamfile(chan, "beep", ast_channel_language(chan));
+	if (res == 0) {
+		res = ast_waitstream(chan, "");
+	}
+	ast_stopstream(chan);
+	return res;
 }
 
 int ast_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)

Modified: team/dlee/record/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_recording.c?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/res/res_stasis_recording.c (original)
+++ team/dlee/record/res/res_stasis_recording.c Fri May 24 08:17:57 2013
@@ -62,7 +62,7 @@
 	/*! Maximum recording duration. 0 for no maximum. */
 	int max_duration_seconds;
 	/*! Which DTMF to use to terminate the recording */
-	enum stasis_app_recording_termination terminate_on;
+	char terminate_on;
 	/*! If true, file is appended to instead of overwriting. */
 	int append:1;
 	/*! If true, no beep is played at the start of recording */
@@ -89,7 +89,25 @@
 	}
 }
 
-enum stasis_app_recording_termination stasis_app_recording_termination_parse(const char *str)
+static const char *state_to_string(enum stasis_app_recording_state state)
+{
+	switch (state) {
+	case STASIS_APP_RECORDING_STATE_QUEUED:
+		return "queued";
+	case STASIS_APP_RECORDING_STATE_RECORDING:
+		return "recording";
+	case STASIS_APP_RECORDING_STATE_PAUSED:
+		return "paused";
+	case STASIS_APP_RECORDING_STATE_COMPLETE:
+		return "done";
+	case STASIS_APP_RECORDING_STATE_FAILED:
+		return "failed";
+	}
+
+	return "?";
+}
+
+char stasis_app_recording_termination_parse(const char *str)
 {
 	if (ast_strlen_zero(str)) {
 		return STASIS_APP_RECORDING_TERMINATE_NONE;
@@ -99,19 +117,19 @@
 		return STASIS_APP_RECORDING_TERMINATE_NONE;
 	}
 
-	if (strcmp(str, "#") == 0) {
-		return STASIS_APP_RECORDING_TERMINATE_HASH;
-	}
-
-	if (strcmp(str, "*") == 0) {
-		return STASIS_APP_RECORDING_TERMINATE_STAR;
-	}
-
 	if (strcmp(str, "any") == 0) {
 		return STASIS_APP_RECORDING_TERMINATE_ANY;
 	}
 
-	return -1;
+	if (strcmp(str, "#") == 0) {
+		return '#';
+	}
+
+	if (strcmp(str, "*") == 0) {
+		return '*';
+	}
+
+	return STASIS_APP_RECORDING_TERMINATE_INVALID;
 }
 
 static void recording_publish(struct stasis_app_recording *recording)
@@ -144,18 +162,58 @@
 	recording_publish(recording);
 }
 
+static int recording_should_terminate(struct stasis_app_recording *recording,
+	char dtmf)
+{
+	int res = 0;
+	switch (recording->terminate_on) {
+	case STASIS_APP_RECORDING_TERMINATE_NONE:
+		break;
+	case STASIS_APP_RECORDING_TERMINATE_ANY:
+		res = 1;
+		break;
+	default:
+		if (dtmf == recording->terminate_on) {
+			res = 1;
+		}
+		break;
+	}
+
+	return res;
+}
+
 static void *record_file(struct stasis_app_control *control,
 	struct ast_channel *chan, void *data)
 {
 	struct stasis_app_recording *recording = data;
+	struct ast_filestream *s;
 	int res;
+	struct timeval start;
+	int ms;
 	long maxms;
+	int ioflags;
+	const char *comment = "Stasis recording";
+	int check = 0;
+	int terminated = 0;
+
+	ast_assert(recording != NULL);
 
 	ao2_lock(recording);
 	recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
 	recording_publish(recording);
 	ao2_unlock(recording);
 
+	ioflags = O_CREAT|O_WRONLY|(recording->append ? O_APPEND : O_TRUNC);
+
+	s = ast_writefile(recording->name,recording->format, comment, ioflags,
+		check, AST_FILE_MODE);
+	if (s == NULL) {
+		ast_log(LOG_WARNING, "Could not create file %s.%s\n",
+			recording->name, recording->format);
+		recording_fail(recording);
+		return NULL;
+	}
+
 	res = ast_auto_answer(chan);
 	if (res != 0) {
 		recording_fail(recording);
@@ -170,7 +228,7 @@
 		return NULL;
 	}
 
-	maxms = control->max_duration_seconds * 1000;
+	maxms = recording->max_duration_seconds * 1000;
 	start = ast_tvnow();
 	while ((ms = ast_remaining_ms(start, maxms))) {
 		RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
@@ -180,7 +238,7 @@
 			break;
 		}
 
-		if (maxduration > 0 && res == 0) {
+		if (maxms > 0 && res == 0) {
 			break;
 		}
 
@@ -197,7 +255,19 @@
 			res = ast_writestream(s, f);
 			break;
 		case AST_FRAME_DTMF:
-			
+			terminated = recording_should_terminate(recording,
+				f->subclass.integer);
+			break;
+		default:
+			/* Drop the frame */
+			break;
+		}
+
+		if (terminated) {
+			break;
+		}
+
+		if (res != 0) {
 			break;
 		}
 	}
@@ -227,8 +297,7 @@
 		ast_strlen_zero(options->name) ||
 		ast_strlen_zero(options->format) ||
 		options->max_silence_seconds < 0 ||
-		options->max_duration_seconds < 0 ||
-		options->terminate_on < 0) {
+		options->max_duration_seconds < 0) {
 		return NULL;
 	}
 
@@ -301,7 +370,7 @@
 		"id", recording->id,
 		"name", recording->name,
 		"format", recording->format,
-		"state", recording->state);
+		"state", state_to_string(recording->state));
 
 	return ast_json_ref(json);
 }

Modified: team/dlee/record/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/resource_channels.c?view=diff&rev=389721&r1=389720&r2=389721
==============================================================================
--- team/dlee/record/res/stasis_http/resource_channels.c (original)
+++ team/dlee/record/res/stasis_http/resource_channels.c Fri May 24 08:17:57 2013
@@ -250,7 +250,7 @@
 	options.terminate_on =
 		stasis_app_recording_termination_parse(args->terminate_on);
 
-	if (options.terminate_on == -1) {
+	if (options.terminate_on == STASIS_APP_RECORDING_TERMINATE_INVALID) {
 		stasis_http_response_error(
 			response, 400, "Bad Request",
 			"terminateOn invalid");
@@ -268,6 +268,14 @@
 	ast_asprintf(&recording_url, "/recording/%s",
 		stasis_app_recording_get_id(recording));
 	if (!recording_url) {
+		stasis_http_response_error(
+			response, 500, "Internal Server Error",
+			"Out of memory");
+		return;
+	}
+
+	json = stasis_app_recording_to_json(recording);
+	if (!json) {
 		stasis_http_response_error(
 			response, 500, "Internal Server Error",
 			"Out of memory");




More information about the asterisk-commits mailing list