FreeCalypso > hg > themwi-interim
diff mtctest/user_cmd.c @ 11:aa2ba9b432af
mtctest: implement play and play-stop commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 09 Jun 2024 04:32:57 +0000 |
parents | a902ccbf6bbc |
children |
line wrap: on
line diff
--- a/mtctest/user_cmd.c Sun Jun 09 04:24:53 2024 +0000 +++ b/mtctest/user_cmd.c Sun Jun 09 04:32:57 2024 +0000 @@ -1,7 +1,7 @@ /* - * In this module we implement stdin command handling: we start with - * 'disc' command for caller-initiated disconnect, and then we'll add - * play commands for RTP output. + * In this module we implement stdin command handling: 'disc' command + * for caller-initiated disconnect; 'play' and 'play-stop' commands + * for RTP output. */ #include <ctype.h> @@ -10,6 +10,47 @@ #include <string.h> #include <strings.h> +static void +play_cmd(args) + char *args; +{ + char *cp, *filename; + unsigned frame_len; + int loop; + + for (cp = args; isspace(*cp); cp++) + ; + if (!*cp) { +inv_syntax: fprintf(stderr, "error: play 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; + frame_len = strtoul(cp, &cp, 0); + if (*cp && !isspace(*cp)) + goto inv_syntax; + if (frame_len < 1 || frame_len > 160) { + fprintf(stderr, "error: frame length argument out of range\n"); + return; + } + while (isspace(*cp)) + cp++; + if (*cp) { + if (strcmp(cp, "loop")) + goto inv_syntax; + loop = 1; + } else + loop = 0; + play_file_cmdop(filename, frame_len, loop); +} + void select_stdin() { @@ -28,6 +69,10 @@ return; if (!strcmp(cp, "disc")) disconnect_command(); + else if (!strncmp(cp, "play", 4) && isspace(cp[4])) + play_cmd(cp + 5); + else if (!strcmp(cp, "play-stop")) + play_file_stop(); else fprintf(stderr, "error: non-understood stdin command\n"); }