[FFmpeg-devel,2/2,v2] avcodec/cbs_av1: add support for Padding OBUs

Submitted by James Almer on April 13, 2019, 7:25 p.m.

Details

Message ID 20190413192541.9060-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer April 13, 2019, 7:25 p.m.
Based on itut_t35 Matadata OBU parsing code.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_av1.c                 | 20 ++++++++++++++++++++
 libavcodec/cbs_av1.h                 |  7 +++++++
 libavcodec/cbs_av1_syntax_template.c | 24 ++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

Comments

Mark Thompson April 14, 2019, 5:22 p.m.
On 13/04/2019 20:25, James Almer wrote:
> Based on itut_t35 Matadata OBU parsing code.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_av1.c                 | 20 ++++++++++++++++++++
>  libavcodec/cbs_av1.h                 |  7 +++++++
>  libavcodec/cbs_av1_syntax_template.c | 24 ++++++++++++++++++++++++
>  3 files changed, 51 insertions(+)
> 
> ...
> diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
> index 56009145e8..675bfe5bb4 100644
> --- a/libavcodec/cbs_av1_syntax_template.c
> +++ b/libavcodec/cbs_av1_syntax_template.c
> @@ -1755,3 +1755,27 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
>  
>      return 0;
>  }
> +
> +static int FUNC(padding)(CodedBitstreamContext *ctx, RWContext *rw,

The standard calls this function "padding_obu".

> +                         AV1RawPadding *current)
> +{
> +    int i, err;
> +
> +    HEADER("Padding");
> +
> +#ifdef READ
> +    // The payload runs up to the start of the trailing bits, but there might
> +    // be arbitrarily many trailing zeroes so we need to read through twice.
> +    current->payload_size = cbs_av1_get_payload_bytes_left(rw);
> +
> +    current->payload_ref = av_buffer_alloc(current->payload_size);
> +    if (!current->payload_ref)
> +        return AVERROR(ENOMEM);
> +    current->payload = current->payload_ref->data;
> +#endif
> +
> +    for (i = 0; i < current->payload_size; i++)
> +        xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
> +
> +    return 0;
> +}
> 

LGTM with that.

Thanks,

- Mark
James Almer April 14, 2019, 6:56 p.m.
On 4/14/2019 2:22 PM, Mark Thompson wrote:
> On 13/04/2019 20:25, James Almer wrote:
>> Based on itut_t35 Matadata OBU parsing code.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavcodec/cbs_av1.c                 | 20 ++++++++++++++++++++
>>  libavcodec/cbs_av1.h                 |  7 +++++++
>>  libavcodec/cbs_av1_syntax_template.c | 24 ++++++++++++++++++++++++
>>  3 files changed, 51 insertions(+)
>>
>> ...
>> diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
>> index 56009145e8..675bfe5bb4 100644
>> --- a/libavcodec/cbs_av1_syntax_template.c
>> +++ b/libavcodec/cbs_av1_syntax_template.c
>> @@ -1755,3 +1755,27 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
>>  
>>      return 0;
>>  }
>> +
>> +static int FUNC(padding)(CodedBitstreamContext *ctx, RWContext *rw,
> 
> The standard calls this function "padding_obu".
> 
>> +                         AV1RawPadding *current)
>> +{
>> +    int i, err;
>> +
>> +    HEADER("Padding");
>> +
>> +#ifdef READ
>> +    // The payload runs up to the start of the trailing bits, but there might
>> +    // be arbitrarily many trailing zeroes so we need to read through twice.
>> +    current->payload_size = cbs_av1_get_payload_bytes_left(rw);
>> +
>> +    current->payload_ref = av_buffer_alloc(current->payload_size);
>> +    if (!current->payload_ref)
>> +        return AVERROR(ENOMEM);
>> +    current->payload = current->payload_ref->data;
>> +#endif
>> +
>> +    for (i = 0; i < current->payload_size; i++)
>> +        xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
>> +
>> +    return 0;
>> +}
>>
> 
> LGTM with that.
> 
> Thanks,

Changed and pushed. Thanks!

Patch hide | download patch | download mbox

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 0c03ca28af..c175038f0d 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -868,6 +868,11 @@  static void cbs_av1_free_tile_data(AV1RawTileData *td)
     av_buffer_unref(&td->data_ref);
 }
 
+static void cbs_av1_free_padding(AV1RawPadding *pd)
+{
+    av_buffer_unref(&pd->payload_ref);
+}
+
 static void cbs_av1_free_metadata(AV1RawMetadata *md)
 {
     switch (md->metadata_type) {
@@ -894,6 +899,9 @@  static void cbs_av1_free_obu(void *unit, uint8_t *content)
     case AV1_OBU_METADATA:
         cbs_av1_free_metadata(&obu->obu.metadata);
         break;
+    case AV1_OBU_PADDING:
+        cbs_av1_free_padding(&obu->obu.padding);
+        break;
     }
 
     av_freep(&obu);
@@ -1068,6 +1076,12 @@  static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
         }
         break;
     case AV1_OBU_PADDING:
+        {
+            err = cbs_av1_read_padding(ctx, &gbc, &obu->obu.padding);
+            if (err < 0)
+                return err;
+        }
+        break;
     default:
         return AVERROR(ENOSYS);
     }
@@ -1193,6 +1207,12 @@  static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
         }
         break;
     case AV1_OBU_PADDING:
+        {
+            err = cbs_av1_write_padding(ctx, pbc, &obu->obu.padding);
+            if (err < 0)
+                return err;
+        }
+        break;
     default:
         return AVERROR(ENOSYS);
     }
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 71ceff9427..e799964b72 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -364,6 +364,12 @@  typedef struct AV1RawMetadata {
     } metadata;
 } AV1RawMetadata;
 
+typedef struct AV1RawPadding {
+    uint8_t     *payload;
+    size_t       payload_size;
+    AVBufferRef *payload_ref;
+} AV1RawPadding;
+
 
 typedef struct AV1RawOBU {
     AV1RawOBUHeader header;
@@ -377,6 +383,7 @@  typedef struct AV1RawOBU {
         AV1RawTileGroup      tile_group;
         AV1RawTileList       tile_list;
         AV1RawMetadata       metadata;
+        AV1RawPadding        padding;
     } obu;
 } AV1RawOBU;
 
diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
index 56009145e8..675bfe5bb4 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1755,3 +1755,27 @@  static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw,
 
     return 0;
 }
+
+static int FUNC(padding)(CodedBitstreamContext *ctx, RWContext *rw,
+                         AV1RawPadding *current)
+{
+    int i, err;
+
+    HEADER("Padding");
+
+#ifdef READ
+    // The payload runs up to the start of the trailing bits, but there might
+    // be arbitrarily many trailing zeroes so we need to read through twice.
+    current->payload_size = cbs_av1_get_payload_bytes_left(rw);
+
+    current->payload_ref = av_buffer_alloc(current->payload_size);
+    if (!current->payload_ref)
+        return AVERROR(ENOMEM);
+    current->payload = current->payload_ref->data;
+#endif
+
+    for (i = 0; i < current->payload_size; i++)
+        xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i);
+
+    return 0;
+}