window-remux.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /******************************************************************************
  2. Copyright (C) 2014 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QFileInfo>
  16. #include <QMutex>
  17. #include <QPointer>
  18. #include <QThread>
  19. #include <QStyledItemDelegate>
  20. #include <memory>
  21. #include "ui_OBSRemux.h"
  22. #include <media-io/media-remux.h>
  23. #include <util/threading.h>
  24. class RemuxQueueModel;
  25. class RemuxWorker;
  26. enum RemuxEntryState {
  27. Empty,
  28. Ready,
  29. Pending,
  30. InProgress,
  31. Complete,
  32. InvalidPath,
  33. Error
  34. };
  35. Q_DECLARE_METATYPE(RemuxEntryState);
  36. class OBSRemux : public QDialog {
  37. Q_OBJECT
  38. QPointer<RemuxQueueModel> queueModel;
  39. QThread remuxer;
  40. QPointer<RemuxWorker> worker;
  41. std::unique_ptr<Ui::OBSRemux> ui;
  42. const char *recPath;
  43. virtual void closeEvent(QCloseEvent *event) override;
  44. virtual void reject() override;
  45. bool autoRemux;
  46. QString autoRemuxFile;
  47. public:
  48. explicit OBSRemux(const char *recPath, QWidget *parent = nullptr,
  49. bool autoRemux = false);
  50. virtual ~OBSRemux() override;
  51. using job_t = std::shared_ptr<struct media_remux_job>;
  52. void AutoRemux(QString inFile, QString outFile);
  53. protected:
  54. virtual void dropEvent(QDropEvent *ev) override;
  55. virtual void dragEnterEvent(QDragEnterEvent *ev) override;
  56. void remuxNextEntry();
  57. private slots:
  58. void rowCountChanged(const QModelIndex &parent, int first, int last);
  59. public slots:
  60. void updateProgress(float percent);
  61. void remuxFinished(bool success);
  62. void beginRemux();
  63. bool stopRemux();
  64. void clearFinished();
  65. void clearAll();
  66. signals:
  67. void remux(const QString &source, const QString &target);
  68. };
  69. class RemuxQueueModel : public QAbstractTableModel {
  70. Q_OBJECT
  71. friend class OBSRemux;
  72. public:
  73. RemuxQueueModel(QObject *parent = 0)
  74. : QAbstractTableModel(parent), isProcessing(false)
  75. {
  76. }
  77. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  78. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  79. QVariant data(const QModelIndex &index, int role) const;
  80. QVariant headerData(int section, Qt::Orientation orientation,
  81. int role = Qt::DisplayRole) const;
  82. Qt::ItemFlags flags(const QModelIndex &index) const;
  83. bool setData(const QModelIndex &index, const QVariant &value, int role);
  84. QFileInfoList checkForOverwrites() const;
  85. bool checkForErrors() const;
  86. void beginProcessing();
  87. void endProcessing();
  88. bool beginNextEntry(QString &inputPath, QString &outputPath);
  89. void finishEntry(bool success);
  90. bool canClearFinished() const;
  91. void clearFinished();
  92. void clearAll();
  93. bool autoRemux = false;
  94. private:
  95. struct RemuxQueueEntry {
  96. RemuxEntryState state;
  97. QString sourcePath;
  98. QString targetPath;
  99. };
  100. QList<RemuxQueueEntry> queue;
  101. bool isProcessing;
  102. static QVariant getIcon(RemuxEntryState state);
  103. void checkInputPath(int row);
  104. };
  105. class RemuxWorker : public QObject {
  106. Q_OBJECT
  107. QMutex updateMutex;
  108. bool isWorking;
  109. float lastProgress;
  110. void UpdateProgress(float percent);
  111. explicit RemuxWorker() : isWorking(false) {}
  112. virtual ~RemuxWorker(){};
  113. private slots:
  114. void remux(const QString &source, const QString &target);
  115. signals:
  116. void updateProgress(float percent);
  117. void remuxFinished(bool success);
  118. friend class OBSRemux;
  119. };
  120. class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
  121. Q_OBJECT
  122. public:
  123. RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath);
  124. virtual QWidget *createEditor(QWidget *parent,
  125. const QStyleOptionViewItem & /* option */,
  126. const QModelIndex &index) const override;
  127. virtual void setEditorData(QWidget *editor,
  128. const QModelIndex &index) const override;
  129. virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
  130. const QModelIndex &index) const override;
  131. virtual void paint(QPainter *painter,
  132. const QStyleOptionViewItem &option,
  133. const QModelIndex &index) const override;
  134. private:
  135. bool isOutput;
  136. QString defaultPath;
  137. const char *PATH_LIST_PROP = "pathList";
  138. void handleBrowse(QWidget *container);
  139. void handleClear(QWidget *container);
  140. private slots:
  141. void updateText();
  142. };