You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Large performance regression fixed by moving mutex further into the Timeline::GetFrame method - only when generating a new frame (allowing cache to actually work freely). Adding mutex back to FFmpegReader::GetFrame. Removing redundant mutex from ReaderBase.h. Adding mutex to all methods that call shrink_to_fit().
This commit is contained in:
@@ -206,8 +206,8 @@ int FFmpegReader::IsHardwareDecodeSupported(int codecid)
|
||||
void FFmpegReader::Open() {
|
||||
// Open reader if not already open
|
||||
if (!is_open) {
|
||||
// Prevent calls to GetFrame when Closing
|
||||
const std::lock_guard<std::recursive_mutex> lock(processingMutex);
|
||||
// Prevent async calls to the following code
|
||||
const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
|
||||
|
||||
// Initialize format context
|
||||
pFormatCtx = NULL;
|
||||
@@ -580,8 +580,8 @@ void FFmpegReader::Open() {
|
||||
void FFmpegReader::Close() {
|
||||
// Close all objects, if reader is 'open'
|
||||
if (is_open) {
|
||||
// Prevent calls to GetFrame when Closing
|
||||
const std::lock_guard<std::recursive_mutex> lock(processingMutex);
|
||||
// Prevent async calls to the following code
|
||||
const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
|
||||
|
||||
// Mark as "closed"
|
||||
is_open = false;
|
||||
@@ -881,13 +881,16 @@ std::shared_ptr<Frame> FFmpegReader::GetFrame(int64_t requested_frame) {
|
||||
// Return the cached frame
|
||||
return frame;
|
||||
} else {
|
||||
// Check the cache a 2nd time (due to a potential previous lock)
|
||||
|
||||
// Prevent async calls to the remainder of this code
|
||||
const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
|
||||
|
||||
// Check the cache a 2nd time (due to the potential previous lock)
|
||||
frame = final_cache.GetFrame(requested_frame);
|
||||
if (frame) {
|
||||
// Debug output
|
||||
ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetFrame", "returned cached frame on 2nd look", requested_frame);
|
||||
|
||||
// Return the cached frame
|
||||
} else {
|
||||
// Frame is not in cache
|
||||
// Reset seek count
|
||||
@@ -2078,6 +2081,9 @@ bool FFmpegReader::IsPartialFrame(int64_t requested_frame) {
|
||||
// Check the working queue, and move finished frames to the finished queue
|
||||
void FFmpegReader::CheckWorkingFrames(int64_t requested_frame) {
|
||||
|
||||
// Prevent async calls to the following code
|
||||
const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
|
||||
|
||||
// Get a list of current working queue frames in the cache (in-progress frames)
|
||||
std::vector<std::shared_ptr<openshot::Frame>> working_frames = working_cache.GetFrames();
|
||||
std::vector<std::shared_ptr<openshot::Frame>>::iterator working_itr;
|
||||
|
||||
Reference in New Issue
Block a user