qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Classes | Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Types | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CoreAV Class Reference

#include <coreav.h>

Inheritance diagram for CoreAV:
Inheritance graph
Collaboration diagram for CoreAV:
Collaboration graph

Classes

struct  ToxAVDeleter
 

Public Types

using CoreAVPtr = std::unique_ptr< CoreAV >
 

Public Slots

bool startCall (uint32_t friendNum, bool video)
 
bool answerCall (uint32_t friendNum, bool video)
 
bool cancelCall (uint32_t friendNum)
 
void timeoutCall (uint32_t friendNum)
 
void start ()
 Starts the CoreAV main loop that calls toxav's main loop. More...
 

Signals

void avInvite (uint32_t friendId, bool video)
 Sent when a friend calls us. More...
 
void avStart (uint32_t friendId, bool video)
 Sent when a call we initiated has started. More...
 
void avEnd (uint32_t friendId, bool error=false)
 Sent when a call was ended by the peer. More...
 

Public Member Functions

void setAudio (IAudioControl &newAudio)
 Set the audio backend. More...
 
IAudioControl * getAudio ()
 Get the audio backend used. More...
 
 ~CoreAV ()
 
bool isCallStarted (const Friend *f) const
 Checks the call status for a Tox friend. More...
 
bool isCallStarted (const Group *f) const
 Checks the call status for a Tox group. More...
 
bool isCallActive (const Friend *f) const
 Checks the call status for a Tox friend. More...
 
bool isCallActive (const Group *g) const
 Checks the call status for a Tox group. More...
 
bool isCallVideoEnabled (const Friend *f) const
 
bool sendCallAudio (uint32_t friendNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate) const
 Send audio frame to a friend. More...
 
void sendCallVideo (uint32_t friendNum, std::shared_ptr< VideoFrame > frame)
 
bool sendGroupCallAudio (int groupNum, const int16_t *pcm, size_t samples, uint8_t chans, uint32_t rate) const
 
VideoSourcegetVideoSourceFromCall (int callNumber) const
 Get a call's video source. More...
 
void sendNoVideo ()
 Signal to all peers that we're not sending video anymore. More...
 
void joinGroupCall (const Group &group)
 Starts a call in an existing AV groupchat. More...
 
void leaveGroupCall (int groupNum)
 Will not leave the group, just stop the call. More...
 
void muteCallInput (const Group *g, bool mute)
 Mutes or unmutes the group call's input (microphone). More...
 
void muteCallOutput (const Group *g, bool mute)
 Mutes or unmutes the group call's output (speaker). More...
 
bool isGroupCallInputMuted (const Group *g) const
 Returns the group calls input (microphone) state. More...
 
bool isGroupCallOutputMuted (const Group *g) const
 Returns the group calls output (speaker) state. More...
 
bool isCallInputMuted (const Friend *f) const
 Returns the calls input (microphone) mute state. More...
 
bool isCallOutputMuted (const Friend *f) const
 Returns the calls output (speaker) mute state. More...
 
void toggleMuteCallInput (const Friend *f)
 Toggles the mute state of the call's input (microphone). More...
 
void toggleMuteCallOutput (const Friend *f)
 Toggles the mute state of the call's output (speaker). More...
 
void invalidateGroupCallPeerSource (const Group &group, ToxPk peerPk)
 Called from core to make sure the source for that peer is invalidated when they leave. More...
 

Static Public Member Functions

static CoreAVPtr makeCoreAV (Tox *core, CompatibleRecursiveMutex &toxCoreLock, IAudioSettings &audioSettings, IGroupSettings &groupSettings)
 Factory method for CoreAV. More...
 
static void groupCallCallback (void *tox, uint32_t group, uint32_t peer, const int16_t *data, unsigned samples, uint8_t channels, uint32_t sample_rate, void *core)
 Called from Tox API when group call receives audio data. More...
 

Private Types

using ToxFriendCallPtr = std::unique_ptr< ToxFriendCall >
 
using ToxGroupCallPtr = std::unique_ptr< ToxGroupCall >
 

Private Slots

static void callCallback (ToxAV *toxAV, uint32_t friendNum, bool audio, bool video, void *self)
 
static void stateCallback (ToxAV *, uint32_t friendNum, uint32_t state, void *self)
 
static void bitrateCallback (ToxAV *toxAV, uint32_t friendNum, uint32_t arate, uint32_t vrate, void *self)
 
static void audioBitrateCallback (ToxAV *toxAV, uint32_t friendNum, uint32_t rate, void *self)
 
static void videoBitrateCallback (ToxAV *toxAV, uint32_t friendNum, uint32_t rate, void *self)
 

Private Member Functions

 CoreAV (std::unique_ptr< ToxAV, ToxAVDeleter > tox, CompatibleRecursiveMutex &toxCoreLock, IAudioSettings &_audioSettings, IGroupSettings &_groupSettings)
 
void connectCallbacks (ToxAV &toxav)
 
void process ()
 

Static Private Member Functions

static void audioFrameCallback (ToxAV *toxAV, uint32_t friendNum, const int16_t *pcm, size_t sampleCount, uint8_t channels, uint32_t samplingRate, void *self)
 
static void videoFrameCallback (ToxAV *toxAV, uint32_t friendNum, uint16_t w, uint16_t h, const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride, void *self)
 

Private Attributes

std::atomic< IAudioControl * > audio
 
std::unique_ptr< ToxAV, ToxAVDeletertoxav
 
std::unique_ptr< QThread > coreavThread
 
QTimer * iterateTimer = nullptr
 
std::map< uint32_t, ToxFriendCallPtrcalls
 Maps friend IDs to ToxFriendCall. More...
 
std::map< int, ToxGroupCallPtrgroupCalls
 Maps group IDs to ToxGroupCalls. More...
 
QReadWriteLock callsLock {QReadWriteLock::Recursive}
 
CompatibleRecursiveMutex & coreLock
 needed to synchronize with the Core thread, some toxav_* functions must not execute at the same time as tox_iterate() More...
 
IAudioSettings & audioSettings
 
IGroupSettingsgroupSettings
 

Static Private Attributes

static constexpr uint32_t VIDEO_DEFAULT_BITRATE = 2500
 Picked at random by fair dice roll. More...
 

Detailed Description

Definition at line 47 of file coreav.h.

Member Typedef Documentation

◆ CoreAVPtr

using CoreAV::CoreAVPtr = std::unique_ptr<CoreAV>

Definition at line 52 of file coreav.h.

◆ ToxFriendCallPtr

using CoreAV::ToxFriendCallPtr = std::unique_ptr<ToxFriendCall>
private

Definition at line 141 of file coreav.h.

◆ ToxGroupCallPtr

using CoreAV::ToxGroupCallPtr = std::unique_ptr<ToxGroupCall>
private

Definition at line 149 of file coreav.h.

Constructor & Destructor Documentation

◆ ~CoreAV()

CoreAV::~CoreAV ( )

Definition at line 158 of file coreav.cpp.

Here is the call graph for this function:

◆ CoreAV()

CoreAV::CoreAV ( std::unique_ptr< ToxAV, ToxAVDeleter tox,
CompatibleRecursiveMutex &  toxCoreLock,
IAudioSettings &  _audioSettings,
IGroupSettings _groupSettings 
)
private

Definition at line 73 of file coreav.cpp.

Member Function Documentation

◆ answerCall

bool CoreAV::answerCall ( uint32_t  friendNum,
bool  video 
)
slot

Definition at line 249 of file coreav.cpp.

Here is the caller graph for this function:

◆ audioBitrateCallback

void CoreAV::audioBitrateCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
uint32_t  rate,
void *  self 
)
staticprivateslot

Definition at line 823 of file coreav.cpp.

Here is the caller graph for this function:

◆ audioFrameCallback()

void CoreAV::audioFrameCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
const int16_t *  pcm,
size_t  sampleCount,
uint8_t  channels,
uint32_t  samplingRate,
void *  self 
)
staticprivate

Definition at line 842 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ avEnd

void CoreAV::avEnd ( uint32_t  friendId,
bool  error = false 
)
signal

Sent when a call was ended by the peer.

Parameters
friendIdId of friend in call list.
Here is the caller graph for this function:

◆ avInvite

void CoreAV::avInvite ( uint32_t  friendId,
bool  video 
)
signal

Sent when a friend calls us.

Parameters
friendIdId of friend in call list.
videoFalse if chat is audio only, true audio and video.

◆ avStart

void CoreAV::avStart ( uint32_t  friendId,
bool  video 
)
signal

Sent when a call we initiated has started.

Parameters
friendIdId of friend in call list.
videoFalse if chat is audio only, true audio and video.

◆ bitrateCallback

void CoreAV::bitrateCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
uint32_t  arate,
uint32_t  vrate,
void *  self 
)
staticprivateslot

Definition at line 811 of file coreav.cpp.

◆ callCallback

void CoreAV::callCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
bool  audio,
bool  video,
void *  self 
)
staticprivateslot

Definition at line 717 of file coreav.cpp.

Here is the caller graph for this function:

◆ cancelCall

bool CoreAV::cancelCall ( uint32_t  friendNum)
slot

Definition at line 299 of file coreav.cpp.

Here is the caller graph for this function:

◆ connectCallbacks()

void CoreAV::connectCallbacks ( ToxAV &  toxav)
private

Definition at line 98 of file coreav.cpp.

Here is the call graph for this function:

◆ getAudio()

IAudioControl * CoreAV::getAudio ( )

Get the audio backend used.

Returns
Pointer to the audio backend
Note
This is needed only for the case CoreAV needs to restart and the restarting class doesn't have access to the audio backend and wants to keep it the same.

Definition at line 153 of file coreav.cpp.

◆ getVideoSourceFromCall()

VideoSource * CoreAV::getVideoSourceFromCall ( int  friendNum) const

Get a call's video source.

Parameters
friendNumId of friend in call list.
Returns
Video surface to show

Definition at line 527 of file coreav.cpp.

Here is the caller graph for this function:

◆ groupCallCallback()

void CoreAV::groupCallCallback ( void *  tox,
uint32_t  group,
uint32_t  peer,
const int16_t *  data,
unsigned  samples,
uint8_t  channels,
uint32_t  sample_rate,
void *  core 
)
static

Called from Tox API when group call receives audio data.

Parameters
[in]toxthe Tox object
[in]groupthe group number
[in]peerthe peer number
[in]datathe audio data to playback
[in]samplesthe audio samples
[in]channelsthe audio channels
[in]sample_ratethe audio sample rate
[in]corethe qTox Core class

Definition at line 467 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalidateGroupCallPeerSource()

void CoreAV::invalidateGroupCallPeerSource ( const Group group,
ToxPk  peerPk 
)

Called from core to make sure the source for that peer is invalidated when they leave.

Parameters
groupGroup Index
peerPeer Index

Definition at line 511 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCallActive() [1/2]

bool CoreAV::isCallActive ( const Friend f) const

Checks the call status for a Tox friend.

Parameters
fthe friend to check
Returns
true, if call is active for the friend, false otherwise

Definition at line 217 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCallActive() [2/2]

bool CoreAV::isCallActive ( const Group g) const

Checks the call status for a Tox group.

Parameters
gthe group to check
Returns
true, if the call is active for the group, false otherwise

Definition at line 232 of file coreav.cpp.

Here is the call graph for this function:

◆ isCallInputMuted()

bool CoreAV::isCallInputMuted ( const Friend f) const

Returns the calls input (microphone) mute state.

Parameters
fThe friend to check
Returns
true when muted, false otherwise

Definition at line 671 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCallOutputMuted()

bool CoreAV::isCallOutputMuted ( const Friend f) const

Returns the calls output (speaker) mute state.

Parameters
friendIdThe friend to check
Returns
true when muted, false otherwise

Definition at line 688 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCallStarted() [1/2]

bool CoreAV::isCallStarted ( const Friend f) const

Checks the call status for a Tox friend.

Parameters
fthe friend to check
Returns
true, if call is started for the friend, false otherwise

Definition at line 195 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCallStarted() [2/2]

bool CoreAV::isCallStarted ( const Group g) const

Checks the call status for a Tox group.

Parameters
gthe group to check
Returns
true, if call is started for the group, false otherwise

Definition at line 206 of file coreav.cpp.

Here is the call graph for this function:

◆ isCallVideoEnabled()

bool CoreAV::isCallVideoEnabled ( const Friend f) const

Definition at line 242 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGroupCallInputMuted()

bool CoreAV::isGroupCallInputMuted ( const Group g) const

Returns the group calls input (microphone) state.

Parameters
groupIdThe group id to check
Returns
true when muted, false otherwise

Definition at line 635 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isGroupCallOutputMuted()

bool CoreAV::isGroupCallOutputMuted ( const Group g) const

Returns the group calls output (speaker) state.

Parameters
groupIdThe group id to check
Returns
true when muted, false otherwise

Definition at line 653 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ joinGroupCall()

void CoreAV::joinGroupCall ( const Group group)

Starts a call in an existing AV groupchat.

Note
Call from the GUI thread.
Parameters
groupIdId of group to join

Definition at line 545 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ leaveGroupCall()

void CoreAV::leaveGroupCall ( int  groupId)

Will not leave the group, just stop the call.

Note
Call from the GUI thread.
Parameters
groupIdId of group to leave

Definition at line 571 of file coreav.cpp.

Here is the caller graph for this function:

◆ makeCoreAV()

CoreAV::CoreAVPtr CoreAV::makeCoreAV ( Tox *  core,
CompatibleRecursiveMutex &  toxCoreLock,
IAudioSettings &  audioSettings,
IGroupSettings groupSettings 
)
static

Factory method for CoreAV.

Parameters
corepointer to the Tox instance
Returns
CoreAV instance on success, {} on failure

Definition at line 113 of file coreav.cpp.

Here is the caller graph for this function:

◆ muteCallInput()

void CoreAV::muteCallInput ( const Group g,
bool  mute 
)

Mutes or unmutes the group call's input (microphone).

Parameters
gThe group
muteTrue to mute, false to unmute

Definition at line 605 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ muteCallOutput()

void CoreAV::muteCallOutput ( const Group g,
bool  mute 
)

Mutes or unmutes the group call's output (speaker).

Parameters
gThe group
muteTrue to mute, false to unmute

Definition at line 620 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

void CoreAV::process ( )
private

Definition at line 183 of file coreav.cpp.

◆ sendCallAudio()

bool CoreAV::sendCallAudio ( uint32_t  callId,
const int16_t *  pcm,
size_t  samples,
uint8_t  chans,
uint32_t  rate 
) const

Send audio frame to a friend.

Parameters
callIdId of friend in call list.
pcmAn array of audio samples (Pulse-code modulation).
samplesNumber of samples in this frame.
chansNumber of audio channels.
rateAudio sampling rate used in this frame.
Returns
False only on error, but not if there's nothing to send.

Definition at line 337 of file coreav.cpp.

Here is the call graph for this function:

◆ sendCallVideo()

void CoreAV::sendCallVideo ( uint32_t  friendNum,
std::shared_ptr< VideoFrame frame 
)

Definition at line 374 of file coreav.cpp.

Here is the call graph for this function:

◆ sendGroupCallAudio()

bool CoreAV::sendGroupCallAudio ( int  groupNum,
const int16_t *  pcm,
size_t  samples,
uint8_t  chans,
uint32_t  rate 
) const

Definition at line 580 of file coreav.cpp.

◆ sendNoVideo()

void CoreAV::sendNoVideo ( )

Signal to all peers that we're not sending video anymore.

Note
The next frame sent cancels this.

Definition at line 704 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAudio()

void CoreAV::setAudio ( IAudioControl &  newAudio)

Set the audio backend.

Parameters
audioThe audio backend to use
Note
This must be called before starting CoreAV and audio must outlive CoreAV

Definition at line 142 of file coreav.cpp.

Here is the caller graph for this function:

◆ start

void CoreAV::start ( )
slot

Starts the CoreAV main loop that calls toxav's main loop.

Definition at line 178 of file coreav.cpp.

◆ startCall

bool CoreAV::startCall ( uint32_t  friendNum,
bool  video 
)
slot

Definition at line 272 of file coreav.cpp.

Here is the caller graph for this function:

◆ stateCallback

void CoreAV::stateCallback ( ToxAV *  toxav,
uint32_t  friendNum,
uint32_t  state,
void *  self 
)
staticprivateslot

Definition at line 752 of file coreav.cpp.

Here is the caller graph for this function:

◆ timeoutCall

void CoreAV::timeoutCall ( uint32_t  friendNum)
slot

Definition at line 317 of file coreav.cpp.

Here is the call graph for this function:

◆ toggleMuteCallInput()

void CoreAV::toggleMuteCallInput ( const Friend f)

Toggles the mute state of the call's input (microphone).

Parameters
fThe friend assigned to the call

Definition at line 429 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toggleMuteCallOutput()

void CoreAV::toggleMuteCallOutput ( const Friend f)

Toggles the mute state of the call's output (speaker).

Parameters
fThe friend assigned to the call

Definition at line 444 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ videoBitrateCallback

void CoreAV::videoBitrateCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
uint32_t  rate,
void *  self 
)
staticprivateslot

Definition at line 833 of file coreav.cpp.

Here is the caller graph for this function:

◆ videoFrameCallback()

void CoreAV::videoFrameCallback ( ToxAV *  toxAV,
uint32_t  friendNum,
uint16_t  w,
uint16_t  h,
const uint8_t *  y,
const uint8_t *  u,
const uint8_t *  v,
int32_t  ystride,
int32_t  ustride,
int32_t  vstride,
void *  self 
)
staticprivate

Definition at line 864 of file coreav.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ audio

std::atomic<IAudioControl*> CoreAV::audio
private

Definition at line 137 of file coreav.h.

◆ audioSettings

IAudioSettings& CoreAV::audioSettings
private

Definition at line 166 of file coreav.h.

◆ calls

std::map<uint32_t, ToxFriendCallPtr> CoreAV::calls
private

Maps friend IDs to ToxFriendCall.

Note
Need to use STL container here, because Qt containers need a copy constructor.

Definition at line 146 of file coreav.h.

◆ callsLock

QReadWriteLock CoreAV::callsLock {QReadWriteLock::Recursive}
mutableprivate

Definition at line 157 of file coreav.h.

◆ coreavThread

std::unique_ptr<QThread> CoreAV::coreavThread
private

Definition at line 139 of file coreav.h.

◆ coreLock

CompatibleRecursiveMutex& CoreAV::coreLock
private

needed to synchronize with the Core thread, some toxav_* functions must not execute at the same time as tox_iterate()

Note
This must be a recursive mutex as we're going to lock it in callbacks

Definition at line 164 of file coreav.h.

◆ groupCalls

std::map<int, ToxGroupCallPtr> CoreAV::groupCalls
private

Maps group IDs to ToxGroupCalls.

Note
Need to use STL container here, because Qt containers need a copy constructor.

Definition at line 154 of file coreav.h.

◆ groupSettings

IGroupSettings& CoreAV::groupSettings
private

Definition at line 167 of file coreav.h.

◆ iterateTimer

QTimer* CoreAV::iterateTimer = nullptr
private

Definition at line 140 of file coreav.h.

◆ toxav

std::unique_ptr<ToxAV, ToxAVDeleter> CoreAV::toxav
private

Definition at line 138 of file coreav.h.

◆ VIDEO_DEFAULT_BITRATE

CoreAV::VIDEO_DEFAULT_BITRATE = 2500
staticconstexprprivate

Picked at random by fair dice roll.

Definition at line 133 of file coreav.h.


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