]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp3dec_filter.c
Introduce filter_node->min_iqs.
[paraslash.git] / mp3dec_filter.c
index 75745044514159adf9918a0757928df91c2249b7..c3f21f126ad7911a67e82903bb0ac12cdb49c13e 100644 (file)
@@ -101,10 +101,9 @@ static void mp3dec_pre_select(struct sched *s, struct task *t)
 {
        struct filter_node *fn = container_of(t, struct filter_node, task);
        size_t iqs = btr_get_input_queue_size(fn->btrn);
-       struct private_mp3dec_data *pmd = fn->private_data;
 
        t->error = 0;
-       if (iqs <= pmd->input_len_barrier)
+       if (iqs <= fn->min_iqs)
                return;
        if (btr_bytes_pending(fn->btrn) > MP3DEC_MAX_PENDING)
                return; /* FIXME, should use reasonable bound on timeout */
@@ -207,23 +206,21 @@ static void mp3dec_post_select(__a_unused struct sched *s, struct task *t)
        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 (pmd->input_len_barrier != 0 && btr_no_parent(btrn)) {
-               ret = -E_MP3DEC_EOF;
+       ret = prepare_filter_node(btrn, fn->min_iqs);
+       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);
@@ -231,16 +228,18 @@ next_frame:
                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;
+                       }
+                       fn->min_iqs += 100;
+                       goto next_buffer;
                } else if (pmd->stream.error != MAD_ERROR_LOSTSYNC)
                        PARA_DEBUG_LOG("header decode: %s\n",
                                mad_stream_errorstr(&pmd->stream));
                goto next_buffer;
        }
-       pmd->input_len_barrier = 0;
+       fn->min_iqs = 0;
        pmd->samplerate = pmd->frame.header.samplerate;
        pmd->channels = MAD_NCHANNELS(&pmd->frame.header);
        ret = mad_frame_decode(&pmd->frame, &pmd->stream);
@@ -316,6 +315,25 @@ err:
        return ret;
 }
 
+static int mp3dec_execute(struct btr_node *btrn, const char *cmd, char **result)
+{
+       struct filter_node *fn = btr_context(btrn);
+       struct private_mp3dec_data *pmd = fn->private_data;
+
+       if (!strcmp(cmd, "samplerate")) {
+               if (pmd->samplerate == 0)
+                       return -ERRNO_TO_PARA_ERROR(ENAVAIL);
+               *result = make_message("%u", pmd->samplerate);
+               return 1;
+       }
+       if (!strcmp(cmd, "channels")) {
+               if (pmd->channels == 0)
+                       return -ERRNO_TO_PARA_ERROR(ENAVAIL);
+               *result = make_message("%u", pmd->channels);
+               return 1;
+       }
+       return -ERRNO_TO_PARA_ERROR(ENOTSUP);
+}
 /**
  * The init function of the mp3dec filter.
  *
@@ -334,6 +352,7 @@ void mp3dec_filter_init(struct filter *f)
        f->parse_config = mp3dec_parse_config;
        f->pre_select = mp3dec_pre_select;
        f->post_select = mp3dec_post_select;
+       f->execute = mp3dec_execute;
        f->help = (struct ggo_help) {
                .short_help = mp3dec_filter_args_info_help,
                .detailed_help = mp3dec_filter_args_info_detailed_help