@@ -41,7 +41,8 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
41
41
}
42
42
43
43
/* *
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.
45
46
* @param decoder Reference to MultiDecoder.
46
47
* @return true if set successfully.
47
48
*/
@@ -215,7 +216,9 @@ uint64_t mdat_sample_pos = 0;
215
216
}
216
217
217
218
/* *
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.
219
222
* @param file Reference to the file to parse.
220
223
*/
221
224
bool parseFile (File& file) {
@@ -254,6 +257,7 @@ uint64_t mdat_sample_pos = 0;
254
257
if (fixed_sample_size) {
255
258
currentSize = fixed_sample_size;
256
259
} else {
260
+ // if buffer is empty, fill it again
257
261
if (stsz_buf.isEmpty ()) {
258
262
uint64_t pos = stsz_offset + 20 + sample_index * 4 ;
259
263
if (!file->seek (pos)) return false ;
@@ -263,8 +267,9 @@ uint64_t mdat_sample_pos = 0;
263
267
stsz_buf.setWritePos (read_bytes / 4 );
264
268
if (stsz_buf.isEmpty ()) return 0 ;
265
269
}
270
+ // provide next size
266
271
uint32_t val = 0 ;
267
- stsz_buf.read (val);
272
+ if (! stsz_buf.read (val)) return 0 ;
268
273
currentSize = readU32 (val);
269
274
}
270
275
sample_index++;
@@ -283,10 +288,8 @@ uint64_t mdat_sample_pos = 0;
283
288
if (file->read (buffer, 20 ) != 20 ) return false ;
284
289
if (!checkType (buffer, " stsz" , 4 )) return false ;
285
290
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 );
290
293
return true ;
291
294
}
292
295
0 commit comments