Skip to content

Commit

Permalink
Merge pull request #2059 from zenustech/uioff-zeno
Browse files Browse the repository at this point in the history
[cmd] return error info. stop recording when record or path is set to…
  • Loading branch information
zhxx1987 authored Nov 24, 2024
2 parents 5e46c7a + e8cbeea commit e5d17b7
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 120 deletions.
9 changes: 9 additions & 0 deletions ui/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ struct TIMELINE_INFO
TIMELINE_INFO() : beginFrame(0), endFrame(0), currFrame(0), bAlways(false), timelinefps(24) {}
};

enum REC_RETURN_CODE
{
REC_NOERROR = 0,
REC_NO_RECORD_OPTION = 1,
REC_OPTIX_INTERNAL_FATAL = -1,
REC_FFMPEG_FATAL = -3,
REC_NOFFMPEG = -2,
};

struct RECORD_SETTING
{
QString record_path;
Expand Down
12 changes: 8 additions & 4 deletions ui/zenoedit/launch/optixcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int optixcmd(const QCoreApplication& app, int port)
ret = worker.recordFrame_impl(recInfo, frame);
if (!ret) {
zeno::log_error("\n[optixcmd]:{\"result\" : -1}\n");
return -1;
return REC_OPTIX_INTERNAL_FATAL;
}
else {
QString errMsg = QString("\n[optixcmd]: {\"frame\" : %1}\n").arg(frame);
Expand All @@ -197,12 +197,16 @@ int optixcmd(const QCoreApplication& app, int port)
++frame;
}

REC_RETURN_CODE err_info = REC_NOERROR;
if (param.isExportVideo)
{
recordMgr.endRecToExportVideo();
err_info = recordMgr.endRecToExportVideo();
if (err_info != REC_NOERROR) {
zeno::log_error("\n[optixcmd]:{\"result\" : " + std::to_string(err_info) + "}\n");
return REC_NOERROR;
}
}

zeno::log_critical("\n[optixcmd]:{\"result\" : 0}\n");

return 0;
return REC_NOERROR;
}
250 changes: 142 additions & 108 deletions ui/zenoedit/recordmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int record_main(const QCoreApplication& app)
if (cmdParser.isSet("zsg"))
{
param.sZsgPath = cmdParser.value("zsg");
//ÏȽâÎözsgÀïÃæµÄäÖȾ²ÎÊý
//�Ƚ���zsg�������Ⱦ����
ZsgReader::getInstance().readRenderSettings(param.sZsgPath, param);
}
if (cmdParser.isSet("record"))
Expand Down Expand Up @@ -236,150 +236,184 @@ int record_main(const QCoreApplication& app)
QCoreApplication::exit(-2);
});

QObject::connect(zenoApp->getServer(), &ZTcpServer::runFinished, [=]() {
if (!param.bRecord) {
std::cout << "\n[record] record set to false. calculation process finished and exit.\n" << std::flush;
QCoreApplication::exit(0);
}
if (param.sPath.isEmpty()) {
std::cout << "\n[record] record failed because the path to store image has not been set." << std::flush;
QCoreApplication::exit(-1);
}
});

bool ret = AppHelper::openZsgAndRun(param, launchparam);
ZERROR_EXIT(ret, -1); //will launch tcp server to start a calc proc.

//get the final zencache path, like `2023-07-06 18-29-14`
std::shared_ptr<ZCacheMgr> mgr = zenoApp->cacheMgr();
QString zenCacheDir = mgr->cachePath();
ZERROR_EXIT(!zenCacheDir.isEmpty(), -1);
if (param.bRecord && !param.sPath.isEmpty()) {
//get the final zencache path, like `2023-07-06 18-29-14`
std::shared_ptr<ZCacheMgr> mgr = zenoApp->cacheMgr();
QString zenCacheDir = mgr->cachePath();
ZERROR_EXIT(!zenCacheDir.isEmpty(), -1);

QStringList cmdArgs = QCoreApplication::arguments();
QStringList args;
QStringList cmdArgs = QCoreApplication::arguments();
QStringList args;

int idxCachePath = cmdArgs.indexOf("--cachePath");
if (idxCachePath == -1)
{
zeno::log_error("no cache path offered, please specifiy with --cachePath");
return -1;
}

auto pGraphs = zenoApp->graphsManagment();
ZERROR_EXIT(pGraphs, -1);
int idxCachePath = cmdArgs.indexOf("--cachePath");
if (idxCachePath == -1)
{
zeno::log_error("no cache path offered, please specifiy with --cachePath");
return -1;
}

args.append("--optixcmd");
args.append("0");
auto pGraphs = zenoApp->graphsManagment();
ZERROR_EXIT(pGraphs, -1);

args.append("--zsg");
args.append(param.sZsgPath);
args.append("--optixcmd");
args.append("0");

args.append("--cachePath");
args.append(zenCacheDir);
args.append("--zsg");
args.append(param.sZsgPath);

args.append("--cacheautorm");
args.append("1");
args.append("--cachePath");
args.append(zenCacheDir);

args.append("--optixShowBackground");
args.append(QString::number(pGraphs->userdataInfo().optix_show_background));
args.append("--cacheautorm");
args.append("1");

args.append("--frame");
args.append(QString::number(param.iFrame));
args.append("--optixShowBackground");
args.append(QString::number(pGraphs->userdataInfo().optix_show_background));

args.append("--sframe");
args.append(QString::number(param.iSFrame));
args.append("--frame");
args.append(QString::number(param.iFrame));

args.append("--sample");
args.append(QString::number(param.iSample));
args.append("--sframe");
args.append(QString::number(param.iSFrame));

args.append("--pixel");
args.append(param.sPixel);
args.append("--sample");
args.append(QString::number(param.iSample));

args.append("--path");
args.append(param.sPath);
args.append("--pixel");
args.append(param.sPixel);

args.append("--audio");
args.append(param.audioPath);
args.append("--path");
args.append(param.sPath);

args.append("--bitrate");
args.append(QString::number(param.iBitrate));
args.append("--audio");
args.append(param.audioPath);

args.append("--fps");
args.append(QString::number(param.iFps));
args.append("--bitrate");
args.append(QString::number(param.iBitrate));

args.append("--configFilePath");
args.append(param.configFilePath);
args.append("--fps");
args.append(QString::number(param.iFps));

args.append("--cacheNum");
args.append(QString::number(launchparam.cacheNum));
args.append("--configFilePath");
args.append(param.configFilePath);

args.append("--exitWhenRecordFinish");
args.append(QString::number(param.exitWhenRecordFinish));
args.append("--cacheNum");
args.append(QString::number(launchparam.cacheNum));

args.append("--optix");
args.append(QString::number(param.bOptix));
args.append("--exitWhenRecordFinish");
args.append(QString::number(param.exitWhenRecordFinish));

args.append("--video");
args.append(QString::number(param.isExportVideo));
args.append("--optix");
args.append(QString::number(param.bOptix));

args.append("--aov");
args.append(QString::number(param.bAov));
args.append("--video");
args.append(QString::number(param.isExportVideo));

args.append("--exr");
args.append(QString::number(param.export_exr));
args.append("--aov");
args.append(QString::number(param.bAov));

args.append("--needDenoise");
args.append(QString::number(param.needDenoise));
args.append("--exr");
args.append(QString::number(param.export_exr));

args.append("--videoname");
args.append(param.videoName);
args.append("--needDenoise");
args.append(QString::number(param.needDenoise));

args.append("--subzsg");
args.append(param.subZsg);
args.append("--videoname");
args.append(param.videoName);

args.append("--paramsPath");
args.append(launchparam.paramPath);
args.append("--subzsg");
args.append(param.subZsg);

args.append("--paramsJson");
args.append(param.paramsJson);
args.append("--paramsPath");
args.append(launchparam.paramPath);

optixProc->setInputChannelMode(QProcess::InputChannelMode::ManagedInputChannel);
optixProc->setReadChannel(QProcess::ProcessChannel::StandardOutput);
bool enableOptixLog = true;
if (enableOptixLog)
optixProc->setProcessChannelMode(QProcess::ProcessChannelMode::ForwardedErrorChannel);
else
optixProc->setProcessChannelMode(QProcess::ProcessChannelMode::SeparateChannels);
optixProc->start(QCoreApplication::applicationFilePath(), args);
args.append("--paramsJson");
args.append(param.paramsJson);

if (!optixProc->waitForStarted(-1)) {
zeno::log_warn("optix process failed to get started, giving up");
return -1;
}
optixProc->setInputChannelMode(QProcess::InputChannelMode::ManagedInputChannel);
optixProc->setReadChannel(QProcess::ProcessChannel::StandardOutput);
bool enableOptixLog = true;
if (enableOptixLog)
optixProc->setProcessChannelMode(QProcess::ProcessChannelMode::ForwardedErrorChannel);
else
optixProc->setProcessChannelMode(QProcess::ProcessChannelMode::SeparateChannels);
optixProc->start(QCoreApplication::applicationFilePath(), args);

optixProc->closeWriteChannel();

QObject::connect(optixProc, &QProcess::readyRead, [=]() {

while (optixProc->canReadLine()) {
QByteArray content = optixProc->readLine();
if (!optixProc->waitForStarted(-1)) {
zeno::log_warn("optix process failed to get started, giving up");
return -1;
}

if (content.startsWith("[optixcmd]:")) {
static const QString sFlag = "[optixcmd]:";
content = content.mid(sFlag.length());
rapidjson::Document doc;
doc.Parse(content);
ZASSERT_EXIT(doc.IsObject());
if (doc.HasMember("result")) {
ZASSERT_EXIT(doc["result"].IsInt());
int ret = doc["result"].GetInt();
std::cout << "\n[record] result is " << ret << "\n" << std::flush;
QCoreApplication::exit(ret);
}
else if (doc.HasMember("frame")) {
ZASSERT_EXIT(doc["frame"].IsInt());
int frame = doc["frame"].GetInt();
std::cout << "\n[record] frame " << frame << " recording is finished.\n" << std::flush;
optixProc->closeWriteChannel();

QObject::connect(optixProc, &QProcess::readyRead, [=]() {

while (optixProc->canReadLine()) {
QByteArray content = optixProc->readLine();

if (content.startsWith("[optixcmd]:")) {
static const QString sFlag = "[optixcmd]:";
content = content.mid(sFlag.length());
rapidjson::Document doc;
doc.Parse(content);
ZASSERT_EXIT(doc.IsObject());
if (doc.HasMember("result")) {
ZASSERT_EXIT(doc["result"].IsInt());
int ret = doc["result"].GetInt();
std::string err_info;
if (ret != 0) {
switch (ret)
{
case REC_NO_RECORD_OPTION:
err_info = "[error]no record video, please set video=1 on command line";
break;
case REC_OPTIX_INTERNAL_FATAL:
err_info = "[error]internal error on ";
break;
case REC_FFMPEG_FATAL:
err_info = "[error]run error on ffmpeg command";
break;
case REC_NOFFMPEG:
err_info = "[error]no ffmpeg.exe deployed on dir same as zeno.";
break;
}
}
else {
err_info = "the recording returns no error;";
}
std::cout << "\n" << err_info << "\n" << std::flush;
QCoreApplication::exit(ret);
}
else if (doc.HasMember("frame")) {
ZASSERT_EXIT(doc["frame"].IsInt());
int frame = doc["frame"].GetInt();
std::cout << "\n[record] frame " << frame << " recording is finished.\n" << std::flush;
}
}
}
}
});
});

QObject::connect(optixProc, &QProcess::errorOccurred, [=](QProcess::ProcessError error) {
if (QProcess::Crashed == error) {
std::cout << "\n[record] render process has crashed\n" << std::flush;
QCoreApplication::exit(-2);
}
});
QObject::connect(optixProc, &QProcess::errorOccurred, [=](QProcess::ProcessError error) {
if (QProcess::Crashed == error) {
std::cout << "\n[record] render process has crashed\n" << std::flush;
QCoreApplication::exit(-2);
}
});
}

//QObject::connect(optixProc, &QProcess::finished, [=](int exitCode, QProcess::ExitStatus exitStatus) {

Expand Down
20 changes: 13 additions & 7 deletions ui/zenoedit/viewport/recordvideomgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ VideoRecInfo RecordVideoMgr::getRecordInfo() const
return m_recordInfo;
}

void RecordVideoMgr::endRecToExportVideo()
REC_RETURN_CODE RecordVideoMgr::endRecToExportVideo()
{
if (m_recordInfo.bExportEXR) {
emit recordFinished(m_recordInfo.record_path);
return;
return REC_NOERROR;
}
// denoising
if (m_recordInfo.needDenoise) {
Expand Down Expand Up @@ -184,7 +184,7 @@ void RecordVideoMgr::endRecToExportVideo()
}
if (!m_recordInfo.bExportVideo) {
emit recordFinished(m_recordInfo.record_path);
return;
return REC_NO_RECORD_OPTION;
}
//Zenovis::GetInstance().blockSignals(false);
{
Expand Down Expand Up @@ -215,18 +215,24 @@ void RecordVideoMgr::endRecToExportVideo()
.arg(outPath)
.arg(m_recordInfo.audioPath);
ret = QProcess::execute(cmd);
if (ret == 0)
if (ret == 0) {
emit recordFinished(m_recordInfo.record_path);
else
return REC_NOERROR;
}
else {
emit recordFailed(QString());
return;
return REC_FFMPEG_FATAL;
}
}
emit recordFinished(m_recordInfo.record_path);
return REC_NOERROR;
}
else
{
//todo get the error string from QProcess.
emit recordFailed(QString(tr("ffmpeg command failed, please whether check ffmpeg exists.")));
QString err_info = QString(tr("ffmpeg command failed, please whether check ffmpeg exists."));
emit recordFailed(err_info);
return REC_NOFFMPEG;
}
}

Expand Down
Loading

0 comments on commit e5d17b7

Please sign in to comment.