CuteLogger
Fast and simple logging solution for Qt based applications
mltcontroller.h
1/*
2 * Copyright (c) 2011-2024 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 fixLengthProperties(Service &service);
117 void restart(const QString &xml = "");
118 void resetURL();
119 QImage image(Frame *frame, int width, int height);
120 QImage image(Mlt::Producer &producer, int frameNumber, int width, int height);
121 void updateAvformatCaching(int trackCount);
122 bool isAudioFilter(const QString &name);
123 int realTime() const;
124 void setImageDurationFromDefault(Service *service) const;
125 void setDurationFromDefault(Producer *service) const;
126 void lockCreationTime(Producer *producer) const;
127 Producer *setupNewProducer(Producer *newProducer) const;
128 QUuid uuid(Mlt::Properties &properties) const;
129 void setUuid(Mlt::Properties &properties, QUuid uid) const;
130 QUuid ensureHasUuid(Mlt::Properties &properties) const;
131 static void copyFilters(Mlt::Producer &fromProducer, Mlt::Producer &toProducer,
132 bool fromClipboard = false, bool includeDisabled = true);
133 void copyFilters(Mlt::Producer *producer = nullptr);
134 void pasteFilters(Mlt::Producer *producer = nullptr, Mlt::Producer *fromProducer = nullptr);
135 static void adjustFilters(Mlt::Producer &producer, int startIndex = 0);
136 static void adjustFilter(Mlt::Filter *filter, int in, int out, int inDelta, int outDelta,
137 int keyframeDelta);
138 static void adjustClipFilters(Mlt::Producer &producer, int in, int out, int inDelta, int outDelta,
139 int keyframeDelta);
140 bool hasFiltersOnClipboard() const
141 {
142 return m_filtersClipboard->is_valid() && m_filtersClipboard->filter_count() > 0;
143 }
144 QString filtersClipboardXML()
145 {
146 return XML(m_filtersClipboard.get());
147 }
148
149 int audioChannels() const
150 {
151 return m_audioChannels;
152 }
153 Mlt::Repository *repository() const
154 {
155 return m_repo;
156 }
157 Mlt::Profile &profile()
158 {
159 return m_profile;
160 }
161 Mlt::Profile &previewProfile()
162 {
163 return m_previewProfile;
164 }
165 Mlt::Producer *producer() const
166 {
167 return m_producer.data();
168 }
169 Mlt::Consumer *consumer() const
170 {
171 return m_consumer.data();
172 }
173 const QString &URL() const
174 {
175 return m_url;
176 }
177 const TransportControllable *transportControl() const
178 {
179 return &m_transportControl;
180 }
181 Mlt::Producer *savedProducer() const
182 {
183 return m_savedProducer.data();
184 }
185 void setSavedProducer(Mlt::Producer *producer);
186 static Mlt::Filter *getFilter(const QString &name, Mlt::Service *service);
187 QString projectFolder() const
188 {
189 return m_projectFolder;
190 }
191 void setProjectFolder(const QString &folderName);
192 QChar decimalPoint();
193 static void resetLocale();
194 static int filterIn(Mlt::Playlist &playlist, int clipIndex);
195 static int filterOut(Mlt::Playlist &playlist, int clipIndex);
196 void setPreviewScale(int scale);
197 void updatePreviewProfile();
198 static void purgeMemoryPool();
199 static bool fullRange(Mlt::Producer &producer);
200 static bool isMltXml(const QString &s)
201 {
202 return s.contains("<mlt ");
203 }
204 static bool isTrackProducer(Mlt::Producer &producer);
205 static int checkFile(const QString &path);
206 bool blockRefresh(bool block);
207
208 class RefreshBlocker
209 {
210 public:
211 RefreshBlocker()
212 {
213 singleton().blockRefresh(true);
214 }
215 ~RefreshBlocker()
216 {
217 singleton().blockRefresh(false);
218 }
219 };
220
221protected:
222 Mlt::Repository *m_repo;
223 QScopedPointer<Mlt::Producer> m_producer;
224 QScopedPointer<Mlt::FilteredConsumer> m_consumer;
225
226private:
227 Mlt::Profile m_profile;
228 Mlt::Profile m_previewProfile;
229 int m_audioChannels{2};
230 QScopedPointer<Mlt::Filter> m_jackFilter;
231 QString m_url;
232 double m_volume{1.0};
233 TransportControl m_transportControl;
234 QScopedPointer<Mlt::Producer> m_savedProducer;
235 QScopedPointer<Mlt::Producer> m_filtersClipboard;
236 unsigned m_skipJackEvents{0};
237 QString m_projectFolder;
238 QMutex m_saveXmlMutex;
239 bool m_blockRefresh;
240
241 static void on_jack_started(mlt_properties owner, void *object, mlt_event_data data);
242 void onJackStarted(int position);
243 static void on_jack_stopped(mlt_properties owner, void *object, mlt_event_data data);
244 void onJackStopped(int position);
245 void stopJack();
246 void initFiltersClipboard();
247};
248
249} // namespace
250
251#define MLT Mlt::Controller::singleton()
252
253#endif // MLTCONTROLLER_H