memorypool: implemented arenas

A pool can allocate/destroy any amount of arenas during runtime, meaning it
won't run out of memory but we still get the advantages of one large allocation
as opposed to hundreds of small allocations.
This commit is contained in:
itsmattkc
2020-04-14 16:23:45 +10:00
parent feceef0d62
commit a2f954a0a7
4 changed files with 250 additions and 93 deletions
+8 -6
View File
@@ -94,11 +94,10 @@ bool FFmpegDecoder::Open()
FFmpegFramePool* frame_pool = frame_pool_map_.value(stream().get());
if (!frame_pool) {
frame_pool = new FFmpegFramePool();
frame_pool->SetParams(our_instance_->stream()->codecpar->width,
our_instance_->stream()->codecpar->height,
static_cast<AVPixelFormat>(our_instance_->stream()->codecpar->format));
frame_pool->Allocate(256);
frame_pool = new FFmpegFramePool(256,
our_instance_->stream()->codecpar->width,
our_instance_->stream()->codecpar->height,
static_cast<AVPixelFormat>(our_instance_->stream()->codecpar->format));
frame_pool_map_.insert(stream().get(), frame_pool);
}
@@ -346,7 +345,8 @@ SampleBufferPtr FFmpegDecoder::RetrieveAudio(const rational &timecode, const rat
return nullptr;
}
WaveInput input(GetConformedFilename(params));
QString wav_fn = GetConformedFilename(params);
WaveInput input(wav_fn);
if (input.open()) {
const AudioRenderingParams& input_params = input.params();
@@ -361,6 +361,8 @@ SampleBufferPtr FFmpegDecoder::RetrieveAudio(const rational &timecode, const rat
return sample_buffer;
}
qCritical() << "Failed to open cached file" << wav_fn;
return nullptr;
}
+5 -30
View File
@@ -26,10 +26,11 @@ extern "C" {
OLIVE_NAMESPACE_ENTER
FFmpegFramePool::FFmpegFramePool() :
width_(0),
height_(0),
format_(AV_PIX_FMT_NONE)
FFmpegFramePool::FFmpegFramePool(int element_count, int width, int height, AVPixelFormat format) :
MemoryPool(element_count),
width_(width),
height_(height),
format_(format)
{
}
@@ -51,34 +52,8 @@ FFmpegFramePool::ElementPtr FFmpegFramePool::Get(AVFrame *copy)
return ele;
}
void FFmpegFramePool::SetParams(int width, int height, AVPixelFormat format)
{
int old_nb_elements;
if (IsAllocated()) {
old_nb_elements = GetElementCount();
Destroy();
} else {
old_nb_elements = 0;
}
width_ = width;
height_ = height;
format_ = format;
if (old_nb_elements) {
// Re-allocate automatically
Allocate(old_nb_elements);
}
}
size_t FFmpegFramePool::GetElementSize()
{
if (width_ == 0 || height_ == 0 || format_ == AV_PIX_FMT_NONE) {
return 0;
}
int buf_sz = av_image_get_buffer_size(static_cast<AVPixelFormat>(format_),
width_,
height_,
+4 -3
View File
@@ -30,12 +30,13 @@ OLIVE_NAMESPACE_ENTER
class FFmpegFramePool : public MemoryPool<uint8_t>
{
public:
FFmpegFramePool();
FFmpegFramePool(int element_count,
int width,
int height,
AVPixelFormat format);
ElementPtr Get(AVFrame* copy);
void SetParams(int width, int height, AVPixelFormat format);
protected:
virtual size_t GetElementSize() override;