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>
14 #include "recv_cmd.lsg.h"
19 #include "buffer_tree.h"
27 /** Array of error strings. */
30 #define CMD_PTR (lls_cmd(0, recv_suite))
31 #define OPT_RESULT(_name, _lpr) \
32 (lls_opt_result(LSG_RECV_PARA_RECV_OPT_ ## _name, lpr))
33 #define OPT_GIVEN(_name, _lpr) (lls_opt_given(OPT_RESULT(_name, _lpr)))
34 #define OPT_UINT32_VAL(_name, _lpr) (lls_uint32_val(0, OPT_RESULT(_name, _lpr)))
35 #define OPT_STRING_VAL(_name, _lpr) (lls_string_val(0, OPT_RESULT(_name, _lpr)))
38 /** Always log to stderr. */
39 INIT_STDERR_LOGGING(loglevel);
41 static void handle_help_flag(struct lls_parse_result *lpr)
45 if (OPT_GIVEN(DETAILED_HELP, lpr))
46 help = lls_long_help(CMD_PTR);
47 else if (OPT_GIVEN(HELP, lpr))
48 help = lls_short_help(CMD_PTR);
53 print_receiver_helps(OPT_GIVEN(DETAILED_HELP, lpr));
58 * The main function of para_recv.
60 * \param argc number of arguments
61 * \param argv vector of arguments
63 * para_recv uses the specified receiver to receive an audio stream sent by
64 * para_server. The received data is written to stdout.
66 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
68 int main(int argc, char *argv[])
71 const struct receiver *r = NULL;
72 struct receiver_node rn;
73 struct stdout_task sot = {.btrn = NULL};
74 static struct sched s;
76 const struct lls_command *cmd;
77 struct lls_parse_result *lpr; /* command line */
78 struct lls_parse_result *receiver_lpr; /* receiver specific options */
81 ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
84 loglevel = OPT_UINT32_VAL(LOGLEVEL, lpr);
85 version_handle_flag("recv", OPT_GIVEN(VERSION, lpr));
86 handle_help_flag(lpr);
88 memset(&rn, 0, sizeof(struct receiver_node));
89 ret = check_receiver_arg(OPT_STRING_VAL(RECEIVER, lpr), &receiver_lpr);
92 cmd = lls_cmd(ret, recv_cmd_suite);
93 r = lls_user_data(cmd);
95 rn.lpr = receiver_lpr;
96 rn.btrn = btr_new_node(&(struct btr_node_description)
97 EMBRACE(.name = lls_command_name(cmd)));
101 sot.btrn = btr_new_node(&(struct btr_node_description)
102 EMBRACE(.parent = rn.btrn, .name = "stdout"));
103 stdout_task_register(&sot, &s);
105 ti.name = lls_command_name(cmd);
106 ti.pre_select = r->pre_select;
107 ti.post_select = r->post_select;
109 rn.task = task_register(&ti, &s);
111 s.default_timeout.tv_sec = 1;
112 s.default_timeout.tv_usec = 0;
116 btr_remove_node(&sot.btrn);
118 btr_remove_node(&rn.btrn);
119 lls_free_parse_result(receiver_lpr, cmd);
121 lls_free_parse_result(lpr, CMD_PTR);
125 PARA_ERROR_LOG("%s\n", errctx);
127 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
129 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;