kwave  18.07.70
Record-PulseAudio.cpp File Reference
#include "config.h"
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <limits>
#include <pulse/thread-mainloop.h>
#include <QApplication>
#include <QCursor>
#include <QFileInfo>
#include <QLatin1Char>
#include <QLocale>
#include <QString>
#include <QVariant>
#include <QtGlobal>
#include <KLocalizedString>
#include <KUser>
#include "libkwave/Compression.h"
#include "libkwave/SampleFormat.h"
#include "libkwave/String.h"
#include "libkwave/Utils.h"
#include "libkwave/memcpy.h"
#include "Record-PulseAudio.h"
Include dependency graph for Record-PulseAudio.cpp:

Go to the source code of this file.

Macros

#define ELEMENTS_OF(__array__)   (sizeof(__array__) / sizeof(__array__[0]))
 
#define TIMEOUT_WAIT_DEVICE_SCAN   10000
 
#define TIMEOUT_CONNECT_TO_SERVER   20000
 
#define TIMEOUT_CONNECT_RECORD   10000
 
#define TIMEOUT_DISCONNECT_STREAM   10000
 
#define DBG_CASE(x)   case x: qDebug("RecordPulseAudio -> " #x ); break
 
#define DBG_CASE(x)   case x: qDebug("RecordPulseAudio -> " #x ); break
 

Functions

static Kwave::SampleFormat::Format sample_format_of (pa_sample_format_t fmt)
 
static Kwave::byte_order_t endian_of (pa_sample_format_t fmt)
 
static Kwave::Compression::Type compression_of (pa_sample_format_t fmt)
 
static int bits_of (pa_sample_format_t fmt)
 
static int poll_func (struct pollfd *ufds, unsigned long nfds, int timeout, void *userdata)
 

Variables

static const pa_sample_format_t _known_formats []
 

Macro Definition Documentation

◆ DBG_CASE [1/2]

#define DBG_CASE (   x)    case x: qDebug("RecordPulseAudio -> " #x ); break

◆ DBG_CASE [2/2]

#define DBG_CASE (   x)    case x: qDebug("RecordPulseAudio -> " #x ); break

◆ ELEMENTS_OF

#define ELEMENTS_OF (   __array__)    (sizeof(__array__) / sizeof(__array__[0]))

helper macro: returns the number of elements in an array

Definition at line 50 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::detectSampleRates(), and Kwave::RecordPulseAudio::detectSupportedFormats().

◆ TIMEOUT_CONNECT_RECORD

#define TIMEOUT_CONNECT_RECORD   10000

timeout to wait for record [ms]

See also
open()

Definition at line 68 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::initialize().

◆ TIMEOUT_CONNECT_TO_SERVER

#define TIMEOUT_CONNECT_TO_SERVER   20000

timeout to wait for the connection to the server [ms]

See also
connectToServer()

Definition at line 62 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::connectToServer().

◆ TIMEOUT_DISCONNECT_STREAM

#define TIMEOUT_DISCONNECT_STREAM   10000

timeout to wait for disconnecting the recording stream [ms]

See also
close()

Definition at line 74 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::close().

◆ TIMEOUT_WAIT_DEVICE_SCAN

#define TIMEOUT_WAIT_DEVICE_SCAN   10000

timeout for the device scan [ms]

See also
scanDevices()

Definition at line 56 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::scanDevices().

Function Documentation

◆ bits_of()

static int bits_of ( pa_sample_format_t  fmt)
static

Definition at line 166 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::detectSampleFormats(), Kwave::RecordPulseAudio::detectSupportedFormats(), Kwave::RecordPulseAudio::mode2format(), and Kwave::RecordPulseAudio::supportedBits().

167 {
168  int bits = 0;
169  switch (fmt) {
170  case PA_SAMPLE_ULAW: /* FALLTHROUGH */
171  case PA_SAMPLE_ALAW: /* FALLTHROUGH */
172  case PA_SAMPLE_U8:
173  bits = 8;
174  break;
175  case PA_SAMPLE_S16LE: /* FALLTHROUGH */
176  case PA_SAMPLE_S16BE:
177  bits = 16;
178  break;
179  case PA_SAMPLE_S24LE: /* FALLTHROUGH */
180  case PA_SAMPLE_S24BE: /* FALLTHROUGH */
181  case PA_SAMPLE_S24_32LE: /* FALLTHROUGH */
182  case PA_SAMPLE_S24_32BE:
183  bits = 24;
184  break;
185  case PA_SAMPLE_S32LE: /* FALLTHROUGH */
186  case PA_SAMPLE_S32BE: /* FALLTHROUGH */
187  case PA_SAMPLE_FLOAT32LE: /* FALLTHROUGH */
188  case PA_SAMPLE_FLOAT32BE:
189  bits = 32;
190  break;
191  default:
192  bits = 0;
193  break;
194  }
195  return bits;
196 }
Here is the caller graph for this function:

◆ compression_of()

static Kwave::Compression::Type compression_of ( pa_sample_format_t  fmt)
static

Definition at line 148 of file Record-PulseAudio.cpp.

References Kwave::Compression::G711_ALAW, Kwave::Compression::G711_ULAW, and Kwave::Compression::NONE.

Referenced by Kwave::RecordPulseAudio::detectCompressions(), Kwave::RecordPulseAudio::detectSampleFormats(), Kwave::RecordPulseAudio::detectSupportedFormats(), Kwave::RecordPulseAudio::mode2format(), and Kwave::RecordPulseAudio::supportedBits().

149 {
151  switch (fmt) {
152  case PA_SAMPLE_ULAW:
153  compression = Kwave::Compression::G711_ULAW;
154  break;
155  case PA_SAMPLE_ALAW:
156  compression = Kwave::Compression::G711_ALAW;
157  break;
158  default:
159  compression = Kwave::Compression::NONE;
160  break;
161  }
162  return compression;
163 }
Here is the caller graph for this function:

◆ endian_of()

static Kwave::byte_order_t endian_of ( pa_sample_format_t  fmt)
static

find out the endianness of an PulseAudio format

Definition at line 138 of file Record-PulseAudio.cpp.

References Kwave::BigEndian, Kwave::CpuEndian, and Kwave::LittleEndian.

Referenced by Kwave::RecordPulseAudio::detectSupportedFormats(), and Kwave::RecordPulseAudio::endianness().

139 {
140  if (pa_sample_format_is_le(fmt) == 1)
141  return Kwave::LittleEndian;
142  if (pa_sample_format_is_be(fmt) == 1)
143  return Kwave::BigEndian;
144  return Kwave::CpuEndian;
145 }
Here is the caller graph for this function:

◆ poll_func()

static int poll_func ( struct pollfd *  ufds,
unsigned long  nfds,
int  timeout,
void *  userdata 
)
static

Definition at line 862 of file Record-PulseAudio.cpp.

References Kwave::RecordPulseAudio::mainloopPoll().

Referenced by Kwave::RecordPulseAudio::connectToServer().

864 {
866  static_cast<Kwave::RecordPulseAudio *>(userdata);
867  Q_ASSERT(dev);
868  if (!dev) return -1;
869 
870  return dev->mainloopPoll(ufds, nfds, timeout);
871 }
int mainloopPoll(struct pollfd *ufds, unsigned long int nfds, int timeout)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sample_format_of()

static Kwave::SampleFormat::Format sample_format_of ( pa_sample_format_t  fmt)
static

find out the SampleFormat of an PulseAudio format

Definition at line 118 of file Record-PulseAudio.cpp.

References Kwave::SampleFormat::Float, Kwave::SampleFormat::Signed, Kwave::SampleFormat::Unknown, and Kwave::SampleFormat::Unsigned.

Referenced by Kwave::RecordPulseAudio::detectSampleFormats(), Kwave::RecordPulseAudio::detectSupportedFormats(), and Kwave::RecordPulseAudio::mode2format().

119 {
121  switch (fmt) {
122  case PA_SAMPLE_FLOAT32LE: /* FALLTHROUGH */
123  case PA_SAMPLE_FLOAT32BE:
124  sampleFormat = Kwave::SampleFormat::Float;
125  break;
126  case PA_SAMPLE_U8:
127  sampleFormat = Kwave::SampleFormat::Unsigned;
128  break;
129  default:
130  sampleFormat = Kwave::SampleFormat::Signed;
131  break;
132  }
133  return sampleFormat;
134 }
Here is the caller graph for this function:

Variable Documentation

◆ _known_formats

const pa_sample_format_t _known_formats[]
static
Initial value:
=
{
PA_SAMPLE_U8,
PA_SAMPLE_S16LE, PA_SAMPLE_S16BE,
PA_SAMPLE_S24LE, PA_SAMPLE_S24BE,
PA_SAMPLE_S24_32LE, PA_SAMPLE_S24_32BE,
PA_SAMPLE_S32LE, PA_SAMPLE_S32BE,
PA_SAMPLE_FLOAT32LE, PA_SAMPLE_FLOAT32BE,
PA_SAMPLE_ULAW,
PA_SAMPLE_ALAW
}

Global list of all known sample formats.

Note
this list should be sorted so that the most preferable formats come first in the list. When searching for a format that matches a given set of parameters, the first entry is taken.

The sort order should be:

  • compression: none -> ulaw -> alaw -> adpcm -> mpeg ...
  • bits per sample: ascending
  • sample format: signed -> unsigned -> float -> double ...
  • endianness: cpu -> little -> big
  • bytes per sample: ascending

Definition at line 89 of file Record-PulseAudio.cpp.

Referenced by Kwave::RecordPulseAudio::detectSupportedFormats().