You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
318 lines
11 KiB
318 lines
11 KiB
#include "OnvifVideoSourceFinderDialog.h"
|
|
#include "addSourceDialog.h"
|
|
#include "../../data/onvif/include/onvifclient.hpp"
|
|
|
|
OnvifSourceFinderDialog::OnvifSourceFinderDialog(guiAddSourceDialog *parent) : QDialog(parent){
|
|
m_pOnvifObserver = onvifMediaObserver::getInstance();
|
|
m_pParentDialog = parent;
|
|
// m_pStreamSource = NULL;
|
|
m_pHL = new QHBoxLayout();
|
|
m_pHL->setSpacing(6);
|
|
//m_pHL->setContentsMargins(11, 11, 11, 11);
|
|
|
|
m_pVL1 = new QVBoxLayout();
|
|
m_pVL1->setSpacing(6);
|
|
m_pVL2 = new QVBoxLayout();
|
|
m_pVL2->setSpacing(6);
|
|
m_pTreeWidget = new QTreeWidget();
|
|
m_pTreeWidget->headerItem()->setText(0, QString("Networks"));
|
|
connect(m_pTreeWidget, &QTreeWidget::itemClicked, this, &OnvifSourceFinderDialog::treeItemClicked);
|
|
connect(m_pTreeWidget, &QTreeWidget::itemDoubleClicked, this, &OnvifSourceFinderDialog::treeItemClicked);
|
|
//QTreeWidget::itemDoubleClicked
|
|
//QTreeWidget::itemClicked
|
|
//OnvifSourceFinder::treeItemClicked
|
|
m_pHL->addWidget(m_pTreeWidget);
|
|
|
|
m_pTxtLogin = new QLineEdit();
|
|
m_pTxtLogin->setClearButtonEnabled(true);
|
|
m_pTxtLogin->setText("gagua");
|
|
m_pTxtLogin->setPlaceholderText(QApplication::translate("OnvifSourceFinder", "login name", 0));
|
|
|
|
m_pTxtPassword = new QLineEdit();
|
|
m_pTxtPassword->setClearButtonEnabled(true);
|
|
m_pTxtPassword->setText("4GetMyID");
|
|
m_pTxtPassword->setPlaceholderText(QApplication::translate("OnvifSourceFinder", "password", 0));
|
|
|
|
m_pButtonCmdConnect = new QPushButton();
|
|
m_pButtonCmdConnect->setFixedSize(240, 40);
|
|
m_pButtonCmdConnect->setText("Connect");
|
|
QIcon icon1;
|
|
icon1.addFile(QStringLiteral(":pictures/appbar.disconnect.png"), QSize(), QIcon::Normal, QIcon::Off);
|
|
m_pButtonCmdConnect->setIcon(icon1);
|
|
m_pButtonCmdConnect->setIconSize(QSize(32, 32));
|
|
m_pButtonCmdConnect->setEnabled(false);
|
|
//m_pButtonCmdConnect->setFlat(false);
|
|
connect(m_pButtonCmdConnect, &QPushButton::clicked, this, &OnvifSourceFinderDialog::connectToSelectedSource);
|
|
|
|
m_pButtonCmdSearch = new QPushButton();
|
|
m_pButtonCmdSearch->setFixedSize(240,40);
|
|
m_pButtonCmdSearch->setText("Search Networks");
|
|
QIcon icon2;
|
|
icon2.addFile(QStringLiteral(":pictures/appbar.alien.png"), QSize(), QIcon::Normal, QIcon::Off);
|
|
m_pButtonCmdSearch->setIcon(icon2);
|
|
m_pButtonCmdSearch->setIconSize(QSize(32, 32));
|
|
//m_pButtonCmdSearch->setFlat(false);
|
|
connect(m_pButtonCmdSearch, &QPushButton::clicked, this, &OnvifSourceFinderDialog::startDevicesDiscovery);
|
|
|
|
//m_pStreamPreview = new VideoThumbWidget();
|
|
//m_pStreamPreview->setError(true, "No Stream");
|
|
//m_pStreamPreview->init();
|
|
|
|
m_pProgressBar = new QProgressBar();
|
|
|
|
m_pVL2->addWidget(m_pButtonCmdSearch, 0, Qt::AlignLeft | Qt::AlignTop);
|
|
m_pVL2->addWidget(m_pTxtLogin, 0, Qt::AlignLeft | Qt::AlignTop);
|
|
m_pVL2->addWidget(m_pTxtPassword, 0, Qt::AlignLeft | Qt::AlignTop);
|
|
m_pVL2->addWidget(m_pButtonCmdConnect, 0, Qt::AlignLeft | Qt::AlignTop);
|
|
// m_pVL2->addWidget(m_pStreamPreview, 0, Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
m_pHL->addItem(m_pVL2);
|
|
|
|
m_pVL1->addItem(m_pHL);
|
|
m_pProfileslist = new QListWidget(this);
|
|
m_pVL1->addWidget(m_pProfileslist);
|
|
connect(m_pProfileslist, &QListWidget::itemClicked, this, &OnvifSourceFinderDialog::listItemClicked);
|
|
connect(m_pProfileslist, &QListWidget::itemDoubleClicked, this, &OnvifSourceFinderDialog::listItemDblClicked);
|
|
|
|
m_pButtonCmdUseProfile = new QPushButton();
|
|
//m_pButtonCmdUseProfile->setFixedSize(240, 40);
|
|
m_pButtonCmdUseProfile->setText("Use This Profile");
|
|
m_pButtonCmdUseProfile->setIcon(QIcon(":pictures/appbar.alien.png"));
|
|
m_pButtonCmdUseProfile->setEnabled(false);
|
|
connect(m_pButtonCmdUseProfile, &QPushButton::clicked, this, &OnvifSourceFinderDialog::useSelectedProfile);
|
|
m_pVL1->addWidget(m_pButtonCmdUseProfile);
|
|
|
|
m_pVSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
m_pVL1->addItem(m_pVSpacer);
|
|
m_pVL1->addWidget(m_pProgressBar);
|
|
setLayout(m_pVL1);
|
|
setFixedSize(600, 480);
|
|
setWindowTitle("OnVIF Network Observer");
|
|
m_pTimer = NULL;
|
|
};
|
|
|
|
OnvifSourceFinderDialog::~OnvifSourceFinderDialog(){
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::connectToSelectedSource(){
|
|
startAskDevice();
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::startDevicesDiscovery(){
|
|
int nifCount;
|
|
localIpAddresses *mNetworks;
|
|
nifCount = m_pOnvifObserver->getNetworkCounts();
|
|
if( nifCount ){
|
|
m_pButtonCmdSearch->setEnabled(false);
|
|
m_pTreeWidget->clear();
|
|
m_pProgressBar->setValue(0);
|
|
if (m_pTimer == NULL){
|
|
m_pTimer = new QTimer();
|
|
if (m_pTimer != NULL){
|
|
connect(m_pTimer, &QTimer::timeout, this, &OnvifSourceFinderDialog::updateProgress);
|
|
m_pTimer->start(40);
|
|
};
|
|
}
|
|
else m_pTimer->start(40);
|
|
|
|
mNetworks = m_pOnvifObserver->getNetworks();
|
|
for (localIpAddresses::iterator index = mNetworks->begin(); index < mNetworks->end(); index++){
|
|
QTreeWidgetItem *tNode = new QTreeWidgetItem();
|
|
tNode->setText(0, QString((*index)->broadcast));
|
|
m_pTreeWidget->addTopLevelItem(tNode);
|
|
};
|
|
QTreeWidgetItem *tNode = new QTreeWidgetItem();
|
|
tNode->setText(0, QString("239.255.255.250"));
|
|
m_pTreeWidget->addTopLevelItem(tNode);
|
|
m_pProgressBar->setEnabled(true);
|
|
m_pOnvifObserver->startDiscovery();
|
|
} else {
|
|
QMessageBox *mBox = new QMessageBox(
|
|
QMessageBox::Icon::Information,
|
|
QString("Error"),
|
|
QString("No Network Interfaces defined in the system"),
|
|
QMessageBox::StandardButton::Ok
|
|
);
|
|
mBox->show();
|
|
};
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::startAskDevice(void){
|
|
m_pProgressBar->setValue(0);
|
|
//m_pDeviceNode = new onvifDeviceNode(m_pDevURL);
|
|
std::string A, B, C;
|
|
A = std::string(m_pDevURL);
|
|
B = m_pTxtLogin->text().toStdString(); //std::string("gagua");
|
|
C = m_pTxtPassword->text().toStdString(); //std::string("4GetMyID");
|
|
m_pDeviceNode = new OnvifClientDevice( A, B, C );
|
|
if (m_pDeviceNode != NULL){
|
|
m_pProfileslist->clear();
|
|
m_pDeviceNode->GetCapabilities();
|
|
OnvifClientMedia media( *m_pDeviceNode );
|
|
_trt__GetProfilesResponse profiles;
|
|
media.GetProfiles(profiles);
|
|
std::vector<tt__Profile * >::iterator index;
|
|
_trt__GetSnapshotUriResponse SnapshotUriResponse;
|
|
_trt__GetStreamUriResponse StreamUriResponse;
|
|
tt__StreamSetup StreamSetup;
|
|
for (index = profiles.Profiles.begin(); index < profiles.Profiles.end(); index++){
|
|
QListWidgetItem *tNode;
|
|
char koko[256];
|
|
sprintf(koko, "%s [%s]",
|
|
(*index)->Name.c_str(),
|
|
(*index)->token.c_str()
|
|
);
|
|
tNode = new QListWidgetItem( m_pProfileslist );
|
|
tNode->setText(QString(koko));
|
|
media.GetSnapshotUri(SnapshotUriResponse, (*index)->token);
|
|
media.GetStreamUri(StreamUriResponse, StreamSetup, (*index)->token);
|
|
tNode->setData( Qt::DisplayRole, QVariant(QString(koko)));
|
|
if( StreamUriResponse.MediaUri != NULL ) tNode->setData( Qt::StatusTipRole, QVariant(QString(StreamUriResponse.MediaUri->Uri.c_str())));
|
|
if( SnapshotUriResponse.MediaUri != NULL ) tNode->setData( Qt::ToolTipRole, QVariant(QString(SnapshotUriResponse.MediaUri->Uri.c_str())));
|
|
tNode->setIcon(QIcon(":pictures/appbar.film.live.png"));
|
|
};
|
|
/*
|
|
vectorProfileOnvif *tVector;
|
|
tVector = m_pDeviceNode->getProfilesVector();
|
|
if (tVector != NULL){
|
|
for (int index = 0; index < tVector->size(); index++){
|
|
char koko[256];
|
|
sprintf( koko, "%s [%dx%d] %d FPS %s@%d KBps",
|
|
tVector->at(index)->pName,
|
|
tVector->at(index)->nWidth,
|
|
tVector->at(index)->nHeight,
|
|
tVector->at(index)->nFramerate,
|
|
tVector->at(index)->pNcode,
|
|
tVector->at(index)->nBitrate
|
|
);
|
|
QListWidgetItem *tNode;
|
|
tNode = new QListWidgetItem(m_pProfileslist);
|
|
tNode->setText(QString(koko));
|
|
tNode->setIcon(QIcon(":pictures/appbar.film.live.png"));
|
|
//m_pProfileslist->addItem(tNode);
|
|
};
|
|
};
|
|
*/
|
|
};
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::startPrevewNetStream(void){
|
|
char koko[256];
|
|
//koko = m_pDeviceNode->getStreamURI(m_nSelectedProfile);
|
|
std::string A;
|
|
m_pDeviceNode->GetMediaUrl(A);
|
|
sprintf(koko,"s%", A.c_str());
|
|
if (koko != NULL){
|
|
/* if (m_pStreamSource != NULL)delete(m_pStreamSource);
|
|
m_pStreamSource = new videoAVLIBSource();
|
|
if (m_pStreamSource->_open(koko)){
|
|
m_pStreamSource->attachDestination(m_pStreamPreview);
|
|
m_pStreamSource->setStreaming(true);
|
|
m_pStreamPreview->setError(false);
|
|
}else{
|
|
m_pStreamPreview->setError(true, "Error Opening Stream");
|
|
};
|
|
*/
|
|
};
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::updateProgress(){
|
|
int cStat;
|
|
cStat = m_pOnvifObserver->getStatus();
|
|
m_pProgressBar->setValue(cStat);
|
|
if (cStat > 57){
|
|
m_pTimer->stop();
|
|
m_pProgressBar->setValue(100);
|
|
m_pButtonCmdSearch->setEnabled(true);
|
|
vectorWoWoResults *nResults;
|
|
nResults = m_pOnvifObserver->getResults();
|
|
if (nResults->size()){
|
|
resultWoWo *tRecord;
|
|
for (vectorWoWoResults::iterator index = nResults->begin(); index < nResults->end(); index++){
|
|
tRecord = (*index);
|
|
QTreeWidgetItem *tNode = new QTreeWidgetItem();
|
|
tNode->setText(0, QString(tRecord->Type));
|
|
QTreeWidgetItem *bNode = new QTreeWidgetItem();
|
|
bNode->setText(0, QString(tRecord->XAddrs));
|
|
QTreeWidgetItem *rNode = m_pTreeWidget->topLevelItem(tRecord->wowoID);
|
|
tNode->addChild(bNode);
|
|
rNode->addChild(tNode);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::treeItemClicked(QTreeWidgetItem *item, int column){
|
|
if ( NULL != item->parent() && 0 == item->childCount()){
|
|
char fullBuffer[1024];
|
|
sprintf(fullBuffer, "%s", item->text(column).toStdString().c_str());
|
|
CArray *TArr;
|
|
TArr = explode(' ', fullBuffer);
|
|
sprintf(m_pDevURL, "%s", TArr->at(0));
|
|
m_pButtonCmdConnect->setEnabled(true);
|
|
} else {
|
|
m_pButtonCmdConnect->setEnabled(false);
|
|
};
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::listItemClicked(QListWidgetItem *item){
|
|
std::string S,L,P,K;
|
|
S = item->data(Qt::StatusTipRole).toString().toStdString();
|
|
K = item->data(Qt::ToolTipRole).toString().toStdString();
|
|
L = m_pTxtLogin->text().toStdString();
|
|
P = m_pTxtPassword->text().toStdString();
|
|
int aPos = S.find_first_of("://");
|
|
if (aPos > 0) {
|
|
S.insert(aPos + 3, L);
|
|
S.insert(aPos + 3 + L.length(), ":");
|
|
S.insert(aPos + 4 + L.length(), P);
|
|
S.insert(aPos + 4 + L.length() + P.length(), "@");
|
|
}
|
|
aPos = K.find_first_of("://");
|
|
if (aPos > 0) {
|
|
K.insert(aPos + 3, L);
|
|
K.insert(aPos + 3 + L.length(), ":");
|
|
K.insert(aPos + 4 + L.length(), P);
|
|
K.insert(aPos + 4 + L.length() + P.length(), "@");
|
|
};
|
|
sprintf( m_pSelectedVideoMRL,"%s", S.c_str());
|
|
sprintf( m_pSelectedPictureMRL,"%s", K.c_str());
|
|
m_pButtonCmdUseProfile->setEnabled(true);
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::listItemDblClicked(QListWidgetItem *item){
|
|
std::string S, L, P, K;
|
|
S = item->data(Qt::StatusTipRole).toString().toStdString();
|
|
K = item->data(Qt::ToolTipRole).toString().toStdString();
|
|
L = m_pTxtLogin->text().toStdString();
|
|
P = m_pTxtPassword->text().toStdString();
|
|
int aPos = S.find_first_of("://");
|
|
if (aPos > 0) {
|
|
S.insert(aPos + 3, L);
|
|
S.insert(aPos + 3 + L.length(), ":");
|
|
S.insert(aPos + 4 + L.length(), P);
|
|
S.insert(aPos + 4 + L.length() + P.length(), "@");
|
|
}
|
|
aPos = K.find_first_of("://");
|
|
if (aPos > 0) {
|
|
K.insert(aPos + 3, L);
|
|
K.insert(aPos + 3 + L.length(), ":");
|
|
K.insert(aPos + 4 + L.length(), P);
|
|
K.insert(aPos + 4 + L.length() + P.length(), "@");
|
|
};
|
|
sprintf(m_pSelectedVideoMRL, "%s", S.c_str());
|
|
sprintf(m_pSelectedPictureMRL, "%s", K.c_str());
|
|
m_pButtonCmdUseProfile->setEnabled(true);
|
|
};
|
|
|
|
void OnvifSourceFinderDialog::useSelectedProfile(void){
|
|
m_pParentDialog->setNetworkSourcePath(
|
|
m_pSelectedVideoMRL,
|
|
m_pSelectedPictureMRL,
|
|
"",
|
|
m_pDevURL,
|
|
(CSTR) m_pTxtLogin->text().toStdString().c_str(),
|
|
(CSTR) m_pTxtPassword->text().toStdString().c_str()
|
|
);
|
|
hide();
|
|
};
|