annotate test-voice/user_cmd.c @ 13:059b79c9f0c3

sipout-test-voice: add DMW output mode
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Apr 2024 17:09:32 -0800
parents 35c0d9f03c0a
children f96153d15889
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
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 tfo_req_cmd(args)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 char *args;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *cp;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 unsigned sig, codec;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (cp = args; isspace(*cp); cp++)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 ;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (!isdigit(*cp)) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 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
47 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 sig = strtoul(cp, &cp, 0);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (sig > 0xFF) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: Sig argument out of range\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 while (isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cp++;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!isdigit(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 codec = strtoul(cp, &cp, 0);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (*cp && !isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (codec > 14) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 fprintf(stderr, "error: Codec_Type argument out of range\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
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 while (isspace(*cp))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 cp++;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (*cp)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 goto inv_syntax;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 send_tfo_req(sig, codec);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 select_stdin()
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 char buf[256], *cp;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fgets(buf, sizeof buf, stdin);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 cp = index(buf, '\n');
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (cp) {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 while (cp > buf && isspace(cp[-1]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 cp--;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 *cp = '\0';
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 for (cp = buf; isspace(*cp); cp++)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 ;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (!*cp)
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 return;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 send_bye_req();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 send_cancel_req();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 else if (!strncmp(cp, "pcm-fill", 8) && isspace(cp[8]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 pcm_fill_cmd(cp + 9);
13
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
96 else if (!strcmp(cp, "dmw-on"))
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
97 cmd_dmw_on();
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
98 else if (!strcmp(cp, "dmw-off"))
059b79c9f0c3 sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
99 cmd_dmw_off();
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 else if (!strncmp(cp, "tfo-req", 7) && isspace(cp[7]))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 tfo_req_cmd(cp + 8);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 else if (!strcmp(cp, "tfo-stop"))
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 stop_tfo_out();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 else
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 fprintf(stderr, "error: non-understood stdin command\n");
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }