Commit 62074b8f authored by James Almer's avatar James Almer

avcodec/cbs_av1: add a function to strip trailing zeroes from a buffer size

Factor it out from cbs_av1_read_metadata_itut_t35()
Reviewed-by: 's avatarMark Thompson <sw@jkqxz.net>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent b18c8688
...@@ -574,6 +574,17 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, ...@@ -574,6 +574,17 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq,
return diff; return diff;
} }
static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
{
GetBitContext tmp = *gbc;
size_t size = 0;
for (int i = 0; get_bits_left(&tmp) >= 8; i++) {
if (get_bits(&tmp, 8))
size = i;
}
return size;
}
#define HEADER(name) do { \ #define HEADER(name) do { \
ff_cbs_trace_header(ctx, name); \ ff_cbs_trace_header(ctx, name); \
......
...@@ -1674,15 +1674,7 @@ static int FUNC(metadata_itut_t35)(CodedBitstreamContext *ctx, RWContext *rw, ...@@ -1674,15 +1674,7 @@ static int FUNC(metadata_itut_t35)(CodedBitstreamContext *ctx, RWContext *rw,
#ifdef READ #ifdef READ
// The payload runs up to the start of the trailing bits, but there might // 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. // be arbitrarily many trailing zeroes so we need to read through twice.
{ current->payload_size = cbs_av1_get_payload_bytes_left(rw);
GetBitContext tmp = *rw;
current->payload_size = 0;
for (i = 0; get_bits_left(rw) >= 8; i++) {
if (get_bits(rw, 8))
current->payload_size = i;
}
*rw = tmp;
}
current->payload_ref = av_buffer_alloc(current->payload_size); current->payload_ref = av_buffer_alloc(current->payload_size);
if (!current->payload_ref) if (!current->payload_ref)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment