Skip to content

Commit

Permalink
av1: add av1_obu_count() (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh authored Jun 9, 2022
1 parent acfb113 commit c2b9985
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/re_av1.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int av1_obu_encode(struct mbuf *mb, uint8_t type, bool has_size,
size_t len, const uint8_t *payload);
int av1_obu_decode(struct av1_obu_hdr *hdr, struct mbuf *mb);
int av1_obu_print(struct re_printf *pf, const struct av1_obu_hdr *hdr);
unsigned av1_obu_count(const uint8_t *buf, size_t size);


/*
Expand Down
30 changes: 30 additions & 0 deletions src/av1/obu.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,33 @@ int av1_obu_print(struct re_printf *pf, const struct av1_obu_hdr *hdr)
return re_hprintf(pf, "type=%u x=%d s=%d size=%zu",
hdr->type, hdr->x, hdr->s, hdr->size);
}


unsigned av1_obu_count(const uint8_t *buf, size_t size)
{
struct mbuf wrap = {
.buf = (uint8_t *)buf,
.size = size,
.pos = 0,
.end = size
};
unsigned count = 0;

while (mbuf_get_left(&wrap) > 1) {

struct av1_obu_hdr hdr;

int err = av1_obu_decode(&hdr, &wrap);
if (err) {
DEBUG_WARNING("count: could not decode OBU"
" [%zu bytes]: %m\n", size, err);
return 0;
}

mbuf_advance(&wrap, hdr.size);

++count;
}

return count;
}

0 comments on commit c2b9985

Please sign in to comment.