CuteLogger
Fast and simple logging solution for Qt based applications
mltcontroller.h
1 /*
2  * Copyright (c) 2011-2019 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 <QMutex>
26 #include <Mlt.h>
27 #include "transportcontrol.h"
28 
29 // forward declarations
30 class QQuickView;
31 
32 namespace Mlt {
33 
34 const int kMaxImageDurationSecs = 3600 * 4;
35 extern const QString XmlMimeType;
36 
37 class TransportControl : public TransportControllable
38 {
39  Q_OBJECT
40 public slots:
41  void play(double speed = 1.0);
42  void pause();
43  void stop();
44  void seek(int position);
45  void rewind(bool forceChangeDirection);
46  void fastForward(bool forceChangeDirection);
47  void previous(int currentPosition);
48  void next(int currentPosition);
49  void setIn(int);
50  void setOut(int);
51 };
52 
53 class Controller
54 {
55 protected:
56  Controller();
57  virtual int reconfigure(bool isMulti) = 0;
58 
59 public:
60  static Controller& singleton(QObject *parent = 0);
61  virtual ~Controller();
62  static void destroy();
63 
64  virtual QObject* videoWidget() = 0;
65  virtual int setProducer(Mlt::Producer*, bool isMulti = false);
66  virtual int open(const QString& url);
67  bool openXML(const QString& filename);
68  virtual void close();
69  virtual int displayWidth() const = 0;
70  virtual int displayHeight() const = 0;
71 
72  void closeConsumer();
73  virtual void play(double speed = 1.0);
74  virtual void pause();
75  void stop();
76  bool enableJack(bool enable = true);
77  void setVolume(double volume, bool muteOnPause = true);
78  double volume() const;
79  void onWindowResize();
80  virtual void seek(int position);
81  void refreshConsumer(bool scrubAudio = false);
82  void saveXML(const QString& filename, Service* service = 0, bool withRelativePaths = true);
83  QString XML(Service* service = 0, bool withProfile = false, bool withMetadata = false);
84  int consumerChanged();
85  void setProfile(const QString& profile_name);
86  void setAudioChannels(int audioChannels);
87  QString resource() const;
88  bool isSeekable(Mlt::Producer* p = 0) const;
89  bool isClip() const;
90  bool isSeekableClip();
91  bool isPlaylist() const;
92  bool isMultitrack() const;
93  bool isImageProducer(Service* service) const;
94  void rewind(bool forceChangeDirection);
95  void fastForward(bool forceChangeDirection);
96  void previous(int currentPosition);
97  void next(int currentPosition);
98  void setIn(int);
99  void setOut(int);
100  void restart(const QString& xml = "");
101  void resetURL();
102  QImage image(Frame *frame, int width, int height);
103  QImage image(Mlt::Producer& producer, int frameNumber, int width, int height);
104  void updateAvformatCaching(int trackCount);
105  bool isAudioFilter(const QString& name);
106  int realTime() const;
107  void setImageDurationFromDefault(Service* service) const;
108  void setDurationFromDefault(Producer* service) const;
109  QUuid uuid(Mlt::Properties &properties) const;
110  void setUuid(Mlt::Properties &properties, QUuid uid) const;
111  QUuid ensureHasUuid(Mlt::Properties& properties) const;
112  static void copyFilters(Mlt::Producer& fromProducer, Mlt::Producer& toProducer);
113  void copyFilters(Mlt::Producer* producer = 0);
114  void pasteFilters(Mlt::Producer* producer = 0);
115  bool hasFiltersOnClipboard() const {
116  return m_filtersClipboard->is_valid() && m_filtersClipboard->filter_count() > 0;
117  }
118 
119  int audioChannels() const {
120  return m_audioChannels;
121  }
122  Mlt::Repository* repository() const {
123  return m_repo;
124  }
125  Mlt::Profile& profile() const {
126  return *m_profile;
127  }
128  Mlt::Producer* producer() const {
129  return m_producer.data();
130  }
131  Mlt::Consumer* consumer() const {
132  return m_consumer.data();
133  }
134  const QString& URL() const {
135  return m_url;
136  }
137  const TransportControllable* transportControl() const {
138  return &m_transportControl;
139  }
140  Mlt::Producer* savedProducer() const {
141  return m_savedProducer.data();
142  }
143  void setSavedProducer(Mlt::Producer* producer);
144  static Mlt::Filter* getFilter(const QString& name, Mlt::Service* service);
145  QString projectFolder() const { return m_projectFolder; }
146  void setProjectFolder(const QString& folderName);
147 
148 protected:
149  Mlt::Repository* m_repo;
150  QScopedPointer<Mlt::Producer> m_producer;
151  QScopedPointer<Mlt::FilteredConsumer> m_consumer;
152 
153 private:
154  QScopedPointer<Mlt::Profile> m_profile;
155  int m_audioChannels;
156  QScopedPointer<Mlt::Filter> m_jackFilter;
157  QString m_url;
158  double m_volume;
159  TransportControl m_transportControl;
160  QScopedPointer<Mlt::Producer> m_savedProducer;
161  QScopedPointer<Mlt::Producer> m_filtersClipboard;
162  unsigned m_skipJackEvents;
163  QString m_projectFolder;
164  QMutex m_saveXmlMutex;
165 
166  static void on_jack_started(mlt_properties owner, void* object, mlt_position *position);
167  void onJackStarted(int position);
168  static void on_jack_stopped(mlt_properties owner, void* object, mlt_position *position);
169  void onJackStopped(int position);
170  void stopJack();
171 };
172 
173 } // namespace
174 
175 #define MLT Mlt::Controller::singleton()
176 
177 #endif // MLTCONTROLLER_H
Definition: encodedock.h:35