Slightly reduce lock usage

Locking the frame_buffer mutex to reference the input frame into the
tmp_frame is unnecessary.

This also fixes the missing unlock on error.
This commit is contained in:
Romain Vimont 2022-01-27 15:30:09 +01:00
parent 8e4d3beb01
commit 02b5e87802

View file

@ -51,8 +51,6 @@ swap_frames(AVFrame **lhs, AVFrame **rhs) {
bool bool
sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame, sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
bool *previous_frame_skipped) { bool *previous_frame_skipped) {
sc_mutex_lock(&fb->mutex);
// Use a temporary frame to preserve pending_frame in case of error. // 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. // tmp_frame is an empty frame, no need to call av_frame_unref() beforehand.
int r = av_frame_ref(fb->tmp_frame, frame); int r = av_frame_ref(fb->tmp_frame, frame);
@ -61,6 +59,8 @@ sc_frame_buffer_push(struct sc_frame_buffer *fb, const AVFrame *frame,
return false; return false;
} }
sc_mutex_lock(&fb->mutex);
// Now that av_frame_ref() succeeded, we can replace the previous // Now that av_frame_ref() succeeded, we can replace the previous
// pending_frame // pending_frame
swap_frames(&fb->pending_frame, &fb->tmp_frame); swap_frames(&fb->pending_frame, &fb->tmp_frame);