2016-02-23 23:16:51 +00: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/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMutex>
|
2016-02-23 23:16:51 +00:00
|
|
|
#include <QPointer>
|
|
|
|
#include <QThread>
|
2019-07-27 12:47:10 +00:00
|
|
|
#include <QStyledItemDelegate>
|
2016-02-23 23:16:51 +00:00
|
|
|
#include <memory>
|
|
|
|
#include "ui_OBSRemux.h"
|
|
|
|
|
|
|
|
#include <media-io/media-remux.h>
|
|
|
|
#include <util/threading.h>
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
class RemuxQueueModel;
|
2016-02-23 23:16:51 +00:00
|
|
|
class RemuxWorker;
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
enum RemuxEntryState
|
|
|
|
{
|
|
|
|
Empty,
|
|
|
|
Ready,
|
|
|
|
Pending,
|
|
|
|
InProgress,
|
|
|
|
Complete,
|
|
|
|
InvalidPath,
|
|
|
|
Error
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(RemuxEntryState);
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
class OBSRemux : public QDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
QPointer<RemuxQueueModel> queueModel;
|
2016-02-23 23:16:51 +00:00
|
|
|
QThread remuxer;
|
|
|
|
QPointer<RemuxWorker> worker;
|
|
|
|
|
|
|
|
std::unique_ptr<Ui::OBSRemux> ui;
|
|
|
|
|
|
|
|
const char *recPath;
|
|
|
|
|
|
|
|
virtual void closeEvent(QCloseEvent *event) override;
|
|
|
|
virtual void reject() override;
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
bool autoRemux;
|
|
|
|
QString autoRemuxFile;
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
public:
|
2019-07-27 12:47:10 +00:00
|
|
|
explicit OBSRemux(const char *recPath, QWidget *parent = nullptr,
|
|
|
|
bool autoRemux = false);
|
2016-02-23 23:16:51 +00:00
|
|
|
virtual ~OBSRemux() override;
|
|
|
|
|
|
|
|
using job_t = std::shared_ptr<struct media_remux_job>;
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
void AutoRemux(QString inFile, QString outFile);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void dropEvent(QDropEvent *ev);
|
|
|
|
void dragEnterEvent(QDragEnterEvent *ev);
|
|
|
|
|
|
|
|
void remuxNextEntry();
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
private slots:
|
2019-07-27 12:47:10 +00:00
|
|
|
void rowCountChanged(const QModelIndex &parent, int first, int last);
|
2016-02-23 23:16:51 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void updateProgress(float percent);
|
|
|
|
void remuxFinished(bool success);
|
2019-07-27 12:47:10 +00:00
|
|
|
void beginRemux();
|
|
|
|
bool stopRemux();
|
|
|
|
void clearFinished();
|
|
|
|
void clearAll();
|
2016-02-23 23:16:51 +00:00
|
|
|
|
|
|
|
signals:
|
2019-07-27 12:47:10 +00:00
|
|
|
void remux(const QString &source, const QString &target);
|
|
|
|
};
|
|
|
|
|
|
|
|
class RemuxQueueModel : public QAbstractTableModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
friend class OBSRemux;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RemuxQueueModel(QObject *parent = 0)
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
, isProcessing(false) {}
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
|
|
|
int role = Qt::DisplayRole) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value,
|
|
|
|
int role);
|
|
|
|
|
|
|
|
QFileInfoList checkForOverwrites() const;
|
|
|
|
bool checkForErrors() const;
|
|
|
|
void beginProcessing();
|
|
|
|
void endProcessing();
|
|
|
|
bool beginNextEntry(QString &inputPath, QString &outputPath);
|
|
|
|
void finishEntry(bool success);
|
|
|
|
bool canClearFinished() const;
|
|
|
|
void clearFinished();
|
|
|
|
void clearAll();
|
|
|
|
|
|
|
|
bool autoRemux = false;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct RemuxQueueEntry
|
|
|
|
{
|
|
|
|
RemuxEntryState state;
|
|
|
|
|
|
|
|
QString sourcePath;
|
|
|
|
QString targetPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
QList<RemuxQueueEntry> queue;
|
|
|
|
bool isProcessing;
|
|
|
|
|
|
|
|
static QVariant getIcon(RemuxEntryState state);
|
|
|
|
|
|
|
|
void checkInputPath(int row);
|
2016-02-23 23:16:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RemuxWorker : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
QMutex updateMutex;
|
|
|
|
|
|
|
|
bool isWorking;
|
2016-02-23 23:16:51 +00:00
|
|
|
|
|
|
|
float lastProgress;
|
|
|
|
void UpdateProgress(float percent);
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
explicit RemuxWorker()
|
|
|
|
: isWorking(false) { }
|
|
|
|
virtual ~RemuxWorker() {};
|
2016-02-23 23:16:51 +00:00
|
|
|
|
|
|
|
private slots:
|
2019-07-27 12:47:10 +00:00
|
|
|
void remux(const QString &source, const QString &target);
|
2016-02-23 23:16:51 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void updateProgress(float percent);
|
|
|
|
void remuxFinished(bool success);
|
|
|
|
|
|
|
|
friend class OBSRemux;
|
|
|
|
};
|
2019-07-27 12:47:10 +00:00
|
|
|
|
|
|
|
class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath);
|
|
|
|
|
|
|
|
virtual QWidget *createEditor(QWidget *parent,
|
|
|
|
const QStyleOptionViewItem & /* option */,
|
|
|
|
const QModelIndex &index) const override;
|
|
|
|
|
|
|
|
virtual void setEditorData(QWidget *editor, const QModelIndex &index)
|
|
|
|
const override;
|
|
|
|
virtual void setModelData(QWidget *editor,
|
|
|
|
QAbstractItemModel *model,
|
|
|
|
const QModelIndex &index) const override;
|
|
|
|
virtual void paint(QPainter *painter,
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool isOutput;
|
|
|
|
QString defaultPath;
|
|
|
|
const char *PATH_LIST_PROP = "pathList";
|
|
|
|
|
|
|
|
void handleBrowse(QWidget *container);
|
|
|
|
void handleClear(QWidget *container);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateText();
|
|
|
|
};
|