]> git.sesse.net Git - nageru/blobdiff - alsa_input.h
Make ALSA initialization errors fail-soft.
[nageru] / alsa_input.h
index 07e8fe52e18dac164cdc6d967e92e3cf48fe1042..a93b984fb2ec48ff0d32d4fe4fcfa650317c2a04 100644 (file)
@@ -30,6 +30,11 @@ public:
        ALSAInput(const char *device, unsigned sample_rate, unsigned num_channels, audio_callback_t audio_callback, ALSAPool *parent_pool, unsigned internal_dev_index);
        ~ALSAInput();
 
+       // If not called before start_capture_thread(), the capture thread
+       // will call it until it succeeds.
+       bool open_device();
+
+       // Not valid before the device has been successfully opened.
        // NOTE: Might very well be different from the sample rate given to the
        // constructor, since the card might not support the one you wanted.
        unsigned get_sample_rate() const { return sample_rate; }
@@ -40,7 +45,13 @@ public:
 private:
        void capture_thread_func();
        int64_t frames_to_pts(uint64_t n) const;
-       void die_on_error(const char *func_name, int err);
+
+       enum class CaptureEndReason {
+               REQUESTED_QUIT,
+               DEVICE_GONE,
+               OTHER_ERROR
+       };
+       CaptureEndReason do_capture();
 
        std::string device;
        unsigned sample_rate, num_channels, num_periods;
@@ -49,7 +60,7 @@ private:
        bmusb::AudioFormat audio_format;
        audio_callback_t audio_callback;
 
-       snd_pcm_t *pcm_handle;
+       snd_pcm_t *pcm_handle = nullptr;
        std::thread capture_thread;
        std::atomic<bool> should_quit{false};
        std::unique_ptr<uint8_t[]> buffer;