Skip to content

Commit 689edc8

Browse files
committed
M4AAudioFileDemuxer: rename method names
1 parent 317eedf commit 689edc8

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

src/AudioTools/AudioCodecs/M4AAudioFileDemuxer.h

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
9090
parser.begin();
9191
end();
9292
if (p_decoder) p_decoder->begin();
93-
if (!parseFile(file)) return false;
93+
if (!parseFile()) return false;
9494
if (!readStszHeader()) return false;
9595
if (!checkMdat()) return false;
9696
mdat_sample_pos = mdat_offset + mdat_pos;
@@ -140,15 +140,14 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
140140
/// Returns true as long as there are samples to process.
141141
operator bool() { return sample_count > 0 && sample_index < sample_count; }
142142

143-
144143
uint32_t sampleIndex() const { return sample_index; }
145144

146145
uint32_t size() const { return sample_count; }
147146

148147
uint32_t getMdatOffset() const { return mdat_offset; }
149148

150149
/**
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
152151
* @return stsz sample size in bytes.
153152
*/
154153
uint32_t getNextSampleSize() {
@@ -177,16 +176,49 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
177176
return currentSize;
178177
}
179178

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) {
181193
p_file = filePtr;
182194
sample_index = 0;
183195
sample_count = sampleCount;
184196
stsz_offset = stszOffset;
185197
}
186198

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+
}
187219

188220
protected:
189-
File* p_file = nullptr; ///< Pointer to the open file
221+
File* p_file = nullptr; ///< Pointer to the open file
190222
uint64_t mdat_offset = 0; ///< Offset of mdat box payload
191223
uint64_t mdat_size = 0; ///< Size of mdat box payload
192224
uint64_t stsz_offset = 0; ///< Offset of stsz box
@@ -265,25 +297,6 @@ class M4AAudioFileDemuxer : public M4ACommonDemuxer {
265297
false);
266298
}
267299

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-
287300
/**
288301
* @brief Executes the callback for a completed frame.
289302
* @param size Size of the frame.

src/AudioTools/AudioCodecs/M4AFileSampleSizeBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class M4AFileSampleSizeBuffer : public BaseBuffer<stsz_sample_size_t> {
4545
if (p_file != nullptr && demuxer.getMdatOffset() == 0) {
4646
uint32_t offset = p_container->getDemuxer().getStszFileOffset();
4747
uint32_t s_count = p_container->getDemuxer().getSampleCount();
48-
demuxer.setupForSampleSize(p_file, s_count, offset);
48+
demuxer.beginSampleSizeAccess(p_file, s_count, offset);
4949
}
5050
size_t pos = p_file->position();
5151
data = demuxer.getNextSampleSize();

0 commit comments

Comments
 (0)