mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	make use of new alsa SND_PCM_NO_AUTO_xxx flags; redirect alsa errors to normal PA log system
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2245 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									0f28de6f17
								
							
						
					
					
						commit
						1c5f66519d
					
				
					 2 changed files with 44 additions and 4 deletions
				
			
		| 
						 | 
					@ -36,6 +36,7 @@
 | 
				
			||||||
#include <pulsecore/log.h>
 | 
					#include <pulsecore/log.h>
 | 
				
			||||||
#include <pulsecore/macro.h>
 | 
					#include <pulsecore/macro.h>
 | 
				
			||||||
#include <pulsecore/core-util.h>
 | 
					#include <pulsecore/core-util.h>
 | 
				
			||||||
 | 
					#include <pulsecore/atomic.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "alsa-util.h"
 | 
					#include "alsa-util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -571,7 +572,11 @@ snd_pcm_t *pa_alsa_open_by_device_id(
 | 
				
			||||||
        d = pa_sprintf_malloc("%s:%s", device_table[i].name, dev_id);
 | 
					        d = pa_sprintf_malloc("%s:%s", device_table[i].name, dev_id);
 | 
				
			||||||
        pa_log_debug("Trying %s...", d);
 | 
					        pa_log_debug("Trying %s...", d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ((err = snd_pcm_open(&pcm_handle, d, mode, SND_PCM_NONBLOCK)) < 0) {
 | 
					        if ((err = snd_pcm_open(&pcm_handle, d, mode,
 | 
				
			||||||
 | 
					                                SND_PCM_NONBLOCK|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_RESAMPLE|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_CHANNELS|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_FORMAT)) < 0) {
 | 
				
			||||||
            pa_log_info("Couldn't open PCM device %s: %s", d, snd_strerror(err));
 | 
					            pa_log_info("Couldn't open PCM device %s: %s", d, snd_strerror(err));
 | 
				
			||||||
            pa_xfree(d);
 | 
					            pa_xfree(d);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
| 
						 | 
					@ -595,9 +600,9 @@ snd_pcm_t *pa_alsa_open_by_device_id(
 | 
				
			||||||
        return pcm_handle;
 | 
					        return pcm_handle;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* OK, we didn't find any good device, so let's try the raw hw: stuff */
 | 
					    /* OK, we didn't find any good device, so let's try the raw plughw: stuff */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    d = pa_sprintf_malloc("hw:%s", dev_id);
 | 
					    d = pa_sprintf_malloc("plughw:%s", dev_id);
 | 
				
			||||||
    pa_log_debug("Trying %s as last resort...", d);
 | 
					    pa_log_debug("Trying %s as last resort...", d);
 | 
				
			||||||
    pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched);
 | 
					    pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched);
 | 
				
			||||||
    pa_xfree(d);
 | 
					    pa_xfree(d);
 | 
				
			||||||
| 
						 | 
					@ -632,7 +637,10 @@ snd_pcm_t *pa_alsa_open_by_device_string(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (;;) {
 | 
					    for (;;) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ((err = snd_pcm_open(&pcm_handle, d, mode, SND_PCM_NONBLOCK)) < 0) {
 | 
					        if ((err = snd_pcm_open(&pcm_handle, d, mode, SND_PCM_NONBLOCK|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_RESAMPLE|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_CHANNELS|
 | 
				
			||||||
 | 
					                                SND_PCM_NO_AUTO_FORMAT)) < 0) {
 | 
				
			||||||
            pa_log("Error opening PCM device %s: %s", d, snd_strerror(err));
 | 
					            pa_log("Error opening PCM device %s: %s", d, snd_strerror(err));
 | 
				
			||||||
            pa_xfree(d);
 | 
					            pa_xfree(d);
 | 
				
			||||||
            return NULL;
 | 
					            return NULL;
 | 
				
			||||||
| 
						 | 
					@ -937,3 +945,31 @@ void pa_alsa_dump_status(snd_pcm_t *pcm) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert_se(snd_output_close(out) == 0);
 | 
					    pa_assert_se(snd_output_close(out) == 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void alsa_error_handler(const char *file, int line, const char *function, int err, const char *fmt,...) {
 | 
				
			||||||
 | 
					    va_list ap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    va_start(ap, fmt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_log_levelv_meta(PA_LOG_WARN, file, line, function, fmt, ap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    va_end(ap);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static pa_atomic_t n_error_handler_installed = PA_ATOMIC_INIT(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_alsa_redirect_errors_inc(void) {
 | 
				
			||||||
 | 
					    /* This is not really thread safe, but we do our best */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (pa_atomic_inc(&n_error_handler_installed) == 0)
 | 
				
			||||||
 | 
					        snd_lib_error_set_handler(alsa_error_handler);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_alsa_redirect_errors_dec(void) {
 | 
				
			||||||
 | 
					    int r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_assert_se((r = pa_atomic_dec(&n_error_handler_installed)) >= 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (r == 1)
 | 
				
			||||||
 | 
					        snd_lib_error_set_handler(NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,4 +85,8 @@ void pa_alsa_0dB_capture(snd_mixer_elem_t *elem);
 | 
				
			||||||
void pa_alsa_dump(snd_pcm_t *pcm);
 | 
					void pa_alsa_dump(snd_pcm_t *pcm);
 | 
				
			||||||
void pa_alsa_dump_status(snd_pcm_t *pcm);
 | 
					void pa_alsa_dump_status(snd_pcm_t *pcm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void pa_alsa_redirect_errors_inc(void);
 | 
				
			||||||
 | 
					void pa_alsa_redirect_errors_dec(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue