CuteLogger
Fast and simple logging solution for Qt based applications
mltcontroller.h
1/*
2 * Copyright (c) 2011-2023 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
31class QQuickView;
32
33#define MLT_LC_CATEGORY LC_ALL
34#define MLT_LC_NAME "LC_ALL"
35
36#if LIBMLT_VERSION_INT >= ((7<<16)+(19<<8))
37#define kAudioIndexProperty "astream"
38#define kVideoIndexProperty "vstream"
39#else
40#define kAudioIndexProperty "audio_index"
41#define kVideoIndexProperty "video_index"
42#endif
43
44namespace Mlt {
45
46const int kMaxImageDurationSecs = 3600 * 4;
47extern const QString XmlMimeType;
48
49class TransportControl : public TransportControllable
50{
51 Q_OBJECT
52public slots:
53 void play(double speed = 1.0) override;
54 void pause() override;
55 void stop() override;
56 void seek(int position) override;
57 void rewind(bool forceChangeDirection) override;
58 void fastForward(bool forceChangeDirection) override;
59 void previous(int currentPosition) override;
60 void next(int currentPosition) override;
61 void setIn(int) override;
62 void setOut(int) override;
63};
64
65class Controller
66{
67protected:
68 Controller();
69 virtual int reconfigure(bool isMulti) = 0;
70
71public:
72 static Controller &singleton(QObject *parent = nullptr);
73 virtual ~Controller();
74 static void destroy();
75
76 virtual QObject *videoWidget() = 0;
77 virtual int setProducer(Mlt::Producer *, bool isMulti = false);
78 virtual int open(const QString &url, const QString &urlToSave, bool skipConvert = false);
79 bool openXML(const QString &filename);
80 virtual void close();
81 virtual int displayWidth() const = 0;
82 virtual int displayHeight() const = 0;
83
84 void closeConsumer();
85 virtual void play(double speed = 1.0);
86 bool isPaused() const;
87 virtual void pause();
88 void stop();
89 bool enableJack(bool enable = true);
90 void setVolume(double volume, bool muteOnPause = true);
91 double volume() const;
92 void onWindowResize();
93 virtual void seek(int position);
94 virtual void refreshConsumer(bool scrubAudio = false);
95 bool saveXML(const QString &filename, Service *service = nullptr, bool withRelativePaths = true,
96 QTemporaryFile *tempFile = nullptr, bool proxy = false, QString projectNote = QString());
97 QString XML(Service *service = nullptr, bool withProfile = false, bool withMetadata = true);
98 int consumerChanged();
99 void setProfile(const QString &profile_name);
100 void setAudioChannels(int audioChannels);
101 QString resource() const;
102 bool isSeekable(Mlt::Producer *p = nullptr) const;
103 bool isLiveProducer(Mlt::Producer *p = nullptr) const;
104 bool isClip() const;
105 bool isSeekableClip();
106 bool isPlaylist() const;
107 bool isMultitrack() const;
108 bool isImageProducer(Service *service) const;
109 bool isFileProducer(Service *service) const;
110 void rewind(bool forceChangeDirection);
111 void fastForward(bool forceChangeDirection);
112 void previous(int currentPosition);
113 void next(int currentPosition);
114 void setIn(int);
115 void setOut(int);
116 void restart(const QString &xml = "");
117 void resetURL();
118 QImage image(Frame *frame, int width, int height);
119 QImage image(Mlt::Producer &producer, int frameNumber, int width, int height);
120 void updateAvformatCaching(int trackCount);
121 bool isAudioFilter(const QString &name);
122 int realTime() const;
123 void setImageDurationFromDefault(Service *service) const;
124 void setDurationFromDefault(Producer *service) const;
125 void lockCreationTime(Producer *producer) const;
126 Producer *setupNewProducer(Producer *newProducer) const;
127 QUuid uuid(Mlt::Properties &properties) const;
128 void setUuid(Mlt::Properties &properties, QUuid uid) const;
129 QUuid ensureHasUuid(Mlt::Properties &properties) const;
130 static void copyFilters(Mlt::Producer &fromProducer, Mlt::Producer &toProducer,
131 bool fromClipboard = false, bool includeDisabled = true);
132 void copyFilters(Mlt::Producer *producer = nullptr);
133 void pasteFilters(Mlt::Producer *producer = nullptr, Mlt::Producer *fromProducer = nullptr);
134 static void adjustFilters(Mlt::Producer &producer, int startIndex = 0);
135 static void adjustFilter(Mlt::Filter *filter, int in, int out, int inDelta, int outDelta,
136 int keyframeDelta);
137 static void adjustClipFilters(Mlt::Producer &producer, int in, int out, int inDelta, int outDelta,
138 int keyframeDelta);
139 bool hasFiltersOnClipboard() const
140 {
141 return m_filtersClipboard->is_valid() && m_filtersClipboard->filter_count() > 0;
142 }
143 QString filtersClipboardXML()
144 {
145 return XML(m_filtersClipboard.get());
146 }
147
148 int audioChannels() const
149 {
150 return m_audioChannels;
151 }
152 Mlt::Repository *repository() const
153 {
154 return m_repo;
155 }
156 Mlt::Profile &profile()
157 {
158 return m_profile;
159 }
160 Mlt::Profile &previewProfile()
161 {
162 return m_previewProfile;
163 }
164 Mlt::Producer *producer() const
165 {
166 return m_producer.data();
167 }
168 Mlt::Consumer *consumer() const
169 {
170 return m_consumer.data();
171 }
172 const QString &URL() const
173 {
174 return m_url;
175 }
176 const TransportControllable *transportControl() const
177 {
178 return &m_transportControl;
179 }
180 Mlt::Producer *savedProducer() const
181 {
182 return m_savedProducer.data();
183 }
184 void setSavedProducer(Mlt::Producer *producer);
185 static Mlt::Filter *getFilter(const QString &name, Mlt::Service *service);
186 QString projectFolder() const
187 {
188 return m_projectFolder;
189 }
190 void setProjectFolder(const QString &folderName);
191 QChar decimalPoint();
192 static void resetLocale();
193 static int filterIn(Mlt::Playlist &playlist, int clipIndex);
194 static int filterOut(Mlt::Playlist &playlist, int clipIndex);
195 void setPreviewScale(int scale);
196 void updatePreviewProfile();
197 static void purgeMemoryPool();
198 static bool fullRange(Mlt::Producer &producer);
199 static bool isMltXml(const QString &s)
200 {
201 return s.contains("<mlt ");
202 }
203 static bool isTrackProducer(Mlt::Producer &producer);
204 static int checkFile(const QString &path);
205 bool blockRefresh(bool block);
206
207 class RefreshBlocker
208 {
209 public:
210 RefreshBlocker()
211 {
212 singleton().blockRefresh(true);
213 }
214 ~RefreshBlocker()
215 {
216 singleton().blockRefresh(false);
217 }
218 };
219
220protected:
221 Mlt::Repository *m_repo;
222 QScopedPointer<Mlt::Producer> m_producer;
223 QScopedPointer<Mlt::FilteredConsumer> m_consumer;
224
225private:
226 Mlt::Profile m_profile;
227 Mlt::Profile m_previewProfile;
228 int m_audioChannels{2};
229 QScopedPointer<Mlt::Filter> m_jackFilter;
230 QString m_url;
231 double m_volume{1.0};
232 TransportControl m_transportControl;
233 QScopedPointer<Mlt::Producer> m_savedProducer;
234 QScopedPointer<Mlt::Producer> m_filtersClipboard;
235 unsigned m_skipJackEvents{0};
236 QString m_projectFolder;
237 QMutex m_saveXmlMutex;
238 bool m_blockRefresh;
239
240 static void on_jack_started(mlt_properties owner, void *object, mlt_event_data data);
241 void onJackStarted(int position);
242 static void on_jack_stopped(mlt_properties owner, void *object, mlt_event_data data);
243 void onJackStopped(int position);
244 void stopJack();
245 void initFiltersClipboard();
246};
247
248} // namespace
249
250#define MLT Mlt::Controller::singleton()
251
252#endif // MLTCONTROLLER_H