ffmpegdecoder: impose limit on memory frame cache

This commit is contained in:
itsmattkc
2020-04-14 15:16:38 +10:00
parent 9cc343bf13
commit feceef0d62
2 changed files with 15 additions and 1 deletions
+14 -1
View File
@@ -98,7 +98,7 @@ bool FFmpegDecoder::Open()
frame_pool->SetParams(our_instance_->stream()->codecpar->width,
our_instance_->stream()->codecpar->height,
static_cast<AVPixelFormat>(our_instance_->stream()->codecpar->format));
frame_pool->Allocate(128);
frame_pool->Allocate(256);
frame_pool_map_.insert(stream().get(), frame_pool);
}
@@ -1015,6 +1015,10 @@ FFmpegFramePool::ElementPtr FFmpegDecoderInstance::RetrieveFrame(const int64_t&
previous = cached_frames_.last();
}
// Clear early frames
// FIXME: Hardcoded value (only stores a maximum of 2 seconds in the cache at any time)
TruncateCacheRangeTo(2*second_ts_);
// Append this frame and signal to other threads that a new frame has arrived
cached_frames_.append(cached);
@@ -1164,6 +1168,15 @@ void FFmpegDecoderInstance::RemoveFramesBefore(const qint64 &t)
}
}
void FFmpegDecoderInstance::TruncateCacheRangeTo(const qint64 &t)
{
// We keep one frame in memory as an identifier for what pts the decoder is up to
while (cached_frames_.size() > 1 && (RangeEnd() - RangeStart()) > t) {
cached_frames_.removeFirst();
cache_at_zero_ = false;
}
}
rational FFmpegDecoderInstance::sample_aspect_ratio() const
{
return av_guess_sample_aspect_ratio(fmt_ctx_, avstream_, nullptr);
+1
View File
@@ -62,6 +62,7 @@ public:
FFmpegFramePool::ElementPtr GetFrameFromCache(const int64_t& t) const;
void RemoveFramesBefore(const qint64& t);
void TruncateCacheRangeTo(const qint64& t);
rational sample_aspect_ratio() const;
AVStream* stream() const;