[svn-commits] dlee: branch dlee/record-controls r395199 - in /team/dlee/record-controls: fu...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 23 15:00:46 CDT 2013


Author: dlee
Date: Tue Jul 23 15:00:44 2013
New Revision: 395199

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395199
Log:
Web and application layers implemented.

Modified:
    team/dlee/record-controls/funcs/func_frame_trace.c
    team/dlee/record-controls/include/asterisk/frame.h
    team/dlee/record-controls/include/asterisk/stasis_app_recording.h
    team/dlee/record-controls/main/channel.c
    team/dlee/record-controls/res/res_stasis_recording.c
    team/dlee/record-controls/res/stasis_http/resource_recordings.c

Modified: team/dlee/record-controls/funcs/func_frame_trace.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/funcs/func_frame_trace.c?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/funcs/func_frame_trace.c (original)
+++ team/dlee/record-controls/funcs/func_frame_trace.c Tue Jul 23 15:00:44 2013
@@ -343,6 +343,18 @@
 		case AST_CONTROL_STREAM_FORWARD:
 			ast_verbose("SubClass: STREAM_FORWARD\n");
 			break;
+		case AST_CONTROL_RECORD_CANCEL:
+			ast_verbose("SubClass: RECORD_CANCEL\n");
+			break;
+		case AST_CONTROL_RECORD_STOP:
+			ast_verbose("SubClass: RECORD_STOP\n");
+			break;
+		case AST_CONTROL_RECORD_SUSPEND:
+			ast_verbose("SubClass: RECORD_SUSPEND\n");
+			break;
+		case AST_CONTROL_RECORD_MUTE:
+			ast_verbose("SubClass: RECORD_MUTE\n");
+			break;
 		}
 
 		if (frame->subclass.integer == -1) {

Modified: team/dlee/record-controls/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/include/asterisk/frame.h?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/include/asterisk/frame.h (original)
+++ team/dlee/record-controls/include/asterisk/frame.h Tue Jul 23 15:00:44 2013
@@ -278,7 +278,11 @@
 	AST_CONTROL_STREAM_RESTART = 1002,	/*!< Indicate to a channel in playback to restart the stream */
 	AST_CONTROL_STREAM_REVERSE = 1003,	/*!< Indicate to a channel in playback to rewind */
 	AST_CONTROL_STREAM_FORWARD = 1004,	/*!< Indicate to a channel in playback to fast forward */
-
+	/* Control frames to manipulate recording on a channel. */
+	AST_CONTROL_RECORD_CANCEL = 1100,	/*!< Indicated to a channel in record to stop recording and discard the file */
+	AST_CONTROL_RECORD_STOP = 1101,	/*!< Indicated to a channel in record to stop recording */
+	AST_CONTROL_RECORD_SUSPEND = 1102,	/*!< Indicated to a channel in record to suspend/unsuspend recording */
+	AST_CONTROL_RECORD_MUTE = 1103,	/*!< Indicated to a channel in record to mute/unmute (i.e. write silence) recording */
 };
 
 enum ast_frame_read_action {

Modified: team/dlee/record-controls/include/asterisk/stasis_app_recording.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/include/asterisk/stasis_app_recording.h?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/include/asterisk/stasis_app_recording.h (original)
+++ team/dlee/record-controls/include/asterisk/stasis_app_recording.h Tue Jul 23 15:00:44 2013
@@ -44,14 +44,23 @@
 	STASIS_APP_RECORDING_STATE_PAUSED,
 	/*! The media has stopped recording */
 	STASIS_APP_RECORDING_STATE_COMPLETE,
-	/*! The media has stopped playing */
+	/*! The media has stopped recording, with error */
 	STASIS_APP_RECORDING_STATE_FAILED,
+	/*! The media has stopped recording, discard the recording file */
+	STASIS_APP_RECORDING_STATE_CANCELED,
+	STASIS_APP_RECORDING_STATE_MAX,
 };
 
 /*! Valid operation for controlling a recording. */
 enum stasis_app_recording_media_operation {
+	STASIS_APP_RECORDING_CANCEL,
 	/*! Stop the recording operation. */
 	STASIS_APP_RECORDING_STOP,
+	STASIS_APP_RECORDING_PAUSE,
+	STASIS_APP_RECORDING_UNPAUSE,
+	STASIS_APP_RECORDING_MUTE,
+	STASIS_APP_RECORDING_UNMUTE,
+	STASIS_APP_RECORDING_OPER_MAX,
 };
 
 #define STASIS_APP_RECORDING_TERMINATE_INVALID 0

Modified: team/dlee/record-controls/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/main/channel.c?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/main/channel.c (original)
+++ team/dlee/record-controls/main/channel.c Tue Jul 23 15:00:44 2013
@@ -4308,6 +4308,10 @@
 	case AST_CONTROL_STREAM_REVERSE:
 	case AST_CONTROL_STREAM_FORWARD:
 	case AST_CONTROL_STREAM_RESTART:
+	case AST_CONTROL_RECORD_CANCEL:
+	case AST_CONTROL_RECORD_STOP:
+	case AST_CONTROL_RECORD_SUSPEND:
+	case AST_CONTROL_RECORD_MUTE:
 		break;
 
 	case AST_CONTROL_INCOMPLETE:
@@ -4566,6 +4570,10 @@
 	case AST_CONTROL_STREAM_REVERSE:
 	case AST_CONTROL_STREAM_FORWARD:
 	case AST_CONTROL_STREAM_RESTART:
+	case AST_CONTROL_RECORD_CANCEL:
+	case AST_CONTROL_RECORD_STOP:
+	case AST_CONTROL_RECORD_SUSPEND:
+	case AST_CONTROL_RECORD_MUTE:
 		/* Nothing left to do for these. */
 		res = 0;
 		break;

Modified: team/dlee/record-controls/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/res/res_stasis_recording.c?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/res/res_stasis_recording.c (original)
+++ team/dlee/record-controls/res/res_stasis_recording.c Tue Jul 23 15:00:44 2013
@@ -59,11 +59,13 @@
 	struct stasis_app_recording_options *options;
 	/*! Absolute path (minus extension) of the recording */
 	char *absolute_name;
-	/*! Control object for the channel we're playing back to */
+	/*! Control object for the channel we're recording */
 	struct stasis_app_control *control;
 
 	/*! Current state of the recording. */
 	enum stasis_app_recording_state state;
+	/*! Indicates whether the recording is currently muted */
+	int muted:1;
 };
 
 static int recording_hash(const void *obj, int flags)
@@ -99,6 +101,10 @@
 		return "done";
 	case STASIS_APP_RECORDING_STATE_FAILED:
 		return "failed";
+	case STASIS_APP_RECORDING_STATE_CANCELED:
+		return "canceled";
+	case STASIS_APP_RECORDING_STATE_MAX:
+		return "?";
 	}
 
 	return "?";
@@ -403,12 +409,124 @@
 	return ast_json_ref(json);
 }
 
+typedef int (*recording_operation_cb)(struct stasis_app_recording *recording);
+
+static int recording_noop(struct stasis_app_recording *recording)
+{
+	return 0;
+}
+
+static int recording_disregard(struct stasis_app_recording *recording)
+{
+	recording->state = STASIS_APP_RECORDING_STATE_CANCELED;
+	return 0;
+}
+
+static int recording_cancel(struct stasis_app_recording *recording)
+{
+	recording->state = STASIS_APP_RECORDING_STATE_CANCELED;
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_CANCEL);
+}
+
+static int recording_stop(struct stasis_app_recording *recording)
+{
+	recording->state = STASIS_APP_RECORDING_STATE_COMPLETE;
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_STOP);
+}
+
+static int recording_pause(struct stasis_app_recording *recording)
+{
+	recording->state = STASIS_APP_RECORDING_STATE_PAUSED;
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_SUSPEND);
+}
+
+static int recording_unpause(struct stasis_app_recording *recording)
+{
+	recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_SUSPEND);
+}
+
+static int recording_mute(struct stasis_app_recording *recording)
+{
+	if (recording->muted) {
+		/* already muted */
+		return 0;
+	}
+
+	recording->muted = 1;
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_MUTE);
+}
+
+static int recording_unmute(struct stasis_app_recording *recording)
+{
+	if (!recording->muted) {
+		/* already unmuted */
+		return 0;
+	}
+
+	return stasis_app_control_queue_control(recording->control,
+		AST_CONTROL_RECORD_MUTE);
+}
+
+recording_operation_cb operations[STASIS_APP_RECORDING_STATE_MAX][STASIS_APP_RECORDING_OPER_MAX] = {
+	[STASIS_APP_RECORDING_STATE_QUEUED][STASIS_APP_RECORDING_CANCEL] = recording_disregard,
+	[STASIS_APP_RECORDING_STATE_QUEUED][STASIS_APP_RECORDING_STOP] = recording_disregard,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_CANCEL] = recording_cancel,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_STOP] = recording_stop,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_PAUSE] = recording_pause,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_UNPAUSE] = recording_noop,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_MUTE] = recording_mute,
+	[STASIS_APP_RECORDING_STATE_RECORDING][STASIS_APP_RECORDING_UNMUTE] = recording_unmute,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_CANCEL] = recording_cancel,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_STOP] = recording_stop,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_PAUSE] = recording_noop,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_UNPAUSE] = recording_unpause,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_MUTE] = recording_mute,
+	[STASIS_APP_RECORDING_STATE_PAUSED][STASIS_APP_RECORDING_UNMUTE] = recording_unmute,
+};
+
 enum stasis_app_recording_oper_results stasis_app_recording_operation(
 	struct stasis_app_recording *recording,
 	enum stasis_app_recording_media_operation operation)
 {
-	ast_assert(0); // TODO
-	return STASIS_APP_RECORDING_OPER_FAILED;
+	recording_operation_cb cb;
+	SCOPED_AO2LOCK(lock, recording);
+
+	if (recording->state < 0 || recording->state >= STASIS_APP_RECORDING_STATE_MAX) {
+		ast_log(LOG_WARNING, "Invalid recording state %d\n",
+			recording->state);
+		return -1;
+	}
+
+	if (operation < 0 || operation >= STASIS_APP_RECORDING_OPER_MAX) {
+		ast_log(LOG_WARNING, "Invalid recording operation %d\n",
+			operation);
+		return -1;
+	}
+
+	cb = operations[recording->state][operation];
+
+	if (!cb) {
+		if (recording->state != STASIS_APP_RECORDING_STATE_RECORDING) {
+			/* So we can be specific in our error message. */
+			return STASIS_APP_RECORDING_OPER_NOT_RECORDING;
+		} else {
+			/* And, really, all operations should be valid during
+			 * recording */
+			ast_log(LOG_ERROR,
+				"Unhandled operation during recording: %d\n",
+				operation);
+			return STASIS_APP_RECORDING_OPER_FAILED;
+		}
+	}
+
+	return cb(recording) ?
+		STASIS_APP_RECORDING_OPER_FAILED : STASIS_APP_RECORDING_OPER_OK;
 }
 
 static int load_module(void)

Modified: team/dlee/record-controls/res/stasis_http/resource_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/res/stasis_http/resource_recordings.c?view=diff&rev=395199&r1=395198&r2=395199
==============================================================================
--- team/dlee/record-controls/res/stasis_http/resource_recordings.c (original)
+++ team/dlee/record-controls/res/stasis_http/resource_recordings.c Tue Jul 23 15:00:44 2013
@@ -71,27 +71,81 @@
 	stasis_http_response_ok(response, ast_json_ref(json));
 }
 
-void stasis_http_cancel_recording(struct ast_variable *headers, struct ast_cancel_recording_args *args, struct stasis_http_response *response)
+static void control_recording(const char *name,
+	enum stasis_app_recording_media_operation operation,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_cancel_recording\n");
+	RAII_VAR(struct stasis_app_recording *, recording, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	enum stasis_app_recording_oper_results res;
+
+	recording = stasis_app_recording_find_by_name(name);
+	if (recording == NULL) {
+		stasis_http_response_error(response, 404, "Not Found",
+			"Recording not found");
+		return;
+	}
+
+	res = stasis_app_recording_operation(recording, operation);
+
+	switch (res) {
+	case STASIS_APP_RECORDING_OPER_OK:
+		stasis_http_response_no_content(response);
+		return;
+	case STASIS_APP_RECORDING_OPER_FAILED:
+		stasis_http_response_error(response, 500,
+			"Internal Server Error", "Recording operation failed");
+		return;
+	case STASIS_APP_RECORDING_OPER_NOT_RECORDING:
+		stasis_http_response_error(response, 409,
+			"Conflict", "Recording not in session");
+	}
 }
-void stasis_http_stop_recording(struct ast_variable *headers, struct ast_stop_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_cancel_recording(struct ast_variable *headers,
+	struct ast_cancel_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_stop_recording\n");
+	control_recording(args->recording_name, STASIS_APP_RECORDING_CANCEL,
+		response);
 }
-void stasis_http_pause_recording(struct ast_variable *headers, struct ast_pause_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_stop_recording(struct ast_variable *headers,
+	struct ast_stop_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_pause_recording\n");
+	control_recording(args->recording_name, STASIS_APP_RECORDING_STOP,
+		response);
 }
-void stasis_http_unpause_recording(struct ast_variable *headers, struct ast_unpause_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_pause_recording(struct ast_variable *headers,
+	struct ast_pause_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_unpause_recording\n");
+	control_recording(args->recording_name, STASIS_APP_RECORDING_PAUSE,
+		response);
 }
-void stasis_http_mute_recording(struct ast_variable *headers, struct ast_mute_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_unpause_recording(struct ast_variable *headers,
+	struct ast_unpause_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_mute_recording\n");
+	control_recording(args->recording_name, STASIS_APP_RECORDING_UNPAUSE,
+		response);
 }
-void stasis_http_unmute_recording(struct ast_variable *headers, struct ast_unmute_recording_args *args, struct stasis_http_response *response)
+
+void stasis_http_mute_recording(struct ast_variable *headers,
+	struct ast_mute_recording_args *args,
+	struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_unmute_recording\n");
+	control_recording(args->recording_name, STASIS_APP_RECORDING_MUTE,
+		response);
 }
+
+void stasis_http_unmute_recording(struct ast_variable *headers,
+	struct ast_unmute_recording_args *args,
+	struct stasis_http_response *response)
+{
+	control_recording(args->recording_name, STASIS_APP_RECORDING_UNMUTE,
+		response);
+}




More information about the svn-commits mailing list