Mercurial > audlegacy-plugins
comparison src/madplug/input.c @ 773:22c82f3c0411 trunk
[svn] - reduce connection latency to http stream.
- remove unnecessary functions.
- remove redundant dialog which had been shown when madplug failed to open audio output.
- some cleanups.
author | yaz |
---|---|
date | Fri, 02 Mar 2007 20:28:55 -0800 |
parents | 1d3f70ac6b31 |
children | a24cc8848b9a |
comparison
equal
deleted
inserted
replaced
772:18dd1dd2d232 | 773:22c82f3c0411 |
---|---|
64 #define HEADER_SIZE 256 | 64 #define HEADER_SIZE 256 |
65 #define LINE_LENGTH 256 | 65 #define LINE_LENGTH 256 |
66 | 66 |
67 extern gboolean scan_file(struct mad_info_t *info, gboolean fast); | 67 extern gboolean scan_file(struct mad_info_t *info, gboolean fast); |
68 | 68 |
69 // new VFS handles url. | |
70 static void input_parse_url(struct mad_info_t *info) | |
71 { | |
72 info->filename = g_strdup(info->url); | |
73 return; | |
74 } | |
75 | |
76 | |
77 /** | 69 /** |
78 * init the mad_info_t struct. | 70 * init the mad_info_t struct. |
79 */ | 71 */ |
80 gboolean input_init(struct mad_info_t * info, const char *url) | 72 gboolean input_init(struct mad_info_t * info, const char *url) |
81 { | 73 { |
106 info->replaygain_album_peak_str = 0; | 98 info->replaygain_album_peak_str = 0; |
107 info->replaygain_track_peak_str = 0; | 99 info->replaygain_track_peak_str = 0; |
108 info->mp3gain_undo_str = 0; | 100 info->mp3gain_undo_str = 0; |
109 info->mp3gain_minmax_str = 0; | 101 info->mp3gain_minmax_str = 0; |
110 | 102 |
103 // from input_read_replaygain() | |
104 info->has_replaygain = FALSE; | |
105 info->replaygain_album_scale = -1; | |
106 info->replaygain_track_scale = -1; | |
107 info->mp3gain_undo = -77; | |
108 info->mp3gain_minmax = -77; | |
109 | |
111 info->tuple = NULL; | 110 info->tuple = NULL; |
112 | 111 |
113 input_parse_url(info); | 112 info->filename = g_strdup(url); |
114 | 113 |
115 info->infile = vfs_fopen(info->filename, "rb"); | 114 info->infile = vfs_fopen(info->filename, "rb"); |
116 if (info->infile == NULL) { | 115 if (info->infile == NULL) { |
117 return FALSE; | 116 return FALSE; |
118 } | 117 } |
330 g_print("i: string = %s\n", rtn); | 329 g_print("i: string = %s\n", rtn); |
331 #endif | 330 #endif |
332 return rtn; | 331 return rtn; |
333 } | 332 } |
334 | 333 |
334 | |
335 static void input_alloc_tag(struct mad_info_t *info) | |
336 { | |
337 TitleInput *title_input; | |
338 | |
339 if (info->tuple == NULL) { | |
340 title_input = bmp_title_input_new(); | |
341 info->tuple = title_input; | |
342 info->tuple->length = -1; //will be refferd in decoder.c | |
343 } | |
344 else | |
345 title_input = info->tuple; | |
346 } | |
347 | |
335 /** | 348 /** |
336 * read the ID3 tag | 349 * read the ID3 tag |
337 */ | 350 */ |
338 static void input_read_tag(struct mad_info_t *info) | 351 static void input_read_tag(struct mad_info_t *info) |
339 { | 352 { |
348 info->tuple = title_input; | 361 info->tuple = title_input; |
349 } | 362 } |
350 else | 363 else |
351 title_input = info->tuple; | 364 title_input = info->tuple; |
352 | 365 |
353 if(info->infile) | 366 #define REUSE_FD 1 |
354 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); | 367 #if REUSE_FD |
368 if(info->infile) { | |
369 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); | |
370 } | |
355 else | 371 else |
372 #endif | |
356 info->id3file = id3_file_open(info->filename, ID3_FILE_MODE_READONLY); | 373 info->id3file = id3_file_open(info->filename, ID3_FILE_MODE_READONLY); |
374 | |
357 if (!info->id3file) { | 375 if (!info->id3file) { |
376 #ifdef DEBUG | |
377 g_message("read_tag: no id3file"); | |
378 #endif | |
358 return; | 379 return; |
359 } | 380 } |
360 | 381 |
361 info->tag = id3_file_tag(info->id3file); | 382 info->tag = id3_file_tag(info->id3file); |
362 if (!info->tag) { | 383 if (!info->tag) { |
384 #ifdef DEBUG | |
385 g_message("read_tag: no tag"); | |
386 #endif | |
363 return; | 387 return; |
364 } | 388 } |
365 | 389 |
366 title_input->performer = | 390 title_input->performer = |
367 input_id3_get_string(info->tag, ID3_FRAME_ARTIST); | 391 input_id3_get_string(info->tag, ID3_FRAME_ARTIST); |
416 g_message("e: input_read_tag"); | 440 g_message("e: input_read_tag"); |
417 #endif | 441 #endif |
418 | 442 |
419 } | 443 } |
420 | 444 |
421 static void input_process_remote_metadata(struct mad_info_t *info) | 445 void input_process_remote_metadata(struct mad_info_t *info) |
422 { | 446 { |
423 if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) <= 0){ | 447 if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) <= 0){ |
424 gchar *tmp = NULL; | 448 gchar *tmp = NULL; |
425 | 449 #ifdef DEBUG |
450 #ifdef DEBUG_INTENSIVELY | |
451 g_message("process_remote_meta"); | |
452 #endif | |
453 #endif | |
426 g_free(info->title); | 454 g_free(info->title); |
427 info->title = NULL; | 455 info->title = NULL; |
428 g_free(info->tuple->track_name); | 456 g_free(info->tuple->track_name); |
429 info->tuple->track_name = NULL; | 457 info->tuple->track_name = NULL; |
430 g_free(info->tuple->album_name); | 458 g_free(info->tuple->album_name); |
448 if (info->tuple->track_name && info->tuple->album_name) | 476 if (info->tuple->track_name && info->tuple->album_name) |
449 tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name); | 477 tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name); |
450 else if (info->tuple->album_name) | 478 else if (info->tuple->album_name) |
451 tmp = g_strdup(info->tuple->album_name); | 479 tmp = g_strdup(info->tuple->album_name); |
452 else | 480 else |
453 tmp = g_strdup(""); // really? | 481 tmp = g_strdup(g_basename(info->filename)); |
454 | 482 |
455 mad_plugin->set_info(tmp, | 483 mad_plugin->set_info(tmp, |
456 -1, // indicate the stream is unseekable | 484 -1, // indicate the stream is unseekable |
457 info->bitrate, info->freq, info->channels); | 485 info->bitrate, info->freq, info->channels); |
458 g_free(tmp); | 486 g_free(tmp); |
465 * For local files this means ID3 tag etc. | 493 * For local files this means ID3 tag etc. |
466 */ | 494 */ |
467 gboolean input_get_info(struct mad_info_t *info, gboolean fast_scan) | 495 gboolean input_get_info(struct mad_info_t *info, gboolean fast_scan) |
468 { | 496 { |
469 #ifdef DEBUG | 497 #ifdef DEBUG |
470 g_message("f: input_get_info: %s, fast_scan = %s", info->title, fast_scan ? "TRUE" : "FALSE"); | 498 g_message("f: input_get_info: %s, fast_scan = %s", info->filename, fast_scan ? "TRUE" : "FALSE"); |
471 #endif /* DEBUG */ | 499 #endif /* DEBUG */ |
472 | 500 |
473 input_read_tag(info); | 501 input_alloc_tag(info); |
474 input_read_replaygain(info); | 502 |
503 if(!info->remote) { // reduce startup delay | |
504 input_read_tag(info); | |
505 read_replaygain(info); | |
506 } | |
475 | 507 |
476 /* scan mp3 file, decoding headers */ | 508 /* scan mp3 file, decoding headers */ |
477 if (scan_file(info, fast_scan) == FALSE) { | 509 if (scan_file(info, fast_scan) == FALSE) { |
510 #ifdef DEBUG | |
511 g_message("input_get_info: scan_file failed"); | |
512 #endif | |
478 return FALSE; | 513 return FALSE; |
479 } | 514 } |
480 | 515 |
481 /* reset the input file to the start */ | 516 /* reset the input file to the start */ |
482 vfs_fseek(info->infile, 0, SEEK_SET); | 517 vfs_fseek(info->infile, 0, SEEK_SET); |
483 info->offset = 0; | 518 info->offset = 0; |
484 | |
485 input_process_remote_metadata(info); | |
486 | 519 |
487 /* use the filename for the title as a last resort */ | 520 /* use the filename for the title as a last resort */ |
488 if (!info->title) { | 521 if (!info->title) { |
489 char *pos = strrchr(info->filename, DIR_SEPARATOR); | 522 char *pos = strrchr(info->filename, DIR_SEPARATOR); |
490 if (pos) | 523 if (pos) |
524 if(len == 0){ | 557 if(len == 0){ |
525 if(info->playback) | 558 if(info->playback) |
526 info->playback->eof = TRUE; | 559 info->playback->eof = TRUE; |
527 } | 560 } |
528 | 561 |
529 input_process_remote_metadata(info); | |
530 | |
531 #ifdef DEBUG | 562 #ifdef DEBUG |
532 #ifdef DEBUG_INTENSIVELY | 563 #ifdef DEBUG_INTENSIVELY |
533 g_message ("e: input_get_data: size=%d offset=%d", len, info->offset); | 564 g_message ("e: input_get_data: size=%d offset=%d", len, info->offset); |
534 #endif | 565 #endif |
535 #endif | 566 #endif |