2 * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file recv.c the stand-alone audio stream receiver */
10 #include <sys/types.h>
13 #include "recv_cmd.lsg.h"
18 #include "buffer_tree.h"
26 /** Array of error strings. */
29 #define CMD_PTR (lls_cmd(0, recv_suite))
30 #define OPT_RESULT(_name, _lpr) \
31 (lls_opt_result(LSG_RECV_PARA_RECV_OPT_ ## _name, lpr))
32 #define OPT_GIVEN(_name, _lpr) (lls_opt_given(OPT_RESULT(_name, _lpr)))
33 #define OPT_UINT32_VAL(_name, _lpr) (lls_uint32_val(0, OPT_RESULT(_name, _lpr)))
34 #define OPT_STRING_VAL(_name, _lpr) (lls_string_val(0, OPT_RESULT(_name, _lpr)))
37 /** Always log to stderr. */
38 INIT_STDERR_LOGGING(loglevel);
40 static void handle_help_flag(struct lls_parse_result *lpr)
44 if (OPT_GIVEN(DETAILED_HELP, lpr))
45 help = lls_long_help(CMD_PTR);
46 else if (OPT_GIVEN(HELP, lpr))
47 help = lls_short_help(CMD_PTR);
52 print_receiver_helps(OPT_GIVEN(DETAILED_HELP, lpr));
57 * The main function of para_recv.
59 * \param argc number of arguments
60 * \param argv vector of arguments
62 * para_recv uses the specified receiver to receive an audio stream sent by
63 * para_server. The received data is written to stdout.
65 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
67 int main(int argc, char *argv[])
70 const struct receiver *r = NULL;
71 struct receiver_node rn;
72 struct stdout_task sot = {.btrn = NULL};
73 static struct sched s;
75 const struct lls_command *cmd;
76 struct lls_parse_result *lpr; /* command line */
77 struct lls_parse_result *receiver_lpr; /* receiver specific options */
80 ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
83 loglevel = OPT_UINT32_VAL(LOGLEVEL, lpr);
84 version_handle_flag("recv", OPT_GIVEN(VERSION, lpr));
85 handle_help_flag(lpr);
87 memset(&rn, 0, sizeof(struct receiver_node));
88 ret = check_receiver_arg(OPT_STRING_VAL(RECEIVER, lpr), &receiver_lpr);
91 cmd = lls_cmd(ret, recv_cmd_suite);
92 r = lls_user_data(cmd);
94 rn.lpr = receiver_lpr;
95 rn.btrn = btr_new_node(&(struct btr_node_description)
96 EMBRACE(.name = lls_command_name(cmd)));
100 sot.btrn = btr_new_node(&(struct btr_node_description)
101 EMBRACE(.parent = rn.btrn, .name = "stdout"));
102 stdout_task_register(&sot, &s);
104 ti.name = lls_command_name(cmd);
105 ti.pre_select = r->pre_select;
106 ti.post_select = r->post_select;
108 rn.task = task_register(&ti, &s);
110 s.default_timeout.tv_sec = 1;
111 s.default_timeout.tv_usec = 0;
115 btr_remove_node(&sot.btrn);
117 btr_remove_node(&rn.btrn);
118 lls_free_parse_result(receiver_lpr, cmd);
120 lls_free_parse_result(lpr, CMD_PTR);
124 PARA_ERROR_LOG("%s\n", errctx);
126 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
128 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;