X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=prebuffer_filter.c;h=ad2373767a8b8df5793472b795ac3d5b85327b55;hp=6fac4cb31d944db1aa603fbfdd71819a946a359c;hb=9d232e636d79a2321e280fe3eee6839c8f45c36f;hpb=f76ab46a9216133332cb7e17d38d392caeca22cb diff --git a/prebuffer_filter.c b/prebuffer_filter.c index 6fac4cb3..ad237376 100644 --- a/prebuffer_filter.c +++ b/prebuffer_filter.c @@ -1,18 +1,14 @@ -/* - * Copyright (C) 2009-2014 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2009 Andre Noll , see file COPYING. */ /** \file prebuffer_filter.c Paraslash's prebuffering filter. */ #include +#include #include "para.h" -#include "prebuffer_filter.cmdline.h" +#include "filter_cmd.lsg.h" #include "list.h" #include "sched.h" -#include "ggo.h" #include "buffer_tree.h" #include "filter.h" #include "string.h" @@ -20,30 +16,28 @@ /** Data specific to the prebuffer filter. */ struct private_prebuffer_data { - /** The configuration data for this instance of the filter. */ - struct prebuffer_filter_args_info *conf; /** Number of bytes prebuffered or -1 if no longer prebuffering. */ int prebuffered; /** End of prebuffering period. */ struct timeval barrier; }; -static void prebuffer_pre_select(struct sched *s, struct task *t) +static void prebuffer_pre_select(struct sched *s, void *context) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = context; struct btr_node *btrn = fn->btrn; size_t iqs = btr_get_input_queue_size(btrn); struct private_prebuffer_data *ppd = fn->private_data; - struct prebuffer_filter_args_info *conf = ppd->conf; struct timeval diff; if (iqs == 0) return; if (ppd->barrier.tv_sec == 0) { + uint32_t duration = FILTER_CMD_OPT_UINT32_VAL(PREBUFFER, + DURATION, fn->lpr); struct timeval tv; - PARA_INFO_LOG("prebuffer period %dms\n", - conf->duration_arg); - ms2tv(conf->duration_arg, &tv); + PARA_INFO_LOG("prebuffer period %" PRIu32 "ms\n", duration); + ms2tv(duration, &tv); tv_add(&tv, now, &ppd->barrier); } if (tv_diff(&ppd->barrier, now, &diff) < 0) @@ -56,72 +50,33 @@ static void prebuffer_close(struct filter_node *fn) free(fn->private_data); } -static int prebuffer_post_select(__a_unused struct sched *s, struct task *t) +static int prebuffer_post_select(__a_unused struct sched *s, void *context) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = context; struct btr_node *btrn = fn->btrn; size_t iqs = btr_get_input_queue_size(btrn); struct private_prebuffer_data *ppd = fn->private_data; - struct prebuffer_filter_args_info *conf = ppd->conf; + uint32_t size = FILTER_CMD_OPT_UINT32_VAL(PREBUFFER, SIZE, fn->lpr); if (ppd->barrier.tv_sec == 0) return 0; if (tv_diff(now, &ppd->barrier, NULL) < 0) return 0; - if (iqs < conf->size_arg) + if (iqs < size) 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 *conf = para_calloc(sizeof(*conf)); - int ret = -E_PREBUFFER_SYNTAX; - - prebuffer_filter_cmdline_parser(argc, argv, conf); - ret = -ERRNO_TO_PARA_ERROR(EINVAL); - if (conf->duration_arg < 0) - goto err; - if (conf->size_arg < 0) - goto err; - PARA_NOTICE_LOG("prebuffering %ims, %i bytes\n", conf->duration_arg, - conf->size_arg); - *config = conf; - return 1; -err: - free(conf); - return ret; -} - static void prebuffer_open(struct filter_node *fn) { struct private_prebuffer_data *ppd = para_calloc(sizeof(*ppd)); - - ppd->conf = fn->conf; fn->private_data = ppd; } -static void prebuffer_free_config(void *conf) -{ - prebuffer_filter_cmdline_parser_free(conf); -} - -/** - * The init function of the prebuffer filter. - * - * \param f Pointer to the struct to initialize. - */ -void prebuffer_filter_init(struct filter *f) -{ - struct prebuffer_filter_args_info dummy; - - prebuffer_filter_cmdline_parser_init(&dummy); - f->open = prebuffer_open; - f->close = prebuffer_close; - 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)DEFINE_GGO_HELP(prebuffer_filter); -} +const struct filter lsg_filter_cmd_com_prebuffer_user_data = { + .open = prebuffer_open, + .close = prebuffer_close, + .pre_select = prebuffer_pre_select, + .post_select = prebuffer_post_select, +};