-static int find_atom(struct mp4 *f, uint64_t base, uint32_t size,
- const char *name)
-{
- uint32_t remaining = size;
- uint64_t atom_offset = base;
-
- for (;;) {
- int ret;
- char atom_name[4];
- uint32_t atom_size;
-
- set_position(f, atom_offset);
-
- if (remaining < 8)
- return -1;
- ret = read_int32(f, &atom_size);
- if (ret <= 0)
- return ret;
- if (atom_size > remaining || atom_size < 8)
- return -1;
- ret = read_data(f, atom_name, 4);
- if (ret <= 0)
- return ret;
- if (!memcmp(atom_name, name, 4)) {
- set_position(f, atom_offset);
- return 1;
- }
- remaining -= atom_size;
- atom_offset += atom_size;
- }
-}
-
-/*
- * Try to find atom <name> with atom <name_inside> in it. Besides -1/0/1 for
- * error, EOF and success, this function may return 2 to indicate that the
- * desired atoms were not found.
- */
-static int find_atom_v2(struct mp4 *f, uint64_t base, uint32_t size,
- const char *name, uint32_t extraheaders, const char *name_inside)
-{
- uint64_t first_base = (uint64_t) (-1);
-
- for (;;) {
- uint64_t mybase;
- uint32_t mysize;
- int ret = find_atom(f, base, size, name);
-
- if (ret <= 0)
- return ret;
- mybase = get_position(f);
- ret = read_int32(f, &mysize);
- if (ret <= 0)
- return ret;
- if (first_base == (uint64_t) (-1))
- first_base = mybase;
-
- if (mysize < 8 + extraheaders)
- break;
-
- if (find_atom (f, mybase + (8 + extraheaders),
- mysize - (8 + extraheaders), name_inside)) {
- set_position(f, mybase);
- return 1;
- }
- base += mysize;
- if (size <= mysize)
- break;
- size -= mysize;
- }
- if (first_base != (uint64_t)(-1)) {
- set_position(f, first_base);
- return 1;
- }
- /* wanted atom inside not found */
- return 2;
-}
-