2 * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
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"
19 #include "write_common.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
50 * prints an error message and calls exit().
52 void *check_writer_arg_or_die(const char *wa
, int *writer_num
)
64 PARA_INFO_LOG("checking %s\n", wa
);
66 const char *name
= writer_names
[i
];
67 size_t len
= strlen(name
);
72 if (strncmp(name
, wa
, len
))
76 cmdline
= c
? wa
+ len
+ 1 : NULL
;
80 PARA_EMERG_LOG("invalid writer %s\n", wa
);
83 ret
= create_shifted_argv(cmdline
, " \t", &argv
);
85 PARA_EMERG_LOG("%s: %s\n", wa
, para_strerror(-ret
));
89 argv
[0] = make_message("%s_write", writer_names
[i
]);
91 conf
= writers
[i
].parse_config_or_die(argc
, argv
);
97 * Open a writer node and register the corresponding task.
99 * \param wn The writer node to open.
100 * \param parent The parent btr node (the source for the writer node).
101 * \param s The scheduler instance to register the task to.
103 * The configuration of the writer node stored in \p wn->conf must be
104 * initialized before this function may be called.
106 void register_writer_node(struct writer_node
*wn
, struct btr_node
*parent
,
109 struct writer
*w
= writers
+ wn
->writer_num
;
111 wn
->btrn
= btr_new_node(&(struct btr_node_description
)
112 EMBRACE(.name
= writer_names
[wn
->writer_num
], .parent
= parent
,
113 .handler
= w
->execute
, .context
= wn
));
114 wn
->task
= task_register(&(struct task_info
) {
115 .name
= writer_names
[wn
->writer_num
],
116 .pre_select
= w
->pre_select
,
117 .post_select
= w
->post_select
,
123 * Print the help text of all writers to stdout.
125 * \param flags Passed to \ref ggo_print_help().
127 void print_writer_helps(unsigned flags
)
131 printf_or_die("\nAvailable writers: ");
133 printf_or_die("%s%s", i
? " " : "", writer_names
[i
]);
136 struct writer
*w
= writers
+ i
;
138 if (!w
->help
.short_help
)
140 printf_or_die("\n%s: %s", writer_names
[i
],
142 ggo_print_help(&w
->help
, flags
);
146 static void get_btr_value(struct btr_node
*btrn
, const char *cmd
,
150 int ret
= btr_exec_up(btrn
, cmd
, &buf
);
154 * This really should not happen. It means one of our parent
155 * nodes died unexpectedly. Proceed with fingers crossed.
157 PARA_CRIT_LOG("cmd %s: %s\n", cmd
, para_strerror(-ret
));
161 ret
= para_atoi32(buf
, result
);
167 * Ask parent btr nodes for the sample rate of the current stream.
169 * \param btrn Where to start the search.
170 * \param result Filled in by this function.
172 * This function is assumed to succeed and terminates on errors.
174 void get_btr_sample_rate(struct btr_node
*btrn
, int32_t *result
)
176 get_btr_value(btrn
, "sample_rate", result
);
180 * Ask parent btr nodes for the channel count of the current stream.
182 * \param btrn See \ref get_btr_sample_rate.
183 * \param result See \ref get_btr_sample_rate.
185 void get_btr_channels(struct btr_node
*btrn
, int32_t *result
)
187 get_btr_value(btrn
, "channels", result
);
191 * Ask parent btr nodes for the number of bits per sample and the byte sex.
193 * \param btrn See \ref get_btr_sample_rate.
194 * \param result Contains the sample format as an enum sample_format type.
196 void get_btr_sample_format(struct btr_node
*btrn
, int32_t *result
)
198 get_btr_value(btrn
, "sample_format", result
);