ffmpegdecoder: re-use existing frame pool for memory management

This commit is contained in:
itsmattkc
2020-04-12 14:12:08 +10:00
parent fa16d2169b
commit cdf5a1058d
6 changed files with 189 additions and 105 deletions
+11 -15
View File
@@ -21,10 +21,10 @@
#ifndef FFMPEGFRAMECACHE_H
#define FFMPEGFRAMECACHE_H
#include <QList>
#include <QLinkedList>
#include <QMutex>
#include "codec/frame.h"
#include "avframeptr.h"
#include "render/videoparams.h"
OLIVE_NAMESPACE_ENTER
@@ -34,22 +34,23 @@ class FFmpegFrameCache
public:
FFmpegFrameCache() = default;
static Frame* Get(const VideoRenderingParams& params);
static AVFramePtr Get(int width, int height, int format);
static void Release(Frame* f);
static void Release(AVFramePtr f);
class Client
{
public:
Client() = default;
Frame* append(const VideoRenderingParams &params);
AVFramePtr append(int width, int height, int format);
AVFramePtr append(AVFrame *copy);
void clear();
bool isEmpty() const;
Frame* first() const;
Frame* at(int i) const;
Frame* last() const;
AVFramePtr first() const;
AVFramePtr at(int i) const;
AVFramePtr last() const;
int size() const;
void accessedFirst();
@@ -59,19 +60,14 @@ public:
void remove_old_frames(qint64 older_than);
private:
struct CachedFrame {
Frame* frame;
qint64 accessed;
};
QList<CachedFrame> frames_;
QList<AVFramePtr> frames_;
};
private:
static QMutex pool_lock_;
static QList<Frame*> frame_pool_;
static QLinkedList<AVFramePtr> frame_pool_;
};