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