"Fossies" - the Fresh Open Source Software Archive

Member "ssr-0.4.2/src/AV/Input/ALSAInput.h" (18 May 2020, 1811 Bytes) of package /linux/privat/ssr-0.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ALSAInput.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.4.1_vs_0.4.2.

    1 /*
    2 Copyright (c) 2012-2020 Maarten Baert <maarten-baert@hotmail.com>
    3 
    4 This file is part of SimpleScreenRecorder.
    5 
    6 SimpleScreenRecorder is free software: you can redistribute it and/or modify
    7 it under the terms of the GNU General Public License as published by
    8 the Free Software Foundation, either version 3 of the License, or
    9 (at your option) any later version.
   10 
   11 SimpleScreenRecorder is distributed in the hope that it will be useful,
   12 but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 GNU General Public License for more details.
   15 
   16 You should have received a copy of the GNU General Public License
   17 along with SimpleScreenRecorder.  If not, see <http://www.gnu.org/licenses/>.
   18 */
   19 
   20 #pragma once
   21 #include "Global.h"
   22 
   23 #if SSR_USE_ALSA
   24 
   25 #include "SourceSink.h"
   26 #include "MutexDataPair.h"
   27 
   28 #include <alsa/asoundlib.h>
   29 
   30 class ALSAInput : public AudioSource {
   31 
   32 public:
   33     struct Source {
   34         std::string m_name, m_description;
   35         inline Source(const std::string& name, const std::string& description) : m_name(name), m_description(description) {}
   36     };
   37 
   38 private:
   39     static const int64_t START_DELAY;
   40 
   41 private:
   42     QString m_source_name;
   43     AVSampleFormat m_sample_format;
   44     bool m_convert_24_to_32;
   45     unsigned int m_sample_rate, m_channels;
   46     unsigned int m_period_size, m_buffer_size;
   47 
   48     snd_pcm_t *m_alsa_pcm;
   49 
   50     std::thread m_thread;
   51     std::atomic<bool> m_should_stop, m_error_occurred;
   52 
   53 public:
   54     ALSAInput(const QString& source_name, unsigned int sample_rate);
   55     ~ALSAInput();
   56 
   57     // Returns whether an error has occurred in the input thread.
   58     // This function is thread-safe.
   59     inline bool HasErrorOccurred() { return m_error_occurred; }
   60 
   61 public:
   62     static std::vector<Source> GetSourceList();
   63 
   64 private:
   65     void Init();
   66     void Free();
   67 
   68     void InputThread();
   69 
   70 };
   71 
   72 #endif