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