Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs
@ 2022-04-05  6:49 Xiaolei Yu
  2022-04-05  9:10 ` Anton Khirnov
  0 siblings, 1 reply; 5+ messages in thread
From: Xiaolei Yu @ 2022-04-05  6:49 UTC (permalink / raw)
  To: ffmpeg-devel


For cases which prefer rejecting broken bitstreams.
---
 libavcodec/hevc_refs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fe18ca2b1d..7ea70e301b 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -426,7 +426,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
 
 /* add a reference with the given poc to the list and mark it as used in DPB */
 static int add_candidate_ref(HEVCContext *s, RefPicList *list,
-                             int poc, int ref_flag, uint8_t use_msb)
+                             int poc, int ref_flag, uint8_t use_msb, int maybe_missing)
 {
     HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
 
@@ -434,6 +434,9 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list,
         return AVERROR_INVALIDDATA;
 
     if (!ref) {
+        if ((s->avctx->err_recognition & AV_EF_COMPLIANT) && !maybe_missing)
+            return AVERROR_INVALIDDATA;
+
         ref = generate_missing_ref(s, poc);
         if (!ref)
             return AVERROR(ENOMEM);
@@ -476,6 +479,7 @@ int ff_hevc_frame_rps(HEVCContext *s)
     for (i = 0; i < short_rps->num_delta_pocs; i++) {
         int poc = s->poc + short_rps->delta_poc[i];
         int list;
+        int maybe_missing;
 
         if (!short_rps->used[i])
             list = ST_FOLL;
@@ -484,7 +488,10 @@ int ff_hevc_frame_rps(HEVCContext *s)
         else
             list = ST_CURR_AFT;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1);
+        maybe_missing = list != ST_CURR_BEF && list != ST_CURR_AFT;
+
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1,
+                                maybe_missing);
         if (ret < 0)
             goto fail;
     }
@@ -493,8 +500,10 @@ int ff_hevc_frame_rps(HEVCContext *s)
     for (i = 0; i < long_rps->nb_refs; i++) {
         int poc  = long_rps->poc[i];
         int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
+        int maybe_missing = list != LT_CURR;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]);
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i],
+                                maybe_missing);
         if (ret < 0)
             goto fail;
     }
-- 
2.35.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs
  2022-04-05  6:49 [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs Xiaolei Yu
@ 2022-04-05  9:10 ` Anton Khirnov
  2022-04-16  8:30   ` Xiaolei Yu
       [not found]   ` <2237ca87-c339-b00c-1562-5c49faee0987@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Anton Khirnov @ 2022-04-05  9:10 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting Xiaolei Yu (2022-04-05 08:49:24)
> 
> For cases which prefer rejecting broken bitstreams.
> ---
>  libavcodec/hevc_refs.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index fe18ca2b1d..7ea70e301b 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -426,7 +426,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
>  
>  /* add a reference with the given poc to the list and mark it as used in DPB */
>  static int add_candidate_ref(HEVCContext *s, RefPicList *list,
> -                             int poc, int ref_flag, uint8_t use_msb)
> +                             int poc, int ref_flag, uint8_t use_msb, int maybe_missing)

allow_missing would be clearer IMO

>  {
>      HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
>  
> @@ -434,6 +434,9 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list,
>          return AVERROR_INVALIDDATA;
>  
>      if (!ref) {
> +        if ((s->avctx->err_recognition & AV_EF_COMPLIANT) && !maybe_missing)

a log message would be nice, so one can easily tell where exactly the
error comes from

-- 
Anton Khirnov
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs
  2022-04-05  9:10 ` Anton Khirnov
@ 2022-04-16  8:30   ` Xiaolei Yu
       [not found]   ` <2237ca87-c339-b00c-1562-5c49faee0987@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Xiaolei Yu @ 2022-04-16  8:30 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1.1.1: Type: text/plain, Size: 1398 bytes --]

On 4/5/22 17:10, Anton Khirnov wrote:
> Quoting Xiaolei Yu (2022-04-05 08:49:24)
>>
>> For cases which prefer rejecting broken bitstreams.
>> ---
>>  libavcodec/hevc_refs.c | 15 ++++++++++++---
>>  1 file changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
>> index fe18ca2b1d..7ea70e301b 100644
>> --- a/libavcodec/hevc_refs.c
>> +++ b/libavcodec/hevc_refs.cfind_ref_idx(
>> @@ -426,7 +426,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
>>
>>  /* add a reference with the given poc to the list and mark it as used in DPB */
>>  static int add_candidate_ref(HEVCContext *s, RefPicList *list,
>> -                             int poc, int ref_flag, uint8_t use_msb)
>> +                             int poc, int ref_flag, uint8_t use_msb, int maybe_missing)
>
> allow_missing would be clearer IMO
>

done

>>  {
>>      HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
>>
>> @@ -434,6 +434,9 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list,
>>          return AVERROR_INVALIDDATA;
>>
>>      if (!ref) {
>> +        if ((s->avctx->err_recognition & AV_EF_COMPLIANT) && !maybe_missing)
>
> a log message would be nice, so one can easily tell where exactly the
> error comes from
>

Moved the log message from find_ref_idx to where the missing refs are to be generated.

[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 669 bytes --]

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH v2 1/2] avcodec/hevcdec: skip generating missing refs in foll lists
       [not found]   ` <2237ca87-c339-b00c-1562-5c49faee0987@gmail.com>
@ 2022-04-16  8:31     ` Xiaolei Yu
  2022-04-16  8:31     ` [FFmpeg-devel] [PATCH v2 2/2] avcodec/hevcdec: detect non-conformant missing refs Xiaolei Yu
  1 sibling, 0 replies; 5+ messages in thread
From: Xiaolei Yu @ 2022-04-16  8:31 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1.1: Type: text/plain, Size: 2734 bytes --]

Missing refs shall be generated only when they are actually used.

Without this change a sequence of a BLA picture and an associated RASL picture
would still be decoded without complaints if the RASL picture is mislabeled
as RADL.
---
 libavcodec/hevc_refs.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index fe18ca2b1d..84a21991c7 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -378,9 +378,6 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb)
         }
     }
 
-    if (s->nal_unit_type != HEVC_NAL_CRA_NUT && !IS_BLA(s))
-        av_log(s->avctx, AV_LOG_ERROR,
-               "Could not find ref with POC %d\n", poc);
     return NULL;
 }
 
@@ -426,7 +423,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
 
 /* add a reference with the given poc to the list and mark it as used in DPB */
 static int add_candidate_ref(HEVCContext *s, RefPicList *list,
-                             int poc, int ref_flag, uint8_t use_msb)
+                             int poc, int ref_flag, uint8_t use_msb, enum RPSType rps_type)
 {
     HEVCFrame *ref = find_ref_idx(s, poc, use_msb);
 
@@ -434,6 +431,15 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list,
         return AVERROR_INVALIDDATA;
 
     if (!ref) {
+        int allow_missing = !(rps_type == ST_CURR_BEF || rps_type == ST_CURR_AFT ||
+                              rps_type == LT_CURR);
+
+        /* skip generating missing refs in foll lists as they are not used by current frame */
+        if (allow_missing)
+            return 0;
+
+        av_log(s->avctx, AV_LOG_ERROR, "Could not find ref with POC %d\n", poc);
+
         ref = generate_missing_ref(s, poc);
         if (!ref)
             return AVERROR(ENOMEM);
@@ -484,7 +490,7 @@ int ff_hevc_frame_rps(HEVCContext *s)
         else
             list = ST_CURR_AFT;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1);
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1, list);
         if (ret < 0)
             goto fail;
     }
@@ -494,7 +500,8 @@ int ff_hevc_frame_rps(HEVCContext *s)
         int poc  = long_rps->poc[i];
         int list = long_rps->used[i] ? LT_CURR : LT_FOLL;
 
-        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]);
+        ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i],
+                                list);
         if (ret < 0)
             goto fail;
     }
-- 
2.35.1

[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 669 bytes --]

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH v2 2/2] avcodec/hevcdec: detect non-conformant missing refs
       [not found]   ` <2237ca87-c339-b00c-1562-5c49faee0987@gmail.com>
  2022-04-16  8:31     ` [FFmpeg-devel] [PATCH v2 1/2] avcodec/hevcdec: skip generating missing refs in foll lists Xiaolei Yu
@ 2022-04-16  8:31     ` Xiaolei Yu
  1 sibling, 0 replies; 5+ messages in thread
From: Xiaolei Yu @ 2022-04-16  8:31 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1.1: Type: text/plain, Size: 664 bytes --]

For cases which prefer rejecting broken bitstreams.
---
 libavcodec/hevc_refs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 84a21991c7..9f8b6022c4 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -439,6 +439,8 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list,
             return 0;
 
         av_log(s->avctx, AV_LOG_ERROR, "Could not find ref with POC %d\n", poc);
+        if (s->avctx->err_recognition & AV_EF_COMPLIANT)
+            return AVERROR_INVALIDDATA;
 
         ref = generate_missing_ref(s, poc);
         if (!ref)
-- 
2.35.1


[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 669 bytes --]

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-16  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05  6:49 [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs Xiaolei Yu
2022-04-05  9:10 ` Anton Khirnov
2022-04-16  8:30   ` Xiaolei Yu
     [not found]   ` <2237ca87-c339-b00c-1562-5c49faee0987@gmail.com>
2022-04-16  8:31     ` [FFmpeg-devel] [PATCH v2 1/2] avcodec/hevcdec: skip generating missing refs in foll lists Xiaolei Yu
2022-04-16  8:31     ` [FFmpeg-devel] [PATCH v2 2/2] avcodec/hevcdec: detect non-conformant missing refs Xiaolei Yu

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git