summaryrefslogtreecommitdiff
path: root/libavcodec/av1_parse.h
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-08-15 23:31:04 -0300
committerJames Almer <jamrial@gmail.com>2018-08-17 15:09:01 -0300
commit96a7099f3ed57aa6dd8de2e727e25a4508743bd8 (patch)
treebfa0e71b24049989e73b6ac04bfac3ed07993506 /libavcodec/av1_parse.h
parentc85852d3de636d18b41c4e5fdcdbc18bde7f3b1f (diff)
avcodec/av1_parse: take trailing bits into account when initializing the GetBitContext
Also only initialize it in ff_av1_packet_split() and not ff_av1_extract_obu(), same as h2645_parse, so GetBitContext specific failures may not affect the latter. Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/av1_parse.h')
-rw-r--r--libavcodec/av1_parse.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index 9a6e6835ab..0de619dbec 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -23,6 +23,7 @@
#include <stdint.h>
+#include "av1.h"
#include "avcodec.h"
#include "get_bits.h"
@@ -31,6 +32,12 @@ typedef struct AV1OBU {
int size;
const uint8_t *data;
+ /**
+ * Size, in bits, of just the data, excluding the trailing_one_bit and
+ * any trailing padding.
+ */
+ int size_bits;
+
/** Size of entire OBU, including header */
int raw_size;
const uint8_t *raw_data;
@@ -133,4 +140,35 @@ static inline int parse_obu_header(const uint8_t *buf, int buf_size,
return size;
}
+static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
+{
+ int v;
+
+ /* There are no trailing bits on these */
+ if (type == AV1_OBU_TILE_GROUP || type == AV1_OBU_FRAME) {
+ if (size > INT_MAX / 8)
+ return AVERROR(ERANGE);
+ else
+ return size * 8;
+ }
+
+ while (size > 0 && buf[size - 1] == 0)
+ size--;
+
+ if (!size)
+ return 0;
+
+ v = buf[size - 1];
+
+ if (size > INT_MAX / 8)
+ return AVERROR(ERANGE);
+ size *= 8;
+
+ /* Remove the trailing_one_bit and following trailing zeros */
+ if (v)
+ size -= ff_ctz(v) + 1;
+
+ return size;
+}
+
#endif /* AVCODEC_AV1_PARSE_H */