comparison src/flacng/plugin.c @ 2417:0427c5d07a66

added mseek support to flacng. patch by Piotr Garus. thanks Piotr!
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Fri, 22 Feb 2008 17:25:46 +0900
parents ead24454f4b7
children 6c272f46fa99
comparison
equal deleted inserted replaced
2416:372c4e0943ed 2417:0427c5d07a66
37 .about = flac_aboutbox, 37 .about = flac_aboutbox,
38 .is_our_file = flac_is_our_file, 38 .is_our_file = flac_is_our_file,
39 .play_file = flac_play_file, 39 .play_file = flac_play_file,
40 .stop = flac_stop, 40 .stop = flac_stop,
41 .pause = flac_pause, 41 .pause = flac_pause,
42 .mseek = flac_mseek,
42 .seek = flac_seek, 43 .seek = flac_seek,
43 .get_song_info = flac_get_song_info, 44 .get_song_info = flac_get_song_info,
44 .get_song_tuple = flac_get_song_tuple, // get a tuple 45 .get_song_tuple = flac_get_song_tuple, // get a tuple
45 .is_our_file_from_vfs = flac_is_our_fd, // version of is_our_file which is handed an FD 46 .is_our_file_from_vfs = flac_is_our_fd, // version of is_our_file which is handed an FD
46 .vfs_extensions = flac_fmts // vector of fileextensions allowed by the plugin 47 .vfs_extensions = flac_fmts // vector of fileextensions allowed by the plugin
53 FLAC__StreamDecoder* test_decoder; 54 FLAC__StreamDecoder* test_decoder;
54 FLAC__StreamDecoder* main_decoder; 55 FLAC__StreamDecoder* main_decoder;
55 callback_info* test_info; 56 callback_info* test_info;
56 callback_info* main_info; 57 callback_info* main_info;
57 gboolean plugin_initialized = FALSE; 58 gboolean plugin_initialized = FALSE;
58 gint seek_to = -1; 59 glong seek_to = -1;
59 static GThread* thread = NULL; 60 static GThread* thread = NULL;
60 61
61 /* === */ 62 /* === */
62 63
63 void flac_init(void) { 64 void flac_init(void) {
434 435
435 /* 436 /*
436 * Do we have to seek to somewhere? 437 * Do we have to seek to somewhere?
437 */ 438 */
438 if (-1 != seek_to) { 439 if (-1 != seek_to) {
439 _DEBUG("Seek requested to %d seconds", seek_to); 440 _DEBUG("Seek requested to %d miliseconds", seek_to);
440 441
441 seek_sample = seek_to * main_info->stream.samplerate; 442 seek_sample = (unsigned long)((gint64)seek_to * (gint64) main_info->stream.samplerate / 1000L );
442 _DEBUG("Seek requested to sample %d", seek_sample); 443 _DEBUG("Seek requested to sample %d", seek_sample);
443 if (FALSE == FLAC__stream_decoder_seek_absolute(main_decoder, seek_sample)) { 444 if (FALSE == FLAC__stream_decoder_seek_absolute(main_decoder, seek_sample)) {
444 _ERROR("Could not seek to sample %d!", seek_sample); 445 _ERROR("Could not seek to sample %d!", seek_sample);
445 } else { 446 } else {
446 /* 447 /*
447 * Flush the buffers 448 * Flush the buffers
448 */ 449 */
449 flac_ip.output->flush(seek_to * 1000); 450 flac_ip.output->flush(seek_to);
450 } 451 }
451 seek_to = -1; 452 seek_to = -1;
452 } 453 }
453 454
454 /* 455 /*
572 _LEAVE; 573 _LEAVE;
573 } 574 }
574 575
575 /* --- */ 576 /* --- */
576 577
577 void flac_seek(InputPlayback* input, gint time) { 578 void flac_mseek(InputPlayback* input, gulong milisecond) {
578 579
579 _ENTER; 580 _ENTER;
580 581
581 if (!input->playing) { 582 if (!input->playing) {
582 _DEBUG("Can not seek while not playing"); 583 _DEBUG("Can not seek while not playing");
583 _LEAVE; 584 _LEAVE;
584 } 585 }
585 586
586 _DEBUG("Requesting seek to %d", time); 587 _DEBUG("Requesting seek to %d", milisecond);
587 seek_to = time; 588 seek_to = milisecond;
588 589
589 while (-1 != seek_to) { 590 while (-1 != seek_to) {
590 g_usleep(10000); 591 g_usleep(10000);
591 } 592 }
592 593
593 _LEAVE; 594 _LEAVE;
595 }
596
597 void flac_seek(InputPlayback* input, gint time) {
598 gulong milisecond = time * 1000;
599 flac_mseek(input, milisecond);
594 } 600 }
595 601
596 /* --- */ 602 /* --- */
597 603
598 void flac_get_song_info(gchar* filename, gchar** title, gint* length) { 604 void flac_get_song_info(gchar* filename, gchar** title, gint* length) {