bool PreviewGenerator::LocalPreviewRun(void) { programInfo.MarkAsInUse(true, kInUseID); float aspect = 0; int len, width, height, sz; long long captime = captureTime; if (captime < 0) { timeInSeconds = true; captime = (gContext->GetNumSetting("PreviewPixmapOffset", 64) + gContext->GetNumSetting("RecordPreRoll", 0)); } len = width = height = sz = 0; unsigned char *data = (unsigned char*) GetScreenGrab(&programInfo, pathname, captime, timeInSeconds, sz, width, height, aspect); QString outname = CreateAccessibleFilename(pathname, outFileName); int dw = (outSize.width() < 0) ? width : outSize.width(); int dh = (outSize.height() < 0) ? height : outSize.height(); bool ok = SavePreview(outname, data, width, height, aspect, dw, dh); if (data) delete[] data; programInfo.MarkAsInUse(false); return ok; }
bool PreviewGenerator::RemotePreviewRun(void) { QStringList strlist = "QUERY_GENPIXMAP"; programInfo.ToStringList(strlist); strlist.push_back(timeInSeconds ? "s" : "f"); encodeLongLong(strlist, captureTime); if (outFileName.isEmpty()) { strlist.push_back("<EMPTY>"); } else { QFileInfo fi(outFileName); strlist.push_back(fi.fileName()); } strlist.push_back(QString::number(outSize.width())); strlist.push_back(QString::number(outSize.height())); bool ok = false; if (createSockets) { if (!RemotePreviewSetup()) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to open sockets."); return false; } if (serverSock) { serverSock->writeStringList(strlist); ok = serverSock->readStringList(strlist, false); } RemotePreviewTeardown(); } else { ok = gContext->SendReceiveStringList(strlist); } if (!ok || strlist.empty() || (strlist[0] != "OK")) { if (!ok) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Remote Preview failed due to communications error."); } else if (strlist.size() > 1) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Remote Preview failed, reason given: " <<strlist[1]); } else { VERBOSE(VB_IMPORTANT, LOC_ERR + "Remote Preview failed due to an uknown error."); } return false; } if (outFileName.isEmpty()) return true; // find file, copy/move to output file name & location... QString url = QString::null; QString fn = QFileInfo(outFileName).fileName(); QByteArray data; ok = false; QStringList fileNames; fileNames.push_back(CreateAccessibleFilename(programInfo.pathname, fn)); fileNames.push_back(CreateAccessibleFilename(programInfo.pathname, "")); QStringList::const_iterator it = fileNames.begin(); for ( ; it != fileNames.end() && (!ok || data.isEmpty()); ++it) { data.resize(0); url = *it; RemoteFile *rf = new RemoteFile(url, false, 0); ok = rf->SaveAs(data); delete rf; } if (ok && data.size()) { QFile file(outFileName); ok = file.open(IO_Raw|IO_WriteOnly); if (!ok) { VERBOSE(VB_IMPORTANT, QString("Failed to open: '%1'") .arg(outFileName)); } off_t offset = 0; size_t remaining = (ok) ? data.size() : 0; uint failure_cnt = 0; while ((remaining > 0) && (failure_cnt < 5)) { ssize_t written = file.writeBlock(data.data() + offset, remaining); if (written < 0) { failure_cnt++; usleep(50000); continue; } failure_cnt = 0; offset += written; remaining -= written; } if (ok && !remaining) { VERBOSE(VB_PLAYBACK, QString("Saved: '%1'") .arg(outFileName)); } } return ok && data.size(); }
bool PreviewGenerator::LocalPreviewRun(void) { programInfo.MarkAsInUse(true, kPreviewGeneratorInUseID); float aspect = 0; int width, height, sz; long long captime = captureTime; QDateTime dt = QDateTime::currentDateTime(); if (captime > 0) LOG(VB_GENERAL, LOG_INFO, "Preview from time spec"); if (captime < 0) { captime = programInfo.QueryBookmark(); if (captime > 0) { timeInSeconds = false; LOG(VB_GENERAL, LOG_INFO, QString("Preview from bookmark (frame %1)").arg(captime)); } else captime = -1; } if (captime < 0) { timeInSeconds = true; int startEarly = 0; int programDuration = 0; int preroll = gCoreContext->GetNumSetting("RecordPreRoll", 0); if (programInfo.GetScheduledStartTime().isValid() && programInfo.GetScheduledEndTime().isValid() && (programInfo.GetScheduledStartTime() != programInfo.GetScheduledEndTime())) { programDuration = programInfo.GetScheduledStartTime() .secsTo(programInfo.GetScheduledEndTime()); } if (programInfo.GetRecordingStartTime().isValid() && programInfo.GetScheduledStartTime().isValid() && (programInfo.GetRecordingStartTime() != programInfo.GetScheduledStartTime())) { startEarly = programInfo.GetRecordingStartTime() .secsTo(programInfo.GetScheduledStartTime()); } if (programDuration > 0) { captime = startEarly + (programDuration / 3); } if (captime < 0) captime = 600; captime += preroll; LOG(VB_GENERAL, LOG_INFO, QString("Preview at calculated offset (%1 seconds)").arg(captime)); } width = height = sz = 0; unsigned char *data = (unsigned char*) GetScreenGrab(programInfo, pathname, captime, timeInSeconds, sz, width, height, aspect); QString outname = CreateAccessibleFilename(pathname, outFileName); int dw = (outSize.width() < 0) ? width : outSize.width(); int dh = (outSize.height() < 0) ? height : outSize.height(); bool ok = SavePreview(outname, data, width, height, aspect, dw, dh); if (ok) { // Backdate file to start of preview time in case a bookmark was made // while we were generating the preview. struct utimbuf times; times.actime = times.modtime = dt.toTime_t(); utime(outname.toLocal8Bit().constData(), ×); } delete[] data; programInfo.MarkAsInUse(false, kPreviewGeneratorInUseID); return ok; }