Get the last few packets from the mac encoder.
This commit is contained in:
1 parent
2d67e1b718
commit
c9b81e5757
1 file changed
+12
-10
+12
-10
@@ -32,6 +32,8 @@ typedef struct AudioFileIO
|
|||||||
|
|
||||||
UInt64 outputPos;
|
UInt64 outputPos;
|
||||||
|
|
||||||
|
bool done;
|
||||||
|
|
||||||
AudioStreamPacketDescription * _Nullable pktDescs;
|
AudioStreamPacketDescription * _Nullable pktDescs;
|
||||||
} AudioFileIO;
|
} AudioFileIO;
|
||||||
|
|
||||||
@@ -336,7 +338,13 @@ OSStatus EncoderDataProc(AudioConverterRef inAudioConverter,
|
|||||||
|
|
||||||
if (!availableBytes) {
|
if (!availableBytes) {
|
||||||
*ioNumberDataPackets = 0;
|
*ioNumberDataPackets = 0;
|
||||||
return 1;
|
if (afio->done) {
|
||||||
|
ioData->mBuffers[0].mDataByteSize = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out how much to read
|
// Figure out how much to read
|
||||||
@@ -375,7 +383,8 @@ static MP42SampleBuffer *encode(AudioConverterRef encoder, AudioFileIO *afio)
|
|||||||
|
|
||||||
UInt32 availableBytes = sfifo_used(afio->ringBuffer);
|
UInt32 availableBytes = sfifo_used(afio->ringBuffer);
|
||||||
// Check if we need more data
|
// Check if we need more data
|
||||||
if (availableBytes < afio->inSamples * afio->inSizePerPacket) {
|
if (!afio->done &&
|
||||||
|
availableBytes < afio->inSamples * afio->inSizePerPacket) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,14 +425,6 @@ static MP42SampleBuffer *encode(AudioConverterRef encoder, AudioFileIO *afio)
|
|||||||
|
|
||||||
static MP42SampleBuffer *flush(AudioConverterRef encoder, AudioFileIO *afio)
|
static MP42SampleBuffer *flush(AudioConverterRef encoder, AudioFileIO *afio)
|
||||||
{
|
{
|
||||||
UInt32 availableBytes = sfifo_used(afio->ringBuffer);
|
|
||||||
UInt32 pad = afio->inSamples * afio->inSizePerPacket - availableBytes;
|
|
||||||
|
|
||||||
if (pad > 0 && availableBytes > 0) {
|
|
||||||
UInt8 *padBuffer = calloc(1, pad);
|
|
||||||
sfifo_write(afio->ringBuffer, padBuffer, pad);
|
|
||||||
free(padBuffer);
|
|
||||||
}
|
|
||||||
MP42SampleBuffer *outSample = encode(encoder, afio);
|
MP42SampleBuffer *outSample = encode(encoder, afio);
|
||||||
return outSample;
|
return outSample;
|
||||||
}
|
}
|
||||||
@@ -452,6 +453,7 @@ static inline void enqueue(MP42AudioEncoder *self, MP42SampleBuffer *outSample)
|
|||||||
|
|
||||||
if (sampleBuffer->flags & MP42SampleBufferFlagEndOfFile) {
|
if (sampleBuffer->flags & MP42SampleBufferFlagEndOfFile) {
|
||||||
if (_encoder) {
|
if (_encoder) {
|
||||||
|
_afio->done = true;
|
||||||
while ((outSample = flush(_encoder, _afio))) {
|
while ((outSample = flush(_encoder, _afio))) {
|
||||||
enqueue(self, outSample);
|
enqueue(self, outSample);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user