next_buffer:
t->error = 0;
- iqs = btr_get_input_queue_size(btrn);
- if (iqs < 2048) {
- if (!btr_no_parent(btrn)) /* wait for more data */
- return;
- }
- if (btr_bytes_pending(btrn) > AACDEC_MAX_PENDING)
- return;
- /* avoid "buffer too small" errors from the decoder */
- for (;;) {
- len = btr_next_buffer(btrn, (char **)&inbuf);
- if (len >= 2048)
- break;
- if (btr_merge(btrn) < 2) /* only one buffer left */
- break;
- }
- //PARA_CRIT_LOG("next buffer: %zu\n", len);
- if (len == 0) {
- if (btr_no_parent(btrn)) {
- ret = -E_AACDEC_EOF;
- goto err;
- }
+ ret = prepare_filter_node(btrn, 2048);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
return;
- }
+ len = btr_next_buffer(btrn, (char **)&inbuf);
+ iqs = btr_get_input_queue_size(btrn);
if (!padd->initialized) {
unsigned long rate = 0;
unsigned char channels = 0;
return;
}
}
+
+bool btr_eof(struct btr_node *btrn)
+{
+ char *buf;
+ size_t len = btr_next_buffer(btrn, &buf);
+
+ return (len == 0 && btr_no_parent(btrn));
+}
void *btr_context(struct btr_node *btrn);
int btr_merge(struct btr_node *btrn);
void btr_merge_to(struct btr_node *btrn, size_t dest_size);
+bool btr_eof(struct btr_node *btrn);
int check_filter_arg(char *filter_arg, void **conf);
void filter_post_select(__a_unused struct sched *s, struct task *t);
void print_filter_helps(int detailed);
+int prepare_filter_node(struct btr_node *btrn, size_t min_len);
static inline void write_int16_host_endian(char *buf, int val)
{
}
}
+
+/** 640K ought to be enough for everybody ;) */
+#define FILTER_MAX_PENDING (640 * 1024)
+
+int prepare_filter_node(struct btr_node *btrn, size_t min_len)
+{
+ size_t iqs;
+
+ if (btr_eof(btrn))
+ return -E_FC_EOF;
+ if (btr_bytes_pending(btrn) > FILTER_MAX_PENDING)
+ return 0;
+ iqs = btr_get_input_queue_size(btrn);
+ if (iqs < min_len && !btr_no_parent(btrn))
+ return 0;
+ assert(iqs != 0);
+ /* avoid "buffer too small" errors from the decoder */
+ btr_merge_to(btrn, min_len);
+ return 1;
+}
int i, ret;
struct private_mp3dec_data *pmd = fn->private_data;
struct btr_node *btrn = fn->btrn;
- size_t loaded, used, len = btr_get_input_queue_size(btrn);
+ size_t loaded, used, len, iqs;
char *inbuffer, *outbuffer;
+next_buffer:
pmd->stream.error = 0;
t->error = 0;
- if (btr_bytes_pending(btrn) > MP3DEC_MAX_PENDING)
- return;
- if (need_bad_data_delay(pmd, len))
+ iqs = btr_get_input_queue_size(btrn);
+ if (need_bad_data_delay(pmd, iqs))
return;
- if (len <= pmd->input_len_barrier && btr_no_parent(btrn)) {
- ret = -E_MP3DEC_EOF;
+ ret = prepare_filter_node(btrn, pmd->input_len_barrier);
+ if (ret < 0)
goto err;
- }
-next_buffer:
- len = btr_next_buffer(btrn, &inbuffer);
- if (len == 0)
+ if (ret == 0)
return;
+ len = btr_next_buffer(btrn, &inbuffer);
mad_stream_buffer(&pmd->stream, (unsigned char *)inbuffer, len);
next_frame:
ret = mad_header_decode(&pmd->frame.header, &pmd->stream);
used = used_mad_buffer_bytes(&pmd->stream, len);
btr_consume(btrn, used);
if (pmd->stream.error == MAD_ERROR_BUFLEN) {
- pmd->input_len_barrier = len - used;
- ret = btr_merge(btrn);
- if (ret != 2)
- return;
+ if (len == iqs && btr_no_parent(btrn)) {
+ ret = -E_MP3DEC_EOF;
+ goto err;
+ }
+ pmd->input_len_barrier += 100;
+ goto next_buffer;
} else if (pmd->stream.error != MAD_ERROR_LOSTSYNC)
PARA_DEBUG_LOG("header decode: %s\n",
mad_stream_errorstr(&pmd->stream));
unsigned int channels;
/** Current sample rate in Hz. */
unsigned int samplerate;
+ size_t min_iqs;
};
static size_t cb_read_nobtr(void *buf, size_t size, size_t nmemb, void *datasource)
struct filter_node *fn = container_of(t, struct filter_node, task);
struct private_oggdec_data *pod = fn->private_data;
struct btr_node *btrn = fn->btrn;
- size_t iqs = btr_get_input_queue_size(btrn);
+ size_t iqs, len;
int ret;
+ char *in;
t->error = 0;
- if (!pod->vf && iqs) {
- struct oggdec_filter_args_info *conf = fn->conf;
+ ret = prepare_filter_node(btrn, pod->min_iqs);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
+ return;
+ 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));
ovc); /* the ov_open_callbacks */
if (oret == OV_ENOTVORBIS || oret == OV_EBADHEADER) {
/* this might be due to the input buffer being too small */
- int ib = 1024 * conf->initial_buffer_arg; /* initial buffer */
- if (iqs < ib) {
+ if (!btr_no_parent(btrn)) {
free(pod->vf);
pod->vf = NULL;
+ pod->min_iqs = iqs + 1;
return;
}
ret = (oret == OV_ENOTVORBIS)?
int ret, converted = 0;
struct private_wmadec_data *pwd = fn->private_data;
struct btr_node *btrn = fn->btrn;
- size_t iqs, len, min_len;
+ size_t len, min_len;
char *in;
min_len = pwd? WMA_FRAME_SKIP + pwd->ahi.block_align : 8192;
next_buffer:
t->error = 0;
- if (btr_bytes_pending(btrn) > WMADEC_MAX_PENDING)
+ ret = prepare_filter_node(btrn, min_len);
+ if (ret < 0)
+ goto err;
+ if (ret == 0)
return;
- iqs = btr_get_input_queue_size(btrn);
- if (iqs < min_len) {
- if (!btr_no_parent(btrn)) /* wait for more data */
- return;
- ret = -E_WMADEC_EOF;
+ len = btr_next_buffer(btrn, (char **)&in);
+ ret = -E_WMADEC_EOF;
+ if (len < min_len)
goto err;
- }
- /* avoid "buffer too small" errors from the decoder */
- btr_merge_to(btrn, min_len);
- len = btr_next_buffer(btrn, &in);
- assert(len >= min_len);
if (!pwd) {
ret = wma_decode_init(in, len, &pwd);
if (ret < 0)