[FFmpeg-devel] [PATCH 1/5] av1_parser: parser_obu_header, return has_size_flag

Xu Guangxin guangxin.xu at intel.com
Thu Aug 6 11:04:12 EEST 2020


From: Xu Guangxin <Guangxin.Xu at intel.com>

we need check has_size_flag for low overhead obu
---
 libavcodec/av1_parse.c |  4 ++--
 libavcodec/av1_parse.h |  8 ++++----
 libavformat/av1.c      | 12 ++++++------
 libavformat/av1dec.c   | 10 +++++-----
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..b59b4e5e45 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -29,11 +29,11 @@
 int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx)
 {
     int64_t obu_size;
-    int start_pos, type, temporal_id, spatial_id;
+    int start_pos, type, temporal_id, spatial_id, has_size_flag;
     int len;
 
     len = parse_obu_header(buf, length, &obu_size, &start_pos,
-                           &type, &temporal_id, &spatial_id);
+                           &type, &temporal_id, &spatial_id, &has_size_flag);
     if (len < 0)
         return len;
 
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index 01bcd646c2..a3b39f039c 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -99,10 +99,10 @@ static inline int64_t leb128(GetBitContext *gb) {
 
 static inline int parse_obu_header(const uint8_t *buf, int buf_size,
                                    int64_t *obu_size, int *start_pos, int *type,
-                                   int *temporal_id, int *spatial_id)
+                                   int *temporal_id, int *spatial_id, int *has_size_flag)
 {
     GetBitContext gb;
-    int ret, extension_flag, has_size_flag;
+    int ret, extension_flag;
     int64_t size;
 
     ret = init_get_bits8(&gb, buf, FFMIN(buf_size, 2 + 8)); // OBU header fields + max leb128 length
@@ -114,7 +114,7 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size,
 
     *type      = get_bits(&gb, 4);
     extension_flag = get_bits1(&gb);
-    has_size_flag  = get_bits1(&gb);
+    *has_size_flag  = get_bits1(&gb);
     skip_bits1(&gb); // obu_reserved_1bit
 
     if (extension_flag) {
@@ -125,7 +125,7 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size,
         *temporal_id = *spatial_id = 0;
     }
 
-    *obu_size  = has_size_flag ? leb128(&gb)
+    *obu_size  = *has_size_flag ? leb128(&gb)
                                : buf_size - 1 - extension_flag;
 
     if (get_bits_left(&gb) < 0)
diff --git a/libavformat/av1.c b/libavformat/av1.c
index 0cbffb1fd8..10d6815d1f 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -34,7 +34,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf,
 {
     const uint8_t *start = buf, *end = buf + size;
     int64_t obu_size;
-    int off, start_pos, type, temporal_id, spatial_id;
+    int off, start_pos, type, temporal_id, spatial_id, has_size_flag;
     enum {
         START_NOT_FOUND,
         START_FOUND,
@@ -45,7 +45,7 @@ static int av1_filter_obus(AVIOContext *pb, const uint8_t *buf,
     off = size = 0;
     while (buf < end) {
         int len = parse_obu_header(buf, end - buf, &obu_size, &start_pos,
-                                   &type, &temporal_id, &spatial_id);
+                                   &type, &temporal_id, &spatial_id, &has_size_flag);
         if (len < 0)
             return len;
 
@@ -334,14 +334,14 @@ static int parse_sequence_header(AV1SequenceParameters *seq_params, const uint8_
 int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, int size)
 {
     int64_t obu_size;
-    int start_pos, type, temporal_id, spatial_id;
+    int start_pos, type, temporal_id, spatial_id, has_size_flag;
 
     if (size <= 0)
         return AVERROR_INVALIDDATA;
 
     while (size > 0) {
         int len = parse_obu_header(buf, size, &obu_size, &start_pos,
-                                   &type, &temporal_id, &spatial_id);
+                                   &type, &temporal_id, &spatial_id, &has_size_flag);
         if (len < 0)
             return len;
 
@@ -369,7 +369,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
     uint8_t header[4], *meta;
     const uint8_t *seq;
     int64_t obu_size;
-    int start_pos, type, temporal_id, spatial_id;
+    int start_pos, type, temporal_id, spatial_id, has_size_flag;
     int ret, nb_seq = 0, seq_size, meta_size;
 
     if (size <= 0)
@@ -381,7 +381,7 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
 
     while (size > 0) {
         int len = parse_obu_header(buf, size, &obu_size, &start_pos,
-                                   &type, &temporal_id, &spatial_id);
+                                   &type, &temporal_id, &spatial_id, &has_size_flag);
         if (len < 0) {
             ret = len;
             goto fail;
diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index 1be2fac1c1..297e87cc52 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -57,13 +57,13 @@ static int leb(AVIOContext *pb, uint32_t *len) {
     return i;
 }
 
-static int read_obu(const uint8_t *buf, int size, int64_t *obu_size, int *type)
+static int read_obu(const uint8_t *buf, int size, int64_t *obu_size, int *type, int *has_size_flag)
 {
     int start_pos, temporal_id, spatial_id;
     int len;
 
     len = parse_obu_header(buf, size, obu_size, &start_pos,
-                           type, &temporal_id, &spatial_id);
+                           type, &temporal_id, &spatial_id, has_size_flag);
     if (len < 0)
         return len;
 
@@ -76,7 +76,7 @@ static int annexb_probe(const AVProbeData *p)
     int64_t obu_size;
     uint32_t temporal_unit_size, frame_unit_size, obu_unit_size;
     int seq = 0;
-    int ret, type, cnt = 0;
+    int ret, type, cnt = 0, has_size_flag;
 
     ffio_init_context(&pb, p->buf, p->buf_size, 0,
                       NULL, NULL, NULL, NULL);
@@ -103,7 +103,7 @@ static int annexb_probe(const AVProbeData *p)
         return 0;
 
     // Check that the first OBU is a Temporal Delimiter.
-    ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type);
+    ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type, &has_size_flag);
     if (ret < 0 || type != AV1_OBU_TEMPORAL_DELIMITER || obu_size > 0)
         return 0;
     cnt += obu_unit_size;
@@ -118,7 +118,7 @@ static int annexb_probe(const AVProbeData *p)
         if (pb.eof_reached || pb.error)
             return 0;
 
-        ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type);
+        ret = read_obu(p->buf + cnt, FFMIN(p->buf_size - cnt, obu_unit_size), &obu_size, &type, &has_size_flag);
         if (ret < 0)
             return 0;
         cnt += obu_unit_size;
-- 
2.17.1



More information about the ffmpeg-devel mailing list