2 * Copyright (C) 2006-2010 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 */
17 #include "buffer_tree.h"
21 /** the array containing the names of all supported writers */
22 const char *writer_names
[] ={WRITER_NAMES
};
24 /** the array of supported writers */
25 struct writer writers
[NUM_SUPPORTED_WRITERS
] = {WRITER_ARRAY
};
28 * Call the init function of each supported paraslash writer.
30 void writer_init(void)
35 writers
[i
].init(&writers
[i
]);
38 * check if given string is a valid command line for any writer
40 * \param \wa string of the form writer_name:options
41 * \param writer_num contains the number of the writer upon success
43 * This function checks whether \a wa starts with the name of a supported
44 * paraslash writer, optionally followed by a colon and any options for that
45 * writer. If a valid writer name was found and further are present, the
46 * remaining part of \a wa is passed to that writer's config parser.
48 * \return On success, a pointer to the gengetopt args info struct is returned
49 * and \a writer_num contains the number of the writer. Otherwise this function
52 void *check_writer_arg(const char *wa
, int *writer_num
)
56 *writer_num
= -E_WRITE_COMMON_SYNTAX
;
57 PARA_INFO_LOG("checking %s\n", wa
);
59 const char *name
= writer_names
[i
];
60 size_t len
= strlen(name
);
64 if (strncmp(name
, wa
, len
))
69 if (c
&& !writers
[i
].parse_config
)
72 return writers
[i
].parse_config(c
? wa
+ len
+ 1 : "");
74 PARA_ERROR_LOG("writer not found\n");
78 void register_writer_node(struct writer_node
*wn
, struct btr_node
*parent
)
80 struct writer
*w
= writers
+ wn
->writer_num
;
81 char *name
= make_message("%s writer", writer_names
[wn
->writer_num
]);
84 wn
->btrn
= btr_new_node(&(struct btr_node_description
)
85 EMBRACE(.name
= name
, .parent
= parent
,
86 .handler
= w
->execute
, .context
= wn
));
87 strcpy(wn
->task
.status
, name
);
90 wn
->task
.post_select
= w
->post_select
;
91 wn
->task
.pre_select
= w
->pre_select
;
92 register_task(&wn
->task
);
96 * Setup a writer node with the default writer.
98 * If arg is \p NULL, the OS-dependent default writer is used with an empty
99 * configuration string. It defaults to alsa for Linux, osx for OS X, oss for
100 * *BSD and the file writer if neither of these is supported.
102 * Once the writer configuration has been retrieved, a writer node is created,
103 * its buffer tree node is added to the buffer tree as a child of the given
106 * Finally, the new writer node's taks structure is initialized and registered
107 * to the paraslash scheduler.
109 * \return A pointer to the allocated writer node group.
111 int setup_writer_node(const char *arg
, struct btr_node
*parent
,
112 struct writer_node
*wn
)
115 wn
->conf
= check_writer_arg(arg
, &wn
->writer_num
);
117 wn
->writer_num
= DEFAULT_WRITER
;
118 wn
->conf
= writers
[DEFAULT_WRITER
].parse_config("");
121 return -E_WRITE_COMMON_SYNTAX
;
122 register_writer_node(wn
, parent
);
128 * Print the help text of all writers to stdout.
130 * \param detailed Whether to print the detailed help text.
132 void print_writer_helps(int detailed
)
136 printf_or_die("\nAvailable writers: \n\t");
138 printf_or_die("%s%s", i
? " " : "", writer_names
[i
]);
139 printf_or_die("\n\n");
141 struct writer
*w
= writers
+ i
;
143 if (!w
->help
.short_help
)
145 printf_or_die("Options for %s:\n", writer_names
[i
]);
146 ggo_print_help(&w
->help
, detailed
);
150 static int get_btr_value(struct btr_node
*btrn
, const char *key
, int32_t *result
)
153 int ret
= btr_exec_up(btrn
, key
, &buf
);
157 ret
= para_atoi32(buf
, result
);
163 * Ask parent btr nodes for the samplerate of the current stream.
165 int get_btr_samplerate(struct btr_node
*btrn
, int32_t *result
)
167 return get_btr_value(btrn
, "samplerate", result
);
171 * Ask parent btr nodes for the channel count of the current stream.
173 int get_btr_channels(struct btr_node
*btrn
, int32_t *result
)
175 return get_btr_value(btrn
, "channels", result
);