v4l2videodec: release decode only frame in input list
authorDean Zhang (张安迪) <dean.zhang@mediatek.com>
Mon, 6 Jan 2025 12:30:51 +0000 (20:30 +0800)
committerBackport Bot <gitlab-backport-bot@gstreamer-foundation.org>
Mon, 6 Jan 2025 17:00:15 +0000 (17:00 +0000)
For some frames with decode-only flag, the v4l2 decoder will not
put them in output list. The corresponding decode-only frames will
be still kept in input list, which may cause potential performance
issue when the input list is full. So release the decode-only frames
according to the decode-only flag after they are processed by decoder
driver.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8247>

subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c

index f435f659cca5247179cb317da89e6e40cd2a9bdf..0b81ac662a25171d9b2a2cbc91ed8a483bcb7704 100644 (file)
@@ -811,9 +811,17 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
     gboolean warned = FALSE;
 
     /* Garbage collect old frames in case of codec bugs */
-    while ((oldest_frame = gst_video_decoder_get_oldest_frame (decoder)) &&
-        check_system_frame_number_too_old (frame->system_frame_number,
-            oldest_frame->system_frame_number)) {
+    while ((oldest_frame = gst_video_decoder_get_oldest_frame (decoder))) {
+      if (frame->system_frame_number > oldest_frame->system_frame_number &&
+          GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (oldest_frame)) {
+        gst_video_decoder_finish_frame (decoder, oldest_frame);
+        oldest_frame = NULL;
+        continue;
+      }
+
+      if (G_LIKELY (!check_system_frame_number_too_old
+              (frame->system_frame_number, oldest_frame->system_frame_number)))
+        break;
       if (oldest_frame->system_frame_number > 0) {
         gst_video_decoder_drop_frame (decoder, oldest_frame);
         oldest_frame = NULL;