Skip to content

Commit 0aa7a19

Browse files
committed
MP4 rename data callback to incremental data callback
1 parent 4617605 commit 0aa7a19

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/AudioTools/AudioCodecs/MP4ParserIncremental.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ namespace audio_tools {
1414
*/
1515
class MP4ParserIncremental : public MP4Parser {
1616
public:
17-
using DataCallback = std::function<void(Box&, const uint8_t* data, size_t len,
17+
using IncrementalDataCallback = std::function<void(Box&, const uint8_t* data, size_t len,
1818
bool is_final, void* ref)>;
1919

2020
/**
2121
* @brief Defines the callback for all incremental box data.
2222
* @param cb Callback function for all boxes.
2323
*/
24-
void setIncrementalDataCallback(DataCallback cb) { data_callback = cb; }
24+
void setIncrementalDataCallback(IncrementalDataCallback cb) { incremental_data_callback = cb; }
2525

2626
/**
2727
* @brief Defines a specific callback for incremental data of a box type.
2828
* @param type 4-character box type (e.g. "mdat").
2929
* @param cb Callback function for this box type.
3030
* @param callGeneric If true, the generic callback will also be called after the type-specific callback.
3131
*/
32-
void setIncrementalDataCallback(const char* type, DataCallback cb, bool callGeneric = true) {
32+
void setIncrementalDataCallback(const char* type, IncrementalDataCallback cb, bool callGeneric = true) {
3333
CallbackEntry entry;
3434
strncpy(entry.type, type, 4);
3535
entry.type[4] = '\0'; // Ensure null-termination
3636
entry.cb = cb;
3737
entry.callGeneric = callGeneric;
38-
data_callbacks.push_back(entry);
38+
incremental_data_callbacks.push_back(entry);
3939
}
4040

4141
/**
@@ -59,12 +59,12 @@ class MP4ParserIncremental : public MP4Parser {
5959
*/
6060
struct CallbackEntry {
6161
char type[5]; ///< 4-character box type
62-
DataCallback cb; ///< Callback function
62+
IncrementalDataCallback cb; ///< Callback function
6363
bool callGeneric = true; ///< If true, also call the generic callback after this one
6464
};
6565

66-
DataCallback data_callback = defaultDataCallback; ///< Generic incremental data callback
67-
Vector<CallbackEntry> data_callbacks; ///< List of type-specific incremental data callbacks
66+
IncrementalDataCallback incremental_data_callback = defaultIncrementalDataCallback; ///< Generic incremental data callback
67+
Vector<CallbackEntry> incremental_data_callbacks; ///< List of type-specific incremental data callbacks
6868
bool box_in_progress = false; ///< True if currently parsing a box incrementally
6969
size_t box_bytes_received = 0; ///< Bytes received so far for the current box
7070
size_t box_bytes_expected = 0; ///< Total expected bytes for the current box
@@ -80,7 +80,7 @@ class MP4ParserIncremental : public MP4Parser {
8080
* @param is_final True if this is the last chunk for this box.
8181
* @param ref Optional reference pointer.
8282
*/
83-
static void defaultDataCallback(Box& box, const uint8_t* data, size_t len,
83+
static void defaultIncrementalDataCallback(Box& box, const uint8_t* data, size_t len,
8484
bool is_final, void* ref) {
8585
char space[box.level * 2 + 1];
8686
memset(space, ' ', box.level * 2);
@@ -221,7 +221,7 @@ class MP4ParserIncremental : public MP4Parser {
221221

222222
if (available_payload > 0) {
223223
box_bytes_received += available_payload;
224-
if (data_callback) {
224+
if (incremental_data_callback) {
225225
strcpy(box.type, box_type);
226226
box.id = ++this->box.id;
227227
box.data = nullptr;
@@ -239,7 +239,7 @@ class MP4ParserIncremental : public MP4Parser {
239239
// incremental callback
240240
box.size = box_bytes_expected;
241241
box.data_size = available_payload;
242-
processDataCallback(box, p + headerSize, available_payload, false, ref);
242+
processIncrementalDataCallback(box, p + headerSize, available_payload, false, ref);
243243
}
244244
}
245245
fileOffset += (bufferSize - buffer.available());
@@ -255,7 +255,7 @@ class MP4ParserIncremental : public MP4Parser {
255255
size_t to_read = std::min((size_t)box_bytes_expected - box_bytes_received,
256256
(size_t)buffer.available());
257257
if (to_read == 0) return false;
258-
if (data_callback) {
258+
if (incremental_data_callback) {
259259
strcpy(box.type, box_type);
260260
box.id = ++this->box.id;
261261
box.data = nullptr;
@@ -265,7 +265,7 @@ class MP4ParserIncremental : public MP4Parser {
265265
box.offset = box_offset + box_bytes_received;
266266
box.is_complete = (box_bytes_received + to_read == box_bytes_expected);
267267
box.is_container = false;
268-
processDataCallback(box, buffer.data(), to_read, box.is_complete, ref);
268+
processIncrementalDataCallback(box, buffer.data(), to_read, box.is_complete, ref);
269269
}
270270
box_bytes_received += to_read;
271271
fileOffset += to_read;
@@ -286,20 +286,20 @@ class MP4ParserIncremental : public MP4Parser {
286286
* @param is_final True if this is the last chunk for this box.
287287
* @param ref Optional reference pointer.
288288
*/
289-
void processDataCallback(Box& box, const uint8_t* data, size_t len,
289+
void processIncrementalDataCallback(Box& box, const uint8_t* data, size_t len,
290290
bool is_final, void* ref) {
291291
bool is_called = false;
292292
bool call_generic = true;
293-
for (auto& entry : data_callbacks) {
293+
for (auto& entry : incremental_data_callbacks) {
294294
if (StrView(entry.type) == box.type) {
295295
entry.cb(box, data, len, is_final, ref);
296296
is_called = true;
297297
if (!entry.callGeneric) call_generic = false;
298298
break;
299299
}
300300
}
301-
if ((!is_called || call_generic) && data_callback) {
302-
data_callback(box, data, len, is_final, ref);
301+
if ((!is_called || call_generic) && incremental_data_callback) {
302+
incremental_data_callback(box, data, len, is_final, ref);
303303
}
304304
}
305305

0 commit comments

Comments
 (0)