From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E053F49331 for ; Wed, 8 May 2024 15:43:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0AFEA68D6AC; Wed, 8 May 2024 18:43:17 +0300 (EEST) Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5561A68D410 for ; Wed, 8 May 2024 18:43:11 +0300 (EEST) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a59c448b44aso950790666b.2 for ; Wed, 08 May 2024 08:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715182990; x=1715787790; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YPwvW/6+Ap3QtbKpXm5uj1k141vvcIcKSecNiFCEZZo=; b=OwpSWnkAjUyzH5UY/Kwvhuy0JleZp99jxAEjVhVyGwyDSt3esxtNjm8QziiCTEi1wT 18/UHhsT5JZ219qJIryeTjeYxsaoQxj7ymaFta3jwpSevwHy5it/7pHcTOE2TXlnZA4T zSOiKYWRmH3Te+3lnyXSgoBiKkOwLPhe9d/kPlTYJ6dG1aCoTmGbUmixw//PEmB+xYZd 1lQeSLoHy/k/TlpgG9nELmGTye/U7k6DmAmd23cBtNoklTL9pYRn/lxD/F8J0lP1xOzL y7a6rNHl9dl74z/gtQ1akM8KpIIGcuh426XiT0Is2PWTvCTsWIsCWlNC7dc6u2bvu6ho As9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715182990; x=1715787790; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YPwvW/6+Ap3QtbKpXm5uj1k141vvcIcKSecNiFCEZZo=; b=RXfDYPDyohpIlctmZM7c7J4J2HyTPilwlzT2yZIKYWIzo6yh6u0QyT8azOShbc8m2E wXb0O/wu2qpgIs4DDcCfia4oGpI/NxUMPr+DaAVhgqE/QS7p5JQFnEAR2ony61QvLMLi fVeR6T/SNCAiasp53EHrzUz4IrqksMLQjFeHtEma6E6q8865PbTQmQaoR+R5vTpwoi4W A2ufh5Rsqtvy9V/oY0UUlkX3XagxAGQzrPY8e9ubDS4wyPv9YG5TZm5W3JHNkwiO9anc cWe6smKt0DK0VGM1XTJ90EUU3R22XfeZdgUEUcaVFijbsQ9KM2g2sSLgAQPdR1X87F2i Sg+Q== X-Gm-Message-State: AOJu0YzXeLZOv0AFeJaEwQzJYyHFrRFikPZVNvDIo7pLA99yRIeHkySP cVK7H1BiXcqHAQPijOZdtt/+rAz91gpLOYOKZbceUhqEPUauV0JSRjiINA== X-Google-Smtp-Source: AGHT+IG2oOBNG86yC3sYp/tQk4eAECgdlYQprZo+4zTlLAOsd6f5baQXr4RdvU1caGjk2mcqWvKV5Q== X-Received: by 2002:a17:906:3848:b0:a59:db0f:6bdd with SMTP id a640c23a62f3a-a59fb95dff7mr184366866b.44.1715182990178; Wed, 08 May 2024 08:43:10 -0700 (PDT) Received: from mitsuki.. (ip-78-45-35-87.bb.vodafone.cz. [78.45.35.87]) by smtp.gmail.com with ESMTPSA id my37-20020a1709065a6500b00a59ae892a68sm5183621ejc.167.2024.05.08.08.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 08:43:09 -0700 (PDT) From: David Rosca To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 May 2024 17:41:36 +0200 Message-ID: <20240508154213.24388-2-nowrep@gmail.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavc/vaapi_h264: Fix merging fields in DPB with missing references X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: David Rosca Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: If there are missing references, h264 decode does error concealment by copying previous refs which means there will be duplicated surfaces. Check long_ref and frame_idx in addition to surface when looking for the other field to avoid trying to merge with wrong picture. Also allow to merge with multiple pictures in case there are duplicates of the other field. --- v2: Check long_ref/frame_idx + multiple merge libavcodec/vaapi_h264.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c index b47531ce1c..398e92568c 100644 --- a/libavcodec/vaapi_h264.c +++ b/libavcodec/vaapi_h264.c @@ -93,14 +93,19 @@ typedef struct DPB { */ static int dpb_add(DPB *dpb, const H264Picture *pic) { - int i; + int i, pic_frame_idx, merged = 0; if (dpb->size >= dpb->max_size) return -1; + pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num; + for (i = 0; i < dpb->size; i++) { VAPictureH264 * const va_pic = &dpb->va_pics[i]; - if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) { + int va_pic_long_ref = !!(va_pic->flags & VA_PICTURE_H264_LONG_TERM_REFERENCE); + if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f) && + va_pic_long_ref == pic->long_ref && + va_pic->frame_idx == pic_frame_idx) { VAPictureH264 temp_va_pic; fill_vaapi_pic(&temp_va_pic, pic, 0); @@ -112,11 +117,14 @@ static int dpb_add(DPB *dpb, const H264Picture *pic) } else { va_pic->BottomFieldOrderCnt = temp_va_pic.BottomFieldOrderCnt; } + merged = 1; } - return 0; } } + if (merged) + return 0; + fill_vaapi_pic(&dpb->va_pics[dpb->size++], pic, 0); return 0; } -- 2.45.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".