- 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;