Merge branch 'master' of https://github.com/olive-editor/olive
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -15,8 +15,7 @@ public:
|
||||
|
||||
static bool ShouldFreeMemory();
|
||||
|
||||
public slots:
|
||||
void ConsumedMemory();
|
||||
bool RegisterMemory();
|
||||
|
||||
signals:
|
||||
void FreeMemory();
|
||||
|
||||
Reference in New Issue
Block a user