comparison src/flac113/plugin.c @ 488:5e375eca97da trunk

[svn] - flac 113 plugin: allow to do seek and other operations on http sources
author giacomo
date Sun, 21 Jan 2007 11:17:52 -0800
parents 3e41d8efe752
children 9fc8b269e811
comparison
equal deleted inserted replaced
487:f541940d5475 488:5e375eca97da
394 flac_ip.output->pause(p); 394 flac_ip.output->pause(p);
395 } 395 }
396 396
397 void FLAC_XMMS__seek(int time) 397 void FLAC_XMMS__seek(int time)
398 { 398 {
399 if(!stream_data_.is_http_source) { 399 stream_data_.seek_to_in_sec = time;
400 stream_data_.seek_to_in_sec = time; 400 stream_data_.eof = false;
401 stream_data_.eof = false; 401
402 402 while(stream_data_.seek_to_in_sec != -1)
403 while(stream_data_.seek_to_in_sec != -1) 403 xmms_usleep(10000);
404 xmms_usleep(10000);
405 }
406 } 404 }
407 405
408 int FLAC_XMMS__get_time() 406 int FLAC_XMMS__get_time()
409 { 407 {
410 if(audio_error_) 408 if(audio_error_)
520 stream_data_.eof = true; 518 stream_data_.eof = true;
521 break; 519 break;
522 } 520 }
523 blocksize = sample_buffer_last_ - sample_buffer_first_ - s; 521 blocksize = sample_buffer_last_ - sample_buffer_first_ - s;
524 decode_position_frame_last = decode_position_frame; 522 decode_position_frame_last = decode_position_frame;
525 if(stream_data_.is_http_source || !FLAC__stream_decoder_get_decode_position(decoder_, &decode_position_frame)) 523 if(!FLAC__stream_decoder_get_decode_position(decoder_, &decode_position_frame))
526 decode_position_frame = 0; 524 decode_position_frame = 0;
527 } 525 }
528 if(sample_buffer_last_ - sample_buffer_first_ > 0) { 526 if(sample_buffer_last_ - sample_buffer_first_ > 0) {
529 const unsigned n = min(sample_buffer_last_ - sample_buffer_first_, SAMPLES_PER_WRITE); 527 const unsigned n = min(sample_buffer_last_ - sample_buffer_first_, SAMPLES_PER_WRITE);
530 int bytes = n * stream_data_.channels * stream_data_.sample_format_bytes_per_sample; 528 int bytes = n * stream_data_.channels * stream_data_.sample_format_bytes_per_sample;
559 xmms_usleep(10000); 557 xmms_usleep(10000);
560 } 558 }
561 } 559 }
562 else 560 else
563 xmms_usleep(10000); 561 xmms_usleep(10000);
564 if(!stream_data_.is_http_source && stream_data_.seek_to_in_sec != -1) { 562 if(stream_data_.seek_to_in_sec != -1) {
565 const double distance = (double)stream_data_.seek_to_in_sec * 1000.0 / (double)stream_data_.length_in_msec; 563 const double distance = (double)stream_data_.seek_to_in_sec * 1000.0 / (double)stream_data_.length_in_msec;
566 FLAC__uint64 target_sample = (FLAC__uint64)(distance * (double)stream_data_.total_samples); 564 FLAC__uint64 target_sample = (FLAC__uint64)(distance * (double)stream_data_.total_samples);
567 if(stream_data_.total_samples > 0 && target_sample >= stream_data_.total_samples) 565 if(stream_data_.total_samples > 0 && target_sample >= stream_data_.total_samples)
568 target_sample = stream_data_.total_samples - 1; 566 target_sample = stream_data_.total_samples - 1;
569 if(FLAC__stream_decoder_seek_absolute(decoder_, target_sample)) { 567 if(FLAC__stream_decoder_seek_absolute(decoder_, target_sample)) {
763 static FLAC__StreamDecoderSeekStatus seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) 761 static FLAC__StreamDecoderSeekStatus seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
764 { 762 {
765 stream_data_struct *stream_data = (stream_data_struct *)client_data; 763 stream_data_struct *stream_data = (stream_data_struct *)client_data;
766 (void)decoder; 764 (void)decoder;
767 765
768 if ( stream_data->is_http_source ) 766 g_print("SEEK\n");
769 return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
770 767
771 if ( vfs_fseek( stream_data->vfsfile , (glong)absolute_byte_offset , SEEK_SET ) < 0 ) 768 if ( vfs_fseek( stream_data->vfsfile , (glong)absolute_byte_offset , SEEK_SET ) < 0 )
772 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; 769 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
773 else 770 else
774 return FLAC__STREAM_DECODER_SEEK_STATUS_OK; 771 return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
777 static FLAC__StreamDecoderTellStatus tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) 774 static FLAC__StreamDecoderTellStatus tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
778 { 775 {
779 stream_data_struct *stream_data = (stream_data_struct *)client_data; 776 stream_data_struct *stream_data = (stream_data_struct *)client_data;
780 glong pos; 777 glong pos;
781 (void)decoder; 778 (void)decoder;
782
783 if ( stream_data->is_http_source )
784 return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
785 779
786 if ( (pos = vfs_ftell(stream_data->vfsfile)) < 0 ) 780 if ( (pos = vfs_ftell(stream_data->vfsfile)) < 0 )
787 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; 781 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
788 else 782 else
789 { 783 {
796 { 790 {
797 stream_data_struct *stream_data = (stream_data_struct *)client_data; 791 stream_data_struct *stream_data = (stream_data_struct *)client_data;
798 glong current_pos = 0; 792 glong current_pos = 0;
799 glong length = 0; 793 glong length = 0;
800 (void)decoder; 794 (void)decoder;
801
802 if ( stream_data->is_http_source )
803 return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
804 795
805 current_pos = vfs_ftell(stream_data->vfsfile); 796 current_pos = vfs_ftell(stream_data->vfsfile);
806 if ( current_pos < 0 ) 797 if ( current_pos < 0 )
807 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; 798 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
808 799
826 static FLAC__bool eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data) 817 static FLAC__bool eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
827 { 818 {
828 stream_data_struct *stream_data = (stream_data_struct *)client_data; 819 stream_data_struct *stream_data = (stream_data_struct *)client_data;
829 (void)decoder; 820 (void)decoder;
830 821
831 if ( stream_data->is_http_source ) 822 return vfs_feof( stream_data->vfsfile );
832 return FALSE; 823 }
833 else
834 return vfs_feof( stream_data->vfsfile );
835 }