Skip to content

Commit

Permalink
perf: Improve performance of video frame buffering.
Browse files Browse the repository at this point in the history
This hashtable used std::function dispatch to a function pointer for no
good reason. It could have just used the function pointer instead. Now
we use neither and statically bind the hash function to the hash map.
  • Loading branch information
iphydf committed Dec 24, 2024
1 parent 5403734 commit ffcef56
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/video/videoframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class VideoFrame
const bool linesizeAligned;
};

struct FrameBufferKeyHash
{
size_t operator()(const FrameBufferKey& key) const
{
return FrameBufferKey::hash(key);
}
};

private:
static FrameBufferKey getFrameKey(const QSize& frameSize, const int pixFmt, const int linesize);
static FrameBufferKey getFrameKey(const QSize& frameSize, const int pixFmt,
Expand All @@ -131,8 +139,7 @@ class VideoFrame
const IDType sourceID;

// Main framebuffer store
std::unordered_map<FrameBufferKey, AVFrame*, std::function<decltype(FrameBufferKey::hash)>>
frameBuffer{3, FrameBufferKey::hash};
std::unordered_map<FrameBufferKey, AVFrame*, FrameBufferKeyHash> frameBuffer{3};

// Source frame
const QRect sourceDimensions;
Expand Down

0 comments on commit ffcef56

Please sign in to comment.