- if (num_filters(i) < filternum)
- continue;
- /* success */
- j = 1;
- list_for_each_entry(fn, &s->fci->filters, node)
- if (filternum <= 0 || j++ == filternum)
- break;
- return fn;
- }
- return NULL;
-}
-
-static void start_stream_writer(int slot_num)
-{
- int ret, fds[3] = {1, -1, -1};
- struct slot_info *s = &slot[slot_num];
- struct audio_format_info *a = &afi[s->format];
- char *glob = NULL;
-
- if (a->write_cmd)
- glob = glob_cmd(a->write_cmd);
- if (!glob)
- glob = para_strdup("para_play");
- PARA_INFO_LOG("starting stream writer: %s\n", glob);
- open_filters(slot_num);
- ret = para_exec_cmdline_pid(&s->wpid, glob, fds);
- free(glob);
- if (ret < 0) {
- PARA_ERROR_LOG("exec failed (%d)\n", ret);
- return;
- }
- s->write_fd = fds[0];
- add_close_on_fork_list(s->write_fd);
- /* we write to this fd in do_select, so we need non-blocking */
- fcntl(s->write_fd, F_SETFL, O_NONBLOCK);
- gettimeofday(&s->wstime, NULL);
- current_decoder = slot_num;
- activate_inactive_grab_clients(slot_num, s->format, &s->fci->filters);
-}
-
-static void open_receiver(int format)
-{
- struct audio_format_info *a = &afi[format];
- struct slot_info *s;
- int ret, slot_num;
-
- slot_num = get_empty_slot();
- if (slot_num < 0)
- clean_exit(EXIT_FAILURE, PARA_STRERROR(-slot_num));
- s = &slot[slot_num];
- s->format = format;
- gettimeofday(&s->rtime, NULL);
- s->wtime = s->rtime;
- s->receiver_node = para_calloc(sizeof(struct receiver_node));
- s->receiver_node->conf = a->receiver_conf;
- ret = a->receiver->open(s->receiver_node);
- if (ret < 0) {
- PARA_ERROR_LOG("failed to open receiver (%s)\n",
- PARA_STRERROR(-ret));
- free(s->receiver_node);
- s->receiver_node = NULL;
- return;