[svn-commits] dlee: branch dlee/record-controls r395240 - in /team/dlee/record-controls: ma...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 23 23:49:48 CDT 2013


Author: dlee
Date: Tue Jul 23 23:49:46 2013
New Revision: 395240

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395240
Log:
Hacked together recording control frame stuffz

Modified:
    team/dlee/record-controls/main/app.c
    team/dlee/record-controls/res/res_stasis_http_recordings.c
    team/dlee/record-controls/rest-api/api-docs/recordings.json

Modified: team/dlee/record-controls/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/main/app.c?view=diff&rev=395240&r1=395239&r2=395240
==============================================================================
--- team/dlee/record-controls/main/app.c (original)
+++ team/dlee/record-controls/main/app.c Tue Jul 23 23:49:46 2013
@@ -1144,6 +1144,34 @@
 	return d;
 }
 
+static struct ast_frame *make_silence(const struct ast_frame *orig)
+{
+	struct ast_frame *silence;
+	size_t size;
+	size_t datalen;
+
+	if (!orig) {
+		return NULL;
+	}
+
+	datalen = sizeof(short) * orig->samples;
+	size = sizeof(*silence) + datalen;
+	silence = ast_calloc(1, size);
+	if (!silence) {
+		return NULL;
+	}
+
+	silence->mallocd = AST_MALLOCD_HDR;
+	silence->frametype = AST_FRAME_VOICE;
+	silence->data.ptr = (void *)(silence + 1);
+	silence->samples = orig->samples;
+	silence->datalen = datalen;
+
+	ast_format_set(&silence->subclass.format, AST_FORMAT_SLINEAR, 0);
+
+	return silence;
+}
+
 static int global_silence_threshold = 128;
 static int global_maxsilence = 0;
 
@@ -1183,6 +1211,7 @@
 	int totalsilence = 0;
 	int dspsilence = 0;
 	int olddspsilence = 0;
+	int pausedsilence = 0;
 	struct ast_format rfmt;
 	struct ast_silence_generator *silgen = NULL;
 	char prependfile[PATH_MAX];
@@ -1295,7 +1324,10 @@
 		/* Loop forever, writing the packets we read to the writer(s), until
 		   we read a digit or get a hangup */
 		struct ast_frame *f;
-		for (;;) {
+		int paused = 0;
+		int muted = 0;
+		int running = 1;
+		while (running) {
 			if (!(res = ast_waitfor(chan, 2000))) {
 				ast_debug(1, "One waitfor failed, trying another\n");
 				/* Try one more time in case of masq */
@@ -1314,11 +1346,27 @@
 			}
 			if (f->frametype == AST_FRAME_VOICE) {
 				/* write each format */
-				for (x = 0; x < fmtcnt; x++) {
-					if (prepend && !others[x]) {
-						break;
+				if (paused) {
+					/* It's all good */
+					res = 0;
+				} else {
+					RAII_VAR(struct ast_frame *, silence, NULL, ast_frame_dtor);
+					struct ast_frame *orig = f;
+
+					if (muted) {
+						silence = make_silence(orig);
+						if (!silence) {
+							break;
+						}
+						f = silence;
 					}
-					res = ast_writestream(others[x], f);
+					for (x = 0; x < fmtcnt; x++) {
+						if (prepend && !others[x]) {
+							break;
+						}
+						res = ast_writestream(others[x], f);
+					}
+					f = orig;
 				}
 
 				/* Silence Detection */
@@ -1329,6 +1377,17 @@
 						totalsilence += olddspsilence;
 					}
 					olddspsilence = dspsilence;
+
+					if (paused) {
+						/* record how much silence there was while we are paused */
+						pausedsilence = dspsilence;
+					} else if (dspsilence > pausedsilence) {
+						/* ignore the paused silence */
+						dspsilence -= pausedsilence;
+					} else {
+						/* we're not paused, and dspsilence is less than paused silence. reset pausedsilence */
+						pausedsilence = 0;
+					}
 
 					if (dspsilence > maxsilence) {
 						/* Ended happily with silence */
@@ -1361,9 +1420,31 @@
 					break;
 				}
 				if (strchr(canceldtmf, f->subclass.integer)) {
-					ast_verb(3, "User cancelled message by pressing %c\n", f->subclass.integer);
+					ast_verb(3, "User canceled message by pressing %c\n", f->subclass.integer);
 					res = f->subclass.integer;
 					outmsg = 0;
+					break;
+				}
+			} else if (f->frametype == AST_FRAME_CONTROL) {
+				switch (f->subclass.integer) {
+				case AST_CONTROL_RECORD_CANCEL:
+					ast_verb(3, "Message canceled by control\n");
+					running = 0;
+					outmsg = 0; /* cancels the recording */
+					break;
+				case AST_CONTROL_RECORD_STOP:
+					ast_verb(3, "Message ended by control\n");
+					running = 0;
+					break;
+				case AST_CONTROL_RECORD_SUSPEND:
+					paused = !paused;
+					ast_verb(3, "Message %spaused by control\n",
+						paused ? "" : "un");
+					break;
+				case AST_CONTROL_RECORD_MUTE:
+					muted = !muted;
+					ast_verb(3, "Message %smuted by control\n",
+						muted ? "" : "un");
 					break;
 				}
 			}

Modified: team/dlee/record-controls/res/res_stasis_http_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/res/res_stasis_http_recordings.c?view=diff&rev=395240&r1=395239&r2=395240
==============================================================================
--- team/dlee/record-controls/res/res_stasis_http_recordings.c (original)
+++ team/dlee/record-controls/res/res_stasis_http_recordings.c Tue Jul 23 23:49:46 2013
@@ -283,6 +283,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -337,6 +338,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -391,6 +393,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -445,6 +448,8 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
+	case 409: /* Recording not in session */
 		is_valid = 1;
 		break;
 	default:
@@ -499,6 +504,8 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
+	case 409: /* Recording not in session */
 		is_valid = 1;
 		break;
 	default:
@@ -553,6 +560,8 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
+	case 409: /* Recording not in session */
 		is_valid = 1;
 		break;
 	default:
@@ -607,6 +616,8 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
+	case 409: /* Recording not in session */
 		is_valid = 1;
 		break;
 	default:

Modified: team/dlee/record-controls/rest-api/api-docs/recordings.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record-controls/rest-api/api-docs/recordings.json?view=diff&rev=395240&r1=395239&r2=395240
==============================================================================
--- team/dlee/record-controls/rest-api/api-docs/recordings.json (original)
+++ team/dlee/record-controls/rest-api/api-docs/recordings.json Tue Jul 23 23:49:46 2013
@@ -87,6 +87,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				},
 				{
@@ -103,6 +109,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				}
 			]
@@ -123,6 +135,12 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
 						}
 					]
 				}
@@ -146,6 +164,16 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						},
+						{
+							"code": 409,
+							"reason": "Recording not in session"
+						}
 					]
 				}
 			]
@@ -166,6 +194,16 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						},
+						{
+							"code": 409,
+							"reason": "Recording not in session"
 						}
 					]
 				}
@@ -189,6 +227,16 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						},
+						{
+							"code": 409,
+							"reason": "Recording not in session"
+						}
 					]
 				}
 			]
@@ -209,6 +257,16 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						},
+						{
+							"code": 409,
+							"reason": "Recording not in session"
 						}
 					]
 				}




More information about the svn-commits mailing list