Mercurial > audlegacy
annotate src/audacious/flow.c @ 3716:9489aae0d872
introduce playback_get_length()
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Thu, 11 Oct 2007 19:25:08 +0200 |
parents | 6f4068a0f291 |
children | a41fb6bc632a |
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 | |
23 #include "flow.h" | |
24 | |
25 mowgli_object_class_t flow_klass; | |
26 | |
27 static void | |
28 flow_destructor(Flow *flow) | |
29 { | |
30 FlowElement *element, *element2; | |
31 | |
32 g_return_if_fail(flow != NULL); | |
33 | |
34 MOWGLI_ITER_FOREACH_SAFE(element, element2, flow->head) | |
35 g_slice_free(FlowElement, element); | |
36 | |
37 g_slice_free(Flow, flow); | |
38 } | |
39 | |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
40 gsize |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
41 flow_execute(Flow *flow, gint time, gpointer *data, gsize len, AFormat fmt, |
3551 | 42 gint srate, gint channels) |
43 { | |
44 FlowElement *element; | |
45 FlowContext context = {}; | |
46 | |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
47 g_return_val_if_fail(flow != NULL, 0); |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
48 g_return_val_if_fail(data != NULL, 0); |
3551 | 49 |
3558
5aec9950c47a
Add time to flow_execute() and friends.
William Pitcock <nenolod@atheme.org>
parents:
3551
diff
changeset
|
50 context.time = time; |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
51 context.data = *data; |
3551 | 52 context.len = len; |
53 context.fmt = fmt; | |
54 context.srate = srate; | |
55 context.channels = channels; | |
56 context.error = FALSE; | |
57 | |
58 MOWGLI_ITER_FOREACH(element, flow->head) | |
59 { | |
60 element->func(&context); | |
61 | |
62 if (context.error) | |
63 break; | |
64 } | |
3708
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
65 |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
66 *data = context.data; |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
67 |
6f4068a0f291
make sndstretch work properly
William Pitcock <nenolod@atheme.org>
parents:
3563
diff
changeset
|
68 return context.len; |
3551 | 69 } |
70 | |
71 Flow * | |
72 flow_new(void) | |
73 { | |
74 static int init = 0; | |
75 Flow *out; | |
76 | |
77 if (!init) | |
78 { | |
79 mowgli_object_class_init(&flow_klass, "audacious.flow", | |
80 (mowgli_destructor_t) flow_destructor, FALSE); | |
81 ++init; | |
82 } | |
83 | |
84 out = g_slice_new0(Flow); | |
85 mowgli_object_init(mowgli_object(out), NULL, &flow_klass, NULL); | |
86 | |
87 return out; | |
88 } | |
89 | |
90 void | |
91 flow_link_element(Flow *flow, FlowFunction func) | |
92 { | |
93 FlowElement *element; | |
94 | |
95 g_return_if_fail(flow != NULL); | |
96 g_return_if_fail(func != NULL); | |
97 | |
98 element = g_slice_new0(FlowElement); | |
99 element->func = func; | |
100 element->prev = flow->tail; | |
101 | |
102 if (flow->tail) | |
103 flow->tail->next = element; | |
104 | |
105 flow->tail = element; | |
3563 | 106 |
107 if (!flow->head) | |
108 flow->head = element; | |
3551 | 109 } |
110 | |
111 /* TBD: unlink all elements of func, or just the first --nenolod */ | |
112 void | |
113 flow_unlink_element(Flow *flow, FlowFunction func) | |
114 { | |
115 FlowElement *iter, *iter2; | |
116 | |
117 g_return_if_fail(flow != NULL); | |
118 g_return_if_fail(func != NULL); | |
119 | |
120 MOWGLI_ITER_FOREACH_SAFE(iter, iter2, flow->head) | |
121 if (iter->func == func) | |
122 { | |
123 if (iter->next) | |
124 iter->next->prev = iter->prev; | |
125 | |
126 iter->prev->next = iter->next; | |
127 | |
3563 | 128 if (flow->tail == iter) |
129 flow->tail = iter->prev; | |
130 | |
131 if (flow->head == iter) | |
132 flow->head = iter->next; | |
133 | |
3551 | 134 g_slice_free(FlowElement, iter); |
135 } | |
136 } |