X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=oggdec_filter.c;h=511e6405e533c1028a511b0828ea479b31b67b77;hp=274d0c2a141222dbb2022d97c9d9fbb047173528;hb=c282c836791cedf57c128555af90af37c7c01c05;hpb=4bd379f56960bddd9623f78b80f40b1dc9337a99 diff --git a/oggdec_filter.c b/oggdec_filter.c index 274d0c2a..511e6405 100644 --- a/oggdec_filter.c +++ b/oggdec_filter.c @@ -159,10 +159,8 @@ static void ogg_close(struct filter_node *fn) fn->private_data = NULL; } -#define OGGDEC_MAX_PENDING (640 * 1024) #define OGGDEC_OUTPUT_CHUNK_SIZE (64 * 1024) - static int oggdec_execute(struct btr_node *btrn, const char *cmd, char **result) { struct filter_node *fn = btr_context(btrn); @@ -183,18 +181,59 @@ static int oggdec_execute(struct btr_node *btrn, const char *cmd, char **result) return -ERRNO_TO_PARA_ERROR(ENOTSUP); } -static void ogg_pre_select(struct sched *s, struct task *t) +static int ogg_init(struct filter_node *fn) { - struct filter_node *fn = container_of(t, struct filter_node, task); - size_t iqs = btr_get_input_queue_size(fn->btrn); - - t->error = 0; - if (iqs == 0) - return; - if (btr_bytes_pending(fn->btrn) > OGGDEC_MAX_PENDING) - return; /* FIXME, should use reasonable bound on timeout */ - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; + struct private_oggdec_data *pod = fn->private_data; + struct btr_node *btrn = fn->btrn; + int ret, oret; + size_t iqs; + struct timeval delay = {0, 500 * 1000}; + + pod->vf = para_malloc(sizeof(struct OggVorbis_File)); + PARA_NOTICE_LOG("min_iqs: %zu, opening ov callbacks\n", fn->min_iqs); +open: + oret = ov_open_callbacks(fn, pod->vf, + NULL, /* no initial buffer */ + 0, /* no initial bytes */ + ovc); /* the ov_open_callbacks */ + if (oret == OV_ENOTVORBIS || oret == OV_EBADHEADER) { + /* this might be due to the input buffer being too small */ + if (!btr_no_parent(btrn)) { + fn->min_iqs += 1000; + iqs = btr_get_input_queue_size(btrn); + ret = 0; + if (iqs <= fn->min_iqs) + goto out; + btr_merge(btrn, fn->min_iqs); + goto open; + } + ret = (oret == OV_ENOTVORBIS)? + -E_OGGDEC_NOTVORBIS : -E_OGGDEC_BADHEADER; + goto out; + } + ret = -E_OGGDEC_READ; + if (oret == OV_EREAD) + goto out; + ret = -E_OGGDEC_VERSION; + if (oret == OV_EVERSION) + goto out; + ret = -E_OGGDEC_FAULT; + if (oret < 0) + goto out; + pod->channels = ov_info(pod->vf, 0)->channels; + pod->samplerate = ov_info(pod->vf, 0)->rate; + PARA_NOTICE_LOG("%d channels, %d Hz\n", pod->channels, + pod->samplerate); + /* wait a bit to avoid buffer underruns */ + tv_add(now, &delay, &pod->stream_start); + ret = 1; +out: + if (ret <= 0) { + free(pod->vf); + pod->vf = NULL; + } else + fn->min_iqs = 0; + return ret; } static void ogg_post_select(__a_unused struct sched *s, struct task *t) @@ -207,50 +246,16 @@ static void ogg_post_select(__a_unused struct sched *s, struct task *t) char *in; t->error = 0; - ret = prepare_filter_node(btrn, fn->min_iqs); - if (ret < 0) - goto err; - if (ret == 0) - return; + ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL); + if (ret <= 0) + goto out; + btr_merge(btrn, fn->min_iqs); len = btr_next_buffer(btrn, &in); iqs = btr_get_input_queue_size(btrn); if (!pod->vf) { - int oret; - - pod->vf = para_malloc(sizeof(struct OggVorbis_File)); - PARA_NOTICE_LOG("input queue: %zu, opening ov callbacks\n", iqs); - oret = ov_open_callbacks(fn, pod->vf, - NULL, /* no initial buffer */ - 0, /* no initial bytes */ - ovc); /* the ov_open_callbacks */ - if (oret == OV_ENOTVORBIS || oret == OV_EBADHEADER) { - /* this might be due to the input buffer being too small */ - if (!btr_no_parent(btrn)) { - free(pod->vf); - pod->vf = NULL; - fn->min_iqs = iqs + 1; - return; - } - ret = (oret == OV_ENOTVORBIS)? - -E_OGGDEC_NOTVORBIS : -E_OGGDEC_BADHEADER; - goto err; - } - ret = -E_OGGDEC_READ; - if (oret == OV_EREAD) - goto err; - ret = -E_OGGDEC_VERSION; - if (oret == OV_EVERSION) - goto err; - ret = -E_OGGDEC_FAULT; - if (oret < 0) - goto err; - pod->channels = ov_info(pod->vf, 0)->channels; - pod->samplerate = ov_info(pod->vf, 0)->rate; - PARA_NOTICE_LOG("%d channels, %d Hz\n", pod->channels, - pod->samplerate); - ///* wait a bit to avoid buffer underruns */ - //tv_add(now, &(struct timeval){0, 500 * 1000}, &pod->stream_start); - return; + ret = ogg_init(fn); + if (ret <= 0) + goto out; } for (;;) { char *out = para_malloc(OGGDEC_OUTPUT_CHUNK_SIZE); @@ -259,25 +264,27 @@ static void ogg_post_select(__a_unused struct sched *s, struct task *t) if (read_ret <= 0) free(out); if (read_ret == 0) { - ret = -E_OGGDEC_EOF; if (btr_no_parent(btrn)) - goto err; - return; + ret = -E_OGGDEC_EOF; + else + ret = 0; + goto out; } + ret = 0; if (read_ret == OV_HOLE) - return; - if (read_ret < 0) { - ret = -E_OGGDEC_BADLINK; - goto err; - } + goto out; + ret = -E_OGGDEC_BADLINK; + if (read_ret < 0) + goto out; btr_add_output(out, read_ret, btrn); + if (btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL) == 0) + return; /* enough data for the moment */ + } +out: + if (ret < 0) { + t->error = ret; + btr_remove_node(btrn); } - -err: - assert(ret < 0); - ogg_close(fn); - t->error = ret; - btr_del_node(btrn); } static ssize_t ogg_convert(char *inbuffer, size_t len, struct filter_node *fn) @@ -377,6 +384,11 @@ err: return ret; } +static void oggdec_free_config(void *conf) +{ + oggdec_cmdline_parser_free(conf); +} + /** * The init function of the ogg vorbis decoder. * @@ -390,9 +402,10 @@ void oggdec_filter_init(struct filter *f) f->open = ogg_open; f->close = ogg_close; f->convert = ogg_convert; - f->pre_select = ogg_pre_select; + f->pre_select = generic_filter_pre_select; f->post_select = ogg_post_select; f->parse_config = oggdec_parse_config; + f->free_config = oggdec_free_config; f->execute = oggdec_execute; f->help = (struct ggo_help) { .short_help = oggdec_filter_args_info_help,