Mercurial > audlegacy
annotate src/audacious/flow.c @ 4516:9fbb55542e73
hookified many function calls
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 23 Apr 2008 20:11:10 +0200 |
parents | a41fb6bc632a |
children |
rev | line source |
---|---|
3551 | 1 /* |
2 * Audacious | |
3 * Copyright (c) 2007 William Pitcock | |
4 * | |
5 * flow.c: flow management API. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; under version 3 of the License. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
18 * | |
19 * The Audacious team does not consider modular code linking to | |
20 * Audacious or using our public API to be a derived work. | |
21 */ | |
22 | |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
23 #define AUD_DEBUG |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
24 |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
25 #include "main.h" |
3551 | 26 #include "flow.h" |
27 | |
28 mowgli_object_class_t flow_klass; | |
29 | |
30 static void | |
31 flow_destructor(Flow *flow) | |
32 { | |
33 FlowElement *element, *element2; | |
34 | |
35 g_return_if_fail(flow != NULL); | |
36 | |
37 MOWGLI_ITER_FOREACH_SAFE(element, element2, flow->head) | |
38 g_slice_free(FlowElement, element); | |
39 | |
40 g_slice_free(Flow, flow); | |
41 } | |
42 | |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
43 gsize |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
44 flow_execute(Flow *flow, gint time, gpointer *data, gsize len, AFormat fmt, |
3551 | 45 gint srate, gint channels) |
46 { | |
47 FlowElement *element; | |
48 FlowContext context = {}; | |
49 | |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
50 g_return_val_if_fail(flow != NULL, 0); |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
51 g_return_val_if_fail(data != NULL, 0); |
3551 | 52 |
3558
5aec9950c47a
Add time to flow_execute() and friends.
William Pitcock <nenolod@atheme.org>
parents:
3551
diff
changeset
|
53 context.time = time; |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
54 context.data = *data; |
3551 | 55 context.len = len; |
56 context.fmt = fmt; | |
57 context.srate = srate; | |
58 context.channels = channels; | |
59 context.error = FALSE; | |
60 | |
61 MOWGLI_ITER_FOREACH(element, flow->head) | |
62 { | |
63 element->func(&context); | |
64 | |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
65 if (context.error) { |
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
66 AUDDBG("context.error!\n"); |
3551 | 67 break; |
4267
a41fb6bc632a
- src stuff traveled to src_flow.c
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
3708
diff
changeset
|
68 } |
3551 | 69 } |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
70 |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
71 *data = context.data; |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
72 |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
73 return context.len; |
3551 | 74 } |
75 | |
76 Flow * | |
77 flow_new(void) | |
78 { | |
79 static int init = 0; | |
80 Flow *out; | |
81 | |
82 if (!init) | |
83 { | |
84 mowgli_object_class_init(&flow_klass, "audacious.flow", | |
85 (mowgli_destructor_t) flow_destructor, FALSE); | |
86 ++init; | |
87 } | |
88 | |
89 out = g_slice_new0(Flow); | |
90 mowgli_object_init(mowgli_object(out), NULL, &flow_klass, NULL); | |
91 | |
92 return out; | |
93 } | |
94 | |
95 void | |
96 flow_link_element(Flow *flow, FlowFunction func) | |
97 { | |
98 FlowElement *element; | |
99 | |
100 g_return_if_fail(flow != NULL); | |
101 g_return_if_fail(func != NULL); | |
102 | |
103 element = g_slice_new0(FlowElement); | |
104 element->func = func; | |
105 element->prev = flow->tail; | |
106 | |
107 if (flow->tail) | |
108 flow->tail->next = element; | |
109 | |
110 flow->tail = element; | |
3563 | 111 |
112 if (!flow->head) | |
113 flow->head = element; | |
3551 | 114 } |
115 | |
116 /* TBD: unlink all elements of func, or just the first --nenolod */ | |
117 void | |
118 flow_unlink_element(Flow *flow, FlowFunction func) | |
119 { | |
120 FlowElement *iter, *iter2; | |
121 | |
122 g_return_if_fail(flow != NULL); | |
123 g_return_if_fail(func != NULL); | |
124 | |
125 MOWGLI_ITER_FOREACH_SAFE(iter, iter2, flow->head) | |
126 if (iter->func == func) | |
127 { | |
128 if (iter->next) | |
129 iter->next->prev = iter->prev; | |
130 | |
131 iter->prev->next = iter->next; | |
132 | |
3563 | 133 if (flow->tail == iter) |
134 flow->tail = iter->prev; | |
135 | |
136 if (flow->head == iter) | |
137 flow->head = iter->next; | |
138 | |
3551 | 139 g_slice_free(FlowElement, iter); |
140 } | |
141 } |