2 * Copyright (C) 2006-2012 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file write_common.c common functions of para_audiod and para_write */
16 #include "buffer_tree.h"
20 /** the array containing the names of all supported writers */
21 const char *writer_names[] ={WRITER_NAMES};
23 /** the array of supported writers */
24 struct writer writers[NUM_SUPPORTED_WRITERS] = {WRITER_ARRAY};
27 * Call the init function of each supported paraslash writer.
29 void writer_init(void)
34 writers[i].init(&writers[i]);
37 * Check if given string is a valid command line for any writer.
39 * \param \wa String of the form writer_name:options.
40 * \param writer_num Contains the number of the writer upon success.
42 * This function checks whether \a wa starts with the name of a supported
43 * paraslash writer, optionally followed by a colon and any options for that
44 * writer. If a valid writer name was found and further are present, the
45 * remaining part of \a wa is passed to that writer's config parser.
47 * \return On success, a pointer to the gengetopt args info struct is returned
48 * and \a writer_num contains the number of the writer. Otherwise this function
49 * prints an error message and calls exit().
51 void *check_writer_arg_or_die(const char *wa, int *writer_num)
55 PARA_INFO_LOG("checking %s\n", wa);
57 const char *name = writer_names[i];
58 size_t len = strlen(name);
62 if (strncmp(name, wa, len))
68 return writers[i].parse_config_or_die(c? wa + len + 1 : "");
70 PARA_EMERG_LOG("invalid writer %s\n", wa);
75 * Open a writer node and register the corresponding task.
77 * \param wn The writer node to open.
78 * \param parent The parent btr node (the source for the writer node).
79 * \param s The scheduler instance to register the task to.
81 * The configuration of the writer node stored in \p wn->conf must be
82 * initialized before this function may be called.
84 void register_writer_node(struct writer_node *wn, struct btr_node *parent,
87 struct writer *w = writers + wn->writer_num;
88 char *name = make_message("%s writer", writer_names[wn->writer_num]);
90 wn->btrn = btr_new_node(&(struct btr_node_description)
91 EMBRACE(.name = name, .parent = parent,
92 .handler = w->execute, .context = wn));
93 strcpy(wn->task.status, name);
95 wn->task.post_select = w->post_select;
96 wn->task.pre_select = w->pre_select;
97 register_task(s, &wn->task);
101 * Print the help text of all writers to stdout.
103 * \param detailed Whether to print the detailed help text.
105 void print_writer_helps(int detailed)
109 printf_or_die("\nAvailable writers: \n\t");
111 printf_or_die("%s%s", i? " " : "", writer_names[i]);
112 printf_or_die("\n\n");
114 struct writer *w = writers + i;
116 if (!w->help.short_help)
118 printf_or_die("Options for %s:\n", writer_names[i]);
119 ggo_print_help(&w->help, detailed);
123 static void get_btr_value(struct btr_node *btrn, const char *cmd,
127 int ret = btr_exec_up(btrn, cmd, &buf);
131 * This really should not happen. It means one of our parent
132 * nodes died unexpectedly. Proceed with fingers crossed.
134 PARA_CRIT_LOG("cmd %s: %s\n", cmd, para_strerror(-ret));
138 ret = para_atoi32(buf, result);
144 * Ask parent btr nodes for the sample rate of the current stream.
146 * \param btrn Where to start the search.
147 * \param result Filled in by this function.
149 * This function is assumed to succeed and terminates on errors.
151 void get_btr_sample_rate(struct btr_node *btrn, int32_t *result)
153 get_btr_value(btrn, "sample_rate", result);
157 * Ask parent btr nodes for the channel count of the current stream.
159 * \param btrn See \ref get_btr_sample_rate.
160 * \param result See \ref get_btr_sample_rate.
162 void get_btr_channels(struct btr_node *btrn, int32_t *result)
164 get_btr_value(btrn, "channels", result);
168 * Ask parent btr nodes for the number of bits per sample and the byte sex.
170 * \param btrn See \ref get_btr_sample_rate.
171 * \param result Contains the sample format as an enum sample_format type.
173 void get_btr_sample_format(struct btr_node *btrn, int32_t *result)
175 get_btr_value(btrn, "sample_format", result);