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"
18 #include "buffer_tree.h"
20 #include "recv.cmdline.h"
27 /** Array of error strings. */
30 /** The gengetopt args info struct. */
31 static struct recv_args_info conf;
34 /** Always log to stderr. */
35 INIT_STDERR_LOGGING(loglevel);
37 __noreturn static void print_help_and_die(void)
39 bool d = conf.detailed_help_given;
41 recv_cmdline_parser_print_detailed_help();
43 recv_cmdline_parser_print_help();
44 print_receiver_helps(d);
49 * The main function of para_recv.
51 * \param argc number of arguments
52 * \param argv vector of arguments
54 * para_recv uses the specified receiver to receive an audio stream sent by
55 * para_server. The received data is written to stdout.
57 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
59 int main(int argc, char *argv[])
62 bool r_opened = false;
63 const struct receiver *r = NULL;
64 struct receiver_node rn;
65 struct stdout_task sot = {.btrn = NULL};
66 static struct sched s;
68 const struct lls_command *cmd;
69 struct lls_parse_result *receiver_lpr; /* receiver specific options */
71 recv_cmdline_parser(argc, argv, &conf);
72 loglevel = get_loglevel_by_name(conf.loglevel_arg);
73 version_handle_flag("recv", conf.version_given);
75 if (conf.help_given || conf.detailed_help_given)
78 memset(&rn, 0, sizeof(struct receiver_node));
79 ret = check_receiver_arg(conf.receiver_arg, &receiver_lpr);
82 cmd = lls_cmd(ret, recv_cmd_suite);
83 r = lls_user_data(cmd);
85 rn.lpr = receiver_lpr;
86 rn.btrn = btr_new_node(&(struct btr_node_description)
87 EMBRACE(.name = lls_command_name(cmd)));
90 goto free_receiver_lpr;
93 sot.btrn = btr_new_node(&(struct btr_node_description)
94 EMBRACE(.parent = rn.btrn, .name = "stdout"));
95 stdout_task_register(&sot, &s);
97 ti.name = lls_command_name(cmd);
98 ti.pre_select = r->pre_select;
99 ti.post_select = r->post_select;
101 rn.task = task_register(&ti, &s);
103 s.default_timeout.tv_sec = 1;
104 s.default_timeout.tv_usec = 0;
108 btr_remove_node(&sot.btrn);
109 btr_remove_node(&rn.btrn);
111 lls_free_parse_result(receiver_lpr, cmd);
115 btr_remove_node(&rn.btrn);
116 btr_remove_node(&sot.btrn);
119 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
120 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;