Skip to content

Commit

Permalink
Do now allow multiple jobs with the same target file
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Feb 27, 2025
1 parent 8c6cd18 commit e3215a1
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/docks/encodedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,13 @@ MeltJob *EncodeDock::createMeltJob(Mlt::Producer *service, const QString &target
if (Util::warnIfNotWritable(target, this, caption))
return nullptr;

if (JOBS.targetIsInProgress(target)) {
QMessageBox::warning(this, windowTitle(),
QObject::tr("A job already exists for %1")
.arg(target));
return nullptr;
}

// if image sequence, change filename to include number
QString mytarget = target;
if (!ui->disableVideoCheckbox->isChecked()) {
Expand Down
1 change: 1 addition & 0 deletions src/docks/timelinedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3864,6 +3864,7 @@ void TimelineDock::recordAudio()
#endif
args << "-flush_packets" << "1" << "-y" << filename;
m_recordJob.reset(new FfmpegJob("vo", args, false, priority));
m_recordJob->setTarget(filename);
connect(m_recordJob.get(), SIGNAL(started()), SLOT(onRecordStarted()));
connect(m_recordJob.get(), SIGNAL(finished(AbstractJob *, bool)),
SLOT(onRecordFinished(AbstractJob *, bool)));
Expand Down
14 changes: 13 additions & 1 deletion src/jobqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void JobQueue::removeFinished()
QMutexLocker locker(&m_mutex);
auto row = 0;
foreach (AbstractJob *job, m_jobs) {
if (job->ran() && job->state() != QProcess::Running) {
if (job->isFinished()) {
removeRow(row);
m_jobs.removeOne(job);
delete job;
Expand All @@ -236,3 +236,15 @@ void JobQueue::removeFinished()
}
}
}

bool JobQueue::targetIsInProgress(const QString &target)
{
if (!m_jobs.isEmpty() && !target.isEmpty()) {
foreach (AbstractJob *job, m_jobs) {
if (!job->isFinished() && job->target() == target) {
return true;
}
}
}
return false;
}
1 change: 1 addition & 0 deletions src/jobqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class JobQueue : public QStandardItemModel
{
return m_jobs;
}
bool targetIsInProgress(const QString &target);

signals:
void jobAdded();
Expand Down
13 changes: 13 additions & 0 deletions src/jobs/abstractjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class AbstractJob : public QProcess
QStandardItem *standardItem();
bool ran() const;
bool stopped() const;
bool isFinished() const
{
return (ran() && state() != QProcess::Running);
}
void appendToLog(const QString &);
QString log() const;
QString label() const
Expand All @@ -63,6 +67,14 @@ class AbstractJob : public QProcess
}
void setPostJobAction(PostJobAction *action);
bool paused() const;
void setTarget(const QString & target)
{
m_target = target;
}
QString target()
{
return m_target;
}

public slots:
void start(const QString &program, const QStringList &arguments);
Expand Down Expand Up @@ -101,6 +113,7 @@ private slots:
QAction *m_actionPause;
QAction *m_actionResume;
bool m_isPaused;
QString m_target;
};

#endif // ABSTRACTJOB_H
1 change: 1 addition & 0 deletions src/jobs/meltjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ MeltJob::MeltJob(const QString &name, const QString &xml, int frameRateNum, int
, m_currentFrame(0)
, m_useMultiConsumer(false)
{
setTarget(name);
if (!xml.isEmpty()) {
QAction *action = new QAction(tr("View XML"), this);
action->setToolTip(tr("View the MLT XML for this job"));
Expand Down
1 change: 1 addition & 0 deletions src/jobs/qimagejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ QImageJob::QImageJob(const QString &destFilePath, const QString &srcFilePath, co
, m_destFilePath(destFilePath)
, m_height(height)
{
setTarget(destFilePath);
setLabel(tr("Make proxy for %1").arg(Util::baseName(srcFilePath)));
}

Expand Down
1 change: 1 addition & 0 deletions src/jobs/whisperjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WhisperJob::WhisperJob(const QString &name, const QString &iWavFile, const QStri
, m_maxLength(maxLength)
, m_previousPercent(0)
{
setTarget(oSrtFile);
}

WhisperJob::~WhisperJob()
Expand Down
6 changes: 6 additions & 0 deletions src/proxymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ void ProxyManager::generateVideoProxy(Mlt::Producer &producer, bool fullRange, S
auto hwCodecs = Settings.encodeHardware();
QString hwFilters;

if (JOBS.targetIsInProgress(fileName)) {
LOG_ERROR() << "A job is already in progress for" << fileName;
return;
}

// Touch file to make it in progress
QFile file(fileName);
file.open(QIODevice::WriteOnly);
Expand Down Expand Up @@ -248,6 +253,7 @@ void ProxyManager::generateVideoProxy(Mlt::Producer &producer, bool fullRange, S

FfmpegJob *job = new FfmpegJob(fileName, args, true);
job->setLabel(QObject::tr("Make proxy for %1").arg(Util::baseName(resource)));
job->setTarget(fileName);
if (replace) {
job->setPostJobAction(new ProxyReplacePostJobAction(resource, fileName, hash));
} else {
Expand Down
11 changes: 11 additions & 0 deletions src/transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void Transcoder::convert(TranscodeDialog &dialog)
.arg(fi.fileName()));
return;
}
if (JOBS.targetIsInProgress(filename)) {
MAIN.showStatusMessage(tr("A job already exists for %1").arg(filename));
return;
}
if (Util::warnIfNotWritable(filename, MAIN.centralWidget(), dialog.windowTitle()))
return;

Expand Down Expand Up @@ -123,6 +127,12 @@ void Transcoder::convert(TranscodeDialog &dialog)
QFileInfo fi(resource);
filename = path + nameFormat.arg(fi.completeBaseName(), suffix);
filename = Util::getNextFile(filename);
if (JOBS.targetIsInProgress(filename)) {
if (JOBS.targetIsInProgress(filename)) {
MAIN.showStatusMessage(tr("A job already exists for %1").arg(filename));
return;
}
}
convertProducer(&producer, dialog, filename);
}
}
Expand Down Expand Up @@ -274,6 +284,7 @@ void Transcoder::convertProducer(Mlt::Producer *producer, TranscodeDialog &dialo

FfmpegJob *job = new FfmpegJob(filename, args, false);
job->setLabel(tr("Convert %1").arg(Util::baseName(filename)));
job->setTarget(filename);
if (dialog.isSubClip()) {
if (producer->get(kMultitrackItemProperty)) {
QString s = QString::fromLatin1(producer->get(kMultitrackItemProperty));
Expand Down
14 changes: 14 additions & 0 deletions src/widgets/avformatproducerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ void AvformatProducerWidget::on_reverseButton_clicked()
.arg(fi.fileName()));
return;
}
if (JOBS.targetIsInProgress(filename)) {
QMessageBox::warning(this, dialog.windowTitle(),
QObject::tr("A job already exists for %1")
.arg(filename));
return;
}
if (Util::warnIfNotWritable(filename, this, dialog.windowTitle()))
return;

Expand Down Expand Up @@ -989,6 +995,7 @@ void AvformatProducerWidget::on_reverseButton_clicked()
MeltJob *meltJob = new MeltJob(filename, meltArgs,
m_producer->get_int("meta.media.frame_rate_num"), m_producer->get_int("meta.media.frame_rate_den"));
meltJob->setLabel(tr("Reverse %1").arg(Util::baseName(resource)));
meltJob->setTarget(filename);

if (m_producer->get(kMultitrackItemProperty)) {
QString s = QString::fromLatin1(m_producer->get(kMultitrackItemProperty));
Expand Down Expand Up @@ -1034,6 +1041,12 @@ void AvformatProducerWidget::on_actionExtractSubclip_triggered()
.arg(fi.fileName()));
return;
}
if (JOBS.targetIsInProgress(filename)) {
QMessageBox::warning(this, caption,
QObject::tr("A job already exists for %1")
.arg(filename));
return;
}
if (Util::warnIfNotWritable(filename, this, caption))
return;
Settings.setSavePath(QFileInfo(filename).path());
Expand Down Expand Up @@ -1066,6 +1079,7 @@ void AvformatProducerWidget::on_actionExtractSubclip_triggered()
// Run the ffmpeg job.
FfmpegJob *ffmpegJob = new FfmpegJob(filename, ffmpegArgs, false);
ffmpegJob->setLabel(tr("Extract sub-clip %1").arg(Util::baseName(resource)));
ffmpegJob->setTarget(filename);
JOBS.add(ffmpegJob);
}
}
Expand Down

0 comments on commit e3215a1

Please sign in to comment.