mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	* if an ALSA device doesn't support the channel count requested, use what ALSA suggests instead
* if an ALSA device doesn't support the sampling freq requested, use what ALSA suggests and resample if this deviates more than 10% from what we requested * fix segfault freeing an unitialized mixer_fdl field git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@992 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									821a49b967
								
							
						
					
					
						commit
						bb820db4b5
					
				
					 4 changed files with 36 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -249,11 +249,12 @@ int pa_alsa_fdlist_init_mixer(struct pa_alsa_fdlist *fdl, snd_mixer_t *mixer_han
 | 
			
		|||
 | 
			
		||||
/* Set the hardware parameters of the given ALSA device. Returns the
 | 
			
		||||
 * selected fragment settings in *period and *period_size */
 | 
			
		||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) {
 | 
			
		||||
int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, pa_sample_spec *ss, uint32_t *periods, snd_pcm_uframes_t *period_size) {
 | 
			
		||||
    int ret = -1;
 | 
			
		||||
    snd_pcm_uframes_t buffer_size;
 | 
			
		||||
    snd_pcm_hw_params_t *hwparams = NULL;
 | 
			
		||||
    unsigned int r = ss->rate;
 | 
			
		||||
    unsigned int c = ss->channels;
 | 
			
		||||
    
 | 
			
		||||
    static const snd_pcm_format_t format_trans[] = {
 | 
			
		||||
        [PA_SAMPLE_U8] = SND_PCM_FORMAT_U8,
 | 
			
		||||
| 
						 | 
				
			
			@ -273,14 +274,24 @@ int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint3
 | 
			
		|||
    	(ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0 ||
 | 
			
		||||
        (ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[ss->format])) < 0 ||
 | 
			
		||||
    	(ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &r, NULL)) < 0 ||
 | 
			
		||||
        (ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, ss->channels)) < 0 ||
 | 
			
		||||
        (ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0 || 
 | 
			
		||||
        (*period_size > 0 && (ret = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, period_size, NULL)) < 0) ||
 | 
			
		||||
        (*periods > 0 && (ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size)) < 0) ||
 | 
			
		||||
        (ret = snd_pcm_hw_params(pcm_handle, hwparams)) < 0)
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (ss->rate != r) 
 | 
			
		||||
    if (ss->rate != r) {
 | 
			
		||||
        pa_log_info(__FILE__": device doesn't support %u Hz, changed to %u Hz.", ss->rate, r);
 | 
			
		||||
 | 
			
		||||
        /* If the sample rate deviates too much, we need to resample */
 | 
			
		||||
        if (r < ss->rate*.9 || r > ss->rate*1.1)
 | 
			
		||||
            ss->rate = r;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (ss->channels != c) {
 | 
			
		||||
        pa_log_info(__FILE__": device doesn't support %u channels, changed to %u.", ss->channels, c);
 | 
			
		||||
        ss->channels = c;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if ((ret = snd_pcm_prepare(pcm_handle)) < 0)
 | 
			
		||||
        goto finish;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue