static ssize_t aacdec(char *input_buffer, size_t len, struct filter_node *fn)
{
struct private_aacdec_data *padd = fn->private_data;
- struct filter_chain_info *fci = fn->fci;
+ struct filter_chain *fc = fn->fc;
int i, ret;
unsigned char *p, *outbuffer;
unsigned char *inbuf = (unsigned char*)input_buffer;
if (fn->loaded > fn->bufsize * 4 / 5)
return 0;
- if (len < 1000 && !*fci->eof)
+ if (len < 1000 && !*fc->eof)
return 0;
if (!padd->initialized) {
&channels) < 0)
goto out;
}
- fci->samplerate = rate;
- fci->channels = channels;
+ fc->samplerate = rate;
+ fc->channels = channels;
PARA_INFO_LOG("rate: %u, channels: %d\n",
- fci->samplerate, fci->channels);
+ fc->samplerate, fc->channels);
padd->initialized = 1;
}
if (padd->decoder_length > 0) {
#define INBUF_SIZE 32 * 1024
-static struct filter_chain_info filter_chain_info_struct;
-static struct filter_chain_info *fci = &filter_chain_info_struct;
+static struct filter_chain filter_chain_struct;
+static struct filter_chain *fc = &filter_chain_struct;
struct gengetopt_args_info conf;
int i, filter_num;
struct filter_node *fn;
- INIT_LIST_HEAD(&fci->filters);
+ INIT_LIST_HEAD(&fc->filters);
- fci->inbuf = inbuf;
- fci->in_loaded = &loaded;
- fci->eof = &eof;
+ fc->inbuf = inbuf;
+ fc->in_loaded = &loaded;
+ fc->eof = &eof;
for (i = 0; i < conf.filter_given; i++) {
char *fa = para_strdup(conf.filter_arg[i]);
free(fn);
return filter_num;
}
- fn->fci = fci;
+ fn->fc = fc;
INIT_LIST_HEAD(&fn->callbacks);
fn->filter = &filters[filter_num];
PARA_DEBUG_LOG("adding %s to filter chain\n", fn->filter->name);
- list_add_tail(&fn->node, &fci->filters);
+ list_add_tail(&fn->node, &fc->filters);
}
- if (list_empty(&fci->filters))
+ if (list_empty(&fc->filters))
return -E_NO_FILTERS;
return 1;
}
{
struct filter_node *fn;
- list_for_each_entry(fn, &fci->filters, node) {
+ list_for_each_entry(fn, &fc->filters, node) {
fn->filter->open(fn);
PARA_INFO_LOG("opened %s filter\n", fn->filter->name);
- fci->outbuf = fn->buf;
- fci->out_loaded = &fn->loaded;
+ fc->outbuf = fn->buf;
+ fc->out_loaded = &fn->loaded;
}
}
if (ret < 0)
goto out;
open_filters();
- ib = fci->inbuf;
- ob = fci->outbuf;
- il = fci->in_loaded;
- ol = fci->out_loaded;
+ ib = fc->inbuf;
+ ob = fc->outbuf;
+ il = fc->in_loaded;
+ ol = fc->out_loaded;
PARA_DEBUG_LOG("ib %p in, ob: %p\n", ib, ob);
again:
if (*il < INBUF_SIZE && !eof) {
eof = 1;
*il += ret;
}
- ret = filter_io(fci);
+ ret = filter_io(fc);
if (ret < 0)
goto out;
converted = ret;
out:
if (ret < 0)
PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
- close_filters(fci);
+ close_filters(fc);
return ret;
}
* describes one running instance of a chain of filters
*
*/
-struct filter_chain_info {
-/**
- *
- *
- * the number of channels of the current stream
- *
- * Set by the decoding filter
- */
- unsigned int channels;
-/**
- *
- *
- * current samplerate in Hz
- *
- * Set by the decoding filter
- */
- unsigned int samplerate;
-/**
- *
- *
- * the list containing all filter nodes in this filter chain
- */
- struct list_head filters;
-/**
- *
- *
- * the input buffer of the filter chain
- *
- * This is set to point to the output buffer of the receiving application (the
- * buffer used to read from stdin for para_filter; the output buffer of the
- * current receiver for para_audiod)
- */
- char *inbuf;
-/**
- *
- *
- * the output buffer of the filter chain
- *
- * Points to the output buffer of the last filter in the filter chain
-**/
- char *outbuf;
-/**
- *
- *
- * pointer to variable containing the number of bytes loaded in the input buffer
- */
- size_t *in_loaded;
-/**
- *
- *
- * pointer to variable containing the number of bytes loaded in the output buffer
- */
- size_t *out_loaded;
-/**
- *
- *
- * non-zero if end of file was encountered
- */
- int *eof;
-/**
- *
- *
- * non-zero if an error occured
- */
- int error;
+struct filter_chain {
+ /**
+ *
+ *
+ * the number of channels of the current stream
+ *
+ * Set by the decoding filter
+ */
+ unsigned int channels;
+ /**
+ *
+ *
+ * current samplerate in Hz
+ *
+ * Set by the decoding filter
+ */
+ unsigned int samplerate;
+ /**
+ *
+ *
+ * the list containing all filter nodes in this filter chain
+ */
+ struct list_head filters;
+ /**
+ *
+ *
+ * the input buffer of the filter chain
+ *
+ * This is set to point to the output buffer of the receiving application (the
+ * buffer used to read from stdin for para_filter; the output buffer of the
+ * current receiver for para_audiod)
+ */
+ char *inbuf;
+ /**
+ *
+ *
+ * the output buffer of the filter chain
+ *
+ * Points to the output buffer of the last filter in the filter chain
+ **/
+ char *outbuf;
+ /**
+ *
+ *
+ * pointer to variable containing the number of bytes loaded in the input buffer
+ */
+ size_t *in_loaded;
+ /**
+ *
+ *
+ * pointer to variable containing the number of bytes loaded in the output buffer
+ */
+ size_t *out_loaded;
+ /**
+ *
+ *
+ * non-zero if end of file was encountered
+ */
+ int *eof;
+ /**
+ *
+ *
+ * non-zero if an error occured
+ */
+ int error;
};
/**
*
* the filter chain this filter node belongs to
*/
- struct filter_chain_info *fci;
+ struct filter_chain *fc;
/**
*
*
};
-void close_filters(struct filter_chain_info *fci);
-int filter_io(struct filter_chain_info *fci);
+void close_filters(struct filter_chain *fc);
+int filter_io(struct filter_chain *fc);
void filter_init(struct filter *all_filters);
int check_filter_arg(char *filter_arg, void **conf);
int del_filter_callback(struct filter_callback *fcb);
/**
* call the convert function of each filter
*
- * \param fci the filter chain containing the list of filter nodes.
+ * \param fc the filter chain containing the list of filter nodes.
*
* This is the core function of the filter subsystem. It loops over the list of
- * filter nodes determined by \a fci and calls the filter's convert function if
+ * filter nodes determined by \a fc and calls the filter's convert function if
* there is input available for the filter node in question. If the convert
* function consumed some or all of its input data, all registered input
* callbacks are called. Similarly, if a convert function produced output, all
*
* \sa filter_node, filter#convert, filter_callback
*/
-int filter_io(struct filter_chain_info *fci)
+int filter_io(struct filter_chain *fc)
{
struct filter_node *fn;
char *ib;
size_t *loaded;
int conv, conv_total = 0;
again:
- ib = fci->inbuf;
- loaded = fci->in_loaded;
+ ib = fc->inbuf;
+ loaded = fc->in_loaded;
conv = 0;
- list_for_each_entry(fn, &fci->filters, node) {
+ list_for_each_entry(fn, &fc->filters, node) {
int ret;
if (*loaded && fn->loaded < fn->bufsize) {
size_t old_fn_loaded = fn->loaded;
- PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n", fci, *loaded, fn->filter->name);
+ PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n",
+ fc, *loaded, fn->filter->name);
ret = fn->filter->convert(ib, *loaded, fn);
if (ret < 0) {
- if (!fci->error)
- fci->error = -ret;
+ if (!fc->error)
+ fc->error = -ret;
return ret;
}
- call_callbacks(fn, ib, ret, fn->buf + old_fn_loaded, fn->loaded - old_fn_loaded);
+ call_callbacks(fn, ib, ret, fn->buf + old_fn_loaded,
+ fn->loaded - old_fn_loaded);
*loaded -= ret;
conv += ret;
if (*loaded && ret) {
/**
* close all filter nodes and its callbacks
*
- * \param fci the filter chain to close
+ * \param fc the filter chain to close
*
- * For each filter node determined by \a fci, call the close function of each
+ * For each filter node determined by \a fc, call the close function of each
* registered filter callback as well as the close function of the
* corresponding filter. Free all resources and destroy all callback lists and
* the filter node list.
*
* \sa filter::close, filter_callback::close
*/
-void close_filters(struct filter_chain_info *fci)
+void close_filters(struct filter_chain *fc)
{
struct filter_node *fn, *tmp;
- if (!fci)
+ if (!fc)
return;
- PARA_DEBUG_LOG("closing filter chain %p\n", fci);
- list_for_each_entry_safe(fn, tmp, &fci->filters, node) {
- PARA_NOTICE_LOG("closing %s filter callbacks (fci %p, fn %p)\n", fn->filter->name, fci, fn);
+ PARA_DEBUG_LOG("closing filter chain %p\n", fc);
+ list_for_each_entry_safe(fn, tmp, &fc->filters, node) {
+ PARA_NOTICE_LOG("closing %s filter callbacks (fc %p, fn %p)\n", fn->filter->name, fc, fn);
close_callbacks(fn);
- PARA_NOTICE_LOG("closing %s filter (fci %p, fn %p)\n", fn->filter->name, fci, fn);
+ PARA_NOTICE_LOG("closing %s filter (fc %p, fn %p)\n", fn->filter->name, fc, fn);
fn->filter->close(fn);
list_del(&fn->node);
free(fn);
goto out;
return FRAME_HEADER_SIZE;
}
- fn->fci->samplerate = pmd->frame.header.samplerate;
- fn->fci->channels = MAD_NCHANNELS(&pmd->frame.header);
+ fn->fc->samplerate = pmd->frame.header.samplerate;
+ fn->fc->channels = MAD_NCHANNELS(&pmd->frame.header);
ret = mad_frame_decode(&pmd->frame, &pmd->stream);
if (ret) {
if (MAD_RECOVERABLE(pmd->stream.error) || pmd->stream.error == MAD_ERROR_BUFLEN)
if (pmd->stream.next_frame) { /* we still have some data */
size_t off = pmd->stream.bufend - pmd->stream.next_frame;
PARA_DEBUG_LOG("converted %zd, rate: %u, returning %zd\n", len - off,
- fn->fci->samplerate, copy - off);
+ fn->fc->samplerate, copy - off);
return copy - off;
}
return copy;
size_t ret, have = pod->inbuf_len - pod->converted;
char *p = pod->inbuf + pod->converted;
- if (*fn->fci->eof)
+ if (*fn->fc->eof)
return 0;
// PARA_DEBUG_LOG("pod = %p\n", pod);
// PARA_DEBUG_LOG("vorbis requests %d bytes, have %d\n", size * nmemb, have);
if (!pod->vf) {
int ib = 1024 * conf->initial_buffer_arg; /* initial buffer */
- if (len <ib && !*fn->fci->eof && !fn->fci->error) {
+ if (len <ib && !*fn->fc->eof && !fn->fc->error) {
PARA_INFO_LOG("initial input buffer %zd/%d, waiting for more data\n",
len, ib);
return 0;
return -E_OGGDEC_BADHEADER;
if (ret < 0)
return -E_OGGDEC_FAULT;
- fn->fci->channels = ov_info(pod->vf, 0)->channels;
- fn->fci->samplerate = ov_info(pod->vf, 0)->rate;
- PARA_NOTICE_LOG("%d channels, %d Hz\n", fn->fci->channels, fn->fci->samplerate);
+ fn->fc->channels = ov_info(pod->vf, 0)->channels;
+ fn->fc->samplerate = ov_info(pod->vf, 0)->rate;
+ PARA_NOTICE_LOG("%d channels, %d Hz\n", fn->fc->channels, fn->fc->samplerate);
}
again:
ret = ov_read(pod->vf, fn->buf + fn->loaded, fn->bufsize - fn->loaded,
if (ret < 0)
return -E_OGGDEC_BADLINK;
fn->loaded += ret;
- if (!*fn->fci->eof && !fn->fci->error && fn->loaded < fn->bufsize)
+ if (!*fn->fc->eof && !fn->fc->error && fn->loaded < fn->bufsize)
goto again;
return pod->converted;
}
int *bof = fn->private_data;
if (*bof) {
- make_wav_header(fn->fci->channels, fn->fci->samplerate, fn);
+ make_wav_header(fn->fc->channels, fn->fc->samplerate, fn);
fn->loaded = WAV_HEADER_LEN;
*bof = 0;
// return 0;