@@ -90,7 +90,7 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
90
90
parser.begin ();
91
91
end ();
92
92
if (p_decoder) p_decoder->begin ();
93
- if (!parseFile (file )) return false ;
93
+ if (!parseFile ()) return false ;
94
94
if (!readStszHeader ()) return false ;
95
95
if (!checkMdat ()) return false ;
96
96
mdat_sample_pos = mdat_offset + mdat_pos;
@@ -140,15 +140,14 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
140
140
// / Returns true as long as there are samples to process.
141
141
operator bool () { return sample_count > 0 && sample_index < sample_count; }
142
142
143
-
144
143
uint32_t sampleIndex () const { return sample_index; }
145
144
146
145
uint32_t size () const { return sample_count; }
147
146
148
147
uint32_t getMdatOffset () const { return mdat_offset; }
149
148
150
149
/* *
151
- * @brief Provides the next sample size from the stsz box.
150
+ * @brief Provides the next sample size (= frame size) from the stsz box queue
152
151
* @return stsz sample size in bytes.
153
152
*/
154
153
uint32_t getNextSampleSize () {
@@ -177,16 +176,49 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
177
176
return currentSize;
178
177
}
179
178
180
- void setupForSampleSize (File* filePtr, uint32_t sampleCount, uint32_t stszOffset){
179
+ /* *
180
+ * @brief Initializes the demuxer for reading sample sizes from the stsz box.
181
+ *
182
+ * This method sets the file pointer, resets the sample index, sets the total sample count,
183
+ * and records the offset of the stsz box in the file. It is typically called before reading
184
+ * sample sizes directly from the file, ensuring the demuxer is properly positioned.
185
+ *
186
+ * @param filePtr Pointer to the open file.
187
+ * @param sampleCount Total number of samples in the file.
188
+ * @param stszOffset Offset of the stsz box in the file.
189
+ */
190
+
191
+ void beginSampleSizeAccess (File* filePtr, uint32_t sampleCount,
192
+ uint32_t stszOffset) {
181
193
p_file = filePtr;
182
194
sample_index = 0 ;
183
195
sample_count = sampleCount;
184
196
stsz_offset = stszOffset;
185
197
}
186
198
199
+ /* *
200
+ * @brief Parses the file and feeds data to the parser until we have
201
+ * all the necessary data: 1) stsd box processed, 2) mdat offset found,
202
+ * 3) stsz offset found.
203
+ * Usually this method is not needed, but it comes in handy if you need
204
+ * to process a file which is not in streaming format!
205
+ * @param file Reference to the file to parse.
206
+ */
207
+ bool parseFile () {
208
+ uint8_t buffer[1024 ];
209
+ p_file->seek (0 );
210
+ while (p_file->available ()) {
211
+ int to_read = min (sizeof (buffer), parser.availableForWrite ());
212
+ size_t len = p_file->read (buffer, to_read);
213
+ parser.write (buffer, len);
214
+ // stop if we have all the data
215
+ if (stsd_processed && mdat_offset && stsz_offset) return true ;
216
+ }
217
+ return false ;
218
+ }
187
219
188
220
protected:
189
- File* p_file = nullptr ; // /< Pointer to the open file
221
+ File* p_file = nullptr ; // /< Pointer to the open file
190
222
uint64_t mdat_offset = 0 ; // /< Offset of mdat box payload
191
223
uint64_t mdat_size = 0 ; // /< Size of mdat box payload
192
224
uint64_t stsz_offset = 0 ; // /< Offset of stsz box
@@ -265,25 +297,6 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
265
297
false );
266
298
}
267
299
268
- /* *
269
- * @brief Parses the file and feeds data to the parser until we have
270
- * all the necessary data: 1) stsd box processed, 2) mdat offset found,
271
- * 3) stsz offset found.
272
- * @param file Reference to the file to parse.
273
- */
274
- bool parseFile (File& file) {
275
- uint8_t buffer[1024 ];
276
- file.seek (0 );
277
- while (file.available ()) {
278
- int to_read = min (sizeof (buffer), parser.availableForWrite ());
279
- size_t len = file.read (buffer, to_read);
280
- parser.write (buffer, len);
281
- // stop if we have all the data
282
- if (stsd_processed && mdat_offset && stsz_offset) return true ;
283
- }
284
- return false ;
285
- }
286
-
287
300
/* *
288
301
* @brief Executes the callback for a completed frame.
289
302
* @param size Size of the frame.
0 commit comments