Mercurial > audlegacy-plugins
comparison src/madplug/input.c @ 1485:4e612b01f303
- make use of tuple_formatter_make_title_string(). now madplug can show file name if metadata is not available.
- temporal fix for the bug which prevented from playing remote file.
- some cleanups.
| author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
|---|---|
| date | Mon, 13 Aug 2007 19:57:03 +0900 |
| parents | eb0913bf54c3 |
| children | d158ce84fda7 |
comparison
equal
deleted
inserted
replaced
| 1483:e8330e6bd0ba | 1485:4e612b01f303 |
|---|---|
| 72 gboolean input_init(struct mad_info_t * info, const char *url, VFSFile *fd) | 72 gboolean input_init(struct mad_info_t * info, const char *url, VFSFile *fd) |
| 73 { | 73 { |
| 74 #ifdef DEBUG | 74 #ifdef DEBUG |
| 75 g_message("f: input_init"); | 75 g_message("f: input_init"); |
| 76 #endif | 76 #endif |
| 77 memset(info, 0, sizeof(struct mad_info_t)); | 77 memset(info, 0, sizeof(struct mad_info_t)); // all fields are cleared to 0 --yaz |
| 78 | 78 |
| 79 info->fmt = FMT_S16_LE; | 79 info->fmt = FMT_S16_LE; |
| 80 info->channels = -1; | 80 info->channels = -1; |
| 81 info->mpeg_layer = -1; | 81 info->mpeg_layer = -1; |
| 82 info->size = -1; | 82 info->size = -1; |
| 83 info->freq = -1; | 83 info->freq = -1; |
| 84 info->seek = -1; | 84 info->seek = -1; |
| 85 info->duration = mad_timer_zero; | 85 info->duration = mad_timer_zero; |
| 86 info->pos = mad_timer_zero; | 86 info->pos = mad_timer_zero; |
| 87 info->url = g_strdup(url); | 87 info->url = g_strdup(url); |
| 88 info->current_frame = 0; | 88 info->filename = g_strdup(url); |
| 89 info->frames = 0; | |
| 90 info->bitrate = 0; | |
| 91 info->vbr = 0; | |
| 92 info->mode = 0; | |
| 93 info->title = 0; | |
| 94 info->offset = 0; | |
| 95 info->prev_title = NULL; | |
| 96 | |
| 97 info->replaygain_album_str = 0; | |
| 98 info->replaygain_track_str = 0; | |
| 99 info->replaygain_album_peak_str = 0; | |
| 100 info->replaygain_track_peak_str = 0; | |
| 101 info->mp3gain_undo_str = 0; | |
| 102 info->mp3gain_minmax_str = 0; | |
| 103 | 89 |
| 104 // from input_read_replaygain() | 90 // from input_read_replaygain() |
| 105 info->has_replaygain = FALSE; | |
| 106 info->replaygain_album_scale = -1; | 91 info->replaygain_album_scale = -1; |
| 107 info->replaygain_track_scale = -1; | 92 info->replaygain_track_scale = -1; |
| 108 info->mp3gain_undo = -77; | 93 info->mp3gain_undo = -77; |
| 109 info->mp3gain_minmax = -77; | 94 info->mp3gain_minmax = -77; |
| 110 | |
| 111 info->tuple = NULL; | |
| 112 | |
| 113 info->filename = g_strdup(url); | |
| 114 | 95 |
| 115 if(!fd){ | 96 if(!fd){ |
| 116 info->infile = vfs_fopen(info->filename, "rb"); | 97 info->infile = vfs_fopen(info->filename, "rb"); |
| 117 if (info->infile == NULL) { | 98 if (info->infile == NULL) { |
| 118 return FALSE; | 99 return FALSE; |
| 351 g_free(scratch); | 332 g_free(scratch); |
| 352 } | 333 } |
| 353 | 334 |
| 354 static void input_alloc_tag(struct mad_info_t *info) | 335 static void input_alloc_tag(struct mad_info_t *info) |
| 355 { | 336 { |
| 356 Tuple *title_input; | 337 Tuple *tuple; |
| 357 | 338 |
| 358 if (info->tuple == NULL) { | 339 if (info->tuple == NULL) { |
| 359 title_input = tuple_new(); | 340 tuple = tuple_new(); |
| 360 info->tuple = title_input; | 341 info->tuple = tuple; |
| 361 tuple_associate_int(info->tuple, "length", -1); | 342 tuple_associate_int(info->tuple, "length", -1); |
| 362 } | 343 } |
| 363 else | |
| 364 title_input = info->tuple; | |
| 365 } | 344 } |
| 366 | 345 |
| 367 /** | 346 /** |
| 368 * read the ID3 tag | 347 * read the ID3 tag |
| 369 */ | 348 */ |
| 370 static void input_read_tag(struct mad_info_t *info) | 349 static void input_read_tag(struct mad_info_t *info) |
| 371 { | 350 { |
| 372 gchar *string = NULL; | 351 gchar *string = NULL; |
| 373 gchar *realfn = NULL; | 352 gchar *realfn = NULL; |
| 374 Tuple *title_input; | 353 Tuple *tuple; |
| 375 glong curpos = 0; | 354 glong curpos = 0; |
| 376 | 355 |
| 377 #ifdef DEBUG | 356 #ifdef DEBUG |
| 378 g_message("f: input_read_tag"); | 357 g_message("f: input_read_tag"); |
| 379 #endif | 358 #endif |
| 380 if (info->tuple == NULL) { | 359 if (info->tuple == NULL) { |
| 381 title_input = tuple_new(); | 360 tuple = tuple_new(); |
| 382 info->tuple = title_input; | 361 info->tuple = tuple; |
| 383 } | 362 } |
| 384 else | 363 else |
| 385 title_input = info->tuple; | 364 tuple = info->tuple; |
| 386 | 365 |
| 387 if(info->infile) { | 366 if(info->infile) { |
| 388 curpos = vfs_ftell(info->infile); | 367 curpos = vfs_ftell(info->infile); |
| 389 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); | 368 info->id3file = id3_file_vfsopen(info->infile, ID3_FILE_MODE_READONLY); |
| 390 } | 369 } |
| 405 g_message("read_tag: no tag"); | 384 g_message("read_tag: no tag"); |
| 406 #endif | 385 #endif |
| 407 return; | 386 return; |
| 408 } | 387 } |
| 409 | 388 |
| 410 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_ARTIST, "artist"); | 389 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ARTIST, "artist"); |
| 411 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_TITLE, "title"); | 390 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_TITLE, "title"); |
| 412 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_ALBUM, "album"); | 391 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_ALBUM, "album"); |
| 413 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_GENRE, "genre"); | 392 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_GENRE, "genre"); |
| 414 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_COMMENT, "comment"); | 393 input_set_and_free_tag(info->tag, tuple, ID3_FRAME_COMMENT, "comment"); |
| 415 | 394 |
| 416 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK); | 395 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK); |
| 417 if (string) { | 396 if (string) { |
| 418 tuple_associate_int(title_input, "track-number", atoi(string)); | 397 tuple_associate_int(tuple, "track-number", atoi(string)); |
| 419 g_free(string); | 398 g_free(string); |
| 420 string = NULL; | 399 string = NULL; |
| 421 } | 400 } |
| 422 | 401 |
| 423 // year | 402 // year |
| 425 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC | 404 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC |
| 426 if (!string) | 405 if (!string) |
| 427 string = input_id3_get_string(info->tag, "TYER"); | 406 string = input_id3_get_string(info->tag, "TYER"); |
| 428 | 407 |
| 429 if (string) { | 408 if (string) { |
| 430 tuple_associate_int(title_input, "year", atoi(string)); | 409 tuple_associate_int(tuple, "year", atoi(string)); |
| 431 g_free(string); | 410 g_free(string); |
| 432 string = NULL; | 411 string = NULL; |
| 433 } | 412 } |
| 434 | 413 |
| 435 // length | 414 // length |
| 436 string = input_id3_get_string(info->tag, "TLEN"); | 415 string = input_id3_get_string(info->tag, "TLEN"); |
| 437 if (string) { | 416 if (string) { |
| 438 tuple_associate_int(title_input, "length", atoi(string)); | 417 tuple_associate_int(tuple, "length", atoi(string)); |
| 439 #ifdef DEBUG | 418 #ifdef DEBUG |
| 440 g_message("input_read_tag: TLEN = %d", atoi(string)); | 419 g_message("input_read_tag: TLEN = %d", atoi(string)); |
| 441 #endif | 420 #endif |
| 442 g_free(string); | 421 g_free(string); |
| 443 string = NULL; | 422 string = NULL; |
| 444 } | 423 } |
| 445 | 424 |
| 446 realfn = g_filename_from_uri(info->filename, NULL, NULL); | 425 realfn = g_filename_from_uri(info->filename, NULL, NULL); |
| 447 | 426 |
| 448 string = g_strdup(g_basename(realfn ? realfn : info->filename)); | 427 string = g_strdup(g_basename(realfn ? realfn : info->filename)); |
| 449 tuple_associate_string(title_input, "file-name", string); | 428 tuple_associate_string(tuple, "file-name", string); |
| 450 g_free(string); | 429 g_free(string); |
| 451 | 430 |
| 452 string = g_path_get_dirname(realfn ? realfn : info->filename); | 431 string = g_path_get_dirname(realfn ? realfn : info->filename); |
| 453 tuple_associate_string(title_input, "file-path", string); | 432 tuple_associate_string(tuple, "file-path", string); |
| 454 g_free(string); | 433 g_free(string); |
| 455 | 434 |
| 456 if ((string = strrchr(realfn ? realfn : info->filename, '.'))) { | 435 if ((string = strrchr(realfn ? realfn : info->filename, '.'))) { |
| 457 *string = '\0'; // make filename end at dot. | 436 *string = '\0'; // make filename end at dot. |
| 458 tuple_associate_string(title_input, "file-ext", string + 1); | 437 tuple_associate_string(tuple, "file-ext", string + 1); |
| 459 } | 438 } |
| 460 | 439 |
| 461 g_free(realfn); realfn = NULL; | 440 g_free(realfn); realfn = NULL; |
| 462 | 441 |
| 463 tuple_associate_string(title_input, "codec", "MPEG Audio (MP3)"); | 442 tuple_associate_string(tuple, "codec", "MPEG Audio (MP3)"); |
| 464 tuple_associate_string(title_input, "quality", "lossy"); | 443 tuple_associate_string(tuple, "quality", "lossy"); |
| 465 | 444 |
| 466 info->title = tuple_formatter_process_string(title_input, audmad_config.title_override == TRUE ? | 445 info->title = tuple_formatter_make_title_string(tuple, audmad_config.title_override == TRUE ? |
| 467 audmad_config.id3_format : get_gentitle_format()); | 446 audmad_config.id3_format : get_gentitle_format()); |
| 468 | 447 |
| 469 // for connection via proxy, we have to stop transfer once. I can't explain the reason. | 448 // for connection via proxy, we have to stop transfer once. I can't explain the reason. |
| 470 if (info->infile != NULL) { | 449 if (info->infile != NULL) { |
| 471 vfs_fseek(info->infile, -1, SEEK_SET); // an impossible request | 450 vfs_fseek(info->infile, -1, SEEK_SET); // an impossible request |
