diff --git a/plugins/VOIP/VOIPPlugin.cpp b/plugins/VOIP/VOIPPlugin.cpp index f914aa81b..78ab5820e 100644 --- a/plugins/VOIP/VOIPPlugin.cpp +++ b/plugins/VOIP/VOIPPlugin.cpp @@ -90,10 +90,10 @@ VOIPPlugin::VOIPPlugin() mVOIPGUIHandler = new VOIPGUIHandler ; mVOIPNotify = new VOIPNotify ; - QObject::connect(mVOIPNotify,SIGNAL(voipInvitationReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedInvitation(const RsPeerId&)),Qt::QueuedConnection) ; + QObject::connect(mVOIPNotify,SIGNAL(voipInvitationReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedInvitation(const RsPeerId&,int)),Qt::QueuedConnection) ; QObject::connect(mVOIPNotify,SIGNAL(voipDataReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipData(const RsPeerId&)),Qt::QueuedConnection) ; - QObject::connect(mVOIPNotify,SIGNAL(voipAcceptReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipAccept(const RsPeerId&)),Qt::QueuedConnection) ; - QObject::connect(mVOIPNotify,SIGNAL(voipHangUpReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipHangUp(const RsPeerId&)),Qt::QueuedConnection) ; + QObject::connect(mVOIPNotify,SIGNAL(voipAcceptReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipAccept(const RsPeerId&,int)),Qt::QueuedConnection) ; + QObject::connect(mVOIPNotify,SIGNAL(voipHangUpReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipHangUp(const RsPeerId&,int)),Qt::QueuedConnection) ; QObject::connect(mVOIPNotify,SIGNAL(voipBandwidthInfoReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const RsPeerId&,int)),Qt::QueuedConnection) ; Q_INIT_RESOURCE(VOIP_images); diff --git a/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp b/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp index a60b94550..abcb170e8 100644 --- a/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp +++ b/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp @@ -25,6 +25,7 @@ #include #include "interface/rsVOIP.h" + #include "gui/SoundManager.h" #include "util/HandleRichText.h" #include "gui/common/StatusDefs.h" @@ -65,6 +66,7 @@ VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget, VOIPNotify *n audioListenToggleButton->setAutoRaise(true) ; audioListenToggleButton->setText(QString()) ; audioListenToggleButton->setToolTip(tr("Mute")); + audioListenToggleButton->setEnabled(false); QIcon iconaudioCaptureToggleButton ; iconaudioCaptureToggleButton.addPixmap(QPixmap(":/images/call-start.png")) ; @@ -281,20 +283,172 @@ VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget, VOIPNotify *n inputVideoDevice->setEchoVideoTarget(echoVideoDevice) ; inputVideoDevice->setVideoProcessor(videoProcessor) ; videoProcessor->setDisplayTarget(outputVideoDevice) ; + + //Ring + pbAudioRing = new QProgressBar(); + pbAudioRing->setOrientation(Qt::Horizontal); + pbAudioRing->setRange(0, 99); + pbAudioRing->setTextVisible(false); + pbAudioRing->setHidden(true); + pbVideoRing = new QProgressBar(); + pbVideoRing->setOrientation(Qt::Horizontal); + pbVideoRing->setRange(0, 99); + pbVideoRing->setTextVisible(false); + pbVideoRing->setHidden(true); + mChatWidget->addChatBarWidget(pbAudioRing); + mChatWidget->addChatBarWidget(pbVideoRing); + + sendAudioRingTime = -1; + sendVideoRingTime = -1; + recAudioRingTime = -1; + recVideoRingTime = -1; + + timerAudioRing = new QTimer(this); + timerAudioRing->setInterval(300); + timerAudioRing->setSingleShot(true); + connect(timerAudioRing, SIGNAL(timeout()), this, SLOT(timerAudioRingTimeOut())); + timerVideoRing = new QTimer(this); + timerVideoRing->setInterval(300); + timerVideoRing->setSingleShot(true); + connect(timerVideoRing, SIGNAL(timeout()), this, SLOT(timerVideoRingTimeOut())); } VOIPChatWidgetHolder::~VOIPChatWidgetHolder() { + hangupCall(); + if(inputAudioDevice != NULL) inputAudioDevice->stop() ; delete inputVideoDevice ; delete videoProcessor ; + deleteButtonMap(); - button_map::iterator it = buttonMapTakeVideo.begin(); - while (it != buttonMapTakeVideo.end()) { - it = buttonMapTakeVideo.erase(it); - } + // stop and delete timers + timerAudioRing->stop(); + delete(timerAudioRing); + timerVideoRing->stop(); + delete(timerVideoRing); +} + +void VOIPChatWidgetHolder::deleteButtonMap(int flags) +{ + button_map::iterator it = buttonMapTakeCall.begin(); + while (it != buttonMapTakeCall.end()) { + if (((it.key().left(1) == "a") && (flags & RS_VOIP_FLAGS_AUDIO_DATA)) + || ((it.key().left(1) == "v") && (flags & RS_VOIP_FLAGS_VIDEO_DATA)) ) { + QPair pair = it.value(); + delete pair.second; + delete pair.first; + if (flags & RS_VOIP_FLAGS_AUDIO_DATA) recAudioRingTime = -1; + if (flags & RS_VOIP_FLAGS_VIDEO_DATA) recVideoRingTime = -1; + it = buttonMapTakeCall.erase(it); + } else { + ++it; + } + } +} + +void VOIPChatWidgetHolder::addNewAudioButtonMap(const RsPeerId &peer_id) +{ + if (mChatWidget) { + recAudioRingTime = 0; + timerAudioRingTimeOut(); + + QString buttonName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + if (buttonName.isEmpty()) buttonName = QString::fromStdString(peer_id.toStdString().c_str()); + if (buttonName.isEmpty()) buttonName = "VoIP"; + button_map::iterator it = buttonMapTakeCall.find(QString("a").append(buttonName)); + if (it == buttonMapTakeCall.end()){ + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 inviting you to start an audio conversation. Do you want Accept or Decline the invitation?").arg(buttonName), ChatWidget::MSGTYPE_SYSTEM); + + RSButtonOnText *buttonT = mChatWidget->getNewButtonOnTextBrowser(tr("Accept Audio Call")); + buttonT->setToolTip(tr("Activate audio")); + buttonT->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);") + ); + + buttonT->updateImage(); + + connect(buttonT,SIGNAL(clicked()),this,SLOT(startAudioCapture())); + connect(buttonT,SIGNAL(mouseEnter()),this,SLOT(botMouseEnterTake())); + connect(buttonT,SIGNAL(mouseLeave()),this,SLOT(botMouseLeaveTake())); + + RSButtonOnText *buttonD = mChatWidget->getNewButtonOnTextBrowser(tr("Decline Audio Call")); + buttonD->setToolTip(tr("Refuse audio call")); + buttonD->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 #c7220d, stop: 1 #6a1106);") + ); + + buttonD->updateImage(); + + connect(buttonD,SIGNAL(clicked()),this,SLOT(hangupCallAudio())); + connect(buttonD,SIGNAL(mouseEnter()),this,SLOT(botMouseEnterDecline())); + connect(buttonD,SIGNAL(mouseLeave()),this,SLOT(botMouseLeaveDecline())); + + buttonMapTakeCall.insert(QString("a").append(buttonName), QPair(buttonT, buttonD)); + } + } +} + +void VOIPChatWidgetHolder::addNewVideoButtonMap(const RsPeerId &peer_id) +{ + if (mChatWidget) { + recVideoRingTime = 0; + timerVideoRingTimeOut(); + + QString buttonName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + if (buttonName.isEmpty()) buttonName = QString::fromStdString(peer_id.toStdString().c_str()); + if (buttonName.isEmpty()) buttonName = "VoIP"; + button_map::iterator it = buttonMapTakeCall.find(QString("v").append(buttonName)); + if (it == buttonMapTakeCall.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 *buttonT = mChatWidget->getNewButtonOnTextBrowser(tr("Accept Video Call")); + buttonT->setToolTip(tr("Activate camera")); + buttonT->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);") + ); + + buttonT->updateImage(); + + connect(buttonT,SIGNAL(clicked()),this,SLOT(startVideoCapture())); + connect(buttonT,SIGNAL(mouseEnter()),this,SLOT(botMouseEnterTake())); + connect(buttonT,SIGNAL(mouseLeave()),this,SLOT(botMouseLeaveTake())); + + RSButtonOnText *buttonD = mChatWidget->getNewButtonOnTextBrowser(tr("Decline Video Call")); + buttonD->setToolTip(tr("Refuse video call")); + buttonD->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 #c7220d, stop: 1 #6a1106);") + ); + + buttonD->updateImage(); + + connect(buttonD,SIGNAL(clicked()),this,SLOT(hangupCallVideo())); + connect(buttonD,SIGNAL(mouseEnter()),this,SLOT(botMouseEnterDecline())); + connect(buttonD,SIGNAL(mouseLeave()),this,SLOT(botMouseLeaveDecline())); + + buttonMapTakeCall.insert(QString("v").append(buttonName), QPair(buttonT, buttonD)); + } + } } bool VOIPChatWidgetHolder::eventFilter(QObject *obj, QEvent *event) @@ -314,24 +468,59 @@ bool VOIPChatWidgetHolder::eventFilter(QObject *obj, QEvent *event) void VOIPChatWidgetHolder::hangupCall() { + hangupCallAudio(); + hangupCallVideo(); + hangupButton->hide(); + hangupButtonFS->hide(); + deleteButtonMap(); +} + +void VOIPChatWidgetHolder::hangupCallAudio() +{ + bool atLeastOneChecked = false; if (audioCaptureToggleButton->isChecked()) { audioCaptureToggleButton->setChecked(false); toggleAudioCapture(); + atLeastOneChecked = true; } + if (!atLeastOneChecked) { + //Decline button ,Friend hang up or chat close + if (recAudioRingTime != -1) { + rsVOIP->sendVoipHangUpCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_AUDIO_DATA); + deleteButtonMap(RS_VOIP_FLAGS_AUDIO_DATA); + } + sendAudioRingTime = -1; + recAudioRingTime = -1; + } +} + +void VOIPChatWidgetHolder::hangupCallVideo() +{ + bool atLeastOneChecked = false; if (videoCaptureToggleButton->isChecked()) { videoCaptureToggleButton->setChecked(false); toggleVideoCapture(); + atLeastOneChecked = true; } if (fullscreenToggleButton->isChecked()) { fullscreenToggleButton->setChecked(false); toggleFullScreen(); + atLeastOneChecked = true; } if (hideChatTextToggleButton->isChecked()) { hideChatTextToggleButton->setChecked(false); toggleHideChatText(); + atLeastOneChecked = true; + } + if (!atLeastOneChecked) { + //Decline button ,Friend hang up or chat close + if (recVideoRingTime != -1) { + rsVOIP->sendVoipHangUpCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_VIDEO_DATA); + deleteButtonMap(RS_VOIP_FLAGS_VIDEO_DATA); + } + sendVideoRingTime = -1; + recVideoRingTime = -1; } - hangupButton->hide(); - hangupButtonFS->hide(); } void VOIPChatWidgetHolder::toggleAudioListenFS() @@ -357,6 +546,7 @@ void VOIPChatWidgetHolder::toggleAudioListen() void VOIPChatWidgetHolder::startAudioCapture() { + recAudioRingTime = -2; audioCaptureToggleButton->setChecked(true); toggleAudioCapture(); } @@ -369,57 +559,85 @@ void VOIPChatWidgetHolder::toggleAudioCaptureFS() void VOIPChatWidgetHolder::toggleAudioCapture() { - if (audioCaptureToggleButton->isChecked()) { - //activate audio output - audioListenToggleButton->setChecked(true); - audioListenToggleButtonFS->setChecked(true); - audioCaptureToggleButton->setToolTip(tr("Hold Call")); - hangupButton->show(); - hangupButtonFS->show(); + if (audioCaptureToggleButton->isChecked()) { + if (recAudioRingTime == -1) { + if (sendAudioRingTime == -1) { + sendAudioRingTime = 0; + timerAudioRingTimeOut(); + rsVOIP->sendVoipRinging(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_AUDIO_DATA); + return; //Start Audio when accept received + } + } + if (recAudioRingTime != -1) + rsVOIP->sendVoipAcceptCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_AUDIO_DATA); + recAudioRingTime = -1; //Stop ringing - //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); - } - - button_map::iterator it = buttonMapTakeVideo.begin(); - while (it != buttonMapTakeVideo.end()) { - RSButtonOnText *button = it.value(); - delete button; - it = buttonMapTakeVideo.erase(it); - } - - } else { - disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); - if (inputAudioDevice) { - inputAudioDevice->stop(); - } - if (mChatWidget) { - mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Audio Call stopped."), ChatWidget::MSGTYPE_SYSTEM); - } - audioCaptureToggleButton->setToolTip(tr("Resume Call")); - hangupButton->hide(); - hangupButtonFS->hide(); - } - audioCaptureToggleButtonFS->setChecked(audioCaptureToggleButton->isChecked()); - audioCaptureToggleButtonFS->setToolTip(audioCaptureToggleButton->toolTip()); + //activate buttons + audioListenToggleButton->setEnabled(true); + audioListenToggleButton->setChecked(true); + audioListenToggleButtonFS->setEnabled(true); + audioListenToggleButtonFS->setChecked(true); + audioCaptureToggleButton->setToolTip(tr("Hold Call")); + hangupButton->show(); + hangupButtonFS->show(); + + //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); + + //send system message + if (mChatWidget) + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("Outgoing Call is started..."), ChatWidget::MSGTYPE_SYSTEM); + + deleteButtonMap(RS_VOIP_FLAGS_AUDIO_DATA); + } else { + //desactivate buttons + audioListenToggleButton->setEnabled(false); + audioListenToggleButton->setChecked(false); + audioListenToggleButtonFS->setEnabled(false); + audioListenToggleButtonFS->setChecked(false); + audioCaptureToggleButton->setToolTip(tr("Resume Call")); + if (!videoCaptureToggleButton->isChecked()) { + hangupButton->hide(); + hangupButtonFS->hide(); + } + + if (recAudioRingTime <= -1){ + //desactivate audio input + disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); + if (inputAudioDevice) { + inputAudioDevice->stop(); + } + + //send system message + if (mChatWidget) + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("Outgoing Audio Call stopped."), ChatWidget::MSGTYPE_SYSTEM); + + rsVOIP->sendVoipHangUpCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_AUDIO_DATA); + } + + sendAudioRingTime = -1; + recAudioRingTime = -1; + + } + audioCaptureToggleButtonFS->setChecked(audioCaptureToggleButton->isChecked()); + audioCaptureToggleButtonFS->setToolTip(audioCaptureToggleButton->toolTip()); } void VOIPChatWidgetHolder::startVideoCapture() { + recVideoRingTime = -2; videoCaptureToggleButton->setChecked(true); toggleVideoCapture(); } @@ -434,31 +652,38 @@ void VOIPChatWidgetHolder::toggleVideoCapture() { if (videoCaptureToggleButton->isChecked()) { + if (recVideoRingTime == -1) { + if (sendVideoRingTime == -1) { + sendVideoRingTime = 0; + timerVideoRingTimeOut(); + rsVOIP->sendVoipRinging(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_VIDEO_DATA); + return; //Start Video when accept received + } + } + if (recVideoRingTime != -1) + rsVOIP->sendVoipAcceptCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_VIDEO_DATA); + recVideoRingTime = -1; //Stop ringing + + //activate buttons hideChatTextToggleButton->setEnabled(true); fullscreenToggleButton->setEnabled(true); fullscreenToggleButtonFS->setEnabled(true); + videoCaptureToggleButton->setToolTip(tr("Shut camera off")); hangupButton->show(); hangupButtonFS->show(); + //activate video input - // videoWidget->show(); inputVideoDevice->start() ; - videoCaptureToggleButton->setToolTip(tr("Shut camera off")); - - if (mChatWidget) + //send system message + if (mChatWidget) 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); - } - } - else - { + deleteButtonMap(RS_VOIP_FLAGS_VIDEO_DATA); + } else { + //desactivate buttons hideChatTextToggleButton->setEnabled(false); hideChatTextToggleButton->setChecked(false); toggleHideChatText(); @@ -467,17 +692,29 @@ void VOIPChatWidgetHolder::toggleVideoCapture() fullscreenToggleButtonFS->setEnabled(false); fullscreenToggleButtonFS->setChecked(false); toggleFullScreen(); - hangupButton->hide(); - hangupButtonFS->hide(); - - inputVideoDevice->stop() ; videoCaptureToggleButton->setToolTip(tr("Activate camera")); - outputVideoDevice->showFrameOff(); - videoWidget->hide(); - - if (mChatWidget) - mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() - , tr("Video call stopped"), ChatWidget::MSGTYPE_SYSTEM); + if (!audioCaptureToggleButton->isChecked()) { + hangupButton->hide(); + hangupButtonFS->hide(); + } + + if (recVideoRingTime<=-1){ + //desactivate video input + inputVideoDevice->stop() ; + outputVideoDevice->showFrameOff(); + videoWidget->hide(); + + //send system message + if (mChatWidget) + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("Video call stopped"), ChatWidget::MSGTYPE_SYSTEM); + + rsVOIP->sendVoipHangUpCall(mChatWidget->getChatId().toPeerId(), RS_VOIP_FLAGS_VIDEO_DATA); + } + + sendVideoRingTime = -1; + recVideoRingTime = -1; + } videoCaptureToggleButtonFS->setChecked(videoCaptureToggleButton->isChecked()); videoCaptureToggleButtonFS->setToolTip(videoCaptureToggleButton->toolTip()); @@ -485,50 +722,19 @@ void VOIPChatWidgetHolder::toggleVideoCapture() void VOIPChatWidgetHolder::addVideoData(const RsPeerId &peer_id, QByteArray* array) { - 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);") + sendVideoRingTime = -2;//Receive Video so Accepted + if (!videoCaptureToggleButton->isChecked()) { + addNewVideoButtonMap(peer_id); + return; + } - ); + RsVOIPDataChunk chunk ; + chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO ; + chunk.size = array->size() ; + chunk.data = array->data() ; - button->updateImage(); + videoProcessor->receiveEncodedData(chunk) ; - 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) ; - } } void VOIPChatWidgetHolder::toggleHideChatText() @@ -602,34 +808,62 @@ void VOIPChatWidgetHolder::showNormalView() toggleFullScreen(); } -void VOIPChatWidgetHolder::botMouseEnter() +void VOIPChatWidgetHolder::botMouseEnterTake() { RSButtonOnText *source = qobject_cast(QObject::sender()); if (source){ 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);") - - ); + .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);") + ); //source->setDown(true); } } -void VOIPChatWidgetHolder::botMouseLeave() +void VOIPChatWidgetHolder::botMouseLeaveTake() { RSButtonOnText *source = qobject_cast(QObject::sender()); if (source){ 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);") + .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);") + ); + //source->setDown(false); + } +} - ); +void VOIPChatWidgetHolder::botMouseEnterDecline() +{ + RSButtonOnText *source = qobject_cast(QObject::sender()); + if (source){ + 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);") + ); + //source->setDown(true); + } +} + +void VOIPChatWidgetHolder::botMouseLeaveDecline() +{ + RSButtonOnText *source = qobject_cast(QObject::sender()); + if (source){ + 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 #c7220d, stop: 1 #6a1106);") + ); //source->setDown(false); } } @@ -641,57 +875,9 @@ void VOIPChatWidgetHolder::setAcceptedBandwidth(uint32_t bytes_per_sec) void VOIPChatWidgetHolder::addAudioData(const RsPeerId &peer_id, QByteArray* array) { + sendAudioRingTime = -2;//Receive Audio so Accepted 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); - QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity", effect); - anim->setStartValue(1); - anim->setKeyValueAt(0.5,0); - anim->setEndValue(1); - anim->setDuration(400); - anim->start(); - } - - 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 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); - } - } - - audioCaptureToggleButton->setToolTip(tr("Answer")); - - //TODO make a sound for the incoming call -// soundManager->play(VOIP_SOUND_INCOMING_CALL); - if (mVOIPNotify) mVOIPNotify->notifyReceivedVoipAudioCall(peer_id); - + addNewAudioButtonMap(peer_id); return; } @@ -733,7 +919,7 @@ void VOIPChatWidgetHolder::sendVideoData() RsVOIPDataChunk chunk ; while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk)) - rsVOIP->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk) ; + rsVOIP->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk) ; } void VOIPChatWidgetHolder::sendAudioData() @@ -743,7 +929,7 @@ void VOIPChatWidgetHolder::sendAudioData() RsVOIPDataChunk chunk; chunk.size = qbarray.size(); chunk.data = (void*)qbarray.constData(); - chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO ; + chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO ; rsVOIP->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk); } } @@ -752,8 +938,8 @@ void VOIPChatWidgetHolder::updateStatus(int status) { bool enabled = (status != RS_STATUS_OFFLINE); - audioListenToggleButton->setEnabled(enabled); - audioListenToggleButtonFS->setEnabled(enabled); + audioListenToggleButton->setEnabled(audioCaptureToggleButton->isChecked() && enabled); + audioListenToggleButtonFS->setEnabled(audioCaptureToggleButton->isChecked() && enabled); audioCaptureToggleButton->setEnabled(enabled); audioCaptureToggleButtonFS->setEnabled(enabled); videoCaptureToggleButton->setEnabled(enabled); @@ -764,3 +950,206 @@ void VOIPChatWidgetHolder::updateStatus(int status) hangupButton->setEnabled(enabled); hangupButtonFS->setEnabled(enabled); } + +void VOIPChatWidgetHolder::ReceivedInvitation(const RsPeerId &peer_id, int flags) +{ + switch(flags){ + case RS_VOIP_FLAGS_AUDIO_DATA: { + if (audioCaptureToggleButton->isChecked()) { + if (recAudioRingTime != -1) + toggleAudioCapture(); + } else { + addNewAudioButtonMap(peer_id); + } + } + break; + case RS_VOIP_FLAGS_VIDEO_DATA: { + if (videoCaptureToggleButton->isChecked()) { + if (recVideoRingTime != -1) + toggleVideoCapture(); + } else { + addNewVideoButtonMap(peer_id); + } + } + break; + default: + std::cerr << "VOIPChatWidgetHolder::ReceivedInvitation(): Received unknown flags item # " << flags << ": not handled yet ! Sorry" << std::endl; + break ; + } +} + +void VOIPChatWidgetHolder::ReceivedVoipHangUp(const RsPeerId &peer_id, int flags) +{ + switch(flags){ + case RS_VOIP_FLAGS_AUDIO_DATA | RS_VOIP_FLAGS_VIDEO_DATA: { + if (mChatWidget) { + if (videoCaptureToggleButton->isChecked() || audioCaptureToggleButton->isChecked()) { + QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 hang up. Your call is closed.").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); + } + hangupCall(); + } + } + break; + case RS_VOIP_FLAGS_AUDIO_DATA: { + if (mChatWidget) { + if (audioCaptureToggleButton->isChecked()) { + QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 hang up. Your audio call is closed.").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); + } + hangupCallAudio(); + } + } + break; + case RS_VOIP_FLAGS_VIDEO_DATA: { + if (mChatWidget) { + if (videoCaptureToggleButton->isChecked()) { + QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 hang up. Your video call is closed.").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); + } + hangupCallVideo(); + } + } + break; + default: + std::cerr << "VOIPChatWidgetHolder::ReceivedVoipHangUp(): Received unknown flags item # " << flags << ": not handled yet ! Sorry" << std::endl; + break ; + } + //deleteButtonMap(); +} + +void VOIPChatWidgetHolder::ReceivedVoipAccept(const RsPeerId &peer_id, int flags) +{ + switch(flags){ + case RS_VOIP_FLAGS_AUDIO_DATA: { + if (mChatWidget) { + sendAudioRingTime = -2; + QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 accepted your audio call.").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); + if (audioCaptureToggleButton->isChecked()) + toggleAudioCapture(); + } + } + break; + case RS_VOIP_FLAGS_VIDEO_DATA: { + if (mChatWidget) { + sendVideoRingTime = -2; + QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str()); + mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime() + , tr("%1 accepted your video call.").arg(peerName), ChatWidget::MSGTYPE_SYSTEM); + if (videoCaptureToggleButton->isChecked()) + toggleVideoCapture(); + } + } + break; + default: + std::cerr << "VOIPChatWidgetHolder::ReceivedVoipHangUp(): Received unknown flags item # " << flags << ": not handled yet ! Sorry" << std::endl; + break ; + } +} + +void VOIPChatWidgetHolder::timerAudioRingTimeOut() +{ + //Sending or receiving (-2 connected, -1 reseted, >=0 in progress) + if (sendAudioRingTime >= 0) { + //Sending + ++sendAudioRingTime; + if (sendAudioRingTime == 100) sendAudioRingTime = 0; + pbAudioRing->setValue(sendAudioRingTime); + pbAudioRing->setToolTip(tr("Waiting your friend respond your audio call.")); + pbAudioRing->setVisible(true); + + timerAudioRing->start(); + } else if(recAudioRingTime >= 0) { + //Receiving + ++recAudioRingTime; + if (recAudioRingTime == 100) recAudioRingTime = 0; + pbAudioRing->setValue(recAudioRingTime); + pbAudioRing->setToolTip(tr("Your friend is calling you for audio. Respond.")); + pbAudioRing->setVisible(true); + + //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); + QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity", effect); + anim->setStartValue(1); + anim->setKeyValueAt(0.5,0); + anim->setEndValue(1); + anim->setDuration(timerAudioRing->interval()); + anim->start(); + } + audioCaptureToggleButton->setToolTip(tr("Answer")); + + //TODO make a sound for the incoming call + //soundManager->play(VOIP_SOUND_INCOMING_CALL); + + if (mVOIPNotify) mVOIPNotify->notifyReceivedVoipAudioCall(mChatWidget->getChatId().toPeerId()); + + timerAudioRing->start(); + } else { + //Nothing to do, reset stat + pbAudioRing->setHidden(true); + pbAudioRing->setValue(0); + pbAudioRing->setToolTip(""); + audioCaptureToggleButton->setGraphicsEffect(0); + } +} + +void VOIPChatWidgetHolder::timerVideoRingTimeOut() +{ + //Sending or receiving (-2 connected, -1 reseted, >=0 in progress) + if (sendVideoRingTime >= 0) { + //Sending + ++sendVideoRingTime; + if (sendVideoRingTime == 100) sendVideoRingTime = 0; + pbVideoRing->setValue(sendVideoRingTime); + pbVideoRing->setToolTip(tr("Waiting your friend respond your video call.")); + pbVideoRing->setVisible(true); + + timerVideoRing->start(); + } else if(recVideoRingTime >= 0) { + //Receiving + ++recVideoRingTime; + if (recVideoRingTime == 100) recVideoRingTime = 0; + pbVideoRing->setValue(recVideoRingTime); + pbVideoRing->setToolTip(tr("Your friend is calling you for video. Respond.")); + pbVideoRing->setVisible(true); + + //launch an animation. Don't launch it if already animating + if (!videoCaptureToggleButton->graphicsEffect() + || (videoCaptureToggleButton->graphicsEffect()->inherits("QGraphicsOpacityEffect") + && ((QGraphicsOpacityEffect*)videoCaptureToggleButton->graphicsEffect())->opacity() == 1) + ) { + QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(audioListenToggleButton); + videoCaptureToggleButton->setGraphicsEffect(effect); + QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity", effect); + anim->setStartValue(1); + anim->setKeyValueAt(0.5,0); + anim->setEndValue(1); + anim->setDuration(timerVideoRing->interval()); + anim->start(); + } + videoCaptureToggleButton->setToolTip(tr("Answer")); + + //TODO make a sound for the incoming call + // soundManager->play(VOIP_SOUND_INCOMING_CALL); + + if (mVOIPNotify) mVOIPNotify->notifyReceivedVoipVideoCall(mChatWidget->getChatId().toPeerId()); + + timerVideoRing->start(); + } else { + //Nothing to do, reset stat + pbVideoRing->setHidden(true); + pbVideoRing->setValue(0); + pbVideoRing->setToolTip(""); + videoCaptureToggleButton->setGraphicsEffect(0); + } +} diff --git a/plugins/VOIP/gui/VOIPChatWidgetHolder.h b/plugins/VOIP/gui/VOIPChatWidgetHolder.h index ccea1167a..94f6fce96 100644 --- a/plugins/VOIP/gui/VOIPChatWidgetHolder.h +++ b/plugins/VOIP/gui/VOIPChatWidgetHolder.h @@ -20,12 +20,16 @@ ****************************************************************/ #pragma once - -#include "gui/VOIPNotify.h" - +//Qt #include #include +#include +#include +//VOIP +#include "gui/VOIPNotify.h" #include +#include "services/rsVOIPItems.h" +//retroshare-gui #include #include @@ -52,6 +56,10 @@ public: void addVideoData(const RsPeerId &peer_id, QByteArray* array) ; void setAcceptedBandwidth(uint32_t bytes_per_sec) ; + void ReceivedInvitation(const RsPeerId &peer_id, int flags) ; + void ReceivedVoipHangUp(const RsPeerId &peer_id, int flags) ; + void ReceivedVoipAccept(const RsPeerId &peer_id, int flags) ; + public slots: void sendAudioData(); void sendVideoData(); @@ -69,10 +77,19 @@ private slots: void toggleFullScreen(); void toggleFullScreenFS(); void hangupCall() ; - void botMouseEnter(); - void botMouseLeave(); + void hangupCallAudio() ; + void hangupCallVideo() ; + void botMouseEnterTake(); + void botMouseLeaveTake(); + void botMouseEnterDecline(); + void botMouseLeaveDecline(); + void timerAudioRingTimeOut(); + void timerVideoRingTimeOut(); private: + void deleteButtonMap(int flags = RS_VOIP_FLAGS_AUDIO_DATA | RS_VOIP_FLAGS_VIDEO_DATA); + void addNewVideoButtonMap(const RsPeerId &peer_id); + void addNewAudioButtonMap(const RsPeerId &peer_id); void replaceFullscreenWidget(); void showNormalView(); @@ -115,8 +132,18 @@ protected: QToolButton *hangupButtonFS ; QFrame *toolBarFS; - typedef QMap button_map; - button_map buttonMapTakeVideo; + typedef QMap > button_map; + button_map buttonMapTakeCall; + + //Waiting for peer accept + QProgressBar *pbAudioRing; + QProgressBar *pbVideoRing; + QTimer *timerAudioRing; + QTimer *timerVideoRing; + int sendAudioRingTime; //(-2 connected, -1 reseted, >=0 in progress) + int sendVideoRingTime; //(-2 connected, -1 reseted, >=0 in progress) + int recAudioRingTime; //(-2 connected, -1 reseted, >=0 in progress) + int recVideoRingTime; //(-2 connected, -1 reseted, >=0 in progress) VOIPNotify *mVOIPNotify; }; diff --git a/plugins/VOIP/gui/VOIPGUIHandler.cpp b/plugins/VOIP/gui/VOIPGUIHandler.cpp index 03703d71a..03e4739be 100644 --- a/plugins/VOIP/gui/VOIPGUIHandler.cpp +++ b/plugins/VOIP/gui/VOIPGUIHandler.cpp @@ -22,28 +22,89 @@ #include #include #include "VOIPGUIHandler.h" -#include #include + +#include #include "gui/chat/ChatWidget.h" #include "gui/settings/rsharesettings.h" -void VOIPGUIHandler::ReceivedInvitation(const RsPeerId &/*peer_id*/) +void VOIPGUIHandler::ReceivedInvitation(const RsPeerId &peer_id, int flags) { - std::cerr << "****** VOIPGUIHandler: received Invitation!" << std::endl; +#ifdef VOIPGUIHANDLER_DEBUG + std::cerr << "****** VOIPGUIHandler: received Invitation from peer " << peer_id.toStdString() << " with flags==" << flags << std::endl; +#endif + ChatDialog *di = ChatDialog::getChat(ChatId(peer_id), Settings->getChatFlags()); + if (di) { + ChatWidget *cw = di->getChatWidget(); + if(cw) { + const QList &chatWidgetHolderList = cw->chatWidgetHolderList(); + + foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) + { + VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; + + if (acwh) + acwh->ReceivedInvitation(peer_id, flags); + } + } + } else { + std::cerr << "VOIPGUIHandler::ReceivedInvitation() Error: received invitaion call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; + } } -void VOIPGUIHandler::ReceivedVoipHangUp(const RsPeerId &/*peer_id*/) +void VOIPGUIHandler::ReceivedVoipHangUp(const RsPeerId &peer_id, int flags) { - std::cerr << "****** VOIPGUIHandler: received HangUp!" << std::endl; +#ifdef VOIPGUIHANDLER_DEBUG + std::cerr << "****** VOIPGUIHandler: received HangUp from peer " << peer_id.toStdString() << " with flags==" << flags << std::endl; +#endif + ChatDialog *di = ChatDialog::getExistingChat(ChatId(peer_id)) ; + if (di) { + ChatWidget *cw = di->getChatWidget(); + if(cw) { + const QList &chatWidgetHolderList = cw->chatWidgetHolderList(); + + foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) + { + VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; + + if (acwh) + acwh->ReceivedVoipHangUp(peer_id, flags); + } + } + } else { + std::cerr << "VOIPGUIHandler::ReceivedVoipHangUp() Error: Received hangup call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; + } } -void VOIPGUIHandler::ReceivedVoipAccept(const RsPeerId &/*peer_id*/) +void VOIPGUIHandler::ReceivedVoipAccept(const RsPeerId &peer_id, int flags) { - std::cerr << "****** VOIPGUIHandler: received VoipAccept!" << std::endl; +#ifdef VOIPGUIHANDLER_DEBUG + std::cerr << "****** VOIPGUIHandler: received VoipAccept from peer " << peer_id.toStdString() << " with flags==" << flags << std::endl; +#endif + ChatDialog *di = ChatDialog::getExistingChat(ChatId(peer_id)) ; + if (di) { + ChatWidget *cw = di->getChatWidget(); + if(cw) { + const QList &chatWidgetHolderList = cw->chatWidgetHolderList(); + + foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) + { + VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; + + if (acwh) + acwh->ReceivedVoipAccept(peer_id, flags); + } + } + } else { + std::cerr << "VOIPGUIHandler::ReceivedVoipAccept() Error: Received accept call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; + } } void VOIPGUIHandler::ReceivedVoipData(const RsPeerId &peer_id) { +#ifdef VOIPGUIHANDLER_DEBUG + std::cerr << "****** VOIPGUIHandler: received VoipData from peer " << peer_id.toStdString() << std::endl; +#endif std::vector chunks ; if(!rsVOIP->getIncomingData(peer_id,chunks)) @@ -72,14 +133,14 @@ void VOIPGUIHandler::ReceivedVoipData(const RsPeerId &peer_id) else if(chunks[chunkIndex].type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO) acwh->addVideoData(peer_id, &qb); else - std::cerr << "VOIPGUIHandler: Unknown data type received. type=" << chunks[chunkIndex].type << std::endl; + std::cerr << "VOIPGUIHandler::ReceivedVoipData(): Unknown data type received. type=" << chunks[chunkIndex].type << std::endl; } break; } } } } else { - std::cerr << "VOIPGUIHandler Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl; + std::cerr << "VOIPGUIHandler::ReceivedVoipData() Error: received data for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; } for(unsigned int chunkIndex=0; chunkIndexgetChatWidget(); - if(!cw) - { - return ; - } + ChatWidget *cw = di->getChatWidget(); + if(!cw) + { + return ; + } - const QList &chatWidgetHolderList = cw->chatWidgetHolderList(); + const QList &chatWidgetHolderList = cw->chatWidgetHolderList(); - foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) - { - VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; + foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) + { + VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; - if (acwh) - acwh->setAcceptedBandwidth(bytes_per_sec); + if (acwh) + acwh->setAcceptedBandwidth(bytes_per_sec); + } + } else { + std::cerr << "VOIPGUIHandler::ReceivedVoipBandwidthInfo() Error: received bandwidth info for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; } } void VOIPGUIHandler::AnswerAudioCall(const RsPeerId &peer_id) { +#ifdef VOIPGUIHANDLER_DEBUG + std::cerr << "VOIPGUIHandler::Answer to Audio Call for peer " << peer_id.toStdString() << std::endl; +#endif + ChatDialog *di = ChatDialog::getExistingChat(ChatId(peer_id)) ; if (di) { ChatWidget *cw = di->getChatWidget(); @@ -132,9 +199,8 @@ void VOIPGUIHandler::AnswerAudioCall(const RsPeerId &peer_id) } } } else { - std::cerr << "VOIPGUIHandler Error: answer audio call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; + std::cerr << "VOIPGUIHandler::AnswerAudioCall() Error: answer audio call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; } - } void VOIPGUIHandler::AnswerVideoCall(const RsPeerId &peer_id) @@ -154,7 +220,6 @@ void VOIPGUIHandler::AnswerVideoCall(const RsPeerId &peer_id) } } } else { - std::cerr << "VOIPGUIHandler Error: answer video call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; + std::cerr << "VOIPGUIHandler::AnswerVideoCall() Error: answer video call for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl; } - } diff --git a/plugins/VOIP/gui/VOIPGUIHandler.h b/plugins/VOIP/gui/VOIPGUIHandler.h index 69396a084..cb52890c1 100644 --- a/plugins/VOIP/gui/VOIPGUIHandler.h +++ b/plugins/VOIP/gui/VOIPGUIHandler.h @@ -32,6 +32,9 @@ #include #include +/*** +#define VOIPGUIHANDLER_DEBUG 1 +***/ class VOIPGUIHandler: public QObject { @@ -41,9 +44,9 @@ public: static void AnswerVideoCall(const RsPeerId &peer_id) ; public slots: - void ReceivedInvitation(const RsPeerId &peer_id) ; + void ReceivedInvitation(const RsPeerId &peer_id, int flags) ; void ReceivedVoipData(const RsPeerId &peer_id) ; - void ReceivedVoipHangUp(const RsPeerId &peer_id) ; - void ReceivedVoipAccept(const RsPeerId &peer_id) ; + void ReceivedVoipHangUp(const RsPeerId &peer_id, int flags) ; + void ReceivedVoipAccept(const RsPeerId &peer_id, int flags) ; void ReceivedVoipBandwidthInfo(const RsPeerId &peer_id, int) ; }; diff --git a/plugins/VOIP/gui/VOIPNotify.cpp b/plugins/VOIP/gui/VOIPNotify.cpp index 3e954ea70..f2def5ee6 100644 --- a/plugins/VOIP/gui/VOIPNotify.cpp +++ b/plugins/VOIP/gui/VOIPNotify.cpp @@ -23,9 +23,9 @@ //Call qRegisterMetaType("RsPeerId"); to enable these SIGNALs -void VOIPNotify::notifyReceivedVoipAccept(const RsPeerId& peer_id) +void VOIPNotify::notifyReceivedVoipAccept(const RsPeerId& peer_id, const uint32_t flags) { - emit voipAcceptReceived(peer_id) ; + emit voipAcceptReceived(peer_id, flags) ; } void VOIPNotify::notifyReceivedVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) { @@ -35,13 +35,13 @@ void VOIPNotify::notifyReceivedVoipData(const RsPeerId &peer_id) { emit voipDataReceived(peer_id) ; } -void VOIPNotify::notifyReceivedVoipHangUp(const RsPeerId &peer_id) +void VOIPNotify::notifyReceivedVoipHangUp(const RsPeerId &peer_id, const uint32_t flags) { - emit voipHangUpReceived(peer_id) ; + emit voipHangUpReceived(peer_id, flags) ; } -void VOIPNotify::notifyReceivedVoipInvite(const RsPeerId& peer_id) +void VOIPNotify::notifyReceivedVoipInvite(const RsPeerId& peer_id, const uint32_t flags) { - emit voipInvitationReceived(peer_id) ; + emit voipInvitationReceived(peer_id, flags) ; } void VOIPNotify::notifyReceivedVoipAudioCall(const RsPeerId &peer_id) { diff --git a/plugins/VOIP/gui/VOIPNotify.h b/plugins/VOIP/gui/VOIPNotify.h index 4ee1e9e1f..31353f8fc 100644 --- a/plugins/VOIP/gui/VOIPNotify.h +++ b/plugins/VOIP/gui/VOIPNotify.h @@ -38,21 +38,20 @@ class VOIPNotify: public QObject Q_OBJECT public: - void notifyReceivedVoipAccept(const RsPeerId &peer_id) ; + void notifyReceivedVoipAccept(const RsPeerId &peer_id, const uint32_t flags) ; void notifyReceivedVoipBandwidth(const RsPeerId &peer_id, uint32_t bytes_per_sec) ; void notifyReceivedVoipData(const RsPeerId &peer_id) ; - void notifyReceivedVoipHangUp(const RsPeerId &peer_id) ; - void notifyReceivedVoipInvite(const RsPeerId &peer_id) ; + void notifyReceivedVoipHangUp(const RsPeerId &peer_id, const uint32_t flags) ; + void notifyReceivedVoipInvite(const RsPeerId &peer_id, const uint32_t flags) ; void notifyReceivedVoipAudioCall(const RsPeerId &peer_id) ; void notifyReceivedVoipVideoCall(const RsPeerId &peer_id) ; signals: - void voipAcceptReceived(const RsPeerId &peer_id) ; // emitted when the peer accepts the call + void voipAcceptReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer accepts the call void voipBandwidthInfoReceived(const RsPeerId &peer_id, int bytes_per_sec) ; // emitted when measured bandwidth info is received by the peer. void voipDataReceived(const RsPeerId &peer_id) ; // signal emitted when some voip data has been received - void voipHangUpReceived(const RsPeerId &peer_id) ; // emitted when the peer closes the call (i.e. hangs up) - void voipInvitationReceived(const RsPeerId &peer_id) ; // signal emitted when an invitation has been received - + void voipHangUpReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer closes the call (i.e. hangs up) + void voipInvitationReceived(const RsPeerId &peer_id, int flags) ; // signal emitted when an invitation has been received void voipAudioCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send audio void voipVideoCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send video }; diff --git a/plugins/VOIP/gui/VOIPToasterItem.cpp b/plugins/VOIP/gui/VOIPToasterItem.cpp index f848ea3e6..e704f5433 100644 --- a/plugins/VOIP/gui/VOIPToasterItem.cpp +++ b/plugins/VOIP/gui/VOIPToasterItem.cpp @@ -79,7 +79,8 @@ void VOIPToasterItem::chatButtonSlot() hide(); } -void VOIPToasterItem::voipAcceptReceived(const RsPeerId &) +#ifdef VOIPTOASTERNOTIFY_ALL +void VOIPToasterItem::voipAcceptReceived(const RsPeerId &, int ) { } @@ -91,11 +92,11 @@ void VOIPToasterItem::voipDataReceived(const RsPeerId &) { } -void VOIPToasterItem::voipHangUpReceived(const RsPeerId &) +void VOIPToasterItem::voipHangUpReceived(const RsPeerId &, int ) { } -void VOIPToasterItem::voipInvitationReceived(const RsPeerId &) +void VOIPToasterItem::voipInvitationReceived(const RsPeerId &, int ) { } @@ -106,4 +107,4 @@ void VOIPToasterItem::voipAudioCallReceived(const RsPeerId &) void VOIPToasterItem::voipVideoCallReceived(const RsPeerId &) { } - +#endif diff --git a/plugins/VOIP/gui/VOIPToasterItem.h b/plugins/VOIP/gui/VOIPToasterItem.h index dc43bd41c..8d4f82ebd 100644 --- a/plugins/VOIP/gui/VOIPToasterItem.h +++ b/plugins/VOIP/gui/VOIPToasterItem.h @@ -45,13 +45,15 @@ public: private slots: void chatButtonSlot(); - void voipAcceptReceived(const RsPeerId &peer_id) ; // emitted when the peer accepts the call +#ifdef VOIPTOASTERNOTIFY_ALL + void voipAcceptReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer accepts the call void voipBandwidthInfoReceived(const RsPeerId &peer_id, int bytes_per_sec) ; // emitted when measured bandwidth info is received by the peer. void voipDataReceived(const RsPeerId &peer_id) ; // signal emitted when some voip data has been received - void voipHangUpReceived(const RsPeerId &peer_id) ; // emitted when the peer closes the call (i.e. hangs up) - void voipInvitationReceived(const RsPeerId &peer_id) ; // signal emitted when an invitation has been received + void voipHangUpReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer closes the call (i.e. hangs up) + void voipInvitationReceived(const RsPeerId &peer_id, int flags) ; // signal emitted when an invitation has been received void voipAudioCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send audio void voipVideoCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send video +#endif private: RsPeerId mPeerId; diff --git a/plugins/VOIP/gui/VOIPToasterNotify.cpp b/plugins/VOIP/gui/VOIPToasterNotify.cpp index 050e30925..7d2ef37b4 100644 --- a/plugins/VOIP/gui/VOIPToasterNotify.cpp +++ b/plugins/VOIP/gui/VOIPToasterNotify.cpp @@ -36,11 +36,11 @@ VOIPToasterNotify::VOIPToasterNotify(RsVOIP *VOIP, VOIPNotify *notify, QObject * mMutex = new QMutex(); #ifdef VOIPTOASTERNOTIFY_ALL - connect(mVOIPNotify, SIGNAL(voipAcceptReceived(const RsPeerId&)), this, SLOT(voipAcceptReceived(const RsPeerId&)), Qt::QueuedConnection); + connect(mVOIPNotify, SIGNAL(voipAcceptReceived(const RsPeerId&, int)), this, SLOT(voipAcceptReceived(const RsPeerId&, int)), Qt::QueuedConnection); connect(mVOIPNotify, SIGNAL(voipBandwidthInfoReceived(const RsPeerId&, int)), this, SLOT(voipBandwidthInfoReceived(RsPeerId&, int)), Qt::QueuedConnection); connect(mVOIPNotify, SIGNAL(voipDataReceived(const RsPeerId&)), this, SLOT(voipDataReceived(const RsPeerId&)), Qt::QueuedConnection); - connect(mVOIPNotify, SIGNAL(voipHangUpReceived(const RsPeerId&)), this, SLOT(voipHangUpReceived(const RsPeerId&)), Qt::QueuedConnection); - connect(mVOIPNotify, SIGNAL(voipInvitationReceived(const RsPeerId&)), this, SLOT(voipInvitationReceived(const RsPeerId&)), Qt::QueuedConnection); + connect(mVOIPNotify, SIGNAL(voipHangUpReceived(const RsPeerId&, int)), this, SLOT(voipHangUpReceived(const RsPeerId&, int)), Qt::QueuedConnection); + connect(mVOIPNotify, SIGNAL(voipInvitationReceived(const RsPeerId&, int)), this, SLOT(voipInvitationReceived(const RsPeerId&, int)), Qt::QueuedConnection); #endif connect(mVOIPNotify, SIGNAL(voipAudioCallReceived(const RsPeerId&)), this, SLOT(voipAudioCallReceived(const RsPeerId&)), Qt::QueuedConnection); connect(mVOIPNotify, SIGNAL(voipVideoCallReceived(const RsPeerId&)), this, SLOT(voipVideoCallReceived(const RsPeerId&)), Qt::QueuedConnection); @@ -186,7 +186,7 @@ ToasterItem* VOIPToasterNotify::testToasterItem(QString tag) } #ifdef VOIPTOASTERNOTIFY_ALL -void VOIPToasterNotify::voipAcceptReceived(const RsPeerId &peer_id) +void VOIPToasterNotify::voipAcceptReceived(const RsPeerId &peer_id, int flags) { if (peer_id.isNull()) { return; @@ -258,7 +258,7 @@ void VOIPToasterNotify::voipDataReceived(const RsPeerId &peer_id) mMutex->unlock(); } -void VOIPToasterNotify::voipHangUpReceived(const RsPeerId &peer_id) +void VOIPToasterNotify::voipHangUpReceived(const RsPeerId &peer_id, int flags) { if (peer_id.isNull()) { return; @@ -282,7 +282,7 @@ void VOIPToasterNotify::voipHangUpReceived(const RsPeerId &peer_id) mMutex->unlock(); } -void VOIPToasterNotify::voipInvitationReceived(const RsPeerId &peer_id) +void VOIPToasterNotify::voipInvitationReceived(const RsPeerId &peer_id, int flags) { if (peer_id.isNull()) { return; diff --git a/plugins/VOIP/gui/VOIPToasterNotify.h b/plugins/VOIP/gui/VOIPToasterNotify.h index 7b24a28fb..035589533 100644 --- a/plugins/VOIP/gui/VOIPToasterNotify.h +++ b/plugins/VOIP/gui/VOIPToasterNotify.h @@ -60,11 +60,11 @@ public: private slots: #ifdef VOIPTOASTERNOTIFY_ALL - void voipAcceptReceived(const RsPeerId &peer_id) ; // emitted when the peer accepts the call + void voipAcceptReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer accepts the call void voipBandwidthInfoReceived(const RsPeerId &peer_id, int bytes_per_sec) ; // emitted when measured bandwidth info is received by the peer. void voipDataReceived(const RsPeerId &peer_id) ; // signal emitted when some voip data has been received - void voipHangUpReceived(const RsPeerId &peer_id) ; // emitted when the peer closes the call (i.e. hangs up) - void voipInvitationReceived(const RsPeerId &peer_id) ; // signal emitted when an invitation has been received + void voipHangUpReceived(const RsPeerId &peer_id, int flags) ; // emitted when the peer closes the call (i.e. hangs up) + void voipInvitationReceived(const RsPeerId &peer_id, int flags) ; // signal emitted when an invitation has been received #endif void voipAudioCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send audio void voipVideoCallReceived(const RsPeerId &peer_id) ; // emitted when the peer is calling and own don't send video diff --git a/plugins/VOIP/interface/rsVOIP.h b/plugins/VOIP/interface/rsVOIP.h index 2e7e56eb4..8b7fd3d7b 100644 --- a/plugins/VOIP/interface/rsVOIP.h +++ b/plugins/VOIP/interface/rsVOIP.h @@ -65,9 +65,9 @@ struct RsVOIPDataChunk class RsVOIP { public: - virtual int sendVoipHangUpCall(const RsPeerId& peer_id) = 0; - virtual int sendVoipRinging(const RsPeerId& peer_id) = 0; - virtual int sendVoipAcceptCall(const RsPeerId& peer_id) = 0; + virtual int sendVoipHangUpCall(const RsPeerId& peer_id, uint32_t flags) = 0; + virtual int sendVoipRinging(const RsPeerId& peer_id, uint32_t flags) = 0; + virtual int sendVoipAcceptCall(const RsPeerId& peer_id, uint32_t flags) = 0; // Sending data. The client keeps the memory ownership and must delete it after calling this. virtual int sendVoipData(const RsPeerId& peer_id,const RsVOIPDataChunk& chunk) = 0; diff --git a/plugins/VOIP/services/p3VOIP.cc b/plugins/VOIP/services/p3VOIP.cc index fb164bd7c..c0867299d 100644 --- a/plugins/VOIP/services/p3VOIP.cc +++ b/plugins/VOIP/services/p3VOIP.cc @@ -219,36 +219,36 @@ void p3VOIP::sendBandwidthInfo() } } -int p3VOIP::sendVoipHangUpCall(const RsPeerId &peer_id) +int p3VOIP::sendVoipHangUpCall(const RsPeerId &peer_id, uint32_t flags) { RsVOIPProtocolItem *item = new RsVOIPProtocolItem ; item->protocol = RsVOIPProtocolItem::VoipProtocol_Close; - item->flags = 0 ; + item->flags = flags ; item->PeerId(peer_id) ; sendItem(item) ; return true ; } -int p3VOIP::sendVoipAcceptCall(const RsPeerId& peer_id) +int p3VOIP::sendVoipAcceptCall(const RsPeerId& peer_id, uint32_t flags) { RsVOIPProtocolItem *item = new RsVOIPProtocolItem ; item->protocol = RsVOIPProtocolItem::VoipProtocol_Ackn ; - item->flags = 0 ; + item->flags = flags ; item->PeerId(peer_id) ; sendItem(item) ; return true ; } -int p3VOIP::sendVoipRinging(const RsPeerId &peer_id) +int p3VOIP::sendVoipRinging(const RsPeerId &peer_id, uint32_t flags) { RsVOIPProtocolItem *item = new RsVOIPProtocolItem ; item->protocol = RsVOIPProtocolItem::VoipProtocol_Ring ; - item->flags = 0 ; + item->flags = flags ; item->PeerId(peer_id) ; sendItem(item) ; @@ -362,33 +362,31 @@ void p3VOIP::handleProtocol(RsVOIPProtocolItem *item) switch(item->protocol) { - case RsVOIPProtocolItem::VoipProtocol_Ring: mNotify->notifyReceivedVoipInvite(item->PeerId()); + case RsVOIPProtocolItem::VoipProtocol_Ring: mNotify->notifyReceivedVoipInvite(item->PeerId(), (uint32_t)item->flags); #ifdef DEBUG_VOIP - std::cerr << "p3VOIP::handleProtocol(): Received protocol ring item." << std::endl; + std::cerr << "p3VOIP::handleProtocol(): Received protocol ring item." << std::endl; #endif - break ; + break ; - case RsVOIPProtocolItem::VoipProtocol_Ackn: mNotify->notifyReceivedVoipAccept(item->PeerId()); + case RsVOIPProtocolItem::VoipProtocol_Ackn: mNotify->notifyReceivedVoipAccept(item->PeerId(), (uint32_t)item->flags); #ifdef DEBUG_VOIP - std::cerr << "p3VOIP::handleProtocol(): Received protocol accept call" << std::endl; + std::cerr << "p3VOIP::handleProtocol(): Received protocol accept call" << std::endl; #endif - break ; + break ; - case RsVOIPProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId()); + case RsVOIPProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId(), (uint32_t)item->flags); #ifdef DEBUG_VOIP - std::cerr << "p3VOIP::handleProtocol(): Received protocol Close call." << std::endl; + std::cerr << "p3VOIP::handleProtocol(): Received protocol Close call." << std::endl; #endif - break ; + break ; case RsVOIPProtocolItem::VoipProtocol_Bandwidth: mNotify->notifyReceivedVoipBandwidth(item->PeerId(),(uint32_t)item->flags); #ifdef DEBUG_VOIP - std::cerr << "p3VOIP::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl; + std::cerr << "p3VOIP::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl; #endif - break ; + break ; default: -#ifdef DEBUG_VOIP - std::cerr << "p3VOIP::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl; -#endif - break ; + std::cerr << "p3VOIP::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl; + break ; } } diff --git a/plugins/VOIP/services/p3VOIP.h b/plugins/VOIP/services/p3VOIP.h index 03cbf795a..961496019 100644 --- a/plugins/VOIP/services/p3VOIP.h +++ b/plugins/VOIP/services/p3VOIP.h @@ -83,9 +83,9 @@ class p3VOIP: public RsPQIService, public RsVOIP // virtual bool getIncomingData(const RsPeerId& peer_id,std::vector& chunks) ; - virtual int sendVoipHangUpCall(const RsPeerId& peer_id) ; - virtual int sendVoipRinging(const RsPeerId& peer_id) ; - virtual int sendVoipAcceptCall(const RsPeerId &peer_id) ; + virtual int sendVoipHangUpCall(const RsPeerId& peer_id, uint32_t flags) ; + virtual int sendVoipRinging(const RsPeerId& peer_id, uint32_t flags) ; + virtual int sendVoipAcceptCall(const RsPeerId &peer_id, uint32_t flags) ; /***** overloaded from p3Service *****/ /*! diff --git a/plugins/VOIP/services/rsVOIPItems.cc b/plugins/VOIP/services/rsVOIPItems.cc index a75fa4c16..afc76b505 100644 --- a/plugins/VOIP/services/rsVOIPItems.cc +++ b/plugins/VOIP/services/rsVOIPItems.cc @@ -71,7 +71,7 @@ std::ostream& RsVOIPProtocolItem::print(std::ostream &out, uint16_t indent) out << "flags: " << flags << std::endl; printIndent(out, int_Indent); - out << "protocol: " << std::hex << protocol << std::dec << std::endl; + out << "protocol: " << std::hex << (uint32_t)protocol << std::dec << std::endl; printRsItemEnd(out, "RsVOIPProtocolItem", indent); return out; @@ -160,7 +160,7 @@ bool RsVOIPProtocolItem::serialise(void *data, uint32_t& pktsize) offset += 8; /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, protocol); + ok &= setRawUInt32(data, tlvsize, &offset, (uint32_t)protocol); ok &= setRawUInt32(data, tlvsize, &offset, flags); if (offset != tlvsize) @@ -300,7 +300,9 @@ RsVOIPProtocolItem::RsVOIPProtocolItem(void *data, uint32_t pktsize) offset += 8; /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &protocol); + uint32_t uint_Protocol; + ok &= getRawUInt32(data, rssize, &offset, &uint_Protocol); + protocol = static_cast(uint_Protocol); ok &= getRawUInt32(data, rssize, &offset, &flags); if (offset != rssize) diff --git a/plugins/VOIP/services/rsVOIPItems.h b/plugins/VOIP/services/rsVOIPItems.h index 7658ea4cc..7d083fde5 100644 --- a/plugins/VOIP/services/rsVOIPItems.h +++ b/plugins/VOIP/services/rsVOIPItems.h @@ -76,8 +76,8 @@ class RsVOIPItem: public RsItem setPriorityLevel(QOS_PRIORITY_RS_VOIP) ; } - virtual ~RsVOIPItem() {}; - virtual void clear() {}; + virtual ~RsVOIPItem() {} + virtual void clear() {} virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ; virtual bool serialise(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialise themselves ? @@ -138,14 +138,13 @@ class RsVOIPBandwidthItem: public RsVOIPItem uint32_t bytes_per_sec ; // bandwidth in bytes per sec. }; - class RsVOIPProtocolItem: public RsVOIPItem { public: RsVOIPProtocolItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {} RsVOIPProtocolItem(void *data,uint32_t size) ; - enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } ; + typedef enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } en_Protocol; virtual bool serialise(void *data,uint32_t& size) ; virtual uint32_t serial_size() const ; @@ -153,7 +152,7 @@ class RsVOIPProtocolItem: public RsVOIPItem virtual ~RsVOIPProtocolItem() {} virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); - uint32_t protocol ; + en_Protocol protocol ; uint32_t flags ; };