Qt 4.8
Signals | Public Functions | Public Variables | Private Types | Private Slots | Private Functions | Static Private Functions | Properties | List of all members
QAudioInputPrivate Class Reference

#include <qaudioinput_alsa_p.h>

Inheritance diagram for QAudioInputPrivate:
QAbstractAudioInput QAbstractAudioInput QAbstractAudioInput QObject QObject QObject

Signals

void processMore ()
 
- Signals inherited from QAbstractAudioInput
void notify ()
 This signal is emitted when x ms of audio data has been processed the interval set by setNotifyInterval(x). More...
 
void stateChanged (QAudio::State)
 This signal is emitted when the device state has changed. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void audioDeviceError ()
 
void audioDeviceFull ()
 
void audioDeviceStop ()
 
void audioThreadStart ()
 
void audioThreadStop ()
 
int bufferSize () const
 Returns the audio buffer size in milliseconds. More...
 
int bufferSize () const
 Returns the audio buffer size in milliseconds. More...
 
int bufferSize () const
 Returns the audio buffer size in milliseconds. More...
 
int bytesReady () const
 Returns the amount of audio data available to read in bytes. More...
 
int bytesReady () const
 Returns the amount of audio data available to read in bytes. More...
 
int bytesReady () const
 Returns the amount of audio data available to read in bytes. More...
 
void close ()
 
qint64 elapsedUSecs () const
 Returns the milliseconds since start() was called, including time in Idle and suspend states. More...
 
qint64 elapsedUSecs () const
 Returns the milliseconds since start() was called, including time in Idle and suspend states. More...
 
qint64 elapsedUSecs () const
 Returns the milliseconds since start() was called, including time in Idle and suspend states. More...
 
QAudio::Error error () const
 Returns the error state. More...
 
QAudio::Error error () const
 Returns the error state. More...
 
QAudio::Error error () const
 Returns the error state. More...
 
QAudioFormat format () const
 Returns the QAudioFormat being used. More...
 
QAudioFormat format () const
 Returns the QAudioFormat being used. More...
 
QAudioFormat format () const
 Returns the QAudioFormat being used. More...
 
void idle ()
 
int notifyInterval () const
 Returns the notify interval in milliseconds. More...
 
int notifyInterval () const
 Returns the notify interval in milliseconds. More...
 
int notifyInterval () const
 Returns the notify interval in milliseconds. More...
 
bool open ()
 
int periodSize () const
 Returns the period size in bytes. More...
 
int periodSize () const
 Returns the period size in bytes. More...
 
int periodSize () const
 Returns the period size in bytes. More...
 
qint64 processedUSecs () const
 Returns the amount of audio data processed since start() was called in milliseconds. More...
 
qint64 processedUSecs () const
 Returns the amount of audio data processed since start() was called in milliseconds. More...
 
qint64 processedUSecs () const
 Returns the amount of audio data processed since start() was called in milliseconds. More...
 
 QAudioInputPrivate (const QByteArray &device, const QAudioFormat &audioFormat)
 
 QAudioInputPrivate (const QByteArray &device, const QAudioFormat &audioFormat)
 
 QAudioInputPrivate (const QByteArray &device, QAudioFormat const &format)
 
qint64 read (char *data, qint64 len)
 
qint64 read (char *data, qint64 len)
 
void reset ()
 Drops all audio data in the buffers, resets buffers to zero. More...
 
void reset ()
 Drops all audio data in the buffers, resets buffers to zero. More...
 
void reset ()
 Drops all audio data in the buffers, resets buffers to zero. More...
 
void resume ()
 Resumes processing audio data after a suspend(). More...
 
void resume ()
 Resumes processing audio data after a suspend(). More...
 
void resume ()
 Resumes processing audio data after a suspend(). More...
 
void setBufferSize (int value)
 Sets the audio buffer size to value in milliseconds. More...
 
void setBufferSize (int value)
 Sets the audio buffer size to value in milliseconds. More...
 
void setBufferSize (int value)
 Sets the audio buffer size to value in milliseconds. More...
 
void setNotifyInterval (int milliSeconds)
 Sets the interval for notify() signal to be emitted. More...
 
void setNotifyInterval (int milliSeconds)
 Sets the interval for notify() signal to be emitted. More...
 
void setNotifyInterval (int milliSeconds)
 Sets the interval for notify() signal to be emitted. More...
 
QIODevicestart (QIODevice *device=0)
 Uses the device as the QIODevice to transfer data. More...
 
QIODevicestart (QIODevice *device=0)
 Uses the device as the QIODevice to transfer data. More...
 
QIODevicestart (QIODevice *device)
 Uses the device as the QIODevice to transfer data. More...
 
void startTimers ()
 
QAudio::State state () const
 Returns the state of audio processing. More...
 
QAudio::State state () const
 Returns the state of audio processing. More...
 
QAudio::State state () const
 Returns the state of audio processing. More...
 
void stop ()
 Stops the audio input. More...
 
void stop ()
 Stops the audio input. More...
 
void stop ()
 Stops the audio input. More...
 
void stopTimers ()
 
void suspend ()
 Stops processing audio data, preserving buffered audio data. More...
 
void suspend ()
 Stops processing audio data, preserving buffered audio data. More...
 
void suspend ()
 Stops processing audio data, preserving buffered audio data. More...
 
 ~QAudioInputPrivate ()
 
 ~QAudioInputPrivate ()
 
 ~QAudioInputPrivate ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QtMultimediaInternal::QAudioInputBufferaudioBuffer
 
AudioDeviceID audioDeviceId
 
QAbstractAudioDeviceInfoaudioDeviceInfo
 
QAudioFormat audioFormat
 
QIODeviceaudioIO
 
QIODeviceaudioSource
 
QAtomicInt audioThreadState
 
AudioUnit audioUnit
 
Float64 clockFrequency
 
AudioStreamBasicDescription deviceFormat
 
QAudio::State deviceState
 
QAudio::Error errorCode
 
QAudio::Error errorState
 
snd_pcm_t * handle
 
int internalBufferSize
 
QTimerintervalTimer
 
bool isOpen
 
QMutex mutex
 
int periodSizeBytes
 
bool resuming
 
QAudioFormat settings
 
UInt64 startTime
 
QAudio::State stateCode
 
AudioStreamBasicDescription streamFormat
 
QWaitCondition threadFinished
 
qint64 totalFrames
 
qint64 totalTimeValue
 

Private Types

enum  { Running, Stopped }
 

Private Slots

bool deviceReady ()
 
bool deviceReady ()
 
void deviceStopped ()
 
void feedback ()
 
void userFeed ()
 

Private Functions

WAVEHDR * allocateBlocks (int size, int count)
 
int checkBytesReady ()
 
void close ()
 
void close ()
 
void drain ()
 
void freeBlocks (WAVEHDR *blockArray)
 
bool open ()
 
bool open ()
 
int setFormat ()
 
int xrun_recovery (int err)
 

Static Private Functions

static OSStatus inputCallback (void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
 
static void QT_WIN_CALLBACK waveInProc (HWAVEIN hWaveIn, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
 

Properties

snd_pcm_access_t access
 
snd_async_handler_t * ahandler
 
char * audioBuffer
 
snd_pcm_uframes_t buffer_frames
 
qint32 buffer_size
 
int buffer_size
 
unsigned int buffer_time
 
int bytesAvailable
 
QElapsedTimer clockStamp
 
qint64 elapsedTimeOffset
 
volatile bool finished
 
qint32 header
 
HWAVEIN hWaveIn
 
snd_pcm_hw_params_t * hwparams
 
int intervalTime
 
QByteArray m_device
 
snd_pcm_format_t pcmformat
 
snd_pcm_uframes_t period_frames
 
qint32 period_size
 
int period_size
 
unsigned int period_time
 
bool pullMode
 
MMRESULT result
 
QTimertimer
 
QTime timeStamp
 
QElapsedTimer timeStamp
 
snd_timestamp_t * timestamp
 
QTime timeStampOpened
 
WAVEHDR * waveBlocks
 
int waveCurrentBlock
 
volatile int waveFreeBlockCount
 
WAVEFORMATEX wfx
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 75 of file qaudioinput_alsa_p.h.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
Running 
Stopped 

Definition at line 154 of file qaudioinput_mac_p.h.

Constructors and Destructors

◆ QAudioInputPrivate() [1/3]

QAudioInputPrivate::QAudioInputPrivate ( const QByteArray device,
const QAudioFormat audioFormat 
)

Definition at line 61 of file qaudioinput_alsa_p.cpp.

61  :
62  settings(audioFormat)
63 {
64  bytesAvailable = 0;
65  handle = 0;
66  ahandler = 0;
67  access = SND_PCM_ACCESS_RW_INTERLEAVED;
68  pcmformat = SND_PCM_FORMAT_S16;
69  buffer_size = 0;
70  period_size = 0;
71  buffer_time = 100000;
72  period_time = 20000;
73  totalTimeValue = 0;
74  intervalTime = 1000;
75  audioBuffer = 0;
78  audioSource = 0;
79  pullMode = true;
80  resuming = false;
81 
82  m_device = device;
83 
84  timer = new QTimer(this);
85  connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
86 }
snd_async_handler_t * ahandler
#define SLOT(a)
Definition: qobjectdefs.h:226
snd_pcm_access_t access
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAudio::Error errorState
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
snd_pcm_format_t pcmformat
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
QAudio::State deviceState

◆ ~QAudioInputPrivate() [1/3]

QAudioInputPrivate::~QAudioInputPrivate ( )

Definition at line 88 of file qaudioinput_alsa_p.cpp.

89 {
90  close();
91  disconnect(timer, SIGNAL(timeout()));
93  delete timer;
94 }
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895

◆ QAudioInputPrivate() [2/3]

QAudioInputPrivate::QAudioInputPrivate ( const QByteArray device,
QAudioFormat const &  format 
)

◆ ~QAudioInputPrivate() [2/3]

QAudioInputPrivate::~QAudioInputPrivate ( )

◆ QAudioInputPrivate() [3/3]

QAudioInputPrivate::QAudioInputPrivate ( const QByteArray device,
const QAudioFormat audioFormat 
)

◆ ~QAudioInputPrivate() [3/3]

QAudioInputPrivate::~QAudioInputPrivate ( )

Functions

◆ allocateBlocks()

WAVEHDR * QAudioInputPrivate::allocateBlocks ( int  size,
int  count 
)
private

Definition at line 112 of file qaudioinput_win32_p.cpp.

Referenced by freeBlocks().

113 {
114  int i;
115  unsigned char* buffer;
116  WAVEHDR* blocks;
117  DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count;
118 
119  if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
120  totalBufferSize)) == 0) {
121  qWarning("QAudioInput: Memory allocation error");
122  return 0;
123  }
124  blocks = (WAVEHDR*)buffer;
125  buffer += sizeof(WAVEHDR)*count;
126  for(i = 0; i < count; i++) {
127  blocks[i].dwBufferLength = size;
128  blocks[i].lpData = (LPSTR)buffer;
129  blocks[i].dwBytesRecorded=0;
130  blocks[i].dwUser = 0L;
131  blocks[i].dwFlags = 0L;
132  blocks[i].dwLoops = 0L;
133  result = waveInPrepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR));
134  if(result != MMSYSERR_NOERROR) {
135  qWarning("QAudioInput: Can't prepare block %d",i);
136  return 0;
137  }
138  buffer += size;
139  }
140  return blocks;
141 }
Q_CORE_EXPORT void qWarning(const char *,...)

◆ audioDeviceError()

void QAudioInputPrivate::audioDeviceError ( )

Definition at line 887 of file qaudioinput_mac_p.cpp.

Referenced by inputCallback().

888 {
891  audioDeviceStop();
892 
895  QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
896  }
897 }
QAudio::State stateCode
QAudio::Error errorCode
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ audioDeviceFull()

void QAudioInputPrivate::audioDeviceFull ( )

Definition at line 875 of file qaudioinput_mac_p.cpp.

Referenced by inputCallback().

876 {
879  audioDeviceStop();
880 
883  QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
884  }
885 }
QAudio::State stateCode
QAudio::Error errorCode
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QReadWriteLock lock
Definition: proxyconf.cpp:399
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ audioDeviceStop()

void QAudioInputPrivate::audioDeviceStop ( )

Definition at line 868 of file qaudioinput_mac_p.cpp.

Referenced by inputCallback().

869 {
870  AudioOutputUnitStop(audioUnit);
873 }
QWaitCondition threadFinished

◆ audioThreadStart()

void QAudioInputPrivate::audioThreadStart ( )

Definition at line 861 of file qaudioinput_mac_p.cpp.

862 {
863  startTimers();
865  AudioOutputUnitStart(audioUnit);
866 }

◆ audioThreadStop()

void QAudioInputPrivate::audioThreadStop ( )

Definition at line 854 of file qaudioinput_mac_p.cpp.

855 {
856  stopTimers();
859 }
bool testAndSetAcquire(int expectedValue, int newValue)
Atomic test-and-set.
QWaitCondition threadFinished
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)

◆ bufferSize() [1/3]

int QAudioInputPrivate::bufferSize ( ) const
virtual

Returns the audio buffer size in milliseconds.

Implements QAbstractAudioInput.

◆ bufferSize() [2/3]

int QAudioInputPrivate::bufferSize ( ) const
virtual

Returns the audio buffer size in milliseconds.

Implements QAbstractAudioInput.

Definition at line 614 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

615 {
616  return buffer_size;
617 }

◆ bufferSize() [3/3]

int QAudioInputPrivate::bufferSize ( ) const
virtual

Returns the audio buffer size in milliseconds.

Implements QAbstractAudioInput.

◆ bytesReady() [1/3]

int QAudioInputPrivate::bytesReady ( ) const
virtual

Returns the amount of audio data available to read in bytes.

Implements QAbstractAudioInput.

Definition at line 478 of file qaudioinput_alsa_p.cpp.

Referenced by feedback(), and freeBlocks().

479 {
480  return qMax(bytesAvailable, 0);
481 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ bytesReady() [2/3]

int QAudioInputPrivate::bytesReady ( ) const
virtual

Returns the amount of audio data available to read in bytes.

Implements QAbstractAudioInput.

◆ bytesReady() [3/3]

int QAudioInputPrivate::bytesReady ( ) const
virtual

Returns the amount of audio data available to read in bytes.

Implements QAbstractAudioInput.

◆ checkBytesReady()

int QAudioInputPrivate::checkBytesReady ( )
private

Definition at line 458 of file qaudioinput_alsa_p.cpp.

Referenced by deviceReady(), open(), read(), and xrun_recovery().

459 {
460  if(resuming)
464  bytesAvailable = 0;
465  else {
466  int frames = snd_pcm_avail_update(handle);
467  if (frames < 0) {
468  bytesAvailable = frames;
469  } else {
470  if((int)frames > (int)buffer_frames)
471  frames = buffer_frames;
472  bytesAvailable = snd_pcm_frames_to_bytes(handle, frames);
473  }
474  }
475  return bytesAvailable;
476 }
snd_pcm_uframes_t buffer_frames
QAudio::State deviceState

◆ close() [1/3]

void QAudioInputPrivate::close ( )

◆ close() [2/3]

void QAudioInputPrivate::close ( )
private

Definition at line 445 of file qaudioinput_alsa_p.cpp.

Referenced by deviceReady(), feedback(), freeBlocks(), read(), start(), stop(), xrun_recovery(), and ~QAudioInputPrivate().

446 {
447  timer->stop();
448 
449  if ( handle ) {
450  snd_pcm_drop( handle );
451  snd_pcm_close( handle );
452  handle = 0;
453  delete [] audioBuffer;
454  audioBuffer=0;
455  }
456 }
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ close() [3/3]

void QAudioInputPrivate::close ( )
private

◆ deviceReady [1/2]

bool QAudioInputPrivate::deviceReady ( )
privateslot

Definition at line 663 of file qaudioinput_alsa_p.cpp.

Referenced by feedback(), and userFeed().

664 {
665  if(pullMode) {
666  // reads some audio data and writes it to QIODevice
667  read(0, buffer_size);
668  } else {
669  // emits readyRead() so user will call read() on QIODevice to get some audio data
671  a->trigger();
672  }
674 
676  return true;
677 
678  if (bytesAvailable < 0) {
679  // bytesAvailable as negative is error code, try to recover from it.
682  if (bytesAvailable < 0) {
683  // recovery failed must stop and set error.
684  close();
688  return 0;
689  }
690  }
691 
693  emit notify();
695  timeStamp.restart();
696  }
697  return true;
698 }
long ASN1_INTEGER_get ASN1_INTEGER * a
T * qobject_cast(QObject *object)
Definition: qobject.h:375
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
qint64 read(char *data, qint64 len)
qint64 restart()
Restarts the timer and returns the time elapsed since the previous start.
QAudio::Error errorState
#define emit
Definition: qobjectdefs.h:76
void notify()
This signal is emitted when x ms of audio data has been processed the interval set by setNotifyInterv...
QAudio::State deviceState

◆ deviceReady [2/2]

bool QAudioInputPrivate::deviceReady ( )
privateslot

◆ deviceStopped

void QAudioInputPrivate::deviceStopped ( )
privateslot

Definition at line 912 of file qaudioinput_mac_p.cpp.

913 {
914  stopTimers();
916 }
QAudio::State stateCode
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
#define emit
Definition: qobjectdefs.h:76

◆ drain()

void QAudioInputPrivate::drain ( )
private

Definition at line 714 of file qaudioinput_alsa_p.cpp.

715 {
716  if(handle)
717  snd_pcm_drain(handle);
718 }

◆ elapsedUSecs() [1/3]

qint64 QAudioInputPrivate::elapsedUSecs ( ) const
virtual

Returns the milliseconds since start() was called, including time in Idle and suspend states.

Implements QAbstractAudioInput.

◆ elapsedUSecs() [2/3]

qint64 QAudioInputPrivate::elapsedUSecs ( ) const
virtual

Returns the milliseconds since start() was called, including time in Idle and suspend states.

Implements QAbstractAudioInput.

Definition at line 700 of file qaudioinput_alsa_p.cpp.

Referenced by feedback().

701 {
703  return 0;
704 
705  return clockStamp.elapsed()*1000;
706 }
QElapsedTimer clockStamp
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
QAudio::State deviceState

◆ elapsedUSecs() [3/3]

qint64 QAudioInputPrivate::elapsedUSecs ( ) const
virtual

Returns the milliseconds since start() was called, including time in Idle and suspend states.

Implements QAbstractAudioInput.

◆ error() [1/3]

QAudio::Error QAudioInputPrivate::error ( ) const
virtual

Returns the error state.

Implements QAbstractAudioInput.

◆ error() [2/3]

QAudio::Error QAudioInputPrivate::error ( ) const
virtual

Returns the error state.

Implements QAbstractAudioInput.

Definition at line 96 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

97 {
98  return errorState;
99 }
QAudio::Error errorState

◆ error() [3/3]

QAudio::Error QAudioInputPrivate::error ( ) const
virtual

Returns the error state.

Implements QAbstractAudioInput.

◆ feedback

void QAudioInputPrivate::feedback ( )
privateslot

Definition at line 553 of file qaudioinput_win32_p.cpp.

Referenced by freeBlocks(), and waveInProc().

554 {
555 #ifdef DEBUG_AUDIO
556  QTime now(QTime::currentTime());
557  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT "<<this;
558 #endif
560  QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection);
561 }
Q_CORE_EXPORT void qDebug(const char *,...)
The QTime class provides clock time functions.
Definition: qdatetime.h:148
static QTime currentTime()
Returns the current time as reported by the system clock.
Definition: qdatetime.cpp:3125
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QAudio::State deviceState

◆ format() [1/3]

QAudioFormat QAudioInputPrivate::format ( ) const
virtual

Returns the QAudioFormat being used.

Implements QAbstractAudioInput.

◆ format() [2/3]

QAudioFormat QAudioInputPrivate::format ( ) const
virtual

Returns the QAudioFormat being used.

Implements QAbstractAudioInput.

Definition at line 107 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

108 {
109  return settings;
110 }

◆ format() [3/3]

QAudioFormat QAudioInputPrivate::format ( ) const
virtual

Returns the QAudioFormat being used.

Implements QAbstractAudioInput.

◆ freeBlocks()

void QAudioInputPrivate::freeBlocks ( WAVEHDR *  blockArray)
private

Definition at line 143 of file qaudioinput_win32_p.cpp.

144 {
145  WAVEHDR* blocks = blockArray;
146 
147  int count = buffer_size/period_size;
148 
149  for(int i = 0; i < count; i++) {
150  waveInUnprepareHeader(hWaveIn,blocks, sizeof(WAVEHDR));
151  blocks++;
152  }
153  HeapFree(GetProcessHeap(), 0, blockArray);
154 }

◆ idle()

void QAudioInputPrivate::idle ( )

◆ inputCallback()

OSStatus QAudioInputPrivate::inputCallback ( void *  inRefCon,
AudioUnitRenderActionFlags *  ioActionFlags,
const AudioTimeStamp *  inTimeStamp,
UInt32  inBusNumber,
UInt32  inNumberFrames,
AudioBufferList *  ioData 
)
staticprivate

Definition at line 919 of file qaudioinput_mac_p.cpp.

925 {
926  Q_UNUSED(ioData);
927 
928  QAudioInputPrivate* d = static_cast<QAudioInputPrivate*>(inRefCon);
929 
930  const int threadState = d->audioThreadState.fetchAndAddAcquire(0);
931  if (threadState == Stopped)
932  d->audioDeviceStop();
933  else {
934  qint64 framesWritten;
935 
936  framesWritten = d->audioBuffer->renderFromDevice(d->audioUnit,
937  ioActionFlags,
938  inTimeStamp,
939  inBusNumber,
940  inNumberFrames);
941 
942  if (framesWritten > 0)
943  d->totalFrames += framesWritten;
944  else if (framesWritten == 0)
945  d->audioDeviceFull();
946  else if (framesWritten < 0)
947  d->audioDeviceError();
948  }
949 
950  return noErr;
951 }
double d
Definition: qnumeric_p.h:62
__int64 qint64
Definition: qglobal.h:942
int fetchAndAddAcquire(int valueToAdd)
Atomic fetch-and-add.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ notifyInterval() [1/3]

int QAudioInputPrivate::notifyInterval ( ) const
virtual

Returns the notify interval in milliseconds.

Implements QAbstractAudioInput.

◆ notifyInterval() [2/3]

int QAudioInputPrivate::notifyInterval ( ) const
virtual

Returns the notify interval in milliseconds.

Implements QAbstractAudioInput.

Definition at line 629 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

630 {
631  return intervalTime;
632 }

◆ notifyInterval() [3/3]

int QAudioInputPrivate::notifyInterval ( ) const
virtual

Returns the notify interval in milliseconds.

Implements QAbstractAudioInput.

◆ open() [1/3]

bool QAudioInputPrivate::open ( )

◆ open() [2/3]

bool QAudioInputPrivate::open ( )
private

Definition at line 253 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks(), start(), and xrun_recovery().

254 {
255 #ifdef DEBUG_AUDIO
256  QTime now(QTime::currentTime());
257  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
258 #endif
260  timeStamp.restart();
261  elapsedTimeOffset = 0;
262 
263  int dir;
264  int err = 0;
265  int count=0;
266  unsigned int freakuency=settings.frequency();
267 
268  if (!settings.isValid()) {
269  qWarning("QAudioOutput: open error, invalid format.");
270  } else if (settings.frequency() <= 0) {
271  qWarning("QAudioOutput: open error, invalid sample rate (%d).",
272  settings.frequency());
273  } else {
274  err = -1;
275  }
276 
277  if (err == 0) {
280  return false;
281  }
282 
283 
286  if(dev.compare(QLatin1String("default")) == 0) {
287 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
288  dev = QLatin1String(devices.first());
289 #else
290  dev = QLatin1String("hw:0,0");
291 #endif
292  } else {
293 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
294  dev = QLatin1String(m_device);
295 #else
296  int idx = 0;
297  char *name;
298 
299  QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
300 
301  while(snd_card_get_name(idx,&name) == 0) {
302  if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
303  break;
304  idx++;
305  }
306  dev = QString(QLatin1String("hw:%1,0")).arg(idx);
307 #endif
308  }
309 
310  // Step 1: try and open the device
311  while((count < 5) && (err < 0)) {
312  err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
313  if(err < 0)
314  count++;
315  }
316  if (( err < 0)||(handle == 0)) {
320  return false;
321  }
322  snd_pcm_nonblock( handle, 0 );
323 
324  // Step 2: Set the desired HW parameters.
325  snd_pcm_hw_params_alloca( &hwparams );
326 
327  bool fatal = false;
328  QString errMessage;
329  unsigned int chunks = 8;
330 
331  err = snd_pcm_hw_params_any( handle, hwparams );
332  if ( err < 0 ) {
333  fatal = true;
334  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err);
335  }
336  if ( !fatal ) {
337  err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
338  if ( err < 0 ) {
339  fatal = true;
340  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
341  }
342  }
343  if ( !fatal ) {
344  err = snd_pcm_hw_params_set_access( handle, hwparams, access );
345  if ( err < 0 ) {
346  fatal = true;
347  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err);
348  }
349  }
350  if ( !fatal ) {
351  err = setFormat();
352  if ( err < 0 ) {
353  fatal = true;
354  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err);
355  }
356  }
357  if ( !fatal ) {
358  err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
359  if ( err < 0 ) {
360  fatal = true;
361  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
362  }
363  }
364  if ( !fatal ) {
365  err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
366  if ( err < 0 ) {
367  fatal = true;
368  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
369  }
370  }
371  if ( !fatal ) {
372  err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
373  if ( err < 0 ) {
374  fatal = true;
375  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
376  }
377  }
378  if ( !fatal ) {
379  err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
380  if ( err < 0 ) {
381  fatal = true;
382  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
383  }
384  }
385  if ( !fatal ) {
386  err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
387  if ( err < 0 ) {
388  fatal = true;
389  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
390  }
391  }
392  if ( !fatal ) {
393  err = snd_pcm_hw_params(handle, hwparams);
394  if ( err < 0 ) {
395  fatal = true;
396  errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err);
397  }
398  }
399  if( err < 0) {
400  qWarning()<<errMessage;
404  return false;
405  }
406  snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
407  buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames);
408  snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir);
409  period_size = snd_pcm_frames_to_bytes(handle,period_frames);
410  snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir);
411  snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir);
412 
413  // Step 3: Set the desired SW parameters.
414  snd_pcm_sw_params_t *swparams;
415  snd_pcm_sw_params_alloca(&swparams);
416  snd_pcm_sw_params_current(handle, swparams);
417  snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames);
418  snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames);
419  snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames);
420  snd_pcm_sw_params(handle, swparams);
421 
422  // Step 4: Prepare audio
423  if(audioBuffer == 0)
424  audioBuffer = new char[buffer_size];
425  snd_pcm_prepare( handle );
426  snd_pcm_start(handle);
427 
428  // Step 5: Setup timer
430 
431  if(pullMode)
432  connect(audioSource,SIGNAL(readyRead()),this,SLOT(userFeed()));
433 
434  // Step 6: Start audio processing
435  chunks = buffer_size/period_size;
436  timer->start(period_time*chunks/2000);
437 
439 
440  totalTimeValue = 0;
441 
442  return true;
443 }
QElapsedTimer clockStamp
snd_pcm_hw_params_t * hwparams
int frequency() const
Use sampleRate() instead.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define SLOT(a)
Definition: qobjectdefs.h:226
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
snd_pcm_access_t access
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QTime class provides clock time functions.
Definition: qdatetime.h:148
qint64 restart()
Restarts the timer and returns the time elapsed since the previous start.
QAudio::Error errorState
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const char * name
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
bool isValid() const
Returns true if all of the parameters are valid.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
snd_pcm_uframes_t buffer_frames
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QTime currentTime()
Returns the current time as reported by the system clock.
Definition: qdatetime.cpp:3125
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
snd_pcm_uframes_t period_frames
QAudio::State deviceState
static QList< QByteArray > availableDevices(QAudio::Mode)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
int channels() const
Use channelCount() instead.

◆ open() [3/3]

bool QAudioInputPrivate::open ( )
private

◆ periodSize() [1/3]

int QAudioInputPrivate::periodSize ( ) const
virtual

Returns the period size in bytes.

Implements QAbstractAudioInput.

Definition at line 619 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

620 {
621  return period_size;
622 }

◆ periodSize() [2/3]

int QAudioInputPrivate::periodSize ( ) const
virtual

Returns the period size in bytes.

Implements QAbstractAudioInput.

◆ periodSize() [3/3]

int QAudioInputPrivate::periodSize ( ) const
virtual

Returns the period size in bytes.

Implements QAbstractAudioInput.

◆ processedUSecs() [1/3]

qint64 QAudioInputPrivate::processedUSecs ( ) const
virtual

Returns the amount of audio data processed since start() was called in milliseconds.

Implements QAbstractAudioInput.

◆ processedUSecs() [2/3]

qint64 QAudioInputPrivate::processedUSecs ( ) const
virtual

Returns the amount of audio data processed since start() was called in milliseconds.

Implements QAbstractAudioInput.

Definition at line 634 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

635 {
636  qint64 result = qint64(1000000) * totalTimeValue /
639 
640  return result;
641 }
int frequency() const
Use sampleRate() instead.
int sampleSize() const
Returns the current sample size value.
__int64 qint64
Definition: qglobal.h:942
int channels() const
Use channelCount() instead.

◆ processedUSecs() [3/3]

qint64 QAudioInputPrivate::processedUSecs ( ) const
virtual

Returns the amount of audio data processed since start() was called in milliseconds.

Implements QAbstractAudioInput.

◆ processMore

void QAudioInputPrivate::processMore ( )
signal

◆ read() [1/2]

qint64 QAudioInputPrivate::read ( char *  data,
qint64  len 
)

◆ read() [2/2]

qint64 QAudioInputPrivate::read ( char *  data,
qint64  len 
)

Definition at line 483 of file qaudioinput_alsa_p.cpp.

Referenced by deviceReady(), feedback(), and freeBlocks().

484 {
485  // Read in some audio data and write it to QIODevice, pull mode
486  if ( !handle )
487  return 0;
488 
489  // bytesAvaiable is saved as a side effect of checkBytesReady().
490  int bytesToRead = checkBytesReady();
491 
492  if (bytesToRead < 0) {
493  // bytesAvailable as negative is error code, try to recover from it.
494  xrun_recovery(bytesToRead);
495  bytesToRead = checkBytesReady();
496  if (bytesToRead < 0) {
497  // recovery failed must stop and set error.
498  close();
502  return 0;
503  }
504  }
505 
506  bytesToRead = qMin<qint64>(len, bytesToRead);
507  bytesToRead -= bytesToRead % period_size;
508  int count=0, err = 0;
509  while(count < 5) {
510  int chunks = bytesToRead/period_size;
511  int frames = chunks*period_frames;
512  if(frames > (int)buffer_frames)
513  frames = buffer_frames;
514  int readFrames = snd_pcm_readi(handle, audioBuffer, frames);
515  if (readFrames >= 0) {
516  err = snd_pcm_frames_to_bytes(handle, readFrames);
517 #ifdef DEBUG_AUDIO
518  qDebug()<<QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(err).arg(readFrames).toLatin1().constData();
519 #endif
520  break;
521  } else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
523  err = 0;
524  break;
525  } else {
526  if(readFrames == -EPIPE) {
528  err = snd_pcm_prepare(handle);
529  } else if(readFrames == -ESTRPIPE) {
530  err = snd_pcm_prepare(handle);
531  }
532  if(err != 0) break;
533  }
534  count++;
535  }
536  if(err > 0) {
537  // got some send it onward
538 #ifdef DEBUG_AUDIO
539  qDebug()<<"frames to write to QIODevice = "<<
540  snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<<err<<") bytes";
541 #endif
543  return 0;
544  if (pullMode) {
546  if(l < 0) {
547  close();
551  } else if(l == 0) {
556  }
557  } else {
558  bytesAvailable -= err;
559  totalTimeValue += err;
560  resuming = false;
565  }
566  }
567  return l;
568 
569  } else {
570  memcpy(data,audioBuffer,err);
571  bytesAvailable -= err;
572  totalTimeValue += err;
573  resuming = false;
578  }
579  return err;
580  }
581  }
582  return 0;
583 }
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
Q_CORE_EXPORT void qDebug(const char *,...)
QAudio::Error errorState
#define emit
Definition: qobjectdefs.h:76
static const char * data(const QByteArray &arr)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
snd_pcm_uframes_t buffer_frames
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QFactoryLoader * l
snd_pcm_uframes_t period_frames
QAudio::State deviceState
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ reset() [1/3]

void QAudioInputPrivate::reset ( )
virtual

Drops all audio data in the buffers, resets buffers to zero.

Implements QAbstractAudioInput.

Definition at line 708 of file qaudioinput_alsa_p.cpp.

Referenced by feedback(), and xrun_recovery().

709 {
710  if(handle)
711  snd_pcm_reset(handle);
712 }

◆ reset() [2/3]

void QAudioInputPrivate::reset ( )
virtual

Drops all audio data in the buffers, resets buffers to zero.

Implements QAbstractAudioInput.

◆ reset() [3/3]

void QAudioInputPrivate::reset ( )
virtual

Drops all audio data in the buffers, resets buffers to zero.

Implements QAbstractAudioInput.

◆ resume() [1/3]

void QAudioInputPrivate::resume ( )
virtual

Resumes processing audio data after a suspend().

Implements QAbstractAudioInput.

Definition at line 585 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

586 {
588  int err = 0;
589 
590  if(handle) {
591  err = snd_pcm_prepare( handle );
592  if(err < 0)
593  xrun_recovery(err);
594 
595  err = snd_pcm_start(handle);
596  if(err < 0)
597  xrun_recovery(err);
598 
600  }
601  resuming = true;
603  int chunks = buffer_size/period_size;
604  timer->start(period_time*chunks/2000);
606  }
607 }
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
#define emit
Definition: qobjectdefs.h:76
QAudio::State deviceState
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249

◆ resume() [2/3]

void QAudioInputPrivate::resume ( )
virtual

Resumes processing audio data after a suspend().

Implements QAbstractAudioInput.

◆ resume() [3/3]

void QAudioInputPrivate::resume ( )
virtual

Resumes processing audio data after a suspend().

Implements QAbstractAudioInput.

◆ setBufferSize() [1/3]

void QAudioInputPrivate::setBufferSize ( int  value)
virtual

Sets the audio buffer size to value in milliseconds.

Implements QAbstractAudioInput.

◆ setBufferSize() [2/3]

void QAudioInputPrivate::setBufferSize ( int  value)
virtual

Sets the audio buffer size to value in milliseconds.

Implements QAbstractAudioInput.

Definition at line 609 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

610 {
611  buffer_size = value;
612 }

◆ setBufferSize() [3/3]

void QAudioInputPrivate::setBufferSize ( int  value)
virtual

Sets the audio buffer size to value in milliseconds.

Implements QAbstractAudioInput.

◆ setFormat()

int QAudioInputPrivate::setFormat ( )
private

Definition at line 153 of file qaudioinput_alsa_p.cpp.

Referenced by open().

154 {
155  snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
156 
157  if(settings.sampleSize() == 8) {
158  format = SND_PCM_FORMAT_U8;
159  } else if(settings.sampleSize() == 16) {
162  format = SND_PCM_FORMAT_S16_LE;
163  else
164  format = SND_PCM_FORMAT_S16_BE;
167  format = SND_PCM_FORMAT_U16_LE;
168  else
169  format = SND_PCM_FORMAT_U16_BE;
170  }
171  } else if(settings.sampleSize() == 24) {
174  format = SND_PCM_FORMAT_S24_LE;
175  else
176  format = SND_PCM_FORMAT_S24_BE;
179  format = SND_PCM_FORMAT_U24_LE;
180  else
181  format = SND_PCM_FORMAT_U24_BE;
182  }
183  } else if(settings.sampleSize() == 32) {
186  format = SND_PCM_FORMAT_S32_LE;
187  else
188  format = SND_PCM_FORMAT_S32_BE;
191  format = SND_PCM_FORMAT_U32_LE;
192  else
193  format = SND_PCM_FORMAT_U32_BE;
194  } else if(settings.sampleType() == QAudioFormat::Float) {
196  format = SND_PCM_FORMAT_FLOAT_LE;
197  else
198  format = SND_PCM_FORMAT_FLOAT_BE;
199  }
200  } else if(settings.sampleSize() == 64) {
202  format = SND_PCM_FORMAT_FLOAT64_LE;
203  else
204  format = SND_PCM_FORMAT_FLOAT64_BE;
205  }
206 
207  return format != SND_PCM_FORMAT_UNKNOWN
208  ? snd_pcm_hw_params_set_format( handle, hwparams, format)
209  : -1;
210 }
snd_pcm_hw_params_t * hwparams
int sampleSize() const
Returns the current sample size value.
QAudioFormat::Endian byteOrder() const
Returns the current byteOrder value.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.

◆ setNotifyInterval() [1/3]

void QAudioInputPrivate::setNotifyInterval ( int  ms)
virtual

Sets the interval for notify() signal to be emitted.

This is based on the ms of audio data processed not on actual real-time. The resolution of the timer is platform specific.

Implements QAbstractAudioInput.

◆ setNotifyInterval() [2/3]

void QAudioInputPrivate::setNotifyInterval ( int  ms)
virtual

Sets the interval for notify() signal to be emitted.

This is based on the ms of audio data processed not on actual real-time. The resolution of the timer is platform specific.

Implements QAbstractAudioInput.

Definition at line 624 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

625 {
626  intervalTime = qMax(0, ms);
627 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217

◆ setNotifyInterval() [3/3]

void QAudioInputPrivate::setNotifyInterval ( int  ms)
virtual

Sets the interval for notify() signal to be emitted.

This is based on the ms of audio data processed not on actual real-time. The resolution of the timer is platform specific.

Implements QAbstractAudioInput.

◆ start() [1/3]

QIODevice * QAudioInputPrivate::start ( QIODevice device = 0)
virtual

Uses the device as the QIODevice to transfer data.

If device is null then the class creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to read() audio data directly. Passing a QIODevice allows the data to be transferred without any extra code.

Implements QAbstractAudioInput.

Definition at line 212 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

213 {
215  close();
216 
217  if(!pullMode && audioSource) {
218  delete audioSource;
219  }
220 
221  if(device) {
222  //set to pull mode
223  pullMode = true;
224  audioSource = device;
226  } else {
227  //set to push mode
228  pullMode = false;
230  audioSource = new InputPrivate(this);
232  }
233 
234  if( !open() )
235  return 0;
236 
238 
239  return audioSource;
240 }
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
#define emit
Definition: qobjectdefs.h:76
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QAudio::State deviceState

◆ start() [2/3]

QIODevice* QAudioInputPrivate::start ( QIODevice device = 0)
virtual

Uses the device as the QIODevice to transfer data.

If device is null then the class creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to read() audio data directly. Passing a QIODevice allows the data to be transferred without any extra code.

Implements QAbstractAudioInput.

◆ start() [3/3]

QIODevice* QAudioInputPrivate::start ( QIODevice device)
virtual

Uses the device as the QIODevice to transfer data.

If device is null then the class creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to read() audio data directly. Passing a QIODevice allows the data to be transferred without any extra code.

Implements QAbstractAudioInput.

◆ startTimers()

void QAudioInputPrivate::startTimers ( )

Definition at line 899 of file qaudioinput_mac_p.cpp.

900 {
901  audioBuffer->startFlushTimer();
902  if (intervalTimer->interval() > 0)
903  intervalTimer->start();
904 }
int interval
the timeout interval in milliseconds
Definition: qtimer.h:60
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249

◆ state() [1/3]

QAudio::State QAudioInputPrivate::state ( ) const
virtual

Returns the state of audio processing.

Implements QAbstractAudioInput.

Definition at line 101 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

102 {
103  return deviceState;
104 }
QAudio::State deviceState

◆ state() [2/3]

QAudio::State QAudioInputPrivate::state ( ) const
virtual

Returns the state of audio processing.

Implements QAbstractAudioInput.

◆ state() [3/3]

QAudio::State QAudioInputPrivate::state ( ) const
virtual

Returns the state of audio processing.

Implements QAbstractAudioInput.

◆ stop() [1/3]

void QAudioInputPrivate::stop ( )
virtual

Stops the audio input.

Implements QAbstractAudioInput.

◆ stop() [2/3]

void QAudioInputPrivate::stop ( )
virtual

Stops the audio input.

Implements QAbstractAudioInput.

Definition at line 242 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

243 {
245  return;
246 
248 
249  close();
251 }
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
#define emit
Definition: qobjectdefs.h:76
QAudio::State deviceState

◆ stop() [3/3]

void QAudioInputPrivate::stop ( )
virtual

Stops the audio input.

Implements QAbstractAudioInput.

◆ stopTimers()

void QAudioInputPrivate::stopTimers ( )

Definition at line 906 of file qaudioinput_mac_p.cpp.

907 {
908  audioBuffer->stopFlushTimer();
909  intervalTimer->stop();
910 }
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ suspend() [1/3]

void QAudioInputPrivate::suspend ( )
virtual

Stops processing audio data, preserving buffered audio data.

Implements QAbstractAudioInput.

Definition at line 643 of file qaudioinput_alsa_p.cpp.

Referenced by freeBlocks().

644 {
646  timer->stop();
649  }
650 }
void stateChanged(QAudio::State)
This signal is emitted when the device state has changed.
#define emit
Definition: qobjectdefs.h:76
QAudio::State deviceState
void stop()
Stops the timer.
Definition: qtimer.cpp:284

◆ suspend() [2/3]

void QAudioInputPrivate::suspend ( )
virtual

Stops processing audio data, preserving buffered audio data.

Implements QAbstractAudioInput.

◆ suspend() [3/3]

void QAudioInputPrivate::suspend ( )
virtual

Stops processing audio data, preserving buffered audio data.

Implements QAbstractAudioInput.

◆ userFeed

void QAudioInputPrivate::userFeed ( )
privateslot

Definition at line 652 of file qaudioinput_alsa_p.cpp.

Referenced by open(), and QAudioInputPrivate().

653 {
655  return;
656 #ifdef DEBUG_AUDIO
657  QTime now(QTime::currentTime());
658  qDebug()<<now.second()<<"s "<<now.msec()<<"ms :userFeed() IN";
659 #endif
660  deviceReady();
661 }
Q_CORE_EXPORT void qDebug(const char *,...)
The QTime class provides clock time functions.
Definition: qdatetime.h:148
static QTime currentTime()
Returns the current time as reported by the system clock.
Definition: qdatetime.cpp:3125
QAudio::State deviceState

◆ waveInProc()

void QT_WIN_CALLBACK QAudioInputPrivate::waveInProc ( HWAVEIN  hWaveIn,
UINT  uMsg,
DWORD_PTR  dwInstance,
DWORD_PTR  dwParam1,
DWORD_PTR  dwParam2 
)
staticprivate

Definition at line 82 of file qaudioinput_win32_p.cpp.

Referenced by freeBlocks().

84 {
85  Q_UNUSED(dwParam1)
86  Q_UNUSED(dwParam2)
88 
89  QAudioInputPrivate* qAudio;
90  qAudio = (QAudioInputPrivate*)(dwInstance);
91  if(!qAudio)
92  return;
93 
94  QMutexLocker(&qAudio->mutex);
95 
96  switch(uMsg) {
97  case WIM_OPEN:
98  break;
99  case WIM_DATA:
100  if(qAudio->waveFreeBlockCount > 0)
101  qAudio->waveFreeBlockCount--;
102  qAudio->feedback();
103  break;
104  case WIM_CLOSE:
105  qAudio->finished = true;
106  break;
107  default:
108  return;
109  }
110 }
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
volatile int waveFreeBlockCount
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ xrun_recovery()

int QAudioInputPrivate::xrun_recovery ( int  err)
private

Definition at line 112 of file qaudioinput_alsa_p.cpp.

Referenced by deviceReady(), read(), and resume().

113 {
114  int count = 0;
115  bool reset = false;
116 
117  if(err == -EPIPE) {
119  err = snd_pcm_prepare(handle);
120  if(err < 0)
121  reset = true;
122  else {
124  if (bytesAvailable <= 0)
125  reset = true;
126  }
127 
128  } else if((err == -ESTRPIPE)||(err == -EIO)) {
130  while((err = snd_pcm_resume(handle)) == -EAGAIN){
131  usleep(100);
132  count++;
133  if(count > 5) {
134  reset = true;
135  break;
136  }
137  }
138  if(err < 0) {
139  err = snd_pcm_prepare(handle);
140  if(err < 0)
141  reset = true;
142  }
143  }
144  if(reset) {
145  close();
146  open();
147  snd_pcm_prepare(handle);
148  return 0;
149  }
150  return err;
151 }
QAudio::Error errorState
void reset()
Drops all audio data in the buffers, resets buffers to zero.

Properties

◆ access

snd_pcm_access_t QAudioInputPrivate::access
private

Definition at line 136 of file qaudioinput_alsa_p.h.

Referenced by open(), and QAudioInputPrivate().

◆ ahandler

snd_async_handler_t* QAudioInputPrivate::ahandler
private

Definition at line 135 of file qaudioinput_alsa_p.h.

Referenced by QAudioInputPrivate().

◆ audioBuffer [1/2]

QtMultimediaInternal::QAudioInputBuffer* QAudioInputPrivate::audioBuffer

Definition at line 101 of file qaudioinput_mac_p.h.

◆ audioBuffer [2/2]

char* QAudioInputPrivate::audioBuffer
private

Definition at line 125 of file qaudioinput_alsa_p.h.

Referenced by close(), inputCallback(), open(), QAudioInputPrivate(), and read().

◆ audioDeviceId

AudioDeviceID QAudioInputPrivate::audioDeviceId

Definition at line 96 of file qaudioinput_mac_p.h.

◆ audioDeviceInfo

QAbstractAudioDeviceInfo* QAudioInputPrivate::audioDeviceInfo

Definition at line 108 of file qaudioinput_mac_p.h.

◆ audioFormat

QAudioFormat QAudioInputPrivate::audioFormat

Definition at line 93 of file qaudioinput_mac_p.h.

◆ audioIO

QIODevice* QAudioInputPrivate::audioIO

Definition at line 94 of file qaudioinput_mac_p.h.

◆ audioSource

QIODevice * QAudioInputPrivate::audioSource

◆ audioThreadState

QAtomicInt QAudioInputPrivate::audioThreadState

Definition at line 104 of file qaudioinput_mac_p.h.

Referenced by inputCallback().

◆ audioUnit

AudioUnit QAudioInputPrivate::audioUnit

Definition at line 95 of file qaudioinput_mac_p.h.

Referenced by inputCallback().

◆ buffer_frames

snd_pcm_uframes_t QAudioInputPrivate::buffer_frames
private

Definition at line 133 of file qaudioinput_alsa_p.h.

Referenced by checkBytesReady(), open(), and read().

◆ buffer_size [1/2]

qint32 QAudioInputPrivate::buffer_size
private

Definition at line 106 of file qaudioinput_win32_p.h.

◆ buffer_size [2/2]

int QAudioInputPrivate::buffer_size
private

◆ buffer_time

unsigned int QAudioInputPrivate::buffer_time
private

Definition at line 131 of file qaudioinput_alsa_p.h.

Referenced by open(), and QAudioInputPrivate().

◆ bytesAvailable

int QAudioInputPrivate::bytesAvailable
private

◆ clockFrequency

Float64 QAudioInputPrivate::clockFrequency

Definition at line 97 of file qaudioinput_mac_p.h.

◆ clockStamp

QElapsedTimer QAudioInputPrivate::clockStamp
private

Definition at line 122 of file qaudioinput_alsa_p.h.

Referenced by elapsedUSecs(), and open().

◆ deviceFormat

AudioStreamBasicDescription QAudioInputPrivate::deviceFormat

Definition at line 107 of file qaudioinput_mac_p.h.

◆ deviceState

QAudio::State QAudioInputPrivate::deviceState

◆ elapsedTimeOffset

qint64 QAudioInputPrivate::elapsedTimeOffset
private

Definition at line 123 of file qaudioinput_alsa_p.h.

Referenced by deviceReady(), feedback(), freeBlocks(), and open().

◆ errorCode

QAudio::Error QAudioInputPrivate::errorCode

Definition at line 99 of file qaudioinput_mac_p.h.

◆ errorState

QAudio::Error QAudioInputPrivate::errorState

◆ finished

volatile bool QAudioInputPrivate::finished
private

Definition at line 122 of file qaudioinput_win32_p.h.

Referenced by freeBlocks(), and waveInProc().

◆ handle

snd_pcm_t* QAudioInputPrivate::handle

◆ header

qint32 QAudioInputPrivate::header
private

Definition at line 108 of file qaudioinput_win32_p.h.

Referenced by freeBlocks().

◆ hWaveIn

HWAVEIN QAudioInputPrivate::hWaveIn
private

Definition at line 119 of file qaudioinput_win32_p.h.

Referenced by allocateBlocks(), and freeBlocks().

◆ hwparams

snd_pcm_hw_params_t* QAudioInputPrivate::hwparams
private

Definition at line 139 of file qaudioinput_alsa_p.h.

Referenced by open(), and setFormat().

◆ internalBufferSize

int QAudioInputPrivate::internalBufferSize

Definition at line 91 of file qaudioinput_mac_p.h.

◆ intervalTime

int QAudioInputPrivate::intervalTime
private

◆ intervalTimer

QTimer* QAudioInputPrivate::intervalTimer

Definition at line 105 of file qaudioinput_mac_p.h.

◆ isOpen

bool QAudioInputPrivate::isOpen

Definition at line 89 of file qaudioinput_mac_p.h.

◆ m_device

QByteArray QAudioInputPrivate::m_device
private

Definition at line 127 of file qaudioinput_alsa_p.h.

Referenced by freeBlocks(), open(), and QAudioInputPrivate().

◆ mutex

QMutex QAudioInputPrivate::mutex

Definition at line 102 of file qaudioinput_mac_p.h.

Referenced by freeBlocks(), and waveInProc().

◆ pcmformat

snd_pcm_format_t QAudioInputPrivate::pcmformat
private

Definition at line 137 of file qaudioinput_alsa_p.h.

Referenced by QAudioInputPrivate().

◆ period_frames

snd_pcm_uframes_t QAudioInputPrivate::period_frames
private

Definition at line 134 of file qaudioinput_alsa_p.h.

Referenced by open(), and read().

◆ period_size [1/2]

qint32 QAudioInputPrivate::period_size
private

Definition at line 107 of file qaudioinput_win32_p.h.

◆ period_size [2/2]

int QAudioInputPrivate::period_size
private

◆ period_time

unsigned int QAudioInputPrivate::period_time
private

Definition at line 132 of file qaudioinput_alsa_p.h.

Referenced by open(), QAudioInputPrivate(), and resume().

◆ periodSizeBytes

int QAudioInputPrivate::periodSizeBytes

Definition at line 90 of file qaudioinput_mac_p.h.

◆ pullMode

bool QAudioInputPrivate::pullMode
private

◆ result

MMRESULT QAudioInputPrivate::result
private

Definition at line 120 of file qaudioinput_win32_p.h.

Referenced by allocateBlocks(), freeBlocks(), and processedUSecs().

◆ resuming

bool QAudioInputPrivate::resuming

◆ settings

QAudioFormat QAudioInputPrivate::settings

Definition at line 104 of file qaudioinput_alsa_p.h.

Referenced by format(), freeBlocks(), open(), processedUSecs(), and setFormat().

◆ startTime

UInt64 QAudioInputPrivate::startTime

Definition at line 98 of file qaudioinput_mac_p.h.

◆ stateCode

QAudio::State QAudioInputPrivate::stateCode

Definition at line 100 of file qaudioinput_mac_p.h.

◆ streamFormat

AudioStreamBasicDescription QAudioInputPrivate::streamFormat

Definition at line 106 of file qaudioinput_mac_p.h.

◆ threadFinished

QWaitCondition QAudioInputPrivate::threadFinished

Definition at line 103 of file qaudioinput_mac_p.h.

◆ timer

QTimer* QAudioInputPrivate::timer
private

◆ timeStamp [1/2]

QTime QAudioInputPrivate::timeStamp
private

Definition at line 112 of file qaudioinput_win32_p.h.

◆ timeStamp [2/2]

QElapsedTimer QAudioInputPrivate::timeStamp
private

Definition at line 121 of file qaudioinput_alsa_p.h.

Referenced by deviceReady(), feedback(), freeBlocks(), and open().

◆ timestamp

snd_timestamp_t* QAudioInputPrivate::timestamp
private

Definition at line 138 of file qaudioinput_alsa_p.h.

◆ timeStampOpened

QTime QAudioInputPrivate::timeStampOpened
private

Definition at line 114 of file qaudioinput_win32_p.h.

Referenced by feedback(), and freeBlocks().

◆ totalFrames

qint64 QAudioInputPrivate::totalFrames

Definition at line 92 of file qaudioinput_mac_p.h.

Referenced by inputCallback().

◆ totalTimeValue

qint64 QAudioInputPrivate::totalTimeValue

Definition at line 102 of file qaudioinput_alsa_p.h.

Referenced by freeBlocks(), open(), processedUSecs(), QAudioInputPrivate(), and read().

◆ waveBlocks

WAVEHDR* QAudioInputPrivate::waveBlocks
private

Definition at line 121 of file qaudioinput_win32_p.h.

Referenced by freeBlocks().

◆ waveCurrentBlock

int QAudioInputPrivate::waveCurrentBlock
private

Definition at line 124 of file qaudioinput_win32_p.h.

Referenced by freeBlocks().

◆ waveFreeBlockCount

volatile int QAudioInputPrivate::waveFreeBlockCount
private

Definition at line 123 of file qaudioinput_win32_p.h.

Referenced by freeBlocks(), and waveInProc().

◆ wfx

WAVEFORMATEX QAudioInputPrivate::wfx
private

Definition at line 118 of file qaudioinput_win32_p.h.

Referenced by freeBlocks().


The documentation for this class was generated from the following files: