1 /* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file recv.c the stand-alone audio stream receiver */
9 #include "recv_cmd.lsg.h"
14 #include "buffer_tree.h"
22 /** Array of error strings. */
25 #define CMD_PTR (lls_cmd(0, recv_suite))
26 #define OPT_RESULT(_name, _lpr) \
27 (lls_opt_result(LSG_RECV_PARA_RECV_OPT_ ## _name, lpr))
28 #define OPT_GIVEN(_name, _lpr) (lls_opt_given(OPT_RESULT(_name, _lpr)))
29 #define OPT_UINT32_VAL(_name, _lpr) (lls_uint32_val(0, OPT_RESULT(_name, _lpr)))
30 #define OPT_STRING_VAL(_name, _lpr) (lls_string_val(0, OPT_RESULT(_name, _lpr)))
33 /** Always log to stderr. */
34 INIT_STDERR_LOGGING(loglevel);
36 static void handle_help_flag(struct lls_parse_result *lpr)
40 if (OPT_GIVEN(DETAILED_HELP, lpr))
41 help = lls_long_help(CMD_PTR);
42 else if (OPT_GIVEN(HELP, lpr))
43 help = lls_short_help(CMD_PTR);
48 print_receiver_helps(OPT_GIVEN(DETAILED_HELP, lpr));
53 * The main function of para_recv.
55 * \param argc number of arguments
56 * \param argv vector of arguments
58 * para_recv uses the specified receiver to receive an audio stream sent by
59 * para_server. The received data is written to stdout.
61 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
63 int main(int argc, char *argv[])
66 const struct receiver *r = NULL;
67 struct receiver_node rn;
68 struct stdout_task sot = {.btrn = NULL};
69 static struct sched s;
71 const struct lls_command *cmd;
72 struct lls_parse_result *lpr; /* command line */
73 struct lls_parse_result *receiver_lpr; /* receiver specific options */
76 ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
79 loglevel = OPT_UINT32_VAL(LOGLEVEL, lpr);
80 version_handle_flag("recv", OPT_GIVEN(VERSION, lpr));
81 handle_help_flag(lpr);
82 memset(&rn, 0, sizeof(struct receiver_node));
83 ret = check_receiver_arg(OPT_STRING_VAL(RECEIVER, lpr), &receiver_lpr);
86 cmd = lls_cmd(ret, recv_cmd_suite);
87 r = lls_user_data(cmd);
89 rn.lpr = receiver_lpr;
90 rn.btrn = btr_new_node(&(struct btr_node_description)
91 EMBRACE(.name = lls_command_name(cmd)));
95 sot.btrn = btr_new_node(&(struct btr_node_description)
96 EMBRACE(.parent = rn.btrn, .name = "stdout"));
97 stdout_task_register(&sot, &s);
99 ti.name = lls_command_name(cmd);
100 ti.pre_monitor = r->pre_monitor;
101 ti.post_monitor = r->post_monitor;
103 rn.task = task_register(&ti, &s);
105 s.default_timeout = 1000;
109 btr_remove_node(&sot.btrn);
111 btr_remove_node(&rn.btrn);
112 lls_free_parse_result(receiver_lpr, cmd);
114 lls_free_parse_result(lpr, CMD_PTR);
118 PARA_ERROR_LOG("%s\n", errctx);
120 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
122 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;