]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Use real MLT position in monitors instead of cached one, preventing race condition...
[kdenlive] / src / renderer.h
1 /***************************************************************************
2                          krender.h  -  description
3                             -------------------
4    begin                : Fri Nov 22 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 RENDERER_H
19 #define RENDERER_H
20
21 #include "gentime.h"
22 #include "definitions.h"
23
24 #include <kurl.h>
25
26 #include <qdom.h>
27 #include <qstring.h>
28 #include <qmap.h>
29 #include <QList>
30 #include <QEvent>
31
32
33 /**Render encapsulates the client side of the interface to a renderer.
34 From Kdenlive's point of view, you treat the Render object as the
35 renderer, and simply use it as if it was local. Calls are asyncrhonous -
36 you send a call out, and then receive the return value through the
37 relevant signal that get's emitted once the call completes.
38   *@author Jason Wood
39   */
40
41 class Render;
42
43 class QTimer;
44 class QPixmap;
45
46 namespace Mlt
47 {
48 class Consumer;
49 class Playlist;
50 class Tractor;
51 class Frame;
52 class Producer;
53 class Filter;
54 class Profile;
55 class Service;
56 };
57
58
59 class MltErrorEvent : public QEvent
60 {
61 public:
62     MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
63     QString message() const {
64         return m_message;
65     }
66
67 private:
68     QString m_message;
69 };
70
71
72 class Render: public QObject
73 {
74 Q_OBJECT public:
75
76     enum FailStates { OK = 0,
77                       APP_NOEXIST
78                     };
79
80     Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0);
81     ~Render();
82
83     /** Seeks the renderer clip to the given time. */
84     void seek(GenTime time);
85     void seekToFrame(int pos);
86     void seekToFrameDiff(int diff);
87     int m_isBlocked;
88
89     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
90     QPixmap getImageThumbnail(KUrl url, int width, int height);
91
92     /** Return thumbnail for color clip */
93     //void getImage(int id, QString color, QPoint size);
94
95     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
96
97     /** Return thumbnail for image clip */
98     //void getImage(KUrl url, QPoint size);
99
100     /** Requests a particular frame from the given file.
101      *
102      * The pixmap will be returned by emitting the replyGetImage() signal.
103      * */
104     //void getImage(KUrl url, int frame, QPoint size);
105
106
107     /** Wraps the VEML command of the same name. Sets the current scene list to
108     be list. */
109     int setSceneList(QDomDocument list, int position = 0);
110     int setSceneList(QString playlist, int position = 0);
111     int setProducer(Mlt::Producer *producer, int position);
112     const QString sceneList();
113     bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
114
115     /** Wraps the VEML command of the same name. Tells the renderer to
116     play the current scene at the speed specified, relative to normal
117     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
118     backwards. Does not specify start/stop times for playback.*/
119     void play(double speed);
120     void switchPlay();
121     void pause();
122     /** stop playing */
123     void stop(const GenTime & startTime);
124     void setVolume(double volume);
125
126     QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
127     /** Wraps the VEML command of the same name. Tells the renderer to
128     play the current scene at the speed specified, relative to normal
129     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
130     backwards. Specifes the start/stop times for playback.*/
131     void play(const GenTime & startTime);
132     void playZone(const GenTime & startTime, const GenTime & stopTime);
133     void loopZone(const GenTime & startTime, const GenTime & stopTime);
134
135     void saveZone(KUrl url, QString desc, QPoint zone);
136
137     /** Returns the name of the renderer. */
138     const QString & rendererName() const;
139
140     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
141     not playing anything. */
142     double playSpeed();
143     /** Returns the current seek position of the renderer. */
144     GenTime seekPosition() const;
145     int seekFramePosition() const;
146
147     void emitFrameNumber(double position);
148     void emitConsumerStopped();
149
150     /** Gives the aspect ratio of the consumer */
151     double consumerRatio() const;
152
153     void askForRefresh();
154     void doRefresh();
155
156     /** Save current producer frame as image */
157     void exportCurrentFrame(KUrl url, bool notify);
158
159     /** Turn on or off on screen display */
160     void refreshDisplay();
161     int resetProfile();
162     double fps() const;
163     int renderWidth() const;
164     int renderHeight() const;
165     /** get display aspect ratio */
166     double dar() const;
167
168     /** Playlist manipulation */
169     void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
170     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
171     void mltCutClip(int track, GenTime position);
172     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
173     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
174     int mltTrackDuration(int track);
175     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
176     bool mltResizeClipStart(ItemInfo info, GenTime diff);
177     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
178     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
179     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
180     bool mltRemoveClip(int track, GenTime position);
181     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
182     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
183     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
184     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
185     void mltChangeTrackState(int track, bool mute, bool blind);
186     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
187     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
188     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
189     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
190     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
191     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
192     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
193     void mltDeleteTransparency(int pos, int track, int id);
194     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
195     void mltInsertTrack(int ix, bool videoTrack);
196     void mltDeleteTrack(int ix);
197     void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
198
199     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
200     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
201     to the clip and 0.6 is the speed in percents. The newly created producer will have it's
202     "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
203     in the ClipManager list and speed is the current speed */
204     int mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod);
205
206     QList <Mlt::Producer *> producersList();
207     void updatePreviewSettings();
208     void setDropFrames(bool show);
209
210 private:   // Private attributes & methods
211     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
212     QString m_name;
213     Mlt::Consumer * m_mltConsumer;
214     Mlt::Producer * m_mltProducer;
215     Mlt::Profile *m_mltProfile;
216     double m_framePosition;
217     double m_fps;
218
219     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
220     bool m_isZoneMode;
221     bool m_isLoopMode;
222     GenTime m_loopStart;
223     int m_originalOut;
224
225     /** true when monitor is in split view (several tracks at the same time) */
226     bool m_isSplitView;
227
228     Mlt::Producer *m_blackClip;
229     QString m_activeProfile;
230
231     QTimer *m_refreshTimer;
232     QTimer *m_osdTimer;
233
234     /** A human-readable description of this renderer. */
235     int m_winid;
236
237     /** Sets the description of this renderer to desc. */
238     void closeMlt();
239     void mltCheckLength();
240     void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
241     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
242     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
243     void buildConsumer();
244     void resetZoneMode();
245     void fillSlowMotionProducers();
246
247 private slots:  // Private slots
248     /** refresh monitor display */
249     void refresh();
250     void slotOsdTimeout();
251     int connectPlaylist();
252     //void initSceneList();
253
254 signals:   // Signals
255     /** emitted when the renderer recieves a reply to a getFileProperties request. */
256     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
257
258     /** emitted when the renderer recieves a reply to a getImage request. */
259     void replyGetImage(const QString &, const QPixmap &);
260
261     /** Emitted when the renderer stops, either playing or rendering. */
262     void stopped();
263     /** Emitted when the renderer starts playing. */
264     void playing(double);
265     /** Emitted when the renderer is rendering. */
266     void rendering(const GenTime &);
267     /** Emitted when rendering has finished */
268     void renderFinished();
269     /** Emitted when the current seek position has been changed by the renderer. */
270 //    void positionChanged(const GenTime &);
271     /** Emitted when an error occurs within this renderer. */
272     void error(const QString &, const QString &);
273     void durationChanged(int);
274     void rendererPosition(int);
275     void rendererStopped(int);
276     void removeInvalidClip(const QString &, bool replaceProducer);
277     void refreshDocumentProducers();
278     void blockMonitors();
279
280 public slots:  // Public slots
281     /** Start Consumer */
282     void start();
283     /** Stop Consumer */
284     void stop();
285     void clear();
286     int getLength();
287     /** If the file is readable by mlt, return true, otherwise false */
288     bool isValid(KUrl url);
289
290     /** Wraps the VEML command of the same name. Requests the file properties
291     for the specified url from the renderer. Upon return, the result will be emitted
292     via replyGetFileProperties(). */
293     void getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer = true);
294
295     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
296     static char *decodedString(QString str);
297     void mltSavePlaylist();
298     void slotSplitView(bool doit);
299 };
300
301 #endif