comparison src/vorbis/vorbis.c @ 2375:22641735c9b1

- fixed freezing on track end - remember that buffer_free() returns _free_ space, not used.
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sun, 10 Feb 2008 14:46:28 +0300
parents db02ad480056
children 9056897525e1
comparison
equal deleted inserted replaced
2371:47f6f73438c3 2375:22641735c9b1
32 * Note that this uses vorbisfile, which is not (currently) 32 * Note that this uses vorbisfile, which is not (currently)
33 * thread-safe. 33 * thread-safe.
34 */ 34 */
35 35
36 #include "config.h" 36 #include "config.h"
37 37 /*
38 #define AUD_DEBUG
38 #define DEBUG 39 #define DEBUG
40 */
39 41
40 #define REMOVE_NONEXISTANT_TAG(x) if (x != NULL && !*x) { x = NULL; } 42 #define REMOVE_NONEXISTANT_TAG(x) if (x != NULL && !*x) { x = NULL; }
41 43
42 #include <glib.h> 44 #include <glib.h>
43 #include <gtk/gtk.h> 45 #include <gtk/gtk.h>
358 */ 360 */
359 if (bytes <= 0 && bytes != OV_HOLE) { 361 if (bytes <= 0 && bytes != OV_HOLE) {
360 /* 362 /*
361 * EOF 363 * EOF
362 */ 364 */
365 AUDDBG("EOF\n");
363 playback->playing = 0; 366 playback->playing = 0;
364 playback->output->buffer_free();
365 playback->output->buffer_free();
366 playback->eof = TRUE; 367 playback->eof = TRUE;
367 current_section = last_section; 368 current_section = last_section;
368 } 369 }
369
370
371 370
372 if (current_section <= last_section) { 371 if (current_section <= last_section) {
373 /* 372 /*
374 * The info struct is different in each section. vf 373 * The info struct is different in each section. vf
375 * holds them all for the given bitstream. This 374 * holds them all for the given bitstream. This
385 384
386 385
387 if (vi->rate != samplerate || vi->channels != channels) { 386 if (vi->rate != samplerate || vi->channels != channels) {
388 samplerate = vi->rate; 387 samplerate = vi->rate;
389 channels = vi->channels; 388 channels = vi->channels;
390 playback->output->buffer_free(); 389 while(playback->output->buffer_playing()) g_usleep(50000);
391 playback->output->buffer_free();
392 playback->output->close_audio(); 390 playback->output->close_audio();
393 if (!playback->output-> 391 if (!playback->output->
394 open_audio(FMT_FLOAT, vi->rate, vi->channels)) { 392 open_audio(FMT_FLOAT, vi->rate, vi->channels)) {
395 playback->error = TRUE; 393 playback->error = TRUE;
396 playback->eof = TRUE; 394 playback->eof = TRUE;
438 last_section = current_section; 436 last_section = current_section;
439 437
440 } 438 }
441 } /* main loop */ 439 } /* main loop */
442 440
443 if (!playback->error) 441 if (!playback->error) {
442 /*this loop makes it not skip the last ~4 seconds, but the playback
443 * timer isn't updated in this period, so it still needs a bit of work
444 *
445 * majeru
446 */
447 if(playback->eof) /* do it only on EOF --asphyx */
448 while(playback->output->buffer_playing()) {
449 AUDDBG("waiting for empty output buffer\n");
450 g_usleep(50000);
451 }
452
444 playback->output->close_audio(); 453 playback->output->close_audio();
445 /* fall through intentional */ 454 }
446
447 /*this loop makes it not skip the last ~4 seconds, but the playback
448 * timer isn't updated in this period, so it still needs a bit of work
449 *
450 * majeru
451 */
452 while(playback->output->buffer_playing()&& playback->output->buffer_free())
453 g_usleep(50000);
454 455
455 456
456 play_cleanup: 457 play_cleanup:
457 g_free(title); 458 g_free(title);
458 459
462 */ 463 */
463 g_mutex_lock(vf_mutex); 464 g_mutex_lock(vf_mutex);
464 ov_clear(&vf); 465 ov_clear(&vf);
465 g_mutex_unlock(vf_mutex); 466 g_mutex_unlock(vf_mutex);
466 playback->playing = 0; 467 playback->playing = 0;
467 playback->output->buffer_free();
468 return NULL; 468 return NULL;
469 } 469 }
470 470
471 static void 471 static void
472 vorbis_play(InputPlayback *playback) 472 vorbis_play(InputPlayback *playback)
483 static void 483 static void
484 vorbis_stop(InputPlayback *playback) 484 vorbis_stop(InputPlayback *playback)
485 { 485 {
486 if (playback->playing) { 486 if (playback->playing) {
487 playback->playing = 0; 487 playback->playing = 0;
488 AUDDBG("waiting for playback thread finished\n");
488 g_thread_join(thread); 489 g_thread_join(thread);
490 AUDDBG("playback finished\n");
489 } 491 }
490 } 492 }
491 493
492 static void 494 static void
493 vorbis_pause(InputPlayback *playback, short p) 495 vorbis_pause(InputPlayback *playback, short p)