ffmpegdecoder: share framepool with all instances

We can conserve memory by sharing our frame pool amongst instances of the same
stream.
This commit is contained in:
itsmattkc
2020-04-14 14:51:31 +10:00
parent b3bebeeef3
commit 9cc343bf13
2 changed files with 111 additions and 55 deletions
+14 -13
View File
@@ -41,7 +41,8 @@ extern "C" {
OLIVE_NAMESPACE_ENTER
class FFmpegDecoderInstance {
class FFmpegDecoderInstance : public QObject {
Q_OBJECT
public:
FFmpegDecoderInstance(const char* filename, int stream_index);
virtual ~FFmpegDecoderInstance();
@@ -50,6 +51,8 @@ public:
bool IsValid() const;
void SetFramePool(FFmpegFramePool* frame_pool);
int64_t RangeStart() const;
int64_t RangeEnd() const;
bool CacheContainsTime(const int64_t& t) const;
@@ -97,7 +100,7 @@ private:
QWaitCondition cache_wait_cond_;
QMutex cache_lock_;
QList<FFmpegFramePool::ElementPtr> cached_frames_;
FFmpegFramePool frame_pool_;
FFmpegFramePool* frame_pool_;
int64_t cache_target_time_;
@@ -106,6 +109,12 @@ private:
bool cache_at_zero_;
bool cache_at_eof_;
QTimer clear_timer_;
static const int kMaxFrameLife;
private slots:
void ClearTimerEvent();
};
/**
@@ -175,17 +184,9 @@ private:
rational aspect_ratio_;
int64_t start_time_;
QTimer clear_timer_;
FFmpegDecoderInstance* our_instance_;
static QHash< Stream*, QList<FFmpegDecoderInstance*> > instances_;
static QMutex instance_lock_;
static const int kMaxFrameLife;
private slots:
void ClearTimerEvent();
static QHash< Stream*, QList<FFmpegDecoderInstance*> > instance_map_;
static QHash< Stream*, FFmpegFramePool* > frame_pool_map_;
static QMutex instance_map_lock_;
};