2014-09-02 19:11:55 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2014 by Ruwen Hahn <palana@stunned.de>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "window-remux.hpp"
|
|
|
|
|
|
|
|
#include "obs-app.hpp"
|
|
|
|
|
|
|
|
#include <QCloseEvent>
|
2018-01-15 16:26:49 -08:00
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QItemDelegate>
|
|
|
|
#include <QLineEdit>
|
2014-09-02 19:11:55 -07:00
|
|
|
#include <QMessageBox>
|
2018-01-15 16:26:49 -08:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
#include <QToolButton>
|
2017-05-08 04:53:35 -07:00
|
|
|
#include <QTimer>
|
2014-09-02 19:11:55 -07:00
|
|
|
|
|
|
|
#include "qt-wrappers.hpp"
|
2021-02-04 04:01:35 -08:00
|
|
|
#include "window-basic-main.hpp"
|
2014-09-02 19:11:55 -07:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
enum RemuxEntryColumn {
|
|
|
|
State,
|
|
|
|
InputPath,
|
|
|
|
OutputPath,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
enum RemuxEntryRole { EntryStateRole = Qt::UserRole, NewPathsToProcessRole };
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
Delegate - Presents cells in the grid.
|
|
|
|
**********************************************************/
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryPathItemDelegate::RemuxEntryPathItemDelegate(
|
|
|
|
bool isOutput, const QString &defaultPath)
|
|
|
|
: QStyledItemDelegate(), isOutput(isOutput), defaultPath(defaultPath)
|
2019-04-12 14:38:17 -07:00
|
|
|
{
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
QWidget *RemuxEntryPathItemDelegate::createEditor(
|
|
|
|
QWidget *parent, const QStyleOptionViewItem & /* option */,
|
|
|
|
const QModelIndex &index) const
|
2019-04-12 14:38:17 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryState state =
|
|
|
|
index.model()
|
2019-04-12 14:38:17 -07:00
|
|
|
->index(index.row(), RemuxEntryColumn::State)
|
|
|
|
.data(RemuxEntryRole::EntryStateRole)
|
|
|
|
.value<RemuxEntryState>();
|
|
|
|
if (state == RemuxEntryState::Pending ||
|
2019-06-22 22:13:45 -07:00
|
|
|
state == RemuxEntryState::InProgress) {
|
2019-04-12 14:38:17 -07:00
|
|
|
// Never allow modification of rows that are
|
|
|
|
// in progress.
|
|
|
|
return Q_NULLPTR;
|
|
|
|
} else if (isOutput && state != RemuxEntryState::Ready) {
|
|
|
|
// Do not allow modification of output rows
|
|
|
|
// that aren't associated with a valid input.
|
|
|
|
return Q_NULLPTR;
|
|
|
|
} else if (!isOutput && state == RemuxEntryState::Complete) {
|
|
|
|
// Don't allow modification of rows that are
|
|
|
|
// already complete.
|
|
|
|
return Q_NULLPTR;
|
|
|
|
} else {
|
|
|
|
QSizePolicy buttonSizePolicy(
|
2019-06-22 22:13:45 -07:00
|
|
|
QSizePolicy::Policy::Minimum,
|
|
|
|
QSizePolicy::Policy::Expanding,
|
|
|
|
QSizePolicy::ControlType::PushButton);
|
2019-04-12 14:38:17 -07:00
|
|
|
|
|
|
|
QWidget *container = new QWidget(parent);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto browseCallback = [this, container]() {
|
2019-04-12 14:38:17 -07:00
|
|
|
const_cast<RemuxEntryPathItemDelegate *>(this)
|
2019-06-22 22:13:45 -07:00
|
|
|
->handleBrowse(container);
|
2019-04-12 14:38:17 -07:00
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto clearCallback = [this, container]() {
|
2019-04-12 14:38:17 -07:00
|
|
|
const_cast<RemuxEntryPathItemDelegate *>(this)
|
2019-06-22 22:13:45 -07:00
|
|
|
->handleClear(container);
|
2019-04-12 14:38:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout();
|
2020-12-02 11:29:30 -08:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2019-04-12 14:38:17 -07:00
|
|
|
layout->setSpacing(0);
|
|
|
|
|
|
|
|
QLineEdit *text = new QLineEdit();
|
|
|
|
text->setObjectName(QStringLiteral("text"));
|
2019-06-22 22:13:45 -07:00
|
|
|
text->setSizePolicy(
|
|
|
|
QSizePolicy(QSizePolicy::Policy::Expanding,
|
|
|
|
QSizePolicy::Policy::Expanding,
|
|
|
|
QSizePolicy::ControlType::LineEdit));
|
2019-04-12 14:38:17 -07:00
|
|
|
layout->addWidget(text);
|
|
|
|
|
2020-03-25 17:13:10 -07:00
|
|
|
QObject::connect(text, SIGNAL(editingFinished()), this,
|
|
|
|
SLOT(updateText()));
|
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
QToolButton *browseButton = new QToolButton();
|
|
|
|
browseButton->setText("...");
|
|
|
|
browseButton->setSizePolicy(buttonSizePolicy);
|
|
|
|
layout->addWidget(browseButton);
|
|
|
|
|
|
|
|
container->connect(browseButton, &QToolButton::clicked,
|
2019-06-22 22:13:45 -07:00
|
|
|
browseCallback);
|
2019-04-12 14:38:17 -07:00
|
|
|
|
|
|
|
// The "clear" button is not shown in output cells
|
|
|
|
// or the insertion point's input cell.
|
|
|
|
if (!isOutput && state != RemuxEntryState::Empty) {
|
|
|
|
QToolButton *clearButton = new QToolButton();
|
|
|
|
clearButton->setText("X");
|
|
|
|
clearButton->setSizePolicy(buttonSizePolicy);
|
|
|
|
layout->addWidget(clearButton);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
container->connect(clearButton, &QToolButton::clicked,
|
|
|
|
clearCallback);
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
container->setLayout(layout);
|
|
|
|
container->setFocusProxy(text);
|
|
|
|
return container;
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
2019-04-12 14:38:17 -07:00
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
void RemuxEntryPathItemDelegate::setEditorData(QWidget *editor,
|
2019-06-22 22:13:45 -07:00
|
|
|
const QModelIndex &index) const
|
2019-04-12 14:38:17 -07:00
|
|
|
{
|
|
|
|
QLineEdit *text = editor->findChild<QLineEdit *>();
|
|
|
|
text->setText(index.data().toString());
|
|
|
|
editor->setProperty(PATH_LIST_PROP, QVariant());
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
void RemuxEntryPathItemDelegate::setModelData(QWidget *editor,
|
2019-06-22 22:13:45 -07:00
|
|
|
QAbstractItemModel *model,
|
|
|
|
const QModelIndex &index) const
|
2019-04-12 14:38:17 -07:00
|
|
|
{
|
|
|
|
// We use the PATH_LIST_PROP property to pass a list of
|
|
|
|
// path strings from the editor widget into the model's
|
|
|
|
// NewPathsToProcessRole. This is only used when paths
|
|
|
|
// are selected through the "browse" or "delete" buttons
|
|
|
|
// in the editor. If the user enters new text in the
|
|
|
|
// text box, we simply pass that text on to the model
|
|
|
|
// as normal text data in the default role.
|
|
|
|
QVariant pathListProp = editor->property(PATH_LIST_PROP);
|
|
|
|
if (pathListProp.isValid()) {
|
2019-06-22 22:13:45 -07:00
|
|
|
QStringList list =
|
|
|
|
editor->property(PATH_LIST_PROP).toStringList();
|
2018-01-15 16:26:49 -08:00
|
|
|
if (isOutput) {
|
2019-04-12 14:38:17 -07:00
|
|
|
if (list.size() > 0)
|
|
|
|
model->setData(index, list);
|
|
|
|
} else
|
|
|
|
model->setData(index, list,
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryRole::NewPathsToProcessRole);
|
2019-04-12 14:38:17 -07:00
|
|
|
} else {
|
|
|
|
QLineEdit *lineEdit = editor->findChild<QLineEdit *>();
|
|
|
|
model->setData(index, lineEdit->text());
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
2019-04-12 14:38:17 -07:00
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
void RemuxEntryPathItemDelegate::paint(QPainter *painter,
|
2019-06-22 22:13:45 -07:00
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const
|
2019-04-12 14:38:17 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryState state =
|
|
|
|
index.model()
|
2019-04-12 14:38:17 -07:00
|
|
|
->index(index.row(), RemuxEntryColumn::State)
|
|
|
|
.data(RemuxEntryRole::EntryStateRole)
|
|
|
|
.value<RemuxEntryState>();
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
QStyleOptionViewItem localOption = option;
|
|
|
|
initStyleOption(&localOption, index);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
if (isOutput) {
|
|
|
|
if (state != Ready) {
|
2019-06-22 22:13:45 -07:00
|
|
|
QColor background = localOption.palette.color(
|
|
|
|
QPalette::ColorGroup::Disabled,
|
2019-12-01 09:01:03 -08:00
|
|
|
QPalette::ColorRole::Window);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
localOption.backgroundBrush = QBrush(background);
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
QApplication::style()->drawControl(QStyle::CE_ItemViewItem,
|
2019-06-22 22:13:45 -07:00
|
|
|
&localOption, painter);
|
2019-04-12 14:38:17 -07:00
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
void RemuxEntryPathItemDelegate::handleBrowse(QWidget *container)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
QString OutputPattern = "(*.mp4 *.flv *.mov *.mkv *.ts *.m3u8)";
|
|
|
|
QString InputPattern = "(*.flv *.mov *.mkv *.ts *.m3u8)";
|
2019-04-12 14:38:17 -07:00
|
|
|
|
|
|
|
QLineEdit *text = container->findChild<QLineEdit *>();
|
|
|
|
|
|
|
|
QString currentPath = text->text();
|
|
|
|
if (currentPath.isEmpty())
|
|
|
|
currentPath = defaultPath;
|
|
|
|
|
|
|
|
bool isSet = false;
|
|
|
|
if (isOutput) {
|
2020-07-17 04:32:38 -07:00
|
|
|
QString newPath = SaveFile(container,
|
|
|
|
QTStr("Remux.SelectTarget"),
|
|
|
|
currentPath, OutputPattern);
|
2019-04-12 14:38:17 -07:00
|
|
|
|
|
|
|
if (!newPath.isEmpty()) {
|
|
|
|
container->setProperty(PATH_LIST_PROP,
|
2019-06-22 22:13:45 -07:00
|
|
|
QStringList() << newPath);
|
2019-04-12 14:38:17 -07:00
|
|
|
isSet = true;
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-17 04:32:38 -07:00
|
|
|
QStringList paths = OpenFiles(
|
2019-06-22 22:13:45 -07:00
|
|
|
container, QTStr("Remux.SelectRecording"), currentPath,
|
|
|
|
QTStr("Remux.OBSRecording") + QString(" ") +
|
|
|
|
InputPattern);
|
2019-04-12 14:38:17 -07:00
|
|
|
|
|
|
|
if (!paths.empty()) {
|
|
|
|
container->setProperty(PATH_LIST_PROP, paths);
|
|
|
|
isSet = true;
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 14:38:17 -07:00
|
|
|
if (isSet)
|
2018-01-15 16:26:49 -08:00
|
|
|
emit commitData(container);
|
2019-04-12 14:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxEntryPathItemDelegate::handleClear(QWidget *container)
|
|
|
|
{
|
|
|
|
// An empty string list will indicate that the entry is being
|
|
|
|
// blanked and should be deleted.
|
|
|
|
container->setProperty(PATH_LIST_PROP, QStringList());
|
|
|
|
|
|
|
|
emit commitData(container);
|
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
void RemuxEntryPathItemDelegate::updateText()
|
|
|
|
{
|
|
|
|
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>(sender());
|
2019-04-12 14:39:10 -07:00
|
|
|
QWidget *editor = lineEdit->parentWidget();
|
|
|
|
emit commitData(editor);
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
Model - Manages the queue's data
|
|
|
|
**********************************************************/
|
|
|
|
|
|
|
|
int RemuxQueueModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return queue.length() + (isProcessing ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int RemuxQueueModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return RemuxEntryColumn::Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RemuxQueueModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
QVariant result = QVariant();
|
|
|
|
|
|
|
|
if (index.row() >= queue.length()) {
|
|
|
|
return QVariant();
|
|
|
|
} else if (role == Qt::DisplayRole) {
|
|
|
|
switch (index.column()) {
|
|
|
|
case RemuxEntryColumn::InputPath:
|
|
|
|
result = queue[index.row()].sourcePath;
|
|
|
|
break;
|
|
|
|
case RemuxEntryColumn::OutputPath:
|
|
|
|
result = queue[index.row()].targetPath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (role == Qt::DecorationRole &&
|
2019-06-22 22:13:45 -07:00
|
|
|
index.column() == RemuxEntryColumn::State) {
|
2018-01-15 16:26:49 -08:00
|
|
|
result = getIcon(queue[index.row()].state);
|
|
|
|
} else if (role == RemuxEntryRole::EntryStateRole) {
|
|
|
|
result = queue[index.row()].state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RemuxQueueModel::headerData(int section, Qt::Orientation orientation,
|
2019-06-22 22:13:45 -07:00
|
|
|
int role) const
|
2018-01-15 16:26:49 -08:00
|
|
|
{
|
|
|
|
QVariant result = QVariant();
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole &&
|
2019-06-22 22:13:45 -07:00
|
|
|
orientation == Qt::Orientation::Horizontal) {
|
2018-01-15 16:26:49 -08:00
|
|
|
switch (section) {
|
|
|
|
case RemuxEntryColumn::State:
|
|
|
|
result = QString();
|
|
|
|
break;
|
|
|
|
case RemuxEntryColumn::InputPath:
|
|
|
|
result = QTStr("Remux.SourceFile");
|
|
|
|
break;
|
|
|
|
case RemuxEntryColumn::OutputPath:
|
|
|
|
result = QTStr("Remux.TargetFile");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags RemuxQueueModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
|
|
|
|
|
|
|
if (index.column() == RemuxEntryColumn::InputPath) {
|
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
} else if (index.column() == RemuxEntryColumn::OutputPath &&
|
2019-06-22 22:13:45 -07:00
|
|
|
index.row() != queue.length()) {
|
2018-01-15 16:26:49 -08:00
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemuxQueueModel::setData(const QModelIndex &index, const QVariant &value,
|
2019-06-22 22:13:45 -07:00
|
|
|
int role)
|
2018-01-15 16:26:49 -08:00
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
if (role == RemuxEntryRole::NewPathsToProcessRole) {
|
|
|
|
QStringList pathList = value.toStringList();
|
|
|
|
|
|
|
|
if (pathList.size() == 0) {
|
|
|
|
if (index.row() < queue.size()) {
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(),
|
|
|
|
index.row());
|
|
|
|
queue.removeAt(index.row());
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
} else {
|
2019-06-22 22:13:45 -07:00
|
|
|
if (pathList.size() > 1 &&
|
|
|
|
index.row() < queue.length()) {
|
2018-01-15 16:26:49 -08:00
|
|
|
queue[index.row()].sourcePath = pathList[0];
|
|
|
|
checkInputPath(index.row());
|
|
|
|
|
|
|
|
pathList.removeAt(0);
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pathList.size() > 0) {
|
|
|
|
int row = index.row();
|
|
|
|
int lastRow = row + pathList.size() - 1;
|
|
|
|
beginInsertRows(QModelIndex(), row, lastRow);
|
|
|
|
|
|
|
|
for (QString path : pathList) {
|
|
|
|
RemuxQueueEntry entry;
|
|
|
|
entry.sourcePath = path;
|
|
|
|
|
|
|
|
queue.insert(row, entry);
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
for (row = index.row(); row <= lastRow; row++) {
|
|
|
|
checkInputPath(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (index.row() == queue.length()) {
|
|
|
|
QString path = value.toString();
|
|
|
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
RemuxQueueEntry entry;
|
|
|
|
entry.sourcePath = path;
|
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), queue.length() + 1,
|
2019-06-22 22:13:45 -07:00
|
|
|
queue.length() + 1);
|
2018-01-15 16:26:49 -08:00
|
|
|
queue.append(entry);
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
checkInputPath(index.row());
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QString path = value.toString();
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
if (index.column() == RemuxEntryColumn::InputPath) {
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(),
|
|
|
|
index.row());
|
|
|
|
queue.removeAt(index.row());
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (index.column()) {
|
|
|
|
case RemuxEntryColumn::InputPath:
|
2019-06-22 22:13:45 -07:00
|
|
|
queue[index.row()].sourcePath =
|
|
|
|
value.toString();
|
2018-01-15 16:26:49 -08:00
|
|
|
checkInputPath(index.row());
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case RemuxEntryColumn::OutputPath:
|
2019-06-22 22:13:45 -07:00
|
|
|
queue[index.row()].targetPath =
|
|
|
|
value.toString();
|
2018-01-15 16:26:49 -08:00
|
|
|
emit dataChanged(index, index);
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RemuxQueueModel::getIcon(RemuxEntryState state)
|
|
|
|
{
|
|
|
|
QVariant icon;
|
|
|
|
QStyle *style = QApplication::style();
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case RemuxEntryState::Complete:
|
2019-06-22 22:13:45 -07:00
|
|
|
icon = style->standardIcon(QStyle::SP_DialogApplyButton);
|
2018-01-15 16:26:49 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RemuxEntryState::InProgress:
|
2019-06-22 22:13:45 -07:00
|
|
|
icon = style->standardIcon(QStyle::SP_ArrowRight);
|
2018-01-15 16:26:49 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RemuxEntryState::Error:
|
2019-06-22 22:13:45 -07:00
|
|
|
icon = style->standardIcon(QStyle::SP_DialogCancelButton);
|
2018-01-15 16:26:49 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RemuxEntryState::InvalidPath:
|
2019-06-22 22:13:45 -07:00
|
|
|
icon = style->standardIcon(QStyle::SP_MessageBoxWarning);
|
2018-01-15 16:26:49 -08:00
|
|
|
break;
|
2018-11-06 04:52:01 -08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::checkInputPath(int row)
|
|
|
|
{
|
|
|
|
RemuxQueueEntry &entry = queue[row];
|
|
|
|
|
|
|
|
if (entry.sourcePath.isEmpty()) {
|
|
|
|
entry.state = RemuxEntryState::Empty;
|
|
|
|
} else {
|
2019-12-29 17:58:03 -08:00
|
|
|
entry.sourcePath = QDir::toNativeSeparators(entry.sourcePath);
|
2018-01-15 16:26:49 -08:00
|
|
|
QFileInfo fileInfo(entry.sourcePath);
|
|
|
|
if (fileInfo.exists())
|
|
|
|
entry.state = RemuxEntryState::Ready;
|
|
|
|
else
|
|
|
|
entry.state = RemuxEntryState::InvalidPath;
|
|
|
|
|
|
|
|
if (entry.state == RemuxEntryState::Ready)
|
2019-12-29 17:58:03 -08:00
|
|
|
entry.targetPath = QDir::toNativeSeparators(
|
|
|
|
fileInfo.path() + QDir::separator() +
|
|
|
|
fileInfo.completeBaseName() + ".mp4");
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.state == RemuxEntryState::Ready && isProcessing)
|
|
|
|
entry.state = RemuxEntryState::Pending;
|
|
|
|
|
|
|
|
emit dataChanged(index(row, 0), index(row, RemuxEntryColumn::Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfoList RemuxQueueModel::checkForOverwrites() const
|
|
|
|
{
|
|
|
|
QFileInfoList list;
|
|
|
|
|
|
|
|
for (const RemuxQueueEntry &entry : queue) {
|
|
|
|
if (entry.state == RemuxEntryState::Ready) {
|
|
|
|
QFileInfo fileInfo(entry.targetPath);
|
|
|
|
if (fileInfo.exists()) {
|
|
|
|
list.append(fileInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemuxQueueModel::checkForErrors() const
|
|
|
|
{
|
|
|
|
bool hasErrors = false;
|
|
|
|
|
|
|
|
for (const RemuxQueueEntry &entry : queue) {
|
|
|
|
if (entry.state == RemuxEntryState::Error) {
|
|
|
|
hasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasErrors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::clearAll()
|
|
|
|
{
|
|
|
|
beginRemoveRows(QModelIndex(), 0, queue.size() - 1);
|
|
|
|
queue.clear();
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::clearFinished()
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
for (index = 0; index < queue.size(); index++) {
|
|
|
|
const RemuxQueueEntry &entry = queue[index];
|
|
|
|
if (entry.state == RemuxEntryState::Complete) {
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
queue.removeAt(index);
|
|
|
|
endRemoveRows();
|
|
|
|
index--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemuxQueueModel::canClearFinished() const
|
|
|
|
{
|
|
|
|
bool canClearFinished = false;
|
|
|
|
for (const RemuxQueueEntry &entry : queue)
|
|
|
|
if (entry.state == RemuxEntryState::Complete) {
|
|
|
|
canClearFinished = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return canClearFinished;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::beginProcessing()
|
|
|
|
{
|
|
|
|
for (RemuxQueueEntry &entry : queue)
|
|
|
|
if (entry.state == RemuxEntryState::Ready)
|
|
|
|
entry.state = RemuxEntryState::Pending;
|
|
|
|
|
|
|
|
// Signal that the insertion point no longer exists.
|
|
|
|
beginRemoveRows(QModelIndex(), queue.length(), queue.length());
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
|
|
isProcessing = true;
|
|
|
|
|
|
|
|
emit dataChanged(index(0, RemuxEntryColumn::State),
|
2019-06-22 22:13:45 -07:00
|
|
|
index(queue.length(), RemuxEntryColumn::State));
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::endProcessing()
|
|
|
|
{
|
|
|
|
for (RemuxQueueEntry &entry : queue) {
|
|
|
|
if (entry.state == RemuxEntryState::Pending) {
|
|
|
|
entry.state = RemuxEntryState::Ready;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal that the insertion point exists again.
|
2018-09-23 19:09:59 -07:00
|
|
|
|
|
|
|
if (!autoRemux) {
|
|
|
|
beginInsertRows(QModelIndex(), queue.length(), queue.length());
|
|
|
|
endInsertRows();
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
isProcessing = false;
|
|
|
|
|
|
|
|
emit dataChanged(index(0, RemuxEntryColumn::State),
|
2019-06-22 22:13:45 -07:00
|
|
|
index(queue.length(), RemuxEntryColumn::State));
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RemuxQueueModel::beginNextEntry(QString &inputPath, QString &outputPath)
|
|
|
|
{
|
|
|
|
bool anyStarted = false;
|
|
|
|
|
|
|
|
for (int row = 0; row < queue.length(); row++) {
|
|
|
|
RemuxQueueEntry &entry = queue[row];
|
|
|
|
if (entry.state == RemuxEntryState::Pending) {
|
|
|
|
entry.state = RemuxEntryState::InProgress;
|
|
|
|
|
|
|
|
inputPath = entry.sourcePath;
|
|
|
|
outputPath = entry.targetPath;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
QModelIndex index =
|
|
|
|
this->index(row, RemuxEntryColumn::State);
|
2018-01-15 16:26:49 -08:00
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
|
|
|
anyStarted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return anyStarted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemuxQueueModel::finishEntry(bool success)
|
|
|
|
{
|
|
|
|
for (int row = 0; row < queue.length(); row++) {
|
|
|
|
RemuxQueueEntry &entry = queue[row];
|
|
|
|
if (entry.state == RemuxEntryState::InProgress) {
|
|
|
|
if (success)
|
|
|
|
entry.state = RemuxEntryState::Complete;
|
|
|
|
else
|
|
|
|
entry.state = RemuxEntryState::Error;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
QModelIndex index =
|
|
|
|
this->index(row, RemuxEntryColumn::State);
|
2018-01-15 16:26:49 -08:00
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************
|
|
|
|
The actual remux window implementation
|
|
|
|
**********************************************************/
|
|
|
|
|
2017-05-08 04:53:35 -07:00
|
|
|
OBSRemux::OBSRemux(const char *path, QWidget *parent, bool autoRemux_)
|
2019-06-22 22:13:45 -07:00
|
|
|
: QDialog(parent),
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel(new RemuxQueueModel),
|
2019-06-22 22:13:45 -07:00
|
|
|
worker(new RemuxWorker()),
|
|
|
|
ui(new Ui::OBSRemux),
|
|
|
|
recPath(path),
|
|
|
|
autoRemux(autoRemux_)
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2018-09-18 17:00:01 -07:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
2014-09-02 19:11:55 -07:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->progressBar->setVisible(false);
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)
|
|
|
|
->setEnabled(false);
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2017-05-08 04:53:35 -07:00
|
|
|
if (autoRemux) {
|
|
|
|
resize(280, 40);
|
|
|
|
ui->tableView->hide();
|
|
|
|
ui->buttonBox->hide();
|
|
|
|
ui->label->hide();
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:11:55 -07:00
|
|
|
ui->progressBar->setMinimum(0);
|
|
|
|
ui->progressBar->setMaximum(1000);
|
|
|
|
ui->progressBar->setValue(0);
|
2014-11-01 13:48:58 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
ui->tableView->setModel(queueModel);
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->tableView->setItemDelegateForColumn(
|
|
|
|
RemuxEntryColumn::InputPath,
|
|
|
|
new RemuxEntryPathItemDelegate(false, recPath));
|
|
|
|
ui->tableView->setItemDelegateForColumn(
|
|
|
|
RemuxEntryColumn::OutputPath,
|
|
|
|
new RemuxEntryPathItemDelegate(true, recPath));
|
2018-01-15 16:26:49 -08:00
|
|
|
ui->tableView->horizontalHeader()->setSectionResizeMode(
|
2019-06-22 22:13:45 -07:00
|
|
|
QHeaderView::ResizeMode::Stretch);
|
2018-01-15 16:26:49 -08:00
|
|
|
ui->tableView->horizontalHeader()->setSectionResizeMode(
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryColumn::State, QHeaderView::ResizeMode::Fixed);
|
2018-01-15 16:26:49 -08:00
|
|
|
ui->tableView->setEditTriggers(
|
2019-06-22 22:13:45 -07:00
|
|
|
QAbstractItemView::EditTrigger::CurrentChanged);
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
installEventFilter(CreateShortcutFilter());
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
|
|
|
->setText(QTStr("Remux.Remux"));
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Reset)
|
|
|
|
->setText(QTStr("Remux.ClearFinished"));
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)
|
|
|
|
->setText(QTStr("Remux.ClearAll"));
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Reset)->setDisabled(true);
|
|
|
|
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
|
|
|
|
this, SLOT(beginRemux()));
|
2018-01-15 16:26:49 -08:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Reset),
|
2019-06-22 22:13:45 -07:00
|
|
|
SIGNAL(clicked()), this, SLOT(clearFinished()));
|
2018-01-15 16:26:49 -08:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults),
|
2019-06-22 22:13:45 -07:00
|
|
|
SIGNAL(clicked()), this, SLOT(clearAll()));
|
2017-04-09 06:11:35 -07:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Close),
|
2019-06-22 22:13:45 -07:00
|
|
|
SIGNAL(clicked()), this, SLOT(close()));
|
2017-04-09 06:11:35 -07:00
|
|
|
|
2014-09-02 19:11:55 -07:00
|
|
|
worker->moveToThread(&remuxer);
|
2014-10-13 11:09:44 -07:00
|
|
|
remuxer.start();
|
2014-09-02 19:11:55 -07:00
|
|
|
|
|
|
|
//gcc-4.8 can't use QPointer<RemuxWorker> below
|
|
|
|
RemuxWorker *worker_ = worker;
|
2019-06-22 22:13:45 -07:00
|
|
|
connect(worker_, &RemuxWorker::updateProgress, this,
|
|
|
|
&OBSRemux::updateProgress);
|
2014-09-02 19:11:55 -07:00
|
|
|
connect(&remuxer, &QThread::finished, worker_, &QObject::deleteLater);
|
2019-06-22 22:13:45 -07:00
|
|
|
connect(worker_, &RemuxWorker::remuxFinished, this,
|
|
|
|
&OBSRemux::remuxFinished);
|
2014-09-02 19:11:55 -07:00
|
|
|
connect(this, &OBSRemux::remux, worker_, &RemuxWorker::remux);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
// Guessing the GCC bug mentioned above would also affect
|
|
|
|
// QPointer<RemuxQueueModel>? Unsure.
|
|
|
|
RemuxQueueModel *queueModel_ = queueModel;
|
|
|
|
connect(queueModel_,
|
2019-06-22 22:13:45 -07:00
|
|
|
SIGNAL(rowsInserted(const QModelIndex &, int, int)), this,
|
|
|
|
SLOT(rowCountChanged(const QModelIndex &, int, int)));
|
|
|
|
connect(queueModel_, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
|
|
|
|
this, SLOT(rowCountChanged(const QModelIndex &, int, int)));
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
QModelIndex index = queueModel->createIndex(0, 1);
|
2019-06-22 22:13:45 -07:00
|
|
|
QMetaObject::invokeMethod(ui->tableView, "setCurrentIndex",
|
|
|
|
Qt::QueuedConnection,
|
|
|
|
Q_ARG(const QModelIndex &, index));
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
bool OBSRemux::stopRemux()
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
if (!worker->isWorking)
|
2014-09-02 19:11:55 -07:00
|
|
|
return true;
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
// By locking the worker thread's mutex, we ensure that its
|
|
|
|
// update poll will be blocked as long as we're in here with
|
|
|
|
// the popup open.
|
|
|
|
QMutexLocker lock(&worker->updateMutex);
|
|
|
|
|
|
|
|
bool exit = false;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
if (QMessageBox::critical(nullptr, QTStr("Remux.ExitUnfinishedTitle"),
|
|
|
|
QTStr("Remux.ExitUnfinished"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::No) == QMessageBox::Yes) {
|
2018-01-15 16:26:49 -08:00
|
|
|
exit = true;
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
if (exit) {
|
|
|
|
// Inform the worker it should no longer be
|
|
|
|
// working. It will interrupt accordingly in
|
|
|
|
// its next update callback.
|
|
|
|
worker->isWorking = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exit;
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
OBSRemux::~OBSRemux()
|
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
stopRemux();
|
2014-09-02 19:11:55 -07:00
|
|
|
remuxer.quit();
|
|
|
|
remuxer.wait();
|
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::rowCountChanged(const QModelIndex &, int, int)
|
|
|
|
{
|
|
|
|
// See if there are still any rows ready to remux. Change
|
|
|
|
// the state of the "go" button accordingly.
|
|
|
|
// There must be more than one row, since there will always be
|
|
|
|
// at least one row for the empty insertion point.
|
|
|
|
if (queueModel->rowCount() > 1) {
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)
|
|
|
|
->setEnabled(true);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Reset)
|
|
|
|
->setEnabled(queueModel->canClearFinished());
|
2018-01-15 16:26:49 -08:00
|
|
|
} else {
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)
|
|
|
|
->setEnabled(false);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Reset)
|
|
|
|
->setEnabled(false);
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
}
|
2016-05-09 14:14:43 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::dropEvent(QDropEvent *ev)
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
QStringList urlList;
|
|
|
|
|
|
|
|
for (QUrl url : ev->mimeData()->urls()) {
|
|
|
|
QFileInfo fileInfo(url.toLocalFile());
|
|
|
|
|
|
|
|
if (fileInfo.isDir()) {
|
|
|
|
QStringList directoryFilter;
|
2019-06-22 22:13:45 -07:00
|
|
|
directoryFilter << "*.flv"
|
|
|
|
<< "*.mp4"
|
|
|
|
<< "*.mov"
|
|
|
|
<< "*.mkv"
|
|
|
|
<< "*.ts"
|
|
|
|
<< "*.m3u8";
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
QDirIterator dirIter(fileInfo.absoluteFilePath(),
|
2019-06-22 22:13:45 -07:00
|
|
|
directoryFilter, QDir::Files,
|
|
|
|
QDirIterator::Subdirectories);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
while (dirIter.hasNext()) {
|
|
|
|
urlList.append(dirIter.next());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
urlList.append(fileInfo.canonicalFilePath());
|
|
|
|
}
|
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
if (urlList.empty()) {
|
|
|
|
QMessageBox::information(nullptr,
|
2019-06-22 22:13:45 -07:00
|
|
|
QTStr("Remux.NoFilesAddedTitle"),
|
|
|
|
QTStr("Remux.NoFilesAdded"),
|
|
|
|
QMessageBox::Ok);
|
2018-09-23 19:09:59 -07:00
|
|
|
} else if (!autoRemux) {
|
2019-06-22 22:13:45 -07:00
|
|
|
QModelIndex insertIndex =
|
|
|
|
queueModel->index(queueModel->rowCount() - 1,
|
|
|
|
RemuxEntryColumn::InputPath);
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel->setData(insertIndex, urlList,
|
2019-06-22 22:13:45 -07:00
|
|
|
RemuxEntryRole::NewPathsToProcessRole);
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::dragEnterEvent(QDragEnterEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasUrls() && !worker->isWorking)
|
|
|
|
ev->accept();
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::beginRemux()
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
if (worker->isWorking) {
|
|
|
|
stopRemux();
|
2014-09-02 19:11:55 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
bool proceedWithRemux = true;
|
|
|
|
QFileInfoList overwriteFiles = queueModel->checkForOverwrites();
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
if (!overwriteFiles.empty()) {
|
|
|
|
QString message = QTStr("Remux.FileExists");
|
|
|
|
message += "\n\n";
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
for (QFileInfo fileInfo : overwriteFiles)
|
|
|
|
message += fileInfo.canonicalFilePath() + "\n";
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
if (OBSMessageBox::question(this,
|
2019-06-22 22:13:45 -07:00
|
|
|
QTStr("Remux.FileExistsTitle"),
|
|
|
|
message) != QMessageBox::Yes)
|
2018-01-15 16:26:49 -08:00
|
|
|
proceedWithRemux = false;
|
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
if (!proceedWithRemux)
|
2014-09-02 19:11:55 -07:00
|
|
|
return;
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
// Set all jobs to "pending" first.
|
|
|
|
queueModel->beginProcessing();
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
ui->progressBar->setVisible(true);
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
|
|
|
->setText(QTStr("Remux.Stop"));
|
2018-01-15 16:26:49 -08:00
|
|
|
setAcceptDrops(false);
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
remuxNextEntry();
|
2017-05-08 04:53:35 -07:00
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2017-05-08 04:53:35 -07:00
|
|
|
void OBSRemux::AutoRemux(QString inFile, QString outFile)
|
|
|
|
{
|
|
|
|
if (inFile != "" && outFile != "" && autoRemux) {
|
|
|
|
emit remux(inFile, outFile);
|
|
|
|
autoRemuxFile = inFile;
|
|
|
|
}
|
2018-01-15 16:26:49 -08:00
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::remuxNextEntry()
|
|
|
|
{
|
2014-09-02 19:11:55 -07:00
|
|
|
worker->lastProgress = 0.f;
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
QString inputPath, outputPath;
|
|
|
|
if (queueModel->beginNextEntry(inputPath, outputPath)) {
|
|
|
|
emit remux(inputPath, outputPath);
|
|
|
|
} else {
|
2018-09-23 19:09:59 -07:00
|
|
|
queueModel->autoRemux = autoRemux;
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel->endProcessing();
|
|
|
|
|
2017-05-08 04:53:35 -07:00
|
|
|
if (!autoRemux) {
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSMessageBox::information(
|
|
|
|
this, QTStr("Remux.FinishedTitle"),
|
|
|
|
queueModel->checkForErrors()
|
2017-05-08 04:53:35 -07:00
|
|
|
? QTStr("Remux.FinishedError")
|
|
|
|
: QTStr("Remux.Finished"));
|
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2017-05-08 04:53:35 -07:00
|
|
|
ui->progressBar->setVisible(autoRemux);
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)
|
|
|
|
->setText(QTStr("Remux.Remux"));
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)
|
|
|
|
->setEnabled(true);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Reset)
|
|
|
|
->setEnabled(queueModel->canClearFinished());
|
2018-01-15 16:26:49 -08:00
|
|
|
setAcceptDrops(true);
|
|
|
|
}
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSRemux::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
if (!stopRemux())
|
2014-09-02 19:11:55 -07:00
|
|
|
event->ignore();
|
|
|
|
else
|
|
|
|
QDialog::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSRemux::reject()
|
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
if (!stopRemux())
|
2014-09-02 19:11:55 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSRemux::updateProgress(float percent)
|
|
|
|
{
|
|
|
|
ui->progressBar->setValue(percent * 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSRemux::remuxFinished(bool success)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
2017-05-08 04:53:35 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel->finishEntry(success);
|
2017-05-08 04:53:35 -07:00
|
|
|
|
|
|
|
if (autoRemux && autoRemuxFile != "") {
|
|
|
|
QTimer::singleShot(3000, this, SLOT(close()));
|
2021-02-04 04:01:35 -08:00
|
|
|
|
|
|
|
OBSBasic *main = OBSBasic::Get();
|
|
|
|
main->ShowStatusBarMessage(
|
|
|
|
QTStr("Basic.StatusBar.AutoRemuxedTo")
|
|
|
|
.arg(autoRemuxFile));
|
2017-05-08 04:53:35 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
remuxNextEntry();
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::clearFinished()
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel->clearFinished();
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void OBSRemux::clearAll()
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
queueModel->clearAll();
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
/**********************************************************
|
|
|
|
Worker thread - Executes the libobs remux operation as a
|
|
|
|
background process.
|
|
|
|
**********************************************************/
|
|
|
|
|
2014-09-02 19:11:55 -07:00
|
|
|
void RemuxWorker::UpdateProgress(float percent)
|
|
|
|
{
|
|
|
|
if (abs(lastProgress - percent) < 0.1f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit updateProgress(percent);
|
|
|
|
lastProgress = percent;
|
|
|
|
}
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
void RemuxWorker::remux(const QString &source, const QString &target)
|
2014-09-02 19:11:55 -07:00
|
|
|
{
|
2018-01-15 16:26:49 -08:00
|
|
|
isWorking = true;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto callback = [](void *data, float percent) {
|
|
|
|
RemuxWorker *rw = static_cast<RemuxWorker *>(data);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
QMutexLocker lock(&rw->updateMutex);
|
|
|
|
|
2014-09-02 19:11:55 -07:00
|
|
|
rw->UpdateProgress(percent);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
return rw->isWorking;
|
2014-09-02 19:11:55 -07:00
|
|
|
};
|
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
bool stopped = false;
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
media_remux_job_t mr_job = nullptr;
|
2019-06-22 22:13:45 -07:00
|
|
|
if (media_remux_job_create(&mr_job, QT_TO_UTF8(source),
|
|
|
|
QT_TO_UTF8(target))) {
|
2018-01-15 16:26:49 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
success = media_remux_job_process(mr_job, callback, this);
|
2018-01-15 16:26:49 -08:00
|
|
|
|
|
|
|
media_remux_job_destroy(mr_job);
|
|
|
|
|
|
|
|
stopped = !isWorking;
|
|
|
|
}
|
|
|
|
|
|
|
|
isWorking = false;
|
2014-09-02 19:11:55 -07:00
|
|
|
|
2018-01-15 16:26:49 -08:00
|
|
|
emit remuxFinished(!stopped && success);
|
2014-09-02 19:11:55 -07:00
|
|
|
}
|