]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Remove a lot more of unneeded qstrdup calls (part1: commit 4935).
[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 /**
19  * @class Render
20  * @author Jason Wood
21  * @brief Client side of the interface to a renderer.
22  *
23  * From Kdenlive's point of view, you treat the Render object as the renderer,
24  * and simply use it as if it was local. Calls are asynchronous - you send a
25  * call out, and then receive the return value through the relevant signal that
26  * get's emitted once the call completes.
27  */
28
29 #ifndef RENDERER_H
30 #define RENDERER_H
31
32 #include "gentime.h"
33 #include "definitions.h"
34
35 #include <kurl.h>
36
37 #include <qdom.h>
38 #include <qstring.h>
39 #include <qmap.h>
40 #include <QList>
41 #include <QEvent>
42
43 #ifdef Q_WS_MAC
44 #include "videoglwidget.h"
45 #endif
46
47 class Render;
48
49 class QTimer;
50 class QPixmap;
51
52 namespace Mlt
53 {
54 class Consumer;
55 class Playlist;
56 class Tractor;
57 class Transition;
58 class Frame;
59 class Field;
60 class Producer;
61 class Filter;
62 class Profile;
63 class Service;
64 };
65
66 class MltErrorEvent : public QEvent
67 {
68 public:
69     MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
70     QString message() const {
71         return m_message;
72     }
73
74 private:
75     QString m_message;
76 };
77
78 class Render: public QObject
79 {
80 Q_OBJECT public:
81
82     enum FailStates { OK = 0,
83                       APP_NOEXIST
84                     };
85
86     Render(const QString & rendererName, int winid, int extid, QString profile = QString(), QWidget *parent = 0);
87     ~Render();
88
89     /** @brief Seeks the renderer clip to the given time. */
90     void seek(GenTime time);
91     void seekToFrame(int pos);
92     void seekToFrameDiff(int diff);
93     int m_isBlocked;
94
95     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
96     QPixmap getImageThumbnail(KUrl url, int width, int height);
97
98     /* Return thumbnail for color clip
99     void getImage(int id, QString color, QPoint size);*/
100
101     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
102
103     /* Return thumbnail for image clip
104     void getImage(KUrl url, QPoint size);*/
105
106     /* Requests a particular frame from the given file.
107      *
108      * The pixmap will be returned by emitting the replyGetImage() signal.
109     void getImage(KUrl url, int frame, QPoint size);*/
110
111     int setSceneList(QDomDocument list, int position = 0);
112
113     /** @brief Sets the current scene list.
114      * @param list new scene list
115      * @param position (optional) time to seek to
116      * @return 0 when it has success, different from 0 otherwise
117      *
118      * Creates the producer from the MLT XML QDomDocument. Wraps the VEML
119      * command of the same name. */
120     int setSceneList(QString playlist, int position = 0);
121     int setProducer(Mlt::Producer *producer, int position);
122     const QString sceneList();
123     bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
124
125     /** @brief Tells the renderer to play the scene at the specified speed,
126      * @param speed speed to play the scene to
127      *
128      * The speed is relative to normal playback, e.g. 1.0 is normal speed, 0.0
129      * is paused, -1.0 means play backwards. It does not specify start/stop
130      * times for playback. Wraps the VEML command of the same name. */
131     void play(double speed);
132     void switchPlay();
133     void pause();
134
135     /** @brief Stops playing.
136      * @param startTime time to seek to */
137     void stop(const GenTime & startTime);
138     void setVolume(double volume);
139
140     QImage extractFrame(int frame_position, int width = -1, int height = -1);
141
142     /** @brief Plays the scene starting from a specific time.
143      * @param startTime time to start playing the scene from
144      *
145      * Wraps the VEML command of the same name. */
146     void play(const GenTime & startTime);
147     void playZone(const GenTime & startTime, const GenTime & stopTime);
148     void loopZone(const GenTime & startTime, const GenTime & stopTime);
149
150     void saveZone(KUrl url, QString desc, QPoint zone);
151
152     /** @brief Returns the name of the renderer. */
153     const QString & rendererName() const;
154
155     /** @brief Returns the speed at which the renderer is currently playing.
156      *
157      * It returns 0.0 when the renderer is not playing anything. */
158     double playSpeed();
159
160     /** @brief Returns the current seek position of the renderer. */
161     GenTime seekPosition() const;
162     int seekFramePosition() const;
163
164     void emitFrameUpdated(Mlt::Frame&);
165     void emitFrameNumber(double position);
166     void emitConsumerStopped();
167
168     /** @brief Returns the aspect ratio of the consumer. */
169     double consumerRatio() const;
170
171     void doRefresh();
172
173     /** @brief Saves current producer frame as an image. */
174     void exportCurrentFrame(KUrl url, bool notify);
175
176     /** @brief Turns on or off on screen display. */
177     void refreshDisplay();
178     int resetProfile(const QString profileName);
179     double fps() const;
180
181     /** @brief Returns the width of a frame for this profile. */
182     int frameRenderWidth() const;
183     /** @brief Returns the display width of a frame for this profile. */
184     int renderWidth() const;
185     /** @brief Returns the height of a frame for this profile. */
186     int renderHeight() const;
187
188     /** @brief Returns display aspect ratio. */
189     double dar() const;
190
191     /*
192      * Playlist manipulation.
193      */
194     Mlt::Producer *checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element);
195     int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite = false, bool push = false);
196     bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
197     void mltCutClip(int track, GenTime position);
198     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
199     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
200     int mltTrackDuration(int track);
201     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
202     bool mltResizeClipStart(ItemInfo info, GenTime diff);
203     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
204     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
205     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
206     bool mltRemoveClip(int track, GenTime position);
207
208     /** @brief Deletes an effect from a clip in MLT's playlist. */
209     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
210     bool mltRemoveTrackEffect(int track, QString index, bool updateIndex);
211
212     /** @brief Adds an effect to a clip in MLT's playlist. */
213     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
214     bool mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh);
215     bool mltAddTrackEffect(int track, EffectsParameterList params);
216
217     /** @brief Edits an effect parameters in MLT's playlist. */
218     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
219     bool mltEditTrackEffect(int track, EffectsParameterList params);
220
221     /** @brief Updates the "kdenlive_ix" (index) value of an effect. */
222     void mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos);
223
224     /** @brief Changes the order of effects in MLT's playlist.
225      *
226      * It switches effects from oldPos and newPos, updating the "kdenlive_ix"
227      * (index) value. */
228     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
229     void mltMoveTrackEffect(int track, int oldPos, int newPos);
230
231     /** @brief Enables/disables audio/video in a track. */
232     void mltChangeTrackState(int track, bool mute, bool blind);
233     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
234     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
235     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
236     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force = false);
237     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
238     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
239     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
240     void mltDeleteTransparency(int pos, int track, int id);
241     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
242     void mltInsertTrack(int ix, bool videoTrack);
243     void mltDeleteTrack(int ix);
244     bool mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
245     void mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track);
246     Mlt::Producer *invalidProducer(const QString &id);
247
248     /** @brief Changes the speed of a clip in MLT's playlist.
249      *
250      * It creates a new "framebuffer" producer, which must have its "resource"
251      * property set to "video.mpg?0.6", where "video.mpg" is the path to the
252      * clip and "0.6" is the speed in percentage. The newly created producer
253      * will have its "id" property set to "slowmotion:parentid:speed", where
254      * "parentid" is the id of the original clip in the ClipManager list and
255      * "speed" is the current speed. */
256     int mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double oldspeed, int strobe, Mlt::Producer *prod);
257
258     const QList <Mlt::Producer *> producersList();
259     void updatePreviewSettings();
260     void setDropFrames(bool show);
261     QString updateSceneListFps(double current_fps, double new_fps, QString scene);
262 #ifdef Q_WS_MAC
263     void showFrame(Mlt::Frame&);
264 #endif
265     /** @brief This property is used to decide if the renderer should convert it's frames to QImage for use in other Kdenlive widgets. */
266     bool sendFrameForAnalysis;
267     QList <int> checkTrackSequence(int);
268     void sendFrameUpdate();
269
270 private:
271
272     /** @brief The name of this renderer.
273      *
274      * Useful to identify the renderers by what they do - e.g. background
275      * rendering, workspace monitor, etc. */
276     QString m_name;
277     Mlt::Consumer * m_mltConsumer;
278     Mlt::Producer * m_mltProducer;
279     Mlt::Profile *m_mltProfile;
280     double m_framePosition;
281     double m_fps;
282
283     /** @brief True if we are playing a zone.
284      *
285      * It's determined by the "in" and "out" properties being temporarily
286      * changed. */
287     bool m_isZoneMode;
288     bool m_isLoopMode;
289     GenTime m_loopStart;
290     int m_originalOut;
291
292     /** @brief True when the monitor is in split view. */
293     bool m_isSplitView;
294
295     Mlt::Producer *m_blackClip;
296     QString m_activeProfile;
297
298     QTimer *m_osdTimer;
299
300     /** @brief A human-readable description of this renderer. */
301     int m_winid;
302
303 #ifdef Q_WS_MAC
304     VideoGLWidget *m_glWidget;
305 #endif
306     void closeMlt();
307     void mltCheckLength(Mlt::Tractor *tractor);
308     void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
309     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
310     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
311     void buildConsumer(const QString profileName);
312     void resetZoneMode();
313     void fillSlowMotionProducers();
314
315 private slots:
316
317     /** @brief Refreshes the monitor display. */
318     void refresh();
319     void slotOsdTimeout();
320     int connectPlaylist();
321     //void initSceneList();
322
323 signals:
324
325     /** @brief The renderer received a reply to a getFileProperties request. */
326     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
327
328     /** @brief The renderer received a reply to a getImage request. */
329     void replyGetImage(const QString &, const QPixmap &);
330
331     /** @brief The renderer stopped, either playing or rendering. */
332     void stopped();
333
334     /** @brief The renderer started playing. */
335     void playing(double);
336
337     /** @brief The renderer started rendering. */
338     void rendering(const GenTime &);
339
340     /** @brief The rendering has finished.
341         @see consumer_frame_show
342         This signal seems to be useless; use renderPosition(int) instead --Granjow */
343     void renderFinished();
344
345     /* @brief The current seek position has been changed by the renderer.
346     void positionChanged(const GenTime &);*/
347
348     /** @brief An error occurred within this renderer. */
349     void error(const QString &, const QString &);
350     void durationChanged(int);
351     void rendererPosition(int);
352     void rendererStopped(int);
353     void removeInvalidClip(const QString &, bool replaceProducer);
354     void refreshDocumentProducers();
355
356     /** @brief A frame's image has to be shown.
357      *
358      * Used in Mac OS X. */
359     void showImageSignal(QImage);
360     /** @brief The renderer refreshed the current frame, but no seeking was done. */
361     void frameUpdated(QImage);
362
363 public slots:
364
365     /** @brief Starts the consumer. */
366     void start();
367
368     /** @brief Stops the consumer. */
369     void stop();
370     int getLength();
371
372     /** @brief Checks if the file is readable by MLT. */
373     bool isValid(KUrl url);
374
375     /** @brief Requests the file properties for the specified URL.
376      *
377      * Upon return, the result will be emitted via replyGetFileProperties().
378      * Wraps the VEML command of the same name. */
379     void getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer = true);
380
381     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
382     void mltSavePlaylist();
383     void slotSplitView(bool doit);
384     void slotSwitchFullscreen();
385 };
386
387 #endif