diff options
| author | Anton <anton@picapica.im> | 2026-11-24 02:40:10 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-11-24 02:40:10 +0400 |
| commit | 48417c1da102dc9eb332227237805b8e28f81f97 (patch) | |
| tree | 53defd47a60bf505a3431a0ae4193b1e40b29c2e /pica-client/mediadevice.h | |
| parent | 3922dcc4c4822cc626d62f73ddefbe4fce8e94e5 (diff) | |
| parent | 98d341e2e55852f075001c6c2d084d025a97383f (diff) | |
| download | pica-pica-master.tar.gz pica-pica-master.zip | |
Diffstat (limited to 'pica-client/mediadevice.h')
| -rw-r--r-- | pica-client/mediadevice.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/pica-client/mediadevice.h b/pica-client/mediadevice.h new file mode 100644 index 0000000..432d457 --- /dev/null +++ b/pica-client/mediadevice.h @@ -0,0 +1,77 @@ +#ifndef MEDIADEVICE_H +#define MEDIADEVICE_H + +#include <QString> +#include <QStringList> +#include <QList> +#include <QByteArray> +#include <QMutex> +#include <QMutexLocker> + +enum MediaDeviceStreamDirection +{ + CAPTURE, + PLAYBACK +}; + +struct MediaDeviceInfo +{ + QString device; + QString humanReadable; + int index; +}; + +// Which call a device is currently allowed to work for. A call is identified +// by the pair of its caller's and its callee's id. +// +// The loops of AudioDevice and VideoDevice are started through their thread's +// event queue and stopped by a direct call from another thread, so the two can +// arrive in either order. A plain stop flag that the loop clears on entry +// loses a stop that came first, and the loop then runs with nobody left to +// stop it. Instead the owner opens the session before it queues the start and +// closes it to stop, and a loop only runs while the session that is open is +// the one it was configured for. All of it is safe to call from any thread. +class MediaCallSession +{ +public: + MediaCallSession() : m_open(false) {} + + void open(const QByteArray &caller_id, const QByteArray &callee_id) + { + QMutexLocker locker(&m_mutex); + m_caller_id = caller_id; + m_callee_id = callee_id; + m_open = true; + } + + void close() + { + QMutexLocker locker(&m_mutex); + m_open = false; + } + + bool isOpenFor(const QByteArray &caller_id, const QByteArray &callee_id) const + { + QMutexLocker locker(&m_mutex); + return m_open && m_caller_id == caller_id && m_callee_id == callee_id; + } + +private: + mutable QMutex m_mutex; + bool m_open; + QByteArray m_caller_id; + QByteArray m_callee_id; +}; + +class MediaDevice +{ +public: + MediaDevice(); + virtual ~MediaDevice(); + virtual QList<MediaDeviceInfo> Enumerate(enum MediaDeviceStreamDirection) = 0; + virtual void Capture() = 0; + virtual void Play() = 0; + virtual void Close() = 0; +}; + +#endif // MEDIADEVICE_H |
