Skip to content

Commit

Permalink
Slightly reduce lock usage
Browse files Browse the repository at this point in the history
Locking the frame_buffer mutex to reference the input frame into the
tmp_frame is unnecessary.
  • Loading branch information
rom1v committed Jan 27, 2022
1 parent 8e4d3be commit 7e8a942
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/src/frame_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ swap_frames(AVFrame **lhs, AVFrame **rhs) {
bool
sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
bool *previous_frame_skipped) {
sc_mutex_lock(&fb->mutex);

// Use a temporary frame to preserve pending_frame in case of error.
// tmp_frame is an empty frame, no need to call av_frame_unref() beforehand.
int r = av_frame_ref(fb->tmp_frame, frame);
Expand All @@ -61,6 +59,8 @@ sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
return false;
}

sc_mutex_lock(&fb->mutex);

// Now that av_frame_ref() succeeded, we can replace the previous
// pending_frame
swap_frames(&fb->pending_frame, &fb->tmp_frame);
Expand Down

0 comments on commit 7e8a942

Please sign in to comment.