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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3551
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
1 /*
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
2 * Audacious
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
3 * Copyright (c) 2007 William Pitcock
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
4 *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
5 * flow.c: flow management API.
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
6 *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
9 * the Free Software Foundation; under version 3 of the License.
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
10 *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
14 * GNU General Public License for more details.
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
15 *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
17 * along with this program. If not, see <http://www.gnu.org/licenses>.
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
18 *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
19 * The Audacious team does not consider modular code linking to
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
20 * Audacious or using our public API to be a derived work.
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
21 */
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
22
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
23 #include "flow.h"
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
24
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
25 mowgli_object_class_t flow_klass;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
26
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
27 static void
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
28 flow_destructor(Flow *flow)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
29 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
30 FlowElement *element, *element2;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
31
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
32 g_return_if_fail(flow != NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
33
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
34 MOWGLI_ITER_FOREACH_SAFE(element, element2, flow->head)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
35 g_slice_free(FlowElement, element);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
36
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
37 g_slice_free(Flow, flow);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
38 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
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
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
42 gint srate, gint channels)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
43 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
44 FlowElement *element;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
45 FlowContext context = {};
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
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
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
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
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
52 context.len = len;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
53 context.fmt = fmt;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
54 context.srate = srate;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
55 context.channels = channels;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
56 context.error = FALSE;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
57
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
58 MOWGLI_ITER_FOREACH(element, flow->head)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
59 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
60 element->func(&context);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
61
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
62 if (context.error)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
63 break;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
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
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
69 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
70
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
71 Flow *
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
72 flow_new(void)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
73 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
74 static int init = 0;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
75 Flow *out;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
76
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
77 if (!init)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
78 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
79 mowgli_object_class_init(&flow_klass, "audacious.flow",
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
80 (mowgli_destructor_t) flow_destructor, FALSE);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
81 ++init;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
82 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
83
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
84 out = g_slice_new0(Flow);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
85 mowgli_object_init(mowgli_object(out), NULL, &flow_klass, NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
86
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
87 return out;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
88 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
89
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
90 void
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
91 flow_link_element(Flow *flow, FlowFunction func)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
92 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
93 FlowElement *element;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
94
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
95 g_return_if_fail(flow != NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
96 g_return_if_fail(func != NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
97
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
98 element = g_slice_new0(FlowElement);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
99 element->func = func;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
100 element->prev = flow->tail;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
101
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
102 if (flow->tail)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
103 flow->tail->next = element;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
104
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
105 flow->tail = element;
3563
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
106
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
107 if (!flow->head)
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
108 flow->head = element;
3551
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
109 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
110
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
111 /* TBD: unlink all elements of func, or just the first --nenolod */
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
112 void
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
113 flow_unlink_element(Flow *flow, FlowFunction func)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
114 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
115 FlowElement *iter, *iter2;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
116
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
117 g_return_if_fail(flow != NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
118 g_return_if_fail(func != NULL);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
119
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
120 MOWGLI_ITER_FOREACH_SAFE(iter, iter2, flow->head)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
121 if (iter->func == func)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
122 {
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
123 if (iter->next)
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
124 iter->next->prev = iter->prev;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
125
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
126 iter->prev->next = iter->next;
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
127
3563
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
128 if (flow->tail == iter)
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
129 flow->tail = iter->prev;
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
130
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
131 if (flow->head == iter)
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
132 flow->head = iter->next;
cc888ce7b6fb link/unlink fixes
William Pitcock <nenolod@atheme.org>
parents: 3558
diff changeset
133
3551
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
134 g_slice_free(FlowElement, iter);
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
135 }
d4f9e45c1e27 Flow manager.
William Pitcock <nenolod@atheme.org>
parents:
diff changeset
136 }