ALSABackend: elaborate on start-up error cases
authorRobin Gareus <robin@gareus.org>
Tue, 3 Jun 2014 00:16:56 +0000 (02:16 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 4 Jun 2014 00:19:46 +0000 (02:19 +0200)
libs/backends/alsa/alsa_audiobackend.cc
libs/backends/alsa/zita-alsa-pcmi.cc

index 7ce83ddc40b989cfc722ba004b75d63971811c42..68f54fbe46cf9a3225e099af180908deba80f26c 100644 (file)
@@ -436,9 +436,17 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
 
        unsigned int pos = _capture_device.find(" ");
        _pcmi = new Alsa_pcmi (_capture_device.substr(0, pos).c_str(), _playback_device.substr(0, pos).c_str(), 0, _samplerate, _samples_per_period, _periods_per_cycle, 0);
+       switch (_pcmi->state ()) {
+               case 0: /* OK */ break;
+               case -1: PBD::error << _("AlsaAudioBackend: failed to open device.") << endmsg; break;
+               case -2: PBD::error << _("AlsaAudioBackend: failed to allocate parameters.") << endmsg; break;
+               case -3: PBD::error << _("AlsaAudioBackend: cannot set requested sample rate.") << endmsg; break;
+               case -4: PBD::error << _("AlsaAudioBackend: cannot set requested period size.") << endmsg; break;
+               case -5: PBD::error << _("AlsaAudioBackend: cannot set requested number of periods.") << endmsg; break;
+               case -6: PBD::error << _("AlsaAudioBackend: unsupported sample format.") << endmsg; break;
+               default: PBD::error << _("AlsaAudioBackend: initialization failed.") << endmsg; break;
+       }
        if (_pcmi->state ()) {
-               // TODO get detailed error from _pcmi
-               PBD::error << _("AlsaAudioBackend: failed to open device (see stderr for details).") << endmsg;
                delete _pcmi; _pcmi = 0;
                return -1;
        }
index 8947e1a12ee70b5f329bfe371ee0e0ba4728f620..10b8e08831cb80e76d1b233ceac3a972beb6670c 100644 (file)
@@ -410,6 +410,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                }
        }
 
+       _state = -2;
        if (_play_handle)
        {
                if (snd_pcm_hw_params_malloc (&_play_hwpar) < 0)
@@ -447,16 +448,19 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                if (snd_pcm_hw_params_get_rate (_play_hwpar, &fsamp, &dir) || (fsamp != _fsamp) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested sample rate for playback.\n");
+                       _state = -3;
                        return;
                }
                if (snd_pcm_hw_params_get_period_size (_play_hwpar, &fsize, &dir) || (fsize != _fsize) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested period size for playback.\n");
+                       _state = -4;
                        return;
                }
                if (snd_pcm_hw_params_get_periods (_play_hwpar, &nfrag, &dir) || (nfrag != _nfrag) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested number of periods for playback.\n");
+                       _state = -5;
                        return;
                }
 
@@ -503,6 +507,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle playback sample format.\n");
+                               _state = -6;
                                return;
                }
 #elif __BYTE_ORDER == __BIG_ENDIAN
@@ -540,6 +545,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle playback sample format.\n");
+                               _state = -6;
                                return;
                }
 #else
@@ -554,16 +560,19 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
                if (snd_pcm_hw_params_get_rate (_capt_hwpar, &fsamp, &dir) || (fsamp != _fsamp) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested sample rate for capture.\n");
+                       _state = -3;
                        return;
                }
                if (snd_pcm_hw_params_get_period_size (_capt_hwpar, &fsize, &dir) || (fsize != _fsize) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested period size for capture.\n");
+                       _state = -4;
                        return;
                }
                if (snd_pcm_hw_params_get_periods (_capt_hwpar, &nfrag, &dir) || (nfrag != _nfrag) || dir)
                {
                        if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't get requested number of periods for capture.\n");
+                       _state = -5;
                        return;
                }
 
@@ -605,6 +614,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle capture sample format.\n");
+                               _state = -6;
                                return;
                }
 #elif __BYTE_ORDER == __BIG_ENDIAN
@@ -636,6 +646,7 @@ void Alsa_pcmi::initialise (const char *play_name, const char *capt_name, const
 
                        default:
                                if (_debug & DEBUG_INIT) fprintf (stderr, "Alsa_pcmi: can't handle capture sample format.\n");
+                               _state = -6;
                                return;
                }
 #else