diff test-voice/user_cmd.c @ 15:71f01a834820

sipout-test-voice: implement play with offset
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 May 2024 22:27:07 -0800
parents f96153d15889
children
line wrap: on
line diff
--- a/test-voice/user_cmd.c	Sat May 11 22:10:38 2024 -0800
+++ b/test-voice/user_cmd.c	Sat May 11 22:27:07 2024 -0800
@@ -34,7 +34,7 @@
 }
 
 static void
-play_file_cmd(args)
+play_cmd_plain(args)
 	char *args;
 {
 	char *cp, *filename;
@@ -43,7 +43,7 @@
 	for (cp = args; isspace(*cp); cp++)
 		;
 	if (!*cp) {
-inv_syntax:	fprintf(stderr, "error: play-file command invalid syntax\n");
+inv_syntax:	fprintf(stderr, "error: play command invalid syntax\n");
 		return;
 	}
 	for (filename = cp; *cp && !isspace(*cp); cp++)
@@ -61,6 +61,42 @@
 }
 
 static void
+play_cmd_offset(args)
+	char *args;
+{
+	char *cp, *filename;
+	unsigned offset;
+
+	for (cp = args; isspace(*cp); cp++)
+		;
+	if (!*cp) {
+inv_syntax:	fprintf(stderr, "error: play-offset command invalid syntax\n");
+		return;
+	}
+	for (filename = cp; *cp && !isspace(*cp); cp++)
+		;
+	if (!*cp)
+		goto inv_syntax;
+	*cp++ = '\0';
+	while (isspace(*cp))
+		cp++;
+	if (!isdigit(*cp))
+		goto inv_syntax;
+	offset = strtoul(cp, &cp, 0);
+	if (*cp && !isspace(*cp))
+		goto inv_syntax;
+	if (offset < 1 || offset > 159) {
+		fprintf(stderr, "error: offset argument out of range\n");
+		return;
+	}
+	while (isspace(*cp))
+		cp++;
+	if (*cp)
+		goto inv_syntax;
+	play_file_offset(filename, offset);
+}
+
+static void
 tfo_req_cmd(args)
 	char *args;
 {
@@ -124,8 +160,10 @@
 		cmd_dmw_on();
 	else if (!strcmp(cp, "dmw-off"))
 		cmd_dmw_off();
-	else if (!strncmp(cp, "play-file", 9) && isspace(cp[9]))
-		play_file_cmd(cp + 10);
+	else if (!strncmp(cp, "play", 4) && isspace(cp[4]))
+		play_cmd_plain(cp + 5);
+	else if (!strncmp(cp, "play-offset", 11) && isspace(cp[11]))
+		play_cmd_offset(cp + 12);
 	else if (!strcmp(cp, "play-stop"))
 		play_file_stop();
 	else if (!strncmp(cp, "tfo-req", 7) && isspace(cp[7]))