summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/stream_mgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpegplayer/stream_mgr.c')
-rw-r--r--apps/plugins/mpegplayer/stream_mgr.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/apps/plugins/mpegplayer/stream_mgr.c b/apps/plugins/mpegplayer/stream_mgr.c
index 065843a344..2eed3d355d 100644
--- a/apps/plugins/mpegplayer/stream_mgr.c
+++ b/apps/plugins/mpegplayer/stream_mgr.c
@@ -148,21 +148,21 @@ void stream_add_stream(struct stream *str)
148{ 148{
149 actl_lock(); 149 actl_lock();
150 150
151 list_remove_item(&str->l); 151 list_remove_item(stream_mgr.strl, str);
152 list_add_item(&stream_mgr.strl, &str->l); 152 list_add_item(stream_mgr.strl, str);
153 153
154 actl_unlock(); 154 actl_unlock();
155} 155}
156 156
157/* Callback for various list-moving operations */ 157/* Callback for various list-moving operations */
158static bool strl_enum_callback(struct list_item *item, intptr_t data) 158static bool strl_enum_callback(struct stream *str, intptr_t data)
159{ 159{
160 actl_lock(); 160 actl_lock();
161 161
162 list_remove_item(item); 162 list_remove_item(stream_mgr.strl, str);
163 163
164 if (data == 1) 164 if (data == 1)
165 list_add_item(&stream_mgr.actl, item); 165 list_add_item(stream_mgr.actl, str);
166 166
167 actl_unlock(); 167 actl_unlock();
168 168
@@ -172,38 +172,38 @@ static bool strl_enum_callback(struct list_item *item, intptr_t data)
172/* Clear all streams from active and playback pools */ 172/* Clear all streams from active and playback pools */
173void stream_remove_streams(void) 173void stream_remove_streams(void)
174{ 174{
175 list_enum_items(&stream_mgr.strl, strl_enum_callback, 0); 175 list_enum_items(stream_mgr.strl,
176 (list_enum_callback_t)strl_enum_callback, 0);
176} 177}
177 178
178/* Move the playback pool to the active list */ 179/* Move the playback pool to the active list */
179void move_strl_to_actl(void) 180void move_strl_to_actl(void)
180{ 181{
181 list_enum_items(&stream_mgr.strl, strl_enum_callback, 1); 182 list_enum_items(stream_mgr.strl,
183 (list_enum_callback_t)strl_enum_callback, 1);
182} 184}
183 185
184/* Remove a stream from the active list and return it to the pool */ 186/* Remove a stream from the active list and return it to the pool */
185static bool actl_stream_remove(struct stream *str) 187static bool actl_stream_remove(struct stream *str)
186{ 188{
187 if (list_is_member(&stream_mgr.actl, &str->l)) 189 bool retval;
188 {
189 actl_lock();
190 190
191 list_remove_item(&str->l); 191 actl_lock();
192 list_add_item(&stream_mgr.strl, &str->l);
193 192
194 actl_unlock(); 193 retval = list_remove_item(stream_mgr.actl, str);
195 return true; 194
196 } 195 if (retval)
196 list_add_item(stream_mgr.strl, str);
197 197
198 return false; 198 actl_unlock();
199
200 return retval;
199} 201}
200 202
201/* Broadcast a message to all active streams */ 203/* Broadcast a message to all active streams */
202static bool actl_stream_broadcast_callback(struct list_item *item, 204static bool actl_stream_broadcast_callback(struct stream *str,
203 struct str_broadcast_data *sbd) 205 struct str_broadcast_data *sbd)
204{ 206{
205 struct stream *str = TYPE_FROM_MEMBER(struct stream, item, l);
206
207 switch (sbd->cmd) 207 switch (sbd->cmd)
208 { 208 {
209 case STREAM_PLAY: 209 case STREAM_PLAY:
@@ -215,8 +215,8 @@ static bool actl_stream_broadcast_callback(struct list_item *item,
215 { 215 {
216 actl_lock(); 216 actl_lock();
217 217
218 list_remove_item(item); 218 list_remove_item(stream_mgr.actl, str);
219 list_add_item(&stream_mgr.strl, item); 219 list_add_item(stream_mgr.strl, str);
220 220
221 actl_unlock(); 221 actl_unlock();
222 sbd->data = 0; 222 sbd->data = 0;
@@ -236,7 +236,7 @@ static void actl_stream_broadcast(int cmd, intptr_t data)
236 struct str_broadcast_data sbd; 236 struct str_broadcast_data sbd;
237 sbd.cmd = cmd; 237 sbd.cmd = cmd;
238 sbd.data = data; 238 sbd.data = data;
239 list_enum_items(&stream_mgr.actl, 239 list_enum_items(stream_mgr.actl,
240 (list_enum_callback_t)actl_stream_broadcast_callback, 240 (list_enum_callback_t)actl_stream_broadcast_callback,
241 (intptr_t)&sbd); 241 (intptr_t)&sbd);
242} 242}
@@ -623,7 +623,7 @@ static void stream_on_ev_complete(struct stream *str)
623 { 623 {
624 /* No - remove this stream from the active list */ 624 /* No - remove this stream from the active list */
625 DEBUGF(" finished: 0x%02x\n", str->id); 625 DEBUGF(" finished: 0x%02x\n", str->id);
626 if (list_is_empty(&stream_mgr.actl)) 626 if (list_is_empty(stream_mgr.actl))
627 { 627 {
628 /* All streams have acked - stop playback */ 628 /* All streams have acked - stop playback */
629 stream_on_stop(false); 629 stream_on_stop(false);
@@ -820,10 +820,9 @@ void stream_wait_status(void)
820 820
821/* Returns the smallest file window that includes all active streams' 821/* Returns the smallest file window that includes all active streams'
822 * windows */ 822 * windows */
823static bool stream_get_window_callback(struct list_item *item, 823static bool stream_get_window_callback(struct stream *str,
824 struct stream_window *sw) 824 struct stream_window *sw)
825{ 825{
826 struct stream *str = TYPE_FROM_MEMBER(struct stream, item, l);
827 off_t swl = str->hdr.win_left; 826 off_t swl = str->hdr.win_left;
828 off_t swr = str->hdr.win_right; 827 off_t swr = str->hdr.win_right;
829 828
@@ -845,7 +844,7 @@ bool stream_get_window(struct stream_window *sw)
845 sw->right = LONG_MIN; 844 sw->right = LONG_MIN;
846 845
847 actl_lock(); 846 actl_lock();
848 list_enum_items(&stream_mgr.actl, 847 list_enum_items(stream_mgr.actl,
849 (list_enum_callback_t)stream_get_window_callback, 848 (list_enum_callback_t)stream_get_window_callback,
850 (intptr_t)sw); 849 (intptr_t)sw);
851 actl_unlock(); 850 actl_unlock();
@@ -981,7 +980,6 @@ int stream_init(void)
981 980
982 stream_mgr.status = STREAM_STOPPED; 981 stream_mgr.status = STREAM_STOPPED;
983 stream_mgr_init_state(); 982 stream_mgr_init_state();
984 list_initialize(&stream_mgr.actl);
985 983
986 /* Initialize our window to the outside world first */ 984 /* Initialize our window to the outside world first */
987 rb->mutex_init(&stream_mgr.str_mtx); 985 rb->mutex_init(&stream_mgr.str_mtx);