vpxenc: fix crash if encoder produces unmatching ts
authorGuillaume Desmottes <guillaume.desmottes@onestream.live>
Wed, 11 May 2022 13:18:42 +0000 (15:18 +0200)
committerGuillaume Desmottes <guillaume.desmottes@onestream.live>
Thu, 12 May 2022 11:00:53 +0000 (13:00 +0200)
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/2405>

subprojects/gst-plugins-good/ext/vpx/gstvpxenc.c

index 9781cc6..85af4c0 100644 (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;