1 | /*************************************************************************** |
2 | docclipbase.h - description |
3 | ------------------- |
4 | begin : Fri Apr 12 2002 |
5 | copyright : (C) 2002 by Jason Wood |
6 | email : jasonwood@blueyonder.co.uk |
7 | ***************************************************************************/ |
8 | |
9 | /*************************************************************************** |
10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * |
15 | * * |
16 | ***************************************************************************/ |
17 | |
18 | #ifndef DOCCLIPBASE_H |
19 | #define DOCCLIPBASE_H |
20 | |
21 | /**DocClip is a class for the various types of clip |
22 | *@author Jason Wood |
23 | */ |
24 | |
25 | #include <QtXml/qdom.h> |
26 | #include <QPixmap> |
27 | #include <QObject> |
28 | #include <QTimer> |
29 | #include <QProcess> |
30 | #include <QFuture> |
31 | |
32 | #include <KUrl> |
33 | |
34 | #include "gentime.h" |
35 | #include "definitions.h" |
36 | |
37 | /* |
38 | class DocClipAVFile; |
39 | class EffectDescriptionList;*/ |
40 | class KThumb; |
41 | class ClipManager; |
42 | |
43 | namespace Mlt |
44 | { |
45 | class Producer; |
46 | } |
47 | |
48 | struct CutZoneInfo { |
49 | QPoint zone; |
50 | QString description; |
51 | }; |
52 | |
53 | |
54 | class DocClipBase: public QObject |
55 | { |
56 | Q_OBJECT |
57 | public: |
58 | /** this enum determines the types of "feed" available within this clip. types must be non-exclusive |
59 | * - e.g. if you can have audio and video separately, it should be possible to combin the two, as is |
60 | * done here. If a new clip type is added then it should be possible to combine it with both audio |
61 | * and video. */ |
62 | |
63 | DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id); |
64 | // DocClipBase & operator=(const DocClipBase & clip); |
65 | virtual ~ DocClipBase(); |
66 | |
67 | /** returns the name of this clip. */ |
68 | const QString name() const; |
69 | |
70 | /** Returns the description of this clip. */ |
71 | const QString description() const; |
72 | /** Does this clip need a transparent background (e.g. for titles). */ |
73 | bool isTransparent() const; |
74 | |
75 | /** Returns any property of this clip. */ |
76 | const QString getProperty(const QString &prop) const; |
77 | void setProperty(const QString &key, const QString &value); |
78 | void clearProperty(const QString &key); |
79 | |
80 | /** Returns the internal unique id of the clip. */ |
81 | const QString &getId() const; |
82 | |
83 | bool hasAudioThumb() const; |
84 | //KThumb *thumbCreator; |
85 | bool audioThumbCreated() const; |
86 | /*void getClipMainThumb();*/ |
87 | |
88 | /** returns the duration of this clip */ |
89 | const GenTime & duration() const; |
90 | const GenTime maxDuration() const; |
91 | /** returns the duration of this clip */ |
92 | void setDuration(const GenTime &dur); |
93 | |
94 | /** returns clip type (audio, text, image,...) */ |
95 | const ClipType & clipType() const; |
96 | /** set clip type (audio, text, image,...) */ |
97 | void setClipType(ClipType type); |
98 | |
99 | /** remove tmp file if the clip has one (for example text clips) */ |
100 | void removeTmpFile() const; |
101 | |
102 | /** Returns a url to a file describing this clip. Exactly what this url is, |
103 | whether it is temporary or not, and whether it provokes a render will |
104 | depend entirely on what the clip consists of. */ |
105 | KUrl fileURL() const; |
106 | |
107 | /** Returns true if the clip duration is known, false otherwise. */ |
108 | bool durationKnown() const; |
109 | // Returns the number of frames per second that this clip should play at. |
110 | double framesPerSecond() const; |
111 | |
112 | bool isDocClipAVFile() const { |
113 | return false; |
114 | } |
115 | |
116 | /** Sets producers for the current clip (one for each track due to a limitation in MLT's track mixing */ |
117 | void setProducer(Mlt::Producer *producer, bool reset = false, bool readPropertiesFromProducer = false); |
118 | /** Retrieve a producer for a track */ |
119 | Mlt::Producer *getProducer(int track = -1); |
120 | /** Get a copy of the producer, for use in the clip monitor */ |
121 | Mlt::Producer *getCloneProducer(); |
122 | /** Retrieve the producer that shows only video */ |
123 | Mlt::Producer *videoProducer(int track); |
124 | /** Retrieve the producer that shows only audio */ |
125 | Mlt::Producer *audioProducer(int track); |
126 | |
127 | /** Returns true if this clip is a project clip, false otherwise. Overridden in DocClipProject, |
128 | * where it returns true. */ |
129 | bool isProjectClip() const { |
130 | return false; |
131 | } |
132 | |
133 | /** Reads in the element structure and creates a clip out of it.*/ |
134 | // Returns an XML document that describes part of the current scene. |
135 | QDomDocument sceneToXML(const GenTime & startTime, |
136 | const GenTime & endTime) const; |
137 | /** returns a QString containing all of the XML data required to recreate this clip. */ |
138 | QDomElement toXML(bool hideTemporaryProperties = false) const; |
139 | |
140 | /** Returns true if the xml passed matches the values in this clip */ |
141 | bool matchesXML(const QDomElement & element) const; |
142 | |
143 | void addReference() { |
144 | ++m_refcount; |
145 | } |
146 | void removeReference() { |
147 | --m_refcount; |
148 | } |
149 | uint numReferences() const { |
150 | return m_refcount; |
151 | } |
152 | |
153 | /** Returns the filesize, or 0 if there is no appropriate filesize. */ |
154 | qulonglong fileSize() const; |
155 | |
156 | /** Returns true if this clip refers to the clip passed in. A clip refers to another clip if |
157 | * it uses it as part of it's own composition. */ |
158 | bool referencesClip(DocClipBase * clip) const; |
159 | |
160 | /** Returns the thumbnail producer used by this clip */ |
161 | KThumb *thumbProducer(); |
162 | |
163 | QString getClipHash() const; |
164 | const char *producerProperty(const char *name) const; |
165 | void setProducerProperty(const char *name, const char *data); |
166 | void resetProducerProperty(const char *name); |
167 | void deleteProducers(); |
168 | |
169 | /** Set default play zone for clip monitor */ |
170 | void setZone(const QPoint &zone); |
171 | /** Get default play zone for clip monitor */ |
172 | QPoint zone() const; |
173 | |
174 | /** Returns true is clip is missing but user wants to keep it as placeholder */ |
175 | bool isPlaceHolder() const; |
176 | void setValid(); |
177 | static QString getHash(const QString &path); |
178 | |
179 | void addCutZone(int in, int out, const QString &desc = QString()); |
180 | bool hasCutZone(const QPoint &p) const; |
181 | void removeCutZone(int in, int out); |
182 | QList <CutZoneInfo> cutZones() const; |
183 | void updateCutZone(int oldin, int oldout, int in, int out, const QString &desc = QString()); |
184 | |
185 | bool hasVideoCodec(const QString &codec) const; |
186 | bool hasAudioCodec(const QString &codec) const; |
187 | bool checkHash() const; |
188 | void setPlaceHolder(bool place); |
189 | QImage (int frame, int width, int height); |
190 | void clearThumbProducer(); |
191 | void reloadThumbProducer(); |
192 | void cleanupProducers(); |
193 | bool isClean() const; |
194 | bool getAudioThumbs(); |
195 | void setAnalysisData(const QString &name, const QString &data, int offset = 0); |
196 | QMap <QString, QString> analysisData() const; |
197 | int lastSeekPosition; |
198 | /** Cache for every audio Frame with 10 Bytes */ |
199 | /** format is frame -> channel ->bytes */ |
200 | QMap<int, QMap<int, QByteArray> > audioFrameCache; |
201 | /** Returns all current properties for this clip */ |
202 | QMap <QString, QString> properties() const; |
203 | /** Return the current values for a set of properties */ |
204 | QMap <QString, QString> currentProperties(const QMap<QString, QString> &props); |
205 | QMap <QString, QStringList> metadata() const; |
206 | /** @brief Returns a short info string about the clip to display in tooltip */ |
207 | const QString shortInfo() const; |
208 | |
209 | private: // Private attributes |
210 | /** The number of times this clip is used in the project - the number of references to this clip |
211 | * that exist. */ |
212 | uint m_refcount; |
213 | QList <Mlt::Producer *> m_baseTrackProducers; |
214 | QList <Mlt::Producer *> m_videoTrackProducers; |
215 | QList <Mlt::Producer *> m_audioTrackProducers; |
216 | QList <Mlt::Producer *> m_toDeleteProducers; |
217 | ClipType m_clipType; |
218 | |
219 | /** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */ |
220 | QList < CommentedTime > m_snapMarkers; |
221 | GenTime m_duration; |
222 | |
223 | KThumb *m_thumbProd; |
224 | bool m_audioThumbCreated; |
225 | |
226 | /** a unique numeric id */ |
227 | QString m_id; |
228 | |
229 | /** Wheter the clip is a placeholder (clip missing but user wants to see it) */ |
230 | bool m_placeHolder; |
231 | |
232 | QList <CutZoneInfo> m_cutZones; |
233 | |
234 | /** Holds clip infos like fps, size,... */ |
235 | QMap <QString, QString> m_properties; |
236 | /** Holds clip metadata like author, copyright,... */ |
237 | QMap <QString, QStringList> m_metadata; |
238 | /** Holds clip analysis data that can be used later to create markers or keyframes */ |
239 | QMap <QString, QString> m_analysisdata; |
240 | |
241 | /** Try to make sure we don't delete a producer while using it */ |
242 | QMutex m_producerMutex; |
243 | QMutex m_replaceMutex; |
244 | |
245 | /** @brief This timer will trigger creation of audio thumbnails. */ |
246 | QTimer m_audioTimer; |
247 | |
248 | /** Create connections for audio thumbnails */ |
249 | void slotRefreshProducer(); |
250 | void setProducerProperty(const char *name, int data); |
251 | void setProducerProperty(const char *name, double data); |
252 | void getFileHash(const QString &url); |
253 | /** @brief When duplicating a producer, make sure all manually set properties are passed to it. */ |
254 | void adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind); |
255 | /** @brief Create another instance of a producer. */ |
256 | Mlt::Producer *cloneProducer(Mlt::Producer *source); |
257 | /** @brief Offset all keyframes of a geometry. */ |
258 | const QString geometryWithOffset(const QString &data, int offset); |
259 | |
260 | |
261 | public slots: |
262 | void updateAudioThumbnail(const audioByteArray& data); |
263 | QList < CommentedTime > () const; |
264 | GenTime findNextSnapMarker(const GenTime & currTime); |
265 | GenTime findPreviousSnapMarker(const GenTime & currTime); |
266 | QString deleteSnapMarker(const GenTime & time); |
267 | void editSnapMarker(const GenTime & time, const QString &); |
268 | void (const CommentedTime &marker); |
269 | QList < GenTime > snapMarkers() const; |
270 | QString (const GenTime &t) const; |
271 | CommentedTime markerAt(const GenTime &t) const; |
272 | void setClipThumbFrame(const uint &ix); |
273 | uint getClipThumbFrame() const; |
274 | void setProperties(QMap<QString, QString> properties); |
275 | void setMetadata(const QMap <QString, QString> &properties, const QString &tool = QString()); |
276 | void (const QList <int> &frames); |
277 | |
278 | signals: |
279 | void gotAudioData(); |
280 | /** @brief Generate a proxy clip (lower resolution copy) named like the clip's hash. */ |
281 | void createProxy(const QString &id); |
282 | /** @brief Abort creation of the proxy clip (lower resolution copy). */ |
283 | void abortProxy(const QString &id, const QString &proxyPath); |
284 | }; |
285 | |
286 | #endif |
287 | |