prepare ALSA backend for half-duplex
authorRobin Gareus <robin@gareus.org>
Sun, 14 Jun 2015 18:43:29 +0000 (20:43 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 14 Jun 2015 20:26:06 +0000 (22:26 +0200)
libs/backends/alsa/alsa_audiobackend.cc
libs/backends/alsa/zita-alsa-pcmi.cc

index a2ed9f8b0780776c760bccaa36d9dc25a33907cf..4e65c9e4ba938c205a48c44571bc122960eb0ffb 100644 (file)
@@ -953,8 +953,8 @@ AlsaAudioBackend::register_system_audio_ports()
 {
        LatencyRange lr;
 
-       const int a_ins = _n_inputs > 0 ? _n_inputs : 2;
-       const int a_out = _n_outputs > 0 ? _n_outputs : 2;
+       const int a_ins = _n_inputs;
+       const int a_out = _n_outputs;
 
        /* audio ports */
        lr.min = lr.max = (_measure_latency ? 0 : _systemic_audio_input_latency);
index 6eead7e28bddc6d2b916bd88437a947c1eb24fe6..3c271b69073806f997e5dc4176ef28199dcf0ef3 100644 (file)
@@ -270,6 +270,9 @@ int Alsa_pcmi::play_init (snd_pcm_uframes_t len)
        const snd_pcm_channel_area_t   *a;
        int                            err;
 
+       if (!_play_handle) {
+               return 0;
+       }
        if ((err = snd_pcm_mmap_begin (_play_handle, &a, &_play_offs, &len)) < 0)
        {
                if (_debug & DEBUG_DATA) fprintf (stderr, "Alsa_pcmi: snd_pcm_mmap_begin(play): %s.\n", snd_strerror (err));
@@ -291,6 +294,10 @@ int Alsa_pcmi::capt_init (snd_pcm_uframes_t len)
        const snd_pcm_channel_area_t  *a;
        int                           err;
 
+       if (!_capt_handle) {
+               return 0;
+       }
+
        if ((err = snd_pcm_mmap_begin (_capt_handle, &a, &_capt_offs, &len)) < 0)
        {
                if (_debug & DEBUG_DATA) fprintf (stderr, "Alsa_pcmi: snd_pcm_mmap_begin(capt): %s.\n", snd_strerror (err));
@@ -326,12 +333,14 @@ void Alsa_pcmi::capt_chan  (int chan, float *dst, int len, int step)
 
 int Alsa_pcmi::play_done (int len)
 {
+       if (!_play_handle) return 0;
        return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
 }
 
 
 int Alsa_pcmi::capt_done (int len)
 {
+       if (!_capt_handle) return 0;
        return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
 }
 
@@ -394,7 +403,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                }
        }
 
-       if (! _play_handle || ! _capt_handle) return;
+       if (! _play_handle && ! _capt_handle) return;
 
        if (ctrl_name)
        {