This commit is contained in:
itsmattkc
2020-02-22 00:14:20 +11:00
4 changed files with 14 additions and 24 deletions
+8 -16
View File
@@ -48,10 +48,8 @@ FFmpegDecoder::FFmpegDecoder() :
scale_ctx_(nullptr),
cache_at_zero_(false),
cache_at_eof_(false),
opts_(nullptr),
allow_clear_event_(false)
opts_(nullptr)
{
connect(this, &FFmpegDecoder::ConsumedMemory, MemoryManager::instance(), &MemoryManager::ConsumedMemory, Qt::DirectConnection);
connect(MemoryManager::instance(), &MemoryManager::FreeMemory, this, &FFmpegDecoder::FreeMemory, Qt::DirectConnection);
clear_timer_.setInterval(5000);
@@ -387,9 +385,9 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
}
}
allow_clear_event_ = true;
emit ConsumedMemory();
allow_clear_event_ = false;
if (MemoryManager::instance()->RegisterMemory()) {
RemoveFirstFromFrameCache();
}
// Whatever it is, keep this frame in memory for the time being just in case
cached_frames_.append(working_frame);
@@ -986,18 +984,12 @@ void FFmpegDecoder::ClearResources()
void FFmpegDecoder::FreeMemory()
{
if (!allow_clear_event_) {
mutex_.lock();
}
if (mutex_.tryLock()) {
if (cached_frames_.size() > 1) {
RemoveFirstFromFrameCache();
}
if (cached_frames_.size() > 1) {
RemoveFirstFromFrameCache();
}
if (!allow_clear_event_) {
mutex_.unlock();
} else {
allow_clear_event_ = false;
}
}
-5
View File
@@ -64,9 +64,6 @@ public:
virtual void Index(const QAtomicInt *cancelled) override;
signals:
void ConsumedMemory();
private:
/**
* @brief Handle an error
@@ -129,8 +126,6 @@ private:
QTimer clear_timer_;
QAtomicInt allow_clear_event_;
private slots:
void FreeMemory();
+5 -1
View File
@@ -39,11 +39,15 @@ bool MemoryManager::ShouldFreeMemory()
return (GetAvailableMemory() < minimum_available_memory_);
}
void MemoryManager::ConsumedMemory()
bool MemoryManager::RegisterMemory()
{
if (ShouldFreeMemory()) {
emit FreeMemory();
return true;
}
return false;
}
uint64_t MemoryManager::GetAvailableMemory()
+1 -2
View File
@@ -15,8 +15,7 @@ public:
static bool ShouldFreeMemory();
public slots:
void ConsumedMemory();
bool RegisterMemory();
signals:
void FreeMemory();