Commit 92214030b6 for ffmpeg
commit 92214030b6b9d66665a915b2050c4e18f84c1be0
Author: Zhao Zhili <quinkblack@foxmail.com>
Date: Tue Nov 3 18:25:21 2026 +0800
avcodec/cavsdec: support PFieldSkip in field-coded P pictures
Decoding such pictures failed with AVERROR_PATCHWELCOME. Skip
macroblocks now predict from the same-parity field of the previous
frame, and the zero-vector shortcut compares neighbours against the
reference actually in use.
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 05117a098c..72a3ce70ed 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -607,11 +607,14 @@ void ff_cavs_mv(AVSContext *h, enum cavs_mv_loc nP, enum cavs_mv_loc nC,
mvP->ref_idx = 0;
if (mvC->ref == NOT_AVAIL || (nP == MV_FWD_X3) || (nP == MV_BWD_X3 ))
mvC = &h->mv[nP - 5]; // set to top-left (mvD)
+ /* the zero-vector cases of 9.9.1 a) 2) and 3), against this block's
+ * own reference
+ */
if (mode == MV_PRED_PSKIP &&
(mvA->ref == NOT_AVAIL ||
mvB->ref == NOT_AVAIL ||
- (mvA->x | mvA->y | mvA->ref) == 0 ||
- (mvB->x | mvB->y | mvB->ref) == 0)) {
+ ((mvA->x | mvA->y) == 0 && mvA->ref == ref) ||
+ ((mvB->x | mvB->y) == 0 && mvB->ref == ref))) {
mvP2 = &un_mv;
/* if there is only one suitable candidate, take it */
} else if (mvA->ref >= 0 && mvB->ref < 0 && mvC->ref < 0) {
diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index b51a5e6c19..acc33b0793 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -204,6 +204,7 @@ typedef struct AVSContext {
int pic_structure;
int top_field_first; ///< first coded field is the top one, clause 7.2.3
int b_field_enhanced; ///< BFieldEnhanced of the picture, clause 9.9.1 b)
+ int p_field_skip; ///< PFieldSkip of the picture, clause 9.9.1 a)
int field; ///< field of the current MB, 0 or 1, clause 3.24
int field_mby; ///< macroblock row of the current macroblock in it
int skip_mode_flag; ///< select between skip_count or one skip_flag per MB
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 4138a57a67..ab168ba8ca 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -1397,7 +1397,11 @@ static int decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
set_inter_mb_ctx(h, mb_type, mb_type == P_SKIP);
switch (mb_type) {
case P_SKIP:
- MV(MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, h->ref_base[0]);
+ /* PFieldSkip predicts from the reference marked 1, the same
+ * parity field of the previous frame (9.9.1 a) 1))
+ */
+ MV(MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16,
+ h->ref_base[0] + h->p_field_skip);
break;
case P_16X16:
REF(ref[0], 0, MV_FWD_X0);
@@ -1992,14 +1996,11 @@ static int decode_pic(AVSContext *h)
}
/* in a frame picture the field derivations reduce to the frame ones
- * (9.9.1 b) 3)); PFieldSkip of 9.9.1 a) 1) is not implemented */
+ * (9.9.1 b) 3)) */
h->b_field_enhanced = pb_field_enhanced_flag && !h->pic_structure &&
h->cur.f->pict_type == AV_PICTURE_TYPE_B;
- if (pb_field_enhanced_flag && !h->pic_structure &&
- h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
- avpriv_request_sample(h->avctx, "Enhanced field coded P picture");
- return AVERROR_PATCHWELCOME;
- }
+ h->p_field_skip = pb_field_enhanced_flag && !h->pic_structure &&
+ h->cur.f->pict_type == AV_PICTURE_TYPE_P;
if (!h->progressive) {
h->cur.f->flags |= AV_FRAME_FLAG_INTERLACED;