[9/9] avcodec/extract_extradata_bsf: make sure a Sequence Header was found for av1

Message ID 20181003191538.33448-10-lu_zero@gentoo.org
State New
Headers show
Series
  • [1/9] avcodec/bsf: Add ff_bsf_get_packet_ref() function
Related show

Commit Message

Luca Barbato Oct. 3, 2018, 7:15 p.m.
From: James Almer <jamrial@gmail.com>

A packet may have Metadata OBUs but no Sequence Header OBU, which is
useless as extradata.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
---
 libavcodec/extract_extradata_bsf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

James Almer Oct. 4, 2018, 2:59 a.m. | #1
On 10/3/2018 4:15 PM, Luca Barbato wrote:
> From: James Almer <jamrial@gmail.com>
> 
> A packet may have Metadata OBUs but no Sequence Header OBU, which is
> useless as extradata.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
> ---
>  libavcodec/extract_extradata_bsf.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
> index 2734a7b7d1..9ee2b28d01 100644
> --- a/libavcodec/extract_extradata_bsf.c
> +++ b/libavcodec/extract_extradata_bsf.c
> @@ -67,7 +67,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
>  
>      int extradata_size = 0, filtered_size = 0;
>      int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
> -    int i, ret = 0;
> +    int i, has_seq = 0, ret = 0;
>  
>      ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
>      if (ret < 0)
> @@ -77,12 +77,14 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
>          AV1OBU *obu = &s->av1_pkt.obus[i];
>          if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
>              extradata_size += obu->raw_size;
> +            if (obu->type == AV1_OBU_SEQUENCE_HEADER)
> +                has_seq = 1;
>          } else if (s->remove) {
>              filtered_size += obu->raw_size;
>          }
>      }
>  
> -    if (extradata_size) {
> +    if (extradata_size && has_seq) {
>          AVBufferRef *filtered_buf;
>          uint8_t *extradata, *filtered_data;

Same, i think this would be better squashed with the previous commit.
Luca Barbato Oct. 6, 2018, 7:36 p.m. | #2
On 04/10/2018 04:59, James Almer wrote:
> On 10/3/2018 4:15 PM, Luca Barbato wrote:
>> From: James Almer <jamrial@gmail.com>
>>
>> A packet may have Metadata OBUs but no Sequence Header OBU, which is
>> useless as extradata.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
>> ---
>>  libavcodec/extract_extradata_bsf.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
>> index 2734a7b7d1..9ee2b28d01 100644
>> --- a/libavcodec/extract_extradata_bsf.c
>> +++ b/libavcodec/extract_extradata_bsf.c
>> @@ -67,7 +67,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
>>  
>>      int extradata_size = 0, filtered_size = 0;
>>      int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
>> -    int i, ret = 0;
>> +    int i, has_seq = 0, ret = 0;
>>  
>>      ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
>>      if (ret < 0)
>> @@ -77,12 +77,14 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
>>          AV1OBU *obu = &s->av1_pkt.obus[i];
>>          if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
>>              extradata_size += obu->raw_size;
>> +            if (obu->type == AV1_OBU_SEQUENCE_HEADER)
>> +                has_seq = 1;
>>          } else if (s->remove) {
>>              filtered_size += obu->raw_size;
>>          }
>>      }
>>  
>> -    if (extradata_size) {
>> +    if (extradata_size && has_seq) {
>>          AVBufferRef *filtered_buf;
>>          uint8_t *extradata, *filtered_data;
> 
> Same, i think this would be better squashed with the previous commit.

I'll try to get all the mkv and mp4 commits in, then I'll try to squash
them all once I'm more or less sure they behave as needed.

lu

Patch

diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
index 2734a7b7d1..9ee2b28d01 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -67,7 +67,7 @@  static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
 
     int extradata_size = 0, filtered_size = 0;
     int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
-    int i, ret = 0;
+    int i, has_seq = 0, ret = 0;
 
     ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
     if (ret < 0)
@@ -77,12 +77,14 @@  static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
         AV1OBU *obu = &s->av1_pkt.obus[i];
         if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
             extradata_size += obu->raw_size;
+            if (obu->type == AV1_OBU_SEQUENCE_HEADER)
+                has_seq = 1;
         } else if (s->remove) {
             filtered_size += obu->raw_size;
         }
     }
 
-    if (extradata_size) {
+    if (extradata_size && has_seq) {
         AVBufferRef *filtered_buf;
         uint8_t *extradata, *filtered_data;