#include <stdint.h>
+#include "av1.h"
#include "avcodec.h"
#include "get_bits.h"
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;
/**
* Extract an OBU from a raw bitstream.
*
- * @note This function does not copy or store any bistream data. All
+ * @note This function does not copy or store any bitstream data. All
* the pointers in the AV1OBU structure will be valid as long
* as the input buffer also is.
*/
/**
* Split an input packet into OBUs.
*
- * @note This function does not copy or store any bistream data. All
+ * @note This function does not copy or store any bitstream data. All
* the pointers in the AV1Packet structure will be valid as
* long as the input buffer also is.
*/
size = *obu_size + *start_pos;
- if (size > INT_MAX)
+ if (size > buf_size)
+ return AVERROR_INVALIDDATA;
+
+ 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;
}