return f->current_position;
}
-static int need_parse_when_meta_only(uint8_t atom_type)
-{
- switch (atom_type) {
- case ATOM_EDTS:
- case ATOM_DRMS:
- case ATOM_SINF:
- case ATOM_SCHI:
- case ATOM_STTS:
- case ATOM_STSZ:
- case ATOM_STZ2:
- case ATOM_STCO:
- case ATOM_STSC:
- case ATOM_FRMA:
- case ATOM_IVIV:
- case ATOM_PRIV:
- return 0;
- default:
- return 1;
- }
-}
-
static int32_t set_position(struct mp4 *f, int64_t position)
{
f->cb->seek(f->cb->user_data, position);
return ret;
}
+static bool need_atom(uint8_t atom_type, bool meta_only)
+{
+ /* these are needed in any case */
+ switch (atom_type) {
+ case ATOM_STSD:
+ case ATOM_META:
+ case ATOM_TRAK:
+ case ATOM_MDIA:
+ case ATOM_MINF:
+ case ATOM_STBL:
+ return true;
+ }
+ /* meta-only opens don't need anything else */
+ if (meta_only)
+ return false;
+ /* these are only required for regular opens */
+ switch (atom_type) {
+ case ATOM_STTS:
+ case ATOM_STSZ:
+ case ATOM_STCO:
+ case ATOM_STSC:
+ case ATOM_MDHD:
+ case ATOM_UDTA:
+ return true;
+ }
+ return false;
+}
+
/* parse atoms that are sub atoms of other atoms */
static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, bool meta_only)
{
f->track[f->total_tracks - 1] = para_calloc(
sizeof(struct mp4_track));
}
- /* parse subatoms */
- if (meta_only && !need_parse_when_meta_only(atom_type)) {
+ if (!need_atom(atom_type, meta_only)) {
set_position(f, get_position(f) + size - header_size);
- } else if (atom_type < SUBATOMIC) {
+ continue;
+ }
+ if (atom_type < SUBATOMIC)
ret = parse_sub_atoms(f, size - header_size, meta_only);
- if (ret <= 0)
- return ret;
- } else {
+ else
ret = atom_read(f, size, atom_type);
- if (ret <= 0)
- return ret;
- }
+ if (ret <= 0)
+ return ret;
}
return 1;
}