window-remux.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. {
  28. Empty,
  29. Ready,
  30. Pending,
  31. InProgress,
  32. Complete,
  33. InvalidPath,
  34. Error
  35. };
  36. Q_DECLARE_METATYPE(RemuxEntryState);
  37. class OBSRemux : public QDialog {
  38. Q_OBJECT
  39. QPointer<RemuxQueueModel> queueModel;
  40. QThread remuxer;
  41. QPointer<RemuxWorker> worker;
  42. std::unique_ptr<Ui::OBSRemux> ui;
  43. const char *recPath;
  44. virtual void closeEvent(QCloseEvent *event) override;
  45. virtual void reject() override;
  46. bool autoRemux;
  47. QString autoRemuxFile;
  48. public:
  49. explicit OBSRemux(const char *recPath, QWidget *parent = nullptr,
  50. bool autoRemux = false);
  51. virtual ~OBSRemux() override;
  52. using job_t = std::shared_ptr<struct media_remux_job>;
  53. void AutoRemux(QString inFile, QString outFile);
  54. protected:
  55. void dropEvent(QDropEvent *ev);
  56. void dragEnterEvent(QDragEnterEvent *ev);
  57. void remuxNextEntry();
  58. private slots:
  59. void rowCountChanged(const QModelIndex &parent, int first, int last);
  60. public slots:
  61. void updateProgress(float percent);
  62. void remuxFinished(bool success);
  63. void beginRemux();
  64. bool stopRemux();
  65. void clearFinished();
  66. void clearAll();
  67. signals:
  68. void remux(const QString &source, const QString &target);
  69. };
  70. class RemuxQueueModel : public QAbstractTableModel {
  71. Q_OBJECT
  72. friend class OBSRemux;
  73. public:
  74. RemuxQueueModel(QObject *parent = 0)
  75. : QAbstractTableModel(parent)
  76. , isProcessing(false) {}
  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,
  84. int role);
  85. QFileInfoList checkForOverwrites() const;
  86. bool checkForErrors() const;
  87. void beginProcessing();
  88. void endProcessing();
  89. bool beginNextEntry(QString &inputPath, QString &outputPath);
  90. void finishEntry(bool success);
  91. bool canClearFinished() const;
  92. void clearFinished();
  93. void clearAll();
  94. bool autoRemux = false;
  95. private:
  96. struct RemuxQueueEntry
  97. {
  98. RemuxEntryState state;
  99. QString sourcePath;
  100. QString targetPath;
  101. };
  102. QList<RemuxQueueEntry> queue;
  103. bool isProcessing;
  104. static QVariant getIcon(RemuxEntryState state);
  105. void checkInputPath(int row);
  106. };
  107. class RemuxWorker : public QObject {
  108. Q_OBJECT
  109. QMutex updateMutex;
  110. bool isWorking;
  111. float lastProgress;
  112. void UpdateProgress(float percent);
  113. explicit RemuxWorker()
  114. : isWorking(false) { }
  115. virtual ~RemuxWorker() {};
  116. private slots:
  117. void remux(const QString &source, const QString &target);
  118. signals:
  119. void updateProgress(float percent);
  120. void remuxFinished(bool success);
  121. friend class OBSRemux;
  122. };
  123. class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
  124. Q_OBJECT
  125. public:
  126. RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath);
  127. virtual QWidget *createEditor(QWidget *parent,
  128. const QStyleOptionViewItem & /* option */,
  129. const QModelIndex &index) const override;
  130. virtual void setEditorData(QWidget *editor, const QModelIndex &index)
  131. const override;
  132. virtual void setModelData(QWidget *editor,
  133. QAbstractItemModel *model,
  134. const QModelIndex &index) const override;
  135. virtual void paint(QPainter *painter,
  136. const QStyleOptionViewItem &option,
  137. const QModelIndex &index) const override;
  138. private:
  139. bool isOutput;
  140. QString defaultPath;
  141. const char *PATH_LIST_PROP = "pathList";
  142. void handleBrowse(QWidget *container);
  143. void handleClear(QWidget *container);
  144. private slots:
  145. void updateText();
  146. };