qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toxcall.h
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "audio/iaudiocontrol.h"
23 #include "audio/iaudiosink.h"
24 #include "audio/iaudiosource.h"
25 #include <src/core/toxpk.h>
26 #include <tox/toxav.h>
27 
28 #include <QMap>
29 #include <QMetaObject>
30 #include <QtGlobal>
31 
32 #include <cstdint>
33 #include <memory>
34 
35 class QTimer;
36 class AudioFilterer;
37 class CoreVideoSource;
38 class CoreAV;
39 class Group;
40 
41 class ToxCall : public QObject
42 {
43  Q_OBJECT
44 
45 protected:
46  ToxCall() = delete;
47  ToxCall(bool VideoEnabled, CoreAV& av, IAudioControl& audio);
48  ~ToxCall();
49 
50 public:
51  ToxCall(const ToxCall& other) = delete;
52  ToxCall(ToxCall&& other) = delete;
53 
54  ToxCall& operator=(const ToxCall& other) = delete;
55  ToxCall& operator=(ToxCall&& other) = delete;
56 
57  bool isActive() const;
58  void setActive(bool value);
59 
60  bool getMuteVol() const;
61  void setMuteVol(bool value);
62 
63  bool getMuteMic() const;
64  void setMuteMic(bool value);
65 
66  bool getVideoEnabled() const;
67  void setVideoEnabled(bool value);
68 
69  bool getNullVideoBitrate() const;
70  void setNullVideoBitrate(bool value);
71 
73 
74 protected:
75  bool active{false};
76  CoreAV* av{nullptr};
77  // audio
78  IAudioControl& audio;
79  bool muteMic{false};
80  bool muteVol{false};
81  // video
83  QMetaObject::Connection videoInConn;
84  bool videoEnabled{false};
85  bool nullVideoBitrate{false};
86  std::unique_ptr<IAudioSource> audioSource;
87 };
88 
89 class ToxFriendCall : public ToxCall
90 {
91  Q_OBJECT
92 public:
93  ToxFriendCall() = delete;
94  ToxFriendCall(uint32_t friendId, bool VideoEnabled, CoreAV& av, IAudioControl& audio);
95  ToxFriendCall(ToxFriendCall&& other) = delete;
96  ToxFriendCall& operator=(ToxFriendCall&& other) = delete;
98 
99  TOXAV_FRIEND_CALL_STATE getState() const;
100  void setState(const TOXAV_FRIEND_CALL_STATE& value);
101 
102  void playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const;
103 
104 private slots:
106  void onAudioSinkInvalidated();
107 
108 private:
109  QMetaObject::Connection audioSinkInvalid;
110  TOXAV_FRIEND_CALL_STATE state{TOXAV_FRIEND_CALL_STATE_NONE};
111  std::unique_ptr<IAudioSink> sink;
112  uint32_t friendId;
113 };
114 
115 class ToxGroupCall : public ToxCall
116 {
117  Q_OBJECT
118 public:
119  ToxGroupCall() = delete;
120  ToxGroupCall(const Group& group, CoreAV& av, IAudioControl& audio);
121  ToxGroupCall(ToxGroupCall&& other) = delete;
122  ~ToxGroupCall();
123 
124  ToxGroupCall& operator=(ToxGroupCall&& other) = delete;
125  void removePeer(ToxPk peerId);
126 
127  void playAudioBuffer(const ToxPk& peer, const int16_t* data, int samples, unsigned channels,
128  int sampleRate);
129 
130 private:
131  void addPeer(ToxPk peerId);
132  bool havePeer(ToxPk peerId);
133  void clearPeers();
134 
135  std::map<ToxPk, std::unique_ptr<IAudioSink>> peers;
136  std::map<ToxPk, QMetaObject::Connection> sinkInvalid;
137  const Group& group;
138 
139 private slots:
141  void onAudioSinkInvalidated(ToxPk peerId);
142 };
ToxGroupCall
Definition: toxcall.h:115
ToxCall::ToxCall
ToxCall()=delete
ToxCall::muteVol
bool muteVol
Definition: toxcall.h:80
ToxFriendCall::ToxFriendCall
ToxFriendCall()=delete
ToxCall::videoInConn
QMetaObject::Connection videoInConn
Definition: toxcall.h:83
ToxGroupCall::playAudioBuffer
void playAudioBuffer(const ToxPk &peer, const int16_t *data, int samples, unsigned channels, int sampleRate)
Definition: toxcall.cpp:292
ToxCall::videoSource
CoreVideoSource * videoSource
Definition: toxcall.h:82
ToxFriendCall::getState
TOXAV_FRIEND_CALL_STATE getState() const
Definition: toxcall.cpp:184
ToxGroupCall::~ToxGroupCall
~ToxGroupCall()
Definition: toxcall.cpp:219
ToxGroupCall::peers
std::map< ToxPk, std::unique_ptr< IAudioSink > > peers
Keeps sources for users in group calls.
Definition: toxcall.h:135
ToxFriendCall::onAudioSourceInvalidated
void onAudioSourceInvalidated()
Definition: toxcall.cpp:161
ToxGroupCall::group
const Group & group
Definition: toxcall.h:137
ToxGroupCall::ToxGroupCall
ToxGroupCall()=delete
ToxCall::getVideoEnabled
bool getVideoEnabled() const
Definition: toxcall.cpp:96
ToxGroupCall::onAudioSinkInvalidated
void onAudioSinkInvalidated(ToxPk peerId)
Definition: toxcall.cpp:243
ToxGroupCall::havePeer
bool havePeer(ToxPk peerId)
Definition: toxcall.cpp:276
toxpk.h
ToxCall::active
bool active
Definition: toxcall.h:75
ToxFriendCall::onAudioSinkInvalidated
void onAudioSinkInvalidated()
Definition: toxcall.cpp:173
ToxCall::setMuteVol
void setMuteVol(bool value)
Definition: toxcall.cpp:81
ToxFriendCall::playAudioBuffer
void playAudioBuffer(const int16_t *data, int samples, unsigned channels, int sampleRate) const
Definition: toxcall.cpp:194
ToxCall::~ToxCall
~ToxCall()
Definition: toxcall.cpp:58
ToxCall
Definition: toxcall.h:41
ToxFriendCall::audioSinkInvalid
QMetaObject::Connection audioSinkInvalid
Definition: toxcall.h:109
ToxCall::operator=
ToxCall & operator=(const ToxCall &other)=delete
ToxGroupCall::onAudioSourceInvalidated
void onAudioSourceInvalidated()
Definition: toxcall.cpp:225
ToxCall::setVideoEnabled
void setVideoEnabled(bool value)
Definition: toxcall.cpp:101
ToxCall::getMuteMic
bool getMuteMic() const
Definition: toxcall.cpp:86
ToxCall::nullVideoBitrate
bool nullVideoBitrate
Definition: toxcall.h:85
ToxFriendCall::sink
std::unique_ptr< IAudioSink > sink
Definition: toxcall.h:111
ToxCall::setActive
void setActive(bool value)
Definition: toxcall.cpp:71
ToxGroupCall::removePeer
void removePeer(ToxPk peerId)
Definition: toxcall.cpp:249
ToxCall::audioSource
std::unique_ptr< IAudioSource > audioSource
Definition: toxcall.h:86
ToxFriendCall
Definition: toxcall.h:89
ToxGroupCall::operator=
ToxGroupCall & operator=(ToxGroupCall &&other)=delete
ToxCall::muteMic
bool muteMic
Definition: toxcall.h:79
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
ToxFriendCall::friendId
uint32_t friendId
Definition: toxcall.h:112
ToxCall::av
CoreAV * av
Definition: toxcall.h:76
ToxFriendCall::setState
void setState(const TOXAV_FRIEND_CALL_STATE &value)
Definition: toxcall.cpp:189
ToxFriendCall::state
TOXAV_FRIEND_CALL_STATE state
State of the peer (not ours!)
Definition: toxcall.h:110
ToxCall::setNullVideoBitrate
void setNullVideoBitrate(bool value)
Definition: toxcall.cpp:111
ToxCall::setMuteMic
void setMuteMic(bool value)
Definition: toxcall.cpp:91
Group
Definition: group.h:34
ToxCall::videoEnabled
bool videoEnabled
Definition: toxcall.h:84
ToxGroupCall::sinkInvalid
std::map< ToxPk, QMetaObject::Connection > sinkInvalid
Definition: toxcall.h:136
CoreVideoSource
A VideoSource that emits frames received by Core.
Definition: corevideosource.h:28
ToxCall::getMuteVol
bool getMuteVol() const
Definition: toxcall.cpp:76
ToxCall::audio
IAudioControl & audio
Definition: toxcall.h:78
ToxGroupCall::clearPeers
void clearPeers()
Definition: toxcall.cpp:282
ToxFriendCall::~ToxFriendCall
~ToxFriendCall()
Definition: toxcall.cpp:156
ToxCall::getNullVideoBitrate
bool getNullVideoBitrate() const
Definition: toxcall.cpp:106
ToxGroupCall::addPeer
void addPeer(ToxPk peerId)
Definition: toxcall.cpp:262
CoreAV
Definition: coreav.h:47
ToxCall::isActive
bool isActive() const
Definition: toxcall.cpp:66
ToxFriendCall::operator=
ToxFriendCall & operator=(ToxFriendCall &&other)=delete
ToxCall::getVideoSource
CoreVideoSource * getVideoSource() const
Definition: toxcall.cpp:116