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"
64 struct requestClipInfo {
71 class MltErrorEvent : public QEvent
74 MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
75 QString message() const {
84 class Render: public AbstractRender
88 enum FailStates { OK = 0,
91 /** @brief Build a MLT Renderer
92 * @param rendererName A unique identifier for this renderer
93 * @param winid The parent widget identifier (required for SDL display). Set to 0 for OpenGL rendering
94 * @param profile The MLT profile used for the renderer (default one will be used if empty). */
95 Render(const QString &rendererName, int winid, QString profile = QString(), QWidget *parent = 0);
97 /** @brief Destroy the MLT Renderer. */
100 /** @brief Seeks the renderer clip to the given time. */
101 void seek(GenTime time);
103 void seekToFrameDiff(int diff);
106 QPixmap getImageThumbnail(KUrl url, int width, int height);
108 /** @brief Sets the current MLT producer playlist.
109 * @param list The xml describing the playlist
110 * @param position (optional) time to seek to */
111 int setSceneList(QDomDocument list, int position = 0);
113 /** @brief Sets the current MLT producer playlist.
114 * @param list new playlist
115 * @param position (optional) time to seek to
116 * @return 0 when it has success, different from 0 otherwise
118 * Creates the producer from the text playlist. */
119 int setSceneList(QString playlist, int position = 0);
120 int setProducer(Mlt::Producer *producer, int position);
122 /** @brief Get the current MLT producer playlist.
123 * @return A string describing the playlist */
124 const QString sceneList();
125 bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
127 /** @brief Tells the renderer to play the scene at the specified speed,
128 * @param speed speed to play the scene to
130 * The speed is relative to normal playback, e.g. 1.0 is normal speed, 0.0
131 * is paused, -1.0 means play backwards. It does not specify start/stop */
132 void play(double speed);
133 void switchPlay(bool play);
136 /** @brief Stops playing.
137 * @param startTime time to seek to */
138 void stop(const GenTime &startTime);
141 QImage extractFrame(int frame_position, QString path = QString(), int width = -1, int height = -1);
143 /** @brief Plays the scene starting from a specific time.
144 * @param startTime time to start playing the scene from */
145 void play(const GenTime & startTime);
146 void playZone(const GenTime & startTime, const GenTime & stopTime);
147 void loopZone(const GenTime & startTime, const GenTime & stopTime);
149 void saveZone(KUrl url, QString desc, QPoint zone);
151 /** @brief Returns the name of the renderer. */
152 const QString & rendererName() const;
154 /** @brief Returns the speed at which the renderer is currently playing.
156 * It returns 0.0 when the renderer is not playing anything. */
159 /** @brief Returns the current seek position of the renderer. */
160 GenTime seekPosition() const;
161 int seekFramePosition() const;
163 void emitFrameUpdated(Mlt::Frame&);
164 void emitFrameNumber(double position);
165 void emitConsumerStopped();
167 /** @brief Returns the aspect ratio of the consumer. */
168 double consumerRatio() const;
172 /** @brief Saves current producer frame as an image. */
173 void exportCurrentFrame(KUrl url, bool notify);
175 /** @brief Turns on or off on screen display. */
176 void refreshDisplay();
177 /** @brief Change the Mlt PROFILE
178 * @param profileName The MLT profile name
179 * @param dropSceneList If true, the current playlist will be deleted
181 int resetProfile(const QString& profileName, bool dropSceneList = false);
184 /** @brief Returns the width of a frame for this profile. */
185 int frameRenderWidth() const;
186 /** @brief Returns the display width of a frame for this profile. */
187 int renderWidth() const;
188 /** @brief Returns the height of a frame for this profile. */
189 int renderHeight() const;
191 /** @brief Returns display aspect ratio. */
193 /** @brief Returns sample aspect ratio. */
197 * Playlist manipulation.
199 Mlt::Producer *checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element);
200 int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite = false, bool push = false);
201 bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
202 void mltCutClip(int track, GenTime position);
203 void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset);
204 int mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart);
206 /** @brief Returns the duration/length of @param track as reported by the track producer. */
207 int mltTrackDuration(int track);
209 bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
210 bool mltResizeClipStart(ItemInfo info, GenTime diff);
211 bool mltResizeClipCrop(ItemInfo info, GenTime diff);
212 bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
213 bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
214 bool mltRemoveClip(int track, GenTime position);
216 /** @brief Deletes an effect from a clip in MLT's playlist. */
217 bool mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh = true);
218 bool mltRemoveTrackEffect(int track, int index, bool updateIndex);
220 /** @brief Adds an effect to a clip in MLT's playlist. */
221 bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
222 bool mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh);
223 bool mltAddTrackEffect(int track, EffectsParameterList params);
225 /** @brief Edits an effect parameters in MLT's playlist. */
226 bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
227 bool mltEditTrackEffect(int track, EffectsParameterList params);
229 /** @brief Updates the "kdenlive_ix" (index) value of an effect. */
230 void mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos);
232 /** @brief Changes the order of effects in MLT's playlist.
234 * It switches effects from oldPos and newPos, updating the "kdenlive_ix"
236 void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
237 void mltMoveTrackEffect(int track, int oldPos, int newPos);
239 /** @brief Enables/disables audio/video in a track. */
240 void mltChangeTrackState(int track, bool mute, bool blind);
241 bool mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
242 bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
243 void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
244 void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force = false);
245 void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
246 void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
247 void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
248 void mltDeleteTransparency(int pos, int track, int id);
249 void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
250 void mltInsertTrack(int ix, bool videoTrack);
251 void mltDeleteTrack(int ix);
252 bool mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
253 void mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track);
254 Mlt::Producer *invalidProducer(const QString &id);
256 /** @brief Changes the speed of a clip in MLT's playlist.
258 * It creates a new "framebuffer" producer, which must have its "resource"
259 * property set to "video.mpg?0.6", where "video.mpg" is the path to the
260 * clip and "0.6" is the speed in percentage. The newly created producer
261 * will have its "id" property set to "slowmotion:parentid:speed", where
262 * "parentid" is the id of the original clip in the ClipManager list and
263 * "speed" is the current speed. */
264 int mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double oldspeed, int strobe, Mlt::Producer *prod);
266 const QList <Mlt::Producer *> producersList();
267 void updatePreviewSettings();
268 void setDropFrames(bool show);
269 QString updateSceneListFps(double current_fps, double new_fps, QString scene);
270 void showFrame(Mlt::Frame&);
272 void showAudio(Mlt::Frame&);
273 /** @brief This property is used to decide if the renderer should send audio data for monitoring. */
276 QList <int> checkTrackSequence(int);
277 void sendFrameUpdate();
279 /** @brief Returns a pointer to the main producer. */
280 Mlt::Producer *getProducer();
281 /** @brief Returns the number of clips to process (When requesting clip info). */
282 int processingItems() const;
283 /** @brief Force processing of clip with selected id. */
284 void forceProcessing(const QString &id);
288 /** @brief The name of this renderer.
290 * Useful to identify the renderers by what they do - e.g. background
291 * rendering, workspace monitor, etc. */
293 Mlt::Consumer * m_mltConsumer;
294 Mlt::Producer * m_mltProducer;
295 Mlt::Profile *m_mltProfile;
296 double m_framePosition;
298 bool m_externalConsumer;
300 /** @brief True if we are playing a zone.
302 * It's determined by the "in" and "out" properties being temporarily
309 /** @brief True when the monitor is in split view. */
312 Mlt::Producer *m_blackClip;
313 QString m_activeProfile;
319 /** @brief A human-readable description of this renderer. */
323 QFuture <void> m_infoThread;
324 QList <requestClipInfo> m_requestList;
327 void mltCheckLength(Mlt::Tractor *tractor);
328 void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
329 QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
330 QMap<QString, Mlt::Producer *> m_slowmotionProducers;
332 /** @brief Build the MLT Consumer object with initial settings.
333 * @param profileName The MLT profile to use for the consumer */
334 void buildConsumer(const QString& profileName);
335 void resetZoneMode();
336 void fillSlowMotionProducers();
337 /** @brief Get the track number of the lowest audible (non muted) audio track
338 * @param return The track number */
339 int getLowestNonMutedAudioTrack(Mlt::Tractor tractor);
341 /** @brief Make sure our audio mixing transitions are applied to the lowest track */
342 void fixAudioMixing(Mlt::Tractor tractor);
346 /** @brief Refreshes the monitor display. */
348 void slotOsdTimeout();
349 int connectPlaylist();
350 //void initSceneList();
354 /** @brief The renderer received a reply to a getFileProperties request. */
355 void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const stringMap &, const stringMap &, bool replaceProducer, bool refreshThumbnail = false);
357 /** @brief The renderer received a reply to a getImage request. */
358 void replyGetImage(const QString &, const QString &, int, int);
359 void replyGetImage(const QString &, const QImage &);
361 /** @brief The renderer stopped, either playing or rendering. */
364 /** @brief The renderer started playing. */
365 void playing(double);
367 /** @brief The renderer started rendering. */
368 void rendering(const GenTime &);
370 /** @brief An error occurred within this renderer. */
371 void error(const QString &, const QString &);
372 void durationChanged(int);
373 void rendererPosition(int);
374 void rendererStopped(int);
375 /** @brief The clip is not valid, should be removed from project. */
376 void removeInvalidClip(const QString &, bool replaceProducer);
377 /** @brief The proxy is not valid, should be deleted.
378 * @param id The original clip's id
379 * @param durationError Should be set to true if the proxy failed because it has not same length as original clip
381 void removeInvalidProxy(const QString &id, bool durationError);
382 void refreshDocumentProducers(bool displayRatioChanged, bool fpsChanged);
384 /** @brief If we will delete the producer, make sure to pause the monitor */
385 void blockClipMonitor(const QString &);
387 /** @brief A frame's image has to be shown.
389 * Used in Mac OS X. */
390 void showImageSignal(QImage);
391 void showAudioSignal(const QByteArray &);
395 /** @brief Starts the consumer. */
398 /** @brief Stops the consumer. */
402 /** @brief Checks if the file is readable by MLT. */
403 bool isValid(KUrl url);
405 /** @brief Requests the file properties for the specified URL.
406 @param xml The xml parameters for the clip
407 @param clipId The clip Id string
408 @param imageHeight The height (in pixels) of the returned thumbnail (height of a treewidgetitem in projectlist)
409 @param replaceProducer If true, the MLT producer will be recreated
410 @param selectClip If true, clip item will be selected in project view
411 * Upon return, the result will be emitted via replyGetFileProperties().
412 * Wraps the VEML command of the same name. */
413 void getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer = true);
415 void getFileProperties2();
417 void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
418 void mltSavePlaylist();
419 void slotSplitView(bool doit);
420 void slotSwitchFullscreen();
421 void slotSetVolume(int volume);
422 void seekToFrame(int pos);