comparison libao2/ao_alsa.c @ 26757:0fdf04b07ecb

cosmetics: Remove pointless parentheses from return statements.
author diego
date Fri, 16 May 2008 09:31:55 +0000
parents 2c238fa777ff
children e47193172586
comparison
equal deleted inserted replaced
26756:c43ce7268677 26757:0fdf04b07ecb
230 snd_mixer_close(handle); 230 snd_mixer_close(handle);
231 return CONTROL_OK; 231 return CONTROL_OK;
232 } 232 }
233 233
234 } //end switch 234 } //end switch
235 return(CONTROL_UNKNOWN); 235 return CONTROL_UNKNOWN;
236 } 236 }
237 237
238 static void parse_device (char *dest, const char *src, int len) 238 static void parse_device (char *dest, const char *src, int len)
239 { 239 {
240 char *tmp; 240 char *tmp;
496 { 496 {
497 if (err != -EBUSY && ao_noblock) { 497 if (err != -EBUSY && ao_noblock) {
498 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_OpenInNonblockModeFailed); 498 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_OpenInNonblockModeFailed);
499 if ((err = try_open_device(alsa_device, 0, format == AF_FORMAT_AC3)) < 0) { 499 if ((err = try_open_device(alsa_device, 0, format == AF_FORMAT_AC3)) < 0) {
500 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err)); 500 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err));
501 return(0); 501 return 0;
502 } 502 }
503 } else { 503 } else {
504 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err)); 504 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err));
505 return(0); 505 return 0;
506 } 506 }
507 } 507 }
508 508
509 if ((err = snd_pcm_nonblock(alsa_handler, 0)) < 0) { 509 if ((err = snd_pcm_nonblock(alsa_handler, 0)) < 0) {
510 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_ErrorSetBlockMode, snd_strerror(err)); 510 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_ErrorSetBlockMode, snd_strerror(err));
518 // setting hw-parameters 518 // setting hw-parameters
519 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) 519 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
520 { 520 {
521 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToGetInitialParameters, 521 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToGetInitialParameters,
522 snd_strerror(err)); 522 snd_strerror(err));
523 return(0); 523 return 0;
524 } 524 }
525 525
526 err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams, 526 err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
527 SND_PCM_ACCESS_RW_INTERLEAVED); 527 SND_PCM_ACCESS_RW_INTERLEAVED);
528 if (err < 0) { 528 if (err < 0) {
529 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetAccessType, 529 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetAccessType,
530 snd_strerror(err)); 530 snd_strerror(err));
531 return (0); 531 return 0;
532 } 532 }
533 533
534 /* workaround for nonsupported formats 534 /* workaround for nonsupported formats
535 sets default format to S16_LE if the given formats aren't supported */ 535 sets default format to S16_LE if the given formats aren't supported */
536 if ((err = snd_pcm_hw_params_test_format(alsa_handler, alsa_hwparams, 536 if ((err = snd_pcm_hw_params_test_format(alsa_handler, alsa_hwparams,
545 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, 545 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
546 alsa_format)) < 0) 546 alsa_format)) < 0)
547 { 547 {
548 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetFormat, 548 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetFormat,
549 snd_strerror(err)); 549 snd_strerror(err));
550 return(0); 550 return 0;
551 } 551 }
552 552
553 if ((err = snd_pcm_hw_params_set_channels_near(alsa_handler, alsa_hwparams, 553 if ((err = snd_pcm_hw_params_set_channels_near(alsa_handler, alsa_hwparams,
554 &ao_data.channels)) < 0) 554 &ao_data.channels)) < 0)
555 { 555 {
556 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetChannels, 556 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetChannels,
557 snd_strerror(err)); 557 snd_strerror(err));
558 return(0); 558 return 0;
559 } 559 }
560 560
561 /* workaround for buggy rate plugin (should be fixed in ALSA 1.0.11) 561 /* workaround for buggy rate plugin (should be fixed in ALSA 1.0.11)
562 prefer our own resampler */ 562 prefer our own resampler */
563 #if SND_LIB_VERSION >= 0x010009 563 #if SND_LIB_VERSION >= 0x010009
564 if ((err = snd_pcm_hw_params_set_rate_resample(alsa_handler, alsa_hwparams, 564 if ((err = snd_pcm_hw_params_set_rate_resample(alsa_handler, alsa_hwparams,
565 0)) < 0) 565 0)) < 0)
566 { 566 {
567 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToDisableResampling, 567 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToDisableResampling,
568 snd_strerror(err)); 568 snd_strerror(err));
569 return(0); 569 return 0;
570 } 570 }
571 #endif 571 #endif
572 572
573 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, 573 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams,
574 &ao_data.samplerate, NULL)) < 0) 574 &ao_data.samplerate, NULL)) < 0)
575 { 575 {
576 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetSamplerate2, 576 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetSamplerate2,
577 snd_strerror(err)); 577 snd_strerror(err));
578 return(0); 578 return 0;
579 } 579 }
580 580
581 bytes_per_sample = snd_pcm_format_physical_width(alsa_format) / 8; 581 bytes_per_sample = snd_pcm_format_physical_width(alsa_format) / 8;
582 bytes_per_sample *= ao_data.channels; 582 bytes_per_sample *= ao_data.channels;
583 ao_data.bps = ao_data.samplerate * bytes_per_sample; 583 ao_data.bps = ao_data.samplerate * bytes_per_sample;
590 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, 590 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams,
591 &alsa_buffer_time, NULL)) < 0) 591 &alsa_buffer_time, NULL)) < 0)
592 { 592 {
593 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetBufferTimeNear, 593 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetBufferTimeNear,
594 snd_strerror(err)); 594 snd_strerror(err));
595 return(0); 595 return 0;
596 } else 596 } else
597 alsa_buffer_time = err; 597 alsa_buffer_time = err;
598 598
599 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, 599 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams,
600 &alsa_period_time, NULL)) < 0) 600 &alsa_period_time, NULL)) < 0)
709 ao_data.samplerate, ao_data.channels, bytes_per_sample, ao_data.buffersize, 709 ao_data.samplerate, ao_data.channels, bytes_per_sample, ao_data.buffersize,
710 snd_pcm_format_description(alsa_format)); 710 snd_pcm_format_description(alsa_format));
711 711
712 } // end switch alsa_handler (spdif) 712 } // end switch alsa_handler (spdif)
713 alsa_can_pause = snd_pcm_hw_params_can_pause(alsa_hwparams); 713 alsa_can_pause = snd_pcm_hw_params_can_pause(alsa_hwparams);
714 return(1); 714 return 1;
715 } // end init 715 } // end init
716 716
717 717
718 /* close audio device */ 718 /* close audio device */
719 static void uninit(int immed) 719 static void uninit(int immed)
835 if (res < 0) { 835 if (res < 0) {
836 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_WriteError, snd_strerror(res)); 836 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_WriteError, snd_strerror(res));
837 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_TryingToResetSoundcard); 837 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_TryingToResetSoundcard);
838 if ((res = snd_pcm_prepare(alsa_handler)) < 0) { 838 if ((res = snd_pcm_prepare(alsa_handler)) < 0) {
839 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(res)); 839 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(res));
840 return(0); 840 return 0;
841 break; 841 break;
842 } 842 }
843 } 843 }
844 } while (res == 0); 844 } while (res == 0);
845 845
855 snd_pcm_status_alloca(&status); 855 snd_pcm_status_alloca(&status);
856 856
857 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) 857 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
858 { 858 {
859 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_CannotGetPcmStatus, snd_strerror(ret)); 859 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_CannotGetPcmStatus, snd_strerror(ret));
860 return(0); 860 return 0;
861 } 861 }
862 862
863 ret = snd_pcm_status_get_avail(status) * bytes_per_sample; 863 ret = snd_pcm_status_get_avail(status) * bytes_per_sample;
864 if (ret > ao_data.buffersize) // Buffer underrun? 864 if (ret > ao_data.buffersize) // Buffer underrun?
865 ret = ao_data.buffersize; 865 ret = ao_data.buffersize;
866 return(ret); 866 return ret;
867 } 867 }
868 868
869 /* delay in seconds between first and last sample in buffer */ 869 /* delay in seconds between first and last sample in buffer */
870 static float get_delay(void) 870 static float get_delay(void)
871 { 871 {
882 #endif 882 #endif
883 delay = 0; 883 delay = 0;
884 } 884 }
885 return (float)delay / (float)ao_data.samplerate; 885 return (float)delay / (float)ao_data.samplerate;
886 } else { 886 } else {
887 return(0); 887 return 0;
888 } 888 }
889 } 889 }