File indexing completed on 2024-04-21 04:51:18
0001 /* 0002 SPDX-FileCopyrightText: 2011 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #pragma once 0007 0008 #include "definitions.h" 0009 #include "gentime.h" 0010 #include "monitor/abstractmonitor.h" 0011 0012 #include <QMutex> 0013 #include <QTimer> 0014 0015 // include after QTimer to have C++ pthreads defined 0016 #include <mlt/framework/mlt_types.h> 0017 0018 namespace Mlt { 0019 class Consumer; 0020 class Frame; 0021 class Event; 0022 class Producer; 0023 class Profile; 0024 } // namespace Mlt 0025 0026 /** @class MltDeviceCapture 0027 @brief Interface for MLT capture. 0028 Capturing started by MltDeviceCapture::slotStartCapture () 0029 Capturing is stopped by RecMonitor::slotStopCapture() 0030 */ 0031 class MltDeviceCapture : public AbstractRender 0032 { 0033 Q_OBJECT public : 0034 0035 enum FailStates { 0036 OK = 0, 0037 APP_NOEXIST 0038 }; 0039 /** @brief Build a MLT Renderer 0040 * @param winid The parent widget identifier (required for SDL display). Set to 0 for OpenGL rendering 0041 * @param profile The MLT profile used for the capture (default one will be used if empty). */ 0042 explicit MltDeviceCapture(const QString &profile, /*VideoSurface *surface,*/ QWidget *parent = nullptr); 0043 0044 /** @brief Destroy the MLT Renderer. */ 0045 ~MltDeviceCapture() override; 0046 0047 int doCapture; 0048 0049 /** @brief Someone needs us to send again a frame. */ 0050 void sendFrameUpdate() override {} 0051 0052 void emitFrameUpdated(Mlt::Frame & /*frame*/); 0053 void emitFrameNumber(double position); 0054 void emitConsumerStopped(); 0055 void showFrame(Mlt::Frame & /*frame*/); 0056 void showAudio(Mlt::Frame & /*frame*/); 0057 0058 void saveFrame(Mlt::Frame &frame); 0059 0060 /** @brief Starts the MLT Video4Linux process. 0061 * @param surface The widget onto which the frame should be painted 0062 * Called by RecMonitor::slotRecord () 0063 */ 0064 bool slotStartCapture(const QString ¶ms, const QString &path, const QString &playlist, bool livePreview, bool xmlPlaylist = true); 0065 bool slotStartPreview(const QString &producer, bool xmlFormat = false); 0066 /** @brief Save current frame to file. */ 0067 void captureFrame(const QString &path); 0068 0069 /** @brief This will add the video clip from path and add it in the overlay track. */ 0070 void setOverlay(const QString &path); 0071 0072 /** @brief This will add an MLT video effect to the overlay track. */ 0073 void setOverlayEffect(const QString &tag, const QStringList ¶meters); 0074 0075 /** @brief This will add a horizontal flip effect, easier to work when filming yourself. */ 0076 void mirror(bool activate); 0077 0078 /** @brief True if we are processing an image (yuv > rgb) when recording. */ 0079 bool processingImage; 0080 0081 void pause(); 0082 0083 private: 0084 Mlt::Consumer *m_mltConsumer; 0085 Mlt::Producer *m_mltProducer; 0086 Mlt::Profile *m_mltProfile; 0087 Mlt::Event *m_showFrameEvent; 0088 QString m_activeProfile; 0089 int m_droppedFrames; 0090 /** @brief When true, images will be displayed on monitor while capturing. */ 0091 bool m_livePreview; 0092 /** @brief Count captured frames, used to display only one in ten images while capturing. */ 0093 int m_frameCount{}; 0094 0095 void uyvy2rgb(const unsigned char *yuv_buffer, int width, int height); 0096 0097 QString m_capturePath; 0098 0099 QTimer m_droppedFramesTimer; 0100 0101 QMutex m_mutex; 0102 0103 /** @brief Build the MLT Consumer object with initial settings. 0104 * @param profileName The MLT profile to use for the consumer 0105 * @returns true if consumer is valid */ 0106 bool buildConsumer(const QString &profileName = QString()); 0107 0108 private Q_SLOTS: 0109 void slotPreparePreview(); 0110 void slotAllowPreview(); 0111 /** @brief When capturing, check every second for dropped frames. */ 0112 void slotCheckDroppedFrames(); 0113 0114 Q_SIGNALS: 0115 /** @brief A frame's image has to be shown. 0116 * 0117 * Used in Mac OS X. */ 0118 void showImageSignal(const QImage &); 0119 0120 void frameSaved(const QString &); 0121 0122 void droppedFrames(int); 0123 0124 void unblockPreview(); 0125 void imageReady(const QImage &); 0126 0127 public Q_SLOTS: 0128 /** @brief Stops the consumer. */ 0129 void stop(); 0130 };