1 /***************************************************************************
2 krender.h - description
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)
8 ***************************************************************************/
10 /***************************************************************************
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. *
17 ***************************************************************************/
21 * @brief Client side of the interface to a renderer.
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.
33 #include "definitions.h"
34 #include "abstractmonitor.h"
35 #include "mlt/framework/mlt_types.h"
63 class MltErrorEvent : public QEvent
66 MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
67 QString message() const {
76 class Render: public AbstractRender
80 enum FailStates { OK = 0,
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);
89 /** @brief Destroy the MLT Renderer. */
92 /** @brief Seeks the renderer clip to the given time. */
93 void seek(GenTime time);
95 void seekToFrameDiff(int diff);
98 QPixmap getImageThumbnail(KUrl url, int width, int height);
100 /** @brief Sets the current MLT producer playlist.
101 * @param list The xml describing the playlist
102 * @param position (optional) time to seek to */
103 int setSceneList(QDomDocument list, int position = 0);
105 /** @brief Sets the current MLT producer playlist.
106 * @param list new playlist
107 * @param position (optional) time to seek to
108 * @return 0 when it has success, different from 0 otherwise
110 * Creates the producer from the text playlist. */
111 int setSceneList(QString playlist, int position = 0);
112 int setProducer(Mlt::Producer *producer, int position);
114 /** @brief Get the current MLT producer playlist.
115 * @return A string describing the playlist */
116 const QString sceneList();
117 bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
119 /** @brief Tells the renderer to play the scene at the specified speed,
120 * @param speed speed to play the scene to
122 * The speed is relative to normal playback, e.g. 1.0 is normal speed, 0.0
123 * is paused, -1.0 means play backwards. It does not specify start/stop */
124 void play(double speed);
125 void switchPlay(bool play);
128 /** @brief Stops playing.
129 * @param startTime time to seek to */
130 void stop(const GenTime & startTime);
133 QImage extractFrame(int frame_position, QString path = QString(), int width = -1, int height = -1);
135 /** @brief Plays the scene starting from a specific time.
136 * @param startTime time to start playing the scene from */
137 void play(const GenTime & startTime);
138 void playZone(const GenTime & startTime, const GenTime & stopTime);
139 void loopZone(const GenTime & startTime, const GenTime & stopTime);
141 void saveZone(KUrl url, QString desc, QPoint zone);
143 /** @brief Returns the name of the renderer. */
144 const QString & rendererName() const;
146 /** @brief Returns the speed at which the renderer is currently playing.
148 * It returns 0.0 when the renderer is not playing anything. */
151 /** @brief Returns the current seek position of the renderer. */
152 GenTime seekPosition() const;
153 int seekFramePosition() const;
155 void emitFrameUpdated(Mlt::Frame&);
156 void emitFrameNumber(double position);
157 void emitConsumerStopped();
159 /** @brief Returns the aspect ratio of the consumer. */
160 double consumerRatio() const;
164 /** @brief Saves current producer frame as an image. */
165 void exportCurrentFrame(KUrl url, bool notify);
167 /** @brief Turns on or off on screen display. */
168 void refreshDisplay();
169 /** @brief Change the Mlt PROFILE
170 * @param profileName The MLT profile name
171 * @param dropSceneList If true, the current playlist will be deleted
173 int resetProfile(const QString profileName, bool dropSceneList = false);
176 /** @brief Returns the width of a frame for this profile. */
177 int frameRenderWidth() const;
178 /** @brief Returns the display width of a frame for this profile. */
179 int renderWidth() const;
180 /** @brief Returns the height of a frame for this profile. */
181 int renderHeight() const;
183 /** @brief Returns display aspect ratio. */
185 /** @brief Returns sample aspect ratio. */
189 * Playlist manipulation.
191 Mlt::Producer *checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element);
192 int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite = false, bool push = false);
193 bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
194 void mltCutClip(int track, GenTime position);
195 void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
196 int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
198 /** @brief Returns the duration/length of @param track as reported by the track producer. */
199 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);
208 /** @brief Deletes an effect from a clip in MLT's playlist. */
209 bool mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh = true);
210 bool mltRemoveTrackEffect(int track, int index, bool updateIndex);
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);
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);
221 /** @brief Updates the "kdenlive_ix" (index) value of an effect. */
222 void mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos);
224 /** @brief Changes the order of effects in MLT's playlist.
226 * It switches effects from oldPos and newPos, updating the "kdenlive_ix"
228 void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
229 void mltMoveTrackEffect(int track, int oldPos, int newPos);
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);
248 /** @brief Changes the speed of a clip in MLT's playlist.
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);
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 void showFrame(Mlt::Frame&);
264 void showAudio(Mlt::Frame&);
265 /** @brief This property is used to decide if the renderer should send audio data for monitoring. */
268 QList <int> checkTrackSequence(int);
269 void sendFrameUpdate();
271 /** @brief Returns a pointer to the main producer. */
272 Mlt::Producer *getProducer();
276 /** @brief The name of this renderer.
278 * Useful to identify the renderers by what they do - e.g. background
279 * rendering, workspace monitor, etc. */
281 Mlt::Consumer * m_mltConsumer;
282 Mlt::Producer * m_mltProducer;
283 Mlt::Profile *m_mltProfile;
284 double m_framePosition;
286 bool m_externalConsumer;
288 /** @brief True if we are playing a zone.
290 * It's determined by the "in" and "out" properties being temporarily
297 /** @brief True when the monitor is in split view. */
300 Mlt::Producer *m_blackClip;
301 QString m_activeProfile;
306 /** @brief A human-readable description of this renderer. */
312 void mltCheckLength(Mlt::Tractor *tractor);
313 void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
314 QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
315 QMap<QString, Mlt::Producer *> m_slowmotionProducers;
317 /** @brief Build the MLT Consumer object with initial settings.
318 * @param profileName The MLT profile to use for the consumer */
319 void buildConsumer(const QString profileName);
320 void resetZoneMode();
321 void fillSlowMotionProducers();
322 /** @brief Get the track number of the lowest audible (non muted) audio track
323 * @param return The track number */
324 int getLowestNonMutedAudioTrack(Mlt::Tractor tractor);
326 /** @brief Make sure our audio mixing transitions are applied to the lowest track */
327 void fixAudioMixing(Mlt::Tractor tractor);
331 /** @brief Refreshes the monitor display. */
333 void slotOsdTimeout();
334 int connectPlaylist();
335 //void initSceneList();
339 /** @brief The renderer received a reply to a getFileProperties request. */
340 void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool, bool);
342 /** @brief The renderer received a reply to a getImage request. */
343 void replyGetImage(const QString &, const QPixmap &);
345 /** @brief The renderer stopped, either playing or rendering. */
348 /** @brief The renderer started playing. */
349 void playing(double);
351 /** @brief The renderer started rendering. */
352 void rendering(const GenTime &);
354 /** @brief An error occurred within this renderer. */
355 void error(const QString &, const QString &);
356 void durationChanged(int);
357 void rendererPosition(int);
358 void rendererStopped(int);
359 /** @brief The clip is not valid, should be removed from project. */
360 void removeInvalidClip(const QString &, bool replaceProducer);
361 /** @brief The proxy is not valid, should be deleted.
362 * @param id The original clip's id
363 * @param durationError Should be set to true if the proxy failed because it has not same length as original clip
365 void removeInvalidProxy(const QString &id, bool durationError);
366 void refreshDocumentProducers(bool displayRatioChanged, bool fpsChanged);
368 /** @brief If we will delete the producer, make sure to pause the monitor */
369 void blockClipMonitor(const QString);
371 /** @brief A frame's image has to be shown.
373 * Used in Mac OS X. */
374 void showImageSignal(QImage);
375 void showAudioSignal(const QByteArray);
379 /** @brief Starts the consumer. */
382 /** @brief Stops the consumer. */
386 /** @brief Checks if the file is readable by MLT. */
387 bool isValid(KUrl url);
389 /** @brief Requests the file properties for the specified URL.
390 @param xml The xml parameters for the clip
391 @param clipId The clip Id string
392 @param imageHeight The height (in pixels) of the returned thumbnail (height of a treewidgetitem in projectlist)
393 @param replaceProducer If true, the MLT producer will be recreated
394 @param selectClip If true, clip item will be selected in project view
395 * Upon return, the result will be emitted via replyGetFileProperties().
396 * Wraps the VEML command of the same name. */
397 void getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer = true, bool selectClip = false);
399 void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
400 void mltSavePlaylist();
401 void slotSplitView(bool doit);
402 void slotSwitchFullscreen();
403 void slotSetVolume(int volume);
404 void seekToFrame(int pos);