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