From f26eea162094e91372d1e29900140d052a07e7f4 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 9 Aug 2019 08:21:54 +1000 Subject: [PATCH] moved more objects to shared ptrs --- app/decoder/decoder.cpp | 4 ++-- app/decoder/decoder.h | 6 +++--- app/decoder/ffmpeg/ffmpegdecoder.cpp | 8 ++++---- app/node/processor/renderer/renderer.cpp | 5 ++--- app/node/processor/renderer/renderer.h | 4 ++-- app/node/processor/renderer/rendererthread.h | 3 +++ app/project/item/footage/audiostream.h | 2 ++ app/project/item/footage/footage.cpp | 15 +++++---------- app/project/item/footage/footage.h | 6 +++--- app/project/item/footage/stream.h | 4 ++++ app/project/item/footage/videostream.h | 2 ++ app/task/import/import.cpp | 2 +- 12 files changed, 33 insertions(+), 28 deletions(-) diff --git a/app/decoder/decoder.cpp b/app/decoder/decoder.cpp index 4993bf935..96ee1f257 100644 --- a/app/decoder/decoder.cpp +++ b/app/decoder/decoder.cpp @@ -42,12 +42,12 @@ Decoder::~Decoder() { } -const Stream *Decoder::stream() +StreamPtr Decoder::stream() { return stream_; } -void Decoder::set_stream(const Stream *fs) +void Decoder::set_stream(StreamPtr fs) { Close(); diff --git a/app/decoder/decoder.h b/app/decoder/decoder.h index 38237f60f..35950b6bc 100644 --- a/app/decoder/decoder.h +++ b/app/decoder/decoder.h @@ -80,8 +80,8 @@ public: virtual QString id() = 0; - const Stream* stream(); - void set_stream(const Stream *fs); + StreamPtr stream(); + void set_stream(StreamPtr fs); /** * @brief Probe a footage file and dump metadata about it @@ -194,7 +194,7 @@ protected: bool open_; private: - const Stream* stream_; + StreamPtr stream_; }; #endif // DECODER_H diff --git a/app/decoder/ffmpeg/ffmpegdecoder.cpp b/app/decoder/ffmpeg/ffmpegdecoder.cpp index 06d61ce79..a9b300ec1 100644 --- a/app/decoder/ffmpeg/ffmpegdecoder.cpp +++ b/app/decoder/ffmpeg/ffmpegdecoder.cpp @@ -346,12 +346,12 @@ bool FFmpegDecoder::Probe(Footage *f) avstream_ = fmt_ctx_->streams[i]; - Stream* str; + StreamPtr str; if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { // Create a video stream object - VideoStream* video_stream = new VideoStream(); + VideoStreamPtr video_stream = std::make_shared(); video_stream->set_width(avstream_->codecpar->width); video_stream->set_height(avstream_->codecpar->height); @@ -361,7 +361,7 @@ bool FFmpegDecoder::Probe(Footage *f) } else if (avstream_->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { // Create an audio stream object - AudioStream* audio_stream = new AudioStream(); + AudioStreamPtr audio_stream = std::make_shared(); audio_stream->set_layout(avstream_->codecpar->channel_layout); audio_stream->set_channels(avstream_->codecpar->channels); @@ -372,7 +372,7 @@ bool FFmpegDecoder::Probe(Footage *f) } else { // This is data we can't utilize at the moment, but we make a Stream object anyway to keep parity with the file - str = new Stream(); + str = std::make_shared(); // Set the correct codec type based on FFmpeg's result switch (avstream_->codecpar->codec_type) { diff --git a/app/node/processor/renderer/renderer.cpp b/app/node/processor/renderer/renderer.cpp index f85b367fc..47e60b54d 100644 --- a/app/node/processor/renderer/renderer.cpp +++ b/app/node/processor/renderer/renderer.cpp @@ -50,7 +50,7 @@ void RendererProcessor::Start() threads_.resize(QThread::idealThreadCount()); for (int i=0;i(); threads_[i]->run(); } @@ -67,13 +67,12 @@ void RendererProcessor::Stop() for (int i=0;iCancel(); - delete threads_[i]; } threads_.clear(); } -RendererThread *RendererProcessor::CurrentThread() +RendererThread* RendererProcessor::CurrentThread() { return dynamic_cast(QThread::currentThread()); } diff --git a/app/node/processor/renderer/renderer.h b/app/node/processor/renderer/renderer.h index 6285c22cf..860ee478d 100644 --- a/app/node/processor/renderer/renderer.h +++ b/app/node/processor/renderer/renderer.h @@ -79,10 +79,10 @@ public: * This function attempts a dynamic_cast on QThread::currentThread() to RendererThread, which will return nullptr if * the cast fails (e.g. if this function is called from the main thread rather than a RendererThread). */ - static RendererThread* CurrentThread(); + static RendererThread *CurrentThread(); private: - QVector threads_; + QVector threads_; bool started_; }; diff --git a/app/node/processor/renderer/rendererthread.h b/app/node/processor/renderer/rendererthread.h index 8dde541ba..08859214f 100644 --- a/app/node/processor/renderer/rendererthread.h +++ b/app/node/processor/renderer/rendererthread.h @@ -21,6 +21,7 @@ #ifndef RENDERTHREAD_H #define RENDERTHREAD_H +#include #include #include #include @@ -65,4 +66,6 @@ private: bool cancelled_; }; +using RendererThreadPtr = std::shared_ptr; + #endif // RENDERTHREAD_H diff --git a/app/project/item/footage/audiostream.h b/app/project/item/footage/audiostream.h index 6a89b953a..a6135196c 100644 --- a/app/project/item/footage/audiostream.h +++ b/app/project/item/footage/audiostream.h @@ -47,4 +47,6 @@ private: int sample_rate_; }; +using AudioStreamPtr = std::shared_ptr; + #endif // AUDIOSTREAM_H diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index 574b067cb..dd90fb6d3 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -77,7 +77,7 @@ void Footage::set_timestamp(const QDateTime &t) timestamp_ = t; } -void Footage::add_stream(Stream *s) +void Footage::add_stream(StreamPtr s) { // Add a copy of this stream to the list streams_.append(s); @@ -86,7 +86,7 @@ void Footage::add_stream(Stream *s) streams_.last()->set_footage(this); } -const Stream *Footage::stream(int index) +StreamPtr Footage::stream(int index) { return streams_.at(index); } @@ -118,11 +118,6 @@ void Footage::ClearStreams() } // Delete all streams - for (int i=0;itype() == Stream::kVideo) { - VideoStream* vs = static_cast(s); + VideoStreamPtr vs = std::static_pointer_cast(s); tip.append( QCoreApplication::translate("Footage", @@ -203,7 +198,7 @@ void Footage::UpdateTooltip() QString::number(vs->height())) ); } else if (streams_.at(i)->type() == Stream::kAudio) { - AudioStream* as = static_cast(s); + AudioStreamPtr as = std::static_pointer_cast(s); tip.append( QCoreApplication::translate("Footage", diff --git a/app/project/item/footage/footage.h b/app/project/item/footage/footage.h index bfe1954d6..73697def7 100644 --- a/app/project/item/footage/footage.h +++ b/app/project/item/footage/footage.h @@ -157,7 +157,7 @@ public: * * A pointer to a stream object. The Footage takes ownership of this object and will free it when it's deleted. */ - void add_stream(Stream* s); + void add_stream(StreamPtr s); /** * @brief Retrieve a stream at the given index. @@ -171,7 +171,7 @@ public: * * The stream at the index provided */ - const Stream* stream(int index); + StreamPtr stream(int index); /** * @brief Retrieve total number of streams in this Footage file @@ -243,7 +243,7 @@ private: /** * @brief Internal streams array */ - QList streams_; + QList streams_; /** * @brief Internal ready setting diff --git a/app/project/item/footage/stream.h b/app/project/item/footage/stream.h index 919139317..ef4661176 100644 --- a/app/project/item/footage/stream.h +++ b/app/project/item/footage/stream.h @@ -21,6 +21,8 @@ #ifndef STREAM_H #define STREAM_H +#include + #include "common/rational.h" class Footage; @@ -84,4 +86,6 @@ private: }; +using StreamPtr = std::shared_ptr; + #endif // STREAM_H diff --git a/app/project/item/footage/videostream.h b/app/project/item/footage/videostream.h index 21eabcd3f..a64f0db0d 100644 --- a/app/project/item/footage/videostream.h +++ b/app/project/item/footage/videostream.h @@ -43,4 +43,6 @@ private: int height_; }; +using VideoStreamPtr = std::shared_ptr; + #endif // VIDEOSTREAM_H diff --git a/app/task/import/import.cpp b/app/task/import/import.cpp index 59ddda41f..d742866bd 100644 --- a/app/task/import/import.cpp +++ b/app/task/import/import.cpp @@ -41,7 +41,7 @@ ImportTask::ImportTask(ProjectViewModel *model, Folder *parent, const QStringLis urls_(urls), parent_(parent) { - set_text(tr("Importing %1 files").arg(urls.size())); + set_text(tr("Importing %1 files").arg (urls.size())); } bool ImportTask::Action()