]> git.sesse.net Git - kdenlive/blob - src/mltdevicecapture.h
Merge branch 'master' into audioAlign
[kdenlive] / src / mltdevicecapture.h
1 /***************************************************************************
2                          mltdevicecapture.h  -  description
3                             -------------------
4    begin                : Sun May 21 2011
5    copyright            : (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)
6
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 MltDeviceCapture
20  * @brief Interface for MLT capture.
21  */
22
23 #ifndef MLTDEVICECAPTURE_H
24 #define MLTDEVICECAPTURE_H
25
26 #include "gentime.h"
27 #include "definitions.h"
28 #include "abstractmonitor.h"
29
30 #include <mlt/framework/mlt_types.h>
31
32 #include <QtConcurrentRun>
33
34 namespace Mlt
35 {
36 class Consumer;
37 class Frame;
38 class Event;
39 class Producer;
40 class Profile;
41 };
42
43 class MltDeviceCapture: public AbstractRender
44 {
45 Q_OBJECT public:
46
47     enum FailStates { OK = 0,
48                       APP_NOEXIST
49                     };
50     /** @brief Build a MLT Renderer
51      *  @param winid The parent widget identifier (required for SDL display). Set to 0 for OpenGL rendering
52      *  @param profile The MLT profile used for the capture (default one will be used if empty). */
53     MltDeviceCapture(QString profile, VideoSurface *surface, QWidget *parent = 0);
54
55     /** @brief Destroy the MLT Renderer. */
56     ~MltDeviceCapture();
57
58     int doCapture;
59
60     /** @brief This property is used to decide if the renderer should convert it's frames to QImage for use in other Kdenlive widgets. */
61     bool sendFrameForAnalysis;
62
63     /** @brief Someone needs us to send again a frame. */
64     void sendFrameUpdate() {};
65     
66     void emitFrameUpdated(Mlt::Frame&);
67     void emitFrameNumber(double position);
68     void emitConsumerStopped();
69     void showFrame(Mlt::Frame&);
70     void showAudio(Mlt::Frame&);
71
72     void saveFrame(Mlt::Frame& frame);
73
74     /** @brief Starts the MLT Video4Linux process.
75      * @param surface The widget onto which the frame should be painted
76      */
77     bool slotStartCapture(const QString &params, const QString &path, const QString &playlist, bool livePreview, bool xmlPlaylist = true);
78     bool slotStartPreview(const QString &producer, bool xmlFormat = false);
79     /** @brief A frame arrived from the MLT Video4Linux process. */
80     void gotCapturedFrame(Mlt::Frame& frame);
81     /** @brief Save current frame to file. */
82     void captureFrame(const QString &path);
83     
84     /** @brief This will add the video clip from path and add it in the overlay track. */
85     void setOverlay(const QString &path);
86
87     /** @brief This will add an MLT video effect to the overlay track. */
88     void setOverlayEffect(const QString &tag, QStringList parameters);
89
90     /** @brief This will add a horizontal flip effect, easier to work when filming yourself. */
91     void mirror(bool activate);
92     
93     /** @brief True if we are processing an image (yuv > rgb) when recording. */
94     bool processingImage;
95     
96     void pause();
97
98 private:
99     Mlt::Consumer * m_mltConsumer;
100     Mlt::Producer * m_mltProducer;
101     Mlt::Profile *m_mltProfile;
102     Mlt::Event *m_showFrameEvent;
103     QString m_activeProfile;
104     int m_droppedFrames;
105     /** @brief When true, images will be displayed on monitor while capturing. */
106     bool m_livePreview;
107     /** @brief Count captured frames, used to display only one in ten images while capturing. */
108     int m_frameCount;
109
110     /** @brief The surface onto which the captured frames should be painted. */
111     VideoSurface *m_captureDisplayWidget;
112
113     /** @brief A human-readable description of this renderer. */
114     int m_winid;
115
116     void uyvy2rgb(unsigned char *yuv_buffer, int width, int height);
117
118     QString m_capturePath;
119     
120     QTimer m_droppedFramesTimer;
121     
122     QMutex m_mutex;
123
124     /** @brief Build the MLT Consumer object with initial settings.
125      *  @param profileName The MLT profile to use for the consumer */
126     void buildConsumer(const QString &profileName = QString());
127
128
129 private slots:
130     void slotPreparePreview();
131     void slotAllowPreview();
132     /** @brief When capturing, check every second for dropped frames. */
133     void slotCheckDroppedFrames();
134   
135 signals:
136     /** @brief A frame's image has to be shown.
137      *
138      * Used in Mac OS X. */
139     void showImageSignal(QImage);
140
141     void frameSaved(const QString &);
142     
143     void droppedFrames(int);
144     
145     void unblockPreview();
146     void imageReady(QImage);
147
148
149 public slots:
150
151     /** @brief Stops the consumer. */
152     void stop();
153     void slotDoRefresh();
154 };
155
156 #endif