Skip to content

Commit 602e57b

Browse files
committed
M4AAudioFileDemuxer cleanup
1 parent a407785 commit 602e57b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/AudioTools/AudioCodecs/M4AAudioFileDemuxer.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
4141
}
4242

4343
/**
44-
* @brief Sets the decoder to use for audio frames.
44+
* @brief Sets the decoder to use for audio frames. Please note that
45+
* calls setCallback() to register the decoder callback.
4546
* @param decoder Reference to MultiDecoder.
4647
* @return true if set successfully.
4748
*/
@@ -215,7 +216,9 @@ uint64_t mdat_sample_pos = 0;
215216
}
216217

217218
/**
218-
* @brief Parses the file and feeds data to the parser.
219+
* @brief Parses the file and feeds data to the parser until we have
220+
* all the necessary data: 1) stsd box processed, 2) mdat offset found,
221+
* 3) stsz offset found.
219222
* @param file Reference to the file to parse.
220223
*/
221224
bool parseFile(File& file) {
@@ -254,6 +257,7 @@ uint64_t mdat_sample_pos = 0;
254257
if (fixed_sample_size) {
255258
currentSize = fixed_sample_size;
256259
} else {
260+
// if buffer is empty, fill it again
257261
if (stsz_buf.isEmpty()) {
258262
uint64_t pos = stsz_offset + 20 + sample_index * 4;
259263
if (!file->seek(pos)) return false;
@@ -263,8 +267,9 @@ uint64_t mdat_sample_pos = 0;
263267
stsz_buf.setWritePos(read_bytes / 4);
264268
if (stsz_buf.isEmpty()) return 0;
265269
}
270+
// provide next size
266271
uint32_t val = 0;
267-
stsz_buf.read(val);
272+
if (!stsz_buf.read(val)) return 0;
268273
currentSize = readU32(val);
269274
}
270275
sample_index++;
@@ -283,10 +288,8 @@ uint64_t mdat_sample_pos = 0;
283288
if (file->read(buffer, 20) != 20) return false;
284289
if (!checkType(buffer, "stsz", 4)) return false;
285290
uint8_t* cont = buffer + 8;
286-
fixed_sample_size =
287-
(cont[4] << 24) | (cont[5] << 16) | (cont[6] << 8) | cont[7];
288-
sample_count =
289-
(cont[8] << 24) | (cont[9] << 16) | (cont[10] << 8) | cont[11];
291+
fixed_sample_size = readU32(cont + 4);
292+
sample_count = readU32(cont + 8);
290293
return true;
291294
}
292295

0 commit comments

Comments
 (0)