Mercurial > audlegacy
annotate audacious/playback.c @ 276:28b73b5595d1 trunk
[svn] Raise MAX_CODED_SUPERFRAME_SIZE to 16384 in accordance with ffmpeg CVS.
author | chainsaw |
---|---|
date | Sat, 10 Dec 2005 08:42:49 -0800 |
parents | 6dc4483b4c4c |
children |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public Licensse as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include <glib.h> | |
27 #include <glib/gi18n.h> | |
28 #include <glib/gprintf.h> | |
29 #include <stdlib.h> | |
30 #include <string.h> | |
31 #include <time.h> | |
32 | |
33 #include <unistd.h> | |
34 #include <sys/types.h> | |
35 #include <sys/stat.h> | |
36 #include <dirent.h> | |
37 | |
38 #include "libaudacious/util.h" | |
39 #include "libaudacious/configdb.h" | |
40 | |
41 #include "input.h" | |
42 #include "main.h" | |
43 #include "mainwin.h" | |
44 #include "equalizer.h" | |
45 #include "output.h" | |
46 #include "playlist.h" | |
47 #include "playlistwin.h" | |
48 #include "playlist_list.h" | |
49 #include "skin.h" | |
50 #include "skinwin.h" | |
51 #include "urldecode.h" | |
52 #include "util.h" | |
53 | |
54 | |
55 #include "playback.h" | |
56 | |
57 | |
58 /* FIXME: yuck!! this shouldn't be here... */ | |
59 void | |
60 bmp_playback_set_random_skin(void) | |
61 { | |
62 SkinNode *node; | |
63 guint32 randval; | |
64 | |
65 /* Get a random value to select the skin to use */ | |
66 randval = g_random_int_range(0, g_list_length(skinlist)); | |
67 node = g_list_nth(skinlist, randval)->data; | |
68 bmp_active_skin_load(node->path); | |
69 } | |
70 | |
71 gint | |
72 bmp_playback_get_time(void) | |
73 { | |
74 if (!bmp_playback_get_playing()) | |
75 return -1; | |
76 | |
77 if (!get_current_input_plugin()) | |
78 return -1; | |
79 | |
80 return get_current_input_plugin()->get_time(); | |
81 } | |
82 | |
83 void | |
84 bmp_playback_initiate(void) | |
85 { | |
86 const gchar *filename = NULL; | |
87 | |
88 if (playlist_get_length() == 0) | |
89 return; | |
90 | |
91 if (bmp_playback_get_playing()) | |
92 bmp_playback_stop(); | |
93 | |
94 vis_clear_data(mainwin_vis); | |
95 vis_clear_data(playlistwin_vis); | |
96 svis_clear_data(mainwin_svis); | |
97 mainwin_disable_seekbar(); | |
98 | |
99 filename = playlist_get_filename_to_play(); | |
100 | |
101 if (!filename) | |
102 return; | |
103 | |
104 if (!bmp_playback_play_file(filename)) | |
105 return; | |
106 | |
107 if (bmp_playback_get_time() != -1) { | |
108 equalizerwin_load_auto_preset(filename); | |
109 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
110 cfg.equalizer_bands); | |
111 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
112 cfg.equalizer_bands); | |
113 } | |
114 | |
115 playlist_check_pos_current(); | |
116 mainwin_set_info_text(); | |
117 } | |
118 | |
119 void | |
120 bmp_playback_pause(void) | |
121 { | |
122 if (!bmp_playback_get_playing()) | |
123 return; | |
124 | |
125 if (!get_current_input_plugin()) | |
126 return; | |
127 | |
128 ip_data.paused = !ip_data.paused; | |
129 | |
130 if (ip_data.paused) | |
131 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
132 else | |
133 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
134 | |
154
6dc4483b4c4c
[svn] Don't crash if there's no handler for pausing.
nenolod
parents:
152
diff
changeset
|
135 if (get_current_input_plugin()->pause) |
6dc4483b4c4c
[svn] Don't crash if there's no handler for pausing.
nenolod
parents:
152
diff
changeset
|
136 get_current_input_plugin()->pause(ip_data.paused); |
0 | 137 } |
138 | |
139 void | |
140 bmp_playback_stop(void) | |
141 { | |
142 if (ip_data.playing && get_current_input_plugin()) { | |
143 ip_data.playing = FALSE; | |
144 | |
145 if (bmp_playback_get_paused()) | |
146 bmp_playback_pause(); | |
147 | |
148 if (get_current_input_plugin()->stop) | |
149 get_current_input_plugin()->stop(); | |
150 | |
151 free_vis_data(); | |
152 ip_data.paused = FALSE; | |
153 | |
154 if (input_info_text) { | |
155 g_free(input_info_text); | |
156 input_info_text = NULL; | |
157 mainwin_set_info_text(); | |
158 } | |
159 } | |
160 | |
161 ip_data.playing = FALSE; | |
162 } | |
163 | |
144 | 164 void |
165 bmp_playback_stop_reentrant(void) | |
166 { | |
167 if (ip_data.playing && get_current_input_plugin()) { | |
168 ip_data.playing = FALSE; | |
169 | |
170 if (bmp_playback_get_paused()) | |
171 bmp_playback_pause(); | |
172 | |
173 free_vis_data(); | |
174 ip_data.paused = FALSE; | |
175 | |
176 if (input_info_text) { | |
177 g_free(input_info_text); | |
178 input_info_text = NULL; | |
179 mainwin_set_info_text(); | |
180 } | |
181 } | |
182 | |
183 ip_data.playing = FALSE; | |
184 } | |
0 | 185 |
186 static void | |
187 run_no_output_plugin_dialog(void) | |
188 { | |
189 const gchar *markup = | |
190 N_("<b><big>No output plugin selected.</big></b>\n" | |
191 "You have not selected an output plugin."); | |
192 | |
193 GtkWidget *dialog = | |
194 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
195 GTK_DIALOG_DESTROY_WITH_PARENT, | |
196 GTK_MESSAGE_ERROR, | |
197 GTK_BUTTONS_OK, | |
198 _(markup)); | |
199 gtk_dialog_run(GTK_DIALOG(dialog)); | |
200 gtk_widget_destroy(dialog); | |
201 } | |
202 | |
203 gboolean | |
204 bmp_playback_play_file(const gchar * filename) | |
205 { | |
206 GList *node; | |
207 InputPlugin *ip; | |
208 gchar *filename_proxy; | |
209 | |
210 g_return_val_if_fail(filename != NULL, FALSE); | |
211 | |
212 if (!get_current_output_plugin()) { | |
213 run_no_output_plugin_dialog(); | |
214 mainwin_stop_pushed(); | |
215 return FALSE; | |
216 } | |
217 | |
218 if (cfg.random_skin_on_play) | |
219 bmp_playback_set_random_skin(); | |
220 | |
221 filename_proxy = g_strdup(filename); | |
222 | |
223 node = get_input_list(); | |
224 node = g_list_first(node); | |
225 | |
226 while (node) { | |
227 | |
228 ip = node->data; | |
229 | |
230 if (!ip) | |
231 break; | |
232 | |
233 if (ip && input_is_enabled(ip->filename) && | |
234 ip->is_our_file(filename_proxy)) { | |
235 | |
236 | |
237 set_current_input_plugin(ip); | |
238 ip->output = get_current_output_plugin(); | |
239 ip->play_file(filename_proxy); | |
240 | |
241 /* FIXME: Why the hell (yes,hell!) doesn't the input | |
242 plugin set this itself???? -mderezynski */ | |
243 ip_data.playing = TRUE; | |
244 | |
245 g_free(filename_proxy); | |
246 return TRUE; | |
247 } | |
248 node = g_list_next(node); | |
249 } | |
250 | |
251 input_file_not_playable(filename); | |
252 set_current_input_plugin(NULL); | |
253 mainwin_set_info_text(); | |
254 | |
255 g_free(filename_proxy); | |
256 | |
257 return FALSE; | |
258 } | |
259 | |
260 gboolean | |
261 bmp_playback_get_playing(void) | |
262 { | |
263 return ip_data.playing; | |
264 } | |
265 | |
266 gboolean | |
267 bmp_playback_get_paused(void) | |
268 { | |
269 return ip_data.paused; | |
270 } | |
271 | |
272 void | |
273 bmp_playback_seek(gint time) | |
274 { | |
275 gboolean restore_pause = FALSE; | |
276 gint l=0, r=0; | |
277 | |
278 if (!ip_data.playing) | |
279 return; | |
280 | |
281 if (!get_current_input_plugin()) | |
282 return; | |
283 | |
284 /* FIXME WORKAROUND...that should work with all plugins | |
285 * mute the volume, start playback again, do the seek, then pause again | |
286 * -Patrick Sudowe */ | |
287 if(ip_data.paused) | |
288 { | |
289 restore_pause = TRUE; | |
290 output_get_volume(&l, &r); | |
291 output_set_volume(0,0); | |
292 bmp_playback_pause(); | |
293 } | |
294 | |
295 free_vis_data(); | |
296 get_current_input_plugin()->seek(time); | |
297 | |
298 if(restore_pause) | |
299 { | |
300 bmp_playback_pause(); | |
301 output_set_volume(l, r); | |
302 } | |
303 } | |
304 | |
305 void | |
306 bmp_playback_seek_relative(gint offset) | |
307 { | |
308 gint time = CLAMP(bmp_playback_get_time() / 1000 + offset, | |
309 0, playlist_get_current_length() / 1000 - 1); | |
310 bmp_playback_seek(time); | |
311 } |