2015-05-11 15:40:07 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2015
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-07-13 09:57:25 -04:00
# include <QToolButton>
# include <QPropertyAnimation>
# include <QIcon>
# include <QLayout>
# include <gui/audiodevicehelper.h>
2015-05-11 15:40:07 -04:00
# include "interface/rsVOIP.h"
2014-07-13 09:57:25 -04:00
# include "gui/SoundManager.h"
# include "util/HandleRichText.h"
# include "gui/common/StatusDefs.h"
# include "gui/chat/ChatWidget.h"
# include "VOIPChatWidgetHolder.h"
# include "VideoProcessor.h"
# include "QVideoDevice.h"
# include <retroshare/rsstatus.h>
2015-05-28 09:59:20 -04:00
# include <retroshare/rspeers.h>
2014-07-13 09:57:25 -04:00
2014-12-19 07:17:58 -05:00
# define CALL_START ": / images / call-start.png"
# define CALL_STOP ": / images / call-stop.png"
# define CALL_HOLD ": / images / call-hold.png"
2014-07-13 09:57:25 -04:00
2015-05-26 11:19:57 -04:00
VOIPChatWidgetHolder : : VOIPChatWidgetHolder ( ChatWidget * chatWidget , VOIPNotify * notify )
: QObject ( ) , ChatWidgetHolder ( chatWidget ) , mVOIPNotify ( notify )
2014-07-13 09:57:25 -04:00
{
QIcon icon ;
2014-12-19 07:17:58 -05:00
icon . addPixmap ( QPixmap ( " :/images/audio-volume-muted.png " ) ) ;
icon . addPixmap ( QPixmap ( " :/images/audio-volume-high.png " ) , QIcon : : Normal , QIcon : : On ) ;
icon . addPixmap ( QPixmap ( " :/images/audio-volume-high.png " ) , QIcon : : Disabled , QIcon : : On ) ;
icon . addPixmap ( QPixmap ( " :/images/audio-volume-high.png " ) , QIcon : : Active , QIcon : : On ) ;
icon . addPixmap ( QPixmap ( " :/images/audio-volume-high.png " ) , QIcon : : Selected , QIcon : : On ) ;
2014-07-13 09:57:25 -04:00
audioListenToggleButton = new QToolButton ;
audioListenToggleButton - > setIcon ( icon ) ;
2014-12-19 12:41:34 -05:00
audioListenToggleButton - > setIconSize ( QSize ( 42 , 42 ) ) ;
2014-07-13 09:57:25 -04:00
audioListenToggleButton - > setAutoRaise ( true ) ;
audioListenToggleButton - > setCheckable ( true ) ;
2014-12-19 12:41:34 -05:00
audioListenToggleButton - > setMinimumSize ( QSize ( 44 , 44 ) ) ;
audioListenToggleButton - > setMaximumSize ( QSize ( 44 , 44 ) ) ;
2014-07-13 09:57:25 -04:00
audioListenToggleButton - > setText ( QString ( ) ) ;
audioListenToggleButton - > setToolTip ( tr ( " Mute " ) ) ;
QIcon icon2 ;
2014-12-19 07:17:58 -05:00
icon2 . addPixmap ( QPixmap ( " :/images/call-start.png " ) ) ;
icon2 . addPixmap ( QPixmap ( " :/images/call-hold.png " ) , QIcon : : Normal , QIcon : : On ) ;
icon2 . addPixmap ( QPixmap ( " :/images/call-hold.png " ) , QIcon : : Disabled , QIcon : : On ) ;
icon2 . addPixmap ( QPixmap ( " :/images/call-hold.png " ) , QIcon : : Active , QIcon : : On ) ;
icon2 . addPixmap ( QPixmap ( " :/images/call-hold.png " ) , QIcon : : Selected , QIcon : : On ) ;
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton = new QToolButton ;
2014-12-19 12:41:34 -05:00
audioCaptureToggleButton - > setMinimumSize ( QSize ( 44 , 44 ) ) ;
audioCaptureToggleButton - > setMaximumSize ( QSize ( 44 , 44 ) ) ;
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton - > setText ( QString ( ) ) ;
audioCaptureToggleButton - > setToolTip ( tr ( " Start Call " ) ) ;
audioCaptureToggleButton - > setIcon ( icon2 ) ;
2014-12-19 12:41:34 -05:00
audioCaptureToggleButton - > setIconSize ( QSize ( 42 , 42 ) ) ;
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton - > setAutoRaise ( true ) ;
audioCaptureToggleButton - > setCheckable ( true ) ;
2014-12-19 07:17:58 -05:00
hangupButton = new QToolButton ;
hangupButton - > setIcon ( QIcon ( " :/images/call-stop.png " ) ) ;
2014-12-19 12:41:34 -05:00
hangupButton - > setIconSize ( QSize ( 42 , 42 ) ) ;
hangupButton - > setMinimumSize ( QSize ( 44 , 44 ) ) ;
hangupButton - > setMaximumSize ( QSize ( 44 , 44 ) ) ;
2014-12-19 07:17:58 -05:00
hangupButton - > setCheckable ( false ) ;
hangupButton - > setAutoRaise ( true ) ;
hangupButton - > setText ( QString ( ) ) ;
hangupButton - > setToolTip ( tr ( " Hangup Call " ) ) ;
hangupButton - > hide ( ) ;
2014-07-13 09:57:25 -04:00
QIcon icon3 ;
2014-09-21 08:31:16 -04:00
icon3 . addPixmap ( QPixmap ( " :/images/video-icon-on.png " ) ) ;
icon3 . addPixmap ( QPixmap ( " :/images/video-icon-off.png " ) , QIcon : : Normal , QIcon : : On ) ;
icon3 . addPixmap ( QPixmap ( " :/images/video-icon-off.png " ) , QIcon : : Disabled , QIcon : : On ) ;
icon3 . addPixmap ( QPixmap ( " :/images/video-icon-off.png " ) , QIcon : : Active , QIcon : : On ) ;
icon3 . addPixmap ( QPixmap ( " :/images/video-icon-off.png " ) , QIcon : : Selected , QIcon : : On ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton = new QToolButton ;
2014-12-19 12:41:34 -05:00
videoCaptureToggleButton - > setMinimumSize ( QSize ( 44 , 44 ) ) ;
videoCaptureToggleButton - > setMaximumSize ( QSize ( 44 , 44 ) ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton - > setText ( QString ( ) ) ;
2014-08-13 09:19:22 -04:00
videoCaptureToggleButton - > setToolTip ( tr ( " Start Video Call " ) ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton - > setIcon ( icon3 ) ;
2014-12-19 12:41:34 -05:00
videoCaptureToggleButton - > setIconSize ( QSize ( 42 , 42 ) ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton - > setAutoRaise ( true ) ;
videoCaptureToggleButton - > setCheckable ( true ) ;
connect ( videoCaptureToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleVideoCapture ( ) ) ) ;
connect ( audioListenToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioListen ( ) ) ) ;
connect ( audioCaptureToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioCapture ( ) ) ) ;
connect ( hangupButton , SIGNAL ( clicked ( ) ) , this , SLOT ( hangupCall ( ) ) ) ;
2014-12-19 07:17:58 -05:00
mChatWidget - > addVOIPBarWidget ( audioListenToggleButton ) ;
mChatWidget - > addVOIPBarWidget ( audioCaptureToggleButton ) ;
mChatWidget - > addVOIPBarWidget ( hangupButton ) ;
mChatWidget - > addVOIPBarWidget ( videoCaptureToggleButton ) ;
2014-07-13 09:57:25 -04:00
outputAudioProcessor = NULL ;
outputAudioDevice = NULL ;
inputAudioProcessor = NULL ;
inputAudioDevice = NULL ;
inputVideoDevice = new QVideoInputDevice ( mChatWidget ) ; // not started yet ;-)
2015-08-14 16:44:20 -04:00
videoProcessor = new VideoProcessor ;
2014-07-13 09:57:25 -04:00
// Make a widget with two video devices, one for echo, and one for the talking peer.
videoWidget = new QWidget ( mChatWidget ) ;
2014-12-04 08:49:04 -05:00
videoWidget - > setLayout ( new QVBoxLayout ( ) ) ;
2014-07-13 09:57:25 -04:00
videoWidget - > layout ( ) - > addWidget ( outputVideoDevice = new QVideoOutputDevice ( videoWidget ) ) ;
2014-12-06 09:21:36 -05:00
videoWidget - > layout ( ) - > addWidget ( echoVideoDevice = new QVideoOutputDevice ( videoWidget ) ) ;
2014-09-20 12:28:26 -04:00
videoWidget - > hide ( ) ;
2014-07-13 09:57:25 -04:00
2014-07-15 16:04:31 -04:00
connect ( inputVideoDevice , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendVideoData ( ) ) ) ;
2014-12-04 08:49:04 -05:00
echoVideoDevice - > setMinimumSize ( 320 , 256 ) ;
outputVideoDevice - > setMinimumSize ( 320 , 256 ) ;
2014-12-05 11:47:59 -05:00
echoVideoDevice - > setStyleSheet ( " border: 4px solid #CCCCCC; border-radius: 4px; " ) ;
outputVideoDevice - > setStyleSheet ( " border: 4px solid #CCCCCC; border-radius: 4px; " ) ;
2014-07-13 09:57:25 -04:00
mChatWidget - > addChatHorizontalWidget ( videoWidget ) ;
inputVideoDevice - > setEchoVideoTarget ( echoVideoDevice ) ;
2015-08-14 16:44:20 -04:00
inputVideoDevice - > setVideoProcessor ( videoProcessor ) ;
videoProcessor - > setDisplayTarget ( outputVideoDevice ) ;
2014-07-13 09:57:25 -04:00
}
VOIPChatWidgetHolder : : ~ VOIPChatWidgetHolder ( )
{
if ( inputAudioDevice ! = NULL )
inputAudioDevice - > stop ( ) ;
delete inputVideoDevice ;
2015-08-14 16:44:20 -04:00
delete videoProcessor ;
2015-05-11 15:40:07 -04:00
button_map : : iterator it = buttonMapTakeVideo . begin ( ) ;
while ( it ! = buttonMapTakeVideo . end ( ) ) {
it = buttonMapTakeVideo . erase ( it ) ;
}
2014-07-13 09:57:25 -04:00
}
void VOIPChatWidgetHolder : : toggleAudioListen ( )
{
if ( audioListenToggleButton - > isChecked ( ) ) {
audioListenToggleButton - > setToolTip ( tr ( " Mute yourself " ) ) ;
} else {
audioListenToggleButton - > setToolTip ( tr ( " Unmute yourself " ) ) ;
//audioListenToggleButton->setChecked(false);
/*if (outputAudioDevice) {
outputAudioDevice - > stop ( ) ;
} */
}
}
void VOIPChatWidgetHolder : : hangupCall ( )
{
2014-07-20 16:50:36 -04:00
disconnect ( inputAudioProcessor , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendAudioData ( ) ) ) ;
if ( inputAudioDevice ) {
inputAudioDevice - > stop ( ) ;
}
if ( outputAudioDevice ) {
outputAudioDevice - > stop ( ) ;
}
2014-12-06 09:21:36 -05:00
if ( mChatWidget ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " Outgoing Call stopped. " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
}
2014-07-20 16:50:36 -04:00
audioListenToggleButton - > setChecked ( false ) ;
audioCaptureToggleButton - > setChecked ( false ) ;
2014-09-20 12:44:26 -04:00
hangupButton - > hide ( ) ;
2014-07-13 09:57:25 -04:00
}
2015-05-22 12:02:16 -04:00
void VOIPChatWidgetHolder : : startAudioCapture ( )
{
audioCaptureToggleButton - > setChecked ( true ) ;
toggleAudioCapture ( ) ;
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : toggleAudioCapture ( )
{
if ( audioCaptureToggleButton - > isChecked ( ) ) {
//activate audio output
audioListenToggleButton - > setChecked ( true ) ;
audioCaptureToggleButton - > setToolTip ( tr ( " Hold Call " ) ) ;
2014-09-20 12:44:26 -04:00
hangupButton - > show ( ) ;
2014-07-13 09:57:25 -04:00
//activate audio input
if ( ! inputAudioProcessor ) {
inputAudioProcessor = new QtSpeex : : SpeexInputProcessor ( ) ;
if ( outputAudioProcessor ) {
connect ( outputAudioProcessor , SIGNAL ( playingFrame ( QByteArray * ) ) , inputAudioProcessor , SLOT ( addEchoFrame ( QByteArray * ) ) ) ;
}
inputAudioProcessor - > open ( QIODevice : : WriteOnly | QIODevice : : Unbuffered ) ;
}
if ( ! inputAudioDevice ) {
inputAudioDevice = AudioDeviceHelper : : getPreferedInputDevice ( ) ;
}
connect ( inputAudioProcessor , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendAudioData ( ) ) ) ;
inputAudioDevice - > start ( inputAudioProcessor ) ;
if ( mChatWidget ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " Outgoing Call is started... " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
}
2015-05-22 12:02:16 -04:00
button_map : : iterator it = buttonMapTakeVideo . begin ( ) ;
while ( it ! = buttonMapTakeVideo . end ( ) ) {
RSButtonOnText * button = it . value ( ) ;
delete button ;
it = buttonMapTakeVideo . erase ( it ) ;
}
2014-07-13 09:57:25 -04:00
} else {
disconnect ( inputAudioProcessor , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendAudioData ( ) ) ) ;
if ( inputAudioDevice ) {
inputAudioDevice - > stop ( ) ;
}
audioCaptureToggleButton - > setToolTip ( tr ( " Resume Call " ) ) ;
2014-09-20 12:44:26 -04:00
hangupButton - > hide ( ) ;
2014-07-13 09:57:25 -04:00
}
}
2015-05-11 15:40:07 -04:00
void VOIPChatWidgetHolder : : startVideoCapture ( )
{
videoCaptureToggleButton - > setChecked ( true ) ;
toggleVideoCapture ( ) ;
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : toggleVideoCapture ( )
{
if ( videoCaptureToggleButton - > isChecked ( ) )
{
//activate video input
//
2014-09-20 12:28:26 -04:00
videoWidget - > show ( ) ;
2014-07-13 09:57:25 -04:00
inputVideoDevice - > start ( ) ;
videoCaptureToggleButton - > setToolTip ( tr ( " Shut camera off " ) ) ;
if ( mChatWidget )
2015-05-11 15:40:07 -04:00
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " You're now sending video... " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
button_map : : iterator it = buttonMapTakeVideo . begin ( ) ;
while ( it ! = buttonMapTakeVideo . end ( ) ) {
RSButtonOnText * button = it . value ( ) ;
delete button ;
it = buttonMapTakeVideo . erase ( it ) ;
}
2014-07-13 09:57:25 -04:00
}
else
{
2014-07-17 10:13:02 -04:00
inputVideoDevice - > stop ( ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton - > setToolTip ( tr ( " Activate camera " ) ) ;
2014-07-20 16:50:36 -04:00
outputVideoDevice - > showFrameOff ( ) ;
2014-09-20 12:28:26 -04:00
videoWidget - > hide ( ) ;
2014-12-06 09:21:36 -05:00
if ( mChatWidget )
2015-05-11 15:40:07 -04:00
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " Video call stopped " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
2014-07-13 09:57:25 -04:00
}
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : addVideoData ( const RsPeerId & peer_id , QByteArray * array )
2014-07-15 16:04:31 -04:00
{
2015-08-14 16:44:20 -04:00
if ( ! videoCaptureToggleButton - > isChecked ( ) )
{
if ( mChatWidget ) {
QString buttonName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
if ( buttonName . isEmpty ( ) ) buttonName = " VoIP " ; //TODO maybe change all with GxsId
button_map : : iterator it = buttonMapTakeVideo . find ( buttonName ) ;
if ( it = = buttonMapTakeVideo . end ( ) ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 inviting you to start a video conversation. do you want Accept or Decline the invitation? " ) . arg ( buttonName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
RSButtonOnText * button = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Accept Video Call " ) ) ;
button - > setToolTip ( tr ( " Activate camera " ) ) ;
button - > setStyleSheet ( QString ( " border: 1px solid #199909; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
" stop: 0 #22c70d, stop: 1 #116a06); " )
) ;
button - > updateImage ( ) ;
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( startVideoCapture ( ) ) ) ;
connect ( button , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnter ( ) ) ) ;
connect ( button , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeave ( ) ) ) ;
buttonMapTakeVideo . insert ( buttonName , button ) ;
}
}
//TODO make a sound for the incoming call
// soundManager->play(VOIP_SOUND_INCOMING_CALL);
if ( mVOIPNotify ) mVOIPNotify - > notifyReceivedVoipVideoCall ( peer_id ) ;
}
else
{
RsVOIPDataChunk chunk ;
chunk . type = RsVOIPDataChunk : : RS_VOIP_DATA_TYPE_VIDEO ;
chunk . size = array - > size ( ) ;
chunk . data = array - > data ( ) ;
videoProcessor - > receiveEncodedData ( chunk ) ;
}
2015-05-11 15:40:07 -04:00
}
void VOIPChatWidgetHolder : : botMouseEnter ( )
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
2015-05-22 12:02:16 -04:00
source - > setStyleSheet ( QString ( " border: 1px solid #333333; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
" stop: 0 #444444, stop: 1 #222222); " )
) ;
2015-05-11 15:40:07 -04:00
//source->setDown(true);
}
}
void VOIPChatWidgetHolder : : botMouseLeave ( )
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
2015-05-22 12:02:16 -04:00
source - > setStyleSheet ( QString ( " border: 1px solid #199909; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
" stop: 0 #22c70d, stop: 1 #116a06); " )
) ;
2015-05-11 15:40:07 -04:00
//source->setDown(false);
}
2014-07-15 16:04:31 -04:00
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : setAcceptedBandwidth ( uint32_t bytes_per_sec )
2014-07-20 16:50:36 -04:00
{
2015-08-14 16:44:20 -04:00
videoProcessor - > setMaximumFrameRate ( bytes_per_sec ) ;
2014-07-20 16:50:36 -04:00
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : addAudioData ( const RsPeerId & peer_id , QByteArray * array )
2014-07-13 09:57:25 -04:00
{
if ( ! audioCaptureToggleButton - > isChecked ( ) ) {
//launch an animation. Don't launch it if already animating
if ( ! audioCaptureToggleButton - > graphicsEffect ( ) | |
( audioCaptureToggleButton - > graphicsEffect ( ) - > inherits ( " QGraphicsOpacityEffect " ) & &
( ( QGraphicsOpacityEffect * ) audioCaptureToggleButton - > graphicsEffect ( ) ) - > opacity ( ) = = 1 )
) {
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect ( audioListenToggleButton ) ;
audioCaptureToggleButton - > setGraphicsEffect ( effect ) ;
2015-05-27 08:07:07 -04:00
QPropertyAnimation * anim = new QPropertyAnimation ( effect , " opacity " , effect ) ;
2014-07-13 09:57:25 -04:00
anim - > setStartValue ( 1 ) ;
anim - > setKeyValueAt ( 0.5 , 0 ) ;
anim - > setEndValue ( 1 ) ;
anim - > setDuration ( 400 ) ;
anim - > start ( ) ;
}
2015-05-22 12:02:16 -04:00
if ( mChatWidget ) {
2015-05-28 09:59:20 -04:00
QString buttonName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
2015-05-22 12:02:16 -04:00
if ( buttonName . isEmpty ( ) ) buttonName = " VoIP " ; //TODO maybe change all with GxsId
button_map : : iterator it = buttonMapTakeVideo . find ( buttonName ) ;
if ( it = = buttonMapTakeVideo . end ( ) ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 inviting you to start a audio conversation. do you want Accept or Decline the invitation? " ) . arg ( buttonName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
RSButtonOnText * button = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Accept Call " ) ) ;
button - > setToolTip ( tr ( " Activate audio " ) ) ;
button - > setStyleSheet ( QString ( " border: 1px solid #199909; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
" stop: 0 #22c70d, stop: 1 #116a06); " )
) ;
button - > updateImage ( ) ;
connect ( button , SIGNAL ( clicked ( ) ) , this , SLOT ( startAudioCapture ( ) ) ) ;
connect ( button , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnter ( ) ) ) ;
connect ( button , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeave ( ) ) ) ;
buttonMapTakeVideo . insert ( buttonName , button ) ;
}
}
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton - > setToolTip ( tr ( " Answer " ) ) ;
2015-05-26 11:19:57 -04:00
//TODO make a sound for the incoming call
// soundManager->play(VOIP_SOUND_INCOMING_CALL);
if ( mVOIPNotify ) mVOIPNotify - > notifyReceivedVoipAudioCall ( peer_id ) ;
2014-07-13 09:57:25 -04:00
return ;
}
if ( ! outputAudioDevice ) {
outputAudioDevice = AudioDeviceHelper : : getDefaultOutputDevice ( ) ;
}
if ( ! outputAudioProcessor ) {
//start output audio device
outputAudioProcessor = new QtSpeex : : SpeexOutputProcessor ( ) ;
if ( inputAudioProcessor ) {
connect ( outputAudioProcessor , SIGNAL ( playingFrame ( QByteArray * ) ) , inputAudioProcessor , SLOT ( addEchoFrame ( QByteArray * ) ) ) ;
}
outputAudioProcessor - > open ( QIODevice : : ReadOnly | QIODevice : : Unbuffered ) ;
outputAudioDevice - > start ( outputAudioProcessor ) ;
}
if ( outputAudioDevice & & outputAudioDevice - > error ( ) ! = QAudio : : NoError ) {
std : : cerr < < " Restarting output device. Error before reset " < < outputAudioDevice - > error ( ) < < " buffer size : " < < outputAudioDevice - > bufferSize ( ) < < std : : endl ;
outputAudioDevice - > stop ( ) ;
outputAudioDevice - > reset ( ) ;
if ( outputAudioDevice - > error ( ) = = QAudio : : UnderrunError )
outputAudioDevice - > setBufferSize ( 20 ) ;
outputAudioDevice - > start ( outputAudioProcessor ) ;
}
2015-05-26 11:19:57 -04:00
outputAudioProcessor - > putNetworkPacket ( QString : : fromStdString ( peer_id . toStdString ( ) ) , * array ) ;
2014-07-13 09:57:25 -04:00
//check the input device for errors
if ( inputAudioDevice & & inputAudioDevice - > error ( ) ! = QAudio : : NoError ) {
std : : cerr < < " Restarting input device. Error before reset " < < inputAudioDevice - > error ( ) < < std : : endl ;
inputAudioDevice - > stop ( ) ;
inputAudioDevice - > reset ( ) ;
inputAudioDevice - > start ( inputAudioProcessor ) ;
}
}
2014-07-15 16:04:31 -04:00
void VOIPChatWidgetHolder : : sendVideoData ( )
{
2015-05-11 15:40:07 -04:00
RsVOIPDataChunk chunk ;
2014-07-15 16:04:31 -04:00
while ( inputVideoDevice & & inputVideoDevice - > getNextEncodedPacket ( chunk ) )
2015-05-11 15:40:07 -04:00
rsVOIP - > sendVoipData ( mChatWidget - > getChatId ( ) . toPeerId ( ) , chunk ) ;
2014-07-15 16:04:31 -04:00
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : sendAudioData ( )
{
while ( inputAudioProcessor & & inputAudioProcessor - > hasPendingPackets ( ) ) {
QByteArray qbarray = inputAudioProcessor - > getNetworkPacket ( ) ;
2015-05-11 15:40:07 -04:00
RsVOIPDataChunk chunk ;
2014-07-13 09:57:25 -04:00
chunk . size = qbarray . size ( ) ;
chunk . data = ( void * ) qbarray . constData ( ) ;
2015-05-11 15:40:07 -04:00
chunk . type = RsVOIPDataChunk : : RS_VOIP_DATA_TYPE_AUDIO ;
rsVOIP - > sendVoipData ( mChatWidget - > getChatId ( ) . toPeerId ( ) , chunk ) ;
2014-07-13 09:57:25 -04:00
}
}
void VOIPChatWidgetHolder : : updateStatus ( int status )
{
audioListenToggleButton - > setEnabled ( true ) ;
audioCaptureToggleButton - > setEnabled ( true ) ;
hangupButton - > setEnabled ( true ) ;
switch ( status ) {
case RS_STATUS_OFFLINE :
audioListenToggleButton - > setEnabled ( false ) ;
audioCaptureToggleButton - > setEnabled ( false ) ;
hangupButton - > setEnabled ( false ) ;
break ;
}
}