CuteLogger
Fast and simple logging solution for Qt based applications
mltcontroller.h
1 /*
2  * Copyright (c) 2011-2020 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MLTCONTROLLER_H
19 #define MLTCONTROLLER_H
20 
21 #include <QImage>
22 #include <QString>
23 #include <QUuid>
24 #include <QScopedPointer>
25 #include <QTemporaryFile>
26 #include <QMutex>
27 #include <Mlt.h>
28 #include "transportcontrol.h"
29 
30 // forward declarations
31 class QQuickView;
32 
33 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
34 # define MLT_LC_CATEGORY LC_NUMERIC
35 # define MLT_LC_NAME "LC_NUMERIC"
36 #else
37 # define MLT_LC_CATEGORY LC_ALL
38 # define MLT_LC_NAME "LC_ALL"
39 #endif
40 
41 namespace Mlt {
42 
43 const int kMaxImageDurationSecs = 3600 * 4;
44 extern const QString XmlMimeType;
45 
46 class TransportControl : public TransportControllable
47 {
48  Q_OBJECT
49 public slots:
50  void play(double speed = 1.0) override;
51  void pause() override;
52  void stop() override;
53  void seek(int position) override;
54  void rewind(bool forceChangeDirection) override;
55  void fastForward(bool forceChangeDirection) override;
56  void previous(int currentPosition) override;
57  void next(int currentPosition) override;
58  void setIn(int) override;
59  void setOut(int) override;
60 };
61 
62 class Controller
63 {
64 protected:
65  Controller();
66  virtual int reconfigure(bool isMulti) = 0;
67 
68 public:
69  static Controller& singleton(QObject *parent = nullptr);
70  virtual ~Controller();
71  static void destroy();
72 
73  virtual QObject* videoWidget() = 0;
74  virtual int setProducer(Mlt::Producer*, bool isMulti = false);
75  virtual int open(const QString& url, const QString& urlToSave);
76  bool openXML(const QString& filename);
77  virtual void close();
78  virtual int displayWidth() const = 0;
79  virtual int displayHeight() const = 0;
80 
81  void closeConsumer();
82  virtual void play(double speed = 1.0);
83  bool isPaused() const;
84  virtual void pause();
85  void stop();
86  bool enableJack(bool enable = true);
87  void setVolume(double volume, bool muteOnPause = true);
88  double volume() const;
89  void onWindowResize();
90  virtual void seek(int position);
91  virtual void refreshConsumer(bool scrubAudio = false);
92  bool saveXML(const QString& filename, Service* service = nullptr, bool withRelativePaths = true,
93  QTemporaryFile* tempFile = nullptr, bool proxy = false);
94  QString XML(Service* service = nullptr, bool withProfile = false, bool withMetadata = false);
95  int consumerChanged();
96  void setProfile(const QString& profile_name);
97  void setAudioChannels(int audioChannels);
98  QString resource() const;
99  bool isSeekable(Mlt::Producer* p = nullptr) const;
100  bool isClip() const;
101  bool isSeekableClip();
102  bool isPlaylist() const;
103  bool isMultitrack() const;
104  bool isImageProducer(Service* service) const;
105  bool isFileProducer(Service* service) const;
106  void rewind(bool forceChangeDirection);
107  void fastForward(bool forceChangeDirection);
108  void previous(int currentPosition);
109  void next(int currentPosition);
110  void setIn(int);
111  void setOut(int);
112  void restart(const QString& xml = "");
113  void resetURL();
114  QImage image(Frame *frame, int width, int height);
115  QImage image(Mlt::Producer& producer, int frameNumber, int width, int height);
116  void updateAvformatCaching(int trackCount);
117  bool isAudioFilter(const QString& name);
118  int realTime() const;
119  void setImageDurationFromDefault(Service* service) const;
120  void setDurationFromDefault(Producer* service) const;
121  void lockCreationTime(Producer* producer) const;
122  QUuid uuid(Mlt::Properties &properties) const;
123  void setUuid(Mlt::Properties &properties, QUuid uid) const;
124  QUuid ensureHasUuid(Mlt::Properties& properties) const;
125  static void copyFilters(Mlt::Producer& fromProducer, Mlt::Producer& toProducer, bool fromClipboard = false);
126  void copyFilters(Mlt::Producer* producer = nullptr);
127  void pasteFilters(Mlt::Producer* producer = nullptr);
128  static void adjustFilters(Mlt::Producer& producer, int startIndex = 0);
129  bool hasFiltersOnClipboard() const {
130  return m_filtersClipboard->is_valid() && m_filtersClipboard->filter_count() > 0;
131  }
132 
133  int audioChannels() const {
134  return m_audioChannels;
135  }
136  Mlt::Repository* repository() const {
137  return m_repo;
138  }
139  Mlt::Profile& profile() {
140  return m_profile;
141  }
142  Mlt::Profile& previewProfile() {
143  return m_previewProfile;
144  }
145  Mlt::Producer* producer() const {
146  return m_producer.data();
147  }
148  Mlt::Consumer* consumer() const {
149  return m_consumer.data();
150  }
151  const QString& URL() const {
152  return m_url;
153  }
154  const TransportControllable* transportControl() const {
155  return &m_transportControl;
156  }
157  Mlt::Producer* savedProducer() const {
158  return m_savedProducer.data();
159  }
160  void setSavedProducer(Mlt::Producer* producer);
161  static Mlt::Filter* getFilter(const QString& name, Mlt::Service* service);
162  QString projectFolder() const { return m_projectFolder; }
163  void setProjectFolder(const QString& folderName);
164  QChar decimalPoint();
165  static void resetLocale();
166  static int filterIn(Mlt::Playlist&playlist, int clipIndex);
167  static int filterOut(Mlt::Playlist&playlist, int clipIndex);
168  void setPreviewScale(int scale);
169  void updatePreviewProfile();
170  static void purgeMemoryPool();
171  static bool fullRange(Mlt::Producer& producer);
172 
173 protected:
174  Mlt::Repository* m_repo;
175  QScopedPointer<Mlt::Producer> m_producer;
176  QScopedPointer<Mlt::FilteredConsumer> m_consumer;
177 
178 private:
179  Mlt::Profile m_profile;
180  Mlt::Profile m_previewProfile;
181  int m_audioChannels{2};
182  QScopedPointer<Mlt::Filter> m_jackFilter;
183  QString m_url;
184  double m_volume{1.0};
185  TransportControl m_transportControl;
186  QScopedPointer<Mlt::Producer> m_savedProducer;
187  QScopedPointer<Mlt::Producer> m_filtersClipboard;
188  unsigned m_skipJackEvents{0};
189  QString m_projectFolder;
190  QMutex m_saveXmlMutex;
191 
192  static void on_jack_started(mlt_properties owner, void* object, const mlt_position *position);
193  void onJackStarted(int position);
194  static void on_jack_stopped(mlt_properties owner, void* object, const mlt_position *position);
195  void onJackStopped(int position);
196  void stopJack();
197 };
198 
199 } // namespace
200 
201 #define MLT Mlt::Controller::singleton()
202 
203 #endif // MLTCONTROLLER_H