finsh basic functions

This commit is contained in:
zc 2024-01-18 17:04:21 -08:00
parent ab606d358a
commit 9bac1f9232
5 changed files with 49 additions and 70 deletions

View File

@ -23,15 +23,11 @@ Channel::Channel(QObject* parent)
timer->stop(); timer->stop();
videoInput = nullptr; videoInput = nullptr;
videoEncoder = nullptr;
videoOutput = nullptr; videoOutput = nullptr;
videoEncoder = nullptr;
audioEncoder = nullptr; audioEncoder = nullptr;
record = nullptr; record = nullptr;
// file = nullptr;
// videoDecoder = nullptr;
// audioDecoder = nullptr;
rtsp = nullptr; rtsp = nullptr;
snap = Link::create("EncodeV"); snap = Link::create("EncodeV");
overLay = Link::create("Overlay"); overLay = Link::create("Overlay");
@ -39,7 +35,7 @@ Channel::Channel(QObject* parent)
audioInput = Link::create("InputAlsa"); audioInput = Link::create("InputAlsa");
QVariantMap dataIn; QVariantMap dataIn;
dataIn["path"] = "hw:0,0"; dataIn["path"] = "hw:0,0";
dataIn["channels"] = 2;
audioInput->start(dataIn); audioInput->start(dataIn);
} }
if (audioOutput == nullptr) { if (audioOutput == nullptr) {
@ -54,7 +50,6 @@ Channel::Channel(QObject* parent)
} }
if (file == nullptr) { if (file == nullptr) {
file = Link::create("InputFile"); file = Link::create("InputFile");
file->start();
// one video playback end // one video playback end
connect(file, &LinkObject::newEvent, [=](QString type, QVariant) { connect(file, &LinkObject::newEvent, [=](QString type, QVariant) {
@ -99,10 +94,10 @@ void Channel::init()
videoInput->start(dataVi); videoInput->start(dataVi);
// start water mask // start water mask
overLay->start(); // overLay->start();
// link video input and output, and add water mask // link video input and output, and add water mask
videoInput->linkV(overLay)->linkV(videoOutput); videoInput->linkV(videoOutput);
// capture picture from video // capture picture from video
QVariantMap dataSnap; QVariantMap dataSnap;
@ -139,18 +134,6 @@ void Channel::init()
rtsp->start(dataRtsp); rtsp->start(dataRtsp);
videoInput->linkV(videoEncoder)->linkV(rtsp)->linkV(rtspServer); videoInput->linkV(videoEncoder)->linkV(rtsp)->linkV(rtspServer);
audioInput->linkA(audioEncoder)->linkA(rtsp)->linkA(rtspServer); audioInput->linkA(audioEncoder)->linkA(rtsp)->linkA(rtspServer);
// init file and decoder
// file = Link::create("InputFile");
// file->start();
// videoDecoder = Link::create("DecodeV");
// videoDecoder->start();
// audioDecoder = Link::create("DecodeA");
// audioDecoder->start();
// file->linkV(videoDecoder)->linkV(videoOutput);
// file->linkA(audioDecoder)->linkA(audioOutput);
} }
/** /**
@ -188,7 +171,7 @@ void Channel::startRecord()
dataRecord["path"] = QString("%1/%2/%3.mp4").arg(VideoPath).arg(channelName).arg(curTime); dataRecord["path"] = QString("%1/%2/%3.mp4").arg(VideoPath).arg(channelName).arg(curTime);
record->setData(dataRecord); record->setData(dataRecord);
record->start(); record->start();
setOverlay("Record"); // setOverlay("Record");
timer->start(); timer->start();
snap->invoke("snapSync", QString("%1/%2/%3.jpg").arg(SnapPath).arg(channelName).arg(curTime)); snap->invoke("snapSync", QString("%1/%2/%3.jpg").arg(SnapPath).arg(channelName).arg(curTime));
@ -200,7 +183,7 @@ void Channel::startRecord()
void Channel::stopRecord() void Channel::stopRecord()
{ {
record->stop(true); record->stop(true);
setOverlay("No Record"); // setOverlay("No Record");
timer->stop(); timer->stop();
} }
@ -210,22 +193,32 @@ void Channel::stopRecord()
*/ */
void Channel::startPlayback(QString fileName) void Channel::startPlayback(QString fileName)
{ {
qDebug() << channelName << "start play back, file name:" << fileName;
QString path = QString("%1/%2/%3").arg(VideoPath).arg(channelName).arg(fileName); QString path = QString("%1/%2/%3").arg(VideoPath).arg(channelName).arg(fileName);
// break video input and output // break video input and output
videoInput->unLinkV(videoOutput); videoInput->unLinkV(videoOutput);
file->linkV(videoDecoder)->linkV(videoOutput); videoDecoder->linkV(videoOutput);
QVariantMap dataFile; QVariantMap dataFile;
dataFile["path"] = path; dataFile["path"] = path;
file->setData(dataFile); file->start(dataFile);
// file->start();
isPlayback = true; isPlayback = true;
} }
/**
* @brief play live
*/
void Channel::startPlayLive()
{
videoDecoder->unLinkV(videoOutput);
file->stop(true);
videoInput->linkV(videoOutput);
isPlayback = false;
}
/** /**
* @brief playback -10s * @brief playback -10s
*/ */
@ -257,20 +250,6 @@ void Channel::togglePause()
file->invoke("pause", isPause); file->invoke("pause", isPause);
} }
/**
* @brief play live
*/
void Channel::startPlayLive()
{
// stop playback
videoDecoder->unLinkV(videoOutput);
file->stop(true);
isPlayback = false;
videoInput->linkV(videoOutput);
}
/** /**
* @brief open console process, and use it by command * @brief open console process, and use it by command
* @param com * @param com

View File

@ -8,16 +8,11 @@ Menu::Menu(QWidget* parent)
ui->setupUi(this); ui->setupUi(this);
ui->btnChannelA->setChecked(true); ui->btnChannelA->setChecked(true);
// set window background transparent // move to center
// QPalette pal = palette(); QPoint globalPos = parent->mapToGlobal(QPoint(0, 0));
// pal.setBrush(QPalette::Base, Qt::transparent); int x = globalPos.x() + (parent->width() - this->width()) / 2;
// setPalette(pal); int y = globalPos.y() + (parent->height() - this->height()) / 2;
// setAttribute(Qt::WA_TranslucentBackground, true); this->move(x, y);
QPoint globalPos = parent->mapToGlobal(QPoint(0, 0)); //父窗口绝对坐标
int x = globalPos.x() + (parent->width() - this->width()) / 2; //x坐标
int y = globalPos.y() + (parent->height() - this->height()) / 2; //y坐标
this->move(x, y); //窗口移动
} }
Menu::~Menu() Menu::~Menu()

11
Menu.ui
View File

@ -14,19 +14,18 @@
<string>Form</string> <string>Form</string>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QWidget#Menu{ <string notr="true">/*QWidget#Menu{
background: rgba(0, 0, 0, 0.5);
} }*/
QPushButton { QPushButton {
border: none; border: none;
background: rbga(0, 0, 0, 0.5); background: rgba(0, 0, 0, 0.7);
color: #ffffff; color: #ffffff;
} }
QPushButton::checked{ QPushButton::checked{
color: #0082E5; background: rgba(0, 0, 255, 0.7);
background: rgba(0, 130, 229, 0.5);
}</string> }</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">

View File

@ -213,9 +213,9 @@ void Widget::onReadyRead()
curChannelName = menu->getCurChannel(); curChannelName = menu->getCurChannel();
menu->hide(); menu->hide();
showPlayList(); showPlayList();
} } else {
// if menu hide, then current channel playback and other channel play live // if list widget show, then current channel playback and other channel play live
else { if (ui->listWidget->isVisible()) {
QString fileName = ui->listWidget->currentItem()->text(); QString fileName = ui->listWidget->currentItem()->text();
Channel* channel = nullptr; Channel* channel = nullptr;
for (int i = 0; i < channelList.count(); i++) { for (int i = 0; i < channelList.count(); i++) {
@ -226,10 +226,13 @@ void Widget::onReadyRead()
channelList.at(i)->startPlayLive(); channelList.at(i)->startPlayLive();
} }
} }
if (channel) if (channel) {
channel->startPlayback(fileName); channel->startPlayback(fileName);
isPlayback = true;
}
ui->listWidget->hide(); ui->listWidget->hide();
} }
}
break; break;
case Return: case Return:
if (menu->isVisible()) { if (menu->isVisible()) {

View File

@ -18,6 +18,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Widget</string> <string>Widget</string>
</property> </property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>