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