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>
16 #include "buffer_tree.h"
18 #include "recv.cmdline.h"
25 /** Array of error strings. */
28 extern void afh_recv_init(struct receiver *r);
30 #define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
31 DEFINE_RECEIVER_ARRAY;
33 /** The gengetopt args info struct. */
34 static struct recv_args_info conf;
37 /** Always log to stderr. */
38 INIT_STDERR_LOGGING(loglevel);
40 __noreturn static void print_help_and_die(void)
42 struct ggo_help h = DEFINE_GGO_HELP(recv);
43 bool d = conf.detailed_help_given;
45 ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
46 print_receiver_helps(d? GPH_MODULE_FLAGS_DETAILED : GPH_MODULE_FLAGS);
51 * The main function of para_recv.
53 * \param argc number of arguments
54 * \param argv vector of arguments
56 * para_recv uses the specified receiver to receive an audio stream sent by
57 * para_server. The received data is written to stdout.
59 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
61 int main(int argc, char *argv[])
63 int ret, r_opened = 0, receiver_num;
64 struct receiver *r = NULL;
65 struct receiver_node rn;
66 struct stdout_task sot = {.btrn = NULL};
67 static struct sched s;
70 recv_cmdline_parser(argc, argv, &conf);
71 loglevel = get_loglevel_by_name(conf.loglevel_arg);
72 version_handle_flag("recv", conf.version_given);
74 if (conf.help_given || conf.detailed_help_given)
77 memset(&rn, 0, sizeof(struct receiver_node));
78 rn.conf = check_receiver_arg(conf.receiver_arg, &receiver_num);
80 PARA_EMERG_LOG("invalid receiver specifier\n");
84 r = &receivers[receiver_num];
86 rn.btrn = btr_new_node(&(struct btr_node_description)
87 EMBRACE(.name = r->name));
93 sot.btrn = btr_new_node(&(struct btr_node_description)
94 EMBRACE(.parent = rn.btrn, .name = "stdout"));
95 stdout_task_register(&sot, &s);
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;
110 btr_remove_node(&rn.btrn);
111 btr_remove_node(&sot.btrn);
113 r->free_config(rn.conf);
116 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
117 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;