Fixed some memory leaks in MP42AC3AudioEncoder

This commit is contained in:
Damiano Galassi committed 2017-05-11 12:33:00 +02:00
1 parent 88f4f94e1c
commit c0182dc78b
2 files changed
+23 -26

No files matched your search

+23 -9
View File
@@ -23,12 +23,9 @@ typedef struct AudioFileIO
float *inBuffer; float *inBuffer;
UInt32 inBufferSize; UInt32 inBufferSize;
UInt32 outputMaxSize;
UInt32 inSizePerPacket; UInt32 inSizePerPacket;
UInt32 inSamples; UInt32 inSamples;
UInt32 channelsPerFrame; UInt32 channelsPerFrame;
UInt32 numPacketsPerRead;
AVFrame *frame; AVFrame *frame;
float *samples; float *samples;
@@ -144,17 +141,14 @@ typedef struct AudioFileIO
_afio = malloc(sizeof(AudioFileIO)); _afio = malloc(sizeof(AudioFileIO));
bzero(_afio, sizeof(AudioFileIO)); bzero(_afio, sizeof(AudioFileIO));
_afio->inBufferSize = 1024 * 64; _afio->inBufferSize = 1024 * 64;
_afio->inBuffer = malloc(_afio->inBufferSize); _afio->inBuffer = malloc(_afio->inBufferSize);
_afio->outputMaxSize = _afio->inBufferSize;
_afio->inSizePerPacket = _inputFormat.mBytesPerPacket; _afio->inSizePerPacket = _inputFormat.mBytesPerPacket;
_afio->inSamples = _outputFormat.mFramesPerPacket; _afio->inSamples = _outputFormat.mFramesPerPacket;
_afio->channelsPerFrame = _inputFormat.mChannelsPerFrame; _afio->channelsPerFrame = _inputFormat.mChannelsPerFrame;
_afio->numPacketsPerRead = _afio->inBufferSize / _afio->inSizePerPacket;
_afio->ringBuffer = _ringBuffer; _afio->ringBuffer = _ringBuffer;
_afio->frame = av_frame_alloc(); _afio->frame = av_frame_alloc();
@@ -197,12 +191,32 @@ typedef struct AudioFileIO
{ {
av_frame_free(&_afio->frame); av_frame_free(&_afio->frame);
} }
free(_afio->inBuffer);
free(_afio);
_afio = NULL;
} }
if (_avctx) if (_avctx)
{ {
avcodec_close(_avctx); avcodec_close(_avctx);
av_free(_avctx); av_free(_avctx);
} }
if (_ringBuffer) {
sfifo_close(_ringBuffer);
free(_ringBuffer);
_ringBuffer = NULL;
}
if (_outputLayout) {
free(_outputLayout);
_outputLayout = NULL;
}
if (_inputLayout) {
free(_inputLayout);
_inputLayout = NULL;
}
} }
- (BOOL)createMagicCookie - (BOOL)createMagicCookie
-17
View File
@@ -192,23 +192,6 @@
return (self.trackId > 0); return (self.trackId > 0);
} }
- (void)setConversionSettings:(MP42AudioConversionSettings *)conversionSettings
{
[super setConversionSettings:conversionSettings];
if (conversionSettings == nil) return;
if ([self.name rangeOfString:@"surround" options:NSCaseInsensitiveSearch].location == NSNotFound) return;
if ([conversionSettings.mixDown isEqualToString:SBNoneMixdown]) {
// FFmpeg encoding currently doesn't go beyond 5.1
self.name = (self.channels > 6) ? @"Surround 5.1" : nameForChannelLayoutTag(self.channelLayoutTag);
}
else {
self.name = (self.channels == 1 || [conversionSettings.mixDown isEqualToString:SBMonoMixdown]) ? @"Mono" : @"Stereo";
}
}
- (void)setVolume:(float)newVolume - (void)setVolume:(float)newVolume
{ {
_volume = newVolume; _volume = newVolume;