2 * Copyright (C) 2005-2013 Andre Noll <maan@systemlinux.org>
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 extern void afh_recv_init(struct receiver *r);
27 #define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
28 DEFINE_RECEIVER_ARRAY;
30 /** The gengetopt args info struct. */
31 static struct recv_args_info conf;
34 /** Always log to stderr. */
35 INIT_STDERR_LOGGING(loglevel);
37 /** init array of error codes used by para_recv */
40 __noreturn static void print_help_and_die(void)
42 int d = conf.detailed_help_given;
43 const char **p = d? recv_args_info_detailed_help
44 : recv_args_info_help;
46 printf_or_die("%s\n\n", RECV_CMDLINE_PARSER_PACKAGE "-"
47 RECV_CMDLINE_PARSER_VERSION);
48 printf_or_die("%s\n\n", recv_args_info_usage);
50 printf_or_die("%s\n", *p);
51 print_receiver_helps(d);
55 static void *parse_config(int argc, char *argv[], int *receiver_num)
57 recv_cmdline_parser(argc, argv, &conf);
58 HANDLE_VERSION_FLAG("recv", conf);
59 if (conf.help_given || conf.detailed_help_given)
61 loglevel = get_loglevel_by_name(conf.loglevel_arg);
62 return check_receiver_arg(conf.receiver_arg, receiver_num);
66 * The main function of para_recv.
68 * \param argc number of arguments
69 * \param argv vector of arguments
71 * para_recv uses the specified receiver to receive an audio stream sent by
72 * para_server. The received data is written to stdout.
74 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
76 int main(int argc, char *argv[])
78 int ret, r_opened = 0, receiver_num;
79 struct receiver *r = NULL;
80 struct receiver_node rn;
81 struct stdout_task sot;
82 static struct sched s;
84 s.default_timeout.tv_sec = 1;
85 s.default_timeout.tv_usec = 0;
87 memset(&sot, 0, sizeof(struct stdout_task));
88 memset(&rn, 0, sizeof(struct receiver_node));
91 rn.conf = parse_config(argc, argv, &receiver_num);
93 PARA_EMERG_LOG("parse failed\n");
96 r = &receivers[receiver_num];
98 rn.btrn = btr_new_node(&(struct btr_node_description)
99 EMBRACE(.name = r->name));
105 sot.btrn = btr_new_node(&(struct btr_node_description)
106 EMBRACE(.parent = rn.btrn, .name = "stdout"));
107 stdout_set_defaults(&sot);
108 register_task(&s, &sot.task);
110 rn.task.pre_select = r->pre_select;
111 rn.task.post_select = r->post_select;
112 sprintf(rn.task.status, "%s", r->name);
113 register_task(&s, &rn.task);
119 btr_remove_node(&rn.btrn);
120 btr_remove_node(&sot.btrn);
122 r->free_config(rn.conf);
125 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
126 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;