comparison src/sndfile/plugin.c @ 2999:e2e8f927a08a

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:48:20 +0000
parents 4d778b7a19c6
children
comparison
equal deleted inserted replaced
2998:fc666525b410 2999:e2e8f927a08a
45 static SF_INFO sfinfo; 45 static SF_INFO sfinfo;
46 46
47 static gint song_length; 47 static gint song_length;
48 static gint bit_rate = 0; 48 static gint bit_rate = 0;
49 static glong seek_time = -1; 49 static glong seek_time = -1;
50 static volatile char pause_flag;
50 51
51 static GThread *decode_thread; 52 static GThread *decode_thread;
52 static GMutex *decode_mutex; 53 static GMutex *decode_mutex;
53 static GCond *decode_cond; 54 static GCond *decode_cond;
54 55
119 120
120 static void 121 static void
121 plugin_init (void) 122 plugin_init (void)
122 { 123 {
123 seek_time = -1; 124 seek_time = -1;
125 pause_flag = 0;
124 126
125 decode_mutex = g_mutex_new(); 127 decode_mutex = g_mutex_new();
126 decode_cond = g_cond_new(); 128 decode_cond = g_cond_new();
127 } 129 }
128 130
360 /* It can so close file and return TRUE. */ 362 /* It can so close file and return TRUE. */
361 close_sndfile (tmp_sndfile, vfsfile); 363 close_sndfile (tmp_sndfile, vfsfile);
362 tmp_sndfile = NULL; 364 tmp_sndfile = NULL;
363 365
364 return TRUE; 366 return TRUE;
367 }
368
369 static void do_seek (InputPlayback * playback) {
370 playback->output->flush (seek_time);
371 sf_seek (sndfile, (long long) seek_time * sfinfo.samplerate / 1000, SEEK_SET);
372 seek_time = -1;
373 }
374
375 static void do_pause (InputPlayback * playback) {
376 playback->output->pause (1);
377 while (pause_flag) {
378 if (seek_time != -1)
379 do_seek (playback);
380 g_usleep(50000);
381 }
382 playback->output->pause (0);
365 } 383 }
366 384
367 static gpointer 385 static gpointer
368 play_loop (gpointer arg) 386 play_loop (gpointer arg)
369 { 387 {
411 429
412 g_mutex_unlock(decode_mutex); 430 g_mutex_unlock(decode_mutex);
413 break; 431 break;
414 } 432 }
415 433
416 /* Do seek if seek_time is valid. */ 434 if (seek_time != -1)
417 if (seek_time >= 0) { 435 do_seek (playback);
418 sf_seek (sndfile, (sf_count_t)((gint64)seek_time * (gint64)sfinfo.samplerate / 1000L), 436 if (pause_flag)
419 SEEK_SET); 437 do_pause (playback);
420 playback->output->flush (seek_time);
421 seek_time = -1;
422 }
423 438
424 if (playback->playing == FALSE) 439 if (playback->playing == FALSE)
425 break; 440 break;
426 } 441 }
427 442
477 } 492 }
478 493
479 static void 494 static void
480 play_pause (InputPlayback *playback, gshort p) 495 play_pause (InputPlayback *playback, gshort p)
481 { 496 {
482 playback->output->pause(p); 497 pause_flag = p;
483 } 498 }
484 499
485 static void 500 static void
486 play_stop (InputPlayback *playback) 501 play_stop (InputPlayback *playback)
487 { 502 {