]> git.sesse.net Git - kdenlive/blobdiff - src/mltdevicecapture.cpp
remove debug
[kdenlive] / src / mltdevicecapture.cpp
index b70376646b2a318fc3c1f63f5b9e1073f272bc1e..8414b074d4476f54e6c4aa70c671ab48a815f0a8 100644 (file)
@@ -71,11 +71,11 @@ static void rec_consumer_frame_preview(mlt_consumer, MltDeviceCapture * self, ml
     }
 
     //TODO: connect record monitor to audio scopes
-    /*
+    
     if (self->analyseAudio) {
         self->showAudio(frame);
     }
-    */
+    
 }
 
 
@@ -83,15 +83,16 @@ MltDeviceCapture::MltDeviceCapture(QString profile, VideoPreviewContainer *surfa
     AbstractRender("capture", parent),
     doCapture(0),
     sendFrameForAnalysis(false),
+    analyseAudio(KdenliveSettings::monitor_audio()),
+    processingImage(false),
     m_mltConsumer(NULL),
     m_mltProducer(NULL),
     m_mltProfile(NULL),
+    m_showFrameEvent(NULL),
     m_droppedFrames(0),
     m_livePreview(KdenliveSettings::recording_preview()),
     m_captureDisplayWidget(surface),
-    m_winid((int) surface->winId()),
-    analyseAudio(KdenliveSettings::monitor_audio()),
-    processingImage(false)
+    m_winid((int) surface->winId())
 {
     if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
     buildConsumer(profile);
@@ -114,7 +115,7 @@ void MltDeviceCapture::buildConsumer(const QString &profileName)
     char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
     setenv("MLT_PROFILE", tmp, 1);
     m_mltProfile = new Mlt::Profile(tmp);
-    m_mltProfile->get_profile()->is_explicit = 1;
+    m_mltProfile->set_explicit(true);
     delete[] tmp;
 
     QString videoDriver = KdenliveSettings::videodrivername();
@@ -133,11 +134,11 @@ void MltDeviceCapture::buildConsumer(const QString &profileName)
         m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
         m_mltConsumer->set("preview_off", 1);
         m_mltConsumer->set("preview_format", mlt_image_rgb24);
-        m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
+        m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
     } else {
         m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
         m_mltConsumer->set("window_id", m_winid);
-        m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) rec_consumer_frame_preview);
+        m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) rec_consumer_frame_preview);
     }
     //m_mltConsumer->set("resize", 1);
     //m_mltConsumer->set("terminate_on_pause", 1);
@@ -166,6 +167,10 @@ void MltDeviceCapture::stop()
     bool isPlaylist = false;
     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();
@@ -195,20 +200,6 @@ void MltDeviceCapture::stop()
                 mlt_type = mlt_properties_get(properties, "mlt_type");
                 resource = mlt_properties_get(properties, "mlt_service");
             }
-            for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
-                Mlt::Producer trackProducer(tractor.track(trackNb));
-                Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-                if (trackPlaylist.type() == playlist_type) {
-                    for (int i = 0; i < trackPlaylist.count();i++) {
-                        // We need to manually decrease the ref count and close the producer, otherwise
-                        // the video4linux device stays open, seems like a bug in MLT that is not cleaning properly
-                        mlt_properties props = MLT_PRODUCER_PROPERTIES(trackPlaylist.get_clip(i)->get_parent());
-                        while (mlt_properties_ref_count(props) > 0) mlt_properties_dec_ref(props);
-                        if (trackPlaylist.get_clip(i)) mlt_producer_close(trackPlaylist.get_clip(i)->get_parent());
-                    }
-                    mlt_playlist_close(trackPlaylist.get_playlist());
-                }
-            }
             delete field;
             field = NULL;
         }
@@ -285,7 +276,6 @@ void MltDeviceCapture::showAudio(Mlt::Frame& frame)
     // So the vector is of size samples*channels.
     QVector<int16_t> sampleVector(samples*num_channels);
     memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
-
     if (samples > 0) {
         emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
     }
@@ -372,7 +362,7 @@ void MltDeviceCapture::saveFrame(Mlt::Frame& frame)
     Mlt::Producer trackProducer(tractor.track(0));
     trackProducer.set("hide", 0);
     
-    qimage.rgbSwapped().save(m_capturePath);
+    qimage.save(m_capturePath);
     emit frameSaved(m_capturePath);
     m_capturePath.clear();
 }
@@ -408,7 +398,7 @@ bool MltDeviceCapture::slotStartCapture(const QString &params, const QString &pa
     kDebug()<<"-- CREATING CAP: "<<params<<", PATH: "<<path;
     tmp = qstrdup(QString("avformat:" + path).toUtf8().constData());
     m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
-    m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
+    m_mltConsumer->set("real_time", -KdenliveSettings::mltthreads());
     delete[] tmp;
 
     QStringList paramList = params.split(" ", QString::SkipEmptyParts);
@@ -431,8 +421,7 @@ bool MltDeviceCapture::slotStartCapture(const QString &params, const QString &pa
         return false;
     }
     
-    // FIXME: the event object returned by the listen gets leaked...
-    m_mltConsumer->listen("consumer-frame-render", this, (mlt_listener) rec_consumer_frame_show);
+    if (m_livePreview < 2) m_showFrameEvent = m_mltConsumer->listen("consumer-frame-render", this, (mlt_listener) rec_consumer_frame_show);
     tmp = qstrdup(playlist.toUtf8().constData());
     if (xmlPlaylist) {
         // create an xml producer
@@ -451,6 +440,8 @@ bool MltDeviceCapture::slotStartCapture(const QString &params, const QString &pa
     
     m_mltConsumer->connect(*m_mltProducer);
     if (m_mltConsumer->start() == -1) {
+        if (m_showFrameEvent) delete m_showFrameEvent;
+        m_showFrameEvent = NULL;
         delete m_mltConsumer;
         m_mltConsumer = NULL;
         return 0;
@@ -506,7 +497,7 @@ void MltDeviceCapture::setOverlay(const QString &path)
         Mlt::Field *field = tractor.field();
         Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
         transition->set_in_and_out(0, 0);
-        transition->set("geometry", "0,0:100%x100%:70");
+        transition->set("geometry", "0/0:100%x100%:70");
         transition->set("fill", 1);
         transition->set("operator", "and");
         transition->set("a_track", 0);
@@ -517,7 +508,7 @@ void MltDeviceCapture::setOverlay(const QString &path)
     //delete clip;
 }
 
-void MltDeviceCapture::setOverlayEffect(const QString tag, QStringList parameters)
+void MltDeviceCapture::setOverlayEffect(const QString &tag, QStringList parameters)
 {
     if (m_mltProducer == NULL || !m_mltProducer->is_valid()) return;
     Mlt::Service service(m_mltProducer->parent().get_service());