comparison 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
comparison
equal deleted inserted replaced
10:395c56969bc4 11:aa2ba9b432af
1 /* 1 /*
2 * In this module we implement stdin command handling: we start with 2 * In this module we implement stdin command handling: 'disc' command
3 * 'disc' command for caller-initiated disconnect, and then we'll add 3 * for caller-initiated disconnect; 'play' and 'play-stop' commands
4 * play commands for RTP output. 4 * for RTP output.
5 */ 5 */
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
11 #include <strings.h> 11 #include <strings.h>
12
13 static void
14 play_cmd(args)
15 char *args;
16 {
17 char *cp, *filename;
18 unsigned frame_len;
19 int loop;
20
21 for (cp = args; isspace(*cp); cp++)
22 ;
23 if (!*cp) {
24 inv_syntax: fprintf(stderr, "error: play command invalid syntax\n");
25 return;
26 }
27 for (filename = cp; *cp && !isspace(*cp); cp++)
28 ;
29 if (!*cp)
30 goto inv_syntax;
31 *cp++ = '\0';
32 while (isspace(*cp))
33 cp++;
34 if (!isdigit(*cp))
35 goto inv_syntax;
36 frame_len = strtoul(cp, &cp, 0);
37 if (*cp && !isspace(*cp))
38 goto inv_syntax;
39 if (frame_len < 1 || frame_len > 160) {
40 fprintf(stderr, "error: frame length argument out of range\n");
41 return;
42 }
43 while (isspace(*cp))
44 cp++;
45 if (*cp) {
46 if (strcmp(cp, "loop"))
47 goto inv_syntax;
48 loop = 1;
49 } else
50 loop = 0;
51 play_file_cmdop(filename, frame_len, loop);
52 }
12 53
13 void 54 void
14 select_stdin() 55 select_stdin()
15 { 56 {
16 char buf[256], *cp; 57 char buf[256], *cp;
26 ; 67 ;
27 if (!*cp) 68 if (!*cp)
28 return; 69 return;
29 if (!strcmp(cp, "disc")) 70 if (!strcmp(cp, "disc"))
30 disconnect_command(); 71 disconnect_command();
72 else if (!strncmp(cp, "play", 4) && isspace(cp[4]))
73 play_cmd(cp + 5);
74 else if (!strcmp(cp, "play-stop"))
75 play_file_stop();
31 else 76 else
32 fprintf(stderr, "error: non-understood stdin command\n"); 77 fprintf(stderr, "error: non-understood stdin command\n");
33 } 78 }