comparison src/madplug/plugin.c @ 768:1d3f70ac6b31 trunk

[svn] - remote metadata handling is moved into input_process_remote_metadata(). this function converts string into utf-8 if necessary (mainly for zina). - revise seekable determination logic. duration may be negative value (zina..). - if remote url is passed, scan_file() will use fast scan method irrespective of preference value. - scattered http:// matching codes are aggregate into audmad_is_remote(). - some cleanups.
author yaz
date Fri, 02 Mar 2007 00:14:11 -0800
parents 2430c9773fa7
children 22c82f3c0411
comparison
equal deleted inserted replaced
767:96b884703411 768:1d3f70ac6b31
204 return ((unsigned long) hbuf[0] << 24) | 204 return ((unsigned long) hbuf[0] << 24) |
205 ((unsigned long) hbuf[1] << 16) | 205 ((unsigned long) hbuf[1] << 16) |
206 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3]; 206 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3];
207 } 207 }
208 208
209 gboolean audmad_is_remote(gchar *url)
210 {
211 if (!strncasecmp("http://", url, 7) || !strncasecmp("https://", url, 8))
212 return TRUE;
213 else
214 return FALSE;
215 }
209 216
210 // audacious vfs fast version 217 // audacious vfs fast version
211 static int audmad_is_our_fd(char *filename, VFSFile *fin) 218 static int audmad_is_our_fd(char *filename, VFSFile *fin)
212 { 219 {
213 guint32 check; 220 guint32 check;
217 guchar tmp[4096]; 224 guchar tmp[4096];
218 gint ret, i; 225 gint ret, i;
219 226
220 info.remote = FALSE; 227 info.remote = FALSE;
221 228
222 #if 1 229 if(audmad_is_remote(filename))
223 // XXX: temporary fix
224 if (!strncasecmp("http://", filename, 7) || !strncasecmp("https://", filename, 8))
225 {
226 #ifdef DEBUG
227 g_message("audmad_is_our_fd: remote");
228 #endif
229 info.remote = TRUE; 230 info.remote = TRUE;
230 }
231 #endif
232 231
233 /* I've seen some flac files beginning with id3 frames.. 232 /* I've seen some flac files beginning with id3 frames..
234 so let's exclude known non-mp3 filename extensions */ 233 so let's exclude known non-mp3 filename extensions */
235 if ((ext != NULL) && 234 if ((ext != NULL) &&
236 (!strcasecmp("flac", ext) || !strcasecmp("mpc", ext) || 235 (!strcasecmp("flac", ext) || !strcasecmp("mpc", ext) ||
340 if (input_init(&info, url) == FALSE) { 339 if (input_init(&info, url) == FALSE) {
341 g_message("error initialising input"); 340 g_message("error initialising input");
342 return; 341 return;
343 } 342 }
344 343
345 rtn = input_get_info(&info, audmad_config.fast_play_time_calc); 344 // remote access must use fast scan.
345 rtn = input_get_info(&info, audmad_is_remote(url) ? TRUE : audmad_config.fast_play_time_calc);
346 346
347 if (rtn == FALSE) { 347 if (rtn == FALSE) {
348 g_message("error reading input info"); 348 g_message("error reading input info");
349 return; 349 return;
350 } 350 }
390 return; 390 return;
391 } 391 }
392 392
393 // don't try to get from stopped stream. 393 // don't try to get from stopped stream.
394 if(myinfo.remote && (!myinfo.playback || !myinfo.playback->playing)){ 394 if(myinfo.remote && (!myinfo.playback || !myinfo.playback->playing)){
395 g_print("get_song_info: remote!\n"); 395 #ifdef DEBUG
396 g_message("get_song_info: remote and not playing.");
397 #endif
396 return; 398 return;
397 } 399 }
398 400
399 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { 401 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
400 if(myinfo.tuple->track_name) 402 if(myinfo.tuple->track_name)
494 g_message("f: mad: audmad_get_song_tuple: %s", string); 496 g_message("f: mad: audmad_get_song_tuple: %s", string);
495 g_free(string); 497 g_free(string);
496 string = NULL; 498 string = NULL;
497 #endif 499 #endif
498 500
499 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) == 0){ 501 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){
500 if(info.playback && info.playback->playing) { 502 if(info.playback && info.playback->playing) {
503 gchar *tmp = NULL;
501 tuple = bmp_title_input_new(); 504 tuple = bmp_title_input_new();
502 #ifdef DEBUG 505 #ifdef DEBUG
503 printf("info.playback->playing = %d\n",info.playback->playing); 506 g_message("info.playback->playing = %d",info.playback->playing);
504 #endif 507 #endif
505 tuple->track_name = vfs_get_metadata(info.infile, "track-name"); 508 tmp = vfs_get_metadata(info.infile, "track-name");
506 tuple->album_name = vfs_get_metadata(info.infile, "stream-name"); 509 if(tmp){
507 #ifdef DEBUG 510 tuple->track_name = str_to_utf8(tmp);
508 printf("audmad_get_song_tuple: track_name = %s\n", tuple->track_name); 511 g_free(tmp);
509 printf("audmad_get_song_tuple: stream_name = %s\n", tuple->album_name); 512 tmp = NULL;
513 }
514 tmp = vfs_get_metadata(info.infile, "stream-name");
515 if(tmp){
516 tuple->album_name = str_to_utf8(tmp);
517 g_free(tmp);
518 tmp = NULL;
519 }
520 #ifdef DEBUG
521 g_message("audmad_get_song_tuple: track_name = %s", tuple->track_name);
522 g_message("audmad_get_song_tuple: stream_name = %s", tuple->album_name);
510 #endif 523 #endif
511 tuple->file_name = g_path_get_basename(filename); 524 tuple->file_name = g_path_get_basename(filename);
512 tuple->file_path = g_path_get_dirname(filename); 525 tuple->file_path = g_path_get_dirname(filename);
513 tuple->file_ext = extname(filename); 526 tuple->file_ext = extname(filename);
514 tuple->length = -1; 527 tuple->length = -1;
515 tuple->mtime = 0; // this indicates streaming 528 tuple->mtime = 0; // this indicates streaming
516 #ifdef DEBUG 529 #ifdef DEBUG
517 printf("get_song_tuple remote: tuple\n"); 530 g_message("get_song_tuple remote: tuple");
518 #endif 531 #endif
519 return tuple; 532 return tuple;
520 } 533 }
521 #ifdef DEBUG 534 #ifdef DEBUG
522 printf("get_song_tuple: remote: NULL\n"); 535 g_message("get_song_tuple: remote: NULL");
523 #endif 536 #endif
524 return NULL; 537 return NULL;
525 } 538 }
526 539
527 if ((file = vfs_fopen(filename, "rb")) != NULL) { 540 if ((file = vfs_fopen(filename, "rb")) != NULL) {
560 tuple->length = -1; 573 tuple->length = -1;
561 string = input_id3_get_string(tag, "TLEN"); 574 string = input_id3_get_string(tag, "TLEN");
562 if (string) { 575 if (string) {
563 tuple->length = atoi(string); 576 tuple->length = atoi(string);
564 #ifdef DEBUG 577 #ifdef DEBUG
565 printf("get_song_tuple: TLEN = %d\n", tuple->length); 578 g_message("get_song_tuple: TLEN = %d", tuple->length);
566 #endif 579 #endif
567 g_free(string); 580 g_free(string);
568 string = NULL; 581 string = NULL;
569 } 582 }
570 else { 583 else {
616 #endif 629 #endif
617 return tuple; 630 return tuple;
618 631
619 } 632 }
620 633
621 634 // probably this function is nolonger needed.
635 #if 0
622 /** 636 /**
623 * Retrieve meta-information about URL. 637 * Retrieve meta-information about URL.
624 * For local files this means ID3 tag etc. 638 * For local files this means ID3 tag etc.
625 */ 639 */
626 gboolean mad_get_info(struct mad_info_t * info, gboolean fast_scan) 640 gboolean mad_get_info(struct mad_info_t * info, gboolean fast_scan)
660 #ifdef DEBUG 674 #ifdef DEBUG
661 g_message("e: mad_get_info"); 675 g_message("e: mad_get_info");
662 #endif 676 #endif
663 return TRUE; 677 return TRUE;
664 } 678 }
679 #endif
680
665 681
666 static gchar *fmts[] = { "mp3", "mp2", "mpg", NULL }; 682 static gchar *fmts[] = { "mp3", "mp2", "mpg", NULL };
667 683
668 InputPlugin *get_iplugin_info(void) 684 InputPlugin *get_iplugin_info(void)
669 { 685 {