annotate test-voice/user_cmd.c @ 14:f96153d15889

sipout-test-voice: implement play from file
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 May 2024 22:10:38 -0800
parents 059b79c9f0c3
children 71f01a834820
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement stdin command handling, supporting
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * user-initiated CANCEL and BYE as well as TFO testing commands.
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 pcm_fill_cmd(arg)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *arg;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char *cp;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned octet;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 for (cp = arg; isspace(*cp); cp++)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 ;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (!isxdigit(*cp)) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 inv_syntax: fprintf(stderr, "error: pcm-fill command invalid syntax\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 octet = strtoul(cp, &cp, 16);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (*cp)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (octet > 0xFF) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fprintf(stderr,
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 "error: pcm-fill octet argument out of range\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 set_pcm_fill_octet(octet);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 static void
14
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
37 play_file_cmd(args)
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
38 char *args;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
39 {
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
40 char *cp, *filename;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
41 int loop;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
42
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
43 for (cp = args; isspace(*cp); cp++)
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
44 ;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
45 if (!*cp) {
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
46 inv_syntax: fprintf(stderr, "error: play-file command invalid syntax\n");
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
47 return;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
48 }
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
49 for (filename = cp; *cp && !isspace(*cp); cp++)
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
50 ;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
51 if (*cp) {
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
52 *cp++ = '\0';
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
53 while (isspace(*cp))
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
54 cp++;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
55 if (strcmp(cp, "loop"))
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
56 goto inv_syntax;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
57 loop = 1;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
58 } else
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
59 loop = 0;
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
60 play_file_cmdop(filename, loop);
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
61 }
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
62
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
63 static void
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 tfo_req_cmd(args)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 char *args;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 char *cp;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 unsigned sig, codec;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 for (cp = args; isspace(*cp); cp++)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 ;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (!isdigit(*cp)) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 inv_syntax: fprintf(stderr, "error: tfo-req command invalid syntax\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 sig = strtoul(cp, &cp, 0);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (!isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (sig > 0xFF) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(stderr, "error: Sig argument out of range\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 while (isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 cp++;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (!isdigit(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 codec = strtoul(cp, &cp, 0);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (*cp && !isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (codec > 14) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fprintf(stderr, "error: Codec_Type argument out of range\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 while (isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 cp++;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (*cp)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 send_tfo_req(sig, codec);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 select_stdin()
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 char buf[256], *cp;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 fgets(buf, sizeof buf, stdin);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cp = index(buf, '\n');
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (cp) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 while (cp > buf && isspace(cp[-1]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 cp--;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 *cp = '\0';
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 for (cp = buf; isspace(*cp); cp++)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 ;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (!*cp)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 send_bye_req();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 send_cancel_req();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 else if (!strncmp(cp, "pcm-fill", 8) && isspace(cp[8]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 pcm_fill_cmd(cp + 9);
13
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
123 else if (!strcmp(cp, "dmw-on"))
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
124 cmd_dmw_on();
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
125 else if (!strcmp(cp, "dmw-off"))
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
126 cmd_dmw_off();
14
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
127 else if (!strncmp(cp, "play-file", 9) && isspace(cp[9]))
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
128 play_file_cmd(cp + 10);
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
129 else if (!strcmp(cp, "play-stop"))
f96153d15889 sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents: 13
diff changeset
130 play_file_stop();
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 else if (!strncmp(cp, "tfo-req", 7) && isspace(cp[7]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 tfo_req_cmd(cp + 8);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 else if (!strcmp(cp, "tfo-stop"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 stop_tfo_out();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 else
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 fprintf(stderr, "error: non-understood stdin command\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }