X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=prebuffer_filter.c;h=f4ef76e245c98ca141caf4bd04e8594087ac6da6;hp=207d33245947e1b4ef898d3906c8045d76081a9e;hb=d87806284b9f6be9aab71ccbf0280d273b57eeb3;hpb=c282c836791cedf57c128555af90af37c7c01c05 diff --git a/prebuffer_filter.c b/prebuffer_filter.c index 207d3324..f4ef76e2 100644 --- a/prebuffer_filter.c +++ b/prebuffer_filter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Andre Noll + * Copyright (C) 2009-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,7 +7,6 @@ /** \file prebuffer_filter.c Paraslash's prebuffering filter. */ #include -#include #include "para.h" #include "prebuffer_filter.cmdline.h" @@ -29,52 +28,6 @@ struct private_prebuffer_data { struct timeval barrier; }; -static ssize_t prebuffer_convert(char *inbuf, size_t inbuf_len, - struct filter_node *fn) -{ - struct private_prebuffer_data *ppd = fn->private_data; - struct prebuffer_filter_args_info *conf = ppd->conf; - - if (inbuf_len == 0) { - if (*fn->fc->input_error < 0 && ppd->prebuffered >= 0) - goto prebuffer_end; - return 0; - } - if (ppd->prebuffered < 0) { - size_t copy = PARA_MIN(inbuf_len, fn->bufsize - fn->loaded); - memcpy(fn->buf + fn->loaded, inbuf, copy); - fn->loaded += copy; - return copy; - } - if (ppd->prebuffered + inbuf_len > fn->bufsize) { - fn->bufsize = PARA_MAX(2 * fn->bufsize, - ppd->prebuffered + inbuf_len); - fn->buf = para_realloc(fn->buf, fn->bufsize); - } - memcpy(fn->buf + ppd->prebuffered, inbuf, inbuf_len); - if (ppd->prebuffered == 0) { - struct timeval tv; - PARA_INFO_LOG("prebuffer period %dms\n", - conf->duration_arg); - ms2tv(conf->duration_arg, &tv); - tv_add(&tv, now, &ppd->barrier); - } - ppd->prebuffered += inbuf_len; - PARA_DEBUG_LOG("%d bytes prebuffered\n", ppd->prebuffered); - if (*fn->fc->input_error >= 0) { - struct timeval diff; - if (tv_diff(now, &ppd->barrier, &diff) < 0) - goto out; - if (ppd->prebuffered < conf->size_arg) - goto out; - } -prebuffer_end: - fn->loaded = ppd->prebuffered; - ppd->prebuffered = -1; -out: - return inbuf_len; -} - static void prebuffer_pre_select(struct sched *s, struct task *t) { struct filter_node *fn = container_of(t, struct filter_node, task); @@ -84,7 +37,6 @@ static void prebuffer_pre_select(struct sched *s, struct task *t) struct prebuffer_filter_args_info *conf = ppd->conf; struct timeval diff; - t->error = 0; if (iqs == 0) return; if (ppd->barrier.tv_sec == 0) { @@ -95,22 +47,16 @@ static void prebuffer_pre_select(struct sched *s, struct task *t) tv_add(&tv, now, &ppd->barrier); } if (tv_diff(&ppd->barrier, now, &diff) < 0) - goto min_delay; - if (tv_diff(&diff, &s->timeout, NULL) < 0) - s->timeout = diff; - return; -min_delay: - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; + return sched_min_delay(s); + sched_request_timeout(&diff, s); } static void prebuffer_close(struct filter_node *fn) { free(fn->private_data); - free(fn->buf); } -static void prebuffer_post_select(__a_unused struct sched *s, struct task *t) +static int prebuffer_post_select(__a_unused struct sched *s, struct task *t) { struct filter_node *fn = container_of(t, struct filter_node, task); struct btr_node *btrn = fn->btrn; @@ -118,37 +64,33 @@ static void prebuffer_post_select(__a_unused struct sched *s, struct task *t) struct private_prebuffer_data *ppd = fn->private_data; struct prebuffer_filter_args_info *conf = ppd->conf; - t->error = 0; if (ppd->barrier.tv_sec == 0) - return; + return 0; if (tv_diff(now, &ppd->barrier, NULL) < 0) - return; + return 0; if (iqs < conf->size_arg) - return; - btr_splice_out_node(btrn); - prebuffer_close(fn); - t->error = -E_PREBUFFER_SUCCESS; + return 0; + btr_splice_out_node(&fn->btrn); + return -E_PREBUFFER_SUCCESS; } static int prebuffer_parse_config(int argc, char **argv, void **config) { - struct prebuffer_filter_args_info *prebuffer_conf - = para_calloc(sizeof(*prebuffer_conf)); + struct prebuffer_filter_args_info *conf = para_calloc(sizeof(*conf)); int ret = -E_PREBUFFER_SYNTAX; - if (prebuffer_cmdline_parser(argc, argv, prebuffer_conf)) - goto err; + prebuffer_filter_cmdline_parser(argc, argv, conf); ret = -ERRNO_TO_PARA_ERROR(EINVAL); - if (prebuffer_conf->duration_arg < 0) + if (conf->duration_arg < 0) goto err; - if (prebuffer_conf->size_arg < 0) + if (conf->size_arg < 0) goto err; - PARA_NOTICE_LOG("prebuffering %ims, %i bytes\n", - prebuffer_conf->duration_arg, prebuffer_conf->size_arg); - *config = prebuffer_conf; + PARA_NOTICE_LOG("prebuffering %ims, %i bytes\n", conf->duration_arg, + conf->size_arg); + *config = conf; return 1; err: - free(prebuffer_conf); + free(conf); return ret; } @@ -158,13 +100,11 @@ static void prebuffer_open(struct filter_node *fn) ppd->conf = fn->conf; fn->private_data = ppd; - fn->bufsize = 8192; /* gets increased on demand */ - fn->buf = para_malloc(fn->bufsize); } static void prebuffer_free_config(void *conf) { - prebuffer_cmdline_parser_free(conf); + prebuffer_filter_cmdline_parser_free(conf); } /** @@ -176,16 +116,12 @@ void prebuffer_filter_init(struct filter *f) { struct prebuffer_filter_args_info dummy; - prebuffer_cmdline_parser_init(&dummy); + prebuffer_filter_cmdline_parser_init(&dummy); f->open = prebuffer_open; f->close = prebuffer_close; - f->convert = prebuffer_convert; f->parse_config = prebuffer_parse_config; f->free_config = prebuffer_free_config; f->pre_select = prebuffer_pre_select; f->post_select = prebuffer_post_select; - f->help = (struct ggo_help) { - .short_help = prebuffer_filter_args_info_help, - .detailed_help = prebuffer_filter_args_info_detailed_help - }; + f->help = (struct ggo_help)DEFINE_GGO_HELP(prebuffer_filter); }