mirror of https://github.com/qTox/qTox.git
13 changed files with 210 additions and 154 deletions
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
#include "src/audio/backend/alsource.h" |
||||
#include "src/audio/backend/openal.h" |
||||
|
||||
/**
|
||||
* @brief Emits audio frames captured by an input device or other audio source. |
||||
*/ |
||||
|
||||
/**
|
||||
* @brief Reserves ressources for an audio source |
||||
* @param audio Main audio object, must have longer lifetime than this object. |
||||
*/ |
||||
AlSource::AlSource(OpenAL& al) |
||||
: audio(al) |
||||
, killLock(QMutex::Recursive) |
||||
{} |
||||
|
||||
AlSource::~AlSource() |
||||
{ |
||||
QMutexLocker{&killLock}; |
||||
|
||||
// unsubscribe only if not already killed
|
||||
if (!killed) { |
||||
audio.destroySource(*this); |
||||
killed = true; |
||||
} |
||||
} |
||||
|
||||
AlSource::operator bool() const |
||||
{ |
||||
QMutexLocker{&killLock}; |
||||
return !killed; |
||||
} |
||||
|
||||
void AlSource::kill() |
||||
{ |
||||
killLock.lock(); |
||||
// this flag is only set once here, afterwards the object is considered dead
|
||||
killed = true; |
||||
killLock.unlock(); |
||||
emit invalidated(); |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
#ifndef ALSOURCE_H |
||||
#define ALSOURCE_H |
||||
|
||||
#include "src/audio/iaudiosource.h" |
||||
#include <QMutex> |
||||
#include <QObject> |
||||
|
||||
class OpenAL; |
||||
class AlSource : public IAudioSource |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
AlSource(OpenAL& al); |
||||
AlSource(AlSource& src) = delete; |
||||
AlSource& operator=(const AlSource&) = delete; |
||||
AlSource(AlSource&& other) = delete; |
||||
AlSource& operator=(AlSource&& other) = delete; |
||||
~AlSource(); |
||||
|
||||
operator bool() const; |
||||
|
||||
void kill(); |
||||
|
||||
private: |
||||
OpenAL& audio; |
||||
bool killed = false; |
||||
mutable QMutex killLock; |
||||
}; |
||||
|
||||
#endif // ALSOURCE_H
|
Loading…
Reference in new issue