window-remux.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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),
  75. isProcessing(false)
  76. {
  77. }
  78. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  79. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  80. QVariant data(const QModelIndex &index, int role) const;
  81. QVariant headerData(int section, Qt::Orientation orientation,
  82. int role = Qt::DisplayRole) const;
  83. Qt::ItemFlags flags(const QModelIndex &index) const;
  84. bool setData(const QModelIndex &index, const QVariant &value, 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. RemuxEntryState state;
  98. QString sourcePath;
  99. QString targetPath;
  100. };
  101. QList<RemuxQueueEntry> queue;
  102. bool isProcessing;
  103. static QVariant getIcon(RemuxEntryState state);
  104. void checkInputPath(int row);
  105. };
  106. class RemuxWorker : public QObject {
  107. Q_OBJECT
  108. QMutex updateMutex;
  109. bool isWorking;
  110. float lastProgress;
  111. void UpdateProgress(float percent);
  112. explicit RemuxWorker() : isWorking(false) {}
  113. virtual ~RemuxWorker(){};
  114. private slots:
  115. void remux(const QString &source, const QString &target);
  116. signals:
  117. void updateProgress(float percent);
  118. void remuxFinished(bool success);
  119. friend class OBSRemux;
  120. };
  121. class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
  122. Q_OBJECT
  123. public:
  124. RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath);
  125. virtual QWidget *createEditor(QWidget *parent,
  126. const QStyleOptionViewItem & /* option */,
  127. const QModelIndex &index) const override;
  128. virtual void setEditorData(QWidget *editor,
  129. const QModelIndex &index) const override;
  130. virtual void setModelData(QWidget *editor, QAbstractItemModel *model,
  131. const QModelIndex &index) const override;
  132. virtual void paint(QPainter *painter,
  133. const QStyleOptionViewItem &option,
  134. const QModelIndex &index) const override;
  135. private:
  136. bool isOutput;
  137. QString defaultPath;
  138. const char *PATH_LIST_PROP = "pathList";
  139. void handleBrowse(QWidget *container);
  140. void handleClear(QWidget *container);
  141. private slots:
  142. void updateText();
  143. };