diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,7 +89,7 @@ set(KF5_ICON_COMPATIBILITY TRUE) endif() -find_package(KF5 REQUIRED COMPONENTS Archive Bookmarks CoreAddons Config ConfigWidgets +find_package(KF5 REQUIRED COMPONENTS Archive Bookmarks CoreAddons Config ConfigWidgets DBusAddons KIO WidgetsAddons NotifyConfig NewStuff XmlGui Notifications GuiAddons TextWidgets IconThemes OPTIONAL_COMPONENTS DocTools FileMetaData Crash) @@ -102,7 +102,7 @@ # Search MLT package. find_package(MLT ${MLT_MIN_VERSION} REQUIRED) -set_package_properties(MLT PROPERTIES +set_package_properties(MLT PROPERTIES DESCRIPTION "Multimedia framework and video playout server for TV broadcasting" URL "http://mltframework.org" TYPE RUNTIME diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,8 @@ PURPOSE "") endif() -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -Wextra") +SET(CMAKE_CXX_STANDARD 14) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wcast-align -Wfloat-equal -Wpointer-arith") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunreachable-code -Wchar-subscripts -Wcomment -Wformat") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror-implicit-function-declaration -Wmain -Wmissing-braces") @@ -54,7 +55,7 @@ set(FFMPEG_SUFFIX "" CACHE STRING "FFmpeg custom suffix") find_package(LibV4L2) -set_package_properties(LibV4L2 PROPERTIES +set_package_properties(LibV4L2 PROPERTIES DESCRIPTION "Collection of video4linux support libraries" URL "http://freecode.com/projects/libv4l" TYPE RUNTIME @@ -336,4 +337,3 @@ install(TARGETS kdenlive DESTINATION ${BIN_INSTALL_DIR}) install(FILES kdenliveui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kdenlive) - diff --git a/src/core.h b/src/core.h --- a/src/core.h +++ b/src/core.h @@ -33,6 +33,10 @@ #define EXIT_RESTART (42) #define pCore Core::self() +// Floating point comparisons +#define FLOAT_DELTA 0.001 +#define FLOAT_EQ(a, b) (std::abs((a) - (b)) < (FLOAT_DELTA)) + /** * @class Core * @brief Singleton that provides access to the different parts of Kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -160,7 +161,7 @@ time = qBound(0, time, m_mltProducer->get_length() - 1); if (requestedSeekPosition == SEEK_INACTIVE) { requestedSeekPosition = time; - if (m_mltProducer->get_speed() != 0) { + if (!FLOAT_EQ(m_mltProducer->get_speed(), 0)) { m_mltConsumer->purge(); } m_mltProducer->seek(time); @@ -212,20 +213,18 @@ pix.fill(Qt::black); return pix; } - Mlt::Frame *frame = nullptr; QImage img; bool profileFromSource = m_mltProducer->get_int("meta.media.width") > width; if (KdenliveSettings::gpu_accel() && !profileFromSource) { QString service = m_mltProducer->get("mlt_service"); - QScopedPointer tmpProd(new Mlt::Producer(*m_qmlView->profile(), service.toUtf8().constData(), m_mltProducer->get("resource"))); + std::unique_ptr tmpProd(std::make_unique(*m_qmlView->profile(), service.toUtf8().constData(), m_mltProducer->get("resource"))); Mlt::Filter scaler(*m_qmlView->profile(), "swscale"); Mlt::Filter converter(*m_qmlView->profile(), "avcolor_space"); tmpProd->attach(scaler); tmpProd->attach(converter); tmpProd->seek(m_mltProducer->position()); - frame = tmpProd->get_frame(); - img = KThumb::getFrame(frame, width, height); - delete frame; + std::unique_ptr frame(tmpProd->get_frame()); + img = KThumb::getFrame(frame.get(), width, height); } else if (profileFromSource) { // Our source clip's resolution is higher than current profile, export at full res QScopedPointer tmpProfile(new Mlt::Profile()); @@ -242,14 +241,12 @@ //Clip clp2(*m_mltProducer); Clip(*tmpProd).addEffects(*m_mltProducer); tmpProd->seek(m_mltProducer->position()); - frame = tmpProd->get_frame(); - img = KThumb::getFrame(frame, width, height); - delete frame; + std::unique_ptr frame(tmpProd->get_frame()); + img = KThumb::getFrame(frame.get(), width, height); } } else { - frame = m_mltProducer->get_frame(); - img = KThumb::getFrame(frame, width, height); - delete frame; + std::unique_ptr frame(m_mltProducer->get_frame()); + img = KThumb::getFrame(frame.get(), width, height); } return img; } @@ -513,12 +510,12 @@ } blockSignals(false); Mlt::Tractor tractor(service); - Mlt::Properties retainList((mlt_properties) tractor.get_data("xml_retain")); + Mlt::Properties retainList(static_cast(tractor.get_data("xml_retain"))); if (retainList.is_valid() && retainList.get_data(m_binController->binPlaylistId().toUtf8().constData())) { - Mlt::Playlist playlist((mlt_playlist) retainList.get_data(m_binController->binPlaylistId().toUtf8().constData())); - if (playlist.is_valid() && playlist.type() == playlist_type) { + Mlt::Playlist newPlaylist(static_cast(retainList.get_data(m_binController->binPlaylistId().toUtf8().constData()))); + if (newPlaylist.is_valid() && newPlaylist.type() == playlist_type) { // Load bin clips - m_binController->initializeBin(playlist); + m_binController->initializeBin(newPlaylist); } } // No Playlist found, create new one @@ -631,13 +628,12 @@ xmlConsumer.run(); } else { Mlt::Producer prod(m_mltProducer->get_producer()); - Mlt::Producer *prod2 = prod.cut(zone.x(), zone.y()); + std::unique_ptr prod2(prod.cut(zone.x(), zone.y())); Mlt::Playlist list(*m_mltProducer->profile()); list.insert_at(0, *prod2, 0); //list.set("title", desc.toUtf8().constData()); xmlConsumer.connect(list); xmlConsumer.run(); - delete prod2; } } @@ -762,7 +758,7 @@ m_mltConsumer->stop(); } } - if (currentSpeed == 0) { + if (FLOAT_EQ(currentSpeed, 0)) { m_mltConsumer->start(); m_isRefreshing = true; m_mltConsumer->set("refresh", 1); @@ -787,14 +783,14 @@ if (!m_mltProducer || !m_isActive) { return; } - double current_speed = m_mltProducer->get_speed(); - if (current_speed == speed) { + double currentSpeed = m_mltProducer->get_speed(); + if (FLOAT_EQ(currentSpeed, speed)) { return; } if (m_isZoneMode) { resetZoneMode(); } - if (speed != 0 && m_mltConsumer->get_int("real_time") != m_qmlView->realTime()) { + if (!FLOAT_EQ(speed, 0) && m_mltConsumer->get_int("real_time") != m_qmlView->realTime()) { m_mltConsumer->set("real_time", m_qmlView->realTime()); m_mltConsumer->set("buffer", 25); m_mltConsumer->set("prefill", 1); @@ -803,7 +799,7 @@ m_mltConsumer->stop(); } } - if (current_speed == 0) { + if (FLOAT_EQ(currentSpeed, 0)) { m_mltConsumer->start(); m_isRefreshing = true; m_mltConsumer->set("refresh", 1); @@ -892,7 +888,7 @@ void Render::doRefresh() { - if (m_mltProducer && (playSpeed() == 0) && m_isActive) { + if (m_mltProducer && FLOAT_EQ(playSpeed(), 0) && m_isActive) { if (m_isRefreshing) { m_refreshTimer.start(); } else { @@ -953,7 +949,7 @@ if (!m_mltConsumer || m_mltConsumer->is_stopped()) { return false; } - return playSpeed() != 0; + return !FLOAT_EQ(playSpeed(), 0); } double Render::playSpeed() const @@ -975,7 +971,7 @@ int Render::seekFramePosition() const { - if (m_mltProducer && m_mltProducer->get_speed() == 0) { + if (m_mltProducer && FLOAT_EQ(m_mltProducer->get_speed(), 0)) { return (int) m_mltProducer->position(); } if (m_mltConsumer) { @@ -1019,12 +1015,12 @@ if (requestedSeekPosition != SEEK_INACTIVE) { m_mltProducer->set_speed(0); m_mltProducer->seek(requestedSeekPosition); - if (speed == 0) { + if (FLOAT_EQ(speed, 0)) { m_mltConsumer->set("refresh", 1); } else { m_mltProducer->set_speed(speed); } - } else if (speed < 0){ + } else if (speed < 0) { m_isRefreshing = false; if (pos <= 0) { m_mltProducer->set_speed(0); @@ -1040,7 +1036,7 @@ m_mltProducer->set_speed(1.0); m_mltConsumer->set("refresh", 1); } else { - if (speed == 0) { + if (FLOAT_EQ(speed, 0)) { return false; } } @@ -1069,7 +1065,7 @@ int freq = 48000; int num_channels = 2; int samples = 0; - qint16 *data = (qint16 *)frame.get_audio(audio_format, freq, num_channels, samples); + const qint16 *data = static_cast(frame.get_audio(audio_format, freq, num_channels, samples)); if (!data) { return; @@ -1078,7 +1074,7 @@ // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels. // So the vector is of size samples*channels. audioShortVector sampleVector(samples * num_channels); - memcpy(sampleVector.data(), data, samples * num_channels * sizeof(qint16)); + memcpy(sampleVector.data(), data, static_cast(samples) * static_cast(num_channels) * sizeof(qint16)); if (samples > 0) { emit audioSamplesSignal(sampleVector, freq, num_channels, samples); @@ -1120,9 +1116,8 @@ blackTrackPlaylist.clear(); m_blackClip->set("length", duration + 1); m_blackClip->set("out", duration); - Mlt::Producer *black2 = m_blackClip->cut(0, duration); - blackTrackPlaylist.insert_at(0, black2, 1); - delete black2; + std::unique_ptr black2(m_blackClip->cut(0, duration)); + blackTrackPlaylist.insert_at(0, black2.get(), 1); } else { if (duration > blackclip->parent().get_length()) { blackclip->parent().set("length", duration + 1); @@ -1455,16 +1450,15 @@ int trackNb = tractor.count(); for (int t = 1; t < trackNb; ++t) { - Mlt::Producer *tt = tractor.track(t); - Mlt::Producer trackProducer(tt); - delete tt; + std::unique_ptr tt(tractor.track(t)); + Mlt::Producer trackProducer(tt.get()); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); if (!trackPlaylist.is_valid()) { continue; } int clipNb = trackPlaylist.count(); for (int i = 0; i < clipNb; ++i) { - QScopedPointer c(trackPlaylist.get_clip(i)); + std::unique_ptr c(trackPlaylist.get_clip(i)); Mlt::Producer *nprod = new Mlt::Producer(c->get_parent()); if (nprod) { QString id = nprod->parent().get("id"); @@ -1559,9 +1553,8 @@ void Render::sendFrameUpdate() { if (m_mltProducer) { - Mlt::Frame *frame = m_mltProducer->get_frame(); + std::unique_ptr frame(m_mltProducer->get_frame()); emitFrameUpdated(*frame); - delete frame; } } @@ -1656,11 +1649,10 @@ double Render::getMltVersionInfo(const QString &tag) { double version = 0; - Mlt::Properties *metadata = pCore->getMltRepository()->metadata(producer_type, tag.toUtf8().data()); + std::unique_ptr metadata(pCore->getMltRepository()->metadata(producer_type, tag.toUtf8().data())); if (metadata && metadata->is_valid()) { version = metadata->get_double("version"); } - delete metadata; return version; } @@ -1701,8 +1693,7 @@ m_slowmotionProducers.insert(url, prod); return true; } else if (replace) { - Mlt::Producer *old = m_slowmotionProducers.take(url); - delete old; + delete m_slowmotionProducers.take(url); // Free old url m_slowmotionProducers.insert(url, prod); return true; } @@ -1749,4 +1740,3 @@ xmlConsumer.connect(prod); xmlConsumer.run(); } -