Mercurial > audlegacy-plugins
comparison src/flacng/plugin.c @ 2996:b7c181d0b325
Patch from John Lindgren <john.lindgren@tds.net> to support seeking whilst paused, Debian bug #517692.
| author | Tony Vroon <chainsaw@gentoo.org> |
|---|---|
| date | Wed, 04 Mar 2009 12:45:16 +0000 |
| parents | 2cdf6400594c |
| children |
comparison
equal
deleted
inserted
replaced
| 2995:1192140d9e3f | 2996:b7c181d0b325 |
|---|---|
| 54 FLAC__StreamDecoder* main_decoder; | 54 FLAC__StreamDecoder* main_decoder; |
| 55 callback_info* test_info; | 55 callback_info* test_info; |
| 56 callback_info* main_info; | 56 callback_info* main_info; |
| 57 gboolean plugin_initialized = FALSE; | 57 gboolean plugin_initialized = FALSE; |
| 58 glong seek_to = -1; | 58 glong seek_to = -1; |
| 59 static volatile char pause_flag = 0; | |
| 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) { |
| 300 _LEAVE; | 301 _LEAVE; |
| 301 } | 302 } |
| 302 | 303 |
| 303 /* --- */ | 304 /* --- */ |
| 304 | 305 |
| 306 static void do_seek (InputPlayback * playback) { | |
| 307 playback->output->flush (seek_to); | |
| 308 FLAC__stream_decoder_seek_absolute (main_decoder, (long long) seek_to * main_info->stream.samplerate / 1000); | |
| 309 seek_to = -1; | |
| 310 } | |
| 311 | |
| 312 static void do_pause (InputPlayback * playback) { | |
| 313 playback->output->pause (1); | |
| 314 while (pause_flag) { | |
| 315 if (seek_to != -1) | |
| 316 do_seek (playback); | |
| 317 g_usleep(50000); | |
| 318 } | |
| 319 playback->output->pause (0); | |
| 320 } | |
| 321 | |
| 305 static gpointer flac_play_loop(gpointer arg) { | 322 static gpointer flac_play_loop(gpointer arg) { |
| 306 | 323 |
| 307 /* | 324 /* |
| 308 * The main play loop. | 325 * The main play loop. |
| 309 * Decode a frame, push the decoded data to the output plugin | 326 * Decode a frame, push the decoded data to the output plugin |
| 310 * chunkwise. Repeat until finished. | 327 * chunkwise. Repeat until finished. |
| 311 */ | 328 */ |
| 312 | 329 |
| 313 gint32* read_pointer; | 330 gint32* read_pointer; |
| 314 gint elements_left; | 331 gint elements_left; |
| 315 gint seek_sample; | |
| 316 FLAC__StreamDecoderState state; | 332 FLAC__StreamDecoderState state; |
| 317 struct stream_info stream_info; | 333 struct stream_info stream_info; |
| 318 guint sample_count; | 334 guint sample_count; |
| 319 void* play_buffer; | 335 void* play_buffer; |
| 320 InputPlayback* playback = (InputPlayback *) arg; | 336 InputPlayback* playback = (InputPlayback *) arg; |
| 433 */ | 449 */ |
| 434 main_info->write_pointer = main_info->output_buffer; | 450 main_info->write_pointer = main_info->output_buffer; |
| 435 main_info->buffer_free = BUFFER_SIZE_SAMP; | 451 main_info->buffer_free = BUFFER_SIZE_SAMP; |
| 436 main_info->buffer_used = 0; | 452 main_info->buffer_used = 0; |
| 437 | 453 |
| 438 /* | 454 if (seek_to != -1) |
| 439 * Do we have to seek to somewhere? | 455 do_seek (playback); |
| 440 */ | 456 if (pause_flag) |
| 441 if (-1 != seek_to) { | 457 do_pause (playback); |
| 442 _DEBUG("Seek requested to %d milliseconds", seek_to); | |
| 443 | |
| 444 seek_sample = (unsigned long)((gint64)seek_to * (gint64) main_info->stream.samplerate / 1000L ); | |
| 445 _DEBUG("Seek requested to sample %d", seek_sample); | |
| 446 if (FALSE == FLAC__stream_decoder_seek_absolute(main_decoder, seek_sample)) { | |
| 447 _ERROR("Could not seek to sample %d!", seek_sample); | |
| 448 } else { | |
| 449 /* | |
| 450 * Flush the buffers | |
| 451 */ | |
| 452 playback->output->flush(seek_to); | |
| 453 } | |
| 454 seek_to = -1; | |
| 455 } | |
| 456 | 458 |
| 457 /* | 459 /* |
| 458 * Have we reached the end of the stream? | 460 * Have we reached the end of the stream? |
| 459 */ | 461 */ |
| 460 state = FLAC__stream_decoder_get_state(main_decoder); | 462 state = FLAC__stream_decoder_get_state(main_decoder); |
| 565 } | 567 } |
| 566 | 568 |
| 567 /* --- */ | 569 /* --- */ |
| 568 | 570 |
| 569 void flac_pause(InputPlayback* input, gshort p) { | 571 void flac_pause(InputPlayback* input, gshort p) { |
| 570 | 572 pause_flag = p; |
| 571 _ENTER; | |
| 572 | |
| 573 input->output->pause(p); | |
| 574 | |
| 575 _LEAVE; | |
| 576 } | 573 } |
| 577 | 574 |
| 578 /* --- */ | 575 /* --- */ |
| 579 | 576 |
| 580 void flac_mseek(InputPlayback* input, gulong millisecond) { | 577 void flac_mseek(InputPlayback* input, gulong millisecond) { |
