]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Big update to the proxy clips, fixing several issues. They can now be deleted in...
[kdenlive] / src / renderer.h
1 /***************************************************************************
2                          krender.h  -  description
3                             -------------------
4    begin                : Fri Nov 22 2002
5    copyright            : (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk)
6    copyright            : (C) 2010 by Jean-Baptiste Mardelle (jb@kdenlive.org)
7
8 ***************************************************************************/
9
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18
19 /**
20  * @class Render
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 #include "mlt/framework/mlt_types.h"
35
36 #include <kurl.h>
37
38 #include <qdom.h>
39 #include <qstring.h>
40 #include <qmap.h>
41 #include <QList>
42 #include <QEvent>
43
44
45 class Render;
46
47 class QTimer;
48 class QPixmap;
49
50 namespace Mlt
51 {
52 class Consumer;
53 class Playlist;
54 class Tractor;
55 class Transition;
56 class Frame;
57 class Field;
58 class Producer;
59 class Filter;
60 class Profile;
61 class Service;
62 };
63
64 class MltErrorEvent : public QEvent
65 {
66 public:
67     MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
68     QString message() const {
69         return m_message;
70     }
71
72 private:
73     QString m_message;
74 };
75
76 class Render: public QObject
77 {
78 Q_OBJECT public:
79
80     enum FailStates { OK = 0,
81                       APP_NOEXIST
82                     };
83     /** @brief Build a MLT Renderer
84      *  @param rendererName A unique identifier for this renderer
85      *  @param winid The parent widget identifier (required for SDL display). Set to 0 for OpenGL rendering
86      *  @param profile The MLT profile used for the renderer (default one will be used if empty). */
87     Render(const QString & rendererName, int winid, QString profile = QString(), QWidget *parent = 0);
88
89     /** @brief Destroy the MLT Renderer. */
90     ~Render();
91
92     /** @brief Seeks the renderer clip to the given time. */
93     void seek(GenTime time);
94     void seek(int time);
95     void seekToFrame(int pos);
96     void seekToFrameDiff(int diff);
97     int m_isBlocked;
98
99     QPixmap getImageThumbnail(KUrl url, int width, int height);
100
101     /** @brief Sets the current MLT producer playlist.
102      * @param list The xml describing the playlist
103      * @param position (optional) time to seek to */
104     int setSceneList(QDomDocument list, int position = 0);
105
106     /** @brief Sets the current MLT producer playlist.
107      * @param list new playlist
108      * @param position (optional) time to seek to
109      * @return 0 when it has success, different from 0 otherwise
110      *
111      * Creates the producer from the text playlist. */
112     int setSceneList(QString playlist, int position = 0);
113     int setProducer(Mlt::Producer *producer, int position);
114
115     /** @brief Get the current MLT producer playlist.
116      * @return A string describing the playlist */
117     const QString sceneList();
118     bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
119
120     /** @brief Tells the renderer to play the scene at the specified speed,
121      * @param speed speed to play the scene to
122      *
123      * The speed is relative to normal playback, e.g. 1.0 is normal speed, 0.0
124      * is paused, -1.0 means play backwards. It does not specify start/stop */
125     void play(double speed);
126     void switchPlay();
127     void pause();
128
129     /** @brief Stops playing.
130      * @param startTime time to seek to */
131     void stop(const GenTime & startTime);
132     int volume() const;
133
134     QImage extractFrame(int frame_position, int width = -1, int height = -1);
135
136     /** @brief Plays the scene starting from a specific time.
137      * @param startTime time to start playing the scene from */
138     void play(const GenTime & startTime);
139     void playZone(const GenTime & startTime, const GenTime & stopTime);
140     void loopZone(const GenTime & startTime, const GenTime & stopTime);
141
142     void saveZone(KUrl url, QString desc, QPoint zone);
143
144     /** @brief Returns the name of the renderer. */
145     const QString & rendererName() const;
146
147     /** @brief Returns the speed at which the renderer is currently playing.
148      *
149      * It returns 0.0 when the renderer is not playing anything. */
150     double playSpeed();
151
152     /** @brief Returns the current seek position of the renderer. */
153     GenTime seekPosition() const;
154     int seekFramePosition() const;
155
156     void emitFrameUpdated(Mlt::Frame&);
157     void emitFrameNumber(double position);
158     void emitConsumerStopped();
159
160     /** @brief Returns the aspect ratio of the consumer. */
161     double consumerRatio() const;
162
163     void doRefresh();
164
165     /** @brief Saves current producer frame as an image. */
166     void exportCurrentFrame(KUrl url, bool notify);
167
168     /** @brief Turns on or off on screen display. */
169     void refreshDisplay();
170     int resetProfile(const QString profileName);
171     double fps() const;
172
173     /** @brief Returns the width of a frame for this profile. */
174     int frameRenderWidth() const;
175     /** @brief Returns the display width of a frame for this profile. */
176     int renderWidth() const;
177     /** @brief Returns the height of a frame for this profile. */
178     int renderHeight() const;
179
180     /** @brief Returns display aspect ratio. */
181     double dar() const;
182     /** @brief Returns sample aspect ratio. */
183     double sar() const;
184
185     /*
186      * Playlist manipulation.
187      */
188     Mlt::Producer *checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element);
189     int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite = false, bool push = false);
190     bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
191     void mltCutClip(int track, GenTime position);
192     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
193     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
194
195     /** @brief Returns the duration/length of @param track as reported by the track producer. */
196     int mltTrackDuration(int track);
197
198     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
199     bool mltResizeClipStart(ItemInfo info, GenTime diff);
200     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
201     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
202     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
203     bool mltRemoveClip(int track, GenTime position);
204
205     /** @brief Deletes an effect from a clip in MLT's playlist. */
206     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
207     bool mltRemoveTrackEffect(int track, QString index, bool updateIndex);
208
209     /** @brief Adds an effect to a clip in MLT's playlist. */
210     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
211     bool mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh);
212     bool mltAddTrackEffect(int track, EffectsParameterList params);
213
214     /** @brief Edits an effect parameters in MLT's playlist. */
215     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
216     bool mltEditTrackEffect(int track, EffectsParameterList params);
217
218     /** @brief Updates the "kdenlive_ix" (index) value of an effect. */
219     void mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos);
220
221     /** @brief Changes the order of effects in MLT's playlist.
222      *
223      * It switches effects from oldPos and newPos, updating the "kdenlive_ix"
224      * (index) value. */
225     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
226     void mltMoveTrackEffect(int track, int oldPos, int newPos);
227
228     /** @brief Enables/disables audio/video in a track. */
229     void mltChangeTrackState(int track, bool mute, bool blind);
230     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
231     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
232     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
233     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force = false);
234     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
235     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
236     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
237     void mltDeleteTransparency(int pos, int track, int id);
238     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
239     void mltInsertTrack(int ix, bool videoTrack);
240     void mltDeleteTrack(int ix);
241     bool mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
242     void mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track);
243     Mlt::Producer *invalidProducer(const QString &id);
244
245     /** @brief Changes the speed of a clip in MLT's playlist.
246      *
247      * It creates a new "framebuffer" producer, which must have its "resource"
248      * property set to "video.mpg?0.6", where "video.mpg" is the path to the
249      * clip and "0.6" is the speed in percentage. The newly created producer
250      * will have its "id" property set to "slowmotion:parentid:speed", where
251      * "parentid" is the id of the original clip in the ClipManager list and
252      * "speed" is the current speed. */
253     int mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double oldspeed, int strobe, Mlt::Producer *prod);
254
255     const QList <Mlt::Producer *> producersList();
256     void updatePreviewSettings();
257     void setDropFrames(bool show);
258     QString updateSceneListFps(double current_fps, double new_fps, QString scene);
259     void showFrame(Mlt::Frame&);
260
261     void showAudio(Mlt::Frame&);
262     /** @brief This property is used to decide if the renderer should send audio data for monitoring. */
263     bool analyseAudio;
264     /** @brief This property is used to decide if the renderer should convert it's frames to QImage for use in other Kdenlive widgets. */
265     bool sendFrameForAnalysis;
266     QList <int> checkTrackSequence(int);
267     void sendFrameUpdate();
268
269 private:
270
271     /** @brief The name of this renderer.
272      *
273      * Useful to identify the renderers by what they do - e.g. background
274      * rendering, workspace monitor, etc. */
275     QString m_name;
276     Mlt::Consumer * m_mltConsumer;
277     Mlt::Producer * m_mltProducer;
278     Mlt::Profile *m_mltProfile;
279     double m_framePosition;
280     double m_fps;
281     bool m_externalConsumer;
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     void closeMlt();
304     void mltCheckLength(Mlt::Tractor *tractor);
305     void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
306     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
307     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
308
309     /** @brief Build the MLT Consumer object with initial settings.
310      *  @param profileName The MLT profile to use for the consumer */
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, 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     /** @brief The clip is not valid, should be removed from project. */
354     void removeInvalidClip(const QString &, bool replaceProducer);
355     /** @brief The proxy is not valid, should be deleted. */
356     void removeInvalidProxy(const QString &);
357     void refreshDocumentProducers();
358
359     /** @brief A frame's image has to be shown.
360      *
361      * Used in Mac OS X. */
362     void showImageSignal(QImage);
363     void showAudioSignal(const QByteArray);
364     /** @brief The renderer refreshed the current frame, but no seeking was done. */
365     void frameUpdated(QImage);
366     /** @brief This signal contains the audio of the current frame. */
367     void audioSamplesSignal(const QVector<int16_t>&, int freq, int num_channels, int num_samples);
368
369 public slots:
370
371     /** @brief Starts the consumer. */
372     void start();
373
374     /** @brief Stops the consumer. */
375     void stop();
376     int getLength();
377
378     /** @brief Checks if the file is readable by MLT. */
379     bool isValid(KUrl url);
380
381     /** @brief Requests the file properties for the specified URL.
382         @param xml The xml parameters for the clip
383         @param clipId The clip Id string
384         @param imageHeight The height (in pixels) of the returned thumbnail (height of a treewidgetitem in projectlist)
385         @param replaceProducer If true, the MLT producer will be recreated
386         @param selectClip If true, clip item will be selected in project view
387      * Upon return, the result will be emitted via replyGetFileProperties().
388      * Wraps the VEML command of the same name. */
389     void getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer = true, bool selectClip = false);
390
391     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
392     void mltSavePlaylist();
393     void slotSplitView(bool doit);
394     void slotSwitchFullscreen();
395     void slotSetVolume(int volume);
396 };
397
398 #endif