comparison src/flac113/plugin.c @ 561:914c96de3244 trunk

[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
author iabervon
date Sun, 28 Jan 2007 21:09:12 -0800
parents 221086196f89
children ca3de84e2288
comparison
equal deleted inserted replaced
560:7b4b37819c9d 561:914c96de3244
272 vfs_fclose( vfsfile ); 272 vfs_fclose( vfsfile );
273 273
274 return result; 274 return result;
275 } 275 }
276 276
277 void FLAC_XMMS__play_file(char *filename) 277 void FLAC_XMMS__play_file(InputPlayback *playback)
278 { 278 {
279 char *filename = playback->filename;
279 sample_buffer_first_ = sample_buffer_last_ = 0; 280 sample_buffer_first_ = sample_buffer_last_ = 0;
280 audio_error_ = false; 281 audio_error_ = false;
281 stream_data_.abort_flag = false; 282 stream_data_.abort_flag = false;
282 stream_data_.is_playing = false; 283 stream_data_.is_playing = false;
283 stream_data_.eof = false; 284 stream_data_.eof = false;
323 } 324 }
324 } 325 }
325 FLAC__replaygain_synthesis__init_dither_context(&stream_data_.dither_context, stream_data_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping); 326 FLAC__replaygain_synthesis__init_dither_context(&stream_data_.dither_context, stream_data_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping);
326 stream_data_.is_playing = true; 327 stream_data_.is_playing = true;
327 328
328 if(flac_ip.output->open_audio(stream_data_.sample_format, stream_data_.sample_rate, stream_data_.channels) == 0) { 329 if(playback->output->open_audio(stream_data_.sample_format, stream_data_.sample_rate, stream_data_.channels) == 0) {
329 audio_error_ = true; 330 audio_error_ = true;
330 safe_decoder_finish_(decoder_); 331 safe_decoder_finish_(decoder_);
331 return; 332 return;
332 } 333 }
333 334
337 stream_data_.seek_to_in_sec = -1; 338 stream_data_.seek_to_in_sec = -1;
338 stream_data_.play_thread_open = true; 339 stream_data_.play_thread_open = true;
339 decode_thread_ = g_thread_create((GThreadFunc)play_loop_, NULL, TRUE, NULL); 340 decode_thread_ = g_thread_create((GThreadFunc)play_loop_, NULL, TRUE, NULL);
340 } 341 }
341 342
342 void FLAC_XMMS__stop() 343 void FLAC_XMMS__stop(InputPlayback *playback)
343 { 344 {
344 if(stream_data_.is_playing) { 345 if(stream_data_.is_playing) {
345 stream_data_.is_playing = false; 346 stream_data_.is_playing = false;
346 if(stream_data_.play_thread_open) { 347 if(stream_data_.play_thread_open) {
347 stream_data_.play_thread_open = false; 348 stream_data_.play_thread_open = false;
348 g_thread_join(decode_thread_); 349 g_thread_join(decode_thread_);
349 } 350 }
350 flac_ip.output->close_audio(); 351 playback->output->close_audio();
351 safe_decoder_finish_(decoder_); 352 safe_decoder_finish_(decoder_);
352 } 353 }
353 } 354 }
354 355
355 void FLAC_XMMS__pause(short p) 356 void FLAC_XMMS__pause(InputPlayback *playback, short p)
356 { 357 {
357 flac_ip.output->pause(p); 358 playback->output->pause(p);
358 } 359 }
359 360
360 void FLAC_XMMS__seek(int time) 361 void FLAC_XMMS__seek(InputPlayback *playback, int time)
361 { 362 {
362 stream_data_.seek_to_in_sec = time; 363 stream_data_.seek_to_in_sec = time;
363 stream_data_.eof = false; 364 stream_data_.eof = false;
364 365
365 while(stream_data_.seek_to_in_sec != -1) 366 while(stream_data_.seek_to_in_sec != -1)
366 xmms_usleep(10000); 367 xmms_usleep(10000);
367 } 368 }
368 369
369 int FLAC_XMMS__get_time() 370 int FLAC_XMMS__get_time(InputPlayback *playback)
370 { 371 {
371 if(audio_error_) 372 if(audio_error_)
372 return -2; 373 return -2;
373 if(!stream_data_.is_playing || (stream_data_.eof && !flac_ip.output->buffer_playing())) 374 if(!stream_data_.is_playing || (stream_data_.eof && !playback->output->buffer_playing()))
374 return -1; 375 return -1;
375 else 376 else
376 return flac_ip.output->output_time(); 377 return playback->output->output_time();
377 } 378 }
378 379
379 void FLAC_XMMS__cleanup() 380 void FLAC_XMMS__cleanup()
380 { 381 {
381 g_free(flac_ip.description); 382 g_free(flac_ip.description);
435 * local routines 436 * local routines
436 **********************************************************************/ 437 **********************************************************************/
437 438
438 static void *play_loop_(void *arg) 439 static void *play_loop_(void *arg)
439 { 440 {
441 InputPlayback *playback = arg;
440 unsigned written_time_last = 0, bh_index_last_w = 0, bh_index_last_o = BITRATE_HIST_SIZE, blocksize = 1; 442 unsigned written_time_last = 0, bh_index_last_w = 0, bh_index_last_o = BITRATE_HIST_SIZE, blocksize = 1;
441 FLAC__uint64 decode_position_last = 0, decode_position_frame_last = 0, decode_position_frame = 0; 443 FLAC__uint64 decode_position_last = 0, decode_position_frame_last = 0, decode_position_frame = 0;
442
443 (void)arg;
444 444
445 while(stream_data_.is_playing) { 445 while(stream_data_.is_playing) {
446 if(!stream_data_.eof) { 446 if(!stream_data_.eof) {
447 while(sample_buffer_last_ - sample_buffer_first_ < SAMPLES_PER_WRITE) { 447 while(sample_buffer_last_ - sample_buffer_first_ < SAMPLES_PER_WRITE) {
448 unsigned s; 448 unsigned s;
469 FLAC__byte *sample_buffer_start = sample_buffer_ + sample_buffer_first_ * stream_data_.channels * stream_data_.sample_format_bytes_per_sample; 469 FLAC__byte *sample_buffer_start = sample_buffer_ + sample_buffer_first_ * stream_data_.channels * stream_data_.sample_format_bytes_per_sample;
470 unsigned written_time, bh_index_w; 470 unsigned written_time, bh_index_w;
471 FLAC__uint64 decode_position; 471 FLAC__uint64 decode_position;
472 472
473 sample_buffer_first_ += n; 473 sample_buffer_first_ += n;
474 while(flac_ip.output->buffer_free() < (int)bytes && stream_data_.is_playing && stream_data_.seek_to_in_sec == -1) 474 while(playback->output->buffer_free() < (int)bytes && stream_data_.is_playing && stream_data_.seek_to_in_sec == -1)
475 xmms_usleep(10000); 475 xmms_usleep(10000);
476 if(stream_data_.is_playing && stream_data_.seek_to_in_sec == -1) 476 if(stream_data_.is_playing && stream_data_.seek_to_in_sec == -1)
477 produce_audio(flac_ip.output->written_time(), stream_data_.sample_format, 477 produce_audio(playback->output->written_time(), stream_data_.sample_format,
478 stream_data_.channels, bytes, sample_buffer_start, NULL); 478 stream_data_.channels, bytes, sample_buffer_start, NULL);
479 479
480 /* compute current bitrate */ 480 /* compute current bitrate */
481 481
482 written_time = flac_ip.output->written_time(); 482 written_time = playback->output->written_time();
483 bh_index_w = written_time / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE; 483 bh_index_w = written_time / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
484 if(bh_index_w != bh_index_last_w) { 484 if(bh_index_w != bh_index_last_w) {
485 bh_index_last_w = bh_index_w; 485 bh_index_last_w = bh_index_w;
486 decode_position = decode_position_frame - (double)(sample_buffer_last_ - sample_buffer_first_) * (double)(decode_position_frame - decode_position_frame_last) / (double)blocksize; 486 decode_position = decode_position_frame - (double)(sample_buffer_last_ - sample_buffer_first_) * (double)(decode_position_frame - decode_position_frame_last) / (double)blocksize;
487 bitrate_history_[(bh_index_w + BITRATE_HIST_SIZE - 1) % BITRATE_HIST_SIZE] = 487 bitrate_history_[(bh_index_w + BITRATE_HIST_SIZE - 1) % BITRATE_HIST_SIZE] =
503 const double distance = (double)stream_data_.seek_to_in_sec * 1000.0 / (double)stream_data_.length_in_msec; 503 const double distance = (double)stream_data_.seek_to_in_sec * 1000.0 / (double)stream_data_.length_in_msec;
504 FLAC__uint64 target_sample = (FLAC__uint64)(distance * (double)stream_data_.total_samples); 504 FLAC__uint64 target_sample = (FLAC__uint64)(distance * (double)stream_data_.total_samples);
505 if(stream_data_.total_samples > 0 && target_sample >= stream_data_.total_samples) 505 if(stream_data_.total_samples > 0 && target_sample >= stream_data_.total_samples)
506 target_sample = stream_data_.total_samples - 1; 506 target_sample = stream_data_.total_samples - 1;
507 if(FLAC__stream_decoder_seek_absolute(decoder_, target_sample)) { 507 if(FLAC__stream_decoder_seek_absolute(decoder_, target_sample)) {
508 flac_ip.output->flush(stream_data_.seek_to_in_sec * 1000); 508 playback->output->flush(stream_data_.seek_to_in_sec * 1000);
509 bh_index_last_w = bh_index_last_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE; 509 bh_index_last_w = bh_index_last_o = playback->output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
510 if(!FLAC__stream_decoder_get_decode_position(decoder_, &decode_position_frame)) 510 if(!FLAC__stream_decoder_get_decode_position(decoder_, &decode_position_frame))
511 decode_position_frame = 0; 511 decode_position_frame = 0;
512 stream_data_.eof = false; 512 stream_data_.eof = false;
513 sample_buffer_first_ = sample_buffer_last_ = 0; 513 sample_buffer_first_ = sample_buffer_last_ = 0;
514 } 514 }
522 stream_data_.seek_to_in_sec = -1; 522 stream_data_.seek_to_in_sec = -1;
523 } 523 }
524 else if ( !flac_cfg.title.disable_bitrate_update ) 524 else if ( !flac_cfg.title.disable_bitrate_update )
525 { 525 {
526 /* display the right bitrate from history */ 526 /* display the right bitrate from history */
527 unsigned bh_index_o = flac_ip.output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE; 527 unsigned bh_index_o = playback->output->output_time() / BITRATE_HIST_SEGMENT_MSEC % BITRATE_HIST_SIZE;
528 if(bh_index_o != bh_index_last_o && bh_index_o != bh_index_last_w && bh_index_o != (bh_index_last_w + 1) % BITRATE_HIST_SIZE) { 528 if(bh_index_o != bh_index_last_o && bh_index_o != bh_index_last_w && bh_index_o != (bh_index_last_w + 1) % BITRATE_HIST_SIZE) {
529 bh_index_last_o = bh_index_o; 529 bh_index_last_o = bh_index_o;
530 flac_ip.set_info(stream_data_.title, stream_data_.length_in_msec, bitrate_history_[bh_index_o], stream_data_.sample_rate, stream_data_.channels); 530 flac_ip.set_info(stream_data_.title, stream_data_.length_in_msec, bitrate_history_[bh_index_o], stream_data_.sample_rate, stream_data_.channels);
531 } 531 }
532 } 532 }
533 } 533 }
534 534
535 safe_decoder_finish_(decoder_); 535 safe_decoder_finish_(decoder_);
536 536
537 /* are these two calls necessary? */ 537 /* are these two calls necessary? */
538 flac_ip.output->buffer_free(); 538 playback->output->buffer_free();
539 flac_ip.output->buffer_free(); 539 playback->output->buffer_free();
540 540
541 g_free(stream_data_.title); 541 g_free(stream_data_.title);
542 542
543 g_thread_exit(NULL); 543 g_thread_exit(NULL);
544 return 0; /* to silence the compiler warning about not returning a value */ 544 return 0; /* to silence the compiler warning about not returning a value */