]> git.sesse.net Git - kdenlive/blobdiff - src/mltdevicecapture.cpp
Const'ref
[kdenlive] / src / mltdevicecapture.cpp
index aebcf41c549e9c3abfbfb8f4db494a19fb776921..425b81a6be28fedec74bc74e1f07a14197f3a1a0 100644 (file)
@@ -33,6 +33,7 @@
 #include <QString>
 #include <QApplication>
 #include <QThread>
+#include <QTimer>
 
 #include <cstdlib>
 #include <cstdarg>
@@ -48,12 +49,12 @@ static void consumer_gl_frame_show(mlt_consumer, MltDeviceCapture * self, mlt_fr
     self->showFrame(frame);
 }
 
-static void rec_consumer_frame_show(mlt_consumer, MltDeviceCapture * self, mlt_frame frame_ptr)
+/*static void rec_consumer_frame_show(mlt_consumer, MltDeviceCapture * self, mlt_frame frame_ptr)
 {
     Mlt::Frame frame(frame_ptr);
     if (!frame.is_valid()) return;
     self->gotCapturedFrame(frame);
-}
+}*/
 
 static void rec_consumer_frame_preview(mlt_consumer, MltDeviceCapture * self, mlt_frame frame_ptr)
 {
@@ -76,11 +77,10 @@ static void rec_consumer_frame_preview(mlt_consumer, MltDeviceCapture * self, ml
 }
 
 
-MltDeviceCapture::MltDeviceCapture(QString profile, VideoPreviewContainer *surface, QWidget *parent) :
-    AbstractRender("capture", parent),
+MltDeviceCapture::MltDeviceCapture(QString profile, VideoSurface *surface, QWidget *parent) :
+    AbstractRender(Kdenlive::recordMonitor, parent),
     doCapture(0),
     sendFrameForAnalysis(false),
-    analyseAudio(KdenliveSettings::monitor_audio()),
     processingImage(false),
     m_mltConsumer(NULL),
     m_mltProducer(NULL),
@@ -88,10 +88,12 @@ MltDeviceCapture::MltDeviceCapture(QString profile, VideoPreviewContainer *surfa
     m_showFrameEvent(NULL),
     m_droppedFrames(0),
     m_livePreview(KdenliveSettings::enable_recording_preview()),
-    m_captureDisplayWidget(surface),
     m_winid((int) surface->winId())
 {
-    if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
+    m_captureDisplayWidget = surface;
+    analyseAudio = KdenliveSettings::monitor_audio();
+    if (profile.isEmpty())
+        profile = KdenliveSettings::current_profile();
     buildConsumer(profile);
     connect(this, SIGNAL(unblockPreview()), this, SLOT(slotPreparePreview()));
     m_droppedFramesTimer.setSingleShot(false);
@@ -163,19 +165,29 @@ void MltDeviceCapture::buildConsumer(const QString &profileName)
     //m_mltConsumer->set("real_time", 0);
 }
 
+void MltDeviceCapture::pause()
+{   
+    if (m_mltConsumer) {
+          m_mltConsumer->set("refresh", 0);
+         //m_mltProducer->set_speed(0.0);
+         m_mltConsumer->purge();
+    }
+}
+
 void MltDeviceCapture::stop()
 {
     m_droppedFramesTimer.stop();
     bool isPlaylist = false;
-    disconnect(this, SIGNAL(imageReady(QImage)), this, SIGNAL(frameUpdated(QImage)));
-    m_captureDisplayWidget->stop();
+    //disconnect(this, SIGNAL(imageReady(QImage)), this, SIGNAL(frameUpdated(QImage)));
+    //m_captureDisplayWidget->stop();
     
     if (m_showFrameEvent) delete m_showFrameEvent;
     m_showFrameEvent = NULL;
     
     if (m_mltConsumer) {
         m_mltConsumer->set("refresh", 0);
-        m_mltConsumer->stop();
+        m_mltConsumer->purge();
+       m_mltConsumer->stop();
         //if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
     }
     if (m_mltProducer) {
@@ -215,9 +227,16 @@ void MltDeviceCapture::stop()
 }
 
 
-void MltDeviceCapture::doRefresh()
+void MltDeviceCapture::slotDoRefresh()
 {
-    if (m_mltConsumer) m_mltConsumer->set("refresh", 1);
+    QMutexLocker locker(&m_mutex);
+    if (!m_mltProducer)
+        return;
+    if (m_mltConsumer) {
+        if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
+        m_mltConsumer->purge();
+        m_mltConsumer->set("refresh", 1);
+    }
 }
 
 
@@ -239,9 +258,10 @@ void MltDeviceCapture::emitFrameUpdated(Mlt::Frame& frame)
     int width = 0;
     int height = 0;
     const uchar* image = frame.get_image(format, width, height);
-    QImage qimage(width, height, QImage::Format_ARGB32);
+    QImage qimage(width, height, QImage::Format_RGB888);
+    //QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
     memcpy(qimage.bits(), image, width * height * 3);
-    emit frameUpdated(qimage.rgbSwapped());
+    emit frameUpdated(qimage);
 }
 
 void MltDeviceCapture::showFrame(Mlt::Frame& frame)
@@ -308,7 +328,7 @@ bool MltDeviceCapture::slotStartPreview(const QString &producer, bool xmlFormat)
         return 0;
     }
     m_droppedFramesTimer.start();
-    connect(this, SIGNAL(imageReady(QImage)), this, SIGNAL(frameUpdated(QImage)));
+    //connect(this, SIGNAL(imageReady(QImage)), this, SIGNAL(frameUpdated(QImage)));
     return 1;
 }
 
@@ -343,7 +363,7 @@ void MltDeviceCapture::gotCapturedFrame(Mlt::Frame& frame)
     //memcpy(image.bits(), data, width * height * 3);
     QImage image((uchar *)data, width, height, QImage::Format_RGB888);
 
-    m_captureDisplayWidget->setImage(image);
+    //m_captureDisplayWidget->setImage(image);
 
     //TEST: is it better to process frame conversion ouside MLT???
     /*
@@ -433,15 +453,15 @@ bool MltDeviceCapture::slotStartCapture(const QString &params, const QString &pa
     renderProps->set("mlt_service", "avformat");
     renderProps->set("target", path.toUtf8().constData());
     renderProps->set("real_time", -KdenliveSettings::mltthreads());
-    renderProps->set("terminate_on_pause", 0);
+    //renderProps->set("terminate_on_pause", 0);
     renderProps->set("mlt_profile", m_activeProfile.toUtf8().constData());
     
 
-    QStringList paramList = params.split(" ", QString::SkipEmptyParts);
+    QStringList paramList = params.split(' ', QString::SkipEmptyParts);
     char *tmp2;
-    for (int i = 0; i < paramList.count(); i++) {
-        tmp = qstrdup(paramList.at(i).section("=", 0, 0).toUtf8().constData());
-        QString value = paramList.at(i).section("=", 1, 1);
+    for (int i = 0; i < paramList.count(); ++i) {
+        tmp = qstrdup(paramList.at(i).section('=', 0, 0).toUtf8().constData());
+        QString value = paramList.at(i).section('=', 1, 1);
         if (value == "%threads") value = QString::number(QThread::idealThreadCount());
         tmp2 = qstrdup(value.toUtf8().constData());
         renderProps->set(tmp, tmp2);
@@ -502,19 +522,25 @@ bool MltDeviceCapture::slotStartCapture(const QString &params, const QString &pa
         
     }
     
-    tmp = qstrdup(playlist.toUtf8().constData());
     if (xmlPlaylist) {
         // create an xml producer
-        m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
+        m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
     }
     else {
         // create a producer based on mltproducer parameter
-        m_mltProducer = new Mlt::Producer(*m_mltProfile, tmp);
+        m_mltProducer = new Mlt::Producer(*m_mltProfile, playlist.toUtf8().constData());
     }
-    delete[] tmp;
 
     if (m_mltProducer == NULL || !m_mltProducer->is_valid()) {
         kDebug()<<"//// ERROR CREATRING PROD";
+       if (m_mltConsumer) {
+            delete m_mltConsumer;
+            m_mltConsumer = NULL;
+        }
+       if (m_mltProducer) {
+           delete m_mltProducer;
+           m_mltProducer = NULL;
+       }
         return false;
     }
     
@@ -588,7 +614,7 @@ void MltDeviceCapture::setOverlay(const QString &path)
     //delete clip;
 }
 
-void MltDeviceCapture::setOverlayEffect(const QString &tag, QStringList parameters)
+void MltDeviceCapture::setOverlayEffect(const QString &tag, const QStringList &parameters)
 {
     if (m_mltProducer == NULL || !m_mltProducer->is_valid()) return;
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -626,7 +652,7 @@ void MltDeviceCapture::setOverlayEffect(const QString &tag, QStringList paramete
     delete[] tmp;
     if (filter && filter->is_valid()) {
         for (int j = 0; j < parameters.count(); j++) {
-            filter->set(parameters.at(j).section("=", 0, 0).toUtf8().constData(), parameters.at(j).section("=", 1, 1).toUtf8().constData());
+            filter->set(parameters.at(j).section('=', 0, 0).toUtf8().constData(), parameters.at(j).section('=', 1, 1).toUtf8().constData());
         }
         trackService.attach(*filter);
     }
@@ -731,7 +757,7 @@ void MltDeviceCapture::uyvy2rgb(unsigned char *yuv_buffer, int width, int height
         rgb_ptr += 3;
     }
     //emit imageReady(image);
-    m_captureDisplayWidget->setImage(image);
+    //m_captureDisplayWidget->setImage(image);
     emit unblockPreview();
     //processingImage = false;
 }
@@ -747,3 +773,5 @@ void MltDeviceCapture::slotAllowPreview()
 }
 
 
+
+#include "mltdevicecapture.moc"