a7a957dddde4188381ec042896f75792d965402e
2 * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file recv.c the stand-alone audio stream receiver */
26 #include "recv.cmdline.h"
31 /** the gengetopt args info struct */
32 struct recv_args_info conf
;
34 /** always log to stderr */
35 INIT_STDERR_LOGGING(conf
.loglevel_arg
);
37 /** init array of error codes used by para_recv */
40 static void *parse_config(int argc
, char *argv
[], int *receiver_num
)
44 if (recv_cmdline_parser(argc
, argv
, &conf
))
46 HANDLE_VERSION_FLAG("recv", conf
);
47 if (conf
.list_receivers_given
) {
48 printf("available receivers: ");
49 for (i
= 0; receivers
[i
].name
; i
++)
50 printf("%s%s", i
? " " : "", receivers
[i
].name
);
51 printf("\nTry\n\tpara_recv -r '<receivername> -h'\n"
52 "for help on <receivername>.\n");
55 return check_receiver_arg(conf
.receiver_arg
, receiver_num
);
58 static void rn_event_handler(struct task
*t
)
60 struct receiver_node
*rn
= t
->private_data
;
61 PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t
->ret
));
67 * the main function of para_recv
69 * \param argc number of arguments
70 * \param argv vector of arguments
72 * para_recv uses the specified receiver to receive an audio stream sent by
73 * para_server. The received data is written to stdout.
75 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
77 int main(int argc
, char *argv
[])
79 int ret
, r_opened
= 0, receiver_num
;
80 struct receiver
*r
= NULL
;
81 struct receiver_node rn
;
82 struct stdout_task sot
;
85 s
.default_timeout
.tv_sec
= 1;
86 s
.default_timeout
.tv_usec
= 0;
88 memset(&rn
, 0, sizeof(struct receiver_node
));
89 for (ret
= 0; receivers
[ret
].name
; ret
++)
90 receivers
[ret
].init(&receivers
[ret
]);
92 rn
.conf
= parse_config(argc
, argv
, &receiver_num
);
94 PARA_EMERG_LOG("%s", "parse failed\n");
97 r
= &receivers
[receiver_num
];
104 stdout_set_defaults(&sot
);
106 sot
.loaded
= &rn
.loaded
;
107 sot
.input_eof
= &rn
.eof
;
108 register_task(&sot
.task
);
110 rn
.task
.private_data
= &rn
;
111 rn
.task
.pre_select
= r
->pre_select
;
112 rn
.task
.post_select
= r
->post_select
;
113 rn
.task
.event_handler
= rn_event_handler
;
114 sprintf(rn
.task
.status
, "receiver node");
115 register_task(&rn
.task
);
124 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret
));
125 return ret
< 0? EXIT_FAILURE
: EXIT_SUCCESS
;