source: roaraudio/plugins/universal/filter-slfi-chain.c @ 5984:25da2ce52bdb

Last change on this file since 5984:25da2ce52bdb was 5984:25da2ce52bdb, checked in by phi, 10 years ago

added SLFI filter "chain"

File size: 4.0 KB
Line 
1//filter-slfi-chain.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27#include <libroarlight/libroarlight.h>
28
29#define MAX_FILTER  32
30
31struct slfi_chain {
32 struct roar_slfi_inst * filter[MAX_FILTER];
33 size_t filter_len;
34};
35
36static int __cb_event_add(struct roar_slfi_inst * inst, void * userdata, uint8_t event) {
37 (void)inst;
38 return roar_slfi_event_add(userdata, event);
39}
40
41static int __init(struct roar_slfi_inst * inst, const struct roar_keyval * para, ssize_t paralen) {
42 struct slfi_chain * self = roar_mm_malloc(sizeof(struct slfi_chain));
43
44 (void)para, (void)paralen;
45
46 if ( self == NULL )
47  return -1;
48
49 self->filter_len = 0;
50 inst->userdata = self;
51
52 return 0;
53}
54
55static int __uninit(struct roar_slfi_inst * inst) {
56 struct slfi_chain * self = inst->userdata;
57 size_t i;
58
59 for (i = 0; i < self->filter_len; i++) {
60  roar_slfi_unref(self->filter[i]);
61 }
62
63 return 0;
64}
65
66static int __update(struct roar_slfi_inst * inst, uint8_t * universe, ssize_t size_of_universe, int32_t usecspassed, const uint8_t * event, size_t eventlen) {
67 struct slfi_chain * self = inst->userdata;
68 size_t i;
69 int ret;
70
71 for (i = 0; i < self->filter_len; i++) {
72  ret = roar_slfi_update(self->filter[i], universe, size_of_universe, usecspassed, event, eventlen);
73  if ( ret != 0 )
74   return ret;
75 }
76
77 return 0;
78}
79
80static int __ctl(struct roar_slfi_inst * inst, enum roar_slfi_command command, void * argp) {
81 struct slfi_chain * self = inst->userdata;
82
83 switch (command) {
84  case ROAR_SLFI_CMD_PUSH:
85    if ( self->filter_len == MAX_FILTER ) {
86     roar_err_set(ROAR_ERROR_NOSPC);
87     return -1;
88    }
89    if ( roar_slfi_ref(argp) == -1 )
90     return -1;
91    roar_slfi_cb_set_event_add(argp, __cb_event_add, inst);
92    self->filter[self->filter_len++] = argp;
93    return 0;
94   break;
95#ifndef DEBUG
96  default:
97   break;
98#endif
99 }
100
101 roar_err_set(ROAR_ERROR_BADRQC);
102 return -1;
103}
104
105static const struct roar_slfi_filter filter[1] = {
106 {
107  .name = "chain",
108  .description = "Chain SLFI filter",
109  .flags = ROAR_SLFI_FLAG_NONE,
110  .init = __init,
111  .uninit = __uninit,
112  .update = __update,
113  .ctl = __ctl
114 }
115};
116
117ROAR_DL_PLUGIN_REG_SLFI(filter);
118
119// This is the plugin control block.
120ROAR_DL_PLUGIN_START(filter_slfi_chain) {
121 // Here we set the name and vendor of our plugin.
122 // If you have no Vendor ID you need to use ROAR_DL_PLUGIN_META_PRODUCT_NV().
123 ROAR_DL_PLUGIN_META_PRODUCT_NIV("filter-slfi-chain", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO);
124
125 // This sets the version of your plugin.
126 ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING);
127
128 // This sets the license of your plugin.
129 // If there is no tag for the license you use you can just
130 // use ROAR_DL_PLUGIN_META_LICENSE().
131 ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0);
132
133 // This sets the author and contact infos.
134 // There are several other macros to do this with other parameters.
135 // See ROAR_DL_PLUGIN_META_CONTACT*() in the header or documentation.
136 ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org");
137
138 // This sets the description for your plugin.
139 ROAR_DL_PLUGIN_META_DESC("This is a container plugin for SLFI filter chains.");
140
141 // Load filters.
142 ROAR_DL_PLUGIN_REG_FNFUNC(ROAR_DL_FN_FILTER);
143
144// This is the end of the control block.
145} ROAR_DL_PLUGIN_END
146
147//ll
Note: See TracBrowser for help on using the repository browser.