From 576d3f00984ad57d87c30daf6731d795f7262720 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 8 Dec 2018 20:42:41 +1100 Subject: [PATCH] fixed several memory leaks and image sequences not matching when loading --- io/media.cpp | 2 +- io/media.h | 2 +- panels/project.cpp | 6 +++++- playback/cacher.cpp | 17 ++++++++++------- project/clip.cpp | 4 +++- project/clip.h | 2 ++ project/effect.cpp | 5 +++++ project/effectrow.cpp | 2 +- project/effectrow.h | 2 ++ ui/collapsiblewidget.cpp | 2 +- ui/collapsiblewidget.h | 1 + ui/labelslider.cpp | 6 +++--- 12 files changed, 35 insertions(+), 16 deletions(-) diff --git a/io/media.cpp b/io/media.cpp index f9cc4d8bc..8dd4674a9 100644 --- a/io/media.cpp +++ b/io/media.cpp @@ -10,7 +10,7 @@ extern "C" { #include "project/clip.h" -Media::Media() : ready(false), preview_gen(NULL), invalid(false) { +Media::Media() : ready(false), preview_gen(NULL), invalid(false), in(0), out(0) { ready_lock.lock(); } diff --git a/io/media.h b/io/media.h index 9d1312f06..35e65e4aa 100644 --- a/io/media.h +++ b/io/media.h @@ -45,7 +45,7 @@ struct Media { Media(); ~Media(); - QString url; + QString url; QString name; int64_t length; QVector video_tracks; diff --git a/panels/project.cpp b/panels/project.cpp index 1b124b08d..3e220d458 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -602,7 +602,7 @@ void Project::process_file_list(bool recursive, QStringList& files, QTreeWidgetI } m->using_inout = false; - m->url = file; + m->url = file; m->name = get_file_name_from_path(files.at(i)); // generate waveform/thumbnail in another thread @@ -1004,6 +1004,10 @@ bool Project::load_worker(QFile& f, QXmlStreamReader& stream, int type) { } else if (QFileInfo::exists(internal_proj_dir_test)) { // if path is relative to the last directory the project was saved in m->url = internal_proj_dir_test; dout << "[INFO] Matched" << attr.value().toString() << "relative to project's internal directory"; + } else if (m->url.contains('%')) { + // hack for image sequences (qt won't be able to find the URL with %, but ffmpeg may) + m->url = proj_dir_test; + dout << "[INFO] Guess image sequence" << attr.value().toString() << "path to project's current directory"; } else { dout << "[INFO] Failed to match" << attr.value().toString() << "to file"; } diff --git a/playback/cacher.cpp b/playback/cacher.cpp index 6e2f78395..0c18f5fc4 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -665,22 +665,22 @@ void open_clip_worker(Clip* clip) { clip->max_queue_size = (ms->infinite_length) ? 1 : qCeil(ms->video_frame_rate*0.5); if (ms->video_interlacing != VIDEO_PROGRESSIVE) clip->max_queue_size *= 2; - AVDictionary* opts = NULL; + clip->opts = NULL; // optimized decoding settings - if (clip->stream->codecpar->codec_id != AV_CODEC_ID_PNG && + if (clip->stream->codecpar->codec_id != AV_CODEC_ID_PNG && clip->stream->codecpar->codec_id != AV_CODEC_ID_APNG && clip->stream->codecpar->codec_id != AV_CODEC_ID_TIFF && clip->stream->codecpar->codec_id != AV_CODEC_ID_PSD) { - av_dict_set(&opts, "threads", "auto", 0); + av_dict_set(&clip->opts, "threads", "auto", 0); } if (clip->stream->codecpar->codec_id == AV_CODEC_ID_H264) { - av_dict_set(&opts, "tune", "fastdecode", 0); - av_dict_set(&opts, "tune", "zerolatency", 0); - } + av_dict_set(&clip->opts, "tune", "fastdecode", 0); + av_dict_set(&clip->opts, "tune", "zerolatency", 0); + } // Open codec - if (avcodec_open2(clip->codecCtx, clip->codec, &opts) < 0) { + if (avcodec_open2(clip->codecCtx, clip->codec, &clip->opts) < 0) { dout << "[ERROR] Could not open codec"; } @@ -888,6 +888,9 @@ void close_clip_worker(Clip* clip) { avcodec_close(clip->codecCtx); avcodec_free_context(&clip->codecCtx); + + av_dict_free(&clip->opts); + avformat_close_input(&clip->formatCtx); } diff --git a/project/clip.cpp b/project/clip.cpp index 08bf01299..e4934fcad 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -35,7 +35,8 @@ Clip::Clip(Sequence* s) : use_existing_frame(false), filter_graph(NULL), fbo(NULL), - texture(NULL) + texture(NULL), + opts(NULL) { pkt = av_packet_alloc(); reset(); @@ -88,6 +89,7 @@ void Clip::reset() { codec = NULL; codecCtx = NULL; texture = NULL; + last_invalid_ts = -1; } void Clip::reset_audio() { diff --git a/project/clip.h b/project/clip.h index 8f6659b0f..300659e31 100644 --- a/project/clip.h +++ b/project/clip.h @@ -27,6 +27,7 @@ struct SwsContext; struct SwrContext; struct AVFilterGraph; struct AVFilterContext; +struct AVDictionary; class QOpenGLTexture; struct Clip @@ -87,6 +88,7 @@ struct Clip AVCodecContext* codecCtx; AVPacket* pkt; AVFrame* frame; + AVDictionary* opts; long calculated_length; // temporary variables diff --git a/project/effect.cpp b/project/effect.cpp index 73c661167..8255631ce 100644 --- a/project/effect.cpp +++ b/project/effect.cpp @@ -431,9 +431,14 @@ Effect::~Effect() { close(); } + delete container; + for (int i=0;isetSpacing(0); key_controls->setMargin(0); key_controls->addStretch(); diff --git a/project/effectrow.h b/project/effectrow.h index ec4e2025c..ab89c23f6 100644 --- a/project/effectrow.h +++ b/project/effectrow.h @@ -11,6 +11,7 @@ class QLabel; class KeyframeDelete; class QPushButton; class ComboAction; +class QHBoxLayout; class EffectRow : public QObject { Q_OBJECT @@ -45,6 +46,7 @@ private: int ui_row; QVector fields; + QHBoxLayout* key_controls; QPushButton* keyframe_enable; QPushButton* left_key_nav; QPushButton* key_addremove; diff --git a/ui/collapsiblewidget.cpp b/ui/collapsiblewidget.cpp index f9622b03a..a4284b80b 100644 --- a/ui/collapsiblewidget.cpp +++ b/ui/collapsiblewidget.cpp @@ -22,7 +22,7 @@ CollapsibleWidget::CollapsibleWidget(QWidget* parent) : QWidget(parent) { title_bar = new CollapsibleWidgetHeader(); title_bar->setFocusPolicy(Qt::ClickFocus); title_bar->setAutoFillBackground(true); - QHBoxLayout* title_bar_layout = new QHBoxLayout(); + title_bar_layout = new QHBoxLayout(); title_bar_layout->setMargin(5); title_bar->setLayout(title_bar_layout); enabled_check = new CheckboxEx(); diff --git a/ui/collapsiblewidget.h b/ui/collapsiblewidget.h index d21c38945..b944c208a 100644 --- a/ui/collapsiblewidget.h +++ b/ui/collapsiblewidget.h @@ -41,6 +41,7 @@ private: QVBoxLayout* layout; QPushButton* collapse_button; QFrame* line; + QHBoxLayout* title_bar_layout; signals: void deselect_others(QWidget*); diff --git a/ui/labelslider.cpp b/ui/labelslider.cpp index ab0158f74..357a891db 100644 --- a/ui/labelslider.cpp +++ b/ui/labelslider.cpp @@ -19,10 +19,10 @@ LabelSlider::LabelSlider(QWidget* parent) : QLabel(parent) { setStyleSheet("QLabel{color:#ffc000;text-decoration:underline;}QLabel:disabled{color:#808080;}"); setCursor(Qt::SizeHorCursor); internal_value = -1; + set = false; + display_type = LABELSLIDER_NORMAL; + set_default_value(0); - set_value(0, false); - set = false; - display_type = LABELSLIDER_NORMAL; } void LabelSlider::set_frame_rate(double d) {