comparison src/audacious/input.c @ 4029:76da6fe8cb39

- Branch merge
author Ralf Ertzinger <ralf@skytale.net>
date Wed, 28 Nov 2007 16:55:02 +0100
parents bb709f82068b 67f01143e613
children 9e24c8746d99 1198b6911ca4
comparison
equal deleted inserted replaced
4028:bb709f82068b 4029:76da6fe8cb39
74 FALSE, 74 FALSE,
75 NULL 75 NULL
76 }; 76 };
77 77
78 static GList *vis_list = NULL; 78 static GList *vis_list = NULL;
79 static int volume_l = -1, volume_r = -1;
79 80
80 InputPlayback * 81 InputPlayback *
81 get_current_input_playback(void) 82 get_current_input_playback(void)
82 { 83 {
83 return ip_data.current_input_playback; 84 return ip_data.current_input_playback;
304 } else { 305 } else {
305 return 0; //error 306 return 0; //error
306 } 307 }
307 } 308 }
308 309
310
311 /* do actual probing. this function is called from input_check_file() */
312 static ProbeResult *
313 input_do_check_file(InputPlugin *ip, VFSFile *fd, gchar *filename_proxy, gboolean loading)
314 {
315 ProbeResult *pr = NULL;
316 gint result = 0;
317
318 g_return_val_if_fail(fd != NULL, NULL);
319
320 vfs_rewind(fd);
321
322 /* some input plugins provide probe_for_tuple() only. */
323 if ( (ip->probe_for_tuple && !ip->is_our_file_from_vfs && !ip->is_our_file) ||
324 (ip->probe_for_tuple && ip->have_subtune == TRUE) ||
325 (ip->probe_for_tuple && (cfg.use_pl_metadata && (!loading || (loading && cfg.get_info_on_load)))) ) {
326
327 Tuple *tuple = ip->probe_for_tuple(filename_proxy, fd);
328
329 if (tuple != NULL) {
330 pr = g_new0(ProbeResult, 1);
331 pr->ip = ip;
332 pr->tuple = tuple;
333 tuple_associate_int(pr->tuple, FIELD_MTIME, NULL, input_get_mtime(filename_proxy));
334
335 return pr;
336 }
337 }
338
339 else if (ip->is_our_file_from_vfs != NULL) {
340 result = ip->is_our_file_from_vfs(filename_proxy, fd);
341
342 if (result > 0) {
343 pr = g_new0(ProbeResult, 1);
344 pr->ip = ip;
345
346 return pr;
347 }
348 }
349
350 else if (ip->is_our_file != NULL) {
351 result = ip->is_our_file(filename_proxy);
352
353 if (result > 0) {
354 pr = g_new0(ProbeResult, 1);
355 pr->ip = ip;
356
357 return pr;
358 }
359 }
360
361 return NULL;
362 }
363
364
309 /* 365 /*
310 * input_check_file() 366 * input_check_file()
311 * 367 *
312 * Inputs: 368 * Inputs:
313 * filename to check recursively against input plugins 369 * filename to check recursively against input plugins
339 * --nenolod, Jul 9 2007 395 * --nenolod, Jul 9 2007
340 * 396 *
341 * Adapted to return ProbeResult structure. 397 * Adapted to return ProbeResult structure.
342 * 398 *
343 * --nenolod, Jul 20 2007 399 * --nenolod, Jul 20 2007
400 *
401 * Make use of ext_hash to avoid full scan in input list.
402 *
403 * --yaz, Nov 16 2007
344 */ 404 */
405
406 /* if loading is TRUE, tuple probing can be skipped as regards configuration. */
345 ProbeResult * 407 ProbeResult *
346 input_check_file(const gchar * filename, gboolean show_warning) 408 input_check_file(const gchar *filename, gboolean loading)
347 { 409 {
348 VFSFile *fd; 410 VFSFile *fd;
349 GList *node; 411 GList *node;
350 InputPlugin *ip; 412 InputPlugin *ip;
351 gchar *filename_proxy; 413 gchar *filename_proxy;
352 gint ret = 1; 414 gint ret = 1;
353 gchar *ext, *tmp, *tmp_uri; 415 gchar *ext, *tmp, *tmp_uri;
354 gboolean use_ext_filter; 416 gboolean use_ext_filter = FALSE;
355 gchar *mimetype; 417 gchar *mimetype;
356 ProbeResult *pr = NULL; 418 ProbeResult *pr = NULL;
357 419 GList **list_hdr = NULL;
358 filename_proxy = g_strdup(filename); 420 extern GHashTable *ext_hash;
359 421
360 /* Some URIs will end in ?<subsong> to determine the subsong requested. */ 422 /* Some URIs will end in ?<subsong> to determine the subsong requested. */
361 tmp_uri = g_strdup(filename); 423 tmp_uri = g_strdup(filename);
362
363 tmp = strrchr(tmp_uri, '?'); 424 tmp = strrchr(tmp_uri, '?');
364 425
365 if (tmp != NULL && g_ascii_isdigit(*(tmp + 1))) 426 if (tmp && g_ascii_isdigit(*(tmp + 1)))
366 *tmp = '\0'; 427 *tmp = '\0';
428
429 filename_proxy = g_strdup(tmp_uri);
430 g_free(tmp_uri);
367 431
368 /* Check for plugins with custom URI:// strings */ 432 /* Check for plugins with custom URI:// strings */
369 /* cue:// cdda:// tone:// tact:// */ 433 /* cue:// cdda:// tone:// tact:// */
370 if ((ip = uri_get_plugin(filename)) != NULL && ip->enabled) 434 if ((ip = uri_get_plugin(filename_proxy)) != NULL && ip->enabled) {
371 {
372 printf("Offering '%s' to %s, based on special URL scheme\n", filename, ip->description);
373 if (ip->is_our_file != NULL) 435 if (ip->is_our_file != NULL)
374 ret = ip->is_our_file(filename_proxy); 436 ret = ip->is_our_file(filename_proxy);
375 else 437 else
376 ret = 0; 438 ret = 0;
377 if (ret > 0) 439 if (ret > 0) {
378 {
379 g_free(filename_proxy); 440 g_free(filename_proxy);
380 pr = g_new0(ProbeResult, 1); 441 pr = g_new0(ProbeResult, 1);
381 pr->ip = ip; 442 pr->ip = ip;
382 return pr; 443 return pr;
383 } 444 }
384 g_free(filename_proxy); 445 g_free(filename_proxy);
385 return NULL; 446 return NULL;
386 } 447 }
387 448
388 fd = vfs_buffered_file_new_from_uri(tmp_uri); 449
389 g_free(tmp_uri); 450 // open the file with vfs sub-system
451 fd = vfs_buffered_file_new_from_uri(filename_proxy);
390 452
391 if (!fd) { 453 if (!fd) {
392 printf("Unable to read from %s, giving up.\n", filename_proxy); 454 printf("Unable to read from %s, giving up.\n", filename_proxy);
393 g_free(filename_proxy); 455 g_free(filename_proxy);
394 return NULL; 456 return NULL;
395 } 457 }
396 458
397 ext = strrchr(filename_proxy, '.') + 1; 459
398 460 // apply mimetype check. note that stdio does not support mimetype check.
399 use_ext_filter =
400 (fd != NULL && (!g_strncasecmp(filename, "/", 1) ||
401 !g_strncasecmp(filename, "file://", 7))) ? TRUE : FALSE;
402
403 mimetype = vfs_get_metadata(fd, "content-type"); 461 mimetype = vfs_get_metadata(fd, "content-type");
404 if ((ip = mime_get_plugin(mimetype)) != NULL && ip->enabled) 462 if ((ip = mime_get_plugin(mimetype)) != NULL && ip->enabled) {
405 { 463 while(1) {
406 printf("Offering '%s' to %s, based on mime-type\n", filename, ip->description); 464 if (!ip || !ip->enabled)
407 if (ip->probe_for_tuple != NULL) 465 continue;
408 { 466
409 Tuple *tuple = ip->probe_for_tuple(filename_proxy, fd); 467 pr = input_do_check_file(ip, fd, filename_proxy, loading);
410 468
411 if (tuple != NULL) 469 if(pr) {
412 {
413 g_free(filename_proxy); 470 g_free(filename_proxy);
414 vfs_fclose(fd); 471 vfs_fclose(fd);
415
416 pr = g_new0(ProbeResult, 1);
417 pr->ip = ip;
418 pr->tuple = tuple;
419 tuple_associate_int(pr->tuple, FIELD_MTIME, NULL, input_get_mtime(filename_proxy));
420
421 return pr; 472 return pr;
422 } 473 }
423 } 474 }
424 else if (fd && ip->is_our_file_from_vfs != NULL) 475 }
425 { 476
426 ret = ip->is_our_file_from_vfs(filename_proxy, fd); 477
427 478 // apply ext_hash check
428 if (ret > 0) 479 if(cfg.use_extension_probing) {
429 { 480 use_ext_filter =
430 g_free(filename_proxy); 481 (fd && (!g_strncasecmp(filename_proxy, "/", 1) ||
431 vfs_fclose(fd); 482 !g_strncasecmp(filename_proxy, "file://", 7))) ? TRUE : FALSE;
432 483 }
433 pr = g_new0(ProbeResult, 1); 484
434 pr->ip = ip; 485 if(use_ext_filter) {
435 486 gchar *base, *lext;
436 return pr; 487 gchar *tmp2 = g_filename_from_uri(filename_proxy, NULL, NULL);
437 } 488 gchar *realfn = g_strdup(tmp2 ? tmp2 : filename_proxy);
489 g_free(tmp2);
490
491 base = g_path_get_basename(realfn);
492 g_free(realfn);
493 ext = strrchr(base, '.');
494
495 if(ext) {
496 lext = g_ascii_strdown(ext+1, -1);
497 list_hdr = g_hash_table_lookup(ext_hash, lext);
498 g_free(lext);
438 } 499 }
439 else if (ip->is_our_file != NULL) 500 g_free(base);
440 { 501
441 ret = ip->is_our_file(filename_proxy); 502 if(list_hdr) {
442 503 for(node = *list_hdr; node != NULL; node = g_list_next(node)) {
443 if (ret > 0) 504 ip = INPUT_PLUGIN(node->data);
444 { 505
445 g_free(filename_proxy); 506 if (!ip || !ip->enabled)
446 vfs_fclose(fd); 507 continue;
447 508
448 pr = g_new0(ProbeResult, 1); 509 pr = input_do_check_file(ip, fd, filename_proxy, loading);
449 pr->ip = ip; 510
450 511 if(pr) {
451 return pr; 512 g_free(filename_proxy);
513 vfs_fclose(fd);
514 return pr;
515 }
452 } 516 }
453 } 517 }
454 } 518
455 519 return NULL; // no plugin found.
456 for (node = get_input_list(); node != NULL; node = g_list_next(node)) 520 }
457 { 521
522
523 // do full scan when extension match isn't specified.
524 for (node = get_input_list(); node != NULL; node = g_list_next(node)) {
458 ip = INPUT_PLUGIN(node->data); 525 ip = INPUT_PLUGIN(node->data);
459 526
460 if (!ip || !ip->enabled) 527 if (!ip || !ip->enabled)
461 continue; 528 continue;
462 529
463 printf("Offering '%s' to %s\n", filename, ip->description); 530 pr = input_do_check_file(ip, fd, filename_proxy, loading);
464 531
465 vfs_rewind(fd); 532 if(pr) {
466 533 g_free(filename_proxy);
467 if (cfg.use_extension_probing == TRUE && ip->vfs_extensions != NULL && 534 vfs_fclose(fd);
468 ext != NULL && ext != (gpointer) 0x1 && use_ext_filter == TRUE) 535 return pr;
469 {
470 gint i;
471 gboolean is_our_ext = FALSE;
472
473 for (i = 0; ip->vfs_extensions[i] != NULL; i++)
474 {
475 if (str_has_prefix_nocase(ext, ip->vfs_extensions[i]))
476 {
477 is_our_ext = TRUE;
478 break;
479 }
480 }
481
482 /* not a plugin that supports this extension */
483 if (is_our_ext == FALSE)
484 continue;
485 } 536 }
486 537 }
487 if (fd && ip->probe_for_tuple != NULL) 538
488 { 539
489 Tuple *tuple = ip->probe_for_tuple(filename_proxy, fd); 540 // all probing failed. return NULL
490
491 if (tuple != NULL)
492 {
493 g_free(filename_proxy);
494 vfs_fclose(fd);
495
496 pr = g_new0(ProbeResult, 1);
497 pr->ip = ip;
498 pr->tuple = tuple;
499 tuple_associate_int(pr->tuple, FIELD_MTIME, NULL, input_get_mtime(filename_proxy));
500
501 return pr;
502 }
503 }
504 else if (fd && ip->is_our_file_from_vfs != NULL)
505 {
506 ret = ip->is_our_file_from_vfs(filename_proxy, fd);
507
508 if (ret > 0)
509 {
510 g_free(filename_proxy);
511 vfs_fclose(fd);
512
513 pr = g_new0(ProbeResult, 1);
514 pr->ip = ip;
515
516 return pr;
517 }
518 }
519 else if (ip->is_our_file != NULL)
520 {
521 ret = ip->is_our_file(filename_proxy);
522
523 if (ret > 0)
524 {
525 g_free(filename_proxy);
526 vfs_fclose(fd);
527
528 pr = g_new0(ProbeResult, 1);
529 pr->ip = ip;
530
531 return pr;
532 }
533 }
534
535 if (ret <= -1)
536 break;
537 }
538
539 g_free(filename_proxy); 541 g_free(filename_proxy);
540
541 vfs_fclose(fd); 542 vfs_fclose(fd);
542
543 return NULL; 543 return NULL;
544 } 544 }
545 545
546 546
547 void 547 void
751 } 751 }
752 752
753 void 753 void
754 input_get_volume(gint * l, gint * r) 754 input_get_volume(gint * l, gint * r)
755 { 755 {
756 InputPlayback *playback; 756 if (volume_l == -1 || volume_r == -1)
757 757 output_get_volume(&volume_l, &volume_r);
758 *l = -1; 758
759 *r = -1; 759 *l = volume_l;
760 if (playback_get_playing()) { 760 *r = volume_r;
761 if ((playback = get_current_input_playback()) != NULL &&
762 playback->plugin->get_volume &&
763 playback->plugin->get_volume(l, r))
764 return;
765 }
766 output_get_volume(l, r);
767 } 761 }
768 762
769 void 763 void
770 input_set_volume(gint l, gint r) 764 input_set_volume(gint l, gint r)
771 { 765 {
782 playback->plugin->set_volume && 776 playback->plugin->set_volume &&
783 playback->plugin->set_volume(l, r)) 777 playback->plugin->set_volume(l, r))
784 return; 778 return;
785 779
786 output_set_volume(l, r); 780 output_set_volume(l, r);
781
782 volume_l = l;
783 volume_r = r;
787 } 784 }
788 785
789 void 786 void
790 input_update_vis(gint time) 787 input_update_vis(gint time)
791 { 788 {