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