2018-11-04 10:19:17 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* plugins/VOIP/VOIPPlugin.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright 2011 by Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2012-02-18 10:56:37 -05:00
|
|
|
#include <retroshare/rsplugin.h>
|
2015-01-14 18:26:51 -05:00
|
|
|
#include <retroshare/rsversion.h>
|
2015-10-12 12:25:03 -04:00
|
|
|
#include <retroshare/rsinit.h>
|
2012-02-21 16:53:25 -05:00
|
|
|
#include <retroshare-gui/RsAutoUpdatePage.h>
|
2012-02-18 10:56:37 -05:00
|
|
|
#include <QTranslator>
|
|
|
|
#include <QApplication>
|
2012-02-21 16:53:25 -05:00
|
|
|
#include <QString>
|
2012-08-15 09:54:00 -04:00
|
|
|
#include <QIcon>
|
2013-10-19 20:56:34 -04:00
|
|
|
#include <QMessageBox>
|
2012-02-18 10:56:37 -05:00
|
|
|
|
|
|
|
#include "VOIPPlugin.h"
|
2015-05-11 15:40:07 -04:00
|
|
|
#include "interface/rsVOIP.h"
|
2012-02-21 16:53:25 -05:00
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
#include "gui/AudioInputConfig.h"
|
2014-07-13 09:57:25 -04:00
|
|
|
#include "gui/VOIPChatWidgetHolder.h"
|
2015-05-11 15:40:07 -04:00
|
|
|
#include "gui/VOIPGUIHandler.h"
|
|
|
|
#include "gui/VOIPNotify.h"
|
2012-10-21 17:38:55 -04:00
|
|
|
#include "gui/SoundManager.h"
|
2014-01-01 19:56:46 -05:00
|
|
|
#include "gui/chat/ChatWidget.h"
|
2012-02-18 10:56:37 -05:00
|
|
|
|
2015-06-14 13:45:26 -04:00
|
|
|
#include <opencv/cv.h>
|
|
|
|
#include <speex/speex.h>
|
|
|
|
|
2012-08-15 09:54:00 -04:00
|
|
|
#define IMAGE_VOIP ":/images/talking_on.svg"
|
|
|
|
|
2012-02-18 15:30:10 -05:00
|
|
|
static void *inited = new VOIPPlugin() ;
|
2012-02-18 10:56:37 -05:00
|
|
|
|
|
|
|
extern "C" {
|
2012-02-25 13:15:36 -05:00
|
|
|
|
2012-09-04 17:57:10 -04:00
|
|
|
// This is *the* functions required by RS plugin system to give RS access to the plugin.
|
2012-02-25 13:15:36 -05:00
|
|
|
// Be careful to:
|
|
|
|
// - always respect the C linkage convention
|
|
|
|
// - always return an object of type RsPlugin*
|
|
|
|
//
|
2015-06-16 10:20:59 -04:00
|
|
|
RsPlugin *RETROSHARE_PLUGIN_provide()
|
2012-02-18 10:56:37 -05:00
|
|
|
{
|
2015-06-16 10:20:59 -04:00
|
|
|
return new VOIPPlugin() ;
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
2012-09-04 17:57:10 -04:00
|
|
|
|
|
|
|
// This symbol contains the svn revision number grabbed from the executable.
|
|
|
|
// It will be tested by RS to load the plugin automatically, since it is safe to load plugins
|
|
|
|
// with same revision numbers, assuming that the revision numbers are up-to-date.
|
|
|
|
//
|
2018-09-11 18:33:29 -04:00
|
|
|
uint32_t RETROSHARE_PLUGIN_revision = 0;
|
2012-09-09 09:59:21 -04:00
|
|
|
|
|
|
|
// This symbol contains the svn revision number grabbed from the executable.
|
|
|
|
// It will be tested by RS to load the plugin automatically, since it is safe to load plugins
|
|
|
|
// with same revision numbers, assuming that the revision numbers are up-to-date.
|
|
|
|
//
|
|
|
|
uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ;
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
2015-01-14 18:26:51 -05:00
|
|
|
void VOIPPlugin::getPluginVersion(int& major, int& minor, int& build, int& svn_rev) const
|
2012-02-18 10:56:37 -05:00
|
|
|
{
|
2015-01-14 18:26:51 -05:00
|
|
|
major = RS_MAJOR_VERSION ;
|
|
|
|
minor = RS_MINOR_VERSION ;
|
2018-09-11 18:33:29 -04:00
|
|
|
build = RS_MINI_VERSION ;
|
|
|
|
svn_rev = 0;
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VOIPPlugin::VOIPPlugin()
|
|
|
|
{
|
2015-05-26 11:19:57 -04:00
|
|
|
qRegisterMetaType<RsPeerId>("RsPeerId");
|
2015-05-11 15:40:07 -04:00
|
|
|
mVOIP = NULL ;
|
2012-02-18 10:56:37 -05:00
|
|
|
mPlugInHandler = NULL;
|
|
|
|
mPeers = NULL;
|
2012-02-18 15:30:10 -05:00
|
|
|
config_page = NULL ;
|
2012-08-15 09:54:00 -04:00
|
|
|
mIcon = NULL ;
|
2015-05-26 11:19:57 -04:00
|
|
|
mVOIPToasterNotify = NULL ;
|
2012-02-25 13:15:36 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
mVOIPGUIHandler = new VOIPGUIHandler ;
|
|
|
|
mVOIPNotify = new VOIPNotify ;
|
2012-02-25 13:15:36 -05:00
|
|
|
|
2015-10-10 09:21:59 -04:00
|
|
|
QObject::connect(mVOIPNotify,SIGNAL(voipInvitationReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedInvitation(const RsPeerId&,int)),Qt::QueuedConnection) ;
|
2015-05-26 11:19:57 -04:00
|
|
|
QObject::connect(mVOIPNotify,SIGNAL(voipDataReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipData(const RsPeerId&)),Qt::QueuedConnection) ;
|
2015-10-10 09:21:59 -04:00
|
|
|
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) ;
|
2015-05-26 11:19:57 -04:00
|
|
|
QObject::connect(mVOIPNotify,SIGNAL(voipBandwidthInfoReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const RsPeerId&,int)),Qt::QueuedConnection) ;
|
2015-06-28 06:11:47 -04:00
|
|
|
|
|
|
|
Q_INIT_RESOURCE(VOIP_images);
|
|
|
|
Q_INIT_RESOURCE(VOIP_qss);
|
2015-09-03 19:00:55 -04:00
|
|
|
|
|
|
|
avcodec_register_all();
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
|
|
|
|
{
|
|
|
|
mPeers = interfaces.mPeers;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigPage *VOIPPlugin::qt_config_page() const
|
|
|
|
{
|
2014-07-13 09:57:25 -04:00
|
|
|
// The config pages are deleted when config is closed, so it's important not to static the
|
|
|
|
// created object.
|
|
|
|
//
|
2012-02-19 10:07:47 -05:00
|
|
|
return new AudioInputConfig() ;
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
2012-09-04 17:57:10 -04:00
|
|
|
QDialog *VOIPPlugin::qt_about_page() const
|
|
|
|
{
|
|
|
|
static QMessageBox *about_dialog = NULL ;
|
|
|
|
|
|
|
|
if(about_dialog == NULL)
|
|
|
|
{
|
|
|
|
about_dialog = new QMessageBox() ;
|
|
|
|
|
|
|
|
QString text ;
|
|
|
|
text += QObject::tr("<h3>RetroShare VOIP plugin</h3><br/> * Contributors: Cyril Soler, Josselin Jacquard<br/>") ;
|
2017-03-07 05:56:25 -05:00
|
|
|
text += QObject::tr("<br/>The VOIP plugin adds VOIP to the private chat window of RetroShare. To use it, proceed as follows:<UL>") ;
|
2012-09-04 17:57:10 -04:00
|
|
|
text += QObject::tr("<li> setup microphone levels using the configuration panel</li>") ;
|
2017-03-07 05:56:25 -05:00
|
|
|
text += QObject::tr("<li> check your microphone by looking at the VU-meters</li>") ;
|
2012-09-04 17:57:10 -04:00
|
|
|
text += QObject::tr("<li> in the private chat, enable sound input/output by clicking on the two VOIP icons</li></ul>") ;
|
|
|
|
text += QObject::tr("Your friend needs to run the plugin to talk/listen to you, or course.") ;
|
|
|
|
text += QObject::tr("<br/><br/>This is an experimental feature. Don't hesitate to send comments and suggestion to the RS dev team.") ;
|
|
|
|
|
|
|
|
about_dialog->setText(text) ;
|
|
|
|
about_dialog->setStandardButtons(QMessageBox::Ok) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return about_dialog ;
|
|
|
|
}
|
|
|
|
|
2014-01-01 19:56:46 -05:00
|
|
|
ChatWidgetHolder *VOIPPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget) const
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
2014-01-01 19:56:46 -05:00
|
|
|
switch (chatWidget->chatType()) {
|
|
|
|
case ChatWidget::CHATTYPE_PRIVATE:
|
2015-05-26 11:19:57 -04:00
|
|
|
return new VOIPChatWidgetHolder(chatWidget, mVOIPNotify);
|
2014-01-01 19:56:46 -05:00
|
|
|
case ChatWidget::CHATTYPE_UNKNOWN:
|
|
|
|
case ChatWidget::CHATTYPE_LOBBY:
|
|
|
|
case ChatWidget::CHATTYPE_DISTANT:
|
|
|
|
break;
|
|
|
|
}
|
2012-02-25 16:03:06 -05:00
|
|
|
|
2014-01-01 19:56:46 -05:00
|
|
|
return NULL;
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
|
2014-08-26 18:16:32 -04:00
|
|
|
p3Service *VOIPPlugin::p3_service() const
|
2012-02-18 10:56:37 -05:00
|
|
|
{
|
2016-10-22 17:48:19 -04:00
|
|
|
if(mVOIP == NULL)
|
|
|
|
rsVOIP = mVOIP = new p3VOIP(mPlugInHandler,mVOIPNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months
|
2012-02-18 10:56:37 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
return mVOIP ;
|
2012-02-18 10:56:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void VOIPPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
|
|
|
|
{
|
|
|
|
mPlugInHandler = pgHandler;
|
|
|
|
}
|
|
|
|
|
2012-08-15 09:54:00 -04:00
|
|
|
QIcon *VOIPPlugin::qt_icon() const
|
|
|
|
{
|
|
|
|
if (mIcon == NULL) {
|
|
|
|
mIcon = new QIcon(IMAGE_VOIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIcon;
|
|
|
|
}
|
|
|
|
|
2012-02-18 10:56:37 -05:00
|
|
|
std::string VOIPPlugin::getShortPluginDescription() const
|
|
|
|
{
|
|
|
|
return QApplication::translate("VOIP", "This plugin provides voice communication between friends in RetroShare.").toUtf8().constData();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VOIPPlugin::getPluginName() const
|
|
|
|
{
|
|
|
|
return QApplication::translate("VOIPPlugin", "VOIP").toUtf8().constData();
|
|
|
|
}
|
|
|
|
|
2015-06-14 13:45:26 -04:00
|
|
|
void VOIPPlugin::getLibraries(std::list<RsLibraryInfo> &libraries)
|
|
|
|
{
|
|
|
|
libraries.push_back(RsLibraryInfo("OpenCV", CV_VERSION));
|
|
|
|
|
|
|
|
const char *speexVersion = NULL;
|
|
|
|
if (speex_lib_ctl(SPEEX_LIB_GET_VERSION_STRING, &speexVersion) == 0 && speexVersion) {
|
|
|
|
libraries.push_back(RsLibraryInfo("Speex", speexVersion));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 14:44:02 -04:00
|
|
|
QTranslator* VOIPPlugin::qt_translator(QApplication */*app*/, const QString& languageCode, const QString& externalDir) const
|
2012-02-18 10:56:37 -05:00
|
|
|
{
|
|
|
|
if (languageCode == "en") {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-15 17:37:35 -04:00
|
|
|
QTranslator* translator = new QTranslator();
|
2012-10-11 19:46:54 -04:00
|
|
|
|
2012-10-12 14:44:02 -04:00
|
|
|
if (translator->load(externalDir + "/VOIP_" + languageCode + ".qm")) {
|
2012-10-11 19:46:54 -04:00
|
|
|
return translator;
|
|
|
|
} else if (translator->load(":/lang/VOIP_" + languageCode + ".qm")) {
|
2012-02-18 10:56:37 -05:00
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(translator);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-12 12:25:03 -04:00
|
|
|
void VOIPPlugin::qt_sound_events(SoundEvents &events) const
|
2012-10-21 17:38:55 -04:00
|
|
|
{
|
2018-07-24 17:47:32 -04:00
|
|
|
QDir baseDir = QDir(QString::fromUtf8(RsAccounts::systemDataDirectory().c_str()) + "/sounds");
|
2015-10-12 12:25:03 -04:00
|
|
|
|
|
|
|
events.addEvent(QApplication::translate("VOIP", "VOIP")
|
|
|
|
, QApplication::translate("VOIP", "Incoming audio call")
|
|
|
|
, VOIP_SOUND_INCOMING_AUDIO_CALL
|
|
|
|
, QFileInfo(baseDir, "incomingcall.wav").absoluteFilePath());
|
|
|
|
events.addEvent(QApplication::translate("VOIP", "VOIP")
|
|
|
|
, QApplication::translate("VOIP", "Incoming video call")
|
|
|
|
, VOIP_SOUND_INCOMING_VIDEO_CALL
|
|
|
|
, QFileInfo(baseDir, "incomingcall.wav").absoluteFilePath());
|
|
|
|
events.addEvent(QApplication::translate("VOIP", "VOIP")
|
|
|
|
, QApplication::translate("VOIP", "Outgoing audio call")
|
|
|
|
, VOIP_SOUND_OUTGOING_AUDIO_CALL
|
|
|
|
, QFileInfo(baseDir, "outgoingcall.wav").absoluteFilePath());
|
|
|
|
events.addEvent(QApplication::translate("VOIP", "VOIP")
|
|
|
|
, QApplication::translate("VOIP", "Outgoing video call")
|
|
|
|
, VOIP_SOUND_OUTGOING_VIDEO_CALL
|
|
|
|
, QFileInfo(baseDir, "outgoingcall.wav").absoluteFilePath());
|
2012-10-21 17:38:55 -04:00
|
|
|
}
|
2015-05-26 11:19:57 -04:00
|
|
|
|
|
|
|
ToasterNotify *VOIPPlugin::qt_toasterNotify(){
|
|
|
|
if (!mVOIPToasterNotify) {
|
|
|
|
mVOIPToasterNotify = new VOIPToasterNotify(mVOIP, mVOIPNotify);
|
|
|
|
}
|
|
|
|
return mVOIPToasterNotify;
|
|
|
|
}
|