Mercurial > audlegacy
annotate src/audacious/input.c @ 3110:35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
| author | Christian Birchinger <joker@netswarm.net> |
|---|---|
| date | Fri, 20 Jul 2007 02:35:34 +0200 |
| parents | ba2143c1c6f5 |
| children | 3b6d316f8b09 |
| rev | line source |
|---|---|
| 2313 | 1 /* Audacious - Cross-platform multimedia player |
| 2 * Copyright (C) 2005-2006 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 | |
| 12 * the Free Software Foundation; under version 2 of the License. | |
| 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 | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 22 */ | |
| 23 | |
| 24 #ifdef HAVE_CONFIG_H | |
| 25 # include "config.h" | |
| 26 #endif | |
| 27 | |
| 28 #include <glib.h> | |
| 29 #include <glib/gi18n.h> | |
| 30 #include <gtk/gtk.h> | |
| 31 #include <string.h> | |
| 32 | |
| 33 #include "fft.h" | |
| 34 #include "input.h" | |
| 35 #include "main.h" | |
| 36 #include "output.h" | |
| 37 #include "playback.h" | |
| 38 #include "pluginenum.h" | |
| 2420 | 39 #include "strings.h" |
| 2313 | 40 #include "titlestring.h" |
| 2420 | 41 #include "ui_main.h" |
| 42 #include "util.h" | |
| 43 #include "visualization.h" | |
| 44 #include "widgets/widgetcore.h" | |
|
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
45 #include "ui_skinned_playstatus.h" |
| 2505 | 46 #include "hook.h" |
| 2313 | 47 |
|
2347
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
48 #include "vfs.h" |
|
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
49 #include "vfs_buffer.h" |
|
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
50 #include "vfs_buffered_file.h" |
|
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
51 |
| 2313 | 52 G_LOCK_DEFINE_STATIC(vis_mutex); |
| 53 | |
| 54 struct _VisNode { | |
| 55 gint time; | |
| 56 gint nch; | |
| 57 gint length; /* number of samples per channel */ | |
| 58 gint16 data[2][512]; | |
| 59 }; | |
| 60 | |
| 61 typedef struct _VisNode VisNode; | |
| 62 | |
| 63 | |
| 64 InputPluginData ip_data = { | |
| 65 NULL, | |
| 66 NULL, | |
| 67 FALSE, | |
| 68 FALSE, | |
| 69 FALSE, | |
| 70 FALSE, | |
| 71 NULL | |
| 72 }; | |
| 73 | |
| 74 static GList *vis_list = NULL; | |
| 75 | |
| 76 gchar *input_info_text = NULL; | |
| 77 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
78 InputPlayback * |
|
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
79 get_current_input_playback(void) |
| 2313 | 80 { |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
81 return ip_data.current_input_playback; |
| 2313 | 82 } |
| 83 | |
| 84 void | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
85 set_current_input_playback(InputPlayback * ip) |
| 2313 | 86 { |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
87 ip_data.current_input_playback = ip; |
| 2313 | 88 } |
| 89 | |
| 90 GList * | |
| 91 get_input_list(void) | |
| 92 { | |
| 93 return ip_data.input_list; | |
| 94 } | |
| 95 | |
| 96 | |
| 97 gboolean | |
| 98 input_is_enabled(const gchar * filename) | |
| 99 { | |
| 100 gchar *basename = g_path_get_basename(filename); | |
| 101 gint enabled; | |
| 102 | |
| 103 enabled = GPOINTER_TO_INT(g_hash_table_lookup(plugin_matrix, basename)); | |
| 104 g_free(basename); | |
| 105 | |
| 106 return enabled; | |
| 107 } | |
| 108 | |
| 109 static void | |
| 110 disabled_iplugins_foreach_func(const gchar * name, | |
| 111 gboolean enabled, | |
| 112 GString * list) | |
| 113 { | |
| 114 g_return_if_fail(list != NULL); | |
| 115 | |
| 116 if (enabled) | |
| 117 return; | |
| 118 | |
| 119 if (list->len > 0) | |
| 120 g_string_append(list, ":"); | |
| 121 | |
| 122 g_string_append(list, name); | |
| 123 } | |
| 124 | |
| 125 gchar * | |
| 126 input_stringify_disabled_list(void) | |
| 127 { | |
| 128 GString *disabled_list; | |
| 129 | |
| 130 disabled_list = g_string_new(""); | |
| 131 g_hash_table_foreach(plugin_matrix, | |
| 132 (GHFunc) disabled_iplugins_foreach_func, | |
| 133 disabled_list); | |
| 134 | |
| 135 return g_string_free(disabled_list, FALSE); | |
| 136 } | |
| 137 | |
| 138 void | |
| 139 free_vis_data(void) | |
| 140 { | |
| 141 G_LOCK(vis_mutex); | |
| 142 g_list_foreach(vis_list, (GFunc) g_free, NULL); | |
| 143 g_list_free(vis_list); | |
| 144 vis_list = NULL; | |
| 145 G_UNLOCK(vis_mutex); | |
| 146 } | |
| 147 | |
| 148 static void | |
| 149 convert_to_s16_ne(AFormat fmt, gpointer ptr, gint16 * left, | |
| 150 gint16 * right, gint nch, gint max) | |
| 151 { | |
| 152 gint16 *ptr16; | |
| 153 guint16 *ptru16; | |
| 154 guint8 *ptru8; | |
| 155 gint i; | |
| 156 | |
| 157 switch (fmt) { | |
| 158 case FMT_U8: | |
| 159 ptru8 = ptr; | |
| 160 if (nch == 1) | |
| 161 for (i = 0; i < max; i++) | |
| 162 left[i] = ((*ptru8++) ^ 128) << 8; | |
| 163 else | |
| 164 for (i = 0; i < max; i++) { | |
| 165 left[i] = ((*ptru8++) ^ 128) << 8; | |
| 166 right[i] = ((*ptru8++) ^ 128) << 8; | |
| 167 } | |
| 168 break; | |
| 169 case FMT_S8: | |
| 170 ptru8 = ptr; | |
| 171 if (nch == 1) | |
| 172 for (i = 0; i < max; i++) | |
| 173 left[i] = (*ptru8++) << 8; | |
| 174 else | |
| 175 for (i = 0; i < max; i++) { | |
| 176 left[i] = (*ptru8++) << 8; | |
| 177 right[i] = (*ptru8++) << 8; | |
| 178 } | |
| 179 break; | |
| 180 case FMT_U16_LE: | |
| 181 ptru16 = ptr; | |
| 182 if (nch == 1) | |
| 183 for (i = 0; i < max; i++, ptru16++) | |
| 184 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
| 185 else | |
| 186 for (i = 0; i < max; i++) { | |
| 187 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
| 188 ptru16++; | |
| 189 right[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
| 190 ptru16++; | |
| 191 } | |
| 192 break; | |
| 193 case FMT_U16_BE: | |
| 194 ptru16 = ptr; | |
| 195 if (nch == 1) | |
| 196 for (i = 0; i < max; i++, ptru16++) | |
| 197 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
| 198 else | |
| 199 for (i = 0; i < max; i++) { | |
| 200 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
| 201 ptru16++; | |
| 202 right[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
| 203 ptru16++; | |
| 204 } | |
| 205 break; | |
| 206 case FMT_U16_NE: | |
| 207 ptru16 = ptr; | |
| 208 if (nch == 1) | |
| 209 for (i = 0; i < max; i++) | |
| 210 left[i] = (*ptru16++) ^ 32768; | |
| 211 else | |
| 212 for (i = 0; i < max; i++) { | |
| 213 left[i] = (*ptru16++) ^ 32768; | |
| 214 right[i] = (*ptru16++) ^ 32768; | |
| 215 } | |
| 216 break; | |
| 217 case FMT_S16_LE: | |
| 218 ptr16 = ptr; | |
| 219 if (nch == 1) | |
| 220 for (i = 0; i < max; i++, ptr16++) | |
| 221 left[i] = GINT16_FROM_LE(*ptr16); | |
| 222 else | |
| 223 for (i = 0; i < max; i++) { | |
| 224 left[i] = GINT16_FROM_LE(*ptr16); | |
| 225 ptr16++; | |
| 226 right[i] = GINT16_FROM_LE(*ptr16); | |
| 227 ptr16++; | |
| 228 } | |
| 229 break; | |
| 230 case FMT_S16_BE: | |
| 231 ptr16 = ptr; | |
| 232 if (nch == 1) | |
| 233 for (i = 0; i < max; i++, ptr16++) | |
| 234 left[i] = GINT16_FROM_BE(*ptr16); | |
| 235 else | |
| 236 for (i = 0; i < max; i++) { | |
| 237 left[i] = GINT16_FROM_BE(*ptr16); | |
| 238 ptr16++; | |
| 239 right[i] = GINT16_FROM_BE(*ptr16); | |
| 240 ptr16++; | |
| 241 } | |
| 242 break; | |
| 243 case FMT_S16_NE: | |
| 244 ptr16 = ptr; | |
| 245 if (nch == 1) | |
| 246 for (i = 0; i < max; i++) | |
| 247 left[i] = (*ptr16++); | |
| 248 else | |
| 249 for (i = 0; i < max; i++) { | |
| 250 left[i] = (*ptr16++); | |
| 251 right[i] = (*ptr16++); | |
| 252 } | |
| 253 break; | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 InputVisType | |
| 258 input_get_vis_type() | |
| 259 { | |
| 260 return INPUT_VIS_OFF; | |
| 261 } | |
| 262 | |
| 263 void | |
| 264 input_add_vis_pcm(gint time, AFormat fmt, gint nch, gint length, gpointer ptr) | |
| 265 { | |
| 266 VisNode *vis_node; | |
| 267 gint max; | |
| 268 | |
| 269 max = length / nch; | |
| 270 if (fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE || | |
| 271 fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE) | |
| 272 max /= 2; | |
| 273 max = CLAMP(max, 0, 512); | |
| 274 | |
| 275 vis_node = g_new0(VisNode, 1); | |
| 276 vis_node->time = time; | |
| 277 vis_node->nch = nch; | |
| 278 vis_node->length = max; | |
| 279 convert_to_s16_ne(fmt, ptr, vis_node->data[0], vis_node->data[1], nch, | |
| 280 max); | |
| 281 | |
| 282 G_LOCK(vis_mutex); | |
| 283 vis_list = g_list_append(vis_list, vis_node); | |
| 284 G_UNLOCK(vis_mutex); | |
| 285 } | |
| 286 | |
| 287 void | |
| 288 input_dont_show_warning(GtkObject * object, gpointer user_data) | |
| 289 { | |
| 290 *((gboolean *) user_data) = | |
| 291 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object)); | |
| 292 } | |
| 293 | |
| 294 /* | |
| 295 * input_check_file() | |
| 296 * | |
| 297 * Inputs: | |
| 298 * filename to check recursively against input plugins | |
| 299 * whether or not to show an error | |
| 300 * | |
| 301 * Outputs: | |
| 302 * pointer to input plugin which can handle this file | |
| 303 * otherwise, NULL | |
| 304 * | |
| 305 * (the previous code returned a boolean of whether or not we can | |
| 306 * play the file... even WORSE for performance) | |
| 307 * | |
| 308 * Side Effects: | |
| 309 * various input plugins open the file and probe it | |
| 310 * -- this can have very ugly effects performance wise on streams | |
| 311 * | |
| 312 * --nenolod, Dec 31 2005 | |
| 313 * | |
| 314 * Rewritten to use NewVFS probing, semantics are still basically the same. | |
| 315 * | |
| 316 * --nenolod, Dec 5 2006 | |
| 317 * | |
| 318 * Adapted to use the NewVFS extension probing system if enabled. | |
| 319 * | |
| 320 * --nenolod, Dec 12 2006 | |
|
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
321 * |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
322 * Adapted to use the mimetype system. |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
323 * |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
324 * --nenolod, Jul 9 2007 |
| 2313 | 325 */ |
| 326 InputPlugin * | |
| 327 input_check_file(const gchar * filename, gboolean show_warning) | |
| 328 { | |
| 329 VFSFile *fd; | |
| 330 GList *node; | |
| 331 InputPlugin *ip; | |
| 332 gchar *filename_proxy; | |
| 333 gint ret = 1; | |
|
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
334 gchar *ext, *tmp, *tmp_uri; |
| 2313 | 335 gboolean use_ext_filter; |
|
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
336 gchar *mimetype; |
| 2313 | 337 |
| 338 filename_proxy = g_strdup(filename); | |
|
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
339 |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
340 /* Some URIs will end in ?<subsong> to determine the subsong requested. */ |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
341 tmp_uri = g_strdup(filename); |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
342 |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
343 tmp = strrchr(tmp_uri, '?'); |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
344 |
|
2510
c8d6564f9c82
[svn] - only strip the subsong identifier if it is really a valid subsong identifier. closes #792.
nenolod
parents:
2505
diff
changeset
|
345 if (tmp != NULL && g_ascii_isdigit(*(tmp + 1))) |
|
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
346 *tmp = '\0'; |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
347 |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
348 fd = vfs_buffered_file_new_from_uri(tmp_uri); |
|
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
349 g_free(tmp_uri); |
| 2313 | 350 |
|
3110
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
351 if (!fd) { |
|
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
352 printf("Unreadable to read from %s, giving up.\n", filename_proxy); |
|
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
353 g_free(filename_proxy); |
|
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
354 return NULL; |
|
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
355 } |
|
35e560fa183f
Added a fd NULL check to avoid probing on none-existing fds
Christian Birchinger <joker@netswarm.net>
parents:
3081
diff
changeset
|
356 |
| 2313 | 357 ext = strrchr(filename_proxy, '.') + 1; |
| 358 | |
| 2569 | 359 use_ext_filter = |
| 360 (fd != NULL && (!g_strncasecmp(filename, "/", 1) || | |
| 361 !g_strncasecmp(filename, "file://", 7))) ? TRUE : FALSE; | |
| 2313 | 362 |
|
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
363 mimetype = vfs_get_metadata(fd, "content-type"); |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
364 if ((ip = mime_get_plugin(mimetype)) != NULL) |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
365 { |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
366 g_free(filename_proxy); |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
367 vfs_fclose(fd); |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
368 return ip; |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
369 } |
|
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
370 |
| 2313 | 371 for (node = get_input_list(); node != NULL; node = g_list_next(node)) |
| 372 { | |
| 373 ip = INPUT_PLUGIN(node->data); | |
| 374 | |
| 375 if (!ip || !input_is_enabled(ip->filename)) | |
| 376 continue; | |
| 377 | |
|
2342
f140d0a27093
[svn] - use vfs_rewind() instead of vfs_fseek(fd, 0, seek_set) which was wrong
nenolod
parents:
2331
diff
changeset
|
378 vfs_rewind(fd); |
| 2313 | 379 |
| 2569 | 380 if (cfg.use_extension_probing == TRUE && ip->vfs_extensions != NULL && |
| 381 ext != NULL && ext != (gpointer) 0x1 && use_ext_filter == TRUE) | |
| 2313 | 382 { |
| 383 gint i; | |
| 384 gboolean is_our_ext = FALSE; | |
| 385 | |
| 386 for (i = 0; ip->vfs_extensions[i] != NULL; i++) | |
| 387 { | |
| 388 if (str_has_prefix_nocase(ext, ip->vfs_extensions[i])) | |
| 2331 | 389 { |
| 390 is_our_ext = TRUE; | |
| 391 break; | |
| 392 } | |
| 2313 | 393 } |
| 394 | |
| 395 /* not a plugin that supports this extension */ | |
| 396 if (is_our_ext == FALSE) | |
| 397 continue; | |
| 398 } | |
| 399 | |
|
2427
64948ea58c53
[svn] - revise logic of r3808 so that cdaudio works again.
yaz
parents:
2420
diff
changeset
|
400 if (fd && ip->is_our_file_from_vfs != NULL) |
| 2313 | 401 { |
| 402 ret = ip->is_our_file_from_vfs(filename_proxy, fd); | |
| 403 | |
| 404 if (ret > 0) | |
| 405 { | |
| 406 g_free(filename_proxy); | |
| 407 vfs_fclose(fd); | |
| 408 return ip; | |
| 409 } | |
| 410 } | |
| 411 else if (ip->is_our_file != NULL) | |
| 412 { | |
| 413 ret = ip->is_our_file(filename_proxy); | |
| 414 | |
| 415 if (ret > 0) | |
| 416 { | |
| 417 g_free(filename_proxy); | |
| 418 vfs_fclose(fd); | |
| 419 return ip; | |
| 420 } | |
| 421 } | |
| 422 | |
| 2331 | 423 if (ret <= -1) |
| 424 break; | |
| 2313 | 425 } |
| 426 | |
| 427 g_free(filename_proxy); | |
| 428 | |
| 429 vfs_fclose(fd); | |
| 430 | |
| 431 return NULL; | |
| 432 } | |
| 433 | |
| 434 | |
| 435 void | |
| 436 input_set_eq(gint on, gfloat preamp, gfloat * bands) | |
| 437 { | |
| 438 if (!ip_data.playing) | |
| 439 return; | |
| 440 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
441 if (!get_current_input_playback()) |
| 2313 | 442 return; |
| 443 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
444 if (get_current_input_playback()->plugin->set_eq) |
|
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
445 get_current_input_playback()->plugin->set_eq(on, preamp, bands); |
| 2313 | 446 } |
| 447 | |
| 448 void | |
| 449 input_get_song_info(const gchar * filename, gchar ** title, gint * length) | |
| 450 { | |
| 451 InputPlugin *ip = NULL; | |
| 452 BmpTitleInput *input; | |
| 453 gchar *tmp = NULL, *ext; | |
| 454 gchar *filename_proxy; | |
| 455 | |
| 456 g_return_if_fail(filename != NULL); | |
| 457 g_return_if_fail(title != NULL); | |
| 458 g_return_if_fail(length != NULL); | |
| 459 | |
| 460 filename_proxy = g_strdup(filename); | |
| 461 | |
| 462 ip = input_check_file(filename_proxy, FALSE); | |
| 463 | |
| 2331 | 464 if (ip && ip->get_song_info) { |
| 2313 | 465 ip->get_song_info(filename_proxy, &tmp, length); |
| 466 *title = str_to_utf8(tmp); | |
| 467 g_free(tmp); | |
| 468 } | |
| 469 else { | |
| 470 input = bmp_title_input_new(); | |
| 471 | |
| 472 tmp = g_strdup(filename); | |
| 473 if ((ext = strrchr(tmp, '.'))) | |
| 474 *ext = '\0'; | |
| 475 | |
| 476 input->file_name = g_path_get_basename(tmp); | |
| 477 input->file_ext = ext ? ext + 1 : NULL; | |
| 478 input->file_path = g_path_get_dirname(tmp); | |
| 479 | |
| 480 if ((tmp = xmms_get_titlestring(xmms_get_gentitle_format(), input))) { | |
| 481 (*title) = str_to_utf8(tmp); | |
| 482 g_free(tmp); | |
| 483 } | |
| 484 else { | |
| 485 (*title) = filename_to_utf8(input->file_name); | |
| 486 } | |
| 487 | |
| 488 (*length) = -1; | |
| 489 | |
| 490 bmp_title_input_free(input); | |
| 491 input = NULL; | |
| 492 } | |
| 493 | |
| 494 g_free(filename_proxy); | |
| 495 } | |
| 496 | |
| 497 TitleInput * | |
| 498 input_get_song_tuple(const gchar * filename) | |
| 499 { | |
| 500 InputPlugin *ip = NULL; | |
| 501 TitleInput *input; | |
|
2394
e2aaa7dca389
[svn] - tuple->file_name coming from input plugins have a string with filename + extension, but tuple->file_name coming from input plugins without a get_song_tuple have a string with filename without extension; fix this incongruency, always pass tuple->filename with a string containing filename + extension
giacomo
parents:
2373
diff
changeset
|
502 gchar *ext = NULL; |
| 2313 | 503 gchar *filename_proxy; |
| 504 | |
| 505 if (filename == NULL) | |
| 2331 | 506 return NULL; |
| 2313 | 507 |
| 508 filename_proxy = g_strdup(filename); | |
| 509 | |
| 510 ip = input_check_file(filename_proxy, FALSE); | |
| 511 | |
| 2331 | 512 if (ip && ip->get_song_tuple) |
| 2313 | 513 input = ip->get_song_tuple(filename_proxy); |
| 2331 | 514 else |
| 515 { | |
| 2313 | 516 input = bmp_title_input_new(); |
| 517 | |
|
2394
e2aaa7dca389
[svn] - tuple->file_name coming from input plugins have a string with filename + extension, but tuple->file_name coming from input plugins without a get_song_tuple have a string with filename without extension; fix this incongruency, always pass tuple->filename with a string containing filename + extension
giacomo
parents:
2373
diff
changeset
|
518 ext = strrchr(filename, '.'); |
| 2313 | 519 |
| 2331 | 520 input->track_name = NULL; |
| 521 input->length = -1; | |
| 522 input_get_song_info(filename, &input->track_name, &input->length); | |
|
2394
e2aaa7dca389
[svn] - tuple->file_name coming from input plugins have a string with filename + extension, but tuple->file_name coming from input plugins without a get_song_tuple have a string with filename without extension; fix this incongruency, always pass tuple->filename with a string containing filename + extension
giacomo
parents:
2373
diff
changeset
|
523 input->file_name = g_path_get_basename(filename); |
|
e2aaa7dca389
[svn] - tuple->file_name coming from input plugins have a string with filename + extension, but tuple->file_name coming from input plugins without a get_song_tuple have a string with filename without extension; fix this incongruency, always pass tuple->filename with a string containing filename + extension
giacomo
parents:
2373
diff
changeset
|
524 input->file_ext = ( ( ext != NULL ) ? g_strdup(ext + 1) : NULL ); |
|
e2aaa7dca389
[svn] - tuple->file_name coming from input plugins have a string with filename + extension, but tuple->file_name coming from input plugins without a get_song_tuple have a string with filename without extension; fix this incongruency, always pass tuple->filename with a string containing filename + extension
giacomo
parents:
2373
diff
changeset
|
525 input->file_path = g_path_get_dirname(filename); |
| 2313 | 526 } |
| 527 | |
| 2569 | 528 g_free(filename_proxy); |
| 2313 | 529 return input; |
| 530 } | |
| 531 | |
| 532 static void | |
| 533 input_general_file_info_box(const gchar * filename, InputPlugin * ip) | |
| 534 { | |
| 535 GtkWidget *window, *vbox; | |
| 536 GtkWidget *label, *filename_hbox, *filename_entry; | |
| 537 GtkWidget *bbox, *cancel; | |
| 538 | |
| 539 gchar *title, *fileinfo, *basename, *iplugin; | |
| 540 gchar *filename_utf8; | |
|
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
541 gchar *realfn = NULL; |
| 2313 | 542 |
| 543 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 544 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
| 545 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | |
| 546 | |
|
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
547 realfn = g_filename_from_uri(filename, NULL, NULL); |
|
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
548 basename = g_path_get_basename(realfn ? realfn : filename); |
| 2313 | 549 fileinfo = filename_to_utf8(basename); |
| 550 title = g_strdup_printf(_("audacious: %s"), fileinfo); | |
| 551 | |
| 552 gtk_window_set_title(GTK_WINDOW(window), title); | |
| 553 | |
| 554 g_free(title); | |
| 555 g_free(fileinfo); | |
| 556 g_free(basename); | |
| 557 | |
| 558 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
| 559 | |
| 560 vbox = gtk_vbox_new(FALSE, 10); | |
| 561 gtk_container_add(GTK_CONTAINER(window), vbox); | |
| 562 | |
| 563 filename_hbox = gtk_hbox_new(FALSE, 5); | |
| 564 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
| 565 | |
| 566 label = gtk_label_new(_("Filename:")); | |
| 567 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
| 568 | |
| 569 filename_entry = gtk_entry_new(); | |
|
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
570 filename_utf8 = filename_to_utf8(realfn ? realfn : filename); |
|
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
571 g_free(realfn); realfn = NULL; |
| 2313 | 572 |
| 573 gtk_entry_set_text(GTK_ENTRY(filename_entry), filename_utf8); | |
| 574 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
| 575 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
| 576 | |
| 577 g_free(filename_utf8); | |
| 578 | |
| 579 if (ip) | |
| 580 if (ip->description) | |
| 581 iplugin = ip->description; | |
| 582 else | |
| 583 iplugin = ip->filename; | |
| 584 else | |
| 585 iplugin = _("No input plugin recognized this file"); | |
| 586 | |
| 587 title = g_strdup_printf(_("Input plugin: %s"), iplugin); | |
| 588 | |
| 589 label = gtk_label_new(title); | |
| 590 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 591 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
| 592 g_free(title); | |
| 593 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
| 594 | |
| 595 bbox = gtk_hbutton_box_new(); | |
| 596 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 597 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 598 | |
| 599 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 600 g_signal_connect_swapped(G_OBJECT(cancel), "clicked", | |
| 601 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
| 602 GTK_OBJECT(window)); | |
| 603 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
| 604 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
| 605 | |
| 606 gtk_widget_show_all(window); | |
| 607 } | |
| 608 | |
| 609 void | |
| 610 input_file_info_box(const gchar * filename) | |
| 611 { | |
| 612 InputPlugin *ip; | |
| 613 gchar *filename_proxy; | |
| 614 | |
| 615 filename_proxy = g_strdup(filename); | |
| 616 | |
| 617 ip = input_check_file(filename_proxy, FALSE); | |
| 618 | |
| 619 if (ip->file_info_box) | |
| 620 ip->file_info_box(filename_proxy); | |
| 621 else | |
| 622 input_general_file_info_box(filename, ip); | |
| 623 | |
| 624 input_general_file_info_box(filename, NULL); | |
| 625 g_free(filename_proxy); | |
| 626 } | |
| 627 | |
| 628 GList * | |
| 629 input_scan_dir(const gchar * path) | |
| 630 { | |
| 631 GList *node, *result = NULL; | |
| 632 InputPlugin *ip; | |
| 633 gchar *path_proxy; | |
| 634 | |
| 635 g_return_val_if_fail(path != NULL, NULL); | |
| 636 | |
| 637 if (*path == '/') | |
| 638 while (path[1] == '/') | |
| 639 path++; | |
| 640 | |
| 641 path_proxy = g_strdup(path); | |
| 642 | |
| 643 for (node = get_input_list(); node; node = g_list_next(node)) { | |
| 644 ip = INPUT_PLUGIN(node->data); | |
| 645 | |
| 646 if (!ip) | |
| 647 continue; | |
| 648 | |
| 649 if (!ip->scan_dir) | |
| 650 continue; | |
| 651 | |
| 652 if (!input_is_enabled(ip->filename)) | |
| 653 continue; | |
| 654 | |
| 655 if ((result = ip->scan_dir(path_proxy))) | |
| 656 break; | |
| 657 } | |
| 658 | |
| 659 g_free(path_proxy); | |
| 660 | |
| 661 return result; | |
| 662 } | |
| 663 | |
| 664 void | |
| 665 input_get_volume(gint * l, gint * r) | |
| 666 { | |
| 667 *l = -1; | |
| 668 *r = -1; | |
| 669 if (playback_get_playing()) { | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
670 if (get_current_input_playback() && |
|
2439
f2b3d6428b67
[svn] Allow input plugin that implements get_volume to punt to the output plugin.
iabervon
parents:
2437
diff
changeset
|
671 get_current_input_playback()->plugin->get_volume && |
|
f2b3d6428b67
[svn] Allow input plugin that implements get_volume to punt to the output plugin.
iabervon
parents:
2437
diff
changeset
|
672 get_current_input_playback()->plugin->get_volume(l, r)) { |
| 2313 | 673 return; |
| 674 } | |
| 675 } | |
| 676 output_get_volume(l, r); | |
| 677 } | |
| 678 | |
| 679 void | |
| 680 input_set_volume(gint l, gint r) | |
| 681 { | |
| 2505 | 682 gint h_vol[2]; |
| 683 | |
| 2569 | 684 if (playback_get_playing() && |
| 685 get_current_input_playback() && | |
| 686 get_current_input_playback()->plugin->set_volume && | |
| 687 get_current_input_playback()->plugin->set_volume(l, r)) | |
| 688 return; | |
| 689 | |
| 2313 | 690 output_set_volume(l, r); |
| 2505 | 691 |
| 692 h_vol[0] = l; | |
| 693 h_vol[1] = r; | |
| 694 hook_call("volume set", h_vol); | |
| 2313 | 695 } |
| 696 | |
| 697 void | |
| 698 input_update_vis(gint time) | |
| 699 { | |
| 700 GList *node; | |
| 701 VisNode *vis = NULL, *visnext = NULL; | |
| 702 gboolean found = FALSE; | |
| 703 | |
| 704 G_LOCK(vis_mutex); | |
| 705 node = vis_list; | |
| 706 while (g_list_next(node) && !found) { | |
| 707 visnext = g_list_next(node)->data; | |
| 708 vis = node->data; | |
| 709 | |
| 710 if (vis->time >= time) | |
| 711 break; | |
| 712 | |
| 713 vis_list = g_list_delete_link(vis_list, node); | |
| 714 | |
| 715 if (visnext->time >= time) { | |
| 716 found = TRUE; | |
| 717 break; | |
| 718 } | |
| 719 g_free(vis); | |
| 720 node = vis_list; | |
| 721 } | |
| 722 G_UNLOCK(vis_mutex); | |
| 723 | |
| 724 if (found) { | |
| 725 vis_send_data(vis->data, vis->nch, vis->length); | |
| 726 g_free(vis); | |
| 727 } | |
| 728 else | |
| 729 vis_send_data(NULL, 0, 0); | |
| 730 } | |
| 731 | |
| 732 | |
| 733 gchar * | |
| 734 input_get_info_text(void) | |
| 735 { | |
| 736 return g_strdup(input_info_text); | |
| 737 } | |
| 738 | |
| 739 void | |
| 740 input_set_info_text(const gchar * text) | |
| 741 { | |
| 742 g_free(input_info_text); | |
| 743 input_info_text = g_strdup(text); | |
| 744 mainwin_set_info_text(); | |
| 745 } | |
| 746 | |
| 747 void | |
| 748 input_set_status_buffering(gboolean status) | |
| 749 { | |
| 750 if (!playback_get_playing()) | |
| 751 return; | |
| 752 | |
|
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
753 if (!get_current_input_playback()) |
| 2313 | 754 return; |
| 755 | |
| 756 ip_data.buffering = status; | |
| 757 | |
| 758 g_return_if_fail(mainwin_playstatus != NULL); | |
| 759 | |
|
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
760 if (ip_data.buffering == TRUE && mainwin_playstatus != NULL && UI_SKINNED_PLAYSTATUS(mainwin_playstatus)->status == STATUS_STOP) |
|
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
761 UI_SKINNED_PLAYSTATUS(mainwin_playstatus)->status = STATUS_PLAY; |
| 2313 | 762 |
|
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
763 ui_skinned_playstatus_set_buffering(mainwin_playstatus, ip_data.buffering); |
| 2313 | 764 } |
| 765 | |
| 766 void | |
| 767 input_about(gint index) | |
| 768 { | |
| 769 InputPlugin *ip; | |
| 770 | |
| 771 ip = g_list_nth(ip_data.input_list, index)->data; | |
| 772 if (ip && ip->about) | |
| 773 ip->about(); | |
| 774 } | |
| 775 | |
| 776 void | |
| 777 input_configure(gint index) | |
| 778 { | |
| 779 InputPlugin *ip; | |
| 780 | |
| 781 ip = g_list_nth(ip_data.input_list, index)->data; | |
| 782 if (ip && ip->configure) | |
| 783 ip->configure(); | |
| 784 } |
