/** \fn PreviewGenerator::RunReal(void) * \brief This call creates a preview without starting a new thread. */ bool PreviewGenerator::RunReal(void) { bool ok = false; bool is_local = IsLocal(); if (is_local && LocalPreviewRun()) { ok = true; } else if (!localOnly) { if (is_local) { VERBOSE(VB_IMPORTANT, LOC_WARN + "Failed to save preview." "\n\t\t\tYou may need to check user and group ownership on" "\n\t\t\tyour frontend and backend for quicker previews.\n" "\n\t\t\tAttempting to regenerate preview on backend.\n"); } ok = RemotePreviewRun(); } else { VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Run() file not local: '%1'") .arg(pathname)); } return ok; }
bool PreviewGenerator::Run(void) { bool ok = false; if (!IsLocal()) { if (!localOnly) { ok = RemotePreviewRun(); } else { VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Run() file not local: '%1'") .arg(pathname)); } } else { // This is where we fork and run mythbackend to actually make preview QString command = gContext->GetInstallPrefix() + "/bin/mythbackend --generate-preview "; command += QString("%1x%2") .arg(outSize.width()).arg(outSize.height()); if (captureTime >= 0) command += QString("@%1%2") .arg(captureTime).arg(timeInSeconds ? "s" : "f"); command += " "; command += QString("--chanid %1 ").arg(programInfo.chanid); command += QString("--starttime %1 ") .arg(programInfo.recstartts.toString("yyyyMMddhhmmss")); if (!outFileName.isEmpty()) command += QString("--outfile \"%1\" ").arg(outFileName); int ret = myth_system(command); if (ret) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Encountered problems running " + QString("'%1'").arg(command)); } else { VERBOSE(VB_PLAYBACK, LOC + "Preview process returned 0."); QString outname = (!outFileName.isEmpty()) ? outFileName : (pathname + ".png"); QString lpath = QFileInfo(outname).fileName(); if (lpath == outname) { StorageGroup sgroup; QString tmpFile = sgroup.FindRecordingFile(lpath); outname = (tmpFile.isEmpty()) ? outname : tmpFile; } QFileInfo fi(outname); ok = (fi.exists() && fi.isReadable() && fi.size()); if (ok) VERBOSE(VB_PLAYBACK, LOC + "Preview process ran ok."); else { VERBOSE(VB_IMPORTANT, LOC_ERR + "Preview process not ok." + QString("\n\t\t\tfileinfo(%1)").arg(outname) <<" exists: "<<fi.exists() <<" readable: "<<fi.isReadable() <<" size: "<<fi.size()); } } } if (ok) { QMutexLocker locker(&previewLock); emit previewReady(&programInfo); } return ok; }
/** \fn PreviewGenerator::RunReal(void) * \brief This call creates a preview without starting a new thread. */ bool PreviewGenerator::RunReal(void) { QString msg; QTime tm = QTime::currentTime(); bool ok = false; bool is_local = IsLocal(); if (!is_local && !!(mode & kRemote)) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Run() file not local: '%1'") .arg(pathname)); } else if (!(mode & kLocal) && !(mode & kRemote)) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Run() Preview of '%1' failed " "because mode was invalid 0x%2") .arg(pathname).arg((int)mode,0,16)); } else if (is_local && !!(mode & kLocal) && LocalPreviewRun()) { ok = true; msg = QString("Generated on %1 in %2 seconds, starting at %3") .arg(gCoreContext->GetHostName()) .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } else if (!!(mode & kRemote)) { if (is_local && (mode & kLocal)) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Failed to save preview." "\n\t\t\tYou may need to check user and group ownership on" "\n\t\t\tyour frontend and backend for quicker previews.\n" "\n\t\t\tAttempting to regenerate preview on backend.\n"); } ok = RemotePreviewRun(); if (ok) { msg = QString("Generated remotely in %1 seconds, starting at %2") .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } else { msg = "Remote preview failed"; } } else { msg = "Could not access recording"; } QMutexLocker locker(&previewLock); if (listener) { QString output_fn = outFileName.isEmpty() ? (programInfo.GetPathname()+".png") : outFileName; QDateTime dt; if (ok) { QFileInfo fi(output_fn); if (fi.exists()) dt = fi.lastModified(); } QString message = (ok) ? "PREVIEW_SUCCESS" : "PREVIEW_FAILED"; QStringList list; list.push_back(programInfo.MakeUniqueKey()); list.push_back(output_fn); list.push_back(msg); list.push_back(dt.isValid()?dt.toString(Qt::ISODate):""); list.push_back(token); QCoreApplication::postEvent(listener, new MythEvent(message, list)); } return ok; }
bool PreviewGenerator::Run(void) { QString msg; QDateTime dtm = QDateTime::currentDateTime(); QTime tm = QTime::currentTime(); bool ok = false; QString command = GetInstallPrefix() + "/bin/mythpreviewgen"; bool local_ok = ((IsLocal() || !!(mode & kForceLocal)) && (!!(mode & kLocal)) && QFileInfo(command).isExecutable()); if (!local_ok) { if (!!(mode & kRemote)) { ok = RemotePreviewRun(); if (ok) { msg = QString("Generated remotely in %1 seconds, starting at %2") .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } } else { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Run() cannot generate preview locally for: '%1'") .arg(pathname)); msg = "Failed, local preview requested for remote file."; } } else { // This is where we fork and run mythpreviewgen to actually make preview command += QString(" --size %1x%2") .arg(outSize.width()).arg(outSize.height()); if (captureTime >= 0) { if (timeInSeconds) command += QString(" --seconds %1").arg(captureTime); else command += QString(" --frame %1").arg(captureTime); } command += QString(" --chanid %1").arg(programInfo.GetChanID()); command += QString(" --starttime %1") .arg(programInfo.GetRecordingStartTime(MythDate)); if (!outFileName.isEmpty()) command += QString(" --outfile \"%1\"").arg(outFileName); command += logPropagateArgs; if (!logPropagateQuiet()) command += " --quiet"; // Timeout in 30s uint ret = myth_system(command, kMSDontBlockInputDevs | kMSDontDisableDrawing | kMSProcessEvents, 30); if (ret != GENERIC_EXIT_OK) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Encountered problems running '%1' (%2)") .arg(command) .arg(ret)); } else { LOG(VB_PLAYBACK, LOG_INFO, LOC + "Preview process returned 0."); QString outname = (!outFileName.isEmpty()) ? outFileName : (pathname + ".png"); QString lpath = QFileInfo(outname).fileName(); if (lpath == outname) { StorageGroup sgroup; QString tmpFile = sgroup.FindFile(lpath); outname = (tmpFile.isEmpty()) ? outname : tmpFile; } QFileInfo fi(outname); ok = (fi.exists() && fi.isReadable() && fi.size()); if (ok) { LOG(VB_PLAYBACK, LOG_INFO, LOC + "Preview process ran ok."); msg = QString("Generated on %1 in %2 seconds, starting at %3") .arg(gCoreContext->GetHostName()) .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } else { LOG(VB_GENERAL, LOG_ERR, LOC + "Preview process not ok." + QString("\n\t\t\tfileinfo(%1)").arg(outname) + QString(" exists: %1").arg(fi.exists()) + QString(" readable: %1").arg(fi.isReadable()) + QString(" size: %1").arg(fi.size())); LOG(VB_GENERAL, LOG_ERR, LOC + QString("Despite command '%1' returning success") .arg(command)); msg = QString("Failed to read preview image despite " "preview process returning success."); } } } QMutexLocker locker(&previewLock); // Backdate file to start of preview time in case a bookmark was made // while we were generating the preview. QString output_fn = outFileName.isEmpty() ? (programInfo.GetPathname()+".png") : outFileName; QDateTime dt; if (ok) { QFileInfo fi(output_fn); if (fi.exists()) dt = fi.lastModified(); } QString message = (ok) ? "PREVIEW_SUCCESS" : "PREVIEW_FAILED"; if (listener) { QStringList list; list.push_back(programInfo.MakeUniqueKey()); list.push_back(outFileName.isEmpty() ? (programInfo.GetPathname()+".png") : outFileName); list.push_back(msg); list.push_back(dt.isValid()?dt.toString(Qt::ISODate):""); list.push_back(token); QCoreApplication::postEvent(listener, new MythEvent(message, list)); } return ok; }
bool PreviewGenerator::Run(void) { QString msg; QDateTime dtm = MythDate::current(); QTime tm = QTime::currentTime(); bool ok = false; QString command = GetAppBinDir() + "mythpreviewgen"; bool local_ok = ((IsLocal() || !!(m_mode & kForceLocal)) && (!!(m_mode & kLocal)) && QFileInfo(command).isExecutable()); if (!local_ok) { if (!!(m_mode & kRemote)) { ok = RemotePreviewRun(); if (ok) { msg = QString("Generated remotely in %1 seconds, starting at %2") .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } } else { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Run() cannot generate preview locally for: '%1'") .arg(m_pathname)); msg = "Failed, local preview requested for remote file."; } } else { // This is where we fork and run mythpreviewgen to actually make preview QStringList cmdargs; cmdargs << "--size" << QString("%1x%2").arg(m_outSize.width()).arg(m_outSize.height()); if (m_captureTime >= 0) { if (m_timeInSeconds) cmdargs << "--seconds"; else cmdargs << "--frame"; cmdargs << QString::number(m_captureTime); } cmdargs << "--chanid" << QString::number(m_programInfo.GetChanID()) << "--starttime" << m_programInfo.GetRecordingStartTime(MythDate::kFilename); if (!m_outFileName.isEmpty()) cmdargs << "--outfile" << m_outFileName; // Timeout in 30s MythSystemLegacy *ms = new MythSystemLegacy(command, cmdargs, kMSDontBlockInputDevs | kMSDontDisableDrawing | kMSProcessEvents | kMSAutoCleanup | kMSPropagateLogs); ms->SetNice(10); ms->SetIOPrio(7); ms->Run(30); uint ret = ms->Wait(); delete ms; if (ret != GENERIC_EXIT_OK) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Encountered problems running '%1 %2' - (%3)") .arg(command).arg(cmdargs.join(" ")).arg(ret)); } else { LOG(VB_PLAYBACK, LOG_INFO, LOC + "Preview process returned 0."); QString outname = (!m_outFileName.isEmpty()) ? m_outFileName : (m_pathname + ".png"); QString lpath = QFileInfo(outname).fileName(); if (lpath == outname) { StorageGroup sgroup; QString tmpFile = sgroup.FindFile(lpath); outname = (tmpFile.isEmpty()) ? outname : tmpFile; } QFileInfo fi(outname); ok = (fi.exists() && fi.isReadable() && fi.size()); if (ok) { LOG(VB_PLAYBACK, LOG_INFO, LOC + "Preview process ran ok."); msg = QString("Generated on %1 in %2 seconds, starting at %3") .arg(gCoreContext->GetHostName()) .arg(tm.elapsed()*0.001) .arg(tm.toString(Qt::ISODate)); } else { LOG(VB_GENERAL, LOG_ERR, LOC + "Preview process not ok." + QString("\n\t\t\tfileinfo(%1)").arg(outname) + QString(" exists: %1").arg(fi.exists()) + QString(" readable: %1").arg(fi.isReadable()) + QString(" size: %1").arg(fi.size())); LOG(VB_GENERAL, LOG_ERR, LOC + QString("Despite command '%1' returning success") .arg(command)); msg = QString("Failed to read preview image despite " "preview process returning success."); } } } QMutexLocker locker(&m_previewLock); // Backdate file to start of preview time in case a bookmark was made // while we were generating the preview. QString output_fn = m_outFileName.isEmpty() ? (m_programInfo.GetPathname()+".png") : m_outFileName; QDateTime dt; if (ok) { QFileInfo fi(output_fn); if (fi.exists()) dt = fi.lastModified(); } QString message = (ok) ? "PREVIEW_SUCCESS" : "PREVIEW_FAILED"; if (m_listener) { QStringList list; list.push_back(QString::number(m_programInfo.GetRecordingID())); list.push_back(output_fn); list.push_back(msg); list.push_back(dt.isValid()?dt.toUTC().toString(Qt::ISODate):""); list.push_back(m_token); QCoreApplication::postEvent(m_listener, new MythEvent(message, list)); } return ok; }