vpxenc: fix crash if encoder produces unmatching ts

If for some reason the encoder produces frames with a pts higher than
the input one, we were dropping all the video encoder frames and ended
up crashing when trying to access the pts of a NULL pointer returned by
gst_video_encoder_get_oldest_frame().

I hit this scenario by feeding a decreasing timestamp to vp8enc which
seem to confuse the encoder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2436>
This commit is contained in:
Guillaume Desmottes 2022-05-11 15:18:42 +02:00
parent 0b03893c81
commit 3927e77f4e

View file

@ -2033,6 +2033,13 @@ gst_vpx_enc_process (GstVPXEnc * encoder)
if (frame)
gst_video_encoder_finish_frame (video_encoder, frame);
frame = gst_video_encoder_get_oldest_frame (video_encoder);
if (!frame) {
GST_WARNING_OBJECT (encoder,
"vpx pts %" G_GINT64_FORMAT
" does not match input frames, discarding", pkt->data.frame.pts);
goto out;
}
pts =
gst_util_uint64_scale (frame->pts,
encoder->cfg.g_timebase.den,
@ -2099,6 +2106,8 @@ gst_vpx_enc_process (GstVPXEnc * encoder)
pkt = vpx_codec_get_cx_data (&encoder->encoder, &iter);
}
out:
g_mutex_unlock (&encoder->encoder_lock);
return ret;