blob: 432d4579419900d87107688aaddd5a482a94c66d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
|