8#include "AudioTools/CoreAudio/Buffers.h"
53 using BoxCallback = std::function<void(
Box&,
void*
ref)>;
84 void setCallback(
const char* type, BoxCallback cb,
bool callGeneric =
true) {
86 strncpy(entry.
type, type, 4);
84 void setCallback(
const char* type, BoxCallback cb,
bool callGeneric =
true) {
…}
100 return buffer.size() == size;
130 size_t write(
const uint8_t* data,
size_t len) {
130 size_t write(
const uint8_t* data,
size_t len) {
…}
143 size_t write(
const char* data,
size_t len) {
144 return write(
reinterpret_cast<const uint8_t*
>(data), len);
143 size_t write(
const char* data,
size_t len) {
…}
179 size_t box_size =
readU32(str + idx) - 8;
187 strncpy(
box.
type, (
char*)(str + idx + 4), 4);
191 if (idx >= len)
break;
197 bool findBox(
const char* name,
const uint8_t* data,
size_t len,
Box& result) {
198 for (
int j = 0; j < len - 4; j++) {
202 size_t box_size =
readU32(data + j) - 8;
203 if (box_size < 8)
continue;
208 strncpy(
box.
type, (
char*)(data + j + 4), 4);
197 bool findBox(
const char* name,
const uint8_t* data,
size_t len,
Box& result) {
…}
225 char str_buffer[200];
228 snprintf(str_buffer,
sizeof(str_buffer),
229 "%s- #%u %u) %s, Offset: %u, Size: %u, Data Size: %u, Available: %u", space,
233 Serial.println(str_buffer);
235 printf(
"%s\n", str_buffer);
266 size_t incremental_offset = 0;
298 strncpy(type, (
char*)(p + 4), 4);
300 uint64_t boxSize = size32;
301 size_t headerSize = 8;
303 if (boxSize < headerSize)
return false;
305 int level =
static_cast<int>(
levelStack.size());
313 size_t payload_size =
static_cast<size_t>(boxSize - headerSize);
335 box.
size =
static_cast<size_t>(boxSize - 8);
361 size_t payload_size,
int level) {
388 size_t headerSize,
size_t payload_size,
int level,
397 size_t available_payload = bufferSize -
parseOffset - headerSize;
399 if (available_payload > 0) {
417 incremental_offset += available_payload;
430 if (to_read == 0)
return true;
447 incremental_offset += to_read;
478 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
509 bool is_called =
false;
510 bool call_generic =
true;
512 if (strncmp(entry.type,
box.
type, 4) == 0) {
515 if (!entry.callGeneric) call_generic =
false;
531 static const char* containers_str[] = {
532 "moov",
"trak",
"mdia",
"minf",
"stbl",
"edts",
"dinf",
"udta",
533 "ilst",
"moof",
"traf",
"mfra",
"tref",
"iprp",
"sinf",
"schi"};
534 for (
const char* c : containers_str) {
548 if (
StrView(type) == cont.name)
return true;
560 if (
StrView(type) == cont.name)
return cont.start;
573 return (type !=
nullptr && isalnum(type[offset]) &&
574 isalnum(type[offset + 1]) && isalnum(type[offset + 2]) &&
575 isalnum(type[offset + 3]));
Structure for type-specific callbacks.
Definition MP4Parser.h:58
BoxCallback cb
Callback function.
Definition MP4Parser.h:60
char type[5]
4-character box type
Definition MP4Parser.h:59
bool callGeneric
If true, also call the generic callback after this one.
Definition MP4Parser.h:61