Mercurial > audlegacy
annotate src/audacious/playback.c @ 3249:eff2e785e3b4
add focus_in and focus_out events
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Sun, 05 Aug 2007 11:23:35 +0200 |
parents | 06d89ea93859 |
children | f02623377013 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3093
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
2313 | 13 * |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3093
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
21 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
2313 | 24 */ |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 # include "config.h" | |
28 #endif | |
29 | |
30 #include <glib.h> | |
31 #include <glib/gi18n.h> | |
32 #include <glib/gprintf.h> | |
33 #include <stdlib.h> | |
34 #include <string.h> | |
35 #include <time.h> | |
36 | |
37 #include <unistd.h> | |
38 #include <sys/types.h> | |
39 #include <sys/stat.h> | |
40 #include <dirent.h> | |
41 | |
2717 | 42 #include "configdb.h" |
2313 | 43 |
2420 | 44 #include "hook.h" |
3152
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
45 #include "eventqueue.h" |
2313 | 46 #include "input.h" |
47 #include "main.h" | |
48 #include "ui_equalizer.h" | |
49 #include "output.h" | |
50 #include "playlist.h" | |
2420 | 51 #include "ui_main.h" |
2313 | 52 #include "ui_playlist.h" |
53 #include "ui_skinselector.h" | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
54 #include "ui_skinned_playstatus.h" |
2313 | 55 #include "util.h" |
3082
91df04ec5ef7
From: Daniel Drake <dsd@gentoo.org>
William Pitcock <nenolod@atheme-project.org>
parents:
3042
diff
changeset
|
56 #include "visualization.h" |
2313 | 57 |
58 #include "playback.h" | |
3152
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
59 #include "playback_evlisteners.h" |
2313 | 60 |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
61 static int song_info_timeout_source = 0; |
2313 | 62 |
3152
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
63 void |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
64 playback_eof(void) |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
65 { |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
66 event_queue("playback eof", playlist_get_active()); |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
67 } |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
68 |
3158
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
69 void |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
70 playback_error(void) |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
71 { |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
72 event_queue("playback audio error", NULL); |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
73 } |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
74 |
2313 | 75 gint |
76 playback_get_time(void) | |
77 { | |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
78 InputPlayback *playback; |
2420 | 79 g_return_val_if_fail(playback_get_playing(), -1); |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
80 playback = get_current_input_playback(); |
2313 | 81 |
3180
384cb84c968f
Gracefully handle playback being NULL even if playback_get_playing() is TRUE during playback init.
Christian Birchinger <joker@netswarm.net>
parents:
3179
diff
changeset
|
82 if (!playback) /* playback can be NULL during init even if playing is TRUE */ |
384cb84c968f
Gracefully handle playback being NULL even if playback_get_playing() is TRUE during playback init.
Christian Birchinger <joker@netswarm.net>
parents:
3179
diff
changeset
|
83 return -1; |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
84 if (playback->plugin->get_time) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
85 return playback->plugin->get_time(playback); |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
86 if (playback->error) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
87 return -2; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
88 if (!playback->playing || |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
89 (playback->eof && !playback->output->buffer_playing())) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
90 return -1; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
91 return playback->output->output_time(); |
2313 | 92 } |
93 | |
94 void | |
95 playback_initiate(void) | |
96 { | |
97 PlaylistEntry *entry = NULL; | |
98 Playlist *playlist = playlist_get_active(); | |
99 | |
2420 | 100 g_return_if_fail(playlist_get_length(playlist) != 0); |
2313 | 101 |
3152
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
102 /* initialize playback event listeners if not done already */ |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
103 playback_evlistener_init(); |
c9471f83944c
Add playback_eof(). Plugins should use this instead of playback->eof = 1.
William Pitcock <nenolod@atheme-project.org>
parents:
3128
diff
changeset
|
104 |
2313 | 105 if (playback_get_playing()) |
106 playback_stop(); | |
107 | |
3020 | 108 ui_vis_clear_data(mainwin_vis); |
3054 | 109 ui_svis_clear_data(mainwin_svis); |
2313 | 110 mainwin_disable_seekbar(); |
111 | |
112 entry = playlist_get_entry_to_play(playlist); | |
2420 | 113 g_return_if_fail(entry != NULL); |
2592
6f7be3702c5f
[svn] - revert the penalty-based "find something to play" logic of 1.2. it's
nenolod
parents:
2454
diff
changeset
|
114 playback_play_file(entry); |
2313 | 115 |
3179
d2eae001e562
I don't think that's needed. If you revert it, use playback_get_playing() instead.
Christian Birchinger <joker@netswarm.net>
parents:
3170
diff
changeset
|
116 // if (playback_get_time() != -1) { |
2313 | 117 equalizerwin_load_auto_preset(entry->filename); |
118 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
119 cfg.equalizer_bands); | |
120 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
121 cfg.equalizer_bands); | |
3179
d2eae001e562
I don't think that's needed. If you revert it, use playback_get_playing() instead.
Christian Birchinger <joker@netswarm.net>
parents:
3170
diff
changeset
|
122 // } |
2313 | 123 |
124 playlist_check_pos_current(playlist); | |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
125 mainwin_update_song_info(); |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
126 |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
127 /* FIXME: use g_timeout_add_seconds when glib-2.14 is required */ |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
128 song_info_timeout_source = g_timeout_add(1000, |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
129 (GSourceFunc) mainwin_update_song_info, NULL); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
130 |
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
131 if (cfg.player_shaded) { |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
132 gtk_widget_show(mainwin_stime_min); |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
133 gtk_widget_show(mainwin_stime_sec); |
3042
01ae56759d15
mainwin_sposition is now UiSkinnedHorizontalSlider
Tomasz Mon <desowin@gmail.com>
parents:
3041
diff
changeset
|
134 gtk_widget_show(mainwin_sposition); |
3001
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
135 } else { |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
136 gtk_widget_show(mainwin_minus_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
137 gtk_widget_show(mainwin_10min_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
138 gtk_widget_show(mainwin_min_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
139 gtk_widget_show(mainwin_10sec_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
140 gtk_widget_show(mainwin_sec_num); |
3040
067e0186623a
import UiSkinnedHorizontalSlider
Tomasz Mon <desowin@gmail.com>
parents:
3021
diff
changeset
|
141 gtk_widget_show(mainwin_position); |
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
142 } |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
143 |
3082
91df04ec5ef7
From: Daniel Drake <dsd@gentoo.org>
William Pitcock <nenolod@atheme-project.org>
parents:
3042
diff
changeset
|
144 vis_playback_start(); |
3092
1ddeb9f068ab
Backed out changeset b87335249c69d45d253b1b960a9ec7f60b68e5a5
William Pitcock <nenolod@atheme-project.org>
parents:
3089
diff
changeset
|
145 |
1ddeb9f068ab
Backed out changeset b87335249c69d45d253b1b960a9ec7f60b68e5a5
William Pitcock <nenolod@atheme-project.org>
parents:
3089
diff
changeset
|
146 hook_call("playback begin", entry); |
2313 | 147 } |
148 | |
149 void | |
150 playback_pause(void) | |
151 { | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
152 InputPlayback *playback; |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
153 |
2313 | 154 if (!playback_get_playing()) |
155 return; | |
156 | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
157 if ((playback = get_current_input_playback()) == NULL) |
2313 | 158 return; |
159 | |
160 ip_data.paused = !ip_data.paused; | |
161 | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
162 if (playback->plugin->pause) |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
163 playback->plugin->pause(playback, ip_data.paused); |
2313 | 164 |
3039
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
165 if (ip_data.paused) |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
166 hook_call("playback pause", NULL); |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
167 else |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
168 hook_call("playback unpause", NULL); |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
169 |
2313 | 170 g_return_if_fail(mainwin_playstatus != NULL); |
171 | |
172 if (ip_data.paused) | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
173 ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); |
2313 | 174 else |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
175 ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY); |
2313 | 176 } |
177 | |
178 void | |
179 playback_stop(void) | |
180 { | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
181 InputPlayback *playback; |
2313 | 182 |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
183 if (ip_data.playing && (playback = get_current_input_playback()) != NULL) |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
184 { |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
185 if (playback_get_paused() == TRUE) |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
186 { |
2313 | 187 output_flush(get_written_time()); /* to avoid noise */ |
188 playback_pause(); | |
189 } | |
190 | |
191 ip_data.playing = FALSE; | |
192 | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
193 if (playback->plugin->stop) |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
194 playback->plugin->stop(playback); |
2313 | 195 |
3181
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
196 if (playback->thread != NULL) |
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
197 g_thread_join(playback->thread); |
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
198 |
2313 | 199 free_vis_data(); |
200 ip_data.paused = FALSE; | |
201 | |
3170
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
202 g_free(playback->filename); |
603577228518
get_current_input_playback() cleanups.
William Pitcock <nenolod@atheme-project.org>
parents:
3168
diff
changeset
|
203 g_free(playback); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
204 set_current_input_playback(NULL); |
2313 | 205 } |
206 | |
207 ip_data.buffering = FALSE; | |
208 ip_data.playing = FALSE; | |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
209 |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
210 if (song_info_timeout_source) |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
211 g_source_remove(song_info_timeout_source); |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
212 |
3082
91df04ec5ef7
From: Daniel Drake <dsd@gentoo.org>
William Pitcock <nenolod@atheme-project.org>
parents:
3042
diff
changeset
|
213 vis_playback_stop(); |
91df04ec5ef7
From: Daniel Drake <dsd@gentoo.org>
William Pitcock <nenolod@atheme-project.org>
parents:
3042
diff
changeset
|
214 |
2313 | 215 g_return_if_fail(mainwin_playstatus != NULL); |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
216 ui_skinned_playstatus_set_buffering(mainwin_playstatus, FALSE); |
2313 | 217 } |
218 | |
219 static void | |
220 run_no_output_plugin_dialog(void) | |
221 { | |
222 const gchar *markup = | |
223 N_("<b><big>No output plugin selected.</big></b>\n" | |
224 "You have not selected an output plugin."); | |
225 | |
226 GtkWidget *dialog = | |
227 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
228 GTK_DIALOG_DESTROY_WITH_PARENT, | |
229 GTK_MESSAGE_ERROR, | |
230 GTK_BUTTONS_OK, | |
231 _(markup)); | |
232 gtk_dialog_run(GTK_DIALOG(dialog)); | |
233 gtk_widget_destroy(dialog); | |
234 } | |
235 | |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
236 static gpointer |
3154
732cfad87116
Made a mistake here. Fixing!
William Pitcock <nenolod@atheme-project.org>
parents:
3153
diff
changeset
|
237 playback_monitor_thread(gpointer data) |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
238 { |
3154
732cfad87116
Made a mistake here. Fixing!
William Pitcock <nenolod@atheme-project.org>
parents:
3153
diff
changeset
|
239 PlaylistEntry *entry = (PlaylistEntry *) data; |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
240 InputPlayback *playback; |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
241 |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
242 playback = g_new0(InputPlayback, 1); |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
243 |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
244 entry->decoder->output = &psuedo_output_plugin; |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
245 |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
246 playback->plugin = entry->decoder; |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
247 playback->output = &psuedo_output_plugin; |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
248 playback->filename = g_strdup(entry->filename); |
3181
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
249 playback->thread = g_thread_self(); |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
250 |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
251 set_current_input_playback(playback); |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
252 |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
253 entry->decoder->play_file(playback); |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
254 |
3158
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
255 if (!playback->error && ip_data.playing) |
3156
4a0e216bc825
playback monitor thread: If forced stop occurs, do not queue "playback eof" signal.
William Pitcock <nenolod@atheme-project.org>
parents:
3155
diff
changeset
|
256 playback_eof(); |
3158
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
257 else if (playback->error) |
92717dcb09f6
Send a message from the monitor thread to the main thread for audio errors, like we do with eof condition.
William Pitcock <nenolod@atheme-project.org>
parents:
3156
diff
changeset
|
258 playback_error(); |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
259 |
3181
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
260 playback->thread = NULL; |
1596dcb77acd
Track playback monitor thread in InputPlayback.thread.
William Pitcock <nenolod@atheme-project.org>
parents:
3170
diff
changeset
|
261 g_thread_exit(NULL); |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
262 return NULL; |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
263 } |
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
264 |
2313 | 265 gboolean |
266 playback_play_file(PlaylistEntry *entry) | |
267 { | |
268 g_return_val_if_fail(entry != NULL, FALSE); | |
269 | |
270 if (!get_current_output_plugin()) { | |
271 run_no_output_plugin_dialog(); | |
272 mainwin_stop_pushed(); | |
273 return FALSE; | |
274 } | |
275 | |
276 if (cfg.random_skin_on_play) | |
2443
93686e8815a4
[svn] - Changed playback_set_random_skin() to skin_set_random_skin()
mf0102
parents:
2438
diff
changeset
|
277 skin_set_random_skin(); |
2313 | 278 |
3127
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
279 if (!entry->decoder) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
280 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
281 ProbeResult *pr = input_check_file(entry->filename, FALSE); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
282 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
283 if (pr != NULL) |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
284 { |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
285 entry->decoder = pr->ip; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
286 entry->tuple = pr->tuple; |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
287 |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
288 g_free(pr); |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
289 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
290 } |
c92070f10148
Use ProbeResult (try 1)
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
291 |
3128
343504d43afc
Fix warnings.
William Pitcock <nenolod@atheme-project.org>
parents:
3127
diff
changeset
|
292 if (!entry->decoder || !input_is_enabled(entry->decoder->filename)) |
2313 | 293 { |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
294 set_current_input_playback(NULL); |
2313 | 295 |
296 return FALSE; | |
297 } | |
298 | |
3092
1ddeb9f068ab
Backed out changeset b87335249c69d45d253b1b960a9ec7f60b68e5a5
William Pitcock <nenolod@atheme-project.org>
parents:
3089
diff
changeset
|
299 ip_data.playing = TRUE; |
3153
e0a2ea93f98f
New threading model for playback. Playback code should now *block*.
William Pitcock <nenolod@atheme-project.org>
parents:
3152
diff
changeset
|
300 g_thread_create(playback_monitor_thread, entry, TRUE, NULL); |
2313 | 301 |
302 return TRUE; | |
303 } | |
304 | |
305 gboolean | |
306 playback_get_playing(void) | |
307 { | |
308 return ip_data.playing; | |
309 } | |
310 | |
311 gboolean | |
312 playback_get_paused(void) | |
313 { | |
314 return ip_data.paused; | |
315 } | |
316 | |
317 void | |
318 playback_seek(gint time) | |
319 { | |
3168
ee8a1ed30826
playback_seek(): several WTFs in here (probably from XMMS) fixed
William Pitcock <nenolod@atheme-project.org>
parents:
3165
diff
changeset
|
320 InputPlayback *playback = get_current_input_playback(); |
2313 | 321 gboolean restore_pause = FALSE; |
322 gint l=0, r=0; | |
323 | |
2420 | 324 g_return_if_fail(ip_data.playing); |
3168
ee8a1ed30826
playback_seek(): several WTFs in here (probably from XMMS) fixed
William Pitcock <nenolod@atheme-project.org>
parents:
3165
diff
changeset
|
325 g_return_if_fail(playback != NULL); |
2313 | 326 |
327 /* FIXME WORKAROUND...that should work with all plugins | |
328 * mute the volume, start playback again, do the seek, then pause again | |
329 * -Patrick Sudowe | |
330 */ | |
2420 | 331 if (ip_data.paused) |
2313 | 332 { |
2420 | 333 restore_pause = TRUE; |
334 output_get_volume(&l, &r); | |
335 output_set_volume(0,0); | |
336 playback_pause(); | |
2313 | 337 } |
338 | |
3168
ee8a1ed30826
playback_seek(): several WTFs in here (probably from XMMS) fixed
William Pitcock <nenolod@atheme-project.org>
parents:
3165
diff
changeset
|
339 playback->plugin->seek(playback, time); |
2313 | 340 free_vis_data(); |
341 | |
2420 | 342 if (restore_pause) |
2313 | 343 { |
2420 | 344 playback_pause(); |
345 output_set_volume(l, r); | |
2313 | 346 } |
347 } | |
348 | |
349 void | |
350 playback_seek_relative(gint offset) | |
351 { | |
352 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
353 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
354 playback_seek(time); | |
355 } |