comparison src/madplug/decoder.c @ 896:f0846bdd9de6 trunk

[svn] - small cleanups.
author yaz
date Sat, 24 Mar 2007 09:44:44 -0700
parents 0f9c8d4d3ac4
children a8494c2a87eb
comparison
equal deleted inserted replaced
895:5d7e6f06c9b7 896:f0846bdd9de6
375 g_message("e: scan_file"); 375 g_message("e: scan_file");
376 #endif /* DEBUG */ 376 #endif /* DEBUG */
377 return (info->frames != 0 || info->remote == TRUE); 377 return (info->frames != 0 || info->remote == TRUE);
378 } 378 }
379 379
380 // sanity check for audio open parameters
381 static gboolean check_audio_param(struct mad_info_t *info)
382 {
383 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
384 return FALSE;
385 if(info->freq < 0) // not sure about maximum frequency. --yaz
386 return FALSE;
387 if(info->channels < 1 || info->channels > 2)
388 return FALSE;
389
390 return TRUE;
391 }
392
380 gpointer decode_loop(gpointer arg) 393 gpointer decode_loop(gpointer arg)
381 { 394 {
382 unsigned char buffer[BUFFER_SIZE]; 395 unsigned char buffer[BUFFER_SIZE];
383 int len; 396 int len;
384 gboolean seek_skip = FALSE; 397 gboolean seek_skip = FALSE;
411 } 424 }
412 425
413 #ifdef DEBUG 426 #ifdef DEBUG
414 g_message("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels); 427 g_message("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels);
415 #endif 428 #endif
416 // sanity check. 429
417 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE) 430 if(check_audio_param(info) == FALSE)
418 return NULL; 431 return NULL;
419 if(info->freq < 0) // not sure about maximum frequency. --yaz 432
420 return NULL;
421 if(info->channels < 1 || info->channels > 2)
422 return NULL;
423
424 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) { 433 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) {
425 g_mutex_lock(pb_mutex); 434 g_mutex_lock(pb_mutex);
426 info->playback->error = TRUE; 435 info->playback->error = TRUE;
427 info->playback->eof = 1; 436 info->playback->eof = 1;
428 g_mutex_unlock(pb_mutex); 437 g_mutex_unlock(pb_mutex);
504 } 513 }
505 514
506 while (info->playback->playing) { 515 while (info->playback->playing) {
507 if (info->seek != -1 && info->size > 0) { 516 if (info->seek != -1 && info->size > 0) {
508 #ifdef DEBUG 517 #ifdef DEBUG
509 g_message("seeking: %d", info->seek); 518 g_message("seeking: %ld", info->seek);
510 #endif 519 #endif
511 int new_position; 520 int new_position;
512 gulong milliseconds = 521 gulong milliseconds =
513 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS); 522 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS);
514 if (info->seek >= milliseconds) 523 if (info->seek >= milliseconds)
596 #endif /* DEBUG */ 605 #endif /* DEBUG */
597 info->freq = frame.header.samplerate; 606 info->freq = frame.header.samplerate;
598 info->channels = MAD_NCHANNELS(&frame.header); 607 info->channels = MAD_NCHANNELS(&frame.header);
599 info->playback->output->close_audio(); 608 info->playback->output->close_audio();
600 609
601 // sanity check. 610 if(check_audio_param(info) == FALSE)
602 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
603 return NULL;
604 if(info->freq < 0) // not sure about maximum frequency. --yaz
605 return NULL;
606 if(info->channels < 1 || info->channels > 2)
607 return NULL; 611 return NULL;
608 612
609 if (!info->playback->output->open_audio(info->fmt, info->freq, 613 if (!info->playback->output->open_audio(info->fmt, info->freq,
610 info->channels)) { 614 info->channels)) {
611 g_mutex_lock(pb_mutex); 615 g_mutex_lock(pb_mutex);
646 g_get_current_time(&sleeptime); 650 g_get_current_time(&sleeptime);
647 g_time_val_add(&sleeptime, 500000); 651 g_time_val_add(&sleeptime, 500000);
648 652
649 g_mutex_lock(mad_mutex); 653 g_mutex_lock(mad_mutex);
650 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime); 654 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime);
655 g_mutex_unlock(mad_mutex);
651 if (!info->playback->playing) { 656 if (!info->playback->playing) {
652 g_mutex_unlock(mad_mutex);
653 break; 657 break;
654 } 658 }
655 g_mutex_unlock(mad_mutex); 659
656 } 660 }
657 } 661 }
658 #ifdef DEBUG 662 #ifdef DEBUG
659 g_message("e: decode"); 663 g_message("e: decode");
660 #endif /* DEBUG */ 664 #endif /* DEBUG */